Update V8 to version 4.6.55.
[chromium-blink-merge.git] / ui / compositor / paint_context.h
blobee9134ed837f6bcbd7e7a669a05d43d2da8a93e5
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& invalidation);
36 // Clone a PaintContext with an additional |offset|.
37 PaintContext(const PaintContext& other, const gfx::Vector2d& offset);
39 // Clone a PaintContext that has no consideration for invalidation.
40 enum CloneWithoutInvalidation {
41 CLONE_WITHOUT_INVALIDATION,
43 PaintContext(const PaintContext& other, CloneWithoutInvalidation c);
45 ~PaintContext();
47 // When true, IsRectInvalid() can be called, otherwise its result would be
48 // invalid.
49 bool CanCheckInvalid() const { return !invalidation_.IsEmpty(); }
51 // When true, the |bounds| touches an invalidated area, so should be
52 // re-painted. When false, re-painting can be skipped. Bounds should be in
53 // the local space with offsets up to the painting root in the PaintContext.
54 bool IsRectInvalid(const gfx::Rect& bounds) const {
55 DCHECK(CanCheckInvalid());
56 return invalidation_.Intersects(bounds + offset_);
59 #if DCHECK_IS_ON()
60 void Visited(void* visited) const {
61 if (!root_visited_)
62 root_visited_ = visited;
64 void* RootVisited() const { return root_visited_; }
65 const gfx::Vector2d& PaintOffset() const { return offset_; }
66 #endif
68 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
70 private:
71 // The Recorder classes need access to the internal canvas and friends, but we
72 // don't want to expose them on this class so that people must go through the
73 // recorders to access them.
74 friend class ClipTransformRecorder;
75 friend class CompositingRecorder;
76 friend class PaintRecorder;
77 // The Cache class also needs to access the DisplayItemList to append its
78 // cache contents.
79 friend class PaintCache;
81 cc::DisplayItemList* list_;
82 scoped_ptr<SkPictureRecorder> owned_recorder_;
83 // A pointer to the |owned_recorder_| in this PaintContext, or in another one
84 // which this was copied from. We expect a copied-from PaintContext to outlive
85 // copies made from it.
86 SkPictureRecorder* recorder_;
87 // The device scale of the frame being painted. Used to determine which bitmap
88 // resources to use in the frame.
89 float device_scale_factor_;
90 // Invalidation in the space of the paint root (ie the space of the layer
91 // backing the paint taking place).
92 gfx::Rect invalidation_;
93 // Offset from the PaintContext to the space of the paint root and the
94 // |invalidation_|.
95 gfx::Vector2d offset_;
97 #if DCHECK_IS_ON()
98 // Used to verify that the |invalidation_| is only used to compare against
99 // rects in the same space.
100 mutable void* root_visited_;
101 // Used to verify that paint recorders are not nested. True while a paint
102 // recorder is active.
103 mutable bool inside_paint_recorder_;
104 #endif
106 DISALLOW_COPY_AND_ASSIGN(PaintContext);
109 } // namespace ui
111 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_