diff options
author | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 15:53:12 +0000 |
---|---|---|
committer | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 15:53:12 +0000 |
commit | e414727ea30e03a5d4582bdbba42d67327605273 (patch) | |
tree | 58746c063aea418e36d5a618c67bdf1bec9e7409 /skia/ext/platform_canvas_unittest.cc | |
parent | 33986d3ecde79d6a1bdf2b0edd17fc13bc2cc78b (diff) | |
download | chromium_src-e414727ea30e03a5d4582bdbba42d67327605273.zip chromium_src-e414727ea30e03a5d4582bdbba42d67327605273.tar.gz chromium_src-e414727ea30e03a5d4582bdbba42d67327605273.tar.bz2 |
This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata.
BUG=NONE
TEST=NONE
Review URL: http://codereview.chromium.org/7019013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/platform_canvas_unittest.cc')
-rw-r--r-- | skia/ext/platform_canvas_unittest.cc | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/skia/ext/platform_canvas_unittest.cc b/skia/ext/platform_canvas_unittest.cc index 6e43be2..40cdc70 100644 --- a/skia/ext/platform_canvas_unittest.cc +++ b/skia/ext/platform_canvas_unittest.cc @@ -31,8 +31,8 @@ namespace { bool VerifyRect(const PlatformCanvas& canvas, uint32_t canvas_color, uint32_t rect_color, int x, int y, int w, int h) { - PlatformDevice& device = canvas.getTopPlatformDevice(); - const SkBitmap& bitmap = device.accessBitmap(false); + SkDevice* device = skia::GetTopDevice(canvas); + const SkBitmap& bitmap = device->accessBitmap(false); SkAutoLockPixels lock(bitmap); // For masking out the alpha values. @@ -70,8 +70,8 @@ bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { bool VerifyRoundedRect(const PlatformCanvas& canvas, uint32_t canvas_color, uint32_t rect_color, int x, int y, int w, int h) { - PlatformDevice& device = canvas.getTopPlatformDevice(); - const SkBitmap& bitmap = device.accessBitmap(false); + SkDevice* device = skia::GetTopDevice(canvas); + const SkBitmap& bitmap = device->accessBitmap(false); SkAutoLockPixels lock(bitmap); // Check corner points first. They should be of canvas_color. @@ -103,7 +103,8 @@ bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) { #if defined(OS_WIN) void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { - HDC dc = canvas.beginPlatformPaint(); + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + HDC dc = scoped_platform_paint.GetPlatformSurface(); RECT inner_rc; inner_rc.left = x; @@ -111,21 +112,18 @@ void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { inner_rc.right = x + w; inner_rc.bottom = y + h; FillRect(dc, &inner_rc, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH))); - - canvas.endPlatformPaint(); } #elif defined(OS_MACOSX) void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { - CGContextRef context = canvas.beginPlatformPaint(); - + skia::ScopedPlatformPaint scoped_platform_paint(&canvas); + CGContextRef context = scoped_platform_paint.GetPlatformSurface(); + CGRect inner_rc = CGRectMake(x, y, w, h); // RGBA opaque black CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); CGContextSetFillColorWithColor(context, black); CGColorRelease(black); CGContextFillRect(context, inner_rc); - - canvas.endPlatformPaint(); } #else void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { @@ -244,7 +242,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); @@ -255,8 +253,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); @@ -269,8 +266,7 @@ TEST(PlatformCanvas, FillLayer) { AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque( - kInnerX, kInnerY, kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif canvas.restore(); } @@ -284,7 +280,7 @@ TEST(PlatformCanvas, FillLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } canvas.restore(); @@ -305,7 +301,7 @@ TEST(PlatformCanvas, TranslateLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(0, 0, 100, 100); + MakeOpaque(&canvas, 0, 0, 100, 100); #endif } canvas.restore(); @@ -320,8 +316,7 @@ TEST(PlatformCanvas, TranslateLayer) { LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } canvas.restore(); @@ -336,8 +331,7 @@ TEST(PlatformCanvas, TranslateLayer) { canvas.translate(1, 1); DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY, - kInnerW, kInnerH); + MakeOpaque(&canvas, kInnerX, kInnerY, kInnerW, kInnerH); #endif } canvas.restore(); @@ -355,8 +349,7 @@ TEST(PlatformCanvas, TranslateLayer) { AddClip(canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1); DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY, - kLayerW, kLayerH); + MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH); #endif } canvas.restore(); @@ -384,8 +377,7 @@ TEST(PlatformCanvas, TranslateLayer) { DrawNativeRect(canvas, 0, 0, 100, 100); #if defined(OS_WIN) - canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY, - kLayerW, kLayerH); + MakeOpaque(&canvas, kLayerX, kLayerY, kLayerW, kLayerH); #endif } canvas.restore(); |