Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: ui/views/view.cc

Issue 1053143002: Make View::Paint use ui::PaintRecorder to access PaintContext's canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: paintrecorder: explicit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/compositor/compositor.gyp ('K') | « ui/compositor/paint_recorder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view.cc
diff --git a/ui/views/view.cc b/ui/views/view.cc
index da1491dd6de2e633432815af2cc363c60c4eadef..387363a855348aa5dfc15801fc72b7a4d7b14a3f 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -24,6 +24,7 @@
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/paint_context.h"
+#include "ui/compositor/paint_recorder.h"
#include "ui/events/event_target_iterator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/point3_f.h"
@@ -774,16 +775,18 @@ void View::Paint(const ui::PaintContext& parent_context) {
TRACE_EVENT1("views", "View::Paint", "class", GetClassName());
- gfx::Canvas* canvas = context.canvas();
- gfx::ScopedCanvas scoped_canvas(canvas);
-
// If the view is backed by a layer, it should paint with itself as the origin
// rather than relative to its parent.
- if (!layer()) {
+ bool paint_relative_to_parent = !layer();
+ if (paint_relative_to_parent) {
// Set the clip rect to the bounds of this View. Note that the X (or left)
// position we pass to ClipRect takes into consideration whether or not the
// View uses a right-to-left layout so that we paint the View in its
// mirrored position if need be.
+ ui::PaintRecorder recorder(context);
+ gfx::Canvas* canvas = recorder.canvas();
+ canvas->Save();
+
gfx::Rect clip_rect = bounds();
clip_rect.Inset(clip_insets_);
if (parent_)
@@ -797,12 +800,15 @@ void View::Paint(const ui::PaintContext& parent_context) {
}
{
+ ui::PaintRecorder recorder(context);
+ gfx::Canvas* canvas = recorder.canvas();
+ gfx::ScopedCanvas scoped_canvas(canvas);
+
// 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);
@@ -812,7 +818,13 @@ void View::Paint(const ui::PaintContext& parent_context) {
OnPaint(canvas);
}
+ // View::Paint recursion over the subtree.
PaintChildren(context);
+
+ if (paint_relative_to_parent) {
+ ui::PaintRecorder recorder(context);
+ recorder.canvas()->Restore();
+ }
}
void View::set_background(Background* b) {
« ui/compositor/compositor.gyp ('K') | « ui/compositor/paint_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698