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

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

Issue 647753004: Don't set sent_top_controls_delta when root layer doesn't exist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused variable in unit test Created 6 years, 2 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.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_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 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 clip_size_(layer_size_) { 2243 clip_size_(layer_size_) {
2244 settings_.calculate_top_controls_position = true; 2244 settings_.calculate_top_controls_position = true;
2245 settings_.top_controls_height = 50; 2245 settings_.top_controls_height = 50;
2246 2246
2247 viewport_size_ = 2247 viewport_size_ =
2248 gfx::Size(clip_size_.width(), 2248 gfx::Size(clip_size_.width(),
2249 clip_size_.height() + settings_.top_controls_height); 2249 clip_size_.height() + settings_.top_controls_height);
2250 } 2250 }
2251 2251
2252 void SetupTopControlsAndScrollLayer() { 2252 void SetupTopControlsAndScrollLayer() {
2253 CreateHostImpl(settings_, CreateOutputSurface());
2254
2255 scoped_ptr<LayerImpl> root = 2253 scoped_ptr<LayerImpl> root =
2256 LayerImpl::Create(host_impl_->active_tree(), 1); 2254 LayerImpl::Create(host_impl_->active_tree(), 1);
2257 scoped_ptr<LayerImpl> root_clip = 2255 scoped_ptr<LayerImpl> root_clip =
2258 LayerImpl::Create(host_impl_->active_tree(), 2); 2256 LayerImpl::Create(host_impl_->active_tree(), 2);
2259 root_clip->SetBounds(clip_size_); 2257 root_clip->SetBounds(clip_size_);
2260 root->SetScrollClipLayer(root_clip->id()); 2258 root->SetScrollClipLayer(root_clip->id());
2261 root->SetBounds(layer_size_); 2259 root->SetBounds(layer_size_);
2262 root->SetContentBounds(layer_size_); 2260 root->SetContentBounds(layer_size_);
2263 root->SetPosition(gfx::PointF()); 2261 root->SetPosition(gfx::PointF());
2264 root->SetDrawsContent(false); 2262 root->SetDrawsContent(false);
2265 root->SetIsContainerForFixedPositionLayers(true); 2263 root->SetIsContainerForFixedPositionLayers(true);
2266 int inner_viewport_scroll_layer_id = root->id(); 2264 int inner_viewport_scroll_layer_id = root->id();
2267 int page_scale_layer_id = root_clip->id(); 2265 int page_scale_layer_id = root_clip->id();
2268 root_clip->AddChild(root.Pass()); 2266 root_clip->AddChild(root.Pass());
2269 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 2267 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
2270 host_impl_->active_tree()->SetViewportLayersFromIds( 2268 host_impl_->active_tree()->SetViewportLayersFromIds(
2271 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); 2269 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID);
2272 // Set a viewport size that is large enough to contain both the top controls 2270 // Set a viewport size that is large enough to contain both the top controls
2273 // and some content. 2271 // and some content.
2274 host_impl_->SetViewportSize(viewport_size_); 2272 host_impl_->SetViewportSize(viewport_size_);
2275 host_impl_->SetTopControlsLayoutHeight( 2273 host_impl_->SetTopControlsLayoutHeight(
2276 settings_.top_controls_height); 2274 settings_.top_controls_height);
2277 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2278 EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
2279 2275
2280 host_impl_->CreatePendingTree(); 2276 host_impl_->CreatePendingTree();
2281 root = 2277 root =
2282 LayerImpl::Create(host_impl_->sync_tree(), 1); 2278 LayerImpl::Create(host_impl_->sync_tree(), 1);
2283 root_clip = 2279 root_clip =
2284 LayerImpl::Create(host_impl_->sync_tree(), 2); 2280 LayerImpl::Create(host_impl_->sync_tree(), 2);
2285 root_clip->SetBounds(clip_size_); 2281 root_clip->SetBounds(clip_size_);
2286 root->SetScrollClipLayer(root_clip->id()); 2282 root->SetScrollClipLayer(root_clip->id());
2287 root->SetBounds(layer_size_); 2283 root->SetBounds(layer_size_);
2288 root->SetContentBounds(layer_size_); 2284 root->SetContentBounds(layer_size_);
2289 root->SetPosition(gfx::PointF()); 2285 root->SetPosition(gfx::PointF());
2290 root->SetDrawsContent(false); 2286 root->SetDrawsContent(false);
2291 root->SetIsContainerForFixedPositionLayers(true); 2287 root->SetIsContainerForFixedPositionLayers(true);
2292 inner_viewport_scroll_layer_id = root->id(); 2288 inner_viewport_scroll_layer_id = root->id();
2293 page_scale_layer_id = root_clip->id(); 2289 page_scale_layer_id = root_clip->id();
2294 root_clip->AddChild(root.Pass()); 2290 root_clip->AddChild(root.Pass());
2295 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass()); 2291 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass());
2296 host_impl_->sync_tree()->SetViewportLayersFromIds( 2292 host_impl_->sync_tree()->SetViewportLayersFromIds(
2297 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); 2293 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID);
2298 // Set a viewport size that is large enough to contain both the top controls 2294 // Set a viewport size that is large enough to contain both the top controls
2299 // and some content. 2295 // and some content.
2300 host_impl_->SetViewportSize(viewport_size_); 2296 host_impl_->SetViewportSize(viewport_size_);
2301 host_impl_->sync_tree()->set_top_controls_layout_height( 2297 host_impl_->sync_tree()->set_top_controls_layout_height(
2302 settings_.top_controls_height); 2298 settings_.top_controls_height);
2303 root_clip_ptr = host_impl_->sync_tree()->root_layer();
2304 EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
2305 } 2299 }
2306 2300
2307 protected: 2301 protected:
2308 gfx::Size layer_size_; 2302 gfx::Size layer_size_;
2309 gfx::Size clip_size_; 2303 gfx::Size clip_size_;
2310 gfx::Size viewport_size_; 2304 gfx::Size viewport_size_;
2311 2305
2312 LayerTreeSettings settings_; 2306 LayerTreeSettings settings_;
2313 }; // class LayerTreeHostImplTopControlsTest 2307 }; // class LayerTreeHostImplTopControlsTest
2314 2308
2309 TEST_F(LayerTreeHostImplTopControlsTest,
2310 TopControlsDeltaOnlySentWithRootLayer) {
2311 CreateHostImpl(settings_, CreateOutputSurface());
2312
2313 host_impl_->active_tree()->set_top_controls_delta(-20.f);
2314
2315 // Because LTH::ApplyScrollAndScale doesn't know what to do with a scroll
2316 // delta packet when the root layer doesn't exist yet, make sure not to set
2317 // sent_top_controls_delta either to avoid the delta getting clobbered on the
2318 // next commit.
2319 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
2320 EXPECT_EQ(scroll_info->top_controls_delta, 0.f);
2321 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), 0.f);
2322
2323 SetupTopControlsAndScrollLayer();
2324
2325 // After the root layer exists, it should be set normally.
2326 scroll_info = host_impl_->ProcessScrollDeltas();
2327 EXPECT_EQ(scroll_info->top_controls_delta, -20.f);
2328 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), -20.f);
2329 }
2330
2315 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { 2331 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
2332 CreateHostImpl(settings_, CreateOutputSurface());
2316 SetupTopControlsAndScrollLayer(); 2333 SetupTopControlsAndScrollLayer();
2317 DrawFrame(); 2334 DrawFrame();
2318 2335
2319 EXPECT_EQ(InputHandler::ScrollStarted, 2336 EXPECT_EQ(InputHandler::ScrollStarted,
2320 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2337 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2321 2338
2322 // Make the test scroll delta a fractional amount, to verify that the 2339 // Make the test scroll delta a fractional amount, to verify that the
2323 // fixed container size delta is (1) non-zero, and (2) fractional, and 2340 // fixed container size delta is (1) non-zero, and (2) fractional, and
2324 // (3) matches the movement of the top controls. 2341 // (3) matches the movement of the top controls.
2325 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); 2342 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f);
2326 host_impl_->top_controls_manager()->ScrollBegin(); 2343 host_impl_->top_controls_manager()->ScrollBegin();
2327 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2344 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2328 host_impl_->top_controls_manager()->ScrollEnd(); 2345 host_impl_->top_controls_manager()->ScrollEnd();
2329 2346
2330 LayerImpl* inner_viewport_scroll_layer = 2347 LayerImpl* inner_viewport_scroll_layer =
2331 host_impl_->active_tree()->InnerViewportScrollLayer(); 2348 host_impl_->active_tree()->InnerViewportScrollLayer();
2332 DCHECK(inner_viewport_scroll_layer); 2349 DCHECK(inner_viewport_scroll_layer);
2333 host_impl_->ScrollEnd(); 2350 host_impl_->ScrollEnd();
2334 EXPECT_EQ(top_controls_scroll_delta, 2351 EXPECT_EQ(top_controls_scroll_delta,
2335 inner_viewport_scroll_layer->FixedContainerSizeDelta()); 2352 inner_viewport_scroll_layer->FixedContainerSizeDelta());
2336 } 2353 }
2337 2354
2338 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) { 2355 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) {
2356 CreateHostImpl(settings_, CreateOutputSurface());
2339 SetupTopControlsAndScrollLayer(); 2357 SetupTopControlsAndScrollLayer();
2340 DrawFrame(); 2358 DrawFrame();
2341 2359
2342 EXPECT_EQ(InputHandler::ScrollStarted, 2360 EXPECT_EQ(InputHandler::ScrollStarted,
2343 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2361 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2344 2362
2345 float page_scale = 1.5f; 2363 float page_scale = 1.5f;
2346 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); 2364 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f);
2347 2365
2348 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.f); 2366 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.f);
(...skipping 13 matching lines...) Expand all
2362 double tolerance = 0.0001; 2380 double tolerance = 0.0001;
2363 EXPECT_LT( 2381 EXPECT_LT(
2364 (expected_container_size_delta - 2382 (expected_container_size_delta -
2365 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), 2383 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(),
2366 tolerance); 2384 tolerance);
2367 } 2385 }
2368 2386
2369 // Ensure setting the top controls position explicitly using the setters on the 2387 // Ensure setting the top controls position explicitly using the setters on the
2370 // TreeImpl correctly affects the top controls manager and viewport bounds. 2388 // TreeImpl correctly affects the top controls manager and viewport bounds.
2371 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2389 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2390 CreateHostImpl(settings_, CreateOutputSurface());
2372 SetupTopControlsAndScrollLayer(); 2391 SetupTopControlsAndScrollLayer();
2373 DrawFrame(); 2392 DrawFrame();
2374 2393
2375 host_impl_->active_tree()->set_top_controls_delta(0.f); 2394 host_impl_->active_tree()->set_top_controls_delta(0.f);
2376 host_impl_->active_tree()->set_top_controls_content_offset(30.f); 2395 host_impl_->active_tree()->set_top_controls_content_offset(30.f);
2377 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2396 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset());
2378 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2397 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset());
2379 2398
2380 host_impl_->active_tree()->set_top_controls_delta(-30.f); 2399 host_impl_->active_tree()->set_top_controls_delta(-30.f);
2381 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2400 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2382 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2401 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset());
2383 2402
2384 host_impl_->DidChangeTopControlsPosition(); 2403 host_impl_->DidChangeTopControlsPosition();
2385 2404
2386 // Now that top controls have moved, expect the clip to resize. 2405 // Now that top controls have moved, expect the clip to resize.
2387 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2406 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2388 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2407 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2389 } 2408 }
2390 2409
2391 // Test that the top_controls delta and sent delta are appropriately 2410 // Test that the top_controls delta and sent delta are appropriately
2392 // applied on sync tree activation. The total top controls offset shouldn't 2411 // applied on sync tree activation. The total top controls offset shouldn't
2393 // change after the activation. 2412 // change after the activation.
2394 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { 2413 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
2414 CreateHostImpl(settings_, CreateOutputSurface());
2395 SetupTopControlsAndScrollLayer(); 2415 SetupTopControlsAndScrollLayer();
2396 DrawFrame(); 2416 DrawFrame();
2397 2417
2398 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2418 host_impl_->sync_tree()->set_top_controls_content_offset(15.f);
2399 2419
2400 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2420 host_impl_->active_tree()->set_top_controls_content_offset(20.f);
2401 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2421 host_impl_->active_tree()->set_top_controls_delta(-20.f);
2402 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); 2422 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f);
2403 2423
2404 host_impl_->DidChangeTopControlsPosition(); 2424 host_impl_->DidChangeTopControlsPosition();
(...skipping 14 matching lines...) Expand all
2419 EXPECT_EQ(15.f, host_impl_->active_tree()->top_controls_content_offset()); 2439 EXPECT_EQ(15.f, host_impl_->active_tree()->top_controls_content_offset());
2420 EXPECT_EQ(0.f, 2440 EXPECT_EQ(0.f,
2421 host_impl_->active_tree()->total_top_controls_content_offset()); 2441 host_impl_->active_tree()->total_top_controls_content_offset());
2422 } 2442 }
2423 2443
2424 // Test that changing the top controls layout height is correctly applied to 2444 // Test that changing the top controls layout height is correctly applied to
2425 // the inner viewport container bounds. That is, the top controls layout 2445 // the inner viewport container bounds. That is, the top controls layout
2426 // height is the amount that the inner viewport container was shrunk outside 2446 // height is the amount that the inner viewport container was shrunk outside
2427 // the compositor to accommodate the top controls. 2447 // the compositor to accommodate the top controls.
2428 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { 2448 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
2449 CreateHostImpl(settings_, CreateOutputSurface());
2429 SetupTopControlsAndScrollLayer(); 2450 SetupTopControlsAndScrollLayer();
2430 DrawFrame(); 2451 DrawFrame();
2431 2452
2432 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2453 host_impl_->sync_tree()->set_top_controls_content_offset(15.f);
2433 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); 2454 host_impl_->sync_tree()->set_top_controls_layout_height(15.f);
2434 2455
2435 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2456 host_impl_->active_tree()->set_top_controls_content_offset(20.f);
2436 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2457 host_impl_->active_tree()->set_top_controls_delta(-20.f);
2437 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); 2458 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f);
2438 2459
(...skipping 21 matching lines...) Expand all
2460 host_impl_->DidChangeTopControlsPosition(); 2481 host_impl_->DidChangeTopControlsPosition();
2461 2482
2462 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2483 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset());
2463 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); 2484 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta());
2464 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f), 2485 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f),
2465 root_clip_ptr->bounds()); 2486 root_clip_ptr->bounds());
2466 } 2487 }
2467 2488
2468 TEST_F(LayerTreeHostImplTopControlsTest, 2489 TEST_F(LayerTreeHostImplTopControlsTest,
2469 ScrollNonScrollableRootWithTopControls) { 2490 ScrollNonScrollableRootWithTopControls) {
2491 CreateHostImpl(settings_, CreateOutputSurface());
2470 SetupTopControlsAndScrollLayer(); 2492 SetupTopControlsAndScrollLayer();
2471 DrawFrame(); 2493 DrawFrame();
2472 2494
2473 EXPECT_EQ(InputHandler::ScrollStarted, 2495 EXPECT_EQ(InputHandler::ScrollStarted,
2474 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2496 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2475 2497
2476 host_impl_->top_controls_manager()->ScrollBegin(); 2498 host_impl_->top_controls_manager()->ScrollBegin();
2477 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); 2499 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f));
2478 host_impl_->top_controls_manager()->ScrollEnd(); 2500 host_impl_->top_controls_manager()->ScrollEnd();
2479 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2501 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
(...skipping 4791 matching lines...) Expand 10 before | Expand all | Expand 10 after
7271 // surface. 7293 // surface.
7272 EXPECT_EQ(0, num_lost_surfaces_); 7294 EXPECT_EQ(0, num_lost_surfaces_);
7273 host_impl_->DidLoseOutputSurface(); 7295 host_impl_->DidLoseOutputSurface();
7274 EXPECT_EQ(1, num_lost_surfaces_); 7296 EXPECT_EQ(1, num_lost_surfaces_);
7275 host_impl_->DidLoseOutputSurface(); 7297 host_impl_->DidLoseOutputSurface();
7276 EXPECT_LE(1, num_lost_surfaces_); 7298 EXPECT_LE(1, num_lost_surfaces_);
7277 } 7299 }
7278 7300
7279 } // namespace 7301 } // namespace
7280 } // namespace cc 7302 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698