| OLD | NEW |
| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255); | 215 SkPMColor testColor = SkPreMultiplyARGB(10, 255, 255, 255); |
| 216 bitmap.allocN32Pixels(1,1); | 216 bitmap.allocN32Pixels(1,1); |
| 217 SkAutoLockPixels bitmap_lock(bitmap); | 217 SkAutoLockPixels bitmap_lock(bitmap); |
| 218 *bitmap.getAddr32(0, 0) = testColor; | 218 *bitmap.getAddr32(0, 0) = testColor; |
| 219 WebCursor::CursorInfo cursor_info; | 219 WebCursor::CursorInfo cursor_info; |
| 220 cursor_info.type = WebCursorInfo::TypeCustom; | 220 cursor_info.type = WebCursorInfo::TypeCustom; |
| 221 cursor_info.custom_image = bitmap; | 221 cursor_info.custom_image = bitmap; |
| 222 cursor_info.image_scale_factor = 1; | 222 cursor_info.image_scale_factor = 1; |
| 223 WebCursor custom_cursor; | 223 WebCursor custom_cursor; |
| 224 | 224 |
| 225 // This round trip will convert the cursor to unpremultiplied form | 225 // This round trip will convert the cursor to unpremultiplied form. |
| 226 custom_cursor.InitFromCursorInfo(cursor_info); | 226 custom_cursor.InitFromCursorInfo(cursor_info); |
| 227 custom_cursor.GetCursorInfo(&cursor_info); | 227 custom_cursor.GetCursorInfo(&cursor_info); |
| 228 { | 228 { |
| 229 SkAutoLockPixels lock(cursor_info.custom_image); | 229 SkAutoLockPixels lock(cursor_info.custom_image); |
| 230 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); | 230 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 231 EXPECT_EQ(testColor, | 231 EXPECT_EQ(testColor, |
| 232 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | 232 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Second round trip should not do any conversion because data is alread | 235 // Second round trip should not do any conversion because data is already |
| 236 // unpremultiplied | 236 // unpremultiplied. |
| 237 custom_cursor.InitFromCursorInfo(cursor_info); | 237 custom_cursor.InitFromCursorInfo(cursor_info); |
| 238 custom_cursor.GetCursorInfo(&cursor_info); | 238 custom_cursor.GetCursorInfo(&cursor_info); |
| 239 { | 239 { |
| 240 SkAutoLockPixels lock(cursor_info.custom_image); | 240 SkAutoLockPixels lock(cursor_info.custom_image); |
| 241 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); | 241 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 242 EXPECT_EQ(testColor, | 242 EXPECT_EQ(testColor, |
| 243 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); | 243 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); |
| 244 } | 244 } |
| 245 |
| 246 #if defined(OS_MACOSX) |
| 247 // On MacOS, test roundtrip through NSCursor conversion. |
| 248 WebCursor custom_cursor_copy; |
| 249 custom_cursor_copy.InitFromNSCursor(custom_cursor.GetNativeCursor()); |
| 250 custom_cursor_copy.GetCursorInfo(&cursor_info); |
| 251 { |
| 252 SkAutoLockPixels lock(cursor_info.custom_image); |
| 253 EXPECT_EQ(kUnpremul_SkAlphaType, cursor_info.custom_image.alphaType()); |
| 254 EXPECT_EQ(testColor, |
| 255 SkPreMultiplyColor(*cursor_info.custom_image.getAddr32(0,0))); |
| 256 } |
| 257 #endif |
| 245 } | 258 } |
| 246 | 259 |
| 247 } // namespace content | 260 } // namespace content |
| OLD | NEW |