Skip to content

Commit

Permalink
cc: Turn LayerImpl's damage_rect into a gfx::Rect.
Browse files Browse the repository at this point in the history
Currently it's a float rect so that if you're at some high scale, and
a tile is replaced, we only damage the exact physical pixels.

This would make that a bit more sloppy, so that we'd damage in layer
space. This should be inconsequential however in terms of cost of the
damage rect, and saves us some int->float->int converting every
time a tile is rastered, and some code complexity.

R=enne, vmpstr
BUG=342848
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1320163003

Cr-Commit-Position: refs/heads/master@{#346209}
  • Loading branch information
danakj authored and Commit bot committed Aug 28, 2015
1 parent 6f08264 commit d344ab9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
8 changes: 4 additions & 4 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ const char* LayerImpl::LayerTypeAsString() const {
void LayerImpl::ResetAllChangeTrackingForSubtree() {
layer_property_changed_ = false;

update_rect_ = gfx::Rect();
damage_rect_ = gfx::RectF();
update_rect_.SetRect(0, 0, 0, 0);
damage_rect_.SetRect(0, 0, 0, 0);

if (render_surface_)
render_surface_->ResetPropertyChangedFlag();
Expand Down Expand Up @@ -1377,8 +1377,8 @@ void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
SetNeedsPushProperties();
}

void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) {
damage_rect_.Union(damage_rect);
}

bool LayerImpl::IsExternalScrollActive() const {
Expand Down
14 changes: 7 additions & 7 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,10 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,

// Note this rect is in layer space (not content space).
void SetUpdateRect(const gfx::Rect& update_rect);
gfx::Rect update_rect() const { return update_rect_; }
const gfx::Rect& update_rect() const { return update_rect_; }

void AddDamageRect(const gfx::RectF& damage_rect);

const gfx::RectF& damage_rect() const { return damage_rect_; }
void AddDamageRect(const gfx::Rect& damage_rect);
const gfx::Rect& damage_rect() const { return damage_rect_; }

virtual base::DictionaryValue* LayerTreeAsJson() const;

Expand Down Expand Up @@ -852,11 +851,12 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
private:
// Rect indicating what was repainted/updated during update.
// Note that plugin layers bypass this and leave it empty.
// Uses layer (not content) space.
// This is in the layer's space.
gfx::Rect update_rect_;

// This rect is in layer space.
gfx::RectF damage_rect_;
// Denotes an area that is damaged and needs redraw. This is in the layer's
// space.
gfx::Rect damage_rect_;

// Manages animations for this layer.
scoped_refptr<LayerAnimationController> layer_animation_controller_;
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ bool PictureLayerImpl::RasterSourceUsesLCDText() const {

void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {
if (layer_tree_impl()->IsActiveTree()) {
gfx::RectF layer_damage_rect =
gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale());
gfx::Rect layer_damage_rect = gfx::ScaleToEnclosingRect(
tile->content_rect(), 1.f / tile->contents_scale());
AddDamageRect(layer_damage_rect);
}
if (tile->draw_info().NeedsRaster()) {
Expand Down
20 changes: 11 additions & 9 deletions cc/trees/damage_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ void DamageTracker::ExtendDamageForLayer(LayerImpl* layer,
gfx::Rect rect_in_target_space = layer->GetEnclosingRectInTargetSpace();
data.Update(rect_in_target_space, mailboxId_);

gfx::RectF damage_rect =
gfx::UnionRects(layer->update_rect(), layer->damage_rect());
damage_rect.Intersect(gfx::RectF(layer->bounds()));

if (layer_is_new || layer->LayerPropertyChanged()) {
// If a layer is new or has changed, then its entire layer rect affects the
// target surface.
Expand All @@ -292,11 +288,17 @@ void DamageTracker::ExtendDamageForLayer(LayerImpl* layer,
// The layer's old region is now exposed on the target surface, too.
// Note old_rect_in_target_space is already in target space.
target_damage_rect->Union(old_rect_in_target_space);
} else if (!damage_rect.IsEmpty()) {
// If the layer properties haven't changed, then the the target surface is
// only affected by the layer's damaged area, which could be empty.
gfx::Rect damage_rect_in_target_space = gfx::ToEnclosingRect(
MathUtil::MapClippedRect(layer->draw_transform(), damage_rect));
return;
}

// If the layer properties haven't changed, then the the target surface is
// only affected by the layer's damaged area, which could be empty.
gfx::Rect damage_rect =
gfx::UnionRects(layer->update_rect(), layer->damage_rect());
damage_rect.Intersect(gfx::Rect(layer->bounds()));
if (!damage_rect.IsEmpty()) {
gfx::Rect damage_rect_in_target_space =
MathUtil::MapEnclosingClippedRect(layer->draw_transform(), damage_rect);
target_damage_rect->Union(damage_rect_in_target_space);
}
}
Expand Down
16 changes: 8 additions & 8 deletions cc/trees/damage_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
// CASE 1: Adding the layer damage rect should cause the corresponding damage
// to the surface.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
EmulateDrawingOneFrame(root.get());

// Damage position on the surface should be: position of layer damage_rect
Expand All @@ -278,7 +278,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
// CASE 2: The same layer damage rect twice in a row still produces the same
// damage.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
Expand All @@ -287,7 +287,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
// CASE 3: Adding a different layer damage rect should cause damage on the
// new damaged region, but no additional exposed old region.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(20.f, 25.f, 1.f, 2.f));
child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
EmulateDrawingOneFrame(root.get());

// Damage position on the surface should be: position of layer damage_rect
Expand All @@ -299,8 +299,8 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
// CASE 4: Adding multiple layer damage rects should cause a unified
// damage on root damage rect.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(20.f, 25.f, 1.f, 2.f));
child->AddDamageRect(gfx::RectF(10.f, 15.f, 3.f, 4.f));
child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
child->AddDamageRect(gfx::Rect(10, 15, 3, 4));
EmulateDrawingOneFrame(root.get());

// Damage position on the surface should be: position of layer damage_rect
Expand All @@ -318,7 +318,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
// CASE 1: Adding the layer damage rect and update rect should cause the
// corresponding damage to the surface.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(5.f, 6.f, 12.f, 13.f));
child->AddDamageRect(gfx::Rect(5, 6, 12, 13));
child->SetUpdateRect(gfx::Rect(15, 16, 14, 10));
EmulateDrawingOneFrame(root.get());

Expand All @@ -332,7 +332,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
// CASE 2: The same layer damage rect and update rect twice in a row still
// produces the same damage.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
child->SetUpdateRect(gfx::Rect(10, 11, 14, 15));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
Expand All @@ -342,7 +342,7 @@ TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
// CASE 3: Adding a different layer damage rect and update rect should cause
// damage on the new damaged region, but no additional exposed old region.
ClearDamageForAllSurfaces(root.get());
child->AddDamageRect(gfx::RectF(20.f, 25.f, 2.f, 3.f));
child->AddDamageRect(gfx::Rect(20, 25, 2, 3));
child->SetUpdateRect(gfx::Rect(5, 10, 7, 8));
EmulateDrawingOneFrame(root.get());

Expand Down

0 comments on commit d344ab9

Please sign in to comment.