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

Unified Diff: content/common/cursors/webcursor_unittest.cc

Issue 1251173003: Fix alpha pre-multiplication error with custom cursor images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows build fix Created 5 years, 5 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 | « content/common/cursors/webcursor.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/cursors/webcursor_unittest.cc
diff --git a/content/common/cursors/webcursor_unittest.cc b/content/common/cursors/webcursor_unittest.cc
index d05a68f3d88c24d1d2074686dbebb81f8d702b6d..0fd1a751273643fee10b727255d3181223df2bb6 100644
--- a/content/common/cursors/webcursor_unittest.cc
+++ b/content/common/cursors/webcursor_unittest.cc
@@ -150,7 +150,7 @@ TEST(WebCursorTest, ClampHotspot) {
// Custom Windows message.
ok_custom_pickle.WriteUInt32(0);
base::PickleIterator iter(ok_custom_pickle);
- ASSERT_TRUE(custom_cursor.Deserialize(&iter));
+ EXPECT_TRUE(custom_cursor.Deserialize(&iter));
// Convert to WebCursorInfo, make sure the hotspot got clamped.
WebCursor::CursorInfo info;
@@ -185,7 +185,7 @@ TEST(WebCursorTest, EmptyImage) {
// Make sure we can read this on all platforms; it is technicaally a valid
// cursor.
base::PickleIterator iter(broken_cursor_pickle);
- ASSERT_TRUE(custom_cursor.Deserialize(&iter));
+ EXPECT_TRUE(custom_cursor.Deserialize(&iter));
}
TEST(WebCursorTest, Scale2) {
@@ -210,4 +210,38 @@ TEST(WebCursorTest, Scale2) {
EXPECT_TRUE(custom_cursor.Deserialize(&iter));
}
+TEST(WebCursorTest, AlphaConversion) {
+ SkBitmap bitmap;
+ SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255);
+ bitmap.allocN32Pixels(1,1);
+ SkAutoLockPixels bitmap_lock(bitmap);
+ *bitmap.getAddr32(0, 0) = testColor;
+ WebCursor::CursorInfo cursor_info;
+ cursor_info.type = WebCursorInfo::TypeCustom;
+ cursor_info.custom_image = bitmap;
+ cursor_info.image_scale_factor = 1;
+ WebCursor custom_cursor;
+
+ // This round trip will convert the cursor to unpremultiplied form
+ custom_cursor.InitFromCursorInfo(cursor_info);
+ custom_cursor.GetCursorInfo(&cursor_info);
+ {
+ SkAutoLockPixels lock(cursor_info.custom_image);
+ EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType());
+ EXPECT_EQ(testColor,
+ SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0)));
+ }
+
+ // Second round trip should not do any conversion because data is alread
+ // unpremultiplied
+ custom_cursor.InitFromCursorInfo(cursor_info);
+ custom_cursor.GetCursorInfo(&cursor_info);
+ {
+ SkAutoLockPixels lock(cursor_info.custom_image);
+ EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType());
+ EXPECT_EQ(testColor,
+ SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0)));
+ }
+}
+
} // namespace content
« no previous file with comments | « content/common/cursors/webcursor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698