summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2015-04-24 15:35:11 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-24 22:36:12 +0000
commit0b5eae6c645b9b25e34322d328eaef00d14aef0f (patch)
treed10466b4c45279110361dd7b55b7d508cb5ee1c5
parentd20473d166912de9d8f271c7bdabc75ee60a42f0 (diff)
downloadchromium_src-0b5eae6c645b9b25e34322d328eaef00d14aef0f.zip
chromium_src-0b5eae6c645b9b25e34322d328eaef00d14aef0f.tar.gz
chromium_src-0b5eae6c645b9b25e34322d328eaef00d14aef0f.tar.bz2
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}
-rw-r--r--content/browser/compositor/reflector_impl_unittest.cc13
-rw-r--r--ui/compositor/compositor.cc11
-rw-r--r--ui/compositor/layer.cc51
-rw-r--r--ui/compositor/layer.h10
4 files changed, 44 insertions, 41 deletions
diff --git a/content/browser/compositor/reflector_impl_unittest.cc b/content/browser/compositor/reflector_impl_unittest.cc
index 2f0c299..867a9de 100644
--- a/content/browser/compositor/reflector_impl_unittest.cc
+++ b/content/browser/compositor/reflector_impl_unittest.cc
@@ -91,8 +91,7 @@ class TestOutputSurface : public BrowserCompositorOutputSurface {
gfx::Size SurfaceSize() const override { return gfx::Size(256, 256); }
};
-const gfx::Rect kSubRect = gfx::Rect(0, 0, 64, 64);
-const SkIRect kSkSubRect = SkIRect::MakeXYWH(0, 0, 64, 64);
+const gfx::Rect kSubRect(0, 0, 64, 64);
} // namespace
@@ -161,10 +160,10 @@ TEST_F(ReflectorImplTest, CheckNormalOutputSurface) {
SetUpReflector();
UpdateTexture();
EXPECT_TRUE(mirroring_layer_->TextureFlipped());
- EXPECT_EQ(SkRegion(SkIRect::MakeXYWH(
- 0, output_surface_->SurfaceSize().height() - kSubRect.height(),
- kSubRect.width(), kSubRect.height())),
- mirroring_layer_->damaged_region());
+ gfx::Rect expected_rect =
+ kSubRect + gfx::Vector2d(0, output_surface_->SurfaceSize().height()) -
+ gfx::Vector2d(0, kSubRect.height());
+ EXPECT_EQ(expected_rect, mirroring_layer_->damaged_region());
}
TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) {
@@ -172,7 +171,7 @@ TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) {
SetUpReflector();
UpdateTexture();
EXPECT_FALSE(mirroring_layer_->TextureFlipped());
- EXPECT_EQ(SkRegion(kSkSubRect), mirroring_layer_->damaged_region());
+ EXPECT_EQ(kSubRect, mirroring_layer_->damaged_region());
}
#if defined(USE_OZONE)
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 43dd460..c50f9ef 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -326,9 +326,16 @@ void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {
void Compositor::BeginMainFrameNotExpectedSoon() {
}
+static void SendDamagedRectsRecursive(ui::Layer* layer) {
+ layer->SendDamagedRects();
+ for (auto* child : layer->children())
+ SendDamagedRectsRecursive(child);
+}
+
void Compositor::Layout() {
- if (root_layer_)
- root_layer_->SendDamagedRects();
+ if (!root_layer())
+ return;
+ SendDamagedRectsRecursive(root_layer());
}
void Compositor::RequestNewOutputSurface() {
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 3e61d40..914e000 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -657,11 +657,7 @@ bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid()))
return false;
- damaged_region_.op(invalid_rect.x(),
- invalid_rect.y(),
- invalid_rect.right(),
- invalid_rect.bottom(),
- SkRegion::kUnion_Op);
+ damaged_region_.Union(invalid_rect);
ScheduleDraw();
return true;
}
@@ -673,20 +669,17 @@ void Layer::ScheduleDraw() {
}
void Layer::SendDamagedRects() {
- if ((delegate_ || mailbox_.IsValid()) && !damaged_region_.isEmpty()) {
- for (SkRegion::Iterator iter(damaged_region_); !iter.done(); iter.next()) {
- const SkIRect& sk_damaged = iter.rect();
- gfx::Rect damaged(
- sk_damaged.x(),
- sk_damaged.y(),
- sk_damaged.width(),
- sk_damaged.height());
- cc_layer_->SetNeedsDisplayRect(damaged);
- }
- damaged_region_.setEmpty();
- }
- for (size_t i = 0; i < children_.size(); ++i)
- children_[i]->SendDamagedRects();
+ if (damaged_region_.IsEmpty())
+ return;
+ if (!delegate_ && !mailbox_.IsValid())
+ return;
+
+ for (cc::Region::Iterator iter(damaged_region_); iter.has_rect(); iter.next())
+ cc_layer_->SetNeedsDisplayRect(iter.rect());
+}
+
+void Layer::ClearDamagedRects() {
+ damaged_region_.Clear();
}
void Layer::CompleteAllAnimations() {
@@ -745,6 +738,7 @@ void Layer::PaintContents(
const gfx::Rect& clip,
ContentLayerClient::PaintingControlSetting painting_control) {
TRACE_EVENT1("ui", "Layer::PaintContents", "name", name_);
+ ClearDamagedRects();
scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
sk_canvas, device_scale_factor_));
if (delegate_)
@@ -756,15 +750,16 @@ void Layer::PaintContentsToDisplayList(
const gfx::Rect& clip,
ContentLayerClient::PaintingControlSetting painting_control) {
TRACE_EVENT1("ui", "Layer::PaintContentsToDisplayList", "name", name_);
- if (delegate_) {
- // TODO(danakj): Save the invalidation on the layer and pass that down
- // instead of the |clip| here. That will break everything until View
- // early-outs emit cached display items instead of nothing.
- gfx::Rect invalidation = clip;
- DCHECK(clip.Contains(invalidation));
- delegate_->OnPaintLayer(
- PaintContext(display_list, device_scale_factor_, clip, invalidation));
- }
+ ClearDamagedRects();
+ if (!delegate_)
+ return;
+ // TODO(danakj): Save the invalidation on the layer and pass that down
+ // instead of the |clip| here. That will break everything until View
+ // early-outs emit cached display items instead of nothing.
+ gfx::Rect invalidation = clip;
+ DCHECK(clip.Contains(invalidation));
+ delegate_->OnPaintLayer(
+ PaintContext(display_list, device_scale_factor_, clip, invalidation));
}
bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; }
diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h
index 381e982..bb8b1af 100644
--- a/ui/compositor/layer.h
+++ b/ui/compositor/layer.h
@@ -14,6 +14,7 @@
#include "base/message_loop/message_loop.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/layer_animation_event_observer.h"
+#include "cc/base/region.h"
#include "cc/base/scoped_ptr_vector.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/layer_client.h"
@@ -319,8 +320,9 @@ class COMPOSITOR_EXPORT Layer
// Uses damaged rectangles recorded in |damaged_region_| to invalidate the
// |cc_layer_|.
void SendDamagedRects();
+ void ClearDamagedRects();
- const SkRegion& damaged_region() const { return damaged_region_; }
+ const cc::Region& damaged_region() const { return damaged_region_; }
void CompleteAllAnimations();
@@ -459,9 +461,9 @@ class COMPOSITOR_EXPORT Layer
bool fills_bounds_opaquely_;
bool fills_bounds_completely_;
- // Union of damaged rects, in pixel coordinates, to be used when
- // compositor is ready to paint the content.
- SkRegion damaged_region_;
+ // Union of damaged rects, in layer space, to be used when compositor is ready
+ // to paint the content.
+ cc::Region damaged_region_;
int background_blur_radius_;