diff options
author | vmpstr <vmpstr@chromium.org> | 2015-03-17 18:11:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-18 01:12:00 +0000 |
commit | d46a7acfa02865f2ed8e5ff3aefa34a5263384e9 (patch) | |
tree | 20e39cd3481a7cab831fca1c642d7b9637bfd749 /cc | |
parent | e74aabdb96a388dd0f11c60552710fcfc6b86649 (diff) | |
download | chromium_src-d46a7acfa02865f2ed8e5ff3aefa34a5263384e9.zip chromium_src-d46a7acfa02865f2ed8e5ff3aefa34a5263384e9.tar.gz chromium_src-d46a7acfa02865f2ed8e5ff3aefa34a5263384e9.tar.bz2 |
cc: Use layer_impls to compute content rect in target space
This patch changes the way we get damage for a layer to instead use
the layer itself to compute content bounds in target space.
BUG=463424
R=danakj, enne
Review URL: https://codereview.chromium.org/1015433002
Cr-Commit-Position: refs/heads/master@{#321041}
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layers/heads_up_display_layer_impl.cc | 4 | ||||
-rw-r--r-- | cc/layers/heads_up_display_layer_impl.h | 2 | ||||
-rw-r--r-- | cc/layers/layer_impl.cc | 16 | ||||
-rw-r--r-- | cc/layers/layer_impl.h | 4 | ||||
-rw-r--r-- | cc/layers/painted_scrollbar_layer_impl.cc | 4 | ||||
-rw-r--r-- | cc/layers/painted_scrollbar_layer_impl.h | 1 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.cc | 4 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.h | 1 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_impl.h | 4 | ||||
-rw-r--r-- | cc/trees/damage_tracker.cc | 3 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 115 |
11 files changed, 156 insertions, 2 deletions
diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc index e1a9daf..d81c71a 100644 --- a/cc/layers/heads_up_display_layer_impl.cc +++ b/cc/layers/heads_up_display_layer_impl.cc @@ -223,6 +223,10 @@ void HeadsUpDisplayLayerImpl::ReleaseResources() { resources_.clear(); } +gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { + return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); +} + void HeadsUpDisplayLayerImpl::UpdateHudContents() { const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); diff --git a/cc/layers/heads_up_display_layer_impl.h b/cc/layers/heads_up_display_layer_impl.h index 54bf153..750d991 100644 --- a/cc/layers/heads_up_display_layer_impl.h +++ b/cc/layers/heads_up_display_layer_impl.h @@ -45,6 +45,8 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl { void ReleaseResources() override; + gfx::Rect GetEnclosingRectInTargetSpace() const override; + bool IsAnimatingHUDContents() const { return fade_step_ > 0; } private: diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc index 0353a78..b34948c 100644 --- a/cc/layers/layer_impl.cc +++ b/cc/layers/layer_impl.cc @@ -1594,4 +1594,20 @@ Region LayerImpl::GetInvalidationRegion() { return Region(update_rect_); } +gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { + return MathUtil::MapEnclosingClippedRect( + draw_properties_.target_space_transform, + gfx::Rect(draw_properties_.content_bounds)); +} + +gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { + gfx::Transform scaled_draw_transform = + draw_properties_.target_space_transform; + scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); + gfx::Size scaled_content_bounds = + gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale)); + return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, + gfx::Rect(scaled_content_bounds)); +} + } // namespace cc diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h index 0357252..1c64453 100644 --- a/cc/layers/layer_impl.h +++ b/cc/layers/layer_impl.h @@ -600,6 +600,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // for layers that provide it. virtual Region GetInvalidationRegion(); + virtual gfx::Rect GetEnclosingRectInTargetSpace() const; + protected: LayerImpl(LayerTreeImpl* layer_impl, int id, @@ -626,6 +628,8 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, // Note carefully this does not affect the current layer. void NoteLayerPropertyChangedForDescendants(); + gfx::Rect GetScaledEnclosingRectInTargetSpace(float scale) const; + private: void PushScrollOffset(const gfx::ScrollOffset* scroll_offset); void DidUpdateScrollOffset(); diff --git a/cc/layers/painted_scrollbar_layer_impl.cc b/cc/layers/painted_scrollbar_layer_impl.cc index b05d51e..a085df5 100644 --- a/cc/layers/painted_scrollbar_layer_impl.cc +++ b/cc/layers/painted_scrollbar_layer_impl.cc @@ -131,6 +131,10 @@ void PaintedScrollbarLayerImpl::AppendQuads( } } +gfx::Rect PaintedScrollbarLayerImpl::GetEnclosingRectInTargetSpace() const { + return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); +} + void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { if (thumb_thickness_ == thumb_thickness) return; diff --git a/cc/layers/painted_scrollbar_layer_impl.h b/cc/layers/painted_scrollbar_layer_impl.h index 36a9be9..65d28ae 100644 --- a/cc/layers/painted_scrollbar_layer_impl.h +++ b/cc/layers/painted_scrollbar_layer_impl.h @@ -31,6 +31,7 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase { ResourceProvider* resource_provider) override; void AppendQuads(RenderPass* render_pass, AppendQuadsData* append_quads_data) override; + gfx::Rect GetEnclosingRectInTargetSpace() const override; void SetThumbThickness(int thumb_thickness); void SetThumbLength(int thumb_length); diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 93d6581..23ec891 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -666,6 +666,10 @@ bool PictureLayerImpl::RequiresHighResToDraw() const { return layer_tree_impl()->RequiresHighResToDraw(); } +gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const { + return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale()); +} + gfx::Size PictureLayerImpl::CalculateTileSize( const gfx::Size& content_bounds) const { int max_texture_size = diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 397cb62..b2d3544 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -75,6 +75,7 @@ class CC_EXPORT PictureLayerImpl TilePriority::PriorityBin GetMaxTilePriorityBin() const override; WhichTree GetTree() const override; bool RequiresHighResToDraw() const override; + gfx::Rect GetEnclosingRectInTargetSpace() const override; void UpdateRasterSource(scoped_refptr<RasterSource> raster_source, Region* new_invalidation, diff --git a/cc/test/fake_picture_layer_impl.h b/cc/test/fake_picture_layer_impl.h index 115fe55..ca29b9b 100644 --- a/cc/test/fake_picture_layer_impl.h +++ b/cc/test/fake_picture_layer_impl.h @@ -83,6 +83,10 @@ class FakePictureLayerImpl : public PictureLayerImpl { using PictureLayerImpl::UpdateIdealScales; using PictureLayerImpl::MaximumTilingContentsScale; + void AddTilingUntilNextDraw(float scale) { + last_append_quads_tilings_.push_back(AddTiling(scale)); + } + float raster_page_scale() const { return raster_page_scale_; } void set_raster_page_scale(float scale) { raster_page_scale_ = scale; } diff --git a/cc/trees/damage_tracker.cc b/cc/trees/damage_tracker.cc index 866f09d..235dfcf 100644 --- a/cc/trees/damage_tracker.cc +++ b/cc/trees/damage_tracker.cc @@ -283,8 +283,7 @@ void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, RectMapData& data = RectDataForLayer(layer->id(), &layer_is_new); gfx::Rect old_rect_in_target_space = data.rect_; - gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect( - layer->draw_transform(), gfx::Rect(layer->content_bounds())); + gfx::Rect rect_in_target_space = layer->GetEnclosingRectInTargetSpace(); data.Update(rect_in_target_space, mailboxId_); gfx::RectF damage_rect = diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index aacabd7..4331eaa 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -694,6 +694,13 @@ class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { public: LayerTreeHostTestUndrawnLayersDamageLater() {} + void InitializeSettings(LayerTreeSettings* settings) override { + // If we don't set the minimum contents scale, it's harder to verify whether + // the damage we get is correct. For other scale amounts, please see + // LayerTreeHostTestDamageWithScale. + settings->minimum_contents_scale = 1.f; + } + void SetupTree() override { if (layer_tree_host()->settings().impl_side_painting) root_layer_ = FakePictureLayer::Create(&client_); @@ -788,6 +795,114 @@ class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); +// Tests that if a layer is not drawn because of some reason in the parent then +// its damage is preserved until the next time it is drawn. +class LayerTreeHostTestDamageWithScale : public LayerTreeHostTest { + public: + LayerTreeHostTestDamageWithScale() {} + + void SetupTree() override { + client_.set_fill_with_nonsolid_color(true); + + scoped_ptr<FakePicturePile> pile( + new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, + ImplSidePaintingSettings().default_tile_grid_size)); + root_layer_ = + FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); + root_layer_->SetBounds(gfx::Size(50, 50)); + + pile.reset( + new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, + ImplSidePaintingSettings().default_tile_grid_size)); + child_layer_ = + FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); + child_layer_->SetBounds(gfx::Size(25, 25)); + child_layer_->SetIsDrawable(true); + child_layer_->SetContentsOpaque(true); + root_layer_->AddChild(child_layer_); + + layer_tree_host()->SetRootLayer(root_layer_); + LayerTreeHostTest::SetupTree(); + } + + void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { + // Force the layer to have a tiling at 1.3f scale. Note that if we simply + // add tiling, it will be gone by the time we draw because of aggressive + // cleanup. AddTilingUntilNextDraw ensures that it remains there during + // damage calculation. + FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( + host_impl->active_tree()->LayerById(child_layer_->id())); + child_layer_impl->AddTilingUntilNextDraw(1.3f); + } + + void BeginTest() override { PostSetNeedsCommitToMainThread(); } + + DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, + LayerTreeHostImpl::FrameData* frame_data, + DrawResult draw_result) override { + EXPECT_EQ(DRAW_SUCCESS, draw_result); + + gfx::RectF root_damage_rect; + if (!frame_data->render_passes.empty()) + root_damage_rect = frame_data->render_passes.back()->damage_rect; + + // The first time, the whole view needs be drawn. + // Afterwards, just the opacity of surface_layer1 is changed a few times, + // and each damage should be the bounding box of it and its child. If this + // was working improperly, the damage might not include its childs bounding + // box. + switch (host_impl->active_tree()->source_frame_number()) { + case 0: + EXPECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); + break; + case 1: { + FakePictureLayerImpl* child_layer_impl = + static_cast<FakePictureLayerImpl*>( + host_impl->active_tree()->LayerById(child_layer_->id())); + // We remove tilings pretty aggressively if they are not ideal. Add this + // back in so that we can compare + // child_layer_impl->GetEnclosingRectInTargetSpace to the damage. + child_layer_impl->AddTilingUntilNextDraw(1.3f); + + EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect); + EXPECT_EQ(child_layer_impl->GetEnclosingRectInTargetSpace(), + root_damage_rect); + EXPECT_TRUE(child_layer_impl->GetEnclosingRectInTargetSpace().Contains( + gfx::Rect(child_layer_->bounds()))); + break; + } + default: + NOTREACHED(); + } + + return draw_result; + } + + void DidCommitAndDrawFrame() override { + switch (layer_tree_host()->source_frame_number()) { + case 1: { + // Test not owning the surface. + child_layer_->SetOpacity(0.5f); + break; + } + case 2: + EndTest(); + break; + default: + NOTREACHED(); + } + } + + void AfterTest() override {} + + private: + FakeContentLayerClient client_; + scoped_refptr<Layer> root_layer_; + scoped_refptr<Layer> child_layer_; +}; + +MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestDamageWithScale); + // Tests that if a layer is not drawn because of some reason in the parent, // causing its content bounds to not be computed, then when it is later drawn, // its content bounds get pushed. |