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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 namespace cc { | 57 namespace cc { |
58 namespace { | 58 namespace { |
59 | 59 |
60 class LayerTreeHostImplTest : public testing::Test, | 60 class LayerTreeHostImplTest : public testing::Test, |
61 public LayerTreeHostImplClient { | 61 public LayerTreeHostImplClient { |
62 public: | 62 public: |
63 LayerTreeHostImplTest() | 63 LayerTreeHostImplTest() |
64 : proxy_(scoped_ptr<Thread>(NULL)), | 64 : proxy_(scoped_ptr<Thread>(NULL)), |
65 always_impl_thread_(&proxy_), | 65 always_impl_thread_(&proxy_), |
66 always_main_thread_blocked_(&proxy_), | 66 always_main_thread_blocked_(&proxy_), |
| 67 did_try_initialize_renderer_(false), |
67 on_can_draw_state_changed_called_(false), | 68 on_can_draw_state_changed_called_(false), |
68 has_pending_tree_(false), | 69 has_pending_tree_(false), |
69 did_request_commit_(false), | 70 did_request_commit_(false), |
70 did_request_redraw_(false), | 71 did_request_redraw_(false), |
71 did_upload_visible_tile_(false), | 72 did_upload_visible_tile_(false), |
72 reduce_memory_result_(true) { | 73 reduce_memory_result_(true) { |
73 media::InitializeMediaLibraryForTesting(); | 74 media::InitializeMediaLibraryForTesting(); |
74 } | 75 } |
75 | 76 |
76 virtual void OverrideSettings(LayerTreeSettings* settings) {} | 77 virtual void OverrideSettings(LayerTreeSettings* settings) {} |
77 | 78 |
78 virtual void SetUp() OVERRIDE { | 79 virtual void SetUp() OVERRIDE { |
79 LayerTreeSettings settings; | 80 LayerTreeSettings settings; |
80 settings.minimum_occlusion_tracking_size = gfx::Size(); | 81 settings.minimum_occlusion_tracking_size = gfx::Size(); |
81 OverrideSettings(&settings); | 82 OverrideSettings(&settings); |
82 | 83 |
83 host_impl_ = LayerTreeHostImpl::Create(settings, | 84 host_impl_ = LayerTreeHostImpl::Create(settings, |
84 this, | 85 this, |
85 &proxy_, | 86 &proxy_, |
86 &stats_instrumentation_); | 87 &stats_instrumentation_); |
87 host_impl_->InitializeRenderer(CreateOutputSurface()); | 88 host_impl_->InitializeRenderer(CreateOutputSurface()); |
88 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 89 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
89 } | 90 } |
90 | 91 |
91 virtual void TearDown() OVERRIDE {} | 92 virtual void TearDown() OVERRIDE {} |
92 | 93 |
| 94 virtual void DidTryInitializeRendererOnImplThread( |
| 95 bool success, |
| 96 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { |
| 97 did_try_initialize_renderer_ = true; |
| 98 } |
93 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} | 99 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} |
94 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} | 100 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} |
95 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, | 101 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, |
96 base::TimeDelta interval) OVERRIDE {} | 102 base::TimeDelta interval) OVERRIDE {} |
97 virtual void BeginFrameOnImplThread(base::TimeTicks frame_time) | 103 virtual void BeginFrameOnImplThread(base::TimeTicks frame_time) |
98 OVERRIDE {} | 104 OVERRIDE {} |
99 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { | 105 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { |
100 on_can_draw_state_changed_called_ = true; | 106 on_can_draw_state_changed_called_ = true; |
101 } | 107 } |
102 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) OVERRIDE { | 108 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) OVERRIDE { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 host_impl_->PrepareToDraw(&frame_data, gfx::Rect()); | 274 host_impl_->PrepareToDraw(&frame_data, gfx::Rect()); |
269 host_impl_->DidDrawAllLayers(frame_data); | 275 host_impl_->DidDrawAllLayers(frame_data); |
270 } | 276 } |
271 | 277 |
272 FakeProxy proxy_; | 278 FakeProxy proxy_; |
273 DebugScopedSetImplThread always_impl_thread_; | 279 DebugScopedSetImplThread always_impl_thread_; |
274 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 280 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
275 | 281 |
276 scoped_ptr<LayerTreeHostImpl> host_impl_; | 282 scoped_ptr<LayerTreeHostImpl> host_impl_; |
277 FakeRenderingStatsInstrumentation stats_instrumentation_; | 283 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 284 bool did_try_initialize_renderer_; |
278 bool on_can_draw_state_changed_called_; | 285 bool on_can_draw_state_changed_called_; |
279 bool has_pending_tree_; | 286 bool has_pending_tree_; |
280 bool did_request_commit_; | 287 bool did_request_commit_; |
281 bool did_request_redraw_; | 288 bool did_request_redraw_; |
282 bool did_upload_visible_tile_; | 289 bool did_upload_visible_tile_; |
283 bool reduce_memory_result_; | 290 bool reduce_memory_result_; |
284 }; | 291 }; |
285 | 292 |
286 class TestWebGraphicsContext3DMakeCurrentFails | 293 class TestWebGraphicsContext3DMakeCurrentFails |
287 : public TestWebGraphicsContext3D { | 294 : public TestWebGraphicsContext3D { |
(...skipping 5491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5779 } | 5786 } |
5780 | 5787 |
5781 int frames_began_, frames_ended_; | 5788 int frames_began_, frames_ended_; |
5782 }; | 5789 }; |
5783 | 5790 |
5784 TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) { | 5791 TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) { |
5785 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 5792 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
5786 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 5793 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
5787 CountingSoftwareDevice* software_device = new CountingSoftwareDevice(); | 5794 CountingSoftwareDevice* software_device = new CountingSoftwareDevice(); |
5788 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( | 5795 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( |
| 5796 scoped_ptr<WebKit::WebGraphicsContext3D>(), |
5789 scoped_ptr<SoftwareOutputDevice>(software_device)).release(); | 5797 scoped_ptr<SoftwareOutputDevice>(software_device)).release(); |
5790 host_impl_->InitializeRenderer(scoped_ptr<OutputSurface>(output_surface)); | 5798 host_impl_->InitializeRenderer(scoped_ptr<OutputSurface>(output_surface)); |
5791 | 5799 |
5792 output_surface->set_forced_draw_to_software_device(true); | 5800 output_surface->set_forced_draw_to_software_device(true); |
5793 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); | 5801 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); |
5794 | 5802 |
5795 EXPECT_EQ(0, software_device->frames_began_); | 5803 EXPECT_EQ(0, software_device->frames_began_); |
5796 EXPECT_EQ(0, software_device->frames_ended_); | 5804 EXPECT_EQ(0, software_device->frames_ended_); |
5797 | 5805 |
5798 DrawFrame(); | 5806 DrawFrame(); |
5799 | 5807 |
5800 EXPECT_EQ(1, software_device->frames_began_); | 5808 EXPECT_EQ(1, software_device->frames_began_); |
5801 EXPECT_EQ(1, software_device->frames_ended_); | 5809 EXPECT_EQ(1, software_device->frames_ended_); |
5802 | 5810 |
5803 // Call other API methods that are likely to hit NULL pointer in this mode. | 5811 // Call other API methods that are likely to hit NULL pointer in this mode. |
5804 EXPECT_TRUE(host_impl_->AsValue()); | 5812 EXPECT_TRUE(host_impl_->AsValue()); |
5805 EXPECT_TRUE(host_impl_->ActivationStateAsValue()); | 5813 EXPECT_TRUE(host_impl_->ActivationStateAsValue()); |
5806 } | 5814 } |
5807 | 5815 |
5808 TEST_F(LayerTreeHostImplTest, | 5816 TEST_F(LayerTreeHostImplTest, |
5809 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { | 5817 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { |
5810 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( | 5818 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( |
| 5819 scoped_ptr<WebKit::WebGraphicsContext3D>(), |
5811 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release(); | 5820 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release(); |
5812 host_impl_->InitializeRenderer( | 5821 host_impl_->InitializeRenderer( |
5813 scoped_ptr<OutputSurface>(output_surface)); | 5822 scoped_ptr<OutputSurface>(output_surface)); |
5814 | 5823 |
5815 output_surface->set_forced_draw_to_software_device(true); | 5824 output_surface->set_forced_draw_to_software_device(true); |
5816 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); | 5825 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); |
5817 | 5826 |
5818 // SolidColorLayerImpl will be drawn. | 5827 // SolidColorLayerImpl will be drawn. |
5819 scoped_ptr<SolidColorLayerImpl> root_layer = | 5828 scoped_ptr<SolidColorLayerImpl> root_layer = |
5820 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5829 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
(...skipping 10 matching lines...) Expand all Loading... |
5831 | 5840 |
5832 LayerTreeHostImpl::FrameData frame; | 5841 LayerTreeHostImpl::FrameData frame; |
5833 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 5842 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
5834 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); | 5843 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); |
5835 host_impl_->DidDrawAllLayers(frame); | 5844 host_impl_->DidDrawAllLayers(frame); |
5836 | 5845 |
5837 EXPECT_EQ(1u, frame.will_draw_layers.size()); | 5846 EXPECT_EQ(1u, frame.will_draw_layers.size()); |
5838 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); | 5847 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); |
5839 } | 5848 } |
5840 | 5849 |
| 5850 TEST_F(LayerTreeHostImplTest, DeferredInitializeSmoke) { |
| 5851 host_impl_->InitializeRenderer( |
| 5852 scoped_ptr<OutputSurface>(FakeOutputSurface::CreateDeferredGL( |
| 5853 scoped_ptr<WebKit::WebGraphicsContext3D>( |
| 5854 TestWebGraphicsContext3D::Create( |
| 5855 WebKit::WebGraphicsContext3D::Attributes())), |
| 5856 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())))); |
| 5857 |
| 5858 // Add two layers. |
| 5859 scoped_ptr<SolidColorLayerImpl> root_layer = |
| 5860 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 5861 FakeVideoFrameProvider provider; |
| 5862 scoped_ptr<VideoLayerImpl> video_layer = |
| 5863 VideoLayerImpl::Create(host_impl_->active_tree(), 2, &provider); |
| 5864 video_layer->SetBounds(gfx::Size(10, 10)); |
| 5865 video_layer->SetContentBounds(gfx::Size(10, 10)); |
| 5866 video_layer->SetDrawsContent(true); |
| 5867 root_layer->AddChild(video_layer.PassAs<LayerImpl>()); |
| 5868 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| 5869 |
| 5870 // Software draw. |
| 5871 DrawFrame(); |
| 5872 |
| 5873 // DeferredInitialize and hardware draw. |
| 5874 EXPECT_FALSE(did_try_initialize_renderer_); |
| 5875 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>()); |
| 5876 EXPECT_TRUE(did_try_initialize_renderer_); |
| 5877 |
| 5878 // Defer intialized GL draw. |
| 5879 DrawFrame(); |
| 5880 } |
| 5881 |
5841 } // namespace | 5882 } // namespace |
5842 } // namespace cc | 5883 } // namespace cc |
OLD | NEW |