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 // XXX ADD RASTER PARTIAL TILE TESTS HERE XXX | |
vmpstr
2015/05/15 20:54:21
Is this a TODO or are you going to do this before
danakj
2015/05/15 21:52:14
I'm going to do this before landing.
| |
403 | |
402 class OverlapTest : public ::testing::TestWithParam<float> { | 404 class OverlapTest : public ::testing::TestWithParam<float> { |
403 public: | 405 public: |
404 static float MinContentsScale() { return 1.f / 4.f; } | 406 static float MinContentsScale() { return 1.f / 4.f; } |
405 }; | 407 }; |
406 | 408 |
407 TEST_P(OverlapTest, NoOverlap) { | 409 TEST_P(OverlapTest, NoOverlap) { |
408 gfx::Size tile_size(10, 10); | 410 gfx::Size tile_size(10, 10); |
409 gfx::Size layer_bounds(30, 30); | 411 gfx::Size layer_bounds(30, 30); |
410 gfx::Size bigger_than_layer_bounds(300, 300); | 412 gfx::Size bigger_than_layer_bounds(300, 300); |
411 float contents_scale = GetParam(); | 413 float contents_scale = GetParam(); |
(...skipping 18 matching lines...) Expand all Loading... | |
430 | 432 |
431 scoped_refptr<FakePicturePileImpl> pile = | 433 scoped_refptr<FakePicturePileImpl> pile = |
432 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 434 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
433 gfx::Size content_bounds( | 435 gfx::Size content_bounds( |
434 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 436 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
435 | 437 |
436 SkBitmap bitmap; | 438 SkBitmap bitmap; |
437 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 439 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
438 SkCanvas canvas(bitmap); | 440 SkCanvas canvas(bitmap); |
439 | 441 |
440 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), contents_scale); | 442 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), |
443 gfx::Rect(content_bounds), contents_scale); | |
441 | 444 |
442 for (int y = 0; y < bitmap.height(); y++) { | 445 for (int y = 0; y < bitmap.height(); y++) { |
443 for (int x = 0; x < bitmap.width(); x++) { | 446 for (int x = 0; x < bitmap.width(); x++) { |
444 SkColor color = bitmap.getColor(x, y); | 447 SkColor color = bitmap.getColor(x, y); |
445 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x | 448 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x |
446 << ", y: " << y; | 449 << ", y: " << y; |
447 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x | 450 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x |
448 << ", y: " << y; | 451 << ", y: " << y; |
449 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x | 452 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x |
450 << ", y: " << y; | 453 << ", y: " << y; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 EXPECT_TRUE(iterator); | 543 EXPECT_TRUE(iterator); |
541 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 544 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
542 EXPECT_TRUE(++iterator); | 545 EXPECT_TRUE(++iterator); |
543 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 546 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
544 EXPECT_FALSE(++iterator); | 547 EXPECT_FALSE(++iterator); |
545 } | 548 } |
546 } | 549 } |
547 | 550 |
548 } // namespace | 551 } // namespace |
549 } // namespace cc | 552 } // namespace cc |
OLD | NEW |