| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 391 |
| 392 void ReadbackRequestCallbackTest(base::Closure quit_callback, | 392 void ReadbackRequestCallbackTest(base::Closure quit_callback, |
| 393 const SkBitmap& bitmap, | 393 const SkBitmap& bitmap, |
| 394 ReadbackResponse response) { | 394 ReadbackResponse response) { |
| 395 readback_response_ = response; | 395 readback_response_ = response; |
| 396 if (response != READBACK_SUCCESS) { | 396 if (response != READBACK_SUCCESS) { |
| 397 quit_callback.Run(); | 397 quit_callback.Run(); |
| 398 return; | 398 return; |
| 399 } | 399 } |
| 400 | 400 |
| 401 SkAutoLockPixels bitmap_lock(bitmap); | |
| 402 | |
| 403 // Check that the |bitmap| contains cyan and/or yellow pixels. This is | 401 // Check that the |bitmap| contains cyan and/or yellow pixels. This is |
| 404 // needed because the compositor will read back "blank" frames until the | 402 // needed because the compositor will read back "blank" frames until the |
| 405 // first frame from the renderer is composited. See comments in | 403 // first frame from the renderer is composited. See comments in |
| 406 // PerformTestWithLeftRightRects() for more details about eliminating test | 404 // PerformTestWithLeftRightRects() for more details about eliminating test |
| 407 // flakiness. | 405 // flakiness. |
| 408 bool contains_a_test_color = false; | 406 bool contains_a_test_color = false; |
| 409 for (int i = 0; i < bitmap.width(); ++i) { | 407 for (int i = 0; i < bitmap.width(); ++i) { |
| 410 for (int j = 0; j < bitmap.height(); ++j) { | 408 for (int j = 0; j < bitmap.height(); ++j) { |
| 411 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) | 409 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) |
| 412 continue; | 410 continue; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 431 quit_callback.Run(); | 429 quit_callback.Run(); |
| 432 return; | 430 return; |
| 433 } | 431 } |
| 434 | 432 |
| 435 // Compare the readback |bitmap| to the |expected_bitmap|, pixel-by-pixel. | 433 // Compare the readback |bitmap| to the |expected_bitmap|, pixel-by-pixel. |
| 436 const SkBitmap& expected_bitmap = | 434 const SkBitmap& expected_bitmap = |
| 437 expected_copy_from_compositing_surface_bitmap_; | 435 expected_copy_from_compositing_surface_bitmap_; |
| 438 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | 436 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); |
| 439 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | 437 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); |
| 440 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType()); | 438 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType()); |
| 441 SkAutoLockPixels expected_bitmap_lock(expected_bitmap); | |
| 442 int fails = 0; | 439 int fails = 0; |
| 443 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { | 440 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { |
| 444 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { | 441 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { |
| 445 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) | 442 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) |
| 446 continue; | 443 continue; |
| 447 | 444 |
| 448 SkColor expected_color = expected_bitmap.getColor(i, j); | 445 SkColor expected_color = expected_bitmap.getColor(i, j); |
| 449 SkColor color = bitmap.getColor(i, j); | 446 SkColor color = bitmap.getColor(i, j); |
| 450 int expected_alpha = SkColorGetA(expected_color); | 447 int expected_alpha = SkColorGetA(expected_color); |
| 451 int alpha = SkColorGetA(color); | 448 int alpha = SkColorGetA(color); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } while (readback_response_ != READBACK_SUCCESS); | 646 } while (readback_response_ != READBACK_SUCCESS); |
| 650 } | 647 } |
| 651 | 648 |
| 652 // Sets up |bitmap| to have size |copy_size|. It floods the left half with | 649 // Sets up |bitmap| to have size |copy_size|. It floods the left half with |
| 653 // #0ff and the right half with #ff0. | 650 // #0ff and the right half with #ff0. |
| 654 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { | 651 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { |
| 655 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); | 652 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); |
| 656 // Left half is #0ff. | 653 // Left half is #0ff. |
| 657 bitmap->eraseARGB(255, 0, 255, 255); | 654 bitmap->eraseARGB(255, 0, 255, 255); |
| 658 // Right half is #ff0. | 655 // Right half is #ff0. |
| 659 { | 656 for (int i = 0; i < copy_size.width() / 2; ++i) { |
| 660 SkAutoLockPixels lock(*bitmap); | 657 for (int j = 0; j < copy_size.height(); ++j) { |
| 661 for (int i = 0; i < copy_size.width() / 2; ++i) { | 658 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) = |
| 662 for (int j = 0; j < copy_size.height(); ++j) { | 659 SkColorSetARGB(255, 255, 255, 0); |
| 663 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) = | |
| 664 SkColorSetARGB(255, 255, 255, 0); | |
| 665 } | |
| 666 } | 660 } |
| 667 } | 661 } |
| 668 } | 662 } |
| 669 | 663 |
| 670 protected: | 664 protected: |
| 671 // Additional ReadbackResponse enum values only used within this test module, | 665 // Additional ReadbackResponse enum values only used within this test module, |
| 672 // to distinguish readback exception cases further. | 666 // to distinguish readback exception cases further. |
| 673 enum ExtraReadbackResponsesForTest { | 667 enum ExtraReadbackResponsesForTest { |
| 674 READBACK_NO_RESPONSE = -1337, | 668 READBACK_NO_RESPONSE = -1337, |
| 675 READBACK_NO_TEST_COLORS, | 669 READBACK_NO_TEST_COLORS, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 kTestCompositingModes); | 930 kTestCompositingModes); |
| 937 INSTANTIATE_TEST_CASE_P( | 931 INSTANTIATE_TEST_CASE_P( |
| 938 GLAndSoftwareCompositing, | 932 GLAndSoftwareCompositing, |
| 939 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 933 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
| 940 kTestCompositingModes); | 934 kTestCompositingModes); |
| 941 | 935 |
| 942 #endif // !defined(OS_ANDROID) | 936 #endif // !defined(OS_ANDROID) |
| 943 | 937 |
| 944 } // namespace | 938 } // namespace |
| 945 } // namespace content | 939 } // namespace content |
| OLD | NEW |