OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
6 #define GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
7 | |
8 #include <IOSurface/IOSurface.h> | |
9 #include <QuartzCore/QuartzCore.h> | |
10 #include <deque> | |
11 #include <vector> | |
12 | |
13 #include "base/mac/scoped_cftyperef.h" | |
14 #include "base/mac/scoped_nsobject.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "gpu/gpu_export.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 #include "ui/gfx/geometry/rect_f.h" | |
19 #include "ui/gfx/mac/io_surface.h" | |
20 #include "ui/gfx/transform.h" | |
21 | |
22 @class AVSampleBufferDisplayLayer; | |
23 | |
24 namespace gpu { | |
25 | |
26 // The CALayerTree will construct a hierarchy of CALayers from a linear list, | |
27 // using the algorithm and structure referenced described in | |
28 // https://docs.google.com/document/d/1DtSN9zzvCF44_FQPM7ie01UxGHagQ66zfF5L9Hnig
QY/edit?usp=sharing | |
29 class GPU_EXPORT CALayerTree { | |
30 public: | |
31 CALayerTree(); | |
32 | |
33 // This will remove all CALayers from this tree from their superlayer. | |
34 ~CALayerTree(); | |
35 | |
36 // Append the description of a new CALayer to the tree. This will not | |
37 // create any new CALayers until CommitScheduledCALayers is called. This | |
38 // cannot be called anymore after CommitScheduledCALayers has been called. | |
39 bool ScheduleCALayer(bool is_clipped, | |
40 const gfx::Rect& clip_rect, | |
41 unsigned sorting_context_id, | |
42 const gfx::Transform& transform, | |
43 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
44 const gfx::RectF& contents_rect, | |
45 const gfx::Rect& rect, | |
46 unsigned background_color, | |
47 unsigned edge_aa_mask, | |
48 float opacity); | |
49 | |
50 // Create a CALayer tree for the scheduled layers, and set |superlayer| to | |
51 // have only this tree as its sublayers. If |old_tree| is non-null, then try | |
52 // to re-use the CALayers of |old_tree| as much as possible. |old_tree| will | |
53 // be destroyed at the end of the function, and any CALayers in it which were | |
54 // not re-used by |this| will be removed from the CALayer hierarchy. | |
55 void CommitScheduledCALayers(CALayer* superlayer, | |
56 scoped_ptr<CALayerTree> old_tree, | |
57 float scale_factor); | |
58 | |
59 private: | |
60 struct RootLayer; | |
61 struct ClipAndSortingLayer; | |
62 struct TransformLayer; | |
63 struct ContentLayer; | |
64 | |
65 struct RootLayer { | |
66 RootLayer(); | |
67 | |
68 // This will remove |ca_layer| from its superlayer, if |ca_layer| is | |
69 // non-nil. | |
70 ~RootLayer(); | |
71 | |
72 // Append a new content layer, without modifying the actual CALayer | |
73 // structure. | |
74 bool AddContentLayer(bool is_clipped, | |
75 const gfx::Rect& clip_rect, | |
76 unsigned sorting_context_id, | |
77 const gfx::Transform& transform, | |
78 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
79 const gfx::RectF& contents_rect, | |
80 const gfx::Rect& rect, | |
81 unsigned background_color, | |
82 unsigned edge_aa_mask, | |
83 float opacity); | |
84 | |
85 // Allocate CALayers for this layer and its children, and set their | |
86 // properties appropriately. Re-use the CALayers from |old_layer| if | |
87 // possible. If re-using a CALayer from |old_layer|, reset its |ca_layer| | |
88 // to nil, so that its destructor will not remove an active CALayer. | |
89 void CommitToCA(CALayer* superlayer, | |
90 RootLayer* old_layer, | |
91 float scale_factor); | |
92 | |
93 std::vector<ClipAndSortingLayer> clip_and_sorting_layers; | |
94 base::scoped_nsobject<CALayer> ca_layer; | |
95 | |
96 private: | |
97 DISALLOW_COPY_AND_ASSIGN(RootLayer); | |
98 }; | |
99 struct ClipAndSortingLayer { | |
100 ClipAndSortingLayer(bool is_clipped, | |
101 gfx::Rect clip_rect, | |
102 unsigned sorting_context_id, | |
103 bool is_singleton_sorting_context); | |
104 ClipAndSortingLayer(ClipAndSortingLayer&& layer); | |
105 | |
106 // See the behavior of RootLayer for the effects of these functions on the | |
107 // |ca_layer| member and |old_layer| argument. | |
108 ~ClipAndSortingLayer(); | |
109 void AddContentLayer(const gfx::Transform& transform, | |
110 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
111 const gfx::RectF& contents_rect, | |
112 const gfx::Rect& rect, | |
113 unsigned background_color, | |
114 unsigned edge_aa_mask, | |
115 float opacity); | |
116 void CommitToCA(CALayer* superlayer, | |
117 ClipAndSortingLayer* old_layer, | |
118 float scale_factor); | |
119 | |
120 std::vector<TransformLayer> transform_layers; | |
121 bool is_clipped = false; | |
122 gfx::Rect clip_rect; | |
123 unsigned sorting_context_id = 0; | |
124 bool is_singleton_sorting_context = false; | |
125 base::scoped_nsobject<CALayer> ca_layer; | |
126 | |
127 private: | |
128 DISALLOW_COPY_AND_ASSIGN(ClipAndSortingLayer); | |
129 }; | |
130 struct TransformLayer { | |
131 TransformLayer(const gfx::Transform& transform); | |
132 TransformLayer(TransformLayer&& layer); | |
133 | |
134 // See the behavior of RootLayer for the effects of these functions on the | |
135 // |ca_layer| member and |old_layer| argument. | |
136 ~TransformLayer(); | |
137 void AddContentLayer(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
138 const gfx::RectF& contents_rect, | |
139 const gfx::Rect& rect, | |
140 unsigned background_color, | |
141 unsigned edge_aa_mask, | |
142 float opacity); | |
143 void CommitToCA(CALayer* superlayer, | |
144 TransformLayer* old_layer, | |
145 float scale_factor); | |
146 | |
147 gfx::Transform transform; | |
148 std::vector<ContentLayer> content_layers; | |
149 base::scoped_nsobject<CALayer> ca_layer; | |
150 | |
151 private: | |
152 DISALLOW_COPY_AND_ASSIGN(TransformLayer); | |
153 }; | |
154 struct ContentLayer { | |
155 ContentLayer(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
156 const gfx::RectF& contents_rect, | |
157 const gfx::Rect& rect, | |
158 unsigned background_color, | |
159 unsigned edge_aa_mask, | |
160 float opacity); | |
161 ContentLayer(ContentLayer&& layer); | |
162 | |
163 // See the behavior of RootLayer for the effects of these functions on the | |
164 // |ca_layer| member and |old_layer| argument. | |
165 ~ContentLayer(); | |
166 void CommitToCA(CALayer* parent, | |
167 ContentLayer* old_layer, | |
168 float scale_factor); | |
169 | |
170 // Ensure that the IOSurface be marked as in-use as soon as it is received. | |
171 // When they are committed to the window server, that will also increment | |
172 // their use count. | |
173 const gfx::ScopedInUseIOSurface io_surface; | |
174 gfx::RectF contents_rect; | |
175 gfx::Rect rect; | |
176 unsigned background_color = 0; | |
177 // Note that the CoreAnimation edge antialiasing mask is not the same as | |
178 // the edge antialiasing mask passed to the constructor. | |
179 CAEdgeAntialiasingMask ca_edge_aa_mask = 0; | |
180 float opacity = 1; | |
181 base::scoped_nsobject<CALayer> ca_layer; | |
182 | |
183 // If this layer's contents can be represented as an | |
184 // AVSampleBufferDisplayLayer, then |ca_layer| will point to |av_layer|. | |
185 base::scoped_nsobject<AVSampleBufferDisplayLayer> av_layer; | |
186 bool use_av_layer = false; | |
187 | |
188 private: | |
189 DISALLOW_COPY_AND_ASSIGN(ContentLayer); | |
190 }; | |
191 | |
192 RootLayer root_layer_; | |
193 float scale_factor_ = 1; | |
194 bool has_committed_ = false; | |
195 | |
196 private: | |
197 DISALLOW_COPY_AND_ASSIGN(CALayerTree); | |
198 }; | |
199 | |
200 } // namespace gpu | |
201 | |
202 #endif // GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
OLD | NEW |