bluetooth: android: Initial Low Energy Discovery Sessions.
[chromium-blink-merge.git] / ui / compositor / paint_context.h
blob8a27a1bee3b47a1a2ffc042869ba0dbeb6f4a742
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(cc::DisplayItemList* list,
33 float device_scale_factor,
34 const gfx::Rect& bounds,
35 const gfx::Rect& invalidation);
37 // Clone a PaintContext with an additional |offset|.
38 PaintContext(const PaintContext& other, const gfx::Vector2d& offset);
40 // Clone a PaintContext that has no consideration for invalidation.
41 enum CloneWithoutInvalidation {
42 CLONE_WITHOUT_INVALIDATION,
44 PaintContext(const PaintContext& other, CloneWithoutInvalidation c);
46 ~PaintContext();
48 // When true, IsRectInvalid() can be called, otherwise its result would be
49 // invalid.
50 bool CanCheckInvalid() const { return !invalidation_.IsEmpty(); }
52 // When true, the |bounds| touches an invalidated area, so should be
53 // re-painted. When false, re-painting can be skipped. Bounds should be in
54 // the local space with offsets up to the painting root in the PaintContext.
55 bool IsRectInvalid(const gfx::Rect& bounds) const {
56 DCHECK(CanCheckInvalid());
57 return invalidation_.Intersects(bounds + offset_);
60 #if DCHECK_IS_ON()
61 void Visited(void* visited) const {
62 if (!root_visited_)
63 root_visited_ = visited;
65 void* RootVisited() const { return root_visited_; }
66 const gfx::Vector2d& PaintOffset() const { return offset_; }
67 #endif
69 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
71 private:
72 // The Recorder classes need 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 // recorders to access them.
75 friend class ClipTransformRecorder;
76 friend class CompositingRecorder;
77 friend class PaintRecorder;
78 // The Cache class also needs to access the DisplayItemList to append its
79 // cache contents.
80 friend class PaintCache;
82 cc::DisplayItemList* list_;
83 scoped_ptr<SkPictureRecorder> owned_recorder_;
84 // A pointer to the |owned_recorder_| in this PaintContext, or in another one
85 // which this was copied from. We expect a copied-from PaintContext to outlive
86 // copies made from it.
87 SkPictureRecorder* recorder_;
88 // The device scale of the frame being painted. Used to determine which bitmap
89 // resources to use in the frame.
90 float device_scale_factor_;
91 // The bounds of the area being painted. Not all of it may be invalidated from
92 // the previous frame.
93 gfx::Rect bounds_;
94 // Invalidation in the space of the paint root (ie the space of the layer
95 // backing the paint taking place).
96 gfx::Rect invalidation_;
97 // Offset from the PaintContext to the space of the paint root and the
98 // |invalidation_|.
99 gfx::Vector2d offset_;
101 #if DCHECK_IS_ON()
102 // Used to verify that the |invalidation_| is only used to compare against
103 // rects in the same space.
104 mutable void* root_visited_;
105 // Used to verify that paint recorders are not nested. True while a paint
106 // recorder is active.
107 mutable bool inside_paint_recorder_;
108 #endif
110 DISALLOW_COPY_AND_ASSIGN(PaintContext);
113 } // namespace ui
115 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_