Commit 6f9ccd4f authored by danakj's avatar danakj Committed by Commit bot

views: Remove View::PaintCommon, merge it into View::Paint.

This unifies the painting code path between Views that are and are not
backed by layers, they all go through View::Paint now.

View::Paint will only translate the canvas relative to the parent when
layer() is false, keeping the origin at the origin of the view when it
is backed by a layer().

R=sky
BUG=466426

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

Cr-Commit-Position: refs/heads/master@{#322394}
parent 3df099f5
...@@ -775,56 +775,76 @@ void View::Paint(gfx::Canvas* canvas, const CullSet& cull_set) { ...@@ -775,56 +775,76 @@ void View::Paint(gfx::Canvas* canvas, const CullSet& cull_set) {
gfx::ScopedCanvas scoped_canvas(canvas); gfx::ScopedCanvas scoped_canvas(canvas);
// Paint this View and its children, setting the clip rect to the bounds // If the view is backed by a layer, it should paint with itself as the origin
// of this View and translating the origin to the local bounds' top left // rather than relative to its parent.
// point. if (!layer()) {
// // Set the clip rect to the bounds of this View and translating the origin
// Note that the X (or left) position we pass to ClipRectInt takes into // to the local bounds' top left point.
// consideration whether or not the view uses a right-to-left layout so that //
// we paint our view in its mirrored position if need be. // Note that the X (or left) position we pass to ClipRectInt takes into
gfx::Rect clip_rect = bounds(); // consideration whether or not the view uses a right-to-left layout so that
clip_rect.Inset(clip_insets_); // we paint our view in its mirrored position if need be.
if (parent_) gfx::Rect clip_rect = bounds();
clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); clip_rect.Inset(clip_insets_);
canvas->ClipRect(clip_rect); if (parent_)
if (canvas->IsClipEmpty()) clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect));
return; canvas->ClipRect(clip_rect);
if (canvas->IsClipEmpty())
// Non-empty clip, translate the graphics such that 0,0 corresponds to where return;
// this view is located (related to its parent).
canvas->Translate(GetMirroredPosition().OffsetFromOrigin());
canvas->Transform(GetTransform());
// If we are a paint root, we need to construct our own CullSet object for
// propagation to our children.
if (IsPaintRoot()) {
if (!bounds_tree_)
bounds_tree_.reset(new BoundsTree(2, 5));
// Recompute our bounds tree as needed. // Non-empty clip, translate the graphics such that 0,0 corresponds to where
UpdateRootBounds(bounds_tree_.get(), gfx::Vector2d()); // this view is located (related to its parent).
canvas->Translate(GetMirroredPosition().OffsetFromOrigin());
canvas->Transform(GetTransform());
}
// Grab the clip rect from the supplied canvas to use as the query rect. {
gfx::Rect canvas_bounds; // If the View we are about to paint requested the canvas to be flipped, we
if (!canvas->GetClipBounds(&canvas_bounds)) { // should change the transform appropriately.
NOTREACHED() << "Failed to get clip bounds from the canvas!"; // The canvas mirroring is undone once the View is done painting so that we
return; // don't pass the canvas with the mirrored transform to Views that didn't
// request the canvas to be flipped.
gfx::ScopedCanvas scoped(canvas);
if (FlipCanvasOnPaintForRTLUI()) {
canvas->Translate(gfx::Vector2d(width(), 0));
canvas->Scale(-1, 1);
} }
// Now query our bounds_tree_ for a set of damaged views that intersect // Delegate painting the contents of the View to the virtual OnPaint method.
// our canvas bounds. OnPaint(canvas);
scoped_ptr<base::hash_set<intptr_t>> damaged_views( }
new base::hash_set<intptr_t>());
bounds_tree_->AppendIntersectingRecords(canvas_bounds, damaged_views.get()); // If the view is not a paint root, it should come with a CullSet already
// Construct a CullSet to wrap the damaged views set, it will delete it // constructed for use.
// for us on scope exit. // TODO(danakj): However, if it is a paint root but is also backed by a
CullSet paint_root_cull_set(damaged_views.Pass()); // layer(), we are unable to construct a CullSet because the bounds() do not
// Paint all descendents using our new cull set. // match the position we will be painting at and UpdateRootBounds() does the
PaintCommon(canvas, paint_root_cull_set); // wrong thing.
} else { if (!IsPaintRoot() || layer()) {
// Not a paint root, so we can proceed as normal. PaintChildren(canvas, cull_set);
PaintCommon(canvas, cull_set); return;
} }
// We are a paint root, so we construct our own CullSet object for propagation
// to our children.
if (!bounds_tree_)
bounds_tree_.reset(new BoundsTree(2, 5));
// Recompute our bounds tree as needed.
UpdateRootBounds(bounds_tree_.get(), gfx::Vector2d());
// Grab the clip rect from the supplied canvas to use as the query rect.
gfx::Rect canvas_bounds;
bool got_clip = canvas->GetClipBounds(&canvas_bounds);
DCHECK(got_clip) << "Failed to get clip bounds from the canvas!";
// Now query our bounds_tree_ for a set of damaged views that intersect
// our canvas bounds.
scoped_ptr<base::hash_set<intptr_t>> damaged_views(
new base::hash_set<intptr_t>);
bounds_tree_->AppendIntersectingRecords(canvas_bounds, damaged_views.get());
CullSet paint_root_cull_set(damaged_views.Pass());
PaintChildren(canvas, paint_root_cull_set);
} }
void View::set_background(Background* b) { void View::set_background(Background* b) {
...@@ -1464,11 +1484,11 @@ void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { ...@@ -1464,11 +1484,11 @@ void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) {
} }
void View::OnPaintLayer(gfx::Canvas* canvas) { void View::OnPaintLayer(gfx::Canvas* canvas) {
if (!layer() || !layer()->fills_bounds_opaquely()) if (!layer()->fills_bounds_opaquely())
canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
if (!visible_) if (!visible_)
return; return;
PaintCommon(canvas, CullSet()); Paint(canvas, CullSet());
} }
void View::OnDelegatedFrameDamage( void View::OnDelegatedFrameDamage(
...@@ -1751,25 +1771,6 @@ void View::SchedulePaintBoundsChanged(SchedulePaintType type) { ...@@ -1751,25 +1771,6 @@ void View::SchedulePaintBoundsChanged(SchedulePaintType type) {
} }
} }
void View::PaintCommon(gfx::Canvas* canvas, const CullSet& cull_set) {
{
// If the View we are about to paint requested the canvas to be flipped, we
// should change the transform appropriately.
// The canvas mirroring is undone once the View is done painting so that we
// don't pass the canvas with the mirrored transform to Views that didn't
// request the canvas to be flipped.
gfx::ScopedCanvas scoped(canvas);
if (FlipCanvasOnPaintForRTLUI()) {
canvas->Translate(gfx::Vector2d(width(), 0));
canvas->Scale(-1, 1);
}
OnPaint(canvas);
}
PaintChildren(canvas, cull_set);
}
// Tree operations ------------------------------------------------------------- // Tree operations -------------------------------------------------------------
void View::DoRemoveChildView(View* view, void View::DoRemoveChildView(View* view,
......
...@@ -1244,10 +1244,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -1244,10 +1244,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// new bounds. // new bounds.
void SchedulePaintBoundsChanged(SchedulePaintType type); void SchedulePaintBoundsChanged(SchedulePaintType type);
// Common Paint() code shared by accelerated and non-accelerated code paths to
// invoke OnPaint() on the View.
void PaintCommon(gfx::Canvas* canvas, const CullSet& cull_set);
// Tree operations ----------------------------------------------------------- // Tree operations -----------------------------------------------------------
// Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
......
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