| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "cc/test/fake_output_surface_client.h" | 45 #include "cc/test/fake_output_surface_client.h" |
| 46 #include "cc/test/fake_picture_layer_impl.h" | 46 #include "cc/test/fake_picture_layer_impl.h" |
| 47 #include "cc/test/fake_picture_pile_impl.h" | 47 #include "cc/test/fake_picture_pile_impl.h" |
| 48 #include "cc/test/fake_proxy.h" | 48 #include "cc/test/fake_proxy.h" |
| 49 #include "cc/test/geometry_test_utils.h" | 49 #include "cc/test/geometry_test_utils.h" |
| 50 #include "cc/test/layer_test_common.h" | 50 #include "cc/test/layer_test_common.h" |
| 51 #include "cc/test/layer_tree_test.h" | 51 #include "cc/test/layer_tree_test.h" |
| 52 #include "cc/test/render_pass_test_common.h" | 52 #include "cc/test/render_pass_test_common.h" |
| 53 #include "cc/test/test_gpu_memory_buffer_manager.h" | 53 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 54 #include "cc/test/test_shared_bitmap_manager.h" | 54 #include "cc/test/test_shared_bitmap_manager.h" |
| 55 #include "cc/test/test_task_graph_runner.h" |
| 55 #include "cc/test/test_web_graphics_context_3d.h" | 56 #include "cc/test/test_web_graphics_context_3d.h" |
| 56 #include "cc/trees/layer_tree_impl.h" | 57 #include "cc/trees/layer_tree_impl.h" |
| 57 #include "cc/trees/single_thread_proxy.h" | 58 #include "cc/trees/single_thread_proxy.h" |
| 58 #include "testing/gmock/include/gmock/gmock.h" | 59 #include "testing/gmock/include/gmock/gmock.h" |
| 59 #include "testing/gtest/include/gtest/gtest.h" | 60 #include "testing/gtest/include/gtest/gtest.h" |
| 60 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 61 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 61 #include "ui/gfx/frame_time.h" | 62 #include "ui/gfx/frame_time.h" |
| 62 #include "ui/gfx/geometry/rect_conversions.h" | 63 #include "ui/gfx/geometry/rect_conversions.h" |
| 63 #include "ui/gfx/geometry/size_conversions.h" | 64 #include "ui/gfx/geometry/size_conversions.h" |
| 64 #include "ui/gfx/geometry/vector2d_conversions.h" | 65 #include "ui/gfx/geometry/vector2d_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 class LayerTreeHostImplTest : public testing::Test, | 76 class LayerTreeHostImplTest : public testing::Test, |
| 76 public LayerTreeHostImplClient { | 77 public LayerTreeHostImplClient { |
| 77 public: | 78 public: |
| 78 LayerTreeHostImplTest() | 79 LayerTreeHostImplTest() |
| 79 : proxy_(base::MessageLoopProxy::current(), | 80 : proxy_(base::MessageLoopProxy::current(), |
| 80 base::MessageLoopProxy::current()), | 81 base::MessageLoopProxy::current()), |
| 81 always_impl_thread_(&proxy_), | 82 always_impl_thread_(&proxy_), |
| 82 always_main_thread_blocked_(&proxy_), | 83 always_main_thread_blocked_(&proxy_), |
| 83 shared_bitmap_manager_(new TestSharedBitmapManager), | 84 shared_bitmap_manager_(new TestSharedBitmapManager), |
| 84 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), | 85 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), |
| 86 task_graph_runner_(new TestTaskGraphRunner), |
| 85 on_can_draw_state_changed_called_(false), | 87 on_can_draw_state_changed_called_(false), |
| 86 did_notify_ready_to_activate_(false), | 88 did_notify_ready_to_activate_(false), |
| 87 did_request_commit_(false), | 89 did_request_commit_(false), |
| 88 did_request_redraw_(false), | 90 did_request_redraw_(false), |
| 89 did_request_animate_(false), | 91 did_request_animate_(false), |
| 90 did_request_prepare_tiles_(false), | 92 did_request_prepare_tiles_(false), |
| 91 did_complete_page_scale_animation_(false), | 93 did_complete_page_scale_animation_(false), |
| 92 reduce_memory_result_(true), | 94 reduce_memory_result_(true), |
| 93 current_limit_bytes_(0), | 95 current_limit_bytes_(0), |
| 94 current_priority_cutoff_value_(0) { | 96 current_priority_cutoff_value_(0) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void DidCompletePageScaleAnimationOnImplThread() override { | 157 void DidCompletePageScaleAnimationOnImplThread() override { |
| 156 did_complete_page_scale_animation_ = true; | 158 did_complete_page_scale_animation_ = true; |
| 157 } | 159 } |
| 158 | 160 |
| 159 void set_reduce_memory_result(bool reduce_memory_result) { | 161 void set_reduce_memory_result(bool reduce_memory_result) { |
| 160 reduce_memory_result_ = reduce_memory_result; | 162 reduce_memory_result_ = reduce_memory_result; |
| 161 } | 163 } |
| 162 | 164 |
| 163 virtual bool CreateHostImpl(const LayerTreeSettings& settings, | 165 virtual bool CreateHostImpl(const LayerTreeSettings& settings, |
| 164 scoped_ptr<OutputSurface> output_surface) { | 166 scoped_ptr<OutputSurface> output_surface) { |
| 165 host_impl_ = LayerTreeHostImpl::Create(settings, | 167 host_impl_ = LayerTreeHostImpl::Create( |
| 166 this, | 168 settings, this, &proxy_, &stats_instrumentation_, |
| 167 &proxy_, | 169 shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), |
| 168 &stats_instrumentation_, | 170 task_graph_runner_.get(), 0); |
| 169 shared_bitmap_manager_.get(), | |
| 170 gpu_memory_buffer_manager_.get(), | |
| 171 0); | |
| 172 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); | 171 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); |
| 173 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 172 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 174 return init; | 173 return init; |
| 175 } | 174 } |
| 176 | 175 |
| 177 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { | 176 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { |
| 178 root->SetPosition(gfx::PointF()); | 177 root->SetPosition(gfx::PointF()); |
| 179 root->SetBounds(gfx::Size(10, 10)); | 178 root->SetBounds(gfx::Size(10, 10)); |
| 180 root->SetContentBounds(gfx::Size(10, 10)); | 179 root->SetContentBounds(gfx::Size(10, 10)); |
| 181 root->SetDrawsContent(true); | 180 root->SetDrawsContent(true); |
| 182 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); | 181 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); |
| 183 root->SetHasRenderSurface(true); | 182 root->SetHasRenderSurface(true); |
| 184 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 183 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 185 } | 184 } |
| 186 | 185 |
| 187 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { | 186 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { |
| 188 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); | 187 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); |
| 189 for (size_t i = 0; i < layer->children().size(); ++i) | 188 for (size_t i = 0; i < layer->children().size(); ++i) |
| 190 ExpectClearedScrollDeltasRecursive(layer->children()[i]); | 189 ExpectClearedScrollDeltasRecursive(layer->children()[i]); |
| 191 } | 190 } |
| 192 | 191 |
| 193 static void ExpectContains(const ScrollAndScaleSet& scroll_info, | 192 static void ExpectContains(const ScrollAndScaleSet& scroll_info, |
| 194 int id, | 193 int id, |
| 195 const gfx::Vector2dF& scroll_delta) { | 194 const gfx::Vector2d& scroll_delta) { |
| 196 int times_encountered = 0; | 195 int times_encountered = 0; |
| 197 | 196 |
| 198 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 197 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 199 if (scroll_info.scrolls[i].layer_id != id) | 198 if (scroll_info.scrolls[i].layer_id != id) |
| 200 continue; | 199 continue; |
| 201 EXPECT_VECTOR2DF_NEAR(scroll_delta, scroll_info.scrolls[i].scroll_delta, | 200 EXPECT_VECTOR_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); |
| 202 1.0e-10); | |
| 203 times_encountered++; | 201 times_encountered++; |
| 204 } | 202 } |
| 205 | 203 |
| 206 ASSERT_EQ(1, times_encountered); | 204 ASSERT_EQ(1, times_encountered); |
| 207 } | 205 } |
| 208 | 206 |
| 209 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { | 207 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
| 210 int times_encountered = 0; | 208 int times_encountered = 0; |
| 211 | 209 |
| 212 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 210 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 host_impl_->PrepareToDraw(&frame_data); | 382 host_impl_->PrepareToDraw(&frame_data); |
| 385 host_impl_->DidDrawAllLayers(frame_data); | 383 host_impl_->DidDrawAllLayers(frame_data); |
| 386 } | 384 } |
| 387 | 385 |
| 388 FakeProxy proxy_; | 386 FakeProxy proxy_; |
| 389 DebugScopedSetImplThread always_impl_thread_; | 387 DebugScopedSetImplThread always_impl_thread_; |
| 390 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 388 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
| 391 | 389 |
| 392 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 390 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
| 393 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 391 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 392 scoped_ptr<TestTaskGraphRunner> task_graph_runner_; |
| 394 scoped_ptr<LayerTreeHostImpl> host_impl_; | 393 scoped_ptr<LayerTreeHostImpl> host_impl_; |
| 395 FakeRenderingStatsInstrumentation stats_instrumentation_; | 394 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 396 bool on_can_draw_state_changed_called_; | 395 bool on_can_draw_state_changed_called_; |
| 397 bool did_notify_ready_to_activate_; | 396 bool did_notify_ready_to_activate_; |
| 398 bool did_request_commit_; | 397 bool did_request_commit_; |
| 399 bool did_request_redraw_; | 398 bool did_request_redraw_; |
| 400 bool did_request_animate_; | 399 bool did_request_animate_; |
| 401 bool did_request_prepare_tiles_; | 400 bool did_request_prepare_tiles_; |
| 402 bool did_complete_page_scale_animation_; | 401 bool did_complete_page_scale_animation_; |
| 403 bool reduce_memory_result_; | 402 bool reduce_memory_result_; |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 LayerTreeHostImplClient* client, | 1535 LayerTreeHostImplClient* client, |
| 1537 Proxy* proxy, | 1536 Proxy* proxy, |
| 1538 SharedBitmapManager* manager, | 1537 SharedBitmapManager* manager, |
| 1539 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 1538 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 1540 : LayerTreeHostImpl(settings, | 1539 : LayerTreeHostImpl(settings, |
| 1541 client, | 1540 client, |
| 1542 proxy, | 1541 proxy, |
| 1543 rendering_stats_instrumentation, | 1542 rendering_stats_instrumentation, |
| 1544 manager, | 1543 manager, |
| 1545 NULL, | 1544 NULL, |
| 1545 NULL, |
| 1546 0) {} | 1546 0) {} |
| 1547 | 1547 |
| 1548 BeginFrameArgs CurrentBeginFrameArgs() const override { | 1548 BeginFrameArgs CurrentBeginFrameArgs() const override { |
| 1549 return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | 1549 return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 1550 fake_current_physical_time_); | 1550 fake_current_physical_time_); |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { | 1553 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| 1554 fake_current_physical_time_ = fake_now; | 1554 fake_current_physical_time_ = fake_now; |
| 1555 } | 1555 } |
| (...skipping 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3707 // Scroll to the right in screen coordinates with a gesture. | 3707 // Scroll to the right in screen coordinates with a gesture. |
| 3708 gfx::Vector2d gesture_scroll_delta(10, 0); | 3708 gfx::Vector2d gesture_scroll_delta(10, 0); |
| 3709 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3709 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3710 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 3710 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 3711 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3711 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3712 host_impl_->ScrollEnd(); | 3712 host_impl_->ScrollEnd(); |
| 3713 | 3713 |
| 3714 // The layer should have scrolled down in its local coordinates. | 3714 // The layer should have scrolled down in its local coordinates. |
| 3715 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 3715 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
| 3716 ExpectContains(*scroll_info.get(), scroll_layer->id(), | 3716 ExpectContains(*scroll_info.get(), scroll_layer->id(), |
| 3717 gfx::Vector2dF(0, gesture_scroll_delta.x())); | 3717 gfx::Vector2d(0, gesture_scroll_delta.x())); |
| 3718 | 3718 |
| 3719 // Reset and scroll down with the wheel. | 3719 // Reset and scroll down with the wheel. |
| 3720 scroll_layer->SetScrollDelta(gfx::Vector2dF()); | 3720 scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
| 3721 gfx::Vector2d wheel_scroll_delta(0, 10); | 3721 gfx::Vector2d wheel_scroll_delta(0, 10); |
| 3722 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3722 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3723 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL)); | 3723 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL)); |
| 3724 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); | 3724 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); |
| 3725 host_impl_->ScrollEnd(); | 3725 host_impl_->ScrollEnd(); |
| 3726 | 3726 |
| 3727 // The layer should have scrolled down in its local coordinates. | 3727 // The layer should have scrolled down in its local coordinates. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3766 { | 3766 { |
| 3767 // Scroll down in screen coordinates with a gesture. | 3767 // Scroll down in screen coordinates with a gesture. |
| 3768 gfx::Vector2d gesture_scroll_delta(0, 10); | 3768 gfx::Vector2d gesture_scroll_delta(0, 10); |
| 3769 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3769 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3770 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); | 3770 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); |
| 3771 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3771 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3772 host_impl_->ScrollEnd(); | 3772 host_impl_->ScrollEnd(); |
| 3773 | 3773 |
| 3774 // The child layer should have scrolled down in its local coordinates an | 3774 // The child layer should have scrolled down in its local coordinates an |
| 3775 // amount proportional to the angle between it and the input scroll delta. | 3775 // amount proportional to the angle between it and the input scroll delta. |
| 3776 gfx::Vector2dF expected_scroll_delta( | 3776 gfx::Vector2d expected_scroll_delta( |
| 3777 0, gesture_scroll_delta.y() * | 3777 0, gesture_scroll_delta.y() * |
| 3778 std::cos(MathUtil::Deg2Rad(child_layer_angle))); | 3778 std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
| 3779 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3779 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 3780 host_impl_->ProcessScrollDeltas(); | 3780 host_impl_->ProcessScrollDeltas(); |
| 3781 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3781 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
| 3782 | 3782 |
| 3783 // The root scroll layer should not have scrolled, because the input delta | 3783 // The root scroll layer should not have scrolled, because the input delta |
| 3784 // was close to the layer's axis of movement. | 3784 // was close to the layer's axis of movement. |
| 3785 EXPECT_EQ(scroll_info->scrolls.size(), 1u); | 3785 EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 3786 } | 3786 } |
| 3787 { | 3787 { |
| 3788 // Now reset and scroll the same amount horizontally. | 3788 // Now reset and scroll the same amount horizontally. |
| 3789 child_ptr->SetScrollDelta(gfx::Vector2dF()); | 3789 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
| 3790 gfx::Vector2d gesture_scroll_delta(10, 0); | 3790 gfx::Vector2d gesture_scroll_delta(10, 0); |
| 3791 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3791 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3792 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); | 3792 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); |
| 3793 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3793 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3794 host_impl_->ScrollEnd(); | 3794 host_impl_->ScrollEnd(); |
| 3795 | 3795 |
| 3796 // The child layer should have scrolled down in its local coordinates an | 3796 // The child layer should have scrolled down in its local coordinates an |
| 3797 // amount proportional to the angle between it and the input scroll delta. | 3797 // amount proportional to the angle between it and the input scroll delta. |
| 3798 gfx::Vector2dF expected_scroll_delta( | 3798 gfx::Vector2d expected_scroll_delta( |
| 3799 0, -gesture_scroll_delta.x() * | 3799 0, -gesture_scroll_delta.x() * |
| 3800 std::sin(MathUtil::Deg2Rad(child_layer_angle))); | 3800 std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
| 3801 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3801 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 3802 host_impl_->ProcessScrollDeltas(); | 3802 host_impl_->ProcessScrollDeltas(); |
| 3803 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3803 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
| 3804 | 3804 |
| 3805 // The root scroll layer should have scrolled more, since the input scroll | 3805 // The root scroll layer should have scrolled more, since the input scroll |
| 3806 // delta was mostly orthogonal to the child layer's vertical scroll axis. | 3806 // delta was mostly orthogonal to the child layer's vertical scroll axis. |
| 3807 gfx::Vector2dF expected_root_scroll_delta( | 3807 gfx::Vector2d expected_root_scroll_delta( |
| 3808 gesture_scroll_delta.x() * | 3808 gesture_scroll_delta.x() * |
| 3809 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), | 3809 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), |
| 3810 0); | 3810 0); |
| 3811 ExpectContains(*scroll_info.get(), | 3811 ExpectContains(*scroll_info.get(), |
| 3812 scroll_layer->id(), | 3812 scroll_layer->id(), |
| 3813 expected_root_scroll_delta); | 3813 expected_root_scroll_delta); |
| 3814 } | 3814 } |
| 3815 } | 3815 } |
| 3816 | 3816 |
| 3817 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { | 3817 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5035 context_provider->TestContext3d()->set_have_post_sub_buffer(true); | 5035 context_provider->TestContext3d()->set_have_post_sub_buffer(true); |
| 5036 | 5036 |
| 5037 scoped_ptr<FakeOutputSurface> output_surface( | 5037 scoped_ptr<FakeOutputSurface> output_surface( |
| 5038 FakeOutputSurface::Create3d(context_provider)); | 5038 FakeOutputSurface::Create3d(context_provider)); |
| 5039 FakeOutputSurface* fake_output_surface = output_surface.get(); | 5039 FakeOutputSurface* fake_output_surface = output_surface.get(); |
| 5040 | 5040 |
| 5041 // This test creates its own LayerTreeHostImpl, so | 5041 // This test creates its own LayerTreeHostImpl, so |
| 5042 // that we can force partial swap enabled. | 5042 // that we can force partial swap enabled. |
| 5043 LayerTreeSettings settings; | 5043 LayerTreeSettings settings; |
| 5044 settings.renderer_settings.partial_swap_enabled = true; | 5044 settings.renderer_settings.partial_swap_enabled = true; |
| 5045 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | |
| 5046 new TestSharedBitmapManager()); | |
| 5047 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = | 5045 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
| 5048 LayerTreeHostImpl::Create(settings, | 5046 LayerTreeHostImpl::Create( |
| 5049 this, | 5047 settings, this, &proxy_, &stats_instrumentation_, |
| 5050 &proxy_, | 5048 shared_bitmap_manager_.get(), NULL, task_graph_runner_.get(), 0); |
| 5051 &stats_instrumentation_, | |
| 5052 shared_bitmap_manager.get(), | |
| 5053 NULL, | |
| 5054 0); | |
| 5055 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); | 5049 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); |
| 5056 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); | 5050 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); |
| 5057 | 5051 |
| 5058 scoped_ptr<LayerImpl> root = | 5052 scoped_ptr<LayerImpl> root = |
| 5059 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); | 5053 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); |
| 5060 root->SetHasRenderSurface(true); | 5054 root->SetHasRenderSurface(true); |
| 5061 scoped_ptr<LayerImpl> child = | 5055 scoped_ptr<LayerImpl> child = |
| 5062 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); | 5056 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); |
| 5063 child->SetPosition(gfx::PointF(12.f, 13.f)); | 5057 child->SetPosition(gfx::PointF(12.f, 13.f)); |
| 5064 child->SetBounds(gfx::Size(14, 15)); | 5058 child->SetBounds(gfx::Size(14, 15)); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5290 TEST_F(LayerTreeHostImplTest, PartialSwap) { | 5284 TEST_F(LayerTreeHostImplTest, PartialSwap) { |
| 5291 scoped_ptr<MockContext> context_owned(new MockContext); | 5285 scoped_ptr<MockContext> context_owned(new MockContext); |
| 5292 MockContext* mock_context = context_owned.get(); | 5286 MockContext* mock_context = context_owned.get(); |
| 5293 MockContextHarness harness(mock_context); | 5287 MockContextHarness harness(mock_context); |
| 5294 | 5288 |
| 5295 LayerTreeSettings settings = DefaultSettings(); | 5289 LayerTreeSettings settings = DefaultSettings(); |
| 5296 settings.renderer_settings.partial_swap_enabled = true; | 5290 settings.renderer_settings.partial_swap_enabled = true; |
| 5297 CreateHostImpl(settings, FakeOutputSurface::Create3d(context_owned.Pass())); | 5291 CreateHostImpl(settings, FakeOutputSurface::Create3d(context_owned.Pass())); |
| 5298 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); | 5292 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); |
| 5299 | 5293 |
| 5300 // The first frame is not a partially-swapped one. | 5294 // The first frame is not a partially-swapped one. No scissor should be set. |
| 5301 harness.MustSetScissor(0, 0, 10, 10); | 5295 harness.MustSetNoScissor(); |
| 5302 harness.MustDrawSolidQuad(); | 5296 harness.MustDrawSolidQuad(); |
| 5303 { | 5297 { |
| 5304 LayerTreeHostImpl::FrameData frame; | 5298 LayerTreeHostImpl::FrameData frame; |
| 5305 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 5299 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| 5306 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 5300 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 5307 host_impl_->DidDrawAllLayers(frame); | 5301 host_impl_->DidDrawAllLayers(frame); |
| 5308 } | 5302 } |
| 5309 Mock::VerifyAndClearExpectations(&mock_context); | 5303 Mock::VerifyAndClearExpectations(&mock_context); |
| 5310 | 5304 |
| 5311 // Damage a portion of the frame. | 5305 // Damage a portion of the frame. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5332 RenderingStatsInstrumentation* stats_instrumentation) { | 5326 RenderingStatsInstrumentation* stats_instrumentation) { |
| 5333 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); | 5327 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 5334 scoped_ptr<OutputSurface> output_surface( | 5328 scoped_ptr<OutputSurface> output_surface( |
| 5335 FakeOutputSurface::Create3d(provider)); | 5329 FakeOutputSurface::Create3d(provider)); |
| 5336 provider->BindToCurrentThread(); | 5330 provider->BindToCurrentThread(); |
| 5337 provider->TestContext3d()->set_have_post_sub_buffer(true); | 5331 provider->TestContext3d()->set_have_post_sub_buffer(true); |
| 5338 | 5332 |
| 5339 LayerTreeSettings settings; | 5333 LayerTreeSettings settings; |
| 5340 settings.renderer_settings.partial_swap_enabled = partial_swap; | 5334 settings.renderer_settings.partial_swap_enabled = partial_swap; |
| 5341 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( | 5335 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
| 5342 settings, client, proxy, stats_instrumentation, manager, NULL, 0); | 5336 settings, client, proxy, stats_instrumentation, manager, NULL, NULL, 0); |
| 5343 my_host_impl->InitializeRenderer(output_surface.Pass()); | 5337 my_host_impl->InitializeRenderer(output_surface.Pass()); |
| 5344 my_host_impl->SetViewportSize(gfx::Size(100, 100)); | 5338 my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
| 5345 | 5339 |
| 5346 /* | 5340 /* |
| 5347 Layers are created as follows: | 5341 Layers are created as follows: |
| 5348 | 5342 |
| 5349 +--------------------+ | 5343 +--------------------+ |
| 5350 | 1 | | 5344 | 1 | |
| 5351 | +-----------+ | | 5345 | +-----------+ | |
| 5352 | | 2 | | | 5346 | | 2 | | |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6636 EXPECT_FALSE(did_update_renderer_capabilities_); | 6630 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 6637 | 6631 |
| 6638 // Software draw again. | 6632 // Software draw again. |
| 6639 DrawFrame(); | 6633 DrawFrame(); |
| 6640 } | 6634 } |
| 6641 | 6635 |
| 6642 // Checks that we have a non-0 default allocation if we pass a context that | 6636 // Checks that we have a non-0 default allocation if we pass a context that |
| 6643 // doesn't support memory management extensions. | 6637 // doesn't support memory management extensions. |
| 6644 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { | 6638 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { |
| 6645 LayerTreeSettings settings; | 6639 LayerTreeSettings settings; |
| 6646 host_impl_ = LayerTreeHostImpl::Create(settings, | 6640 host_impl_ = LayerTreeHostImpl::Create( |
| 6647 this, | 6641 settings, this, &proxy_, &stats_instrumentation_, |
| 6648 &proxy_, | 6642 shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), |
| 6649 &stats_instrumentation_, | 6643 task_graph_runner_.get(), 0); |
| 6650 shared_bitmap_manager_.get(), | |
| 6651 gpu_memory_buffer_manager_.get(), | |
| 6652 0); | |
| 6653 | 6644 |
| 6654 scoped_ptr<OutputSurface> output_surface( | 6645 scoped_ptr<OutputSurface> output_surface( |
| 6655 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); | 6646 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); |
| 6656 host_impl_->InitializeRenderer(output_surface.Pass()); | 6647 host_impl_->InitializeRenderer(output_surface.Pass()); |
| 6657 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); | 6648 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); |
| 6658 } | 6649 } |
| 6659 | 6650 |
| 6660 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { | 6651 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { |
| 6661 ManagedMemoryPolicy policy1( | 6652 ManagedMemoryPolicy policy1( |
| 6662 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); | 6653 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6683 | 6674 |
| 6684 host_impl_->SetVisible(true); | 6675 host_impl_->SetVisible(true); |
| 6685 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 6676 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
| 6686 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); | 6677 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); |
| 6687 | 6678 |
| 6688 // Now enable GPU rasterization and test if we get nice to have cutoff, | 6679 // Now enable GPU rasterization and test if we get nice to have cutoff, |
| 6689 // when visible. | 6680 // when visible. |
| 6690 LayerTreeSettings settings; | 6681 LayerTreeSettings settings; |
| 6691 settings.gpu_rasterization_enabled = true; | 6682 settings.gpu_rasterization_enabled = true; |
| 6692 host_impl_ = LayerTreeHostImpl::Create( | 6683 host_impl_ = LayerTreeHostImpl::Create( |
| 6693 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, 0); | 6684 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, NULL, 0); |
| 6694 host_impl_->SetUseGpuRasterization(true); | 6685 host_impl_->SetUseGpuRasterization(true); |
| 6695 host_impl_->SetVisible(true); | 6686 host_impl_->SetVisible(true); |
| 6696 host_impl_->SetMemoryPolicy(policy1); | 6687 host_impl_->SetMemoryPolicy(policy1); |
| 6697 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 6688 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
| 6698 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); | 6689 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); |
| 6699 | 6690 |
| 6700 host_impl_->SetVisible(false); | 6691 host_impl_->SetVisible(false); |
| 6701 EXPECT_EQ(0u, current_limit_bytes_); | 6692 EXPECT_EQ(0u, current_limit_bytes_); |
| 6702 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); | 6693 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); |
| 6703 } | 6694 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6746 host_impl_->SetUseGpuRasterization(true); | 6737 host_impl_->SetUseGpuRasterization(true); |
| 6747 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 6738 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 6748 } | 6739 } |
| 6749 | 6740 |
| 6750 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { | 6741 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { |
| 6751 public: | 6742 public: |
| 6752 void SetUp() override { | 6743 void SetUp() override { |
| 6753 LayerTreeSettings settings; | 6744 LayerTreeSettings settings; |
| 6754 settings.impl_side_painting = true; | 6745 settings.impl_side_painting = true; |
| 6755 | 6746 |
| 6756 fake_host_impl_ = new FakeLayerTreeHostImpl( | 6747 fake_host_impl_ = new FakeLayerTreeHostImpl(settings, &proxy_, |
| 6757 settings, &proxy_, shared_bitmap_manager_.get()); | 6748 shared_bitmap_manager_.get(), |
| 6749 task_graph_runner_.get()); |
| 6758 host_impl_.reset(fake_host_impl_); | 6750 host_impl_.reset(fake_host_impl_); |
| 6759 host_impl_->InitializeRenderer(CreateOutputSurface()); | 6751 host_impl_->InitializeRenderer(CreateOutputSurface()); |
| 6760 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 6752 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 6761 } | 6753 } |
| 6762 | 6754 |
| 6763 FakeLayerTreeHostImpl* fake_host_impl_; | 6755 FakeLayerTreeHostImpl* fake_host_impl_; |
| 6764 }; | 6756 }; |
| 6765 | 6757 |
| 6766 TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { | 6758 TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { |
| 6767 fake_host_impl_->DidModifyTilePriorities(); | 6759 fake_host_impl_->DidModifyTilePriorities(); |
| (...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8121 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10); | 8113 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10); |
| 8122 layer->SetBounds(gfx::Size(10, 10)); | 8114 layer->SetBounds(gfx::Size(10, 10)); |
| 8123 scoped_ptr<FakePictureLayerImpl> nondraw_layer = | 8115 scoped_ptr<FakePictureLayerImpl> nondraw_layer = |
| 8124 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12); | 8116 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12); |
| 8125 nondraw_layer->SetBounds(gfx::Size(10, 10)); | 8117 nondraw_layer->SetBounds(gfx::Size(10, 10)); |
| 8126 | 8118 |
| 8127 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( | 8119 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( |
| 8128 gfx::Size(10, 10), gfx::Size(10, 10))); | 8120 gfx::Size(10, 10), gfx::Size(10, 10))); |
| 8129 Region empty_invalidation; | 8121 Region empty_invalidation; |
| 8130 const PictureLayerTilingSet* null_tiling_set = nullptr; | 8122 const PictureLayerTilingSet* null_tiling_set = nullptr; |
| 8123 layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size()); |
| 8131 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); | 8124 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); |
| 8125 nondraw_layer->set_gpu_raster_max_texture_size( |
| 8126 host_impl_->device_viewport_size()); |
| 8132 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); | 8127 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); |
| 8133 | 8128 |
| 8134 layer->AddChild(nondraw_layer.Pass()); | 8129 layer->AddChild(nondraw_layer.Pass()); |
| 8135 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); | 8130 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); |
| 8136 | 8131 |
| 8137 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 8132 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 8138 LayerImpl* pending_layer = pending_tree->root_layer(); | 8133 LayerImpl* pending_layer = pending_tree->root_layer(); |
| 8139 FakePictureLayerImpl* pending_nondraw_layer = | 8134 FakePictureLayerImpl* pending_nondraw_layer = |
| 8140 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]); | 8135 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]); |
| 8141 | 8136 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8239 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10); | 8234 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10); |
| 8240 layer->SetBounds(gfx::Size(10, 10)); | 8235 layer->SetBounds(gfx::Size(10, 10)); |
| 8241 scoped_ptr<FakePictureLayerImpl> nondraw_layer = | 8236 scoped_ptr<FakePictureLayerImpl> nondraw_layer = |
| 8242 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12); | 8237 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12); |
| 8243 nondraw_layer->SetBounds(gfx::Size(10, 10)); | 8238 nondraw_layer->SetBounds(gfx::Size(10, 10)); |
| 8244 | 8239 |
| 8245 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( | 8240 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( |
| 8246 gfx::Size(10, 10), gfx::Size(10, 10))); | 8241 gfx::Size(10, 10), gfx::Size(10, 10))); |
| 8247 Region empty_invalidation; | 8242 Region empty_invalidation; |
| 8248 const PictureLayerTilingSet* null_tiling_set = nullptr; | 8243 const PictureLayerTilingSet* null_tiling_set = nullptr; |
| 8244 layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size()); |
| 8249 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); | 8245 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); |
| 8246 nondraw_layer->set_gpu_raster_max_texture_size( |
| 8247 host_impl_->device_viewport_size()); |
| 8250 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); | 8248 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); |
| 8251 | 8249 |
| 8252 layer->AddChild(nondraw_layer.Pass()); | 8250 layer->AddChild(nondraw_layer.Pass()); |
| 8253 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); | 8251 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); |
| 8254 | 8252 |
| 8255 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 8253 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 8256 LayerImpl* pending_layer = pending_tree->root_layer(); | 8254 LayerImpl* pending_layer = pending_tree->root_layer(); |
| 8257 FakePictureLayerImpl* pending_nondraw_layer = | 8255 FakePictureLayerImpl* pending_nondraw_layer = |
| 8258 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]); | 8256 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]); |
| 8259 | 8257 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8472 // surface. | 8470 // surface. |
| 8473 EXPECT_EQ(0, num_lost_surfaces_); | 8471 EXPECT_EQ(0, num_lost_surfaces_); |
| 8474 host_impl_->DidLoseOutputSurface(); | 8472 host_impl_->DidLoseOutputSurface(); |
| 8475 EXPECT_EQ(1, num_lost_surfaces_); | 8473 EXPECT_EQ(1, num_lost_surfaces_); |
| 8476 host_impl_->DidLoseOutputSurface(); | 8474 host_impl_->DidLoseOutputSurface(); |
| 8477 EXPECT_LE(1, num_lost_surfaces_); | 8475 EXPECT_LE(1, num_lost_surfaces_); |
| 8478 } | 8476 } |
| 8479 | 8477 |
| 8480 } // namespace | 8478 } // namespace |
| 8481 } // namespace cc | 8479 } // namespace cc |
| OLD | NEW |