Chromium Code Reviews| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 #if !defined(USE_AURA) && !defined(OS_MACOSX) | 82 #if !defined(USE_AURA) && !defined(OS_MACOSX) |
| 83 // Return true if canvas has something that passes for a rounded-corner | 83 // Return true if canvas has something that passes for a rounded-corner |
| 84 // rectangle. Basically, we're just checking to make sure that the pixels in the | 84 // rectangle. Basically, we're just checking to make sure that the pixels in the |
| 85 // middle are of rect_color and pixels in the corners are of canvas_color. | 85 // middle are of rect_color and pixels in the corners are of canvas_color. |
| 86 bool VerifyRoundedRect(const SkCanvas& canvas, | 86 bool VerifyRoundedRect(const SkCanvas& canvas, |
| 87 SkBaseDevice* device, | |
|
f(malita)
2016/08/30 17:41:23
Nit: since device is always derived from canvas, i
tomhudson
2016/08/30 17:48:48
D'oh, yes.
| |
| 87 uint32_t canvas_color, | 88 uint32_t canvas_color, |
| 88 uint32_t rect_color, | 89 uint32_t rect_color, |
| 89 int x, | 90 int x, |
| 90 int y, | 91 int y, |
| 91 int w, | 92 int w, |
| 92 int h) { | 93 int h) { |
| 93 SkBaseDevice* device = skia::GetTopDevice(canvas); | |
| 94 const SkBitmap& bitmap = device->accessBitmap(false); | 94 const SkBitmap& bitmap = device->accessBitmap(false); |
| 95 SkAutoLockPixels lock(bitmap); | 95 SkAutoLockPixels lock(bitmap); |
| 96 | 96 |
| 97 // Check corner points first. They should be of canvas_color. | 97 // Check corner points first. They should be of canvas_color. |
| 98 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; | 98 if (!IsOfColor(bitmap, x, y, canvas_color)) return false; |
| 99 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 99 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
| 100 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; | 100 if (!IsOfColor(bitmap, x, y + h, canvas_color)) return false; |
| 101 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; | 101 if (!IsOfColor(bitmap, x + w, y, canvas_color)) return false; |
| 102 | 102 |
| 103 // Check middle points. They should be of rect_color. | 103 // Check middle points. They should be of rect_color. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 const SkScalar kRadius = 2.0; | 399 const SkScalar kRadius = 2.0; |
| 400 path.addRoundRect(rect, kRadius, kRadius); | 400 path.addRoundRect(rect, kRadius, kRadius); |
| 401 canvas->clipPath(path); | 401 canvas->clipPath(path); |
| 402 | 402 |
| 403 DrawNativeRect(*canvas, 0, 0, 100, 100); | 403 DrawNativeRect(*canvas, 0, 0, 100, 100); |
| 404 #if defined(OS_WIN) | 404 #if defined(OS_WIN) |
| 405 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); | 405 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); |
| 406 #endif | 406 #endif |
| 407 } | 407 } |
| 408 canvas->restore(); | 408 canvas->restore(); |
| 409 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, | 409 EXPECT_TRUE(VerifyRoundedRect(*canvas, canvas->getTopDevice(true), |
| 410 SK_ColorWHITE, SK_ColorBLACK, | |
| 410 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); | 411 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); |
| 411 #endif | 412 #endif |
| 412 } | 413 } |
| 413 | 414 |
| 414 #endif // #if !defined(USE_AURA) | 415 #endif // #if !defined(USE_AURA) |
| 415 | 416 |
| 416 } // namespace skia | 417 } // namespace skia |
| OLD | NEW |