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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « content/common/cursors/webcursor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/pickle.h" 5 #include "base/pickle.h"
6 #include "content/common/cursors/webcursor.h" 6 #include "content/common/cursors/webcursor.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 8 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
9 9
10 using blink::WebCursorInfo; 10 using blink::WebCursorInfo;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ok_custom_pickle.WriteInt(2); 143 ok_custom_pickle.WriteInt(2);
144 // Scale 144 // Scale
145 ok_custom_pickle.WriteFloat(1.0); 145 ok_custom_pickle.WriteFloat(1.0);
146 // Data len including enough data for a 2x2 image. 146 // Data len including enough data for a 2x2 image.
147 ok_custom_pickle.WriteInt(4 * 4); 147 ok_custom_pickle.WriteInt(4 * 4);
148 for (size_t i = 0; i < 4; i++) 148 for (size_t i = 0; i < 4; i++)
149 ok_custom_pickle.WriteUInt32(0); 149 ok_custom_pickle.WriteUInt32(0);
150 // Custom Windows message. 150 // Custom Windows message.
151 ok_custom_pickle.WriteUInt32(0); 151 ok_custom_pickle.WriteUInt32(0);
152 base::PickleIterator iter(ok_custom_pickle); 152 base::PickleIterator iter(ok_custom_pickle);
153 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); 153 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
154 154
155 // Convert to WebCursorInfo, make sure the hotspot got clamped. 155 // Convert to WebCursorInfo, make sure the hotspot got clamped.
156 WebCursor::CursorInfo info; 156 WebCursor::CursorInfo info;
157 custom_cursor.GetCursorInfo(&info); 157 custom_cursor.GetCursorInfo(&info);
158 EXPECT_EQ(gfx::Point(1, 1), info.hotspot); 158 EXPECT_EQ(gfx::Point(1, 1), info.hotspot);
159 159
160 // Set hotspot to an invalid point again, pipe back through WebCursor, 160 // Set hotspot to an invalid point again, pipe back through WebCursor,
161 // and make sure the hotspot got clamped again. 161 // and make sure the hotspot got clamped again.
162 info.hotspot = gfx::Point(-1, -1); 162 info.hotspot = gfx::Point(-1, -1);
163 custom_cursor.InitFromCursorInfo(info); 163 custom_cursor.InitFromCursorInfo(info);
(...skipping 14 matching lines...) Expand all
178 // Scale 178 // Scale
179 broken_cursor_pickle.WriteFloat(1.0); 179 broken_cursor_pickle.WriteFloat(1.0);
180 // No data for the image since the size is 0. 180 // No data for the image since the size is 0.
181 broken_cursor_pickle.WriteInt(0); 181 broken_cursor_pickle.WriteInt(0);
182 // Custom Windows message. 182 // Custom Windows message.
183 broken_cursor_pickle.WriteInt(0); 183 broken_cursor_pickle.WriteInt(0);
184 184
185 // Make sure we can read this on all platforms; it is technicaally a valid 185 // Make sure we can read this on all platforms; it is technicaally a valid
186 // cursor. 186 // cursor.
187 base::PickleIterator iter(broken_cursor_pickle); 187 base::PickleIterator iter(broken_cursor_pickle);
188 ASSERT_TRUE(custom_cursor.Deserialize(&iter)); 188 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
189 } 189 }
190 190
191 TEST(WebCursorTest, Scale2) { 191 TEST(WebCursorTest, Scale2) {
192 WebCursor custom_cursor; 192 WebCursor custom_cursor;
193 // This is a valid custom cursor. 193 // This is a valid custom cursor.
194 base::Pickle ok_custom_pickle; 194 base::Pickle ok_custom_pickle;
195 // Type and hotspots. 195 // Type and hotspots.
196 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom); 196 ok_custom_pickle.WriteInt(WebCursorInfo::TypeCustom);
197 ok_custom_pickle.WriteInt(0); 197 ok_custom_pickle.WriteInt(0);
198 ok_custom_pickle.WriteInt(0); 198 ok_custom_pickle.WriteInt(0);
199 // X & Y 199 // X & Y
200 ok_custom_pickle.WriteInt(1); 200 ok_custom_pickle.WriteInt(1);
201 ok_custom_pickle.WriteInt(1); 201 ok_custom_pickle.WriteInt(1);
202 // Scale - 2 image pixels per UI pixel. 202 // Scale - 2 image pixels per UI pixel.
203 ok_custom_pickle.WriteFloat(2.0); 203 ok_custom_pickle.WriteFloat(2.0);
204 // Data len including enough data for a 1x1 image. 204 // Data len including enough data for a 1x1 image.
205 ok_custom_pickle.WriteInt(4); 205 ok_custom_pickle.WriteInt(4);
206 ok_custom_pickle.WriteUInt32(0); 206 ok_custom_pickle.WriteUInt32(0);
207 // Custom Windows message. 207 // Custom Windows message.
208 ok_custom_pickle.WriteUInt32(0); 208 ok_custom_pickle.WriteUInt32(0);
209 base::PickleIterator iter(ok_custom_pickle); 209 base::PickleIterator iter(ok_custom_pickle);
210 EXPECT_TRUE(custom_cursor.Deserialize(&iter)); 210 EXPECT_TRUE(custom_cursor.Deserialize(&iter));
211 } 211 }
212 212
213 TEST(WebCursorTest, AlphaConversion) {
214 SkBitmap bitmap;
215 SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255);
216 bitmap.allocN32Pixels(1,1);
217 SkAutoLockPixels bitmap_lock(bitmap);
218 *bitmap.getAddr32(0, 0) = testColor;
219 WebCursor::CursorInfo cursor_info;
220 cursor_info.type = WebCursorInfo::TypeCustom;
221 cursor_info.custom_image = bitmap;
222 cursor_info.image_scale_factor = 1;
223 WebCursor custom_cursor;
224
225 // This round trip will convert the cursor to unpremultiplied form
226 custom_cursor.InitFromCursorInfo(cursor_info);
227 custom_cursor.GetCursorInfo(&cursor_info);
228 {
229 SkAutoLockPixels lock(cursor_info.custom_image);
230 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType());
231 EXPECT_EQ(testColor,
232 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0)));
233 }
234
235 // Second round trip should not do any conversion because data is alread
236 // unpremultiplied
237 custom_cursor.InitFromCursorInfo(cursor_info);
238 custom_cursor.GetCursorInfo(&cursor_info);
239 {
240 SkAutoLockPixels lock(cursor_info.custom_image);
241 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType());
242 EXPECT_EQ(testColor,
243 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0)));
244 }
245 }
246
213 } // namespace content 247 } // namespace content
OLDNEW
« 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