| OLD | NEW |
| 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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 16 #include "cc/output/delegated_frame_data.h" | 16 #include "cc/output/delegated_frame_data.h" |
| 17 #include "cc/test/pixel_test_utils.h" | 17 #include "cc/test/pixel_test_utils.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/compositor/compositor_observer.h" | 19 #include "ui/compositor/compositor_observer.h" |
| 20 #include "ui/compositor/compositor_setup.h" | |
| 21 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_animation_sequence.h" | 21 #include "ui/compositor/layer_animation_sequence.h" |
| 23 #include "ui/compositor/layer_animator.h" | 22 #include "ui/compositor/layer_animator.h" |
| 24 #include "ui/compositor/test/test_compositor_host.h" | 23 #include "ui/compositor/test/test_compositor_host.h" |
| 25 #include "ui/compositor/test/test_layers.h" | 24 #include "ui/compositor/test/test_layers.h" |
| 26 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
| 28 #include "ui/gfx/gfx_paths.h" | 27 #include "ui/gfx/gfx_paths.h" |
| 29 #include "ui/gfx/skia_util.h" | 28 #include "ui/gfx/skia_util.h" |
| 30 | 29 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { | 74 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { |
| 76 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); | 75 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); |
| 77 } else { | 76 } else { |
| 78 LOG(ERROR) << "Could not open test data directory."; | 77 LOG(ERROR) << "Could not open test data directory."; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 virtual ~LayerWithRealCompositorTest() {} | 80 virtual ~LayerWithRealCompositorTest() {} |
| 82 | 81 |
| 83 // Overridden from testing::Test: | 82 // Overridden from testing::Test: |
| 84 virtual void SetUp() OVERRIDE { | 83 virtual void SetUp() OVERRIDE { |
| 85 DisableTestCompositor(); | 84 bool allow_test_contexts = false; |
| 85 Compositor::InitializeContextFactoryForTests(allow_test_contexts); |
| 86 Compositor::Initialize(); |
| 87 |
| 86 const gfx::Rect host_bounds(10, 10, 500, 500); | 88 const gfx::Rect host_bounds(10, 10, 500, 500); |
| 87 window_.reset(TestCompositorHost::Create(host_bounds)); | 89 window_.reset(TestCompositorHost::Create(host_bounds)); |
| 88 window_->Show(); | 90 window_->Show(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() OVERRIDE { |
| 94 window_.reset(); |
| 95 Compositor::Terminate(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 Compositor* GetCompositor() { | 98 Compositor* GetCompositor() { |
| 95 return window_->GetCompositor(); | 99 return window_->GetCompositor(); |
| 96 } | 100 } |
| 97 | 101 |
| 98 Layer* CreateLayer(LayerType type) { | 102 Layer* CreateLayer(LayerType type) { |
| 99 return new Layer(type); | 103 return new Layer(type); |
| 100 } | 104 } |
| 101 | 105 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool aborted_; | 307 bool aborted_; |
| 304 | 308 |
| 305 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); | 309 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); |
| 306 }; | 310 }; |
| 307 | 311 |
| 308 } // namespace | 312 } // namespace |
| 309 | 313 |
| 310 #if defined(OS_WIN) | 314 #if defined(OS_WIN) |
| 311 // These are disabled on windows as they don't run correctly on the buildbot. | 315 // These are disabled on windows as they don't run correctly on the buildbot. |
| 312 // Reenable once we move to the real compositor. | 316 // Reenable once we move to the real compositor. |
| 313 #define MAYBE_Delegate DISABLED_Delegate | 317 #define MAYBE_Delegate Delegate |
| 314 #define MAYBE_Draw DISABLED_Draw | 318 #define MAYBE_Draw Draw |
| 315 #define MAYBE_DrawTree DISABLED_DrawTree | 319 #define MAYBE_DrawTree DrawTree |
| 316 #define MAYBE_Hierarchy DISABLED_Hierarchy | 320 #define MAYBE_Hierarchy Hierarchy |
| 317 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture | 321 #define MAYBE_HierarchyNoTexture HierarchyNoTexture |
| 318 #define MAYBE_DrawPixels DISABLED_DrawPixels | 322 #define MAYBE_DrawPixels DrawPixels |
| 319 #define MAYBE_SetRootLayer DISABLED_SetRootLayer | 323 #define MAYBE_SetRootLayer SetRootLayer |
| 320 #define MAYBE_CompositorObservers DISABLED_CompositorObservers | 324 #define MAYBE_CompositorObservers CompositorObservers |
| 321 #define MAYBE_ModifyHierarchy DISABLED_ModifyHierarchy | 325 #define MAYBE_ModifyHierarchy ModifyHierarchy |
| 322 #define MAYBE_Opacity DISABLED_Opacity | 326 #define MAYBE_Opacity Opacity |
| 323 #define MAYBE_ScaleUpDown DISABLED_ScaleUpDown | 327 #define MAYBE_ScaleUpDown ScaleUpDown |
| 324 #define MAYBE_ScaleReparent DISABLED_ScaleReparent | 328 #define MAYBE_ScaleReparent ScaleReparent |
| 325 #define MAYBE_NoScaleCanvas DISABLED_NoScaleCanvas | 329 #define MAYBE_NoScaleCanvas NoScaleCanvas |
| 326 #define MAYBE_AddRemoveThreadedAnimations DISABLED_AddRemoveThreadedAnimations | 330 #define MAYBE_AddRemoveThreadedAnimations AddRemoveThreadedAnimations |
| 327 #define MAYBE_SwitchCCLayerAnimations DISABLED_SwitchCCLayerAnimations | 331 #define MAYBE_SwitchCCLayerAnimations SwitchCCLayerAnimations |
| 328 #else | 332 #else |
| 329 #define MAYBE_Delegate Delegate | 333 #define MAYBE_Delegate Delegate |
| 330 #define MAYBE_Draw Draw | 334 #define MAYBE_Draw Draw |
| 331 #define MAYBE_DrawTree DrawTree | 335 #define MAYBE_DrawTree DrawTree |
| 332 #define MAYBE_Hierarchy Hierarchy | 336 #define MAYBE_Hierarchy Hierarchy |
| 333 #define MAYBE_HierarchyNoTexture HierarchyNoTexture | 337 #define MAYBE_HierarchyNoTexture HierarchyNoTexture |
| 334 #define MAYBE_DrawPixels DrawPixels | 338 #define MAYBE_DrawPixels DrawPixels |
| 335 #define MAYBE_SetRootLayer SetRootLayer | 339 #define MAYBE_SetRootLayer SetRootLayer |
| 336 #define MAYBE_CompositorObservers CompositorObservers | 340 #define MAYBE_CompositorObservers CompositorObservers |
| 337 #define MAYBE_ModifyHierarchy ModifyHierarchy | 341 #define MAYBE_ModifyHierarchy ModifyHierarchy |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 DrawTree(l1.get()); | 376 DrawTree(l1.get()); |
| 373 } | 377 } |
| 374 | 378 |
| 375 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { | 379 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { |
| 376 public: | 380 public: |
| 377 LayerWithDelegateTest() {} | 381 LayerWithDelegateTest() {} |
| 378 virtual ~LayerWithDelegateTest() {} | 382 virtual ~LayerWithDelegateTest() {} |
| 379 | 383 |
| 380 // Overridden from testing::Test: | 384 // Overridden from testing::Test: |
| 381 virtual void SetUp() OVERRIDE { | 385 virtual void SetUp() OVERRIDE { |
| 382 ui::SetupTestCompositor(); | 386 bool allow_test_contexts = true; |
| 387 Compositor::InitializeContextFactoryForTests(allow_test_contexts); |
| 388 Compositor::Initialize(); |
| 383 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); | 389 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); |
| 384 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 390 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
| 385 } | 391 } |
| 386 | 392 |
| 387 virtual void TearDown() OVERRIDE { | 393 virtual void TearDown() OVERRIDE { |
| 394 compositor_.reset(); |
| 395 Compositor::Terminate(); |
| 388 } | 396 } |
| 389 | 397 |
| 390 Compositor* compositor() { return compositor_.get(); } | 398 Compositor* compositor() { return compositor_.get(); } |
| 391 | 399 |
| 392 virtual Layer* CreateLayer(LayerType type) { | 400 virtual Layer* CreateLayer(LayerType type) { |
| 393 return new Layer(type); | 401 return new Layer(type); |
| 394 } | 402 } |
| 395 | 403 |
| 396 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { | 404 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { |
| 397 Layer* layer = new ColoredLayer(color); | 405 Layer* layer = new ColoredLayer(color); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 EXPECT_FALSE(d2.painted()); | 591 EXPECT_FALSE(d2.painted()); |
| 584 // |d3| should have received a paint notification. | 592 // |d3| should have received a paint notification. |
| 585 EXPECT_TRUE(d3.painted()); | 593 EXPECT_TRUE(d3.painted()); |
| 586 } | 594 } |
| 587 | 595 |
| 588 class LayerWithNullDelegateTest : public LayerWithDelegateTest { | 596 class LayerWithNullDelegateTest : public LayerWithDelegateTest { |
| 589 public: | 597 public: |
| 590 LayerWithNullDelegateTest() {} | 598 LayerWithNullDelegateTest() {} |
| 591 virtual ~LayerWithNullDelegateTest() {} | 599 virtual ~LayerWithNullDelegateTest() {} |
| 592 | 600 |
| 593 // Overridden from testing::Test: | |
| 594 virtual void SetUp() OVERRIDE { | 601 virtual void SetUp() OVERRIDE { |
| 595 LayerWithDelegateTest::SetUp(); | 602 LayerWithDelegateTest::SetUp(); |
| 596 default_layer_delegate_.reset(new NullLayerDelegate()); | 603 default_layer_delegate_.reset(new NullLayerDelegate()); |
| 597 } | 604 } |
| 598 | 605 |
| 599 virtual void TearDown() OVERRIDE { | |
| 600 } | |
| 601 | |
| 602 virtual Layer* CreateLayer(LayerType type) OVERRIDE { | 606 virtual Layer* CreateLayer(LayerType type) OVERRIDE { |
| 603 Layer* layer = new Layer(type); | 607 Layer* layer = new Layer(type); |
| 604 layer->set_delegate(default_layer_delegate_.get()); | 608 layer->set_delegate(default_layer_delegate_.get()); |
| 605 return layer; | 609 return layer; |
| 606 } | 610 } |
| 607 | 611 |
| 608 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { | 612 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { |
| 609 Layer* layer = CreateTextureLayer(bounds); | 613 Layer* layer = CreateTextureLayer(bounds); |
| 610 compositor()->SetRootLayer(layer); | 614 compositor()->SetRootLayer(layer); |
| 611 return layer; | 615 return layer; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // The CompositorDelegate (us) should have been told to draw for a move. | 798 // The CompositorDelegate (us) should have been told to draw for a move. |
| 795 WaitForDraw(); | 799 WaitForDraw(); |
| 796 | 800 |
| 797 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); | 801 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); |
| 798 | 802 |
| 799 // The CompositorDelegate (us) should have been told to draw for a resize. | 803 // The CompositorDelegate (us) should have been told to draw for a resize. |
| 800 WaitForDraw(); | 804 WaitForDraw(); |
| 801 } | 805 } |
| 802 | 806 |
| 803 // Checks that pixels are actually drawn to the screen with a read back. | 807 // Checks that pixels are actually drawn to the screen with a read back. |
| 804 // Currently disabled on all platforms, see http://crbug.com/148709. | |
| 805 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { | 808 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { |
| 806 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 809 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
| 807 gfx::Rect(0, 0, 500, 500))); | 810 gfx::Rect(0, 0, 500, 500))); |
| 808 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, | 811 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, |
| 809 gfx::Rect(0, 0, 500, 10))); | 812 gfx::Rect(0, 0, 500, 10))); |
| 810 | 813 |
| 811 layer->Add(layer2.get()); | 814 layer->Add(layer2.get()); |
| 812 | 815 |
| 813 DrawTree(layer.get()); | 816 DrawTree(layer.get()); |
| 814 | 817 |
| 818 // Make sure the compositor will show our layers. |
| 819 EXPECT_EQ(gfx::Size(500, 500).ToString(), GetCompositor()->size().ToString()); |
| 820 |
| 815 SkBitmap bitmap; | 821 SkBitmap bitmap; |
| 816 gfx::Size size = GetCompositor()->size(); | 822 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, gfx::Rect(0, 0, 500, 500))); |
| 817 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, | |
| 818 gfx::Rect(0, 10, | |
| 819 size.width(), size.height() - 10))); | |
| 820 ASSERT_FALSE(bitmap.empty()); | 823 ASSERT_FALSE(bitmap.empty()); |
| 821 | 824 |
| 822 SkAutoLockPixels lock(bitmap); | 825 SkAutoLockPixels lock(bitmap); |
| 823 bool is_all_red = true; | 826 bool is_all_red = true; |
| 824 for (int x = 0; is_all_red && x < 500; x++) | 827 for (int x = 0; is_all_red && x < 500; x++) { |
| 825 for (int y = 0; is_all_red && y < 490; y++) | 828 for (int y = 0; is_all_red && y < 500; y++) { |
| 826 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 829 SkColor actual_color = bitmap.getColor(x, y); |
| 827 | 830 SkColor expected_color = y < 10 ? SK_ColorBLUE : SK_ColorRED; |
| 828 EXPECT_TRUE(is_all_red); | 831 EXPECT_EQ(expected_color, actual_color) |
| 832 << "Pixel error at x=" << x << " y=" << y << "; " |
| 833 << "actual RGBA=(" |
| 834 << SkColorGetR(actual_color) << "," |
| 835 << SkColorGetG(actual_color) << "," |
| 836 << SkColorGetB(actual_color) << "," |
| 837 << SkColorGetA(actual_color) << "); " |
| 838 << "expected RGBA=(" |
| 839 << SkColorGetR(expected_color) << "," |
| 840 << SkColorGetG(expected_color) << "," |
| 841 << SkColorGetB(expected_color) << "," |
| 842 << SkColorGetA(expected_color) << ")"; |
| 843 } |
| 844 } |
| 829 } | 845 } |
| 830 | 846 |
| 831 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 847 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
| 832 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { | 848 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { |
| 833 Compositor* compositor = GetCompositor(); | 849 Compositor* compositor = GetCompositor(); |
| 834 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 850 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
| 835 gfx::Rect(20, 20, 400, 400))); | 851 gfx::Rect(20, 20, 400, 400))); |
| 836 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 852 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
| 837 gfx::Rect(10, 10, 350, 350))); | 853 gfx::Rect(10, 10, 350, 350))); |
| 838 | 854 |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 l1->SetOpacity(0.5f); | 1435 l1->SetOpacity(0.5f); |
| 1420 | 1436 |
| 1421 // Change l1's cc::Layer. | 1437 // Change l1's cc::Layer. |
| 1422 l1->SwitchCCLayerForTest(); | 1438 l1->SwitchCCLayerForTest(); |
| 1423 | 1439 |
| 1424 // Ensure that the opacity animation completed. | 1440 // Ensure that the opacity animation completed. |
| 1425 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1441 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
| 1426 } | 1442 } |
| 1427 | 1443 |
| 1428 } // namespace ui | 1444 } // namespace ui |
| OLD | NEW |