OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "cc/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
7 #include "cc/test/skia_common.h" | 7 #include "cc/test/skia_common.h" |
8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkPixelRef.h" | 10 #include "third_party/skia/include/core/SkPixelRef.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // up to one pixel outside the content rect is guaranteed to be opaque. | 338 // up to one pixel outside the content rect is guaranteed to be opaque. |
339 // Outside of that is undefined. | 339 // Outside of that is undefined. |
340 gfx::Rect canvas_rect(content_rect); | 340 gfx::Rect canvas_rect(content_rect); |
341 canvas_rect.Inset(0, 0, -1, -1); | 341 canvas_rect.Inset(0, 0, -1, -1); |
342 | 342 |
343 SkBitmap bitmap; | 343 SkBitmap bitmap; |
344 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 344 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
345 SkCanvas canvas(bitmap); | 345 SkCanvas canvas(bitmap); |
346 canvas.clear(SK_ColorTRANSPARENT); | 346 canvas.clear(SK_ColorTRANSPARENT); |
347 | 347 |
348 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale); | 348 pile->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); |
349 | 349 |
350 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 350 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
351 int num_pixels = bitmap.width() * bitmap.height(); | 351 int num_pixels = bitmap.width() * bitmap.height(); |
352 bool all_white = true; | 352 bool all_white = true; |
353 for (int i = 0; i < num_pixels; ++i) { | 353 for (int i = 0; i < num_pixels; ++i) { |
354 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); | 354 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); |
355 all_white &= (SkColorGetR(pixels[i]) == 255); | 355 all_white &= (SkColorGetR(pixels[i]) == 255); |
356 all_white &= (SkColorGetG(pixels[i]) == 255); | 356 all_white &= (SkColorGetG(pixels[i]) == 255); |
357 all_white &= (SkColorGetB(pixels[i]) == 255); | 357 all_white &= (SkColorGetB(pixels[i]) == 255); |
358 } | 358 } |
(...skipping 24 matching lines...) Expand all Loading... |
383 gfx::Size content_bounds( | 383 gfx::Size content_bounds( |
384 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 384 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
385 | 385 |
386 gfx::Rect canvas_rect(content_bounds); | 386 gfx::Rect canvas_rect(content_bounds); |
387 canvas_rect.Inset(0, 0, -1, -1); | 387 canvas_rect.Inset(0, 0, -1, -1); |
388 | 388 |
389 SkBitmap bitmap; | 389 SkBitmap bitmap; |
390 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 390 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
391 SkCanvas canvas(bitmap); | 391 SkCanvas canvas(bitmap); |
392 | 392 |
393 pile->PlaybackToCanvas(&canvas, canvas_rect, contents_scale); | 393 pile->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); |
394 | 394 |
395 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 395 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
396 int num_pixels = bitmap.width() * bitmap.height(); | 396 int num_pixels = bitmap.width() * bitmap.height(); |
397 for (int i = 0; i < num_pixels; ++i) { | 397 for (int i = 0; i < num_pixels; ++i) { |
398 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 398 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 class OverlapTest : public ::testing::TestWithParam<float> { | 402 class OverlapTest : public ::testing::TestWithParam<float> { |
403 public: | 403 public: |
(...skipping 26 matching lines...) Expand all Loading... |
430 | 430 |
431 scoped_refptr<FakePicturePileImpl> pile = | 431 scoped_refptr<FakePicturePileImpl> pile = |
432 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 432 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
433 gfx::Size content_bounds( | 433 gfx::Size content_bounds( |
434 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 434 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
435 | 435 |
436 SkBitmap bitmap; | 436 SkBitmap bitmap; |
437 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 437 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
438 SkCanvas canvas(bitmap); | 438 SkCanvas canvas(bitmap); |
439 | 439 |
440 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), contents_scale); | 440 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), |
| 441 gfx::Rect(content_bounds), contents_scale); |
441 | 442 |
442 for (int y = 0; y < bitmap.height(); y++) { | 443 for (int y = 0; y < bitmap.height(); y++) { |
443 for (int x = 0; x < bitmap.width(); x++) { | 444 for (int x = 0; x < bitmap.width(); x++) { |
444 SkColor color = bitmap.getColor(x, y); | 445 SkColor color = bitmap.getColor(x, y); |
445 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x | 446 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x |
446 << ", y: " << y; | 447 << ", y: " << y; |
447 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x | 448 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x |
448 << ", y: " << y; | 449 << ", y: " << y; |
449 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x | 450 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x |
450 << ", y: " << y; | 451 << ", y: " << y; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 EXPECT_TRUE(iterator); | 541 EXPECT_TRUE(iterator); |
541 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 542 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
542 EXPECT_TRUE(++iterator); | 543 EXPECT_TRUE(++iterator); |
543 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 544 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
544 EXPECT_FALSE(++iterator); | 545 EXPECT_FALSE(++iterator); |
545 } | 546 } |
546 } | 547 } |
547 | 548 |
548 } // namespace | 549 } // namespace |
549 } // namespace cc | 550 } // namespace cc |
OLD | NEW |