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.
5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_
6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_
8 #include "base/logging.h"
9 #include "ui/gfx/geometry/rect.h"
20 // Construct a PaintContext that can only re-paint the area in the
22 PaintContext(gfx::Canvas
* canvas
, const gfx::Rect
& invalidation
)
23 : canvas_(canvas
), invalidation_(invalidation
) {
25 root_visited_
= nullptr;
29 // Construct a PaintContext that will re-paint everything (no consideration
31 explicit PaintContext(gfx::Canvas
* canvas
)
32 : PaintContext(canvas
, gfx::Rect()) {}
36 // Clone a PaintContext with an additional |offset|.
37 PaintContext
CloneWithPaintOffset(const gfx::Vector2d
& offset
) const {
38 return PaintContext(*this, offset
);
41 // Clone a PaintContext that has no consideration for invalidation.
42 PaintContext
CloneWithoutInvalidation() const {
43 return PaintContext(canvas_
);
46 // TODO(danakj): Remove this once everything is painting to display lists.
47 gfx::Canvas
* canvas() const { return canvas_
; }
49 // When true, IsRectInvalidated() can be called, otherwise its result would be
51 bool CanCheckInvalidated() const { return !invalidation_
.IsEmpty(); }
53 // When true, the |bounds| touches an invalidated area, so should be
54 // re-painted. When false, re-painting can be skipped. Bounds should be in
55 // the local space with offsets up to the painting root in the PaintContext.
56 bool IsRectInvalidated(const gfx::Rect
& bounds
) const {
57 DCHECK(CanCheckInvalidated());
58 return invalidation_
.Intersects(bounds
+ offset_
);
62 void Visited(void* visited
) const {
64 root_visited_
= visited
;
66 void* RootVisited() const { return root_visited_
; }
67 const gfx::Vector2d
& PaintOffset() const { return offset_
; }
70 const gfx::Rect
& InvalidationForTesting() const { return invalidation_
; }
73 // The PaintRecorder needs access to the internal canvas and friends, but we
74 // don't want to expose them on this class so that people must go through the
75 // recorder to access them.
76 friend class PaintRecorder
;
78 // Clone a PaintContext with an additional |offset|.
79 PaintContext(const PaintContext
& other
, const gfx::Vector2d
& offset
)
80 : canvas_(other
.canvas_
),
81 invalidation_(other
.invalidation_
),
82 offset_(other
.offset_
+ offset
) {
84 root_visited_
= other
.root_visited_
;
89 // Invalidation in the space of the paint root (ie the space of the layer
90 // backing the paint taking place).
91 gfx::Rect invalidation_
;
92 // Offset from the PaintContext to the space of the paint root and the
94 gfx::Vector2d offset_
;
97 // Used to verify that the |invalidation_| is only used to compare against
98 // rects in the same space.
99 mutable void* root_visited_
;
105 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_