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

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

Issue 2340823002: Turn on more of the platform_canvas_unittests (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 20 matching lines...) Expand all
31 #include <cairo.h> 31 #include <cairo.h>
32 #else 32 #else
33 #include <cairo/cairo.h> 33 #include <cairo/cairo.h>
34 #endif // OS_OPENBSD 34 #endif // OS_OPENBSD
35 #endif // USE_CAIRO 35 #endif // USE_CAIRO
36 36
37 namespace skia { 37 namespace skia {
38 38
39 namespace { 39 namespace {
40 40
41 #if defined(OS_WIN) 41 // Uses DstATop transfer mode with SK_ColorBLACK 0xff000000:
42 // the destination pixel will end up with 0xff alpha
43 // if it was transparent black (0x0) before the blend,
44 // it will be set to opaque black (0xff000000).
45 // if it has nonzero alpha before the blend,
46 // it will retain its color.
42 void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) { 47 void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) {
43 if (width <= 0 || height <= 0) 48 if (width <= 0 || height <= 0)
44 return; 49 return;
45 50
46 SkRect rect; 51 SkRect rect;
47 rect.setXYWH(SkIntToScalar(x), SkIntToScalar(y), 52 rect.setXYWH(SkIntToScalar(x), SkIntToScalar(y),
48 SkIntToScalar(width), SkIntToScalar(height)); 53 SkIntToScalar(width), SkIntToScalar(height));
49 SkPaint paint; 54 SkPaint paint;
50 paint.setColor(SK_ColorBLACK); 55 paint.setColor(SK_ColorBLACK);
51 paint.setXfermodeMode(SkXfermode::kDstATop_Mode); 56 paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
52 canvas->drawRect(rect, paint); 57 canvas->drawRect(rect, paint);
53 } 58 }
54 #endif
55 59
56 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { 60 bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) {
57 // For masking out the alpha values. 61 // For masking out the alpha values.
58 static uint32_t alpha_mask = 62 static uint32_t alpha_mask =
59 static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; 63 static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT;
60 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); 64 return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask);
61 } 65 }
62 66
63 // Return true if the canvas is filled to canvas_color, and contains a single 67 // Return true if the canvas is filled to canvas_color, and contains a single
64 // rectangle filled to rect_color. This function ignores the alpha channel, 68 // rectangle filled to rect_color. This function ignores the alpha channel,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST(PlatformCanvas, FillLayer) { 273 TEST(PlatformCanvas, FillLayer) {
270 // Create the canvas initialized to opaque white. 274 // Create the canvas initialized to opaque white.
271 sk_sp<SkCanvas> canvas(CreatePlatformCanvas(16, 16, true)); 275 sk_sp<SkCanvas> canvas(CreatePlatformCanvas(16, 16, true));
272 276
273 // Make a layer and fill it completely to make sure that the bounds are 277 // Make a layer and fill it completely to make sure that the bounds are
274 // correct. 278 // correct.
275 canvas->drawColor(SK_ColorWHITE); 279 canvas->drawColor(SK_ColorWHITE);
276 { 280 {
277 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 281 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
278 DrawNativeRect(*canvas, 0, 0, 100, 100); 282 DrawNativeRect(*canvas, 0, 0, 100, 100);
279 #if defined(OS_WIN)
280 MakeOpaque(canvas.get(), 0, 0, 100, 100); 283 MakeOpaque(canvas.get(), 0, 0, 100, 100);
281 #endif
282 } 284 }
283 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH)); 285 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX, kLayerY, kLayerW, kLayerH));
284 286
285 // Make a layer and fill it partially to make sure the translation is correct. 287 // Make a layer and fill it partially to make sure the translation is correct.
286 canvas->drawColor(SK_ColorWHITE); 288 canvas->drawColor(SK_ColorWHITE);
287 { 289 {
288 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 290 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
289 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH); 291 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
290 #if defined(OS_WIN)
291 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH); 292 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH);
292 #endif
293 } 293 }
294 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH)); 294 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
295 295
296 // Add a clip on the layer and fill to make sure clip is correct. 296 // Add a clip on the layer and fill to make sure clip is correct.
297 canvas->drawColor(SK_ColorWHITE); 297 canvas->drawColor(SK_ColorWHITE);
298 { 298 {
299 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 299 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
300 canvas->save(); 300 canvas->save();
301 AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH); 301 AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
302 DrawNativeRect(*canvas, 0, 0, 100, 100); 302 DrawNativeRect(*canvas, 0, 0, 100, 100);
303 #if defined(OS_WIN)
304 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH); 303 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH);
305 #endif
306 canvas->restore(); 304 canvas->restore();
307 } 305 }
308 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH)); 306 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
309 307
310 // Add a clip and then make the layer to make sure the clip is correct. 308 // Add a clip and then make the layer to make sure the clip is correct.
311 canvas->drawColor(SK_ColorWHITE); 309 canvas->drawColor(SK_ColorWHITE);
312 canvas->save(); 310 canvas->save();
313 AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH); 311 AddClip(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
314 { 312 {
315 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 313 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
316 DrawNativeRect(*canvas, 0, 0, 100, 100); 314 DrawNativeRect(*canvas, 0, 0, 100, 100);
317 #if defined(OS_WIN)
318 MakeOpaque(canvas.get(), 0, 0, 100, 100); 315 MakeOpaque(canvas.get(), 0, 0, 100, 100);
319 #endif
320 } 316 }
321 canvas->restore(); 317 canvas->restore();
322 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH)); 318 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH));
323 } 319 }
324 320
325 #if !defined(USE_AURA) // http://crbug.com/154358
326
327 // Test that translation + make layer works properly. 321 // Test that translation + make layer works properly.
328 TEST(PlatformCanvas, TranslateLayer) { 322 TEST(PlatformCanvas, TranslateLayer) {
329 // Create the canvas initialized to opaque white. 323 // Create the canvas initialized to opaque white.
330 sk_sp<SkCanvas> canvas(CreatePlatformCanvas(16, 16, true)); 324 sk_sp<SkCanvas> canvas(CreatePlatformCanvas(16, 16, true));
331 325
332 // Make a layer and fill it completely to make sure that the bounds are 326 // Make a layer and fill it completely to make sure that the bounds are
333 // correct. 327 // correct.
334 canvas->drawColor(SK_ColorWHITE); 328 canvas->drawColor(SK_ColorWHITE);
335 canvas->save(); 329 canvas->save();
336 canvas->translate(1, 1); 330 canvas->translate(1, 1);
337 { 331 {
338 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 332 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
339 DrawNativeRect(*canvas, 0, 0, 100, 100); 333 DrawNativeRect(*canvas, 0, 0, 100, 100);
340 #if defined(OS_WIN)
341 MakeOpaque(canvas.get(), 0, 0, 100, 100); 334 MakeOpaque(canvas.get(), 0, 0, 100, 100);
342 #endif
343 } 335 }
344 canvas->restore(); 336 canvas->restore();
345 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX + 1, kLayerY + 1, 337 EXPECT_TRUE(VerifyBlackRect(*canvas, kLayerX + 1, kLayerY + 1,
346 kLayerW, kLayerH)); 338 kLayerW, kLayerH));
347 339
348 // Translate then make the layer. 340 // Translate then make the layer.
349 canvas->drawColor(SK_ColorWHITE); 341 canvas->drawColor(SK_ColorWHITE);
350 canvas->save(); 342 canvas->save();
351 canvas->translate(1, 1); 343 canvas->translate(1, 1);
352 { 344 {
353 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 345 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
354 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH); 346 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
355 #if defined(OS_WIN)
356 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH); 347 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH);
357 #endif
358 } 348 }
359 canvas->restore(); 349 canvas->restore();
360 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1, 350 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1,
361 kInnerW, kInnerH)); 351 kInnerW, kInnerH));
362 352
363 // Make the layer then translate. 353 // Make the layer then translate.
364 canvas->drawColor(SK_ColorWHITE); 354 canvas->drawColor(SK_ColorWHITE);
365 canvas->save(); 355 canvas->save();
366 { 356 {
367 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 357 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
368 canvas->translate(1, 1); 358 canvas->translate(1, 1);
369 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH); 359 DrawNativeRect(*canvas, kInnerX, kInnerY, kInnerW, kInnerH);
370 #if defined(OS_WIN)
371 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH); 360 MakeOpaque(canvas.get(), kInnerX, kInnerY, kInnerW, kInnerH);
372 #endif
373 } 361 }
374 canvas->restore(); 362 canvas->restore();
375 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1, 363 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 1, kInnerY + 1,
376 kInnerW, kInnerH)); 364 kInnerW, kInnerH));
377 365
378 // Translate both before and after, and have a clip. 366 // Translate both before and after, and have a clip.
379 canvas->drawColor(SK_ColorWHITE); 367 canvas->drawColor(SK_ColorWHITE);
380 canvas->save(); 368 canvas->save();
381 canvas->translate(1, 1); 369 canvas->translate(1, 1);
382 { 370 {
383 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 371 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
384 canvas->drawColor(SK_ColorWHITE); 372 canvas->drawColor(SK_ColorWHITE);
385 canvas->translate(1, 1); 373 canvas->translate(1, 1);
386 AddClip(*canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1); 374 AddClip(*canvas, kInnerX + 1, kInnerY + 1, kInnerW - 1, kInnerH - 1);
387 DrawNativeRect(*canvas, 0, 0, 100, 100); 375 DrawNativeRect(*canvas, 0, 0, 100, 100);
388 #if defined(OS_WIN)
389 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); 376 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH);
390 #endif
391 } 377 }
392 canvas->restore(); 378 canvas->restore();
393 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 3, kInnerY + 3, 379 EXPECT_TRUE(VerifyBlackRect(*canvas, kInnerX + 3, kInnerY + 3,
394 kInnerW - 1, kInnerH - 1)); 380 kInnerW - 1, kInnerH - 1));
395 381
396 // TODO(dglazkov): Figure out why this fails on Mac (antialiased clipping?), 382 // TODO(dglazkov): Figure out why this fails on Mac (antialiased clipping?),
397 // modify test and remove this guard. 383 // modify test and remove this guard.
398 #if !defined(OS_MACOSX) 384 #if !defined(OS_MACOSX) && !defined(USE_AURA)
399 // Translate both before and after, and have a path clip. 385 // Translate both before and after, and have a path clip.
400 canvas->drawColor(SK_ColorWHITE); 386 canvas->drawColor(SK_ColorWHITE);
401 canvas->save(); 387 canvas->save();
402 canvas->translate(1, 1); 388 canvas->translate(1, 1);
403 { 389 {
404 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH); 390 LayerSaver layer(*canvas, kLayerX, kLayerY, kLayerW, kLayerH);
405 canvas->drawColor(SK_ColorWHITE); 391 canvas->drawColor(SK_ColorWHITE);
406 canvas->translate(1, 1); 392 canvas->translate(1, 1);
407 393
408 SkPath path; 394 SkPath path;
409 SkRect rect; 395 SkRect rect;
410 rect.iset(kInnerX - 1, kInnerY - 1, 396 rect.iset(kInnerX - 1, kInnerY - 1,
411 kInnerX + kInnerW, kInnerY + kInnerH); 397 kInnerX + kInnerW, kInnerY + kInnerH);
412 const SkScalar kRadius = 2.0; 398 const SkScalar kRadius = 2.0;
413 path.addRoundRect(rect, kRadius, kRadius); 399 path.addRoundRect(rect, kRadius, kRadius);
414 canvas->clipPath(path); 400 canvas->clipPath(path);
415 401
416 DrawNativeRect(*canvas, 0, 0, 100, 100); 402 DrawNativeRect(*canvas, 0, 0, 100, 100);
417 #if defined(OS_WIN)
418 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH); 403 MakeOpaque(canvas.get(), kLayerX, kLayerY, kLayerW, kLayerH);
419 #endif
420 } 404 }
421 canvas->restore(); 405 canvas->restore();
422 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, 406 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK,
423 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); 407 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH));
424 #endif 408 #endif
425 } 409 }
426 410
427 #endif // #if !defined(USE_AURA)
428
429 } // namespace skia 411 } // namespace skia
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698