Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: skia/ext/platform_canvas_unittest.cc

Issue 1255073002: clang/win: Fix most -Wunused-function warnings in Chromium code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } else { 56 } else {
57 // Outside the square should be canvas_color 57 // Outside the square should be canvas_color
58 if (!IsOfColor(bitmap, cur_x, cur_y, canvas_color)) 58 if (!IsOfColor(bitmap, cur_x, cur_y, canvas_color))
59 return false; 59 return false;
60 } 60 }
61 } 61 }
62 } 62 }
63 return true; 63 return true;
64 } 64 }
65 65
66 #if !defined(OS_MACOSX) 66 #if !defined(USE_AURA) && !defined(OS_MACOSX)
67 // Return true if canvas has something that passes for a rounded-corner 67 // 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 68 // 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. 69 // middle are of rect_color and pixels in the corners are of canvas_color.
70 bool VerifyRoundedRect(const PlatformCanvas& canvas, 70 bool VerifyRoundedRect(const PlatformCanvas& canvas,
71 uint32_t canvas_color, 71 uint32_t canvas_color,
72 uint32_t rect_color, 72 uint32_t rect_color,
73 int x, 73 int x,
74 int y, 74 int y,
75 int w, 75 int w,
76 int h) { 76 int h) {
(...skipping 16 matching lines...) Expand all
93 return true; 93 return true;
94 } 94 }
95 #endif 95 #endif
96 96
97 // Checks whether there is a white canvas with a black square at the given 97 // Checks whether there is a white canvas with a black square at the given
98 // location in pixels (not in the canvas coordinate system). 98 // location in pixels (not in the canvas coordinate system).
99 bool VerifyBlackRect(const PlatformCanvas& canvas, int x, int y, int w, int h) { 99 bool VerifyBlackRect(const PlatformCanvas& canvas, int x, int y, int w, int h) {
100 return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h); 100 return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h);
101 } 101 }
102 102
103 #if !defined(USE_AURA) // http://crbug.com/154358
103 // Check that every pixel in the canvas is a single color. 104 // Check that every pixel in the canvas is a single color.
104 bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) { 105 bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) {
105 return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0); 106 return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0);
106 } 107 }
108 #endif // !defined(USE_AURA)
107 109
108 #if defined(OS_WIN) 110 #if defined(OS_WIN)
109 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { 111 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
110 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 112 skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
111 HDC dc = scoped_platform_paint.GetPlatformSurface(); 113 HDC dc = scoped_platform_paint.GetPlatformSurface();
112 114
113 RECT inner_rc; 115 RECT inner_rc;
114 inner_rc.left = x; 116 inner_rc.left = x;
115 inner_rc.top = y; 117 inner_rc.top = y;
116 inner_rc.right = x + w; 118 inner_rc.right = x + w;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Make a layer and fill it completely to make sure that the bounds are 203 // Make a layer and fill it completely to make sure that the bounds are
202 // correct. 204 // correct.
203 { 205 {
204 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 206 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
205 canvas->drawColor(SK_ColorBLACK); 207 canvas->drawColor(SK_ColorBLACK);
206 } 208 }
207 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH)); 209 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH));
208 } 210 }
209 211
210 #if !defined(USE_AURA) // http://crbug.com/154358 212 #if !defined(USE_AURA) // http://crbug.com/154358
211
212 // Test native clipping. 213 // Test native clipping.
213 TEST(PlatformCanvas, ClipRegion) { 214 TEST(PlatformCanvas, ClipRegion) {
214 // Initialize a white canvas 215 // Initialize a white canvas
215 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true)); 216 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true));
216 canvas->drawColor(SK_ColorWHITE); 217 canvas->drawColor(SK_ColorWHITE);
217 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 218 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
218 219
219 // Test that initially the canvas has no clip region, by filling it 220 // Test that initially the canvas has no clip region, by filling it
220 // with a black rectangle. 221 // with a black rectangle.
221 // Note: Don't use LayerSaver, since internally it sets a clip region. 222 // Note: Don't use LayerSaver, since internally it sets a clip region.
222 DrawNativeRect(*canvas, 0, 0, 16, 16); 223 DrawNativeRect(*canvas, 0, 0, 16, 16);
223 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorBLACK)); 224 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorBLACK));
224 225
225 // Test that intersecting disjoint clip rectangles sets an empty clip region 226 // Test that intersecting disjoint clip rectangles sets an empty clip region
226 canvas->drawColor(SK_ColorWHITE); 227 canvas->drawColor(SK_ColorWHITE);
227 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 228 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
228 { 229 {
229 LayerSaver layer(*canvas, 0, 0, 16, 16); 230 LayerSaver layer(*canvas, 0, 0, 16, 16);
230 AddClip(*canvas, 2, 3, 4, 5); 231 AddClip(*canvas, 2, 3, 4, 5);
231 AddClip(*canvas, 4, 9, 10, 10); 232 AddClip(*canvas, 4, 9, 10, 10);
232 DrawNativeRect(*canvas, 0, 0, 16, 16); 233 DrawNativeRect(*canvas, 0, 0, 16, 16);
233 } 234 }
234 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 235 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
235 } 236 }
236
237 #endif // !defined(USE_AURA) 237 #endif // !defined(USE_AURA)
238 238
239 // Test the layers get filled properly by native rendering. 239 // Test the layers get filled properly by native rendering.
240 TEST(PlatformCanvas, FillLayer) { 240 TEST(PlatformCanvas, FillLayer) {
241 // Create the canvas initialized to opaque white. 241 // Create the canvas initialized to opaque white.
242 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true)); 242 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true));
243 243
244 // Make a layer and fill it completely to make sure that the bounds are 244 // Make a layer and fill it completely to make sure that the bounds are
245 // correct. 245 // correct.
246 canvas->drawColor(SK_ColorWHITE); 246 canvas->drawColor(SK_ColorWHITE);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 sk_bitmap.lockPixels(); 453 sk_bitmap.lockPixels();
454 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); 454 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
455 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); 455 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
456 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); 456 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
457 sk_bitmap.unlockPixels(); 457 sk_bitmap.unlockPixels();
458 } 458 }
459 459
460 460
461 } // namespace skia 461 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698