Commit 0b5eae6c authored by danakj's avatar danakj Committed by Commit bot

ui: Clean up damaged rects and clear them after painting.

This cleans up some of the damage rects code by converting the SkRegion
to a cc::Region, allowing use of gfx::Rects. It moves the recursion
over the Layer tree out to Compositor instead of on Layer.

And we keep the damaged_region_ valid until the layer is painted. This
will allow us to pass that damaged_region_ to the painting code with
impl-side slimming paint, because with impl-side painting, the paint
clip rect can be larger than the invalidations (as large as the whole
layer).

R=piman@chromium.org, sky
BUG=466426

Committed: https://crrev.com/a5e585868e16ce53c990f764d4943592f11749aa
Cr-Commit-Position: refs/heads/master@{#326547}

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

Cr-Commit-Position: refs/heads/master@{#326912}
parent d20473d1
...@@ -91,8 +91,7 @@ class TestOutputSurface : public BrowserCompositorOutputSurface { ...@@ -91,8 +91,7 @@ class TestOutputSurface : public BrowserCompositorOutputSurface {
gfx::Size SurfaceSize() const override { return gfx::Size(256, 256); } gfx::Size SurfaceSize() const override { return gfx::Size(256, 256); }
}; };
const gfx::Rect kSubRect = gfx::Rect(0, 0, 64, 64); const gfx::Rect kSubRect(0, 0, 64, 64);
const SkIRect kSkSubRect = SkIRect::MakeXYWH(0, 0, 64, 64);
} // namespace } // namespace
...@@ -161,10 +160,10 @@ TEST_F(ReflectorImplTest, CheckNormalOutputSurface) { ...@@ -161,10 +160,10 @@ TEST_F(ReflectorImplTest, CheckNormalOutputSurface) {
SetUpReflector(); SetUpReflector();
UpdateTexture(); UpdateTexture();
EXPECT_TRUE(mirroring_layer_->TextureFlipped()); EXPECT_TRUE(mirroring_layer_->TextureFlipped());
EXPECT_EQ(SkRegion(SkIRect::MakeXYWH( gfx::Rect expected_rect =
0, output_surface_->SurfaceSize().height() - kSubRect.height(), kSubRect + gfx::Vector2d(0, output_surface_->SurfaceSize().height()) -
kSubRect.width(), kSubRect.height())), gfx::Vector2d(0, kSubRect.height());
mirroring_layer_->damaged_region()); EXPECT_EQ(expected_rect, mirroring_layer_->damaged_region());
} }
TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) { TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) {
...@@ -172,7 +171,7 @@ TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) { ...@@ -172,7 +171,7 @@ TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) {
SetUpReflector(); SetUpReflector();
UpdateTexture(); UpdateTexture();
EXPECT_FALSE(mirroring_layer_->TextureFlipped()); EXPECT_FALSE(mirroring_layer_->TextureFlipped());
EXPECT_EQ(SkRegion(kSkSubRect), mirroring_layer_->damaged_region()); EXPECT_EQ(kSubRect, mirroring_layer_->damaged_region());
} }
#if defined(USE_OZONE) #if defined(USE_OZONE)
......
...@@ -326,9 +326,16 @@ void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { ...@@ -326,9 +326,16 @@ void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
void Compositor::BeginMainFrameNotExpectedSoon() { void Compositor::BeginMainFrameNotExpectedSoon() {
} }
static void SendDamagedRectsRecursive(ui::Layer* layer) {
layer->SendDamagedRects();
for (auto* child : layer->children())
SendDamagedRectsRecursive(child);
}
void Compositor::Layout() { void Compositor::Layout() {
if (root_layer_) if (!root_layer())
root_layer_->SendDamagedRects(); return;
SendDamagedRectsRecursive(root_layer());
} }
void Compositor::RequestNewOutputSurface() { void Compositor::RequestNewOutputSurface() {
......
...@@ -657,11 +657,7 @@ bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { ...@@ -657,11 +657,7 @@ bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
return false; return false;
damaged_region_.op(invalid_rect.x(), damaged_region_.Union(invalid_rect);
invalid_rect.y(),
invalid_rect.right(),
invalid_rect.bottom(),
SkRegion::kUnion_Op);
ScheduleDraw(); ScheduleDraw();
return true; return true;
} }
...@@ -673,20 +669,17 @@ void Layer::ScheduleDraw() { ...@@ -673,20 +669,17 @@ void Layer::ScheduleDraw() {
} }
void Layer::SendDamagedRects() { void Layer::SendDamagedRects() {
if ((delegate_ || mailbox_.IsValid()) && !damaged_region_.isEmpty()) { if (damaged_region_.IsEmpty())
for (SkRegion::Iterator iter(damaged_region_); !iter.done(); iter.next()) { return;
const SkIRect& sk_damaged = iter.rect(); if (!delegate_ && !mailbox_.IsValid())
gfx::Rect damaged( return;
sk_damaged.x(),
sk_damaged.y(), for (cc::Region::Iterator iter(damaged_region_); iter.has_rect(); iter.next())
sk_damaged.width(), cc_layer_->SetNeedsDisplayRect(iter.rect());
sk_damaged.height()); }
cc_layer_->SetNeedsDisplayRect(damaged);
} void Layer::ClearDamagedRects() {
damaged_region_.setEmpty(); damaged_region_.Clear();
}
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->SendDamagedRects();
} }
void Layer::CompleteAllAnimations() { void Layer::CompleteAllAnimations() {
...@@ -745,6 +738,7 @@ void Layer::PaintContents( ...@@ -745,6 +738,7 @@ void Layer::PaintContents(
const gfx::Rect& clip, const gfx::Rect& clip,
ContentLayerClient::PaintingControlSetting painting_control) { ContentLayerClient::PaintingControlSetting painting_control) {
TRACE_EVENT1("ui", "Layer::PaintContents", "name", name_); TRACE_EVENT1("ui", "Layer::PaintContents", "name", name_);
ClearDamagedRects();
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
sk_canvas, device_scale_factor_)); sk_canvas, device_scale_factor_));
if (delegate_) if (delegate_)
...@@ -756,15 +750,16 @@ void Layer::PaintContentsToDisplayList( ...@@ -756,15 +750,16 @@ void Layer::PaintContentsToDisplayList(
const gfx::Rect& clip, const gfx::Rect& clip,
ContentLayerClient::PaintingControlSetting painting_control) { ContentLayerClient::PaintingControlSetting painting_control) {
TRACE_EVENT1("ui", "Layer::PaintContentsToDisplayList", "name", name_); TRACE_EVENT1("ui", "Layer::PaintContentsToDisplayList", "name", name_);
if (delegate_) { ClearDamagedRects();
// TODO(danakj): Save the invalidation on the layer and pass that down if (!delegate_)
// instead of the |clip| here. That will break everything until View return;
// early-outs emit cached display items instead of nothing. // TODO(danakj): Save the invalidation on the layer and pass that down
gfx::Rect invalidation = clip; // instead of the |clip| here. That will break everything until View
DCHECK(clip.Contains(invalidation)); // early-outs emit cached display items instead of nothing.
delegate_->OnPaintLayer( gfx::Rect invalidation = clip;
PaintContext(display_list, device_scale_factor_, clip, invalidation)); DCHECK(clip.Contains(invalidation));
} delegate_->OnPaintLayer(
PaintContext(display_list, device_scale_factor_, clip, invalidation));
} }
bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "cc/animation/animation_events.h" #include "cc/animation/animation_events.h"
#include "cc/animation/layer_animation_event_observer.h" #include "cc/animation/layer_animation_event_observer.h"
#include "cc/base/region.h"
#include "cc/base/scoped_ptr_vector.h" #include "cc/base/scoped_ptr_vector.h"
#include "cc/layers/content_layer_client.h" #include "cc/layers/content_layer_client.h"
#include "cc/layers/layer_client.h" #include "cc/layers/layer_client.h"
...@@ -319,8 +320,9 @@ class COMPOSITOR_EXPORT Layer ...@@ -319,8 +320,9 @@ class COMPOSITOR_EXPORT Layer
// Uses damaged rectangles recorded in |damaged_region_| to invalidate the // Uses damaged rectangles recorded in |damaged_region_| to invalidate the
// |cc_layer_|. // |cc_layer_|.
void SendDamagedRects(); void SendDamagedRects();
void ClearDamagedRects();
const SkRegion& damaged_region() const { return damaged_region_; } const cc::Region& damaged_region() const { return damaged_region_; }
void CompleteAllAnimations(); void CompleteAllAnimations();
...@@ -459,9 +461,9 @@ class COMPOSITOR_EXPORT Layer ...@@ -459,9 +461,9 @@ class COMPOSITOR_EXPORT Layer
bool fills_bounds_opaquely_; bool fills_bounds_opaquely_;
bool fills_bounds_completely_; bool fills_bounds_completely_;
// Union of damaged rects, in pixel coordinates, to be used when // Union of damaged rects, in layer space, to be used when compositor is ready
// compositor is ready to paint the content. // to paint the content.
SkRegion damaged_region_; cc::Region damaged_region_;
int background_blur_radius_; int background_blur_radius_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment