diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-02 23:31:07 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-02 23:31:07 +0000 |
commit | d748d0ffa9996ae58ab39c2cfdd5abbfcb6dcec4 (patch) | |
tree | af8aab17d5d6a08ba69022f408792733471da483 /skia/ext/platform_canvas_unittest.cc | |
parent | 89ae13ed038c80228a532f42c92cd5de5bbc8a35 (diff) | |
download | chromium_src-d748d0ffa9996ae58ab39c2cfdd5abbfcb6dcec4.zip chromium_src-d748d0ffa9996ae58ab39c2cfdd5abbfcb6dcec4.tar.gz chromium_src-d748d0ffa9996ae58ab39c2cfdd5abbfcb6dcec4.tar.bz2 |
Change PlatformBitmap memory ownership story. Fix CopyFromBackingStore threading issues.
PlatformBitmap: restructure this class so that, on all platforms,
it is safe to use an SkBitmap derived from the PlatformBitmap
even after the PlatformBitmap is destroyed. In practice
this means changes to Linux (use a different cairo
creation routine that allows us to allocate the memory) and
Windows (the HDC is owned by PlatformBitmap, the HBITMAP
by the SkPixelRef).
CopyFromBackingStore: instead of requiring the caller to
provide a PlatformBitmap, modify the signature so that the
completion callback accepts an SkBitmap. Sometimes, the backing store
copiers will allocate a PlatformBitmap and pass its SkBitmap
to the completion callback, but this becomes merely an
implementation detail. Meanwhile, in the accelerated case,
it is not at all necessary to allocate a PlatformBitmap,
so don't.
This fixes a bug on Linux where the cairo surface context
was being freed on a thread other than the UI thread.
PlatformBitmap is basically not thread safe on Linux,
and this change fixes that. Also fixed is a Dr. Memory
GDI usage warning -- we are sure to de-select the
HBITMAP before deleting the memory DC.
Lastly, moving CopyFromBackingStore's interface to use a
callee-managed SkBitmap conditions the architecture for doing
RGBA->YUV on the GPU, prior to readback.
BUG=109963,159234,161537
Review URL: https://codereview.chromium.org/12087016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/platform_canvas_unittest.cc')
-rw-r--r-- | skia/ext/platform_canvas_unittest.cc | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/skia/ext/platform_canvas_unittest.cc b/skia/ext/platform_canvas_unittest.cc index 3c8b017..572180e 100644 --- a/skia/ext/platform_canvas_unittest.cc +++ b/skia/ext/platform_canvas_unittest.cc @@ -14,11 +14,13 @@ #include <unistd.h> #endif +#include "base/memory/scoped_ptr.h" #include "skia/ext/platform_canvas.h" #include "skia/ext/platform_device.h" #include "testing/gtest/include/gtest/gtest.h" - -#include "SkColor.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkPixelRef.h" namespace skia { @@ -395,4 +397,63 @@ TEST(PlatformCanvas, TranslateLayer) { #endif // #if !defined(USE_AURA) +TEST(PlatformBitmapTest, PlatformBitmap) { + const int kWidth = 400; + const int kHeight = 300; + scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap); + + EXPECT_TRUE(0 == platform_bitmap->GetSurface()); + EXPECT_TRUE(platform_bitmap->GetBitmap().empty()); + EXPECT_TRUE(platform_bitmap->GetBitmap().isNull()); + + EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false)); + + EXPECT_TRUE(0 != platform_bitmap->GetSurface()); + EXPECT_FALSE(platform_bitmap->GetBitmap().empty()); + EXPECT_FALSE(platform_bitmap->GetBitmap().isNull()); + EXPECT_EQ(kWidth, platform_bitmap->GetBitmap().width()); + EXPECT_EQ(kHeight, platform_bitmap->GetBitmap().height()); + EXPECT_LE(platform_bitmap->GetBitmap().width()*4, + platform_bitmap->GetBitmap().rowBytes()); + EXPECT_EQ(SkBitmap::kARGB_8888_Config, // Same for all platforms. + platform_bitmap->GetBitmap().config()); + EXPECT_TRUE(platform_bitmap->GetBitmap().lockPixelsAreWritable()); + EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->isLocked()); + EXPECT_EQ(1, platform_bitmap->GetBitmap().pixelRef()->getRefCnt()); + + *(platform_bitmap->GetBitmap().getAddr32(10, 20)) = 0xDEED1020; + *(platform_bitmap->GetBitmap().getAddr32(20, 30)) = 0xDEED2030; + + SkBitmap sk_bitmap = platform_bitmap->GetBitmap(); + sk_bitmap.lockPixels(); + + EXPECT_EQ(2, platform_bitmap->GetBitmap().pixelRef()->getRefCnt()); + EXPECT_EQ(2, sk_bitmap.pixelRef()->getRefCnt()); + + EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); + EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); + + *(platform_bitmap->GetBitmap().getAddr32(30, 40)) = 0xDEED3040; + + // The SkBitmaps derived from a PlatformBitmap must be capable of outliving + // the PlatformBitmap. + platform_bitmap.reset(); + + EXPECT_EQ(1, sk_bitmap.pixelRef()->getRefCnt()); + + EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); + EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); + EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); + sk_bitmap.unlockPixels(); + + EXPECT_EQ(NULL, sk_bitmap.getPixels()); + + sk_bitmap.lockPixels(); + EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); + EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); + EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); + sk_bitmap.unlockPixels(); +} + + } // namespace skia |