Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / compositor / paint_context.h
blob914f9a9f04ca3ac3393b6cc280af8c0510827173
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/gfx/geometry/rect.h"
11 namespace gfx {
12 class Canvas;
15 namespace ui {
16 class PaintRecorder;
18 class PaintContext {
19 public:
20 // Construct a PaintContext that can only re-paint the area in the
21 // |invalidation|.
22 PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation)
23 : canvas_(canvas), invalidation_(invalidation) {
24 #if DCHECK_IS_ON()
25 root_visited_ = nullptr;
26 #endif
29 // Construct a PaintContext that will re-paint everything (no consideration
30 // for invalidation).
31 explicit PaintContext(gfx::Canvas* canvas)
32 : PaintContext(canvas, gfx::Rect()) {}
34 ~PaintContext() {}
36 // Clone a PaintContext with an additional |offset|.
37 PaintContext CloneWithPaintOffset(const gfx::Vector2d& offset) const {
38 return PaintContext(*this, offset);
41 // Clone a PaintContext that has no consideration for invalidation.
42 PaintContext CloneWithoutInvalidation() const {
43 return PaintContext(canvas_);
46 // TODO(danakj): Remove this once everything is painting to display lists.
47 gfx::Canvas* canvas() const { return canvas_; }
49 // When true, IsRectInvalidated() can be called, otherwise its result would be
50 // invalid.
51 bool CanCheckInvalidated() const { return !invalidation_.IsEmpty(); }
53 // When true, the |bounds| touches an invalidated area, so should be
54 // re-painted. When false, re-painting can be skipped. Bounds should be in
55 // the local space with offsets up to the painting root in the PaintContext.
56 bool IsRectInvalidated(const gfx::Rect& bounds) const {
57 DCHECK(CanCheckInvalidated());
58 return invalidation_.Intersects(bounds + offset_);
61 #if DCHECK_IS_ON()
62 void Visited(void* visited) const {
63 if (!root_visited_)
64 root_visited_ = visited;
66 void* RootVisited() const { return root_visited_; }
67 const gfx::Vector2d& PaintOffset() const { return offset_; }
68 #endif
70 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
72 private:
73 // The PaintRecorder needs access to the internal canvas and friends, but we
74 // don't want to expose them on this class so that people must go through the
75 // recorder to access them.
76 friend class PaintRecorder;
78 // Clone a PaintContext with an additional |offset|.
79 PaintContext(const PaintContext& other, const gfx::Vector2d& offset)
80 : canvas_(other.canvas_),
81 invalidation_(other.invalidation_),
82 offset_(other.offset_ + offset) {
83 #if DCHECK_IS_ON()
84 root_visited_ = other.root_visited_;
85 #endif
88 gfx::Canvas* canvas_;
89 // Invalidation in the space of the paint root (ie the space of the layer
90 // backing the paint taking place).
91 gfx::Rect invalidation_;
92 // Offset from the PaintContext to the space of the paint root and the
93 // |invalidation_|.
94 gfx::Vector2d offset_;
96 #if DCHECK_IS_ON()
97 // Used to verify that the |invalidation_| is only used to compare against
98 // rects in the same space.
99 mutable void* root_visited_;
100 #endif
103 } // namespace ui
105 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_