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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // Make a layer and fill it completely to make sure that the bounds are 201 // Make a layer and fill it completely to make sure that the bounds are
202 // correct. 202 // correct.
203 { 203 {
204 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 204 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
205 canvas->drawColor(SK_ColorBLACK); 205 canvas->drawColor(SK_ColorBLACK);
206 } 206 }
207 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH)); 207 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH));
208 } 208 }
209 209
210 #if !defined(USE_AURA) // http://crbug.com/154358
211
210 // Test native clipping. 212 // Test native clipping.
211 TEST(PlatformCanvas, ClipRegion) { 213 TEST(PlatformCanvas, ClipRegion) {
212 // Initialize a white canvas 214 // Initialize a white canvas
213 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true)); 215 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true));
214 canvas->drawColor(SK_ColorWHITE); 216 canvas->drawColor(SK_ColorWHITE);
215 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 217 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
216 218
217 // Test that initially the canvas has no clip region, by filling it 219 // Test that initially the canvas has no clip region, by filling it
218 // with a black rectangle. 220 // with a black rectangle.
219 // Note: Don't use LayerSaver, since internally it sets a clip region. 221 // Note: Don't use LayerSaver, since internally it sets a clip region.
220 DrawNativeRect(*canvas, 0, 0, 16, 16); 222 DrawNativeRect(*canvas, 0, 0, 16, 16);
221 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorBLACK)); 223 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorBLACK));
222 224
223 // Test that intersecting disjoint clip rectangles sets an empty clip region 225 // Test that intersecting disjoint clip rectangles sets an empty clip region
224 canvas->drawColor(SK_ColorWHITE); 226 canvas->drawColor(SK_ColorWHITE);
225 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 227 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
226 { 228 {
227 LayerSaver layer(*canvas, 0, 0, 16, 16); 229 LayerSaver layer(*canvas, 0, 0, 16, 16);
228 AddClip(*canvas, 2, 3, 4, 5); 230 AddClip(*canvas, 2, 3, 4, 5);
229 AddClip(*canvas, 4, 9, 10, 10); 231 AddClip(*canvas, 4, 9, 10, 10);
230 DrawNativeRect(*canvas, 0, 0, 16, 16); 232 DrawNativeRect(*canvas, 0, 0, 16, 16);
231 } 233 }
232 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE)); 234 EXPECT_TRUE(VerifyCanvasColor(*canvas, SK_ColorWHITE));
233 } 235 }
234 236
237 #endif // !defined(USE_AURA)
238
235 // Test the layers get filled properly by native rendering. 239 // Test the layers get filled properly by native rendering.
236 TEST(PlatformCanvas, FillLayer) { 240 TEST(PlatformCanvas, FillLayer) {
237 // Create the canvas initialized to opaque white. 241 // Create the canvas initialized to opaque white.
238 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true)); 242 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true));
239 243
240 // 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
241 // correct. 245 // correct.
242 canvas->drawColor(SK_ColorWHITE); 246 canvas->drawColor(SK_ColorWHITE);
243 { 247 {
244 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 248 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 286 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
283 DrawNativeRect(*canvas, 0, 0, 100, 100); 287 DrawNativeRect(*canvas, 0, 0, 100, 100);
284 #if defined(OS_WIN) 288 #if defined(OS_WIN)
285 MakeOpaque(canvas.get(), 0, 0, 100, 100); 289 MakeOpaque(canvas.get(), 0, 0, 100, 100);
286 #endif 290 #endif
287 } 291 }
288 canvas->restore(); 292 canvas->restore();
289 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH)); 293 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
290 } 294 }
291 295
296 #if !defined(USE_AURA) // http://crbug.com/154358
297
292 // Test that translation + make layer works properly. 298 // Test that translation + make layer works properly.
293 TEST(PlatformCanvas, TranslateLayer) { 299 TEST(PlatformCanvas, TranslateLayer) {
294 // Create the canvas initialized to opaque white. 300 // Create the canvas initialized to opaque white.
295 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true)); 301 RefPtr<SkCanvas> canvas = AdoptRef(CreatePlatformCanvas(16, 16, true));
296 302
297 // Make a layer and fill it completely to make sure that the bounds are 303 // Make a layer and fill it completely to make sure that the bounds are
298 // correct. 304 // correct.
299 canvas->drawColor(SK_ColorWHITE); 305 canvas->drawColor(SK_ColorWHITE);
300 canvas->save(); 306 canvas->save();
301 canvas->translate(1, 1); 307 canvas->translate(1, 1);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 #if defined(OS_WIN) 388 #if defined(OS_WIN)
383 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); 389 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH);
384 #endif 390 #endif
385 } 391 }
386 canvas->restore(); 392 canvas->restore();
387 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, 393 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK,
388 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); 394 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH));
389 #endif 395 #endif
390 } 396 }
391 397
398 #endif // #if !defined(USE_AURA)
399
392 TEST(PlatformBitmapTest, PlatformBitmap) { 400 TEST(PlatformBitmapTest, PlatformBitmap) {
393 const int kWidth = 400; 401 const int kWidth = 400;
394 const int kHeight = 300; 402 const int kHeight = 300;
395 scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap); 403 scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap);
396 404
397 EXPECT_TRUE(0 == platform_bitmap->GetSurface()); 405 EXPECT_TRUE(0 == platform_bitmap->GetSurface());
398 EXPECT_TRUE(platform_bitmap->GetBitmap().empty()); 406 EXPECT_TRUE(platform_bitmap->GetBitmap().empty());
399 EXPECT_TRUE(platform_bitmap->GetBitmap().isNull()); 407 EXPECT_TRUE(platform_bitmap->GetBitmap().isNull());
400 408
401 EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false)); 409 EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 450
443 sk_bitmap.lockPixels(); 451 sk_bitmap.lockPixels();
444 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); 452 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
445 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); 453 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
446 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); 454 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
447 sk_bitmap.unlockPixels(); 455 sk_bitmap.unlockPixels();
448 } 456 }
449 457
450 458
451 } // namespace skia 459 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698