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" | 7 #include "skia/ext/platform_canvas.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Return true if canvas has something that passes for a rounded-corner | 95 // Return true if canvas has something that passes for a rounded-corner |
96 // rectangle. Basically, we're just checking to make sure that the pixels in the | 96 // rectangle. Basically, we're just checking to make sure that the pixels in the |
97 // middle are of rect_color and pixels in the corners are of canvas_color. | 97 // middle are of rect_color and pixels in the corners are of canvas_color. |
98 bool VerifyRoundedRect(const SkCanvas& canvas, | 98 bool VerifyRoundedRect(const SkCanvas& canvas, |
99 uint32_t canvas_color, | 99 uint32_t canvas_color, |
100 uint32_t rect_color, | 100 uint32_t rect_color, |
101 int x, | 101 int x, |
102 int y, | 102 int y, |
103 int w, | 103 int w, |
104 int h) { | 104 int h) { |
105 SkBaseDevice* device = canvas.getTopDevice(true); | 105 SkPixmap pixmap; |
106 const SkBitmap& bitmap = device->accessBitmap(false); | 106 ASSERT_TRUE(canvas.peekPixels(&pixmap)); |
107 SkAutoLockPixels lock(bitmap); | 107 SkBitmap bitmap; |
| 108 bitmap.installPixels(pixmap); |
108 | 109 |
109 // Check corner points first. They should be of canvas_color. | 110 // Check corner points first. They should be of canvas_color. |
110 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; | 111 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; |
111 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 112 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
112 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; | 113 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; |
113 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 114 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
114 | 115 |
115 // Check middle points. They should be of rect_color. | 116 // Check middle points. They should be of rect_color. |
116 if (!IsOfColor(bitmap, (x + w / 2), y, rect_color)) return false; | 117 if (!IsOfColor(bitmap, (x + w / 2), y, rect_color)) return false; |
117 if (!IsOfColor(bitmap, x, (y + h / 2), rect_color)) return false; | 118 if (!IsOfColor(bitmap, x, (y + h / 2), rect_color)) return false; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 DrawNativeRect(*canvas, 0, 0, 100, 100); | 403 DrawNativeRect(*canvas, 0, 0, 100, 100); |
403 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); | 404 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); |
404 } | 405 } |
405 canvas->restore(); | 406 canvas->restore(); |
406 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, | 407 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, |
407 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); | 408 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); |
408 #endif | 409 #endif |
409 } | 410 } |
410 | 411 |
411 } // namespace skia | 412 } // namespace skia |
OLD | NEW |