| 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.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 | 1313 |
| 1314 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. | 1314 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| 1315 // Verify atomicity of commits and reuse of textures. | 1315 // Verify atomicity of commits and reuse of textures. |
| 1316 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { | 1316 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
| 1317 public: | 1317 public: |
| 1318 void InitializeSettings(LayerTreeSettings* settings) override { | 1318 void InitializeSettings(LayerTreeSettings* settings) override { |
| 1319 settings->renderer_settings.texture_id_allocation_chunk_size = 1; | 1319 settings->renderer_settings.texture_id_allocation_chunk_size = 1; |
| 1320 // Make sure partial texture updates are turned off. | 1320 // Make sure partial texture updates are turned off. |
| 1321 settings->max_partial_texture_updates = 0; | 1321 settings->max_partial_texture_updates = 0; |
| 1322 // Linear fade animator prevents scrollbars from drawing immediately. | 1322 // Linear fade animator prevents scrollbars from drawing immediately. |
| 1323 settings->scrollbar_animator = LayerTreeSettings::NO_ANIMATOR; | 1323 settings->scrollbar_animator = LayerTreeSettings::NoAnimator; |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 void SetupTree() override { | 1326 void SetupTree() override { |
| 1327 layer_ = FakeContentLayer::Create(&client_); | 1327 layer_ = FakeContentLayer::Create(&client_); |
| 1328 layer_->SetBounds(gfx::Size(10, 20)); | 1328 layer_->SetBounds(gfx::Size(10, 20)); |
| 1329 | 1329 |
| 1330 bool paint_scrollbar = true; | 1330 bool paint_scrollbar = true; |
| 1331 bool has_thumb = false; | 1331 bool has_thumb = false; |
| 1332 scrollbar_ = FakePaintedScrollbarLayer::Create( | 1332 scrollbar_ = FakePaintedScrollbarLayer::Create( |
| 1333 paint_scrollbar, has_thumb, layer_->id()); | 1333 paint_scrollbar, has_thumb, layer_->id()); |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 scoped_refptr<FakeContentLayer> child_layer1_; | 2316 scoped_refptr<FakeContentLayer> child_layer1_; |
| 2317 scoped_refptr<FakeContentLayer> child_layer2_; | 2317 scoped_refptr<FakeContentLayer> child_layer2_; |
| 2318 int num_commits_; | 2318 int num_commits_; |
| 2319 }; | 2319 }; |
| 2320 | 2320 |
| 2321 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2321 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
| 2322 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2322 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
| 2323 | 2323 |
| 2324 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { | 2324 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { |
| 2325 public: | 2325 public: |
| 2326 class PaintClient : public FakeContentLayerClient { |
| 2327 public: |
| 2328 PaintClient() : paint_count_(0) {} |
| 2329 |
| 2330 int paint_count() const { return paint_count_; } |
| 2331 |
| 2332 void PaintContents(SkCanvas* canvas, |
| 2333 const gfx::Rect& clip, |
| 2334 PaintingControlSetting picture_control) override { |
| 2335 FakeContentLayerClient::PaintContents(canvas, clip, picture_control); |
| 2336 ++paint_count_; |
| 2337 } |
| 2338 |
| 2339 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 2340 const gfx::Rect& clip, |
| 2341 PaintingControlSetting picture_control) override { |
| 2342 NOTIMPLEMENTED(); |
| 2343 return DisplayItemList::Create(); |
| 2344 } |
| 2345 |
| 2346 bool FillsBoundsCompletely() const override { return false; } |
| 2347 |
| 2348 private: |
| 2349 int paint_count_; |
| 2350 }; |
| 2351 |
| 2326 void SetupTree() override { | 2352 void SetupTree() override { |
| 2327 num_tiles_rastered_ = 0; | 2353 num_tiles_rastered_ = 0; |
| 2328 | 2354 |
| 2329 scoped_refptr<Layer> root_layer = PictureLayer::Create(&client_); | 2355 scoped_refptr<Layer> root_layer; |
| 2356 if (layer_tree_host()->settings().impl_side_painting) |
| 2357 root_layer = PictureLayer::Create(&client_); |
| 2358 else |
| 2359 root_layer = ContentLayer::Create(&client_); |
| 2330 client_.set_fill_with_nonsolid_color(true); | 2360 client_.set_fill_with_nonsolid_color(true); |
| 2331 root_layer->SetIsDrawable(true); | 2361 root_layer->SetIsDrawable(true); |
| 2332 root_layer->SetBounds(gfx::Size(10, 10)); | 2362 root_layer->SetBounds(gfx::Size(10, 10)); |
| 2333 root_layer->SetContentsOpaque(true); | 2363 root_layer->SetContentsOpaque(true); |
| 2334 | 2364 |
| 2335 layer_tree_host()->SetRootLayer(root_layer); | 2365 layer_tree_host()->SetRootLayer(root_layer); |
| 2336 | 2366 |
| 2337 // The expectations are based on the assumption that the default | 2367 // The expecations are based on the assumption that the default |
| 2338 // LCD settings are: | 2368 // LCD settings are: |
| 2339 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2369 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
| 2370 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
| 2340 | 2371 |
| 2341 LayerTreeHostTest::SetupTree(); | 2372 LayerTreeHostTest::SetupTree(); |
| 2342 } | 2373 } |
| 2343 | 2374 |
| 2344 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2375 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 2345 | 2376 |
| 2346 void DidCommitAndDrawFrame() override { | 2377 void DidCommitAndDrawFrame() override { |
| 2347 switch (layer_tree_host()->source_frame_number()) { | 2378 switch (layer_tree_host()->source_frame_number()) { |
| 2348 case 1: | 2379 case 1: |
| 2380 // The first update consists of a paint of the whole layer. |
| 2381 EXPECT_EQ(1, client_.paint_count()); |
| 2382 // LCD text must have been enabled on the layer. |
| 2383 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
| 2349 PostSetNeedsCommitToMainThread(); | 2384 PostSetNeedsCommitToMainThread(); |
| 2350 break; | 2385 break; |
| 2351 case 2: | 2386 case 2: |
| 2387 // Since nothing changed on layer, there should be no paint. |
| 2388 EXPECT_EQ(1, client_.paint_count()); |
| 2389 // LCD text must not have changed. |
| 2390 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
| 2352 // Change layer opacity that should trigger lcd change. | 2391 // Change layer opacity that should trigger lcd change. |
| 2353 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2392 layer_tree_host()->root_layer()->SetOpacity(.5f); |
| 2354 break; | 2393 break; |
| 2355 case 3: | 2394 case 3: |
| 2395 // LCD text doesn't require re-recording, so no painting should occur. |
| 2396 EXPECT_EQ(1, client_.paint_count()); |
| 2397 // LCD text must have been disabled on the layer due to opacity. |
| 2398 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
| 2356 // Change layer opacity that should not trigger lcd change. | 2399 // Change layer opacity that should not trigger lcd change. |
| 2357 layer_tree_host()->root_layer()->SetOpacity(1.f); | 2400 layer_tree_host()->root_layer()->SetOpacity(1.f); |
| 2358 break; | 2401 break; |
| 2359 case 4: | 2402 case 4: |
| 2403 // LCD text doesn't require re-recording, so no painting should occur. |
| 2404 EXPECT_EQ(1, client_.paint_count()); |
| 2405 // Even though LCD text could be allowed. |
| 2406 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
| 2360 EndTest(); | 2407 EndTest(); |
| 2361 break; | 2408 break; |
| 2362 } | 2409 } |
| 2363 } | 2410 } |
| 2364 | 2411 |
| 2365 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | 2412 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |
| 2366 const Tile* tile) override { | 2413 const Tile* tile) override { |
| 2367 ++num_tiles_rastered_; | 2414 ++num_tiles_rastered_; |
| 2368 } | 2415 } |
| 2369 | 2416 |
| 2370 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 2417 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 2371 PictureLayerImpl* root_layer = | |
| 2372 static_cast<PictureLayerImpl*>(host_impl->active_tree()->root_layer()); | |
| 2373 bool can_use_lcd_text = | |
| 2374 host_impl->active_tree()->root_layer()->can_use_lcd_text(); | |
| 2375 switch (host_impl->active_tree()->source_frame_number()) { | 2418 switch (host_impl->active_tree()->source_frame_number()) { |
| 2376 case 0: | 2419 case 0: |
| 2377 // The first draw. | 2420 // The first draw. |
| 2378 EXPECT_EQ(1, num_tiles_rastered_); | 2421 EXPECT_EQ(1, num_tiles_rastered_); |
| 2379 EXPECT_TRUE(can_use_lcd_text); | |
| 2380 EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); | |
| 2381 break; | 2422 break; |
| 2382 case 1: | 2423 case 1: |
| 2383 // Nothing changed on the layer. | 2424 // Nothing changed on the layer. |
| 2384 EXPECT_EQ(1, num_tiles_rastered_); | 2425 EXPECT_EQ(1, num_tiles_rastered_); |
| 2385 EXPECT_TRUE(can_use_lcd_text); | |
| 2386 EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); | |
| 2387 break; | 2426 break; |
| 2388 case 2: | 2427 case 2: |
| 2389 // LCD text was disabled; it should be re-rastered with LCD text off. | 2428 // LCD text was disabled, it should be re-rastered with LCD text off. |
| 2390 EXPECT_EQ(2, num_tiles_rastered_); | 2429 EXPECT_EQ(2, num_tiles_rastered_); |
| 2391 EXPECT_FALSE(can_use_lcd_text); | |
| 2392 EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); | |
| 2393 break; | 2430 break; |
| 2394 case 3: | 2431 case 3: |
| 2395 // LCD text was enabled, but it's sticky and stays off. | 2432 // LCD text was enabled but it's sticky and stays off. |
| 2396 EXPECT_EQ(2, num_tiles_rastered_); | 2433 EXPECT_EQ(2, num_tiles_rastered_); |
| 2397 EXPECT_TRUE(can_use_lcd_text); | |
| 2398 EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); | |
| 2399 break; | 2434 break; |
| 2400 } | 2435 } |
| 2401 } | 2436 } |
| 2402 | 2437 |
| 2403 void AfterTest() override {} | 2438 void AfterTest() override {} |
| 2404 | 2439 |
| 2405 private: | 2440 private: |
| 2406 FakeContentLayerClient client_; | 2441 PaintClient client_; |
| 2407 int num_tiles_rastered_; | 2442 int num_tiles_rastered_; |
| 2408 }; | 2443 }; |
| 2409 | 2444 |
| 2410 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); | 2445 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); |
| 2411 | 2446 |
| 2412 // Verify that the BeginFrame notification is used to initiate rendering. | 2447 // Verify that the BeginFrame notification is used to initiate rendering. |
| 2413 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2448 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
| 2414 public: | 2449 public: |
| 2415 void InitializeSettings(LayerTreeSettings* settings) override { | 2450 void InitializeSettings(LayerTreeSettings* settings) override { |
| 2416 settings->use_external_begin_frame_source = true; | 2451 settings->use_external_begin_frame_source = true; |
| (...skipping 3837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6254 } | 6289 } |
| 6255 | 6290 |
| 6256 void AfterTest() override { EXPECT_TRUE(did_commit_); } | 6291 void AfterTest() override { EXPECT_TRUE(did_commit_); } |
| 6257 | 6292 |
| 6258 private: | 6293 private: |
| 6259 bool did_commit_; | 6294 bool did_commit_; |
| 6260 }; | 6295 }; |
| 6261 | 6296 |
| 6262 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); | 6297 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); |
| 6263 | 6298 |
| 6264 // Verify that if a LayerImpl holds onto a copy request for multiple | |
| 6265 // frames that it will continue to have a render surface through | |
| 6266 // multiple commits, even though the Layer itself has no reason | |
| 6267 // to have a render surface. | |
| 6268 class LayerPreserveRenderSurfaceFromOutputRequests : public LayerTreeHostTest { | |
| 6269 protected: | |
| 6270 void SetupTree() override { | |
| 6271 scoped_refptr<Layer> root = Layer::Create(); | |
| 6272 root->CreateRenderSurface(); | |
| 6273 root->SetBounds(gfx::Size(10, 10)); | |
| 6274 child_ = Layer::Create(); | |
| 6275 child_->SetBounds(gfx::Size(20, 20)); | |
| 6276 root->AddChild(child_); | |
| 6277 | |
| 6278 layer_tree_host()->SetRootLayer(root); | |
| 6279 LayerTreeHostTest::SetupTree(); | |
| 6280 } | |
| 6281 | |
| 6282 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} | |
| 6283 | |
| 6284 void BeginTest() override { | |
| 6285 child_->RequestCopyOfOutput( | |
| 6286 CopyOutputRequest::CreateBitmapRequest(base::Bind(CopyOutputCallback))); | |
| 6287 EXPECT_TRUE(child_->HasCopyRequest()); | |
| 6288 PostSetNeedsCommitToMainThread(); | |
| 6289 } | |
| 6290 | |
| 6291 void DidCommit() override { EXPECT_FALSE(child_->HasCopyRequest()); } | |
| 6292 | |
| 6293 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 6294 LayerImpl* child_impl = host_impl->sync_tree()->LayerById(child_->id()); | |
| 6295 | |
| 6296 switch (host_impl->sync_tree()->source_frame_number()) { | |
| 6297 case 0: | |
| 6298 EXPECT_TRUE(child_impl->HasCopyRequest()); | |
| 6299 EXPECT_TRUE(child_impl->render_surface()); | |
| 6300 break; | |
| 6301 case 1: | |
| 6302 if (host_impl->proxy()->CommitToActiveTree()) { | |
| 6303 EXPECT_TRUE(child_impl->HasCopyRequest()); | |
| 6304 EXPECT_TRUE(child_impl->render_surface()); | |
| 6305 } else { | |
| 6306 EXPECT_FALSE(child_impl->HasCopyRequest()); | |
| 6307 EXPECT_FALSE(child_impl->render_surface()); | |
| 6308 } | |
| 6309 break; | |
| 6310 default: | |
| 6311 NOTREACHED(); | |
| 6312 break; | |
| 6313 } | |
| 6314 } | |
| 6315 | |
| 6316 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | |
| 6317 LayerImpl* child_impl = host_impl->active_tree()->LayerById(child_->id()); | |
| 6318 EXPECT_TRUE(child_impl->HasCopyRequest()); | |
| 6319 EXPECT_TRUE(child_impl->render_surface()); | |
| 6320 | |
| 6321 switch (host_impl->active_tree()->source_frame_number()) { | |
| 6322 case 0: | |
| 6323 // Lose output surface to prevent drawing and cause another commit. | |
| 6324 host_impl->DidLoseOutputSurface(); | |
| 6325 break; | |
| 6326 case 1: | |
| 6327 EndTest(); | |
| 6328 break; | |
| 6329 default: | |
| 6330 NOTREACHED(); | |
| 6331 break; | |
| 6332 } | |
| 6333 } | |
| 6334 | |
| 6335 void AfterTest() override {} | |
| 6336 | |
| 6337 private: | |
| 6338 scoped_refptr<Layer> child_; | |
| 6339 }; | |
| 6340 | |
| 6341 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); | |
| 6342 | |
| 6343 } // namespace cc | 6299 } // namespace cc |
| OLD | NEW |