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

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

Issue 690493002: cc: Add an integration test for what scale we draw with after pinching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pinchblurmerge-test: compile Created 6 years, 1 month 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
« no previous file with comments | « cc/test/test_web_graphics_context_3d.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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"
32 #include "cc/test/fake_content_layer.h" 33 #include "cc/test/fake_content_layer.h"
33 #include "cc/test/fake_content_layer_client.h" 34 #include "cc/test/fake_content_layer_client.h"
34 #include "cc/test/fake_content_layer_impl.h" 35 #include "cc/test/fake_content_layer_impl.h"
35 #include "cc/test/fake_layer_tree_host_client.h" 36 #include "cc/test/fake_layer_tree_host_client.h"
36 #include "cc/test/fake_output_surface.h" 37 #include "cc/test/fake_output_surface.h"
37 #include "cc/test/fake_painted_scrollbar_layer.h" 38 #include "cc/test/fake_painted_scrollbar_layer.h"
38 #include "cc/test/fake_picture_layer.h" 39 #include "cc/test/fake_picture_layer.h"
(...skipping 5106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5145 } 5146 }
5146 } 5147 }
5147 5148
5148 int commit_count_; 5149 int commit_count_;
5149 TestSwapPromiseResult swap_promise_result_[3]; 5150 TestSwapPromiseResult swap_promise_result_[3];
5150 }; 5151 };
5151 5152
5152 // Impl-side painting is not supported for synchronous compositing. 5153 // Impl-side painting is not supported for synchronous compositing.
5153 SINGLE_THREAD_NOIMPL_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise); 5154 SINGLE_THREAD_NOIMPL_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise);
5154 5155
5156 class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest {
5157 protected:
5158 void InitializeSettings(LayerTreeSettings* settings) override {
5159 settings->impl_side_painting = true;
5160 }
5161
5162 void SetupTree() override {
5163 frame_ = 1;
5164 posted_ = false;
5165 client_.set_fill_with_nonsolid_color(true);
5166
5167 scoped_refptr<Layer> root = Layer::Create();
5168 root->SetBounds(gfx::Size(500, 500));
5169
5170 scoped_refptr<Layer> pinch = Layer::Create();
5171 pinch->SetBounds(gfx::Size(500, 500));
5172 pinch->SetScrollClipLayerId(root->id());
5173 pinch->SetIsContainerForFixedPositionLayers(true);
5174 root->AddChild(pinch);
5175
5176 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_);
5177 layer->SetBounds(gfx::Size(500, 500));
5178 pinch->AddChild(layer);
5179
5180 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch);
5181 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
5182 layer_tree_host()->SetRootLayer(root);
5183 LayerTreeHostTest::SetupTree();
5184 }
5185
5186 float FrameQuadScale(LayerTreeHostImpl::FrameData* frame_data) {
5187 RenderPass* root_pass = frame_data->render_passes.back();
5188 EXPECT_EQ(DrawQuad::TILED_CONTENT, root_pass->quad_list.front()->material);
5189 const TileDrawQuad* quad =
5190 TileDrawQuad::MaterialCast(root_pass->quad_list.front());
5191 float quad_scale =
5192 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
5193 float transform_scale =
5194 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0));
5195 return quad_scale / transform_scale;
5196 }
5197
5198 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
5199
5200 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
5201 LayerTreeHostImpl::FrameData* frame_data,
5202 DrawResult draw_result) override {
5203 switch (frame_) {
5204 case 1:
5205 // Drew at scale 1 before any pinching.
5206 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5207 EXPECT_EQ(1.f, FrameQuadScale(frame_data));
5208 PostNextAfterDraw(host_impl);
5209 break;
5210 case 2:
5211 if (frame_data->has_no_damage || frame_data->contains_incomplete_tile)
5212 break;
5213 // Drew at scale 2.2 after pinching in.
5214 EXPECT_EQ(2.2f, host_impl->active_tree()->total_page_scale_factor());
5215 EXPECT_EQ(1.f, FrameQuadScale(frame_data));
5216 PostNextAfterDraw(host_impl);
5217 break;
5218 case 3:
5219 if (frame_data->has_no_damage || frame_data->contains_incomplete_tile)
5220 break;
5221 // Drew at scale 1 with the 1.1 tiling while pinching out.
5222 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5223 EXPECT_EQ(1.1f, FrameQuadScale(frame_data));
5224 PostNextAfterDraw(host_impl);
5225 break;
5226 case 4:
5227 // Drew at scale 1 with the 1.1 tiling after pinching out completed
5228 // while waiting for texture uploads to complete.
5229 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5230 // This frame may not have any damage, since it's actually the same as
5231 // the last frame, and should contain incomplete tiles. We just want to
5232 // make sure we drew here at least once after the pinch ended to be sure
5233 // that drawing after pinch doesn't leave us at the wrong scale forever.
5234 if (!frame_data->has_no_damage) {
5235 EXPECT_EQ(1.1f, FrameQuadScale(frame_data));
5236 EXPECT_TRUE(frame_data->contains_incomplete_tile);
5237 }
5238 PostNextAfterDraw(host_impl);
5239 break;
5240 case 5:
5241 if (frame_data->has_no_damage || frame_data->contains_incomplete_tile)
5242 break;
5243 // Drew at scale 1 after texture uploads are done.
5244 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5245 EXPECT_EQ(1.f, FrameQuadScale(frame_data));
5246 EndTest();
5247 break;
5248 }
5249 return draw_result;
5250 }
5251
5252 void PostNextAfterDraw(LayerTreeHostImpl* host_impl) {
5253 if (posted_)
5254 return;
5255 posted_ = true;
5256 ImplThreadTaskRunner()->PostDelayedTask(
5257 FROM_HERE,
5258 base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next,
5259 base::Unretained(this),
5260 host_impl),
5261 // Use a delay to allow raster/upload to happen in between frames. This
5262 // should cause flakiness if we fail to block raster/upload when
5263 // desired.
5264 base::TimeDelta::FromMilliseconds(16 * 6));
5265 }
5266
5267 void Next(LayerTreeHostImpl* host_impl) {
5268 ++frame_;
5269 posted_ = false;
5270 switch (frame_) {
5271 case 2:
5272 // Pinch zoom in.
5273 host_impl->PinchGestureBegin();
5274 host_impl->PinchGestureUpdate(2.2f, gfx::Point(100, 100));
5275 host_impl->PinchGestureEnd();
5276 break;
5277 case 3:
5278 // Pinch zoom back but don't end it.
5279 host_impl->PinchGestureBegin();
5280 host_impl->PinchGestureUpdate(1.f / 2.2f, gfx::Point(100, 100));
5281 break;
5282 case 4:
5283 // End the pinch, but delay texture uploads.
5284 TestContext()->set_query_result_available_ext(0);
5285 host_impl->PinchGestureEnd();
5286 break;
5287 case 5:
5288 // Let texture uploads complete.
5289 TestContext()->set_query_result_available_ext(1);
5290 break;
5291 }
5292 }
5293
5294 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
5295 const Tile* tile) override {
5296 // On frame_ == 4, we are preventing texture uploads from completing,
5297 // so this verifies they are not completing before frame_ == 5.
5298 // Flaky failures here indicate we're failing to prevent uploads from
5299 // completing.
5300 EXPECT_NE(4, frame_);
5301 }
5302
5303 void AfterTest() override {}
5304
5305 FakeContentLayerClient client_;
5306 int frame_;
5307 bool posted_;
5308 };
5309
5310 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds);
5311
5155 } // namespace cc 5312 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_web_graphics_context_3d.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698