diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-18 09:40:26 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-18 09:40:26 +0000 |
commit | 584abe77f84b1bf56e9633e63d4fe60947eabe27 (patch) | |
tree | 8f362a9a98484c54f67968d42705c82f16328b0c /cc/resources/picture_unittest.cc | |
parent | 5a260744b81b9d3be148c2ac2b9387ab2f015213 (diff) | |
download | chromium_src-584abe77f84b1bf56e9633e63d4fe60947eabe27.zip chromium_src-584abe77f84b1bf56e9633e63d4fe60947eabe27.tar.gz chromium_src-584abe77f84b1bf56e9633e63d4fe60947eabe27.tar.bz2 |
Only use skia::RefPtr for refcounting
For consistency and sanity in Chromium, only use skia::RefPtr in Chromium to
ref count skia classes. SkRefPtr is unsafe to use for newly created objects
because it refs the object that is passed to its constructor. skia::RefPtr
makes this adoption explicit it via skia::AdoptRef and so is much clearer.
This patch also adds a skia::ShareRef function which makes it explicit that the
callsite is adopting a ref which is already owned somewhere else. Using
AdoptRef vs. ShareRef seems much clearer than using SkRefPtr vs. skia::RefPtr.
These are the remaining code sites that use internal Skia reference counted
classes. Once these have been removed, then we can use a PRESUBMIT rule to
prevent new uses from being added.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/15004024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200989 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/picture_unittest.cc')
-rw-r--r-- | cc/resources/picture_unittest.cc | 50 |
1 files changed, 1 insertions, 49 deletions
diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc index c5ddde2..7d92582 100644 --- a/cc/resources/picture_unittest.cc +++ b/cc/resources/picture_unittest.cc @@ -7,6 +7,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "cc/test/fake_content_layer_client.h" +#include "cc/test/skia_common.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkDevice.h" @@ -19,55 +20,6 @@ namespace cc { namespace { -class TestLazyPixelRef : public skia::LazyPixelRef { - public: - // Pure virtual implementation. - TestLazyPixelRef(int width, int height) - : pixels_(new char[4 * width * height]) {} - virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } - virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { - return pixels_.get(); - } - virtual void onUnlockPixels() OVERRIDE {} - virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE { - return true; - } - virtual SkPixelRef* deepCopy( - SkBitmap::Config config, - const SkIRect* subset) OVERRIDE { - this->ref(); - return this; - } - virtual void Decode() OVERRIDE {} - private: - scoped_ptr<char[]> pixels_; -}; - -void DrawPicture(unsigned char* buffer, - gfx::Rect layer_rect, - scoped_refptr<Picture> picture) { - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, - layer_rect.width(), - layer_rect.height()); - bitmap.setPixels(buffer); - SkDevice device(bitmap); - SkCanvas canvas(&device); - canvas.clipRect(gfx::RectToSkRect(layer_rect)); - picture->Raster(&canvas, layer_rect, 1.0f, false); -} - -void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { - SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; - lazy_pixel_ref.reset(new TestLazyPixelRef(size.width(), size.height())); - lazy_pixel_ref->setURI(uri); - - bitmap->setConfig(SkBitmap::kARGB_8888_Config, - size.width(), - size.height()); - bitmap->setPixelRef(lazy_pixel_ref); -} - TEST(PictureTest, AsBase64String) { SkGraphics::Init(); |