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 SkBitmap bitmap; |
106 const SkBitmap& bitmap = device->accessBitmap(false); | 106 bitmap.allocN32Pixels(w, h); |
107 SkAutoLockPixels lock(bitmap); | 107 if (!canvas.readPixels(&bitmap, x, y)) { |
f(malita)
2016/09/17 14:21:22
nit: can readPixels ever fail for this unit test?
reed1
2016/09/19 00:11:52
This is a general pixel checker. I'm not sure that
| |
108 return false; | |
109 } | |
108 | 110 |
109 // Check corner points first. They should be of canvas_color. | 111 // Check corner points first. They should be of canvas_color. |
110 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; | 112 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; |
f(malita)
2016/09/17 14:21:22
Previously we were reading the full backing store,
reed1
2016/09/19 00:11:52
Good point about needing the entire canvas read. W
| |
111 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 113 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
112 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; | 114 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; |
113 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 115 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
114 | 116 |
115 // Check middle points. They should be of rect_color. | 117 // Check middle points. They should be of rect_color. |
116 if (!IsOfColor(bitmap, (x + w / 2), y, rect_color)) return false; | 118 if (!IsOfColor(bitmap, (x + w / 2), y, rect_color)) return false; |
117 if (!IsOfColor(bitmap, x, (y + h / 2), rect_color)) return false; | 119 if (!IsOfColor(bitmap, x, (y + h / 2), rect_color)) return false; |
118 if (!IsOfColor(bitmap, x + w, (y + h / 2), rect_color)) return false; | 120 if (!IsOfColor(bitmap, x + w, (y + h / 2), rect_color)) return false; |
119 if (!IsOfColor(bitmap, (x + w / 2), y + h, rect_color)) return false; | 121 if (!IsOfColor(bitmap, (x + w / 2), y + h, rect_color)) return false; |
120 | 122 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 DrawNativeRect(*canvas, 0, 0, 100, 100); | 404 DrawNativeRect(*canvas, 0, 0, 100, 100); |
403 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); | 405 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); |
404 } | 406 } |
405 canvas->restore(); | 407 canvas->restore(); |
406 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, | 408 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, |
407 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); | 409 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); |
408 #endif | 410 #endif |
409 } | 411 } |
410 | 412 |
411 } // namespace skia | 413 } // namespace skia |
OLD | NEW |