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 { |
sky
2017/06/23 23:40:23
enum class.
malaykeshav
2017/07/07 22:57:10
Done
| |
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, | |
danakj
2017/06/27 16:28:36
Why is this a property of a PaintContext? A view c
malaykeshav
2017/07/07 22:57:10
These are the scales that set the recording bounds
| |
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 const gfx::Size& pixel_size() const { return pixel_bounds_.size(); } | |
85 const gfx::Rect& pixel_bounds() const { return pixel_bounds_; } | |
86 | |
87 // Scales the given DIP measurement to their corresponding canvas measurement | |
88 // using the effective scale factors and corner point scaling logic. | |
89 // Returns the measurements as is, if pixel canvas is disabled. | |
90 gfx::Size ScaleToCornerScaledPixelSize(const gfx::Size& size) const; | |
91 | |
92 // A tranform that converts a given cooridinate from local DIP coordinates to | |
93 // the parent pixel coordinates. | |
94 gfx::Transform TransformToParentPixelSpace() const; | |
95 | |
68 private: | 96 private: |
69 // The Recorder classes need access to the internal canvas and friends, but we | 97 // 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 | 98 // don't want to expose them on this class so that people must go through the |
71 // recorders to access them. | 99 // recorders to access them. |
72 friend class ClipRecorder; | 100 friend class ClipRecorder; |
73 friend class CompositingRecorder; | 101 friend class CompositingRecorder; |
74 friend class PaintRecorder; | 102 friend class PaintRecorder; |
75 friend class TransformRecorder; | 103 friend class TransformRecorder; |
76 // The Cache class also needs to access the DisplayItemList to append its | 104 // The Cache class also needs to access the DisplayItemList to append its |
77 // cache contents. | 105 // cache contents. |
78 friend class PaintCache; | 106 friend class PaintCache; |
79 | 107 |
80 // Returns a rect with the given size in the space of the context's | 108 // Returns a rect with the given size in the space of the context's |
81 // containing layer. | 109 // containing layer. |
82 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; | 110 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; |
83 | 111 |
84 // Returns the given rect translated by the layer space offset. | 112 // Returns the given rect translated by the layer space offset. |
85 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; | 113 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; |
86 | 114 |
115 // Scales the |child_bounds| to its pixel bounds based on the | |
116 // |device_scale_factor_|. The pixel bounds are snapped to the parent bound's | |
117 // right and/or bottom edge if required. | |
118 // This function returns |child_bounds| as is if pixel canvas is disabled. | |
119 gfx::Rect GetSnappedPixelBounds(const gfx::Rect& child_bounds) const; | |
120 | |
121 // Due to decimal rounding during scaling operations the effective device | |
122 // scale factor ends up being different from |device_scale_factor_|. To | |
123 // convert any DIP measurement to its corresponding measurement on the canvas, | |
124 // the following scales must be used. | |
125 float effective_scale_factor_x() const; | |
126 float effective_scale_factor_y() const; | |
127 | |
87 cc::DisplayItemList* list_; | 128 cc::DisplayItemList* list_; |
88 // The device scale of the frame being painted. Used to determine which bitmap | 129 // The device scale of the frame being painted. Used to determine which bitmap |
89 // resources to use in the frame. | 130 // resources to use in the frame. |
90 float device_scale_factor_; | 131 float device_scale_factor_; |
91 // Invalidation in the space of the paint root (ie the space of the layer | 132 // Invalidation in the space of the paint root (ie the space of the layer |
92 // backing the paint taking place). | 133 // backing the paint taking place). This is in pixel size if pixel canvas is |
134 // enabled. | |
93 gfx::Rect invalidation_; | 135 gfx::Rect invalidation_; |
136 // Bounds of the paint context. | |
137 const gfx::Rect bounds_; | |
138 // Bounds of paint context in exact pixel size. This will have the same value | |
139 // as |bounds_| if pixel canvas is disabled. | |
140 const gfx::Rect pixel_bounds_; | |
94 // Offset from the PaintContext to the space of the paint root and the | 141 // Offset from the PaintContext to the space of the paint root and the |
95 // |invalidation_|. | 142 // |invalidation_|. This is in pixels if pixel canvas is enabled. |
96 gfx::Vector2d offset_; | 143 gfx::Vector2d offset_; |
144 // The |scale_type| tells the context how it needs to perform scaling when | |
145 // pixel canvas is enabled. | |
146 int scale_type_ = SCALE_TO_SCALE_FACTOR; | |
97 | 147 |
98 #if DCHECK_IS_ON() | 148 #if DCHECK_IS_ON() |
99 // Used to verify that the |invalidation_| is only used to compare against | 149 // Used to verify that the |invalidation_| is only used to compare against |
100 // rects in the same space. | 150 // rects in the same space. |
101 mutable void* root_visited_; | 151 mutable void* root_visited_; |
102 // Used to verify that paint recorders are not nested. True while a paint | 152 // Used to verify that paint recorders are not nested. True while a paint |
103 // recorder is active. | 153 // recorder is active. |
104 mutable bool inside_paint_recorder_; | 154 mutable bool inside_paint_recorder_; |
105 #endif | 155 #endif |
106 | 156 |
107 DISALLOW_COPY_AND_ASSIGN(PaintContext); | 157 DISALLOW_COPY_AND_ASSIGN(PaintContext); |
108 }; | 158 }; |
109 | 159 |
110 } // namespace ui | 160 } // namespace ui |
111 | 161 |
112 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ | 162 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ |
OLD | NEW |