Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: skia/ext/platform_canvas_unittest.cc

Issue 75020: Make non-rectangular clip region apply in the correct location.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/bitmap_platform_device_win.cc ('k') | skia/ext/platform_device_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/platform_canvas_unittest.cc
===================================================================
--- skia/ext/platform_canvas_unittest.cc (revision 13611)
+++ skia/ext/platform_canvas_unittest.cc (working copy)
@@ -56,6 +56,37 @@
return true;
}
+bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) {
+ // For masking out the alpha values.
+ static uint32_t alpha_mask = 0xFF << SK_A32_SHIFT;
+ return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask);
+}
+
+// Return true if canvas has something that passes for a rounded-corner
+// rectangle. Basically, we're just checking to make sure that the pixels in the
+// middle are of rect_color and pixels in the corners are of canvas_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);
+ SkAutoLockPixels lock(bitmap);
+
+ // Check corner points first. They should be of canvas_color.
+ if (!IsOfColor(bitmap, x, y, canvas_color)) return false;
+ if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false;
+ if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false;
+ if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false;
+
+ // Check middle points. They should be of rect_color.
+ if (!IsOfColor(bitmap, (x + w / 2), y, rect_color)) return false;
+ if (!IsOfColor(bitmap, x, (y + h / 2), rect_color)) return false;
+ if (!IsOfColor(bitmap, x + w, (y + h / 2), rect_color)) return false;
+ if (!IsOfColor(bitmap, (x + w / 2), y + h, rect_color)) return false;
+
+ return true;
+}
+
// Checks whether there is a white canvas with a black square at the given
// location in pixels (not in the canvas coordinate system).
bool VerifyBlackRect(const PlatformCanvas& canvas, int x, int y, int w, int h) {
@@ -152,6 +183,9 @@
const int kInnerW = 2;
const int kInnerH = 3;
+// Radius used by some tests to draw a rounded-corner rectangle.
+const SkScalar kRadius = 2.0;
+
}
// This just checks that our checking code is working properly, it just uses
@@ -313,17 +347,44 @@
canvas.translate(1, 1);
{
LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas.drawColor(SK_ColorWHITE);
canvas.translate(1, 1);
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
+ AddClip(canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1);
DrawNativeRect(canvas, 0, 0, 100, 100);
#if defined(OS_WIN)
- canvas.getTopPlatformDevice().makeOpaque(kInnerX, kInnerY,
- kInnerW, kInnerH);
+ canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY,
+ kLayerW, kLayerH);
#endif
}
canvas.restore();
- EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 2, kInnerY + 2,
- kInnerW, kInnerH));
+ EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 3, kInnerY + 3,
+ kInnerW - 1, kInnerH - 1));
+
+ // Translate both before and after, and have a path clip.
+ canvas.drawColor(SK_ColorWHITE);
+ canvas.save();
+ canvas.translate(1, 1);
+ {
+ LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
+ canvas.drawColor(SK_ColorWHITE);
+ canvas.translate(1, 1);
+
+ SkPath path;
+ SkRect rect;
+ rect.iset(kInnerX - 1, kInnerY - 1,
+ kInnerX + kInnerW, kInnerY + kInnerH);
+ path.addRoundRect(rect, kRadius, kRadius);
+ canvas.clipPath(path);
+
+ DrawNativeRect(canvas, 0, 0, 100, 100);
+#if defined(OS_WIN)
+ canvas.getTopPlatformDevice().makeOpaque(kLayerX, kLayerY,
+ kLayerW, kLayerH);
+#endif
+ }
+ canvas.restore();
+ EXPECT_TRUE(VerifyRoundedRect(canvas, SK_ColorWHITE, SK_ColorBLACK,
+ kInnerX + 1, kInnerY + 1, kInnerW, kInnerH));
}
} // namespace skia
« no previous file with comments | « skia/ext/bitmap_platform_device_win.cc ('k') | skia/ext/platform_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698