| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/barrier_closure.h" | 8 #include "base/barrier_closure.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 462 |
| 463 void ReadbackRequestCallbackTest(base::Closure quit_callback, | 463 void ReadbackRequestCallbackTest(base::Closure quit_callback, |
| 464 const SkBitmap& bitmap, | 464 const SkBitmap& bitmap, |
| 465 ReadbackResponse response) { | 465 ReadbackResponse response) { |
| 466 readback_response_ = response; | 466 readback_response_ = response; |
| 467 if (response != READBACK_SUCCESS) { | 467 if (response != READBACK_SUCCESS) { |
| 468 quit_callback.Run(); | 468 quit_callback.Run(); |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 | 471 |
| 472 SkAutoLockPixels bitmap_lock(bitmap); | |
| 473 | |
| 474 // Check that the |bitmap| contains cyan and/or yellow pixels. This is | 472 // Check that the |bitmap| contains cyan and/or yellow pixels. This is |
| 475 // needed because the compositor will read back "blank" frames until the | 473 // needed because the compositor will read back "blank" frames until the |
| 476 // first frame from the renderer is composited. See comments in | 474 // first frame from the renderer is composited. See comments in |
| 477 // PerformTestWithLeftRightRects() for more details about eliminating test | 475 // PerformTestWithLeftRightRects() for more details about eliminating test |
| 478 // flakiness. | 476 // flakiness. |
| 479 bool contains_a_test_color = false; | 477 bool contains_a_test_color = false; |
| 480 for (int i = 0; i < bitmap.width(); ++i) { | 478 for (int i = 0; i < bitmap.width(); ++i) { |
| 481 for (int j = 0; j < bitmap.height(); ++j) { | 479 for (int j = 0; j < bitmap.height(); ++j) { |
| 482 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) | 480 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) |
| 483 continue; | 481 continue; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 502 quit_callback.Run(); | 500 quit_callback.Run(); |
| 503 return; | 501 return; |
| 504 } | 502 } |
| 505 | 503 |
| 506 // Compare the readback |bitmap| to the |expected_bitmap|, pixel-by-pixel. | 504 // Compare the readback |bitmap| to the |expected_bitmap|, pixel-by-pixel. |
| 507 const SkBitmap& expected_bitmap = | 505 const SkBitmap& expected_bitmap = |
| 508 expected_copy_from_compositing_surface_bitmap_; | 506 expected_copy_from_compositing_surface_bitmap_; |
| 509 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | 507 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); |
| 510 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | 508 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); |
| 511 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType()); | 509 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType()); |
| 512 SkAutoLockPixels expected_bitmap_lock(expected_bitmap); | |
| 513 int fails = 0; | 510 int fails = 0; |
| 514 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { | 511 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { |
| 515 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { | 512 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { |
| 516 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) | 513 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) |
| 517 continue; | 514 continue; |
| 518 | 515 |
| 519 SkColor expected_color = expected_bitmap.getColor(i, j); | 516 SkColor expected_color = expected_bitmap.getColor(i, j); |
| 520 SkColor color = bitmap.getColor(i, j); | 517 SkColor color = bitmap.getColor(i, j); |
| 521 int expected_alpha = SkColorGetA(expected_color); | 518 int expected_alpha = SkColorGetA(expected_color); |
| 522 int alpha = SkColorGetA(color); | 519 int alpha = SkColorGetA(color); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } while (readback_response_ != READBACK_SUCCESS); | 717 } while (readback_response_ != READBACK_SUCCESS); |
| 721 } | 718 } |
| 722 | 719 |
| 723 // Sets up |bitmap| to have size |copy_size|. It floods the left half with | 720 // Sets up |bitmap| to have size |copy_size|. It floods the left half with |
| 724 // #0ff and the right half with #ff0. | 721 // #0ff and the right half with #ff0. |
| 725 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { | 722 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { |
| 726 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); | 723 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); |
| 727 // Left half is #0ff. | 724 // Left half is #0ff. |
| 728 bitmap->eraseARGB(255, 0, 255, 255); | 725 bitmap->eraseARGB(255, 0, 255, 255); |
| 729 // Right half is #ff0. | 726 // Right half is #ff0. |
| 730 { | 727 for (int i = 0; i < copy_size.width() / 2; ++i) { |
| 731 SkAutoLockPixels lock(*bitmap); | 728 for (int j = 0; j < copy_size.height(); ++j) { |
| 732 for (int i = 0; i < copy_size.width() / 2; ++i) { | 729 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) = |
| 733 for (int j = 0; j < copy_size.height(); ++j) { | 730 SkColorSetARGB(255, 255, 255, 0); |
| 734 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) = | |
| 735 SkColorSetARGB(255, 255, 255, 0); | |
| 736 } | |
| 737 } | 731 } |
| 738 } | 732 } |
| 739 } | 733 } |
| 740 | 734 |
| 741 protected: | 735 protected: |
| 742 // Additional ReadbackResponse enum values only used within this test module, | 736 // Additional ReadbackResponse enum values only used within this test module, |
| 743 // to distinguish readback exception cases further. | 737 // to distinguish readback exception cases further. |
| 744 enum ExtraReadbackResponsesForTest { | 738 enum ExtraReadbackResponsesForTest { |
| 745 READBACK_NO_RESPONSE = -1337, | 739 READBACK_NO_RESPONSE = -1337, |
| 746 READBACK_NO_TEST_COLORS, | 740 READBACK_NO_TEST_COLORS, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 kTestCompositingModes); | 1001 kTestCompositingModes); |
| 1008 INSTANTIATE_TEST_CASE_P( | 1002 INSTANTIATE_TEST_CASE_P( |
| 1009 GLAndSoftwareCompositing, | 1003 GLAndSoftwareCompositing, |
| 1010 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 1004 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
| 1011 kTestCompositingModes); | 1005 kTestCompositingModes); |
| 1012 | 1006 |
| 1013 #endif // !defined(OS_ANDROID) | 1007 #endif // !defined(OS_ANDROID) |
| 1014 | 1008 |
| 1015 } // namespace | 1009 } // namespace |
| 1016 } // namespace content | 1010 } // namespace content |
| OLD | NEW |