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 // TODO(awalker): clean up the const/non-const reference handling in this test | 5 // TODO(awalker): clean up the const/non-const reference handling in this test |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
10 #import <ApplicationServices/ApplicationServices.h> | 10 #import <ApplicationServices/ApplicationServices.h> |
11 #endif | 11 #endif |
12 | 12 |
13 #if !defined(OS_WIN) | 13 #if !defined(OS_WIN) |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
19 #include "skia/ext/platform_device.h" | 19 #include "skia/ext/platform_device.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "third_party/skia/include/core/SkColorPriv.h" |
23 #include "third_party/skia/include/core/SkPixelRef.h" | 24 #include "third_party/skia/include/core/SkPixelRef.h" |
24 | 25 |
25 namespace skia { | 26 namespace skia { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
| 30 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { |
| 31 // For masking out the alpha values. |
| 32 static uint32_t alpha_mask = |
| 33 static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; |
| 34 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); |
| 35 } |
| 36 |
29 // Return true if the canvas is filled to canvas_color, and contains a single | 37 // Return true if the canvas is filled to canvas_color, and contains a single |
30 // rectangle filled to rect_color. This function ignores the alpha channel, | 38 // rectangle filled to rect_color. This function ignores the alpha channel, |
31 // since Windows will sometimes clear the alpha channel when drawing, and we | 39 // since Windows will sometimes clear the alpha channel when drawing, and we |
32 // will fix that up later in cases it's necessary. | 40 // will fix that up later in cases it's necessary. |
33 bool VerifyRect(const PlatformCanvas& canvas, | 41 bool VerifyRect(const PlatformCanvas& canvas, |
34 uint32_t canvas_color, uint32_t rect_color, | 42 uint32_t canvas_color, uint32_t rect_color, |
35 int x, int y, int w, int h) { | 43 int x, int y, int w, int h) { |
36 SkBaseDevice* device = skia::GetTopDevice(canvas); | 44 SkBaseDevice* device = skia::GetTopDevice(canvas); |
37 const SkBitmap& bitmap = device->accessBitmap(false); | 45 const SkBitmap& bitmap = device->accessBitmap(false); |
38 SkAutoLockPixels lock(bitmap); | 46 SkAutoLockPixels lock(bitmap); |
39 | 47 |
40 // For masking out the alpha values. | |
41 uint32_t alpha_mask = 0xFF << SK_A32_SHIFT; | |
42 | |
43 for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) { | 48 for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) { |
44 for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) { | 49 for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) { |
45 if (cur_x >= x && cur_x < x + w && | 50 if (cur_x >= x && cur_x < x + w && |
46 cur_y >= y && cur_y < y + h) { | 51 cur_y >= y && cur_y < y + h) { |
47 // Inside the square should be rect_color | 52 // Inside the square should be rect_color |
48 if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) != | 53 if (!IsOfColor(bitmap, cur_x, cur_y, rect_color)) |
49 (rect_color | alpha_mask)) | |
50 return false; | 54 return false; |
51 } else { | 55 } else { |
52 // Outside the square should be canvas_color | 56 // Outside the square should be canvas_color |
53 if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) != | 57 if (!IsOfColor(bitmap, cur_x, cur_y, canvas_color)) |
54 (canvas_color | alpha_mask)) | |
55 return false; | 58 return false; |
56 } | 59 } |
57 } | 60 } |
58 } | 61 } |
59 return true; | 62 return true; |
60 } | 63 } |
61 | 64 |
62 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
63 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { | |
64 // For masking out the alpha values. | |
65 static uint32_t alpha_mask = 0xFF << SK_A32_SHIFT; | |
66 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); | |
67 } | |
68 | |
69 // Return true if canvas has something that passes for a rounded-corner | 66 // Return true if canvas has something that passes for a rounded-corner |
70 // rectangle. Basically, we're just checking to make sure that the pixels in the | 67 // rectangle. Basically, we're just checking to make sure that the pixels in the |
71 // middle are of rect_color and pixels in the corners are of canvas_color. | 68 // middle are of rect_color and pixels in the corners are of canvas_color. |
72 bool VerifyRoundedRect(const PlatformCanvas& canvas, | 69 bool VerifyRoundedRect(const PlatformCanvas& canvas, |
73 uint32_t canvas_color, uint32_t rect_color, | 70 uint32_t canvas_color, uint32_t rect_color, |
74 int x, int y, int w, int h) { | 71 int x, int y, int w, int h) { |
75 SkBaseDevice* device = skia::GetTopDevice(canvas); | 72 SkBaseDevice* device = skia::GetTopDevice(canvas); |
76 const SkBitmap& bitmap = device->accessBitmap(false); | 73 const SkBitmap& bitmap = device->accessBitmap(false); |
77 SkAutoLockPixels lock(bitmap); | 74 SkAutoLockPixels lock(bitmap); |
78 | 75 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 445 |
449 sk_bitmap.lockPixels(); | 446 sk_bitmap.lockPixels(); |
450 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); | 447 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); |
451 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); | 448 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); |
452 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); | 449 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); |
453 sk_bitmap.unlockPixels(); | 450 sk_bitmap.unlockPixels(); |
454 } | 451 } |
455 | 452 |
456 | 453 |
457 } // namespace skia | 454 } // namespace skia |
OLD | NEW |