Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 14772021: cc::OutputSurfaceClient::InitializeForGL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 host_impl_->PrepareToDraw(&frame_data, gfx::Rect()); 276 host_impl_->PrepareToDraw(&frame_data, gfx::Rect());
271 host_impl_->DidDrawAllLayers(frame_data); 277 host_impl_->DidDrawAllLayers(frame_data);
272 } 278 }
273 279
274 FakeProxy proxy_; 280 FakeProxy proxy_;
275 DebugScopedSetImplThread always_impl_thread_; 281 DebugScopedSetImplThread always_impl_thread_;
276 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; 282 DebugScopedSetMainThreadBlocked always_main_thread_blocked_;
277 283
278 scoped_ptr<LayerTreeHostImpl> host_impl_; 284 scoped_ptr<LayerTreeHostImpl> host_impl_;
279 FakeRenderingStatsInstrumentation stats_instrumentation_; 285 FakeRenderingStatsInstrumentation stats_instrumentation_;
286 bool did_try_initialize_renderer_;
280 bool on_can_draw_state_changed_called_; 287 bool on_can_draw_state_changed_called_;
281 bool has_pending_tree_; 288 bool has_pending_tree_;
282 bool did_request_commit_; 289 bool did_request_commit_;
283 bool did_request_redraw_; 290 bool did_request_redraw_;
284 bool did_upload_visible_tile_; 291 bool did_upload_visible_tile_;
285 bool reduce_memory_result_; 292 bool reduce_memory_result_;
286 }; 293 };
287 294
288 class TestWebGraphicsContext3DMakeCurrentFails 295 class TestWebGraphicsContext3DMakeCurrentFails
289 : public TestWebGraphicsContext3D { 296 : public TestWebGraphicsContext3D {
(...skipping 5491 matching lines...) Expand 10 before | Expand all | Expand 10 after
5781 } 5788 }
5782 5789
5783 int frames_began_, frames_ended_; 5790 int frames_began_, frames_ended_;
5784 }; 5791 };
5785 5792
5786 TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) { 5793 TEST_F(LayerTreeHostImplTest, ForcedDrawToSoftwareDeviceBasicRender) {
5787 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 5794 SetupScrollAndContentsLayers(gfx::Size(100, 100));
5788 host_impl_->SetViewportSize(gfx::Size(50, 50)); 5795 host_impl_->SetViewportSize(gfx::Size(50, 50));
5789 CountingSoftwareDevice* software_device = new CountingSoftwareDevice(); 5796 CountingSoftwareDevice* software_device = new CountingSoftwareDevice();
5790 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( 5797 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL(
5798 scoped_ptr<WebKit::WebGraphicsContext3D>(),
5791 scoped_ptr<SoftwareOutputDevice>(software_device)).release(); 5799 scoped_ptr<SoftwareOutputDevice>(software_device)).release();
5792 host_impl_->InitializeRenderer(scoped_ptr<OutputSurface>(output_surface)); 5800 host_impl_->InitializeRenderer(scoped_ptr<OutputSurface>(output_surface));
5793 5801
5794 output_surface->set_forced_draw_to_software_device(true); 5802 output_surface->set_forced_draw_to_software_device(true);
5795 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); 5803 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice());
5796 5804
5797 EXPECT_EQ(0, software_device->frames_began_); 5805 EXPECT_EQ(0, software_device->frames_began_);
5798 EXPECT_EQ(0, software_device->frames_ended_); 5806 EXPECT_EQ(0, software_device->frames_ended_);
5799 5807
5800 DrawFrame(); 5808 DrawFrame();
5801 5809
5802 EXPECT_EQ(1, software_device->frames_began_); 5810 EXPECT_EQ(1, software_device->frames_began_);
5803 EXPECT_EQ(1, software_device->frames_ended_); 5811 EXPECT_EQ(1, software_device->frames_ended_);
5804 5812
5805 // Call other API methods that are likely to hit NULL pointer in this mode. 5813 // Call other API methods that are likely to hit NULL pointer in this mode.
5806 EXPECT_TRUE(host_impl_->AsValue()); 5814 EXPECT_TRUE(host_impl_->AsValue());
5807 EXPECT_TRUE(host_impl_->ActivationStateAsValue()); 5815 EXPECT_TRUE(host_impl_->ActivationStateAsValue());
5808 } 5816 }
5809 5817
5810 TEST_F(LayerTreeHostImplTest, 5818 TEST_F(LayerTreeHostImplTest,
5811 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { 5819 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) {
5812 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL( 5820 FakeOutputSurface* output_surface = FakeOutputSurface::CreateDeferredGL(
5821 scoped_ptr<WebKit::WebGraphicsContext3D>(),
5813 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release(); 5822 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice())).release();
5814 host_impl_->InitializeRenderer( 5823 host_impl_->InitializeRenderer(
5815 scoped_ptr<OutputSurface>(output_surface)); 5824 scoped_ptr<OutputSurface>(output_surface));
5816 5825
5817 output_surface->set_forced_draw_to_software_device(true); 5826 output_surface->set_forced_draw_to_software_device(true);
5818 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice()); 5827 EXPECT_TRUE(output_surface->ForcedDrawToSoftwareDevice());
5819 5828
5820 // SolidColorLayerImpl will be drawn. 5829 // SolidColorLayerImpl will be drawn.
5821 scoped_ptr<SolidColorLayerImpl> root_layer = 5830 scoped_ptr<SolidColorLayerImpl> root_layer =
5822 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); 5831 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
(...skipping 10 matching lines...) Expand all
5833 5842
5834 LayerTreeHostImpl::FrameData frame; 5843 LayerTreeHostImpl::FrameData frame;
5835 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); 5844 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
5836 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 5845 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
5837 host_impl_->DidDrawAllLayers(frame); 5846 host_impl_->DidDrawAllLayers(frame);
5838 5847
5839 EXPECT_EQ(1u, frame.will_draw_layers.size()); 5848 EXPECT_EQ(1u, frame.will_draw_layers.size());
5840 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); 5849 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]);
5841 } 5850 }
5842 5851
5852 TEST_F(LayerTreeHostImplTest, DeferredInitializeSmoke) {
5853 host_impl_->InitializeRenderer(
5854 scoped_ptr<OutputSurface>(FakeOutputSurface::CreateDeferredGL(
5855 scoped_ptr<WebKit::WebGraphicsContext3D>(
5856 TestWebGraphicsContext3D::Create(
5857 WebKit::WebGraphicsContext3D::Attributes())),
5858 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))));
5859
5860 // Add two layers.
5861 scoped_ptr<SolidColorLayerImpl> root_layer =
5862 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
5863 FakeVideoFrameProvider provider;
5864 scoped_ptr<VideoLayerImpl> video_layer =
5865 VideoLayerImpl::Create(host_impl_->active_tree(), 2, &provider);
5866 video_layer->SetBounds(gfx::Size(10, 10));
5867 video_layer->SetContentBounds(gfx::Size(10, 10));
5868 video_layer->SetDrawsContent(true);
5869 root_layer->AddChild(video_layer.PassAs<LayerImpl>());
5870 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>());
5871
5872 // Software draw.
5873 DrawFrame();
5874
5875 // DeferredInitialize and hardware draw.
5876 EXPECT_FALSE(did_try_initialize_renderer_);
5877 host_impl_->DeferredInitialize(scoped_refptr<ContextProvider>());
5878 EXPECT_TRUE(did_try_initialize_renderer_);
5879
5880 // Defer intialized GL draw.
5881 DrawFrame();
5882 }
5883
5843 } // namespace 5884 } // namespace
5844 } // namespace cc 5885 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698