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 "skia/ext/platform_canvas.h" | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "build/build_config.h" | 7 #include "build/build_config.h" |
12 #include "skia/ext/platform_device.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "third_party/skia/include/core/SkBitmap.h" | |
15 #include "third_party/skia/include/core/SkColor.h" | |
16 #include "third_party/skia/include/core/SkColorPriv.h" | |
17 #include "third_party/skia/include/core/SkPixelRef.h" | |
18 | 8 |
19 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
20 #import <ApplicationServices/ApplicationServices.h> | 10 #import <ApplicationServices/ApplicationServices.h> |
21 #endif | 11 #endif |
22 | 12 |
23 #if !defined(OS_WIN) | 13 #if !defined(OS_WIN) |
24 #include <unistd.h> | 14 #include <unistd.h> |
25 #endif | 15 #endif |
26 | 16 |
| 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "skia/ext/platform_canvas.h" |
| 19 #include "skia/ext/platform_device.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "third_party/skia/include/core/SkColorPriv.h" |
| 24 #include "third_party/skia/include/core/SkPixelRef.h" |
| 25 |
27 namespace skia { | 26 namespace skia { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { | 30 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { |
32 // For masking out the alpha values. | 31 // For masking out the alpha values. |
33 static uint32_t alpha_mask = | 32 static uint32_t alpha_mask = |
34 static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; | 33 static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; |
35 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); | 34 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); |
36 } | 35 } |
(...skipping 24 matching lines...) Expand all Loading... |
61 } | 60 } |
62 } | 61 } |
63 return true; | 62 return true; |
64 } | 63 } |
65 | 64 |
66 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
67 // 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 |
68 // 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 |
69 // 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. |
70 bool VerifyRoundedRect(const PlatformCanvas& canvas, | 69 bool VerifyRoundedRect(const PlatformCanvas& canvas, |
71 uint32_t canvas_color, | 70 uint32_t canvas_color, uint32_t rect_color, |
72 uint32_t rect_color, | 71 int x, int y, int w, int h) { |
73 int x, | |
74 int y, | |
75 int w, | |
76 int h) { | |
77 SkBaseDevice* device = skia::GetTopDevice(canvas); | 72 SkBaseDevice* device = skia::GetTopDevice(canvas); |
78 const SkBitmap& bitmap = device->accessBitmap(false); | 73 const SkBitmap& bitmap = device->accessBitmap(false); |
79 SkAutoLockPixels lock(bitmap); | 74 SkAutoLockPixels lock(bitmap); |
80 | 75 |
81 // Check corner points first. They should be of canvas_color. | 76 // Check corner points first. They should be of canvas_color. |
82 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; | 77 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; |
83 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 78 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
84 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; | 79 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; |
85 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 80 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
86 | 81 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 119 |
125 CGRect inner_rc = CGRectMake(x, y, w, h); | 120 CGRect inner_rc = CGRectMake(x, y, w, h); |
126 // RGBA opaque black | 121 // RGBA opaque black |
127 CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); | 122 CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); |
128 CGContextSetFillColorWithColor(context, black); | 123 CGContextSetFillColorWithColor(context, black); |
129 CGColorRelease(black); | 124 CGColorRelease(black); |
130 CGContextFillRect(context, inner_rc); | 125 CGContextFillRect(context, inner_rc); |
131 } | 126 } |
132 #else | 127 #else |
133 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { | 128 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { |
134 NOTIMPLEMENTED(); | 129 notImplemented(); |
135 } | 130 } |
136 #endif | 131 #endif |
137 | 132 |
138 // Clips the contents of the canvas to the given rectangle. This will be | 133 // Clips the contents of the canvas to the given rectangle. This will be |
139 // intersected with any existing clip. | 134 // intersected with any existing clip. |
140 void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) { | 135 void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) { |
141 SkRect rect; | 136 SkRect rect; |
142 rect.set(SkIntToScalar(x), SkIntToScalar(y), | 137 rect.set(SkIntToScalar(x), SkIntToScalar(y), |
143 SkIntToScalar(x + w), SkIntToScalar(y + h)); | 138 SkIntToScalar(x + w), SkIntToScalar(y + h)); |
144 canvas.clipRect(rect); | 139 canvas.clipRect(rect); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 445 |
451 sk_bitmap.lockPixels(); | 446 sk_bitmap.lockPixels(); |
452 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); | 447 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); |
453 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); | 448 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); |
454 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); | 449 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); |
455 sk_bitmap.unlockPixels(); | 450 sk_bitmap.unlockPixels(); |
456 } | 451 } |
457 | 452 |
458 | 453 |
459 } // namespace skia | 454 } // namespace skia |
OLD | NEW |