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

Side by Side Diff: ui/compositor/paint_context.h

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: . Created 5 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_
6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_
7
8 #include "base/logging.h"
9 #include "ui/compositor/compositor_export.h"
10 #include "ui/gfx/geometry/rect.h"
11
12 namespace gfx {
13 class Canvas;
14 }
15
16 namespace ui {
17 class PaintRecorder;
18
19 class COMPOSITOR_EXPORT PaintContext {
20 public:
21 // Construct a PaintContext that can only re-paint the area in the
22 // |invalidation|.
23 PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation)
24 : canvas_(canvas), invalidation_(invalidation) {
25 #if DCHECK_IS_ON()
26 root_visited_ = nullptr;
27 #endif
28 }
29
30 // Construct a PaintContext that will re-paint everything (no consideration
31 // for invalidation).
32 explicit PaintContext(gfx::Canvas* canvas)
33 : PaintContext(canvas, gfx::Rect()) {}
34
35 ~PaintContext() {}
36
37 // Clone a PaintContext with an additional |offset|.
38 PaintContext CloneWithPaintOffset(const gfx::Vector2d& offset) const {
39 return PaintContext(*this, offset);
40 }
41
42 // Clone a PaintContext that has no consideration for invalidation.
43 PaintContext CloneWithoutInvalidation() const {
44 return PaintContext(canvas_);
45 }
46
47 // TODO(danakj): Remove this once everything is painting to display lists.
48 gfx::Canvas* canvas() const { return canvas_; }
49
50 // When true, IsRectInvalidated() can be called, otherwise its result would be
51 // invalid.
52 bool CanCheckInvalidated() const { return !invalidation_.IsEmpty(); }
53
54 // When true, the |bounds| touches an invalidated area, so should be
55 // re-painted. When false, re-painting can be skipped. Bounds should be in
56 // the local space with offsets up to the painting root in the PaintContext.
57 bool IsRectInvalidated(const gfx::Rect& bounds) const {
58 DCHECK(CanCheckInvalidated());
59 return invalidation_.Intersects(bounds + offset_);
60 }
61
62 #if DCHECK_IS_ON()
63 void Visited(void* visited) const {
64 if (!root_visited_)
65 root_visited_ = visited;
66 }
67 void* RootVisited() const { return root_visited_; }
68 const gfx::Vector2d& PaintOffset() const { return offset_; }
69 #endif
70
71 private:
72 // The PaintRecorder needs access to the internal canvas and friends, but we
73 // don't want to expose them on this class so that people must go through the
74 // recorder to access them.
75 friend class PaintRecorder;
76
77 // Clone a PaintContext with an additional |offset|.
78 PaintContext(const PaintContext& other, const gfx::Vector2d& offset)
79 : canvas_(other.canvas_),
80 invalidation_(other.invalidation_),
81 offset_(other.offset_ + offset) {
82 #if DCHECK_IS_ON()
83 root_visited_ = other.root_visited_;
84 #endif
85 }
86
87 gfx::Canvas* canvas_;
88 // Invalidation in the space of the paint root (ie the space of the layer
89 // backing the paint taking place).
90 gfx::Rect invalidation_;
91 // Offset from the PaintContext to the space of the paint root and the
92 // |invalidation_|.
93 gfx::Vector2d offset_;
94
95 #if DCHECK_IS_ON()
96 // Used to verify that the |invalidation_| is only used to compare against
97 // rects in the same space.
98 mutable void* root_visited_;
99 #endif
100 };
101
102 } // namespace ui
103
104 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698