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/compositor/compositor_export.h"
10 #include "ui/gfx/geometry/rect.h"
13 class DisplayItemList
;
21 class ClipTransformRecorder
;
22 class CompositingRecorder
;
25 class COMPOSITOR_EXPORT PaintContext
{
27 // Construct a PaintContext that may only re-paint the area in the
29 PaintContext(gfx::Canvas
* canvas
, const gfx::Rect
& invalidation
);
31 // Construct a PaintContext that may only re-paint the area in the
33 PaintContext(cc::DisplayItemList
* list
,
34 float device_scale_factor
,
35 const gfx::Rect
& bounds
,
36 const gfx::Rect
& invalidation
);
38 // Construct a PaintContext that will re-paint everything (no consideration
40 explicit PaintContext(gfx::Canvas
* canvas
);
42 PaintContext(const PaintContext
& other
);
46 // Clone a PaintContext with an additional |offset|.
47 PaintContext
CloneWithPaintOffset(const gfx::Vector2d
& offset
) const {
48 return PaintContext(*this, offset
);
51 // Clone a PaintContext that has no consideration for invalidation.
52 PaintContext
CloneWithoutInvalidation() const {
53 return PaintContext(canvas_
);
56 // When true, IsRectInvalidated() can be called, otherwise its result would be
58 bool CanCheckInvalidated() const { return !invalidation_
.IsEmpty(); }
60 // When true, the |bounds| touches an invalidated area, so should be
61 // re-painted. When false, re-painting can be skipped. Bounds should be in
62 // the local space with offsets up to the painting root in the PaintContext.
63 bool IsRectInvalidated(const gfx::Rect
& bounds
) const {
64 DCHECK(CanCheckInvalidated());
65 return invalidation_
.Intersects(bounds
+ offset_
);
69 void Visited(void* visited
) const {
71 root_visited_
= visited
;
73 void* RootVisited() const { return root_visited_
; }
74 const gfx::Vector2d
& PaintOffset() const { return offset_
; }
77 const gfx::Rect
& InvalidationForTesting() const { return invalidation_
; }
80 // The Recorder classes need access to the internal canvas and friends, but we
81 // don't want to expose them on this class so that people must go through the
82 // recorders to access them.
83 friend class ClipTransformRecorder
;
84 friend class CompositingRecorder
;
85 friend class PaintRecorder
;
87 PaintContext
& operator=(const PaintContext
& other
) = delete;
89 // Clone a PaintContext with an additional |offset|.
90 PaintContext(const PaintContext
& other
, const gfx::Vector2d
& offset
);
93 cc::DisplayItemList
* list_
;
94 float device_scale_factor_
;
95 // The bounds of the area being painted. Not all of it may be invalidated from
96 // the previous frame.
98 // Invalidation in the space of the paint root (ie the space of the layer
99 // backing the paint taking place).
100 gfx::Rect invalidation_
;
101 // Offset from the PaintContext to the space of the paint root and the
103 gfx::Vector2d offset_
;
106 // Used to verify that the |invalidation_| is only used to compare against
107 // rects in the same space.
108 mutable void* root_visited_
;
114 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_