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.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" |
| 11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
| 12 #include "cc/base/swap_promise.h" | 12 #include "cc/base/swap_promise.h" |
| 13 #include "cc/debug/frame_rate_counter.h" | 13 #include "cc/debug/frame_rate_counter.h" |
| 14 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
| 15 #include "cc/layers/content_layer_client.h" | 15 #include "cc/layers/content_layer_client.h" |
| 16 #include "cc/layers/io_surface_layer.h" | 16 #include "cc/layers/io_surface_layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/layers/painted_scrollbar_layer.h" | 18 #include "cc/layers/painted_scrollbar_layer.h" |
| 19 #include "cc/layers/picture_layer.h" | 19 #include "cc/layers/picture_layer.h" |
| 20 #include "cc/layers/solid_color_layer.h" | 20 #include "cc/layers/solid_color_layer.h" |
| 21 #include "cc/layers/video_layer.h" | 21 #include "cc/layers/video_layer.h" |
| 22 #include "cc/output/begin_frame_args.h" | 22 #include "cc/output/begin_frame_args.h" |
| 23 #include "cc/output/compositor_frame_ack.h" | 23 #include "cc/output/compositor_frame_ack.h" |
| 24 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
| 25 #include "cc/output/copy_output_result.h" | 25 #include "cc/output/copy_output_result.h" |
| 26 #include "cc/output/output_surface.h" | 26 #include "cc/output/output_surface.h" |
| 27 #include "cc/quads/draw_quad.h" | 27 #include "cc/quads/draw_quad.h" |
| 28 #include "cc/quads/io_surface_draw_quad.h" | 28 #include "cc/quads/io_surface_draw_quad.h" |
| 29 #include "cc/quads/tile_draw_quad.h" | |
| 29 #include "cc/resources/prioritized_resource.h" | 30 #include "cc/resources/prioritized_resource.h" |
| 30 #include "cc/resources/prioritized_resource_manager.h" | 31 #include "cc/resources/prioritized_resource_manager.h" |
| 31 #include "cc/resources/resource_update_queue.h" | 32 #include "cc/resources/resource_update_queue.h" |
| 33 #include "cc/test/delayed_raster_trigger.h" | |
| 32 #include "cc/test/fake_content_layer.h" | 34 #include "cc/test/fake_content_layer.h" |
| 33 #include "cc/test/fake_content_layer_client.h" | 35 #include "cc/test/fake_content_layer_client.h" |
| 34 #include "cc/test/fake_content_layer_impl.h" | 36 #include "cc/test/fake_content_layer_impl.h" |
| 35 #include "cc/test/fake_layer_tree_host_client.h" | 37 #include "cc/test/fake_layer_tree_host_client.h" |
| 36 #include "cc/test/fake_output_surface.h" | 38 #include "cc/test/fake_output_surface.h" |
| 37 #include "cc/test/fake_painted_scrollbar_layer.h" | 39 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 38 #include "cc/test/fake_picture_layer.h" | 40 #include "cc/test/fake_picture_layer.h" |
| 39 #include "cc/test/fake_picture_layer_impl.h" | 41 #include "cc/test/fake_picture_layer_impl.h" |
| 40 #include "cc/test/fake_proxy.h" | 42 #include "cc/test/fake_proxy.h" |
| 41 #include "cc/test/fake_scoped_ui_resource.h" | 43 #include "cc/test/fake_scoped_ui_resource.h" |
| (...skipping 5156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5198 | 5200 |
| 5199 void AfterTest() override { | 5201 void AfterTest() override { |
| 5200 EXPECT_TRUE(deltas_sent_to_client_); | 5202 EXPECT_TRUE(deltas_sent_to_client_); |
| 5201 } | 5203 } |
| 5202 | 5204 |
| 5203 ScrollAndScaleSet info_; | 5205 ScrollAndScaleSet info_; |
| 5204 bool deltas_sent_to_client_; | 5206 bool deltas_sent_to_client_; |
| 5205 }; | 5207 }; |
| 5206 | 5208 |
| 5207 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); | 5209 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); |
| 5210 | |
| 5211 class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest { | |
| 5212 protected: | |
| 5213 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 5214 settings->impl_side_painting = true; | |
| 5215 } | |
| 5216 | |
| 5217 void SetupTree() override { | |
| 5218 frame_ = 1; | |
| 5219 posted_ = false; | |
| 5220 client_.set_fill_with_nonsolid_color(true); | |
| 5221 | |
| 5222 scoped_refptr<Layer> root = Layer::Create(); | |
| 5223 root->SetBounds(gfx::Size(500, 500)); | |
| 5224 | |
| 5225 scoped_refptr<Layer> pinch = Layer::Create(); | |
| 5226 pinch->SetBounds(gfx::Size(500, 500)); | |
| 5227 pinch->SetScrollClipLayerId(root->id()); | |
| 5228 pinch->SetIsContainerForFixedPositionLayers(true); | |
| 5229 root->AddChild(pinch); | |
| 5230 | |
| 5231 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_); | |
| 5232 layer->SetBounds(gfx::Size(500, 500)); | |
| 5233 layer->SetContentsOpaque(true); | |
| 5234 layer->SetUseDelayedRaster(&delayed_raster_trigger_); | |
| 5235 pinch->AddChild(layer); | |
| 5236 | |
| 5237 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch); | |
| 5238 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); | |
| 5239 layer_tree_host()->SetRootLayer(root); | |
| 5240 LayerTreeHostTest::SetupTree(); | |
| 5241 } | |
| 5242 | |
| 5243 // Returns the delta scale of all quads in the frame's root pass from their | |
| 5244 // ideal, or 0 if they are not all the same. | |
| 5245 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) { | |
| 5246 if (frame_data->has_no_damage) | |
| 5247 return 0.f; | |
| 5248 float frame_scale = 0.f; | |
| 5249 RenderPass* root_pass = frame_data->render_passes.back(); | |
| 5250 for (const auto& draw_quad : root_pass->quad_list) { | |
| 5251 // Checkerboards mean an incomplete frame. | |
| 5252 if (draw_quad->material != DrawQuad::TILED_CONTENT) | |
| 5253 return 0.f; | |
| 5254 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad); | |
| 5255 float quad_scale = | |
| 5256 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width()); | |
| 5257 float transform_scale = | |
| 5258 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0)); | |
| 5259 float scale = quad_scale / transform_scale; | |
| 5260 if (frame_scale != 0.f && frame_scale != scale) | |
| 5261 return 0.f; | |
| 5262 frame_scale = scale; | |
| 5263 } | |
| 5264 return frame_scale; | |
| 5265 } | |
| 5266 | |
| 5267 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 5268 | |
| 5269 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 5270 LayerTreeHostImpl::FrameData* frame_data, | |
| 5271 DrawResult draw_result) override { | |
| 5272 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data); | |
| 5273 switch (frame_) { | |
| 5274 case 1: | |
| 5275 // Drew at page scale 1 before any pinching. | |
| 5276 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5277 EXPECT_EQ(1.f, quad_scale_delta); | |
| 5278 PostNextAfterDraw(host_impl); | |
| 5279 break; | |
| 5280 case 2: | |
| 5281 if (quad_scale_delta != 1.f) | |
| 5282 break; | |
| 5283 // Drew at page scale 2.2 after pinching in. | |
| 5284 EXPECT_EQ(2.2f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5285 EXPECT_EQ(1.f, quad_scale_delta); | |
| 5286 PostNextAfterDraw(host_impl); | |
| 5287 break; | |
| 5288 case 3: | |
| 5289 if (quad_scale_delta != 2.2f) | |
| 5290 break; | |
| 5291 // Drew at page scale 1 with the 2.2 tiling while pinching out. | |
| 5292 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5293 EXPECT_EQ(2.2f, quad_scale_delta); | |
| 5294 PostNextAfterDraw(host_impl); | |
| 5295 break; | |
| 5296 case 4: | |
| 5297 // Drew at page scale 1 with the 2.2 tiling after pinching out completed | |
| 5298 // while waiting for texture uploads to complete. | |
| 5299 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5300 // This frame will not have any damage, since it's actually the same as | |
| 5301 // the last frame, and should contain no incomplete tiles. We just want | |
| 5302 // to make sure we drew here at least once after the pinch ended to be | |
| 5303 // sure that drawing after pinch doesn't leave us at the wrong scale | |
| 5304 // forever. | |
| 5305 EXPECT_TRUE(frame_data->has_no_damage); | |
| 5306 PostNextAfterDraw(host_impl); | |
| 5307 break; | |
| 5308 case 5: | |
| 5309 if (quad_scale_delta != 1.f) | |
| 5310 break; | |
| 5311 // Drew at scale 1 after texture uploads are done. | |
| 5312 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5313 EXPECT_EQ(1.f, quad_scale_delta); | |
| 5314 EndTest(); | |
| 5315 break; | |
| 5316 } | |
| 5317 return draw_result; | |
| 5318 } | |
| 5319 | |
| 5320 void PostNextAfterDraw(LayerTreeHostImpl* host_impl) { | |
| 5321 if (posted_) | |
| 5322 return; | |
| 5323 posted_ = true; | |
| 5324 ImplThreadTaskRunner()->PostDelayedTask( | |
| 5325 FROM_HERE, base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next, | |
| 5326 base::Unretained(this), host_impl), | |
| 5327 // Use a delay to allow raster/upload to happen in between frames. This | |
| 5328 // should cause flakiness if we fail to block raster/upload when | |
| 5329 // desired. | |
| 5330 base::TimeDelta::FromMilliseconds(16 * 6)); | |
| 5331 } | |
| 5332 | |
| 5333 void Next(LayerTreeHostImpl* host_impl) { | |
| 5334 ++frame_; | |
| 5335 posted_ = false; | |
| 5336 switch (frame_) { | |
| 5337 case 2: | |
| 5338 // Pinch zoom in. | |
| 5339 host_impl->PinchGestureBegin(); | |
| 5340 host_impl->PinchGestureUpdate(2.2f, gfx::Point(100, 100)); | |
| 5341 host_impl->PinchGestureEnd(); | |
| 5342 break; | |
| 5343 case 3: | |
| 5344 // Pinch zoom back to 1.f but don't end it. | |
| 5345 host_impl->PinchGestureBegin(); | |
| 5346 host_impl->PinchGestureUpdate(1.f / 2.2f, gfx::Point(100, 100)); | |
| 5347 break; | |
| 5348 case 4: | |
| 5349 // End the pinch, but delay tile production. | |
| 5350 delayed_raster_trigger_.BeginDelay(); | |
| 5351 host_impl->PinchGestureEnd(); | |
| 5352 break; | |
| 5353 case 5: | |
| 5354 // Let tiles complete. | |
| 5355 delayed_raster_trigger_.EndDelay(); | |
| 5356 // TestContext()->set_query_result_available_ext(1); | |
| 5357 break; | |
| 5358 } | |
| 5359 } | |
| 5360 | |
| 5361 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | |
| 5362 const Tile* tile) override { | |
| 5363 // On frame_ == 4, we are preventing texture uploads from completing, | |
| 5364 // so this verifies they are not completing before frame_ == 5. | |
| 5365 // Flaky failures here indicate we're failing to prevent uploads from | |
| 5366 // completing. | |
| 5367 EXPECT_NE(4, frame_); | |
| 5368 } | |
| 5369 | |
| 5370 void AfterTest() override {} | |
| 5371 | |
| 5372 FakeContentLayerClient client_; | |
| 5373 int frame_; | |
| 5374 bool posted_; | |
| 5375 DelayedRasterTrigger delayed_raster_trigger_; | |
| 5376 }; | |
| 5377 | |
| 5378 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds); | |
| 5379 | |
| 5380 class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy | |
| 5381 : public LayerTreeHostTestCrispUpAfterPinchEnds { | |
| 5382 protected: | |
| 5383 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 5384 settings->impl_side_painting = true; | |
| 5385 settings->use_one_copy = true; | |
| 5386 } | |
| 5387 | |
| 5388 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface( | |
| 5389 bool fallback) override { | |
| 5390 scoped_ptr<TestWebGraphicsContext3D> context3d = | |
| 5391 TestWebGraphicsContext3D::Create(); | |
| 5392 context3d->set_support_image(true); | |
| 5393 context3d->set_support_sync_query(true); | |
| 5394 | |
| 5395 if (delegating_renderer()) | |
| 5396 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); | |
| 5397 else | |
| 5398 return FakeOutputSurface::Create3d(context3d.Pass()); | |
| 5399 } | |
| 5400 }; | |
| 5401 | |
| 5402 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy); | |
| 5403 | |
| 5404 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles | |
| 5405 : public LayerTreeHostTest { | |
| 5406 protected: | |
| 5407 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 5408 settings->impl_side_painting = true; | |
| 5409 } | |
| 5410 | |
| 5411 void SetupTree() override { | |
| 5412 step_ = 1; | |
| 5413 continuous_draws_ = 0; | |
| 5414 client_.set_fill_with_nonsolid_color(true); | |
| 5415 | |
| 5416 scoped_refptr<Layer> root = Layer::Create(); | |
| 5417 root->SetBounds(gfx::Size(500, 500)); | |
| 5418 | |
| 5419 scoped_refptr<Layer> pinch = Layer::Create(); | |
| 5420 pinch->SetBounds(gfx::Size(500, 500)); | |
| 5421 pinch->SetScrollClipLayerId(root->id()); | |
| 5422 pinch->SetIsContainerForFixedPositionLayers(true); | |
| 5423 root->AddChild(pinch); | |
| 5424 | |
| 5425 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_); | |
| 5426 layer->SetBounds(gfx::Size(500, 500)); | |
| 5427 layer->SetContentsOpaque(true); | |
| 5428 layer->SetUseDelayedRaster(&delayed_raster_trigger_); | |
| 5429 pinch->AddChild(layer); | |
| 5430 | |
| 5431 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch); | |
| 5432 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); | |
| 5433 layer_tree_host()->SetRootLayer(root); | |
| 5434 LayerTreeHostTest::SetupTree(); | |
| 5435 } | |
| 5436 | |
| 5437 // Returns the delta scale of all quads in the frame's root pass from their | |
| 5438 // ideal, or 0 if they are not all the same. | |
| 5439 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) { | |
| 5440 if (frame_data->has_no_damage) | |
| 5441 return 0.f; | |
| 5442 float frame_scale = 0.f; | |
| 5443 RenderPass* root_pass = frame_data->render_passes.back(); | |
| 5444 for (const auto& draw_quad : root_pass->quad_list) { | |
| 5445 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad); | |
| 5446 float quad_scale = | |
| 5447 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width()); | |
| 5448 float transform_scale = | |
| 5449 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0)); | |
| 5450 float scale = quad_scale / transform_scale; | |
| 5451 if (frame_scale != 0.f && frame_scale != scale) | |
| 5452 return 0.f; | |
| 5453 frame_scale = scale; | |
| 5454 } | |
| 5455 return frame_scale; | |
| 5456 } | |
| 5457 | |
| 5458 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 5459 | |
| 5460 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 5461 LayerTreeHostImpl::FrameData* frame_data, | |
| 5462 DrawResult draw_result) override { | |
| 5463 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data); | |
| 5464 switch (step_) { | |
| 5465 case 1: | |
| 5466 // Drew at scale 1 before any pinching. | |
| 5467 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5468 EXPECT_EQ(1.f, quad_scale_delta); | |
| 5469 break; | |
| 5470 case 2: | |
| 5471 if (quad_scale_delta != 1.f / 1.5f) | |
| 5472 break; | |
| 5473 // Drew at scale 1 still though the ideal is 1.5. | |
| 5474 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5475 EXPECT_EQ(1.f / 1.5f, quad_scale_delta); | |
| 5476 break; | |
| 5477 case 3: | |
| 5478 // Continuous draws are attempted. | |
| 5479 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5480 if (!frame_data->has_no_damage) | |
| 5481 EXPECT_EQ(1.f / 1.5f, quad_scale_delta); | |
| 5482 break; | |
| 5483 case 4: | |
| 5484 if (quad_scale_delta != 1.f) | |
| 5485 break; | |
| 5486 // Drew at scale 1.5 when all the tiles completed. | |
| 5487 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor()); | |
| 5488 EXPECT_EQ(1.f, quad_scale_delta); | |
| 5489 | |
| 5490 // We should not continue to draw any more. End the test after a timeout | |
| 5491 // to watch for any extraneous draws. | |
| 5492 EndTestAfterDelayMs(16 * 4); | |
|
brianderson
2014/11/10 22:12:31
If there is a failure, this could be flaky, but I
danakj
2014/11/12 20:19:40
Done.
danakj
2014/11/12 20:19:40
Done.
| |
| 5493 ++step_; | |
| 5494 break; | |
| 5495 case 5: | |
| 5496 // No draws should happen once we have a complete frame. | |
| 5497 EXPECT_TRUE(false); | |
|
brianderson
2014/11/10 22:12:31
ADD_FAILURE() << "No draws should happen once we h
danakj
2014/11/12 20:19:40
Done.
| |
| 5498 break; | |
| 5499 } | |
| 5500 return draw_result; | |
| 5501 } | |
| 5502 | |
| 5503 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 5504 switch (step_) { | |
| 5505 case 1: | |
| 5506 // Delay tile production. | |
| 5507 delayed_raster_trigger_.BeginDelay(); | |
| 5508 // Pinch zoom in to cause new tiles to be required. | |
| 5509 host_impl->PinchGestureBegin(); | |
| 5510 host_impl->PinchGestureUpdate(1.5f, gfx::Point(100, 100)); | |
| 5511 host_impl->PinchGestureEnd(); | |
| 5512 ++step_; | |
| 5513 break; | |
| 5514 case 2: | |
| 5515 ++step_; | |
| 5516 break; | |
| 5517 case 3: | |
| 5518 // We should continue to try draw while there are incomplete visible | |
| 5519 // tiles. | |
| 5520 if (++continuous_draws_ > 5) { | |
| 5521 // Allow the tiles to complete. | |
| 5522 delayed_raster_trigger_.EndDelay(); | |
| 5523 ++step_; | |
| 5524 } | |
| 5525 break; | |
| 5526 } | |
| 5527 } | |
| 5528 | |
| 5529 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | |
| 5530 const Tile* tile) override { | |
| 5531 // On step_ == 2, we are preventing texture uploads from completing, | |
| 5532 // so this verifies they are not completing before step_ == 3. | |
| 5533 // Flaky failures here indicate we're failing to prevent uploads from | |
| 5534 // completing. | |
| 5535 EXPECT_NE(2, step_); | |
| 5536 } | |
| 5537 | |
| 5538 void AfterTest() override { EXPECT_GT(continuous_draws_, 5); } | |
| 5539 | |
| 5540 FakeContentLayerClient client_; | |
| 5541 int step_; | |
| 5542 int continuous_draws_; | |
| 5543 DelayedRasterTrigger delayed_raster_trigger_; | |
| 5544 }; | |
| 5545 | |
| 5546 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles); | |
| 5547 | |
| 5208 } // namespace cc | 5548 } // namespace cc |
| OLD | NEW |