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

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

Issue 1418273002: cc: Move draw params from SetExternalDrawConstraints to OnDraw (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ForTesting Created 5 years 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
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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "cc/animation/scrollbar_animation_controller_thinning.h" 17 #include "cc/animation/scrollbar_animation_controller_thinning.h"
17 #include "cc/animation/transform_operations.h" 18 #include "cc/animation/transform_operations.h"
18 #include "cc/base/math_util.h" 19 #include "cc/base/math_util.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 void TearDown() override {} 112 void TearDown() override {}
112 113
113 void UpdateRendererCapabilitiesOnImplThread() override {} 114 void UpdateRendererCapabilitiesOnImplThread() override {}
114 void DidLoseOutputSurfaceOnImplThread() override {} 115 void DidLoseOutputSurfaceOnImplThread() override {}
115 void CommitVSyncParameters(base::TimeTicks timebase, 116 void CommitVSyncParameters(base::TimeTicks timebase,
116 base::TimeDelta interval) override {} 117 base::TimeDelta interval) override {}
117 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {} 118 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {}
118 void DidSwapBuffersOnImplThread() override {} 119 void DidSwapBuffersOnImplThread() override {}
119 void DidSwapBuffersCompleteOnImplThread() override {} 120 void DidSwapBuffersCompleteOnImplThread() override {}
120 void OnResourcelessSoftareDrawStateChanged(bool resourceless_draw) override {}
121 void OnCanDrawStateChanged(bool can_draw) override { 121 void OnCanDrawStateChanged(bool can_draw) override {
122 on_can_draw_state_changed_called_ = true; 122 on_can_draw_state_changed_called_ = true;
123 } 123 }
124 void NotifyReadyToActivate() override { 124 void NotifyReadyToActivate() override {
125 did_notify_ready_to_activate_ = true; 125 did_notify_ready_to_activate_ = true;
126 host_impl_->ActivateSyncTree(); 126 host_impl_->ActivateSyncTree();
127 } 127 }
128 void NotifyReadyToDraw() override {} 128 void NotifyReadyToDraw() override {}
129 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } 129 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; }
130 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { 130 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override {
(...skipping 15 matching lines...) Expand all
146 base::TimeDelta delay) override { 146 base::TimeDelta delay) override {
147 animation_task_ = task; 147 animation_task_ = task;
148 requested_animation_delay_ = delay; 148 requested_animation_delay_ = delay;
149 } 149 }
150 void DidActivateSyncTree() override {} 150 void DidActivateSyncTree() override {}
151 void WillPrepareTiles() override {} 151 void WillPrepareTiles() override {}
152 void DidPrepareTiles() override {} 152 void DidPrepareTiles() override {}
153 void DidCompletePageScaleAnimationOnImplThread() override { 153 void DidCompletePageScaleAnimationOnImplThread() override {
154 did_complete_page_scale_animation_ = true; 154 did_complete_page_scale_animation_ = true;
155 } 155 }
156 void OnDrawForOutputSurface() override {} 156 void OnDrawForOutputSurface(bool resourceless_software_draw) override {
157 scoped_ptr<LayerTreeHostImpl::FrameData> frame(
158 new LayerTreeHostImpl::FrameData);
159 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(frame.get()));
160 host_impl_->DrawLayers(frame.get());
161 host_impl_->DidDrawAllLayers(*frame);
162 host_impl_->SwapBuffers(*frame);
163 last_on_draw_frame_ = std::move(frame);
164 }
157 void PostFrameTimingEventsOnImplThread( 165 void PostFrameTimingEventsOnImplThread(
158 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 166 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
159 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) 167 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
160 override {} 168 override {}
161 169
162 void set_reduce_memory_result(bool reduce_memory_result) { 170 void set_reduce_memory_result(bool reduce_memory_result) {
163 reduce_memory_result_ = reduce_memory_result; 171 reduce_memory_result_ = reduce_memory_result;
164 } 172 }
165 173
166 virtual bool CreateHostImpl(const LayerTreeSettings& settings, 174 virtual bool CreateHostImpl(const LayerTreeSettings& settings,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 RebuildPropertyTrees(); 385 RebuildPropertyTrees();
378 return host_impl_->PrepareToDraw(frame); 386 return host_impl_->PrepareToDraw(frame);
379 } 387 }
380 388
381 void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor); 389 void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor);
382 void pinch_zoom_pan_viewport_test(float device_scale_factor); 390 void pinch_zoom_pan_viewport_test(float device_scale_factor);
383 void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor); 391 void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor);
384 void pinch_zoom_pan_viewport_and_scroll_boundary_test( 392 void pinch_zoom_pan_viewport_and_scroll_boundary_test(
385 float device_scale_factor); 393 float device_scale_factor);
386 394
387 void CheckNotifyCalledIfCanDrawChanged(bool always_draw) {
388 // Note: It is not possible to disable the renderer once it has been set,
389 // so we do not need to test that disabling the renderer notifies us
390 // that can_draw changed.
391 EXPECT_FALSE(host_impl_->CanDraw());
392 on_can_draw_state_changed_called_ = false;
393
394 // Set up the root layer, which allows us to draw.
395 SetupScrollAndContentsLayers(gfx::Size(100, 100));
396 EXPECT_TRUE(host_impl_->CanDraw());
397 EXPECT_TRUE(on_can_draw_state_changed_called_);
398 on_can_draw_state_changed_called_ = false;
399
400 // Toggle the root layer to make sure it toggles can_draw
401 host_impl_->active_tree()->SetRootLayer(nullptr);
402 EXPECT_FALSE(host_impl_->CanDraw());
403 EXPECT_TRUE(on_can_draw_state_changed_called_);
404 on_can_draw_state_changed_called_ = false;
405
406 SetupScrollAndContentsLayers(gfx::Size(100, 100));
407 EXPECT_TRUE(host_impl_->CanDraw());
408 EXPECT_TRUE(on_can_draw_state_changed_called_);
409 on_can_draw_state_changed_called_ = false;
410
411 // Toggle the device viewport size to make sure it toggles can_draw.
412 host_impl_->SetViewportSize(gfx::Size());
413 if (always_draw) {
414 EXPECT_TRUE(host_impl_->CanDraw());
415 } else {
416 EXPECT_FALSE(host_impl_->CanDraw());
417 }
418 EXPECT_TRUE(on_can_draw_state_changed_called_);
419 on_can_draw_state_changed_called_ = false;
420
421 host_impl_->SetViewportSize(gfx::Size(100, 100));
422 EXPECT_TRUE(host_impl_->CanDraw());
423 EXPECT_TRUE(on_can_draw_state_changed_called_);
424 on_can_draw_state_changed_called_ = false;
425 }
426
427 void SetupMouseMoveAtWithDeviceScale(float device_scale_factor); 395 void SetupMouseMoveAtWithDeviceScale(float device_scale_factor);
428 396
429 protected: 397 protected:
430 virtual scoped_ptr<OutputSurface> CreateOutputSurface() { 398 virtual scoped_ptr<OutputSurface> CreateOutputSurface() {
431 return FakeOutputSurface::Create3d(); 399 return FakeOutputSurface::Create3d();
432 } 400 }
433 401
434 void DrawOneFrame() { 402 void DrawOneFrame() {
435 LayerTreeHostImpl::FrameData frame_data; 403 LayerTreeHostImpl::FrameData frame_data;
436 PrepareToDrawFrame(&frame_data); 404 PrepareToDrawFrame(&frame_data);
(...skipping 12 matching lines...) Expand all
449 bool on_can_draw_state_changed_called_; 417 bool on_can_draw_state_changed_called_;
450 bool did_notify_ready_to_activate_; 418 bool did_notify_ready_to_activate_;
451 bool did_request_commit_; 419 bool did_request_commit_;
452 bool did_request_redraw_; 420 bool did_request_redraw_;
453 bool did_request_next_frame_; 421 bool did_request_next_frame_;
454 bool did_request_prepare_tiles_; 422 bool did_request_prepare_tiles_;
455 bool did_complete_page_scale_animation_; 423 bool did_complete_page_scale_animation_;
456 bool reduce_memory_result_; 424 bool reduce_memory_result_;
457 base::Closure animation_task_; 425 base::Closure animation_task_;
458 base::TimeDelta requested_animation_delay_; 426 base::TimeDelta requested_animation_delay_;
427 scoped_ptr<LayerTreeHostImpl::FrameData> last_on_draw_frame_;
459 }; 428 };
460 429
461 // A test fixture for new animation timelines tests. 430 // A test fixture for new animation timelines tests.
462 class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest { 431 class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest {
463 public: 432 public:
464 void SetUp() override { 433 void SetUp() override {
465 LayerTreeSettings settings = DefaultSettings(); 434 LayerTreeSettings settings = DefaultSettings();
466 settings.use_compositor_animation_timelines = true; 435 settings.use_compositor_animation_timelines = true;
467 CreateHostImpl(settings, CreateOutputSurface()); 436 CreateHostImpl(settings, CreateOutputSurface());
468 } 437 }
469 }; 438 };
470 439
471 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { 440 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) {
472 bool always_draw = false; 441 // Note: It is not possible to disable the renderer once it has been set,
473 CheckNotifyCalledIfCanDrawChanged(always_draw); 442 // so we do not need to test that disabling the renderer notifies us
443 // that can_draw changed.
444 EXPECT_FALSE(host_impl_->CanDraw());
445 on_can_draw_state_changed_called_ = false;
446
447 // Set up the root layer, which allows us to draw.
448 SetupScrollAndContentsLayers(gfx::Size(100, 100));
449 EXPECT_TRUE(host_impl_->CanDraw());
450 EXPECT_TRUE(on_can_draw_state_changed_called_);
451 on_can_draw_state_changed_called_ = false;
452
453 // Toggle the root layer to make sure it toggles can_draw
454 host_impl_->active_tree()->SetRootLayer(nullptr);
455 EXPECT_FALSE(host_impl_->CanDraw());
456 EXPECT_TRUE(on_can_draw_state_changed_called_);
457 on_can_draw_state_changed_called_ = false;
458
459 SetupScrollAndContentsLayers(gfx::Size(100, 100));
460 EXPECT_TRUE(host_impl_->CanDraw());
461 EXPECT_TRUE(on_can_draw_state_changed_called_);
462 on_can_draw_state_changed_called_ = false;
463
464 // Toggle the device viewport size to make sure it toggles can_draw.
465 host_impl_->SetViewportSize(gfx::Size());
466 EXPECT_FALSE(host_impl_->CanDraw());
467 EXPECT_TRUE(on_can_draw_state_changed_called_);
468 on_can_draw_state_changed_called_ = false;
469
470 host_impl_->SetViewportSize(gfx::Size(100, 100));
471 EXPECT_TRUE(host_impl_->CanDraw());
472 EXPECT_TRUE(on_can_draw_state_changed_called_);
473 on_can_draw_state_changed_called_ = false;
474 } 474 }
475 475
476 TEST_F(LayerTreeHostImplTest, CanDrawIncompleteFrames) { 476 TEST_F(LayerTreeHostImplTest, ResourcelessDrawWithEmptyViewport) {
boliu 2015/12/15 23:46:45 Rewrote this test. Previous one was basically test
477 CreateHostImpl(DefaultSettings(), 477 CreateHostImpl(DefaultSettings(),
478 FakeOutputSurface::CreateSoftware( 478 FakeOutputSurface::CreateSoftware(
479 make_scoped_ptr(new SoftwareOutputDevice()))); 479 make_scoped_ptr(new SoftwareOutputDevice())));
480 const gfx::Transform external_transform; 480 SetupScrollAndContentsLayers(gfx::Size(100, 100));
481 const gfx::Rect external_viewport; 481 EXPECT_TRUE(host_impl_->CanDraw());
482 const gfx::Rect external_clip; 482 host_impl_->SetViewportSize(gfx::Size());
483 EXPECT_FALSE(host_impl_->CanDraw());
484
485 FakeOutputSurface* fake_output_surface =
486 static_cast<FakeOutputSurface*>(host_impl_->output_surface());
487 EXPECT_EQ(fake_output_surface->num_sent_frames(), 0u);
488 gfx::Transform identity;
489 gfx::Rect viewport(100, 100);
483 const bool resourceless_software_draw = true; 490 const bool resourceless_software_draw = true;
484 host_impl_->SetExternalDrawConstraints( 491 host_impl_->OnDraw(identity, viewport, viewport, resourceless_software_draw);
485 external_transform, external_viewport, external_clip, external_viewport, 492 ASSERT_EQ(fake_output_surface->num_sent_frames(), 1u);
486 external_transform, resourceless_software_draw); 493 EXPECT_EQ(gfx::SizeF(100.f, 100.f),
487 494 fake_output_surface->last_sent_frame().metadata.root_layer_size);
488 bool always_draw = true;
489 CheckNotifyCalledIfCanDrawChanged(always_draw);
490 } 495 }
491 496
492 TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) { 497 TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) {
493 ASSERT_FALSE(host_impl_->active_tree()->root_layer()); 498 ASSERT_FALSE(host_impl_->active_tree()->root_layer());
494 499
495 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); 500 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
496 ASSERT_EQ(scroll_info->scrolls.size(), 0u); 501 ASSERT_EQ(scroll_info->scrolls.size(), 0u);
497 } 502 }
498 503
499 TEST_F(LayerTreeHostImplTest, ScrollDeltaTreeButNoChanges) { 504 TEST_F(LayerTreeHostImplTest, ScrollDeltaTreeButNoChanges) {
(...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after
3375 TEST_F(LayerTreeHostImplTest, 3380 TEST_F(LayerTreeHostImplTest,
3376 PrepareToDrawWhenDrawAndSwapFullViewportEveryFrame) { 3381 PrepareToDrawWhenDrawAndSwapFullViewportEveryFrame) {
3377 CreateHostImpl(DefaultSettings(), 3382 CreateHostImpl(DefaultSettings(),
3378 FakeOutputSurface::CreateSoftware( 3383 FakeOutputSurface::CreateSoftware(
3379 make_scoped_ptr(new SoftwareOutputDevice()))); 3384 make_scoped_ptr(new SoftwareOutputDevice())));
3380 3385
3381 const gfx::Transform external_transform; 3386 const gfx::Transform external_transform;
3382 const gfx::Rect external_viewport; 3387 const gfx::Rect external_viewport;
3383 const gfx::Rect external_clip; 3388 const gfx::Rect external_clip;
3384 const bool resourceless_software_draw = true; 3389 const bool resourceless_software_draw = true;
3385 host_impl_->SetExternalDrawConstraints( 3390 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
3386 external_transform, external_viewport, external_clip, external_viewport, 3391 external_transform);
3387 external_transform, resourceless_software_draw);
3388 3392
3389 std::vector<PrepareToDrawSuccessTestCase> cases; 3393 std::vector<PrepareToDrawSuccessTestCase> cases;
3390 3394
3391 // 0. Default case. 3395 // 0. Default case.
3392 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); 3396 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS));
3393 // 1. Animation with missing tile. 3397 // 1. Animation with missing tile.
3394 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); 3398 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS));
3395 cases.back().layer_between.has_missing_tile = true; 3399 cases.back().layer_between.has_missing_tile = true;
3396 cases.back().layer_between.is_animating = true; 3400 cases.back().layer_between.is_animating = true;
3397 // 2. High res required with incomplete tile. 3401 // 2. High res required with incomplete tile.
3398 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); 3402 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS));
3399 cases.back().high_res_required = true; 3403 cases.back().high_res_required = true;
3400 cases.back().layer_between.has_incomplete_tile = true; 3404 cases.back().layer_between.has_incomplete_tile = true;
3401 // 3. High res required with missing tile. 3405 // 3. High res required with missing tile.
3402 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); 3406 cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS));
3403 cases.back().high_res_required = true; 3407 cases.back().high_res_required = true;
3404 cases.back().layer_between.has_missing_tile = true; 3408 cases.back().layer_between.has_missing_tile = true;
3405 3409
3406 host_impl_->active_tree()->SetRootLayer( 3410 host_impl_->active_tree()->SetRootLayer(
3407 DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); 3411 DidDrawCheckLayer::Create(host_impl_->active_tree(), 1));
3408 DidDrawCheckLayer* root = 3412 DidDrawCheckLayer* root =
3409 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer()); 3413 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer());
3410 root->SetForceRenderSurface(true); 3414 root->SetForceRenderSurface(true);
3411 3415
3412 LayerTreeHostImpl::FrameData frame; 3416 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
3413 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 3417 resourceless_software_draw);
3414 host_impl_->DrawLayers(&frame);
3415 host_impl_->DidDrawAllLayers(frame);
3416 host_impl_->SwapBuffers(frame);
3417 3418
3418 for (size_t i = 0; i < cases.size(); ++i) { 3419 for (size_t i = 0; i < cases.size(); ++i) {
3419 const auto& testcase = cases[i]; 3420 const auto& testcase = cases[i];
3420 std::vector<LayerImpl*> to_remove; 3421 std::vector<LayerImpl*> to_remove;
3421 for (const auto& child : root->children()) 3422 for (const auto& child : root->children())
3422 to_remove.push_back(child.get()); 3423 to_remove.push_back(child.get());
3423 for (auto* child : to_remove) 3424 for (auto* child : to_remove)
3424 root->RemoveChild(child); 3425 root->RemoveChild(child);
3425 3426
3426 std::ostringstream scope; 3427 std::ostringstream scope;
(...skipping 23 matching lines...) Expand all
3450 testcase.layer_after.has_incomplete_tile, 3451 testcase.layer_after.has_incomplete_tile,
3451 testcase.layer_after.is_animating, host_impl_->resource_provider())); 3452 testcase.layer_after.is_animating, host_impl_->resource_provider()));
3452 DidDrawCheckLayer* after = 3453 DidDrawCheckLayer* after =
3453 static_cast<DidDrawCheckLayer*>(root->children().back().get()); 3454 static_cast<DidDrawCheckLayer*>(root->children().back().get());
3454 if (testcase.layer_after.has_copy_request) 3455 if (testcase.layer_after.has_copy_request)
3455 after->AddCopyRequest(); 3456 after->AddCopyRequest();
3456 3457
3457 if (testcase.high_res_required) 3458 if (testcase.high_res_required)
3458 host_impl_->SetRequiresHighResToDraw(); 3459 host_impl_->SetRequiresHighResToDraw();
3459 3460
3460 LayerTreeHostImpl::FrameData frame; 3461 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
3461 EXPECT_EQ(testcase.expected_result, PrepareToDrawFrame(&frame)); 3462 resourceless_software_draw);
3462 host_impl_->DrawLayers(&frame);
3463 host_impl_->DidDrawAllLayers(frame);
3464 host_impl_->SwapBuffers(frame);
3465 } 3463 }
3466 } 3464 }
3467 3465
3468 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { 3466 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) {
3469 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); 3467 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1);
3470 root->SetScrollClipLayer(Layer::INVALID_ID); 3468 root->SetScrollClipLayer(Layer::INVALID_ID);
3471 root->SetForceRenderSurface(true); 3469 root->SetForceRenderSurface(true);
3472 host_impl_->active_tree()->SetRootLayer(std::move(root)); 3470 host_impl_->active_tree()->SetRootLayer(std::move(root));
3473 DrawFrame(); 3471 DrawFrame();
3474 3472
(...skipping 2478 matching lines...) Expand 10 before | Expand all | Expand 10 after
5953 texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); 5951 texture_quad->rect.bottom() / gutter_texture_size_pixels.height());
5954 } 5952 }
5955 } 5953 }
5956 5954
5957 gfx::Size DipSizeToPixelSize(const gfx::Size& size) { 5955 gfx::Size DipSizeToPixelSize(const gfx::Size& size) {
5958 return gfx::ScaleToRoundedSize( 5956 return gfx::ScaleToRoundedSize(
5959 size, host_impl_->active_tree()->device_scale_factor()); 5957 size, host_impl_->active_tree()->device_scale_factor());
5960 } 5958 }
5961 5959
5962 void SetResourcelessSoftwareDraw() { 5960 void SetResourcelessSoftwareDraw() {
5963 const gfx::Transform external_transform;
5964 const gfx::Rect external_viewport;
5965 const gfx::Rect external_clip;
5966 const bool resourceless_software_draw = true; 5961 const bool resourceless_software_draw = true;
5967 host_impl_->SetExternalDrawConstraints( 5962 host_impl_->SetResourcelessSoftwareDrawForTesting(
5968 external_transform, external_viewport, external_clip, external_viewport, 5963 resourceless_software_draw);
5969 external_transform, resourceless_software_draw);
5970 } 5964 }
5971 5965
5972 DrawQuad::Material gutter_quad_material_; 5966 DrawQuad::Material gutter_quad_material_;
5973 gfx::Size gutter_texture_size_; 5967 gfx::Size gutter_texture_size_;
5974 gfx::Size viewport_size_; 5968 gfx::Size viewport_size_;
5975 BlendStateCheckLayer* child_; 5969 BlendStateCheckLayer* child_;
5976 bool did_activate_pending_tree_; 5970 bool did_activate_pending_tree_;
5977 }; 5971 };
5978 5972
5979 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { 5973 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) {
(...skipping 23 matching lines...) Expand all
6003 TestEmptyLayer(); 5997 TestEmptyLayer();
6004 TestLayerInMiddleOfViewport(); 5998 TestLayerInMiddleOfViewport();
6005 TestLayerIsLargerThanViewport(); 5999 TestLayerIsLargerThanViewport();
6006 } 6000 }
6007 6001
6008 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) { 6002 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) {
6009 viewport_size_ = gfx::Size(1000, 1000); 6003 viewport_size_ = gfx::Size(1000, 1000);
6010 6004
6011 bool software = true; 6005 bool software = true;
6012 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); 6006 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software));
6013 SetResourcelessSoftwareDraw();
6014 6007
6015 // Pending tree to force active_tree size invalid. Not used otherwise. 6008 // Pending tree to force active_tree size invalid. Not used otherwise.
6016 host_impl_->CreatePendingTree(); 6009 host_impl_->CreatePendingTree();
6017 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); 6010 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_));
6018 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); 6011 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid());
6019 6012
6020 SetupActiveTreeLayers(); 6013 SetupActiveTreeLayers();
6014 SetResourcelessSoftwareDraw(); // Needed to draw while viewport invalid.
boliu 2015/12/15 23:46:45 This and the test below are the only ones that nee
boliu 2015/12/16 00:00:50 Just found RenderPass::CopyAll, maybe it's easier
boliu 2015/12/16 01:17:46 Ok, did that. Not too bad.
6021 TestEmptyLayer(); 6015 TestEmptyLayer();
6022 TestLayerInMiddleOfViewport(); 6016 TestLayerInMiddleOfViewport();
6023 TestLayerIsLargerThanViewport(); 6017 TestLayerIsLargerThanViewport();
6024 } 6018 }
6025 6019
6026 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeShrinkViewportInvalid) { 6020 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeShrinkViewportInvalid) {
6027 viewport_size_ = gfx::Size(1000, 1000); 6021 viewport_size_ = gfx::Size(1000, 1000);
6028 6022
6029 bool software = true; 6023 bool software = true;
6030 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); 6024 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software));
6031 SetResourcelessSoftwareDraw();
6032 6025
6033 // Set larger viewport and activate it to active tree. 6026 // Set larger viewport and activate it to active tree.
6034 host_impl_->CreatePendingTree(); 6027 host_impl_->CreatePendingTree();
6035 gfx::Size larger_viewport(viewport_size_.width() + 100, 6028 gfx::Size larger_viewport(viewport_size_.width() + 100,
6036 viewport_size_.height() + 100); 6029 viewport_size_.height() + 100);
6037 host_impl_->SetViewportSize(DipSizeToPixelSize(larger_viewport)); 6030 host_impl_->SetViewportSize(DipSizeToPixelSize(larger_viewport));
6038 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); 6031 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid());
6039 host_impl_->ActivateSyncTree(); 6032 host_impl_->ActivateSyncTree();
6040 EXPECT_TRUE(did_activate_pending_tree_); 6033 EXPECT_TRUE(did_activate_pending_tree_);
6041 EXPECT_FALSE(host_impl_->active_tree()->ViewportSizeInvalid()); 6034 EXPECT_FALSE(host_impl_->active_tree()->ViewportSizeInvalid());
6042 6035
6043 // Shrink pending tree viewport without activating. 6036 // Shrink pending tree viewport without activating.
6044 host_impl_->CreatePendingTree(); 6037 host_impl_->CreatePendingTree();
6045 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); 6038 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_));
6046 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); 6039 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid());
6047 6040
6048 SetupActiveTreeLayers(); 6041 SetupActiveTreeLayers();
6042 SetResourcelessSoftwareDraw(); // Needed to draw while viewport invalid.
6049 TestEmptyLayer(); 6043 TestEmptyLayer();
6050 TestLayerInMiddleOfViewport(); 6044 TestLayerInMiddleOfViewport();
6051 TestLayerIsLargerThanViewport(); 6045 TestLayerIsLargerThanViewport();
6052 } 6046 }
6053 6047
6054 class FakeDrawableLayerImpl: public LayerImpl { 6048 class FakeDrawableLayerImpl: public LayerImpl {
6055 public: 6049 public:
6056 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { 6050 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
6057 return make_scoped_ptr(new FakeDrawableLayerImpl(tree_impl, id)); 6051 return make_scoped_ptr(new FakeDrawableLayerImpl(tree_impl, id));
6058 } 6052 }
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
6849 DefaultSettings(), 6843 DefaultSettings(),
6850 FakeOutputSurface::CreateSoftware(make_scoped_ptr(software_device)))); 6844 FakeOutputSurface::CreateSoftware(make_scoped_ptr(software_device))));
6851 host_impl_->SetViewportSize(gfx::Size(50, 50)); 6845 host_impl_->SetViewportSize(gfx::Size(50, 50));
6852 6846
6853 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 6847 SetupScrollAndContentsLayers(gfx::Size(100, 100));
6854 6848
6855 const gfx::Transform external_transform; 6849 const gfx::Transform external_transform;
6856 const gfx::Rect external_viewport; 6850 const gfx::Rect external_viewport;
6857 const gfx::Rect external_clip; 6851 const gfx::Rect external_clip;
6858 const bool resourceless_software_draw = true; 6852 const bool resourceless_software_draw = true;
6859 host_impl_->SetExternalDrawConstraints(external_transform, 6853 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
6860 external_viewport, 6854 external_transform);
6861 external_clip,
6862 external_viewport,
6863 external_transform,
6864 resourceless_software_draw);
6865 6855
6866 EXPECT_EQ(0, software_device->frames_began_); 6856 EXPECT_EQ(0, software_device->frames_began_);
6867 EXPECT_EQ(0, software_device->frames_ended_); 6857 EXPECT_EQ(0, software_device->frames_ended_);
6868 6858
6869 DrawFrame(); 6859 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
6860 resourceless_software_draw);
6870 6861
6871 EXPECT_EQ(1, software_device->frames_began_); 6862 EXPECT_EQ(1, software_device->frames_began_);
6872 EXPECT_EQ(1, software_device->frames_ended_); 6863 EXPECT_EQ(1, software_device->frames_ended_);
6873 6864
6874 // Call another API method that is likely to hit nullptr in this mode. 6865 // Call another API method that is likely to hit nullptr in this mode.
6875 scoped_refptr<base::trace_event::TracedValue> state = 6866 scoped_refptr<base::trace_event::TracedValue> state =
6876 make_scoped_refptr(new base::trace_event::TracedValue()); 6867 make_scoped_refptr(new base::trace_event::TracedValue());
6877 host_impl_->ActivationStateAsValueInto(state.get()); 6868 host_impl_->ActivationStateAsValueInto(state.get());
6878 } 6869 }
6879 6870
6880 TEST_F(LayerTreeHostImplTest, 6871 TEST_F(LayerTreeHostImplTest,
6881 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { 6872 ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) {
6882 set_reduce_memory_result(false); 6873 set_reduce_memory_result(false);
6883 EXPECT_TRUE(CreateHostImpl(DefaultSettings(), 6874 EXPECT_TRUE(CreateHostImpl(DefaultSettings(),
6884 FakeOutputSurface::CreateSoftware( 6875 FakeOutputSurface::CreateSoftware(
6885 make_scoped_ptr(new CountingSoftwareDevice)))); 6876 make_scoped_ptr(new CountingSoftwareDevice))));
6886 6877
6887 const gfx::Transform external_transform; 6878 const gfx::Transform external_transform;
6888 const gfx::Rect external_viewport; 6879 const gfx::Rect external_viewport;
6889 const gfx::Rect external_clip; 6880 const gfx::Rect external_clip;
6890 const bool resourceless_software_draw = true; 6881 const bool resourceless_software_draw = true;
6891 host_impl_->SetExternalDrawConstraints(external_transform, 6882 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
6892 external_viewport, 6883 external_transform);
6893 external_clip,
6894 external_viewport,
6895 external_transform,
6896 resourceless_software_draw);
6897 6884
6898 // SolidColorLayerImpl will be drawn. 6885 // SolidColorLayerImpl will be drawn.
6899 scoped_ptr<SolidColorLayerImpl> root_layer = 6886 scoped_ptr<SolidColorLayerImpl> root_layer =
6900 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); 6887 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
6901 6888
6902 // VideoLayerImpl will not be drawn. 6889 // VideoLayerImpl will not be drawn.
6903 FakeVideoFrameProvider provider; 6890 FakeVideoFrameProvider provider;
6904 scoped_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create( 6891 scoped_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create(
6905 host_impl_->active_tree(), 2, &provider, media::VIDEO_ROTATION_0); 6892 host_impl_->active_tree(), 2, &provider, media::VIDEO_ROTATION_0);
6906 video_layer->SetBounds(gfx::Size(10, 10)); 6893 video_layer->SetBounds(gfx::Size(10, 10));
6907 video_layer->SetDrawsContent(true); 6894 video_layer->SetDrawsContent(true);
6908 root_layer->AddChild(std::move(video_layer)); 6895 root_layer->AddChild(std::move(video_layer));
6909 SetupRootLayerImpl(std::move(root_layer)); 6896 SetupRootLayerImpl(std::move(root_layer));
6910 6897
6911 LayerTreeHostImpl::FrameData frame; 6898 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
6912 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 6899 resourceless_software_draw);
6913 host_impl_->DrawLayers(&frame);
6914 host_impl_->DidDrawAllLayers(frame);
6915 6900
6916 EXPECT_EQ(1u, frame.will_draw_layers.size()); 6901 EXPECT_EQ(1u, last_on_draw_frame_->will_draw_layers.size());
6917 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); 6902 EXPECT_EQ(host_impl_->active_tree()->root_layer(),
6903 last_on_draw_frame_->will_draw_layers[0]);
6918 } 6904 }
6919 6905
6920 // Checks that we have a non-0 default allocation if we pass a context that 6906 // Checks that we have a non-0 default allocation if we pass a context that
6921 // doesn't support memory management extensions. 6907 // doesn't support memory management extensions.
6922 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { 6908 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) {
6923 LayerTreeSettings settings = DefaultSettings(); 6909 LayerTreeSettings settings = DefaultSettings();
6924 host_impl_ = LayerTreeHostImpl::Create( 6910 host_impl_ = LayerTreeHostImpl::Create(
6925 settings, this, &task_runner_provider_, &stats_instrumentation_, 6911 settings, this, &task_runner_provider_, &stats_instrumentation_,
6926 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, 6912 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_,
6927 0); 6913 0);
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after
8429 8415
8430 TEST_F(LayerTreeHostImplTest, ExternalTransformReflectedInNextDraw) { 8416 TEST_F(LayerTreeHostImplTest, ExternalTransformReflectedInNextDraw) {
8431 const gfx::Size layer_size(100, 100); 8417 const gfx::Size layer_size(100, 100);
8432 gfx::Transform external_transform; 8418 gfx::Transform external_transform;
8433 const gfx::Rect external_viewport(layer_size); 8419 const gfx::Rect external_viewport(layer_size);
8434 const gfx::Rect external_clip(layer_size); 8420 const gfx::Rect external_clip(layer_size);
8435 const bool resourceless_software_draw = false; 8421 const bool resourceless_software_draw = false;
8436 LayerImpl* layer = SetupScrollAndContentsLayers(layer_size); 8422 LayerImpl* layer = SetupScrollAndContentsLayers(layer_size);
8437 layer->SetDrawsContent(true); 8423 layer->SetDrawsContent(true);
8438 8424
8439 host_impl_->SetExternalDrawConstraints(external_transform, 8425 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8440 external_viewport, 8426 external_transform);
8441 external_clip, 8427 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8442 external_viewport, 8428 resourceless_software_draw);
8443 external_transform,
8444 resourceless_software_draw);
8445 DrawFrame();
8446 EXPECT_TRANSFORMATION_MATRIX_EQ( 8429 EXPECT_TRANSFORMATION_MATRIX_EQ(
8447 external_transform, layer->draw_properties().target_space_transform); 8430 external_transform, layer->draw_properties().target_space_transform);
8448 8431
8449 external_transform.Translate(20, 20); 8432 external_transform.Translate(20, 20);
8450 host_impl_->SetExternalDrawConstraints(external_transform, 8433 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8451 external_viewport, 8434 external_transform);
8452 external_clip, 8435 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8453 external_viewport, 8436 resourceless_software_draw);
8454 external_transform,
8455 resourceless_software_draw);
8456 DrawFrame();
8457 EXPECT_TRANSFORMATION_MATRIX_EQ( 8437 EXPECT_TRANSFORMATION_MATRIX_EQ(
8458 external_transform, layer->draw_properties().target_space_transform); 8438 external_transform, layer->draw_properties().target_space_transform);
8459 } 8439 }
8460 8440
8461 TEST_F(LayerTreeHostImplTest, ExternalTransformSetNeedsRedraw) { 8441 TEST_F(LayerTreeHostImplTest, ExternalTransformSetNeedsRedraw) {
8462 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 8442 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
8463 8443
8464 const gfx::Size layer_size(100, 100); 8444 const gfx::Size viewport_size(100, 100);
8465 const gfx::Transform external_transform; 8445 host_impl_->SetViewportSize(viewport_size);
8466 const gfx::Rect external_viewport(layer_size); 8446
8467 const gfx::Rect external_clip1(layer_size); 8447 const gfx::Transform transform_for_tile_priority;
8468 const gfx::Rect external_clip2(50, 50); 8448 const gfx::Transform draw_transform;
8449 const gfx::Rect viewport_for_tile_priority1(viewport_size);
8450 const gfx::Rect viewport_for_tile_priority2(50, 50);
8451 const gfx::Rect draw_viewport(viewport_size);
8452 const gfx::Rect clip(viewport_size);
8469 bool resourceless_software_draw = false; 8453 bool resourceless_software_draw = false;
8470 8454
8471 resourceless_software_draw = false; 8455 // Clear any damage.
8472 host_impl_->SetExternalDrawConstraints( 8456 host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority1,
8473 external_transform, external_viewport, external_clip1, external_viewport, 8457 transform_for_tile_priority);
8474 external_transform, resourceless_software_draw); 8458 host_impl_->OnDraw(draw_transform, draw_viewport, clip,
8475 { 8459 resourceless_software_draw);
8476 // Clear any damage. 8460 last_on_draw_frame_.reset();
8477 LayerTreeHostImpl::FrameData frame;
8478 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
8479 host_impl_->DrawLayers(&frame);
8480 host_impl_->DidDrawAllLayers(frame);
8481 host_impl_->SwapBuffers(frame);
8482 }
8483 8461
8484 // Setting new constraints needs redraw. 8462 // Setting new constraints needs redraw.
8485 did_request_redraw_ = false; 8463 did_request_redraw_ = false;
8486 host_impl_->SetExternalDrawConstraints( 8464 host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority2,
8487 external_transform, external_viewport, external_clip2, external_viewport, 8465 transform_for_tile_priority);
8488 external_transform, resourceless_software_draw);
8489 EXPECT_TRUE(did_request_redraw_); 8466 EXPECT_TRUE(did_request_redraw_);
8490 { 8467 host_impl_->OnDraw(draw_transform, draw_viewport, clip,
8491 LayerTreeHostImpl::FrameData frame; 8468 resourceless_software_draw);
8492 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame)); 8469 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
8493 EXPECT_FALSE(frame.has_no_damage); 8470 }
8494 host_impl_->DrawLayers(&frame); 8471
8495 host_impl_->DidDrawAllLayers(frame); 8472 TEST_F(LayerTreeHostImplTest, OnDrawConstraintSetNeedsRedraw) {
8496 host_impl_->SwapBuffers(frame); 8473 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
8474
8475 const gfx::Size viewport_size(100, 100);
8476 host_impl_->SetViewportSize(viewport_size);
8477
8478 const gfx::Transform draw_transform;
8479 const gfx::Rect draw_viewport1(viewport_size);
8480 const gfx::Rect draw_viewport2(50, 50);
8481 const gfx::Rect clip(viewport_size);
8482 bool resourceless_software_draw = false;
8483
8484 // Clear any damage.
8485 host_impl_->OnDraw(draw_transform, draw_viewport1, clip,
8486 resourceless_software_draw);
8487 last_on_draw_frame_.reset();
8488
8489 // Same draw params does not swap.
8490 did_request_redraw_ = false;
8491 host_impl_->OnDraw(draw_transform, draw_viewport1, clip,
8492 resourceless_software_draw);
8493 EXPECT_FALSE(did_request_redraw_);
8494 EXPECT_TRUE(last_on_draw_frame_->has_no_damage);
8495 last_on_draw_frame_.reset();
8496
8497 // Different draw params does swap.
8498 did_request_redraw_ = false;
8499 host_impl_->OnDraw(draw_transform, draw_viewport2, clip,
8500 resourceless_software_draw);
8501 EXPECT_TRUE(did_request_redraw_);
8502 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
8503 }
8504
8505 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest {
8506 protected:
8507 scoped_ptr<OutputSurface> CreateOutputSurface() override {
8508 return FakeOutputSurface::Create3dWithResourcelessSoftwareSupport();
8497 } 8509 }
8510 };
8498 8511
8499 // Resourceless software draw toggles do not need redraw. Damage is 8512 TEST_F(ResourcelessSoftwareLayerTreeHostImplTest,
8500 // set externally by SynchronousCompositorOutputSurface in this case. 8513 ResourcelessSoftwareSetNeedsRedraw) {
8514 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
8501 8515
8502 // Setting resourceless_software_draw do not need redraw. 8516 const gfx::Size viewport_size(100, 100);
8503 did_request_redraw_ = false; 8517 host_impl_->SetViewportSize(viewport_size);
8518
8519 const gfx::Transform draw_transform;
8520 const gfx::Rect draw_viewport(viewport_size);
8521 const gfx::Rect clip(viewport_size);
8522 bool resourceless_software_draw = false;
8523
8524 // Clear any damage.
8525 host_impl_->OnDraw(draw_transform, draw_viewport, clip,
8526 resourceless_software_draw);
8527 last_on_draw_frame_.reset();
8528
8529 // Always swap even if same draw params.
8504 resourceless_software_draw = true; 8530 resourceless_software_draw = true;
8505 host_impl_->SetExternalDrawConstraints( 8531 host_impl_->OnDraw(draw_transform, draw_viewport, clip,
8506 external_transform, external_viewport, external_clip1, external_viewport, 8532 resourceless_software_draw);
8507 external_transform, resourceless_software_draw); 8533 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
8508 EXPECT_FALSE(did_request_redraw_); 8534 last_on_draw_frame_.reset();
8509 // Can't call PrepareToDrawFrame with no change for resourceless software
8510 // draw.
8511 8535
8512 // Unsetting resourceless_software_draw do not need redraw. 8536 // Next hardware draw has damage.
8513 did_request_redraw_ = false;
8514 resourceless_software_draw = false; 8537 resourceless_software_draw = false;
8515 host_impl_->SetExternalDrawConstraints( 8538 host_impl_->OnDraw(draw_transform, draw_viewport, clip,
8516 external_transform, external_viewport, external_clip2, external_viewport, 8539 resourceless_software_draw);
8517 external_transform, resourceless_software_draw); 8540 EXPECT_FALSE(last_on_draw_frame_->has_no_damage);
8518 EXPECT_FALSE(did_request_redraw_);
8519 {
8520 LayerTreeHostImpl::FrameData frame;
8521 EXPECT_EQ(DRAW_SUCCESS, PrepareToDrawFrame(&frame));
8522 EXPECT_TRUE(frame.has_no_damage);
8523 }
8524 } 8541 }
8525 8542
8526 TEST_F(LayerTreeHostImplTest, ExternalViewportAffectsVisibleRects) { 8543 TEST_F(LayerTreeHostImplTest, ExternalViewportAffectsVisibleRects) {
8527 const gfx::Size layer_size(100, 100); 8544 const gfx::Size layer_size(100, 100);
8528 SetupScrollAndContentsLayers(layer_size); 8545 SetupScrollAndContentsLayers(layer_size);
8529 LayerImpl* content_layer = host_impl_->active_tree() 8546 LayerImpl* content_layer = host_impl_->active_tree()
8530 ->OuterViewportScrollLayer() 8547 ->OuterViewportScrollLayer()
8531 ->children()[0] 8548 ->children()[0]
8532 .get(); 8549 .get();
8533 RebuildPropertyTrees(); 8550 RebuildPropertyTrees();
8534 8551
8535 bool update_lcd_text = false; 8552 bool update_lcd_text = false;
8536 8553
8537 host_impl_->SetViewportSize(gfx::Size(90, 90)); 8554 host_impl_->SetViewportSize(gfx::Size(90, 90));
8538 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8555 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text);
8539 EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); 8556 EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect());
8540 8557
8541 gfx::Transform external_transform; 8558 gfx::Transform external_transform;
8542 gfx::Rect external_viewport(10, 20); 8559 gfx::Rect external_viewport(10, 20);
8543 gfx::Rect external_clip(layer_size); 8560 gfx::Rect external_clip(layer_size);
8544 bool resourceless_software_draw = false; 8561 bool resourceless_software_draw = false;
8545 host_impl_->SetExternalDrawConstraints( 8562 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8546 external_transform, external_viewport, external_clip, external_viewport, 8563 external_transform);
8547 external_transform, resourceless_software_draw); 8564 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8548 8565 resourceless_software_draw);
8549 // Visible rects should now be clipped by the external viewport.
8550 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text);
8551 EXPECT_EQ(gfx::Rect(10, 20), content_layer->visible_layer_rect()); 8566 EXPECT_EQ(gfx::Rect(10, 20), content_layer->visible_layer_rect());
8552 8567
8553 // Clear the external viewport. 8568 // Clear the external viewport.
8554 external_viewport = gfx::Rect(); 8569 external_viewport = gfx::Rect();
8555 host_impl_->SetExternalDrawConstraints( 8570 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8556 external_transform, external_viewport, external_clip, external_viewport, 8571 external_transform);
8557 external_transform, resourceless_software_draw);
8558 8572
8559 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8573 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8574 resourceless_software_draw);
8560 EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); 8575 EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect());
8561 } 8576 }
8562 8577
8563 TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsVisibleRects) { 8578 TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsVisibleRects) {
8564 const gfx::Size layer_size(100, 100); 8579 const gfx::Size layer_size(100, 100);
8565 SetupScrollAndContentsLayers(layer_size); 8580 SetupScrollAndContentsLayers(layer_size);
8566 LayerImpl* content_layer = host_impl_->active_tree() 8581 LayerImpl* content_layer = host_impl_->active_tree()
8567 ->OuterViewportScrollLayer() 8582 ->OuterViewportScrollLayer()
8568 ->children()[0] 8583 ->children()[0]
8569 .get(); 8584 .get();
8570 RebuildPropertyTrees(); 8585 RebuildPropertyTrees();
8571 8586
8572 bool update_lcd_text = false; 8587 bool update_lcd_text = false;
8573 8588
8574 host_impl_->SetViewportSize(gfx::Size(50, 50)); 8589 host_impl_->SetViewportSize(gfx::Size(50, 50));
8575 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8590 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text);
8576 EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); 8591 EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect());
8577 8592
8578 gfx::Transform external_transform; 8593 gfx::Transform external_transform;
8579 external_transform.Translate(10, 10); 8594 external_transform.Translate(10, 10);
8580 external_transform.Scale(2, 2); 8595 external_transform.Scale(2, 2);
8581 gfx::Rect external_viewport; 8596 gfx::Rect external_viewport;
8582 gfx::Rect external_clip(layer_size); 8597 gfx::Rect external_clip(layer_size);
8583 bool resourceless_software_draw = false; 8598 bool resourceless_software_draw = false;
8584 host_impl_->SetExternalDrawConstraints( 8599 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8585 external_transform, external_viewport, external_clip, external_viewport, 8600 external_transform);
8586 external_transform, resourceless_software_draw);
8587 8601
8588 // Visible rects should now be shifted and scaled because of the external 8602 // Visible rects should now be shifted and scaled because of the external
8589 // transform. 8603 // transform.
8590 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8604 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8605 resourceless_software_draw);
8591 EXPECT_EQ(gfx::Rect(20, 20), content_layer->visible_layer_rect()); 8606 EXPECT_EQ(gfx::Rect(20, 20), content_layer->visible_layer_rect());
8592 8607
8593 // Clear the external transform. 8608 // Clear the external transform.
8594 external_transform = gfx::Transform(); 8609 external_transform = gfx::Transform();
8595 host_impl_->SetExternalDrawConstraints( 8610 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8596 external_transform, external_viewport, external_clip, external_viewport, 8611 external_transform);
8597 external_transform, resourceless_software_draw);
8598 8612
8599 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8613 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8614 resourceless_software_draw);
8600 EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); 8615 EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect());
8601 } 8616 }
8602 8617
8603 TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { 8618 TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) {
8604 const gfx::Size layer_size(100, 100); 8619 const gfx::Size layer_size(100, 100);
8605 SetupScrollAndContentsLayers(layer_size); 8620 SetupScrollAndContentsLayers(layer_size);
8606 LayerImpl* content_layer = host_impl_->active_tree() 8621 LayerImpl* content_layer = host_impl_->active_tree()
8607 ->OuterViewportScrollLayer() 8622 ->OuterViewportScrollLayer()
8608 ->children()[0] 8623 ->children()[0]
8609 .get(); 8624 .get();
(...skipping 15 matching lines...) Expand all
8625 host_impl_->active_tree()->property_trees()->transform_tree.Node( 8640 host_impl_->active_tree()->property_trees()->transform_tree.Node(
8626 test_layer->transform_tree_index()); 8641 test_layer->transform_tree_index());
8627 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); 8642 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f));
8628 8643
8629 gfx::Transform external_transform; 8644 gfx::Transform external_transform;
8630 external_transform.Translate(10, 10); 8645 external_transform.Translate(10, 10);
8631 external_transform.Scale(2, 2); 8646 external_transform.Scale(2, 2);
8632 gfx::Rect external_viewport; 8647 gfx::Rect external_viewport;
8633 gfx::Rect external_clip(layer_size); 8648 gfx::Rect external_clip(layer_size);
8634 bool resourceless_software_draw = false; 8649 bool resourceless_software_draw = false;
8635 host_impl_->SetExternalDrawConstraints( 8650 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8636 external_transform, external_viewport, external_clip, external_viewport, 8651 external_transform);
8637 external_transform, resourceless_software_draw);
8638 8652
8639 // Transform node's sublayer scale should include the device transform scale. 8653 // Transform node's sublayer scale should include the device transform scale.
8640 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8654 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8655 resourceless_software_draw);
8641 node = host_impl_->active_tree()->property_trees()->transform_tree.Node( 8656 node = host_impl_->active_tree()->property_trees()->transform_tree.Node(
8642 test_layer->transform_tree_index()); 8657 test_layer->transform_tree_index());
8643 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f)); 8658 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f));
8644 8659
8645 // Clear the external transform. 8660 // Clear the external transform.
8646 external_transform = gfx::Transform(); 8661 external_transform = gfx::Transform();
8647 host_impl_->SetExternalDrawConstraints( 8662 host_impl_->SetExternalTilePriorityConstraints(external_viewport,
8648 external_transform, external_viewport, external_clip, external_viewport, 8663 external_transform);
8649 external_transform, resourceless_software_draw);
8650 8664
8651 host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); 8665 host_impl_->OnDraw(external_transform, external_viewport, external_clip,
8666 resourceless_software_draw);
8652 node = host_impl_->active_tree()->property_trees()->transform_tree.Node( 8667 node = host_impl_->active_tree()->property_trees()->transform_tree.Node(
8653 test_layer->transform_tree_index()); 8668 test_layer->transform_tree_index());
8654 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); 8669 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f));
8655 } 8670 }
8656 8671
8657 TEST_F(LayerTreeHostImplTest, ScrollAnimated) { 8672 TEST_F(LayerTreeHostImplTest, ScrollAnimated) {
8658 SetupScrollAndContentsLayers(gfx::Size(100, 200)); 8673 SetupScrollAndContentsLayers(gfx::Size(100, 200));
8659 8674
8660 // Shrink the outer viewport clip layer so that the outer viewport can scroll. 8675 // Shrink the outer viewport clip layer so that the outer viewport can scroll.
8661 host_impl_->OuterViewportScrollLayer()->parent()->SetBounds( 8676 host_impl_->OuterViewportScrollLayer()->parent()->SetBounds(
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
9326 // There should not be any jitter measured till we hit the fixed point hits 9341 // There should not be any jitter measured till we hit the fixed point hits
9327 // threshold. 9342 // threshold.
9328 float expected_jitter = 9343 float expected_jitter =
9329 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; 9344 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0;
9330 EXPECT_EQ(jitter, expected_jitter); 9345 EXPECT_EQ(jitter, expected_jitter);
9331 } 9346 }
9332 } 9347 }
9333 9348
9334 } // namespace 9349 } // namespace
9335 } // namespace cc 9350 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698