Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / compositor / paint_context.h
blobd63f11f7852b44c328b0cef7f855a0c0b1eef8de
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"
13 namespace cc {
14 class DisplayItemList;
17 namespace gfx {
18 class Canvas;
21 class SkPictureRecorder;
23 namespace ui {
24 class ClipTransformRecorder;
25 class CompositingRecorder;
26 class PaintRecorder;
28 class COMPOSITOR_EXPORT PaintContext {
29 public:
30 // Construct a PaintContext that may only re-paint the area in the
31 // |invalidation|.
32 PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation);
34 // Construct a PaintContext that may only re-paint the area in the
35 // |invalidation|.
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
42 // for invalidation).
43 explicit PaintContext(gfx::Canvas* canvas);
45 PaintContext(const PaintContext& other);
47 ~PaintContext();
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
60 // invalid.
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_);
71 #if DCHECK_IS_ON()
72 void Visited(void* visited) const {
73 if (!root_visited_)
74 root_visited_ = visited;
76 void* RootVisited() const { return root_visited_; }
77 const gfx::Vector2d& PaintOffset() const { return offset_; }
78 #endif
80 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
82 private:
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);
95 gfx::Canvas* canvas_;
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.
103 gfx::Rect bounds_;
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
108 // |invalidation_|.
109 gfx::Vector2d offset_;
111 #if DCHECK_IS_ON()
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_;
118 #endif
121 } // namespace ui
123 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_