OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_ | 5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_ |
6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_ | 6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "cc/paint/display_item_list.h" |
12 #include "cc/paint/paint_recorder.h" | 13 #include "cc/paint/paint_recorder.h" |
13 #include "ui/compositor/compositor_export.h" | 14 #include "ui/compositor/compositor_export.h" |
14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 class DisplayItemList; | 18 class DisplayItemList; |
18 } | 19 } |
19 | 20 |
20 namespace ui { | 21 namespace ui { |
21 class ClipRecorder; | 22 class ClipRecorder; |
22 class CompositingRecorder; | 23 class CompositingRecorder; |
23 class PaintRecorder; | 24 class PaintRecorder; |
24 class TransformRecorder; | 25 class TransformRecorder; |
25 | 26 |
26 class COMPOSITOR_EXPORT PaintContext { | 27 class COMPOSITOR_EXPORT PaintContext { |
27 public: | 28 public: |
28 // Construct a PaintContext that may only re-paint the area in the | 29 enum ScaleType { |
29 // |invalidation|. | 30 // Scales the context by the default dsf. Use this if you dont want any form |
| 31 // of distortion during scaling. |
| 32 SCALE_TO_SCALE_FACTOR = 0, |
| 33 |
| 34 // Scales the context based on the effective dsf. This may lead to minor |
| 35 // distortion during scaling. |
| 36 SCALE_TO_FIT |
| 37 }; |
| 38 |
| 39 // Construct a PaintContext of given size that may only re-paint the area in |
| 40 // the |invalidation|. |
30 PaintContext(cc::DisplayItemList* list, | 41 PaintContext(cc::DisplayItemList* list, |
31 float device_scale_factor, | 42 float device_scale_factor, |
32 const gfx::Rect& invalidation); | 43 const gfx::Rect& invalidation, |
| 44 const gfx::Size& size); |
33 | 45 |
34 // Clone a PaintContext with an additional |offset|. | 46 // Clone a PaintContext with different |bounds| that has some offset from its |
35 PaintContext(const PaintContext& other, const gfx::Vector2d& offset); | 47 // parent. |scale_type| should be from |ScaleType|. |
| 48 PaintContext(const PaintContext& other, |
| 49 const gfx::Rect& bounds, |
| 50 int scale_type); |
36 | 51 |
37 // Clone a PaintContext that has no consideration for invalidation. | 52 // Clone a PaintContext that has no consideration for invalidation. |
38 enum CloneWithoutInvalidation { | 53 enum CloneWithoutInvalidation { |
39 CLONE_WITHOUT_INVALIDATION, | 54 CLONE_WITHOUT_INVALIDATION, |
40 }; | 55 }; |
41 PaintContext(const PaintContext& other, CloneWithoutInvalidation c); | 56 PaintContext(const PaintContext& other, CloneWithoutInvalidation c); |
42 | 57 |
43 ~PaintContext(); | 58 ~PaintContext(); |
44 | 59 |
45 // When true, IsRectInvalid() can be called, otherwise its result would be | 60 // When true, ShouldRepaint() can be called, otherwise its result would be |
46 // invalid. | 61 // invalid. |
47 bool CanCheckInvalid() const { return !invalidation_.IsEmpty(); } | 62 bool CanCheckRepaint() const { return !invalidation_.IsEmpty(); } |
48 | 63 |
49 // When true, the |bounds| touches an invalidated area, so should be | 64 // When true, the |pixel_bounds_| touches an invalidated area, so should be |
50 // re-painted. When false, re-painting can be skipped. Bounds should be in | 65 // re-painted. When false, re-painting can be skipped. |
51 // the local space with offsets up to the painting root in the PaintContext. | 66 bool ShouldRepaint() const { |
52 bool IsRectInvalid(const gfx::Rect& bounds) const { | 67 DCHECK(CanCheckRepaint()); |
53 DCHECK(CanCheckInvalid()); | 68 return invalidation_.Intersects(gfx::Rect(pixel_size()) + offset_); |
54 return invalidation_.Intersects(bounds + offset_); | |
55 } | 69 } |
56 | 70 |
57 #if DCHECK_IS_ON() | 71 #if DCHECK_IS_ON() |
58 void Visited(void* visited) const { | 72 void Visited(void* visited) const { |
59 if (!root_visited_) | 73 if (!root_visited_) |
60 root_visited_ = visited; | 74 root_visited_ = visited; |
61 } | 75 } |
62 void* RootVisited() const { return root_visited_; } | 76 void* RootVisited() const { return root_visited_; } |
63 const gfx::Vector2d& PaintOffset() const { return offset_; } | 77 const gfx::Vector2d& PaintOffset() const { return offset_; } |
64 #endif | 78 #endif |
65 | 79 |
66 const gfx::Rect& InvalidationForTesting() const { return invalidation_; } | 80 const gfx::Rect& InvalidationForTesting() const { return invalidation_; } |
67 | 81 |
| 82 bool IsPixelCanvas() const { return list_ && list_->pixel_canvas_enabled(); } |
| 83 |
| 84 // Due to decimal rounding during scaling operations the effective device |
| 85 // scale factor ends up being different from |device_scale_factor_|. To |
| 86 // convert any DIP measurement to its corresponding measurement on the canvas, |
| 87 // the following scales must be used. |
| 88 float effective_scale_factor_x() const; |
| 89 float effective_scale_factor_y() const; |
| 90 |
| 91 const gfx::Size& pixel_size() const { return pixel_bounds_.size(); } |
| 92 const gfx::Rect& pixel_bounds() const { return pixel_bounds_; } |
| 93 |
| 94 // Scales the given DIP measurement to their corresponding canvas measurement |
| 95 // using the effective scale factors and corner point scaling logic. |
| 96 // Returns the measurements as is, if pixel canvas is disabled. |
| 97 gfx::Size ScaleToCorneredPixelSize(const gfx::Size& size) const; |
| 98 |
68 private: | 99 private: |
69 // The Recorder classes need access to the internal canvas and friends, but we | 100 // The Recorder classes need access to the internal canvas and friends, but we |
70 // don't want to expose them on this class so that people must go through the | 101 // don't want to expose them on this class so that people must go through the |
71 // recorders to access them. | 102 // recorders to access them. |
72 friend class ClipRecorder; | 103 friend class ClipRecorder; |
73 friend class CompositingRecorder; | 104 friend class CompositingRecorder; |
74 friend class PaintRecorder; | 105 friend class PaintRecorder; |
75 friend class TransformRecorder; | 106 friend class TransformRecorder; |
76 // The Cache class also needs to access the DisplayItemList to append its | 107 // The Cache class also needs to access the DisplayItemList to append its |
77 // cache contents. | 108 // cache contents. |
78 friend class PaintCache; | 109 friend class PaintCache; |
79 | 110 |
80 // Returns a rect with the given size in the space of the context's | 111 // Returns a rect with the given size in the space of the context's |
81 // containing layer. | 112 // containing layer. |
82 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; | 113 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; |
83 | 114 |
84 // Returns the given rect translated by the layer space offset. | 115 // Returns the given rect translated by the layer space offset. |
85 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; | 116 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; |
86 | 117 |
| 118 // Scales the |child_bounds| to its pixel bounds based on the |
| 119 // |device_scale_factor_|. The pixel bounds are snapped to the parent bound's |
| 120 // right and/or bottom edge if required. |
| 121 // This function returns |child_bounds| as is if pixel canvas is disabled. |
| 122 gfx::Rect GetSnappedPixelBounds(const gfx::Rect& child_bounds) const; |
| 123 |
87 cc::DisplayItemList* list_; | 124 cc::DisplayItemList* list_; |
88 // The device scale of the frame being painted. Used to determine which bitmap | 125 // The device scale of the frame being painted. Used to determine which bitmap |
89 // resources to use in the frame. | 126 // resources to use in the frame. |
90 float device_scale_factor_; | 127 float device_scale_factor_; |
91 // Invalidation in the space of the paint root (ie the space of the layer | 128 // Invalidation in the space of the paint root (ie the space of the layer |
92 // backing the paint taking place). | 129 // backing the paint taking place). This is in pixel size if pixel canvas is |
| 130 // enabled. |
93 gfx::Rect invalidation_; | 131 gfx::Rect invalidation_; |
| 132 // Bounds of the paint context. |
| 133 gfx::Rect bounds_; |
| 134 // Bounds of paint context in exact pixel size. This will have the same value |
| 135 // as |bounds_| if pixel canvas is disabled. |
| 136 gfx::Rect pixel_bounds_; |
94 // Offset from the PaintContext to the space of the paint root and the | 137 // Offset from the PaintContext to the space of the paint root and the |
95 // |invalidation_|. | 138 // |invalidation_|. This is in pixels if pixel canvas is enabled. |
96 gfx::Vector2d offset_; | 139 gfx::Vector2d offset_; |
| 140 // The |scale_type| tells the context how it needs to perform scaling when |
| 141 // pixel canvas is enabled. |
| 142 int scale_type_ = SCALE_TO_SCALE_FACTOR; |
97 | 143 |
98 #if DCHECK_IS_ON() | 144 #if DCHECK_IS_ON() |
99 // Used to verify that the |invalidation_| is only used to compare against | 145 // Used to verify that the |invalidation_| is only used to compare against |
100 // rects in the same space. | 146 // rects in the same space. |
101 mutable void* root_visited_; | 147 mutable void* root_visited_; |
102 // Used to verify that paint recorders are not nested. True while a paint | 148 // Used to verify that paint recorders are not nested. True while a paint |
103 // recorder is active. | 149 // recorder is active. |
104 mutable bool inside_paint_recorder_; | 150 mutable bool inside_paint_recorder_; |
105 #endif | 151 #endif |
106 | 152 |
107 DISALLOW_COPY_AND_ASSIGN(PaintContext); | 153 DISALLOW_COPY_AND_ASSIGN(PaintContext); |
108 }; | 154 }; |
109 | 155 |
110 } // namespace ui | 156 } // namespace ui |
111 | 157 |
112 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ | 158 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ |
OLD | NEW |