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 "base/memory/scoped_ptr.h"
10 #include "ui/compositor/compositor_export.h"
11 #include "ui/gfx/geometry/rect.h"
14 class DisplayItemList
;
21 class SkPictureRecorder
;
24 class ClipTransformRecorder
;
25 class CompositingRecorder
;
28 class COMPOSITOR_EXPORT PaintContext
{
30 // Construct a PaintContext that may only re-paint the area in the
32 PaintContext(gfx::Canvas
* canvas
, const gfx::Rect
& invalidation
);
34 // Construct a PaintContext that may only re-paint the area in the
36 PaintContext(cc::DisplayItemList
* list
,
37 float device_scale_factor
,
38 const gfx::Rect
& bounds
,
39 const gfx::Rect
& invalidation
);
41 // Construct a PaintContext that will re-paint everything (no consideration
43 explicit PaintContext(gfx::Canvas
* canvas
);
45 PaintContext(const PaintContext
& other
);
49 // Clone a PaintContext with an additional |offset|.
50 PaintContext
CloneWithPaintOffset(const gfx::Vector2d
& offset
) const {
51 return PaintContext(*this, offset
);
54 // Clone a PaintContext that has no consideration for invalidation.
55 PaintContext
CloneWithoutInvalidation() const {
56 return PaintContext(canvas_
);
59 // When true, IsRectInvalidated() can be called, otherwise its result would be
61 bool CanCheckInvalidated() const { return !invalidation_
.IsEmpty(); }
63 // When true, the |bounds| touches an invalidated area, so should be
64 // re-painted. When false, re-painting can be skipped. Bounds should be in
65 // the local space with offsets up to the painting root in the PaintContext.
66 bool IsRectInvalidated(const gfx::Rect
& bounds
) const {
67 DCHECK(CanCheckInvalidated());
68 return invalidation_
.Intersects(bounds
+ offset_
);
72 void Visited(void* visited
) const {
74 root_visited_
= visited
;
76 void* RootVisited() const { return root_visited_
; }
77 const gfx::Vector2d
& PaintOffset() const { return offset_
; }
80 const gfx::Rect
& InvalidationForTesting() const { return invalidation_
; }
83 // The Recorder classes need access to the internal canvas and friends, but we
84 // don't want to expose them on this class so that people must go through the
85 // recorders to access them.
86 friend class ClipTransformRecorder
;
87 friend class CompositingRecorder
;
88 friend class PaintRecorder
;
90 PaintContext
& operator=(const PaintContext
& other
) = delete;
92 // Clone a PaintContext with an additional |offset|.
93 PaintContext(const PaintContext
& other
, const gfx::Vector2d
& offset
);
96 cc::DisplayItemList
* list_
;
97 scoped_ptr
<SkPictureRecorder
> recorder_
;
98 // The device scale of the frame being painted. Used to determine which bitmap
99 // resources to use in the frame.
100 float device_scale_factor_
;
101 // The bounds of the area being painted. Not all of it may be invalidated from
102 // the previous frame.
104 // Invalidation in the space of the paint root (ie the space of the layer
105 // backing the paint taking place).
106 gfx::Rect invalidation_
;
107 // Offset from the PaintContext to the space of the paint root and the
109 gfx::Vector2d offset_
;
112 // Used to verify that the |invalidation_| is only used to compare against
113 // rects in the same space.
114 mutable void* root_visited_
;
115 // Used to verify that paint recorders are not nested. True while a paint
116 // recorder is active.
117 mutable bool inside_paint_recorder_
;
123 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_