Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 public: | 64 public: |
| 65 LayerTreeHostImplTest() | 65 LayerTreeHostImplTest() |
| 66 : proxy_(), | 66 : proxy_(), |
| 67 always_impl_thread_(&proxy_), | 67 always_impl_thread_(&proxy_), |
| 68 always_main_thread_blocked_(&proxy_), | 68 always_main_thread_blocked_(&proxy_), |
| 69 on_can_draw_state_changed_called_(false), | 69 on_can_draw_state_changed_called_(false), |
| 70 did_notify_ready_to_activate_(false), | 70 did_notify_ready_to_activate_(false), |
| 71 did_request_commit_(false), | 71 did_request_commit_(false), |
| 72 did_request_redraw_(false), | 72 did_request_redraw_(false), |
| 73 did_upload_visible_tile_(false), | 73 did_upload_visible_tile_(false), |
| 74 did_lose_output_surface_(false), | |
| 74 reduce_memory_result_(true), | 75 reduce_memory_result_(true), |
| 75 current_limit_bytes_(0), | 76 current_limit_bytes_(0), |
| 76 current_priority_cutoff_value_(0) { | 77 current_priority_cutoff_value_(0) { |
| 77 media::InitializeMediaLibraryForTesting(); | 78 media::InitializeMediaLibraryForTesting(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 virtual void SetUp() OVERRIDE { | 81 virtual void SetUp() OVERRIDE { |
| 81 LayerTreeSettings settings; | 82 LayerTreeSettings settings; |
| 82 settings.minimum_occlusion_tracking_size = gfx::Size(); | 83 settings.minimum_occlusion_tracking_size = gfx::Size(); |
| 83 settings.impl_side_painting = true; | 84 settings.impl_side_painting = true; |
| 84 settings.solid_color_scrollbars = true; | 85 settings.solid_color_scrollbars = true; |
| 85 | 86 |
| 86 host_impl_ = LayerTreeHostImpl::Create(settings, | 87 host_impl_ = LayerTreeHostImpl::Create(settings, |
| 87 this, | 88 this, |
| 88 &proxy_, | 89 &proxy_, |
| 89 &stats_instrumentation_); | 90 &stats_instrumentation_); |
| 90 host_impl_->InitializeRenderer(CreateOutputSurface()); | 91 host_impl_->InitializeRenderer(CreateOutputSurface()); |
| 91 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 92 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 92 } | 93 } |
| 93 | 94 |
| 94 virtual void TearDown() OVERRIDE {} | 95 virtual void TearDown() OVERRIDE {} |
| 95 | 96 |
| 96 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} | 97 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { |
| 98 did_lose_output_surface_ = true; | |
| 99 } | |
| 97 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} | 100 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} |
| 98 virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) | 101 virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) |
| 99 OVERRIDE {} | 102 OVERRIDE {} |
| 100 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { | 103 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { |
| 101 on_can_draw_state_changed_called_ = true; | 104 on_can_draw_state_changed_called_ = true; |
| 102 } | 105 } |
| 103 virtual void NotifyReadyToActivate() OVERRIDE { | 106 virtual void NotifyReadyToActivate() OVERRIDE { |
| 104 did_notify_ready_to_activate_ = true; | 107 did_notify_ready_to_activate_ = true; |
| 105 host_impl_->ActivatePendingTree(); | 108 host_impl_->ActivatePendingTree(); |
| 106 } | 109 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 DebugScopedSetImplThread always_impl_thread_; | 347 DebugScopedSetImplThread always_impl_thread_; |
| 345 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 348 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
| 346 | 349 |
| 347 scoped_ptr<LayerTreeHostImpl> host_impl_; | 350 scoped_ptr<LayerTreeHostImpl> host_impl_; |
| 348 FakeRenderingStatsInstrumentation stats_instrumentation_; | 351 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 349 bool on_can_draw_state_changed_called_; | 352 bool on_can_draw_state_changed_called_; |
| 350 bool did_notify_ready_to_activate_; | 353 bool did_notify_ready_to_activate_; |
| 351 bool did_request_commit_; | 354 bool did_request_commit_; |
| 352 bool did_request_redraw_; | 355 bool did_request_redraw_; |
| 353 bool did_upload_visible_tile_; | 356 bool did_upload_visible_tile_; |
| 357 bool did_lose_output_surface_; | |
| 354 bool reduce_memory_result_; | 358 bool reduce_memory_result_; |
| 355 base::TimeDelta requested_scrollbar_animation_delay_; | 359 base::TimeDelta requested_scrollbar_animation_delay_; |
| 356 size_t current_limit_bytes_; | 360 size_t current_limit_bytes_; |
| 357 int current_priority_cutoff_value_; | 361 int current_priority_cutoff_value_; |
| 358 }; | 362 }; |
| 359 | 363 |
| 360 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 364 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
| 361 bool always_draw = false; | 365 bool always_draw = false; |
| 362 CheckNotifyCalledIfCanDrawChanged(always_draw); | 366 CheckNotifyCalledIfCanDrawChanged(always_draw); |
| 363 } | 367 } |
| (...skipping 5856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6220 | 6224 |
| 6221 // Revert back to software. | 6225 // Revert back to software. |
| 6222 output_surface_ptr->ReleaseGL(); | 6226 output_surface_ptr->ReleaseGL(); |
| 6223 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 6227 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 6224 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 6228 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 6225 | 6229 |
| 6226 // Software draw again. | 6230 // Software draw again. |
| 6227 DrawFrame(); | 6231 DrawFrame(); |
| 6228 } | 6232 } |
| 6229 | 6233 |
| 6234 TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_0) { | |
|
boliu
2013/08/28 03:48:17
output_surface_unittests should have a test simila
danakj
2013/08/28 15:36:09
Ya, OutputSurfaceTestInitializeNewContext3d.Client
| |
| 6235 set_reduce_memory_result(false); | |
| 6236 scoped_ptr<FakeOutputSurface> output_surface( | |
| 6237 FakeOutputSurface::CreateDeferredGL( | |
| 6238 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); | |
| 6239 FakeOutputSurface* output_surface_ptr = output_surface.get(); | |
| 6240 EXPECT_TRUE( | |
| 6241 host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); | |
| 6242 | |
| 6243 scoped_ptr<SolidColorLayerImpl> root_layer = | |
| 6244 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | |
| 6245 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | |
| 6246 | |
| 6247 // Software draw. | |
| 6248 DrawFrame(); | |
| 6249 | |
| 6250 scoped_refptr<TestContextProvider> onscreen_context_provider = | |
| 6251 TestContextProvider::Create(); | |
| 6252 scoped_refptr<TestContextProvider> offscreen_context_provider = | |
| 6253 TestContextProvider::Create(); | |
| 6254 | |
| 6255 // Fail initialization of the onscreen context before the OutputSurface binds | |
| 6256 // it to the thread. | |
| 6257 onscreen_context_provider->UnboundTestContext3d() | |
| 6258 ->set_times_make_current_succeeds(0); | |
| 6259 | |
| 6260 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6261 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6262 EXPECT_FALSE(did_lose_output_surface_); | |
| 6263 | |
| 6264 // DeferredInitialize fails. | |
| 6265 EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( | |
| 6266 onscreen_context_provider, offscreen_context_provider)); | |
| 6267 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6268 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6269 | |
| 6270 // Software draw again. | |
| 6271 DrawFrame(); | |
| 6272 } | |
| 6273 | |
| 6274 TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_1) { | |
| 6275 set_reduce_memory_result(false); | |
| 6276 scoped_ptr<FakeOutputSurface> output_surface( | |
| 6277 FakeOutputSurface::CreateDeferredGL( | |
| 6278 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); | |
| 6279 FakeOutputSurface* output_surface_ptr = output_surface.get(); | |
| 6280 EXPECT_TRUE( | |
| 6281 host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); | |
| 6282 | |
| 6283 scoped_ptr<SolidColorLayerImpl> root_layer = | |
| 6284 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | |
| 6285 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | |
| 6286 | |
| 6287 // Software draw. | |
| 6288 DrawFrame(); | |
| 6289 | |
| 6290 scoped_refptr<TestContextProvider> onscreen_context_provider = | |
| 6291 TestContextProvider::Create(); | |
| 6292 scoped_refptr<TestContextProvider> offscreen_context_provider = | |
| 6293 TestContextProvider::Create(); | |
| 6294 | |
| 6295 // Fail initialization of the onscreen context after the OutputSurface binds | |
| 6296 // it to the thread. | |
| 6297 onscreen_context_provider->UnboundTestContext3d() | |
| 6298 ->set_times_make_current_succeeds(2); | |
| 6299 | |
| 6300 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6301 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6302 EXPECT_FALSE(did_lose_output_surface_); | |
| 6303 | |
| 6304 // DeferredInitialize fails. | |
| 6305 EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( | |
| 6306 onscreen_context_provider, offscreen_context_provider)); | |
| 6307 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6308 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6309 | |
| 6310 // We lose the output surface. | |
| 6311 EXPECT_TRUE(did_lose_output_surface_); | |
| 6312 } | |
| 6313 | |
| 6314 TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OnscreenContext_2) { | |
| 6315 set_reduce_memory_result(false); | |
| 6316 scoped_ptr<FakeOutputSurface> output_surface( | |
| 6317 FakeOutputSurface::CreateDeferredGL( | |
| 6318 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); | |
| 6319 FakeOutputSurface* output_surface_ptr = output_surface.get(); | |
| 6320 EXPECT_TRUE( | |
| 6321 host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); | |
| 6322 | |
| 6323 scoped_ptr<SolidColorLayerImpl> root_layer = | |
| 6324 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | |
| 6325 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | |
| 6326 | |
| 6327 // Software draw. | |
| 6328 DrawFrame(); | |
| 6329 | |
| 6330 scoped_refptr<TestContextProvider> onscreen_context_provider = | |
| 6331 TestContextProvider::Create(); | |
| 6332 scoped_refptr<TestContextProvider> offscreen_context_provider = | |
| 6333 TestContextProvider::Create(); | |
| 6334 | |
| 6335 // Fail initialization of the onscreen context after the OutputSurface binds | |
| 6336 // it to the thread and during renderer initialization. | |
| 6337 onscreen_context_provider->UnboundTestContext3d() | |
| 6338 ->set_times_make_current_succeeds(1); | |
| 6339 | |
| 6340 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6341 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6342 EXPECT_FALSE(did_lose_output_surface_); | |
| 6343 | |
| 6344 // DeferredInitialize fails. | |
| 6345 EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( | |
| 6346 onscreen_context_provider, offscreen_context_provider)); | |
| 6347 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6348 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6349 | |
| 6350 // We lose the output surface. | |
| 6351 EXPECT_TRUE(did_lose_output_surface_); | |
| 6352 } | |
| 6353 | |
| 6354 TEST_F(LayerTreeHostImplTest, DeferredInitializeFails_OffscreenContext) { | |
|
boliu
2013/08/28 03:48:17
Load of duplicated code between these 4 tests. Eve
danakj
2013/08/28 15:36:09
Sure!
| |
| 6355 set_reduce_memory_result(false); | |
| 6356 scoped_ptr<FakeOutputSurface> output_surface( | |
| 6357 FakeOutputSurface::CreateDeferredGL( | |
| 6358 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()))); | |
| 6359 FakeOutputSurface* output_surface_ptr = output_surface.get(); | |
| 6360 EXPECT_TRUE( | |
| 6361 host_impl_->InitializeRenderer(output_surface.PassAs<OutputSurface>())); | |
| 6362 | |
| 6363 scoped_ptr<SolidColorLayerImpl> root_layer = | |
| 6364 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | |
| 6365 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | |
| 6366 | |
| 6367 // Software draw. | |
| 6368 DrawFrame(); | |
| 6369 | |
| 6370 scoped_refptr<TestContextProvider> onscreen_context_provider = | |
| 6371 TestContextProvider::Create(); | |
| 6372 scoped_refptr<TestContextProvider> offscreen_context_provider = | |
| 6373 TestContextProvider::Create(); | |
| 6374 | |
| 6375 // Fail initialization of the offscreen context. | |
| 6376 offscreen_context_provider->UnboundTestContext3d() | |
| 6377 ->set_times_make_current_succeeds(0); | |
| 6378 | |
| 6379 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6380 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6381 EXPECT_FALSE(did_lose_output_surface_); | |
| 6382 | |
| 6383 // DeferredInitialize fails. | |
| 6384 EXPECT_FALSE(output_surface_ptr->InitializeAndSetContext3d( | |
| 6385 onscreen_context_provider, offscreen_context_provider)); | |
| 6386 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 6387 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 6388 | |
| 6389 // We lose the output surface. | |
| 6390 EXPECT_TRUE(did_lose_output_surface_); | |
| 6391 } | |
| 6392 | |
| 6230 class ContextThatDoesNotSupportMemoryManagmentExtensions | 6393 class ContextThatDoesNotSupportMemoryManagmentExtensions |
| 6231 : public TestWebGraphicsContext3D { | 6394 : public TestWebGraphicsContext3D { |
| 6232 public: | 6395 public: |
| 6233 // WebGraphicsContext3D methods. | 6396 // WebGraphicsContext3D methods. |
| 6234 virtual WebKit::WebString getString(WebKit::WGC3Denum name) { | 6397 virtual WebKit::WebString getString(WebKit::WGC3Denum name) { |
| 6235 return WebKit::WebString(); | 6398 return WebKit::WebString(); |
| 6236 } | 6399 } |
| 6237 }; | 6400 }; |
| 6238 | 6401 |
| 6239 // Checks that we have a non-0 default allocation if we pass a context that | 6402 // Checks that we have a non-0 default allocation if we pass a context that |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6315 EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(ui_resource_id)); | 6478 EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(ui_resource_id)); |
| 6316 EXPECT_EQ(0u, context3d->NumTextures()); | 6479 EXPECT_EQ(0u, context3d->NumTextures()); |
| 6317 | 6480 |
| 6318 // Should not change state for multiple deletion on one UIResourceId | 6481 // Should not change state for multiple deletion on one UIResourceId |
| 6319 host_impl_->DeleteUIResource(ui_resource_id); | 6482 host_impl_->DeleteUIResource(ui_resource_id); |
| 6320 EXPECT_EQ(0u, context3d->NumTextures()); | 6483 EXPECT_EQ(0u, context3d->NumTextures()); |
| 6321 } | 6484 } |
| 6322 | 6485 |
| 6323 } // namespace | 6486 } // namespace |
| 6324 } // namespace cc | 6487 } // namespace cc |
| OLD | NEW |