Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / compositor / paint_context.h
blob737745fed9d53455e9d4d2059709eef4878ecc19
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"
12 namespace cc {
13 class DisplayItemList;
16 namespace gfx {
17 class Canvas;
20 namespace ui {
21 class ClipTransformRecorder;
22 class CompositingRecorder;
23 class PaintRecorder;
25 class COMPOSITOR_EXPORT PaintContext {
26 public:
27 // Construct a PaintContext that may only re-paint the area in the
28 // |invalidation|.
29 PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation);
31 // Construct a PaintContext that may only re-paint the area in the
32 // |invalidation|.
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
39 // for invalidation).
40 explicit PaintContext(gfx::Canvas* canvas);
42 PaintContext(const PaintContext& other);
44 ~PaintContext();
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
57 // invalid.
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_);
68 #if DCHECK_IS_ON()
69 void Visited(void* visited) const {
70 if (!root_visited_)
71 root_visited_ = visited;
73 void* RootVisited() const { return root_visited_; }
74 const gfx::Vector2d& PaintOffset() const { return offset_; }
75 #endif
77 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
79 private:
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);
92 gfx::Canvas* canvas_;
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.
97 gfx::Rect bounds_;
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
102 // |invalidation_|.
103 gfx::Vector2d offset_;
105 #if DCHECK_IS_ON()
106 // Used to verify that the |invalidation_| is only used to compare against
107 // rects in the same space.
108 mutable void* root_visited_;
109 #endif
112 } // namespace ui
114 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_