OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include <AVFoundation/AVFoundation.h> | 5 #include <AVFoundation/AVFoundation.h> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
13 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" | 13 #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h" |
14 #include "ui/gfx/geometry/dip_util.h" | 14 #include "ui/gfx/geometry/dip_util.h" |
15 #include "ui/gfx/mac/io_surface.h" | 15 #include "ui/gfx/mac/io_surface.h" |
16 | 16 |
17 namespace gpu { | 17 namespace gpu { |
18 | 18 |
| 19 namespace { |
| 20 |
| 21 struct CALayerProperties { |
| 22 bool is_clipped = true; |
| 23 gfx::Rect clip_rect; |
| 24 int sorting_context_id = 0; |
| 25 gfx::Transform transform; |
| 26 gfx::RectF contents_rect = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f); |
| 27 gfx::Rect rect = gfx::Rect(0, 0, 256, 256); |
| 28 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); |
| 29 unsigned edge_aa_mask = 0; |
| 30 float opacity = 1.0f; |
| 31 float scale_factor = 1.0f; |
| 32 unsigned filter = GL_LINEAR; |
| 33 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 34 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 35 }; |
| 36 |
| 37 bool ScheduleCALayer(ui::CARendererLayerTree* tree, |
| 38 CALayerProperties* properties) { |
| 39 return tree->ScheduleCALayer( |
| 40 properties->is_clipped, properties->clip_rect, |
| 41 properties->sorting_context_id, properties->transform, |
| 42 properties->io_surface, properties->cv_pixel_buffer, |
| 43 properties->contents_rect, properties->rect, properties->background_color, |
| 44 properties->edge_aa_mask, properties->opacity, properties->filter); |
| 45 } |
| 46 |
| 47 void UpdateCALayerTree(std::unique_ptr<ui::CARendererLayerTree>& ca_layer_tree, |
| 48 CALayerProperties* properties, |
| 49 CALayer* superlayer) { |
| 50 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 51 new ui::CARendererLayerTree); |
| 52 bool result = ScheduleCALayer(new_ca_layer_tree.get(), properties); |
| 53 EXPECT_TRUE(result); |
| 54 new_ca_layer_tree->CommitScheduledCALayers( |
| 55 superlayer, std::move(ca_layer_tree), properties->scale_factor); |
| 56 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
19 class CALayerTreeTest : public testing::Test { | 61 class CALayerTreeTest : public testing::Test { |
20 protected: | 62 protected: |
21 void SetUp() override { | 63 void SetUp() override { |
22 superlayer_.reset([[CALayer alloc] init]); | 64 superlayer_.reset([[CALayer alloc] init]); |
23 fullscreen_low_power_layer_.reset( | 65 fullscreen_low_power_layer_.reset( |
24 [[AVSampleBufferDisplayLayer alloc] init]); | 66 [[AVSampleBufferDisplayLayer alloc] init]); |
25 } | 67 } |
26 | 68 |
27 base::scoped_nsobject<CALayer> superlayer_; | 69 base::scoped_nsobject<CALayer> superlayer_; |
28 base::scoped_nsobject<AVSampleBufferDisplayLayer> fullscreen_low_power_layer_; | 70 base::scoped_nsobject<AVSampleBufferDisplayLayer> fullscreen_low_power_layer_; |
29 }; | 71 }; |
30 | 72 |
31 // Test updating each layer's properties. | 73 // Test updating each layer's properties. |
32 TEST_F(CALayerTreeTest, PropertyUpdates) { | 74 TEST_F(CALayerTreeTest, PropertyUpdates) { |
33 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( | 75 CALayerProperties properties; |
34 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); | 76 properties.clip_rect = gfx::Rect(2, 4, 8, 16); |
35 bool is_clipped = true; | 77 properties.transform.Translate(10, 20); |
36 gfx::Rect clip_rect(2, 4, 8, 16); | 78 properties.contents_rect = gfx::RectF(0.0f, 0.25f, 0.5f, 0.75f); |
37 int sorting_context_id = 0; | 79 properties.rect = gfx::Rect(16, 32, 64, 128); |
38 gfx::Transform transform; | 80 properties.background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); |
39 transform.Translate(10, 20); | 81 properties.edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; |
40 gfx::RectF contents_rect(0.0f, 0.25f, 0.5f, 0.75f); | 82 properties.opacity = 0.5f; |
41 gfx::Rect rect(16, 32, 64, 128); | 83 properties.io_surface = |
42 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); | 84 gfx::CreateIOSurface(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888); |
43 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; | |
44 float opacity = 0.5f; | |
45 unsigned filter = GL_LINEAR; | |
46 float scale_factor = 1.0f; | |
47 bool result = false; | |
48 | 85 |
49 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; | 86 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; |
50 CALayer* root_layer = nil; | 87 CALayer* root_layer = nil; |
51 CALayer* clip_and_sorting_layer = nil; | 88 CALayer* clip_and_sorting_layer = nil; |
52 CALayer* transform_layer = nil; | 89 CALayer* transform_layer = nil; |
53 CALayer* content_layer = nil; | 90 CALayer* content_layer = nil; |
54 | 91 |
55 // Validate the initial values. | 92 // Validate the initial values. |
56 { | 93 { |
57 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 94 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
58 new ui::CARendererLayerTree); | 95 new ui::CARendererLayerTree); |
59 result = new_ca_layer_tree->ScheduleCALayer( | 96 |
60 is_clipped, | 97 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
61 clip_rect, | |
62 sorting_context_id, | |
63 transform, | |
64 io_surface, | |
65 nullptr, | |
66 contents_rect, | |
67 rect, | |
68 background_color, | |
69 edge_aa_mask, | |
70 opacity, | |
71 filter); | |
72 EXPECT_TRUE(result); | |
73 new_ca_layer_tree->CommitScheduledCALayers( | |
74 superlayer_, std::move(ca_layer_tree), scale_factor); | |
75 std::swap(new_ca_layer_tree, ca_layer_tree); | |
76 | 98 |
77 // Validate the tree structure. | 99 // Validate the tree structure. |
78 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 100 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
79 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 101 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
80 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 102 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
81 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 103 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
82 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 104 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
83 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 105 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
84 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 106 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
85 content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 107 content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
86 | 108 |
87 // Validate the clip and sorting context layer. | 109 // Validate the clip and sorting context layer. |
88 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); | 110 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); |
89 EXPECT_EQ(gfx::Rect(clip_rect.size()), | 111 EXPECT_EQ(gfx::Rect(properties.clip_rect.size()), |
90 gfx::Rect([clip_and_sorting_layer bounds])); | 112 gfx::Rect([clip_and_sorting_layer bounds])); |
91 EXPECT_EQ(clip_rect.origin(), | 113 EXPECT_EQ(properties.clip_rect.origin(), |
92 gfx::Point([clip_and_sorting_layer position])); | 114 gfx::Point([clip_and_sorting_layer position])); |
93 EXPECT_EQ(-clip_rect.origin().x(), | 115 EXPECT_EQ(-properties.clip_rect.origin().x(), |
94 [clip_and_sorting_layer sublayerTransform].m41); | 116 [clip_and_sorting_layer sublayerTransform].m41); |
95 EXPECT_EQ(-clip_rect.origin().y(), | 117 EXPECT_EQ(-properties.clip_rect.origin().y(), |
96 [clip_and_sorting_layer sublayerTransform].m42); | 118 [clip_and_sorting_layer sublayerTransform].m42); |
97 | 119 |
98 // Validate the transform layer. | 120 // Validate the transform layer. |
99 EXPECT_EQ(transform.matrix().get(3, 0), | 121 EXPECT_EQ(properties.transform.matrix().get(3, 0), |
100 [transform_layer sublayerTransform].m41); | 122 [transform_layer sublayerTransform].m41); |
101 EXPECT_EQ(transform.matrix().get(3, 1), | 123 EXPECT_EQ(properties.transform.matrix().get(3, 1), |
102 [transform_layer sublayerTransform].m42); | 124 [transform_layer sublayerTransform].m42); |
103 | 125 |
104 // Validate the content layer. | 126 // Validate the content layer. |
105 EXPECT_EQ(static_cast<id>(io_surface.get()), [content_layer contents]); | 127 EXPECT_EQ(static_cast<id>(properties.io_surface.get()), |
106 EXPECT_EQ(contents_rect, gfx::RectF([content_layer contentsRect])); | 128 [content_layer contents]); |
107 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); | 129 EXPECT_EQ(properties.contents_rect, |
108 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 130 gfx::RectF([content_layer contentsRect])); |
| 131 EXPECT_EQ(properties.rect.origin(), gfx::Point([content_layer position])); |
| 132 EXPECT_EQ(gfx::Rect(properties.rect.size()), |
| 133 gfx::Rect([content_layer bounds])); |
109 EXPECT_EQ(kCALayerLeftEdge, [content_layer edgeAntialiasingMask]); | 134 EXPECT_EQ(kCALayerLeftEdge, [content_layer edgeAntialiasingMask]); |
110 EXPECT_EQ(opacity, [content_layer opacity]); | 135 EXPECT_EQ(properties.opacity, [content_layer opacity]); |
111 EXPECT_NSEQ(kCAFilterLinear, [content_layer minificationFilter]); | 136 EXPECT_NSEQ(kCAFilterLinear, [content_layer minificationFilter]); |
112 EXPECT_NSEQ(kCAFilterLinear, [content_layer magnificationFilter]); | 137 EXPECT_NSEQ(kCAFilterLinear, [content_layer magnificationFilter]); |
113 if ([content_layer respondsToSelector:(@selector(contentsScale))]) | 138 if ([content_layer respondsToSelector:(@selector(contentsScale))]) |
114 EXPECT_EQ(scale_factor, [content_layer contentsScale]); | 139 EXPECT_EQ(properties.scale_factor, [content_layer contentsScale]); |
115 } | 140 } |
116 | 141 |
117 // Update just the clip rect and re-commit. | 142 // Update just the clip rect and re-commit. |
118 { | 143 { |
119 clip_rect = gfx::Rect(4, 8, 16, 32); | 144 properties.clip_rect = gfx::Rect(4, 8, 16, 32); |
120 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 145 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
121 new ui::CARendererLayerTree); | |
122 result = new_ca_layer_tree->ScheduleCALayer( | |
123 is_clipped, | |
124 clip_rect, | |
125 sorting_context_id, | |
126 transform, | |
127 io_surface, | |
128 nullptr, | |
129 contents_rect, | |
130 rect, | |
131 background_color, | |
132 edge_aa_mask, | |
133 opacity, | |
134 filter); | |
135 EXPECT_TRUE(result); | |
136 new_ca_layer_tree->CommitScheduledCALayers( | |
137 superlayer_, std::move(ca_layer_tree), scale_factor); | |
138 std::swap(new_ca_layer_tree, ca_layer_tree); | |
139 | 146 |
140 // Validate the tree structure | 147 // Validate the tree structure |
141 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 148 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
142 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 149 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
143 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 150 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
144 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 151 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
145 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 152 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
146 EXPECT_EQ(transform_layer, | 153 EXPECT_EQ(transform_layer, |
147 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 154 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
148 | 155 |
149 // Validate the clip and sorting context layer. | 156 // Validate the clip and sorting context layer. |
150 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); | 157 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); |
151 EXPECT_EQ(gfx::Rect(clip_rect.size()), | 158 EXPECT_EQ(gfx::Rect(properties.clip_rect.size()), |
152 gfx::Rect([clip_and_sorting_layer bounds])); | 159 gfx::Rect([clip_and_sorting_layer bounds])); |
153 EXPECT_EQ(clip_rect.origin(), | 160 EXPECT_EQ(properties.clip_rect.origin(), |
154 gfx::Point([clip_and_sorting_layer position])); | 161 gfx::Point([clip_and_sorting_layer position])); |
155 EXPECT_EQ(-clip_rect.origin().x(), | 162 EXPECT_EQ(-properties.clip_rect.origin().x(), |
156 [clip_and_sorting_layer sublayerTransform].m41); | 163 [clip_and_sorting_layer sublayerTransform].m41); |
157 EXPECT_EQ(-clip_rect.origin().y(), | 164 EXPECT_EQ(-properties.clip_rect.origin().y(), |
158 [clip_and_sorting_layer sublayerTransform].m42); | 165 [clip_and_sorting_layer sublayerTransform].m42); |
159 } | 166 } |
160 | 167 |
161 // Disable clipping and re-commit. | 168 // Disable clipping and re-commit. |
162 { | 169 { |
163 is_clipped = false; | 170 properties.is_clipped = false; |
164 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 171 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
165 new ui::CARendererLayerTree); | |
166 result = new_ca_layer_tree->ScheduleCALayer( | |
167 is_clipped, | |
168 clip_rect, | |
169 sorting_context_id, | |
170 transform, | |
171 io_surface, | |
172 nullptr, | |
173 contents_rect, | |
174 rect, | |
175 background_color, | |
176 edge_aa_mask, | |
177 opacity, | |
178 filter); | |
179 EXPECT_TRUE(result); | |
180 new_ca_layer_tree->CommitScheduledCALayers( | |
181 superlayer_, std::move(ca_layer_tree), scale_factor); | |
182 std::swap(new_ca_layer_tree, ca_layer_tree); | |
183 | 172 |
184 // Validate the tree structure | 173 // Validate the tree structure |
185 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 174 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
186 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 175 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
187 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 176 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
188 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 177 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
189 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 178 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
190 EXPECT_EQ(transform_layer, | 179 EXPECT_EQ(transform_layer, |
191 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 180 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
192 | 181 |
193 // Validate the clip and sorting context layer. | 182 // Validate the clip and sorting context layer. |
194 EXPECT_FALSE([clip_and_sorting_layer masksToBounds]); | 183 EXPECT_FALSE([clip_and_sorting_layer masksToBounds]); |
195 EXPECT_EQ(gfx::Rect(), gfx::Rect([clip_and_sorting_layer bounds])); | 184 EXPECT_EQ(gfx::Rect(), gfx::Rect([clip_and_sorting_layer bounds])); |
196 EXPECT_EQ(gfx::Point(), gfx::Point([clip_and_sorting_layer position])); | 185 EXPECT_EQ(gfx::Point(), gfx::Point([clip_and_sorting_layer position])); |
197 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m41); | 186 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m41); |
198 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m42); | 187 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m42); |
199 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 188 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
200 } | 189 } |
201 | 190 |
202 // Change the transform and re-commit. | 191 // Change the transform and re-commit. |
203 { | 192 { |
204 transform.Translate(5, 5); | 193 properties.transform.Translate(5, 5); |
205 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 194 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
206 new ui::CARendererLayerTree); | |
207 result = new_ca_layer_tree->ScheduleCALayer( | |
208 is_clipped, | |
209 clip_rect, | |
210 sorting_context_id, | |
211 transform, | |
212 io_surface, | |
213 nullptr, | |
214 contents_rect, | |
215 rect, | |
216 background_color, | |
217 edge_aa_mask, | |
218 opacity, | |
219 filter); | |
220 EXPECT_TRUE(result); | |
221 new_ca_layer_tree->CommitScheduledCALayers( | |
222 superlayer_, std::move(ca_layer_tree), scale_factor); | |
223 std::swap(new_ca_layer_tree, ca_layer_tree); | |
224 | 195 |
225 // Validate the tree structure. | 196 // Validate the tree structure. |
226 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 197 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
227 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 198 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
228 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 199 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
229 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 200 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
230 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 201 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
231 EXPECT_EQ(transform_layer, | 202 EXPECT_EQ(transform_layer, |
232 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 203 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
233 | 204 |
234 // Validate the transform layer. | 205 // Validate the transform layer. |
235 EXPECT_EQ(transform.matrix().get(3, 0), | 206 EXPECT_EQ(properties.transform.matrix().get(3, 0), |
236 [transform_layer sublayerTransform].m41); | 207 [transform_layer sublayerTransform].m41); |
237 EXPECT_EQ(transform.matrix().get(3, 1), | 208 EXPECT_EQ(properties.transform.matrix().get(3, 1), |
238 [transform_layer sublayerTransform].m42); | 209 [transform_layer sublayerTransform].m42); |
239 } | 210 } |
240 | 211 |
241 // Change the edge antialiasing mask and commit. | 212 // Change the edge antialiasing mask and commit. |
242 { | 213 { |
243 edge_aa_mask = GL_CA_LAYER_EDGE_TOP_CHROMIUM; | 214 properties.edge_aa_mask = GL_CA_LAYER_EDGE_TOP_CHROMIUM; |
244 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 215 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
245 new ui::CARendererLayerTree); | |
246 result = new_ca_layer_tree->ScheduleCALayer( | |
247 is_clipped, | |
248 clip_rect, | |
249 sorting_context_id, | |
250 transform, | |
251 io_surface, | |
252 nullptr, | |
253 contents_rect, | |
254 rect, | |
255 background_color, | |
256 edge_aa_mask, | |
257 opacity, | |
258 filter); | |
259 EXPECT_TRUE(result); | |
260 new_ca_layer_tree->CommitScheduledCALayers( | |
261 superlayer_, std::move(ca_layer_tree), scale_factor); | |
262 std::swap(new_ca_layer_tree, ca_layer_tree); | |
263 | 216 |
264 // Validate the tree structure. | 217 // Validate the tree structure. |
265 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 218 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
266 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 219 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
267 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 220 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
268 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 221 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
269 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 222 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
270 EXPECT_EQ(transform_layer, | 223 EXPECT_EQ(transform_layer, |
271 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 224 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
272 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 225 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
273 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 226 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
274 | 227 |
275 // Validate the content layer. Note that top and bottom edges flip. | 228 // Validate the content layer. Note that top and bottom edges flip. |
276 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 229 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
277 } | 230 } |
278 | 231 |
279 // Change the contents and commit. | 232 // Change the contents and commit. |
280 { | 233 { |
281 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 234 properties.io_surface = nullptr; |
282 new ui::CARendererLayerTree); | 235 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
283 result = new_ca_layer_tree->ScheduleCALayer( | |
284 is_clipped, | |
285 clip_rect, | |
286 sorting_context_id, | |
287 transform, | |
288 nullptr, | |
289 nullptr, | |
290 contents_rect, | |
291 rect, | |
292 background_color, | |
293 edge_aa_mask, | |
294 opacity, | |
295 filter); | |
296 EXPECT_TRUE(result); | |
297 new_ca_layer_tree->CommitScheduledCALayers( | |
298 superlayer_, std::move(ca_layer_tree), scale_factor); | |
299 std::swap(new_ca_layer_tree, ca_layer_tree); | |
300 | 236 |
301 // Validate the tree structure. | 237 // Validate the tree structure. |
302 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 238 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
303 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 239 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
304 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 240 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
305 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 241 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
306 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 242 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
307 EXPECT_EQ(transform_layer, | 243 EXPECT_EQ(transform_layer, |
308 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 244 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
309 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 245 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
310 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 246 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
311 | 247 |
312 // Validate the content layer. Note that edge anti-aliasing no longer flips. | 248 // Validate the content layer. Note that edge anti-aliasing no longer flips. |
313 EXPECT_EQ(nil, [content_layer contents]); | 249 EXPECT_EQ(nil, [content_layer contents]); |
314 EXPECT_EQ(kCALayerTopEdge, [content_layer edgeAntialiasingMask]); | 250 EXPECT_EQ(kCALayerTopEdge, [content_layer edgeAntialiasingMask]); |
315 } | 251 } |
316 | 252 |
317 // Change the rect size. | 253 // Change the rect size. |
318 { | 254 { |
319 rect = gfx::Rect(rect.origin(), gfx::Size(32, 16)); | 255 properties.rect = gfx::Rect(properties.rect.origin(), gfx::Size(32, 16)); |
320 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 256 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
321 new ui::CARendererLayerTree); | |
322 result = new_ca_layer_tree->ScheduleCALayer( | |
323 is_clipped, | |
324 clip_rect, | |
325 sorting_context_id, | |
326 transform, | |
327 nullptr, | |
328 nullptr, | |
329 contents_rect, | |
330 rect, | |
331 background_color, | |
332 edge_aa_mask, | |
333 opacity, | |
334 filter); | |
335 EXPECT_TRUE(result); | |
336 new_ca_layer_tree->CommitScheduledCALayers( | |
337 superlayer_, std::move(ca_layer_tree), scale_factor); | |
338 std::swap(new_ca_layer_tree, ca_layer_tree); | |
339 | 257 |
340 // Validate the tree structure. | 258 // Validate the tree structure. |
341 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 259 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
342 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 260 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
343 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 261 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
344 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 262 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
345 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 263 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
346 EXPECT_EQ(transform_layer, | 264 EXPECT_EQ(transform_layer, |
347 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 265 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
348 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 266 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
349 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 267 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
350 | 268 |
351 // Validate the content layer. | 269 // Validate the content layer. |
352 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); | 270 EXPECT_EQ(properties.rect.origin(), gfx::Point([content_layer position])); |
353 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 271 EXPECT_EQ(gfx::Rect(properties.rect.size()), |
| 272 gfx::Rect([content_layer bounds])); |
354 } | 273 } |
355 | 274 |
356 // Change the rect position. | 275 // Change the rect position. |
357 { | 276 { |
358 rect = gfx::Rect(gfx::Point(16, 4), rect.size()); | 277 properties.rect = gfx::Rect(gfx::Point(16, 4), properties.rect.size()); |
359 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 278 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
360 new ui::CARendererLayerTree); | |
361 result = new_ca_layer_tree->ScheduleCALayer( | |
362 is_clipped, | |
363 clip_rect, | |
364 sorting_context_id, | |
365 transform, | |
366 nullptr, | |
367 nullptr, | |
368 contents_rect, | |
369 rect, | |
370 background_color, | |
371 edge_aa_mask, | |
372 opacity, | |
373 filter); | |
374 EXPECT_TRUE(result); | |
375 new_ca_layer_tree->CommitScheduledCALayers( | |
376 superlayer_, std::move(ca_layer_tree), scale_factor); | |
377 std::swap(new_ca_layer_tree, ca_layer_tree); | |
378 | 279 |
379 // Validate the tree structure. | 280 // Validate the tree structure. |
380 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 281 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
381 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 282 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
382 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 283 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
383 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 284 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
384 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 285 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
385 EXPECT_EQ(transform_layer, | 286 EXPECT_EQ(transform_layer, |
386 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 287 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
387 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 288 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
388 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 289 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
389 | 290 |
390 // Validate the content layer. | 291 // Validate the content layer. |
391 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); | 292 EXPECT_EQ(properties.rect.origin(), gfx::Point([content_layer position])); |
392 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 293 EXPECT_EQ(gfx::Rect(properties.rect.size()), |
| 294 gfx::Rect([content_layer bounds])); |
393 } | 295 } |
394 | 296 |
395 // Change the opacity. | 297 // Change the opacity. |
396 { | 298 { |
397 opacity = 1.0f; | 299 properties.opacity = 1.0f; |
398 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 300 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
399 new ui::CARendererLayerTree); | |
400 result = new_ca_layer_tree->ScheduleCALayer( | |
401 is_clipped, | |
402 clip_rect, | |
403 sorting_context_id, | |
404 transform, | |
405 nullptr, | |
406 nullptr, | |
407 contents_rect, | |
408 rect, | |
409 background_color, | |
410 edge_aa_mask, | |
411 opacity, | |
412 filter); | |
413 EXPECT_TRUE(result); | |
414 new_ca_layer_tree->CommitScheduledCALayers( | |
415 superlayer_, std::move(ca_layer_tree), scale_factor); | |
416 std::swap(new_ca_layer_tree, ca_layer_tree); | |
417 | 301 |
418 // Validate the tree structure. | 302 // Validate the tree structure. |
419 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 303 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
420 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 304 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
421 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 305 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
422 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 306 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
423 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 307 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
424 EXPECT_EQ(transform_layer, | 308 EXPECT_EQ(transform_layer, |
425 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 309 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
426 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 310 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
427 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 311 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
428 | 312 |
429 // Validate the content layer. | 313 // Validate the content layer. |
430 EXPECT_EQ(opacity, [content_layer opacity]); | 314 EXPECT_EQ(properties.opacity, [content_layer opacity]); |
431 } | 315 } |
432 | 316 |
433 // Change the filter. | 317 // Change the filter. |
434 { | 318 { |
435 filter = GL_NEAREST; | 319 properties.filter = GL_NEAREST; |
436 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 320 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
437 new ui::CARendererLayerTree); | |
438 result = new_ca_layer_tree->ScheduleCALayer( | |
439 is_clipped, | |
440 clip_rect, | |
441 sorting_context_id, | |
442 transform, | |
443 nullptr, | |
444 nullptr, | |
445 contents_rect, | |
446 rect, | |
447 background_color, | |
448 edge_aa_mask, | |
449 opacity, | |
450 filter); | |
451 EXPECT_TRUE(result); | |
452 new_ca_layer_tree->CommitScheduledCALayers( | |
453 superlayer_, std::move(ca_layer_tree), scale_factor); | |
454 std::swap(new_ca_layer_tree, ca_layer_tree); | |
455 | 321 |
456 // Validate the tree structure. | 322 // Validate the tree structure. |
457 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 323 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
458 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 324 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
459 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 325 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
460 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 326 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
461 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 327 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
462 EXPECT_EQ(transform_layer, | 328 EXPECT_EQ(transform_layer, |
463 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 329 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
464 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 330 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
465 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 331 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
466 | 332 |
467 // Validate the content layer. | 333 // Validate the content layer. |
468 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]); | 334 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]); |
469 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]); | 335 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]); |
470 } | 336 } |
471 | 337 |
472 // Add the clipping and IOSurface contents back. | 338 // Add the clipping and IOSurface contents back. |
473 { | 339 { |
474 is_clipped = true; | 340 properties.is_clipped = true; |
475 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 341 properties.io_surface = |
476 new ui::CARendererLayerTree); | 342 gfx::CreateIOSurface(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888); |
477 result = new_ca_layer_tree->ScheduleCALayer( | 343 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
478 is_clipped, | |
479 clip_rect, | |
480 sorting_context_id, | |
481 transform, | |
482 io_surface, | |
483 nullptr, | |
484 contents_rect, | |
485 rect, | |
486 background_color, | |
487 edge_aa_mask, | |
488 opacity, | |
489 filter); | |
490 EXPECT_TRUE(result); | |
491 new_ca_layer_tree->CommitScheduledCALayers( | |
492 superlayer_, std::move(ca_layer_tree), scale_factor); | |
493 std::swap(new_ca_layer_tree, ca_layer_tree); | |
494 | 344 |
495 // Validate the tree structure. | 345 // Validate the tree structure. |
496 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 346 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
497 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 347 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
498 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 348 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
499 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 349 EXPECT_EQ(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
500 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 350 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
501 EXPECT_EQ(transform_layer, | 351 EXPECT_EQ(transform_layer, |
502 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 352 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
503 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 353 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
504 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 354 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
505 | 355 |
506 // Validate the content layer. | 356 // Validate the content layer. |
507 EXPECT_EQ(static_cast<id>(io_surface.get()), [content_layer contents]); | 357 EXPECT_EQ(static_cast<id>(properties.io_surface.get()), |
| 358 [content_layer contents]); |
508 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 359 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
509 } | 360 } |
510 | 361 |
511 // Change the scale factor. This should result in a new tree being created. | 362 // Change the scale factor. This should result in a new tree being created. |
512 { | 363 { |
513 scale_factor = 2.0f; | 364 properties.scale_factor = 2.0f; |
514 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 365 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
515 new ui::CARendererLayerTree); | |
516 result = new_ca_layer_tree->ScheduleCALayer( | |
517 is_clipped, | |
518 clip_rect, | |
519 sorting_context_id, | |
520 transform, | |
521 io_surface, | |
522 nullptr, | |
523 contents_rect, | |
524 rect, | |
525 background_color, | |
526 edge_aa_mask, | |
527 opacity, | |
528 filter); | |
529 EXPECT_TRUE(result); | |
530 new_ca_layer_tree->CommitScheduledCALayers( | |
531 superlayer_, std::move(ca_layer_tree), scale_factor); | |
532 std::swap(new_ca_layer_tree, ca_layer_tree); | |
533 | 366 |
534 // Validate the tree structure. | 367 // Validate the tree structure. |
535 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 368 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
536 EXPECT_NE(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 369 EXPECT_NE(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
537 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 370 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
538 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 371 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
539 EXPECT_NE(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); | 372 EXPECT_NE(clip_and_sorting_layer, [[root_layer sublayers] objectAtIndex:0]); |
540 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 373 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
541 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 374 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
542 EXPECT_NE(transform_layer, | 375 EXPECT_NE(transform_layer, |
543 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 376 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
544 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 377 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
545 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 378 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
546 EXPECT_NE(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 379 EXPECT_NE(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
547 content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 380 content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
548 | 381 |
549 // Validate the clip and sorting context layer. | 382 // Validate the clip and sorting context layer. |
550 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); | 383 EXPECT_TRUE([clip_and_sorting_layer masksToBounds]); |
551 EXPECT_EQ(gfx::ConvertRectToDIP(scale_factor, gfx::Rect(clip_rect.size())), | 384 EXPECT_EQ(gfx::ConvertRectToDIP(properties.scale_factor, |
| 385 gfx::Rect(properties.clip_rect.size())), |
552 gfx::Rect([clip_and_sorting_layer bounds])); | 386 gfx::Rect([clip_and_sorting_layer bounds])); |
553 EXPECT_EQ(gfx::ConvertPointToDIP(scale_factor, clip_rect.origin()), | 387 EXPECT_EQ(gfx::ConvertPointToDIP(properties.scale_factor, |
| 388 properties.clip_rect.origin()), |
554 gfx::Point([clip_and_sorting_layer position])); | 389 gfx::Point([clip_and_sorting_layer position])); |
555 EXPECT_EQ(-clip_rect.origin().x() / scale_factor, | 390 EXPECT_EQ(-properties.clip_rect.origin().x() / properties.scale_factor, |
556 [clip_and_sorting_layer sublayerTransform].m41); | 391 [clip_and_sorting_layer sublayerTransform].m41); |
557 EXPECT_EQ(-clip_rect.origin().y() / scale_factor, | 392 EXPECT_EQ(-properties.clip_rect.origin().y() / properties.scale_factor, |
558 [clip_and_sorting_layer sublayerTransform].m42); | 393 [clip_and_sorting_layer sublayerTransform].m42); |
559 | 394 |
560 // Validate the transform layer. | 395 // Validate the transform layer. |
561 EXPECT_EQ(transform.matrix().get(3, 0) / scale_factor, | 396 EXPECT_EQ(properties.transform.matrix().get(3, 0) / properties.scale_factor, |
562 [transform_layer sublayerTransform].m41); | 397 [transform_layer sublayerTransform].m41); |
563 EXPECT_EQ(transform.matrix().get(3, 1) / scale_factor, | 398 EXPECT_EQ(properties.transform.matrix().get(3, 1) / properties.scale_factor, |
564 [transform_layer sublayerTransform].m42); | 399 [transform_layer sublayerTransform].m42); |
565 | 400 |
566 // Validate the content layer. | 401 // Validate the content layer. |
567 EXPECT_EQ(static_cast<id>(io_surface.get()), [content_layer contents]); | 402 EXPECT_EQ(static_cast<id>(properties.io_surface.get()), |
568 EXPECT_EQ(contents_rect, gfx::RectF([content_layer contentsRect])); | 403 [content_layer contents]); |
569 EXPECT_EQ(gfx::ConvertPointToDIP(scale_factor, rect.origin()), | 404 EXPECT_EQ(properties.contents_rect, |
| 405 gfx::RectF([content_layer contentsRect])); |
| 406 EXPECT_EQ(gfx::ConvertPointToDIP(properties.scale_factor, |
| 407 properties.rect.origin()), |
570 gfx::Point([content_layer position])); | 408 gfx::Point([content_layer position])); |
571 EXPECT_EQ(gfx::ConvertRectToDIP(scale_factor, gfx::Rect(rect.size())), | 409 EXPECT_EQ(gfx::ConvertRectToDIP(properties.scale_factor, |
| 410 gfx::Rect(properties.rect.size())), |
572 gfx::Rect([content_layer bounds])); | 411 gfx::Rect([content_layer bounds])); |
573 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 412 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
574 EXPECT_EQ(opacity, [content_layer opacity]); | 413 EXPECT_EQ(properties.opacity, [content_layer opacity]); |
575 if ([content_layer respondsToSelector:(@selector(contentsScale))]) | 414 if ([content_layer respondsToSelector:(@selector(contentsScale))]) |
576 EXPECT_EQ(scale_factor, [content_layer contentsScale]); | 415 EXPECT_EQ(properties.scale_factor, [content_layer contentsScale]); |
577 } | 416 } |
578 } | 417 } |
579 | 418 |
580 // Verify that sorting context zero is split at non-flat transforms. | 419 // Verify that sorting context zero is split at non-flat transforms. |
581 TEST_F(CALayerTreeTest, SplitSortingContextZero) { | 420 TEST_F(CALayerTreeTest, SplitSortingContextZero) { |
582 bool is_clipped = false; | 421 CALayerProperties properties; |
583 gfx::Rect clip_rect; | 422 properties.is_clipped = false; |
584 int sorting_context_id = 0; | 423 properties.clip_rect = gfx::Rect(); |
585 gfx::RectF contents_rect(0, 0, 1, 1); | 424 properties.rect = gfx::Rect(0, 0, 256, 256); |
586 gfx::Rect rect(0, 0, 256, 256); | |
587 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | |
588 unsigned edge_aa_mask = 0; | |
589 float opacity = 1.0f; | |
590 float scale_factor = 1.0f; | |
591 unsigned filter = GL_LINEAR; | |
592 | 425 |
593 // We'll use the IOSurface contents to identify the content layers. | 426 // We'll use the IOSurface contents to identify the content layers. |
594 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[5]; | 427 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[5]; |
595 for (size_t i = 0; i < 5; ++i) { | 428 for (size_t i = 0; i < 5; ++i) { |
596 io_surfaces[i].reset(gfx::CreateIOSurface( | 429 io_surfaces[i].reset(gfx::CreateIOSurface( |
597 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); | 430 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); |
598 } | 431 } |
599 | 432 |
600 // Have 5 transforms: | 433 // Have 5 transforms: |
601 // * 2 flat but different (1 sorting context layer, 2 transform layers) | 434 // * 2 flat but different (1 sorting context layer, 2 transform layers) |
602 // * 1 non-flat (new sorting context layer) | 435 // * 1 non-flat (new sorting context layer) |
603 // * 2 flat and the same (new sorting context layer, 1 transform layer) | 436 // * 2 flat and the same (new sorting context layer, 1 transform layer) |
604 gfx::Transform transforms[5]; | 437 gfx::Transform transforms[5]; |
605 transforms[0].Translate(10, 10); | 438 transforms[0].Translate(10, 10); |
606 transforms[1].RotateAboutZAxis(45.0f); | 439 transforms[1].RotateAboutZAxis(45.0f); |
607 transforms[2].RotateAboutYAxis(45.0f); | 440 transforms[2].RotateAboutYAxis(45.0f); |
608 transforms[3].Translate(10, 10); | 441 transforms[3].Translate(10, 10); |
609 transforms[4].Translate(10, 10); | 442 transforms[4].Translate(10, 10); |
610 | 443 |
611 // Schedule and commit the layers. | 444 // Schedule and commit the layers. |
612 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( | 445 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( |
613 new ui::CARendererLayerTree); | 446 new ui::CARendererLayerTree); |
614 for (size_t i = 0; i < 5; ++i) { | 447 for (size_t i = 0; i < 5; ++i) { |
615 bool result = ca_layer_tree->ScheduleCALayer( | 448 properties.io_surface = io_surfaces[i]; |
616 is_clipped, | 449 properties.transform = transforms[i]; |
617 clip_rect, | 450 bool result = ScheduleCALayer(ca_layer_tree.get(), &properties); |
618 sorting_context_id, | |
619 transforms[i], | |
620 io_surfaces[i], | |
621 nullptr, | |
622 contents_rect, | |
623 rect, | |
624 background_color, | |
625 edge_aa_mask, | |
626 opacity, | |
627 filter); | |
628 EXPECT_TRUE(result); | 451 EXPECT_TRUE(result); |
629 } | 452 } |
630 ca_layer_tree->CommitScheduledCALayers(superlayer_, nullptr, scale_factor); | 453 ca_layer_tree->CommitScheduledCALayers(superlayer_, nullptr, |
| 454 properties.scale_factor); |
631 | 455 |
632 // Validate the root layer. | 456 // Validate the root layer. |
633 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 457 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
634 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 458 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
635 | 459 |
636 // Validate that we have 3 sorting context layers. | 460 // Validate that we have 3 sorting context layers. |
637 EXPECT_EQ(3u, [[root_layer sublayers] count]); | 461 EXPECT_EQ(3u, [[root_layer sublayers] count]); |
638 CALayer* clip_and_sorting_layer_0 = [[root_layer sublayers] objectAtIndex:0]; | 462 CALayer* clip_and_sorting_layer_0 = [[root_layer sublayers] objectAtIndex:0]; |
639 CALayer* clip_and_sorting_layer_1 = [[root_layer sublayers] objectAtIndex:1]; | 463 CALayer* clip_and_sorting_layer_1 = [[root_layer sublayers] objectAtIndex:1]; |
640 CALayer* clip_and_sorting_layer_2 = [[root_layer sublayers] objectAtIndex:2]; | 464 CALayer* clip_and_sorting_layer_2 = [[root_layer sublayers] objectAtIndex:2]; |
(...skipping 30 matching lines...) Expand all Loading... |
671 // Validate that the layers come out in order. | 495 // Validate that the layers come out in order. |
672 EXPECT_EQ(static_cast<id>(io_surfaces[0].get()), [content_layer_0 contents]); | 496 EXPECT_EQ(static_cast<id>(io_surfaces[0].get()), [content_layer_0 contents]); |
673 EXPECT_EQ(static_cast<id>(io_surfaces[1].get()), [content_layer_1 contents]); | 497 EXPECT_EQ(static_cast<id>(io_surfaces[1].get()), [content_layer_1 contents]); |
674 EXPECT_EQ(static_cast<id>(io_surfaces[2].get()), [content_layer_2 contents]); | 498 EXPECT_EQ(static_cast<id>(io_surfaces[2].get()), [content_layer_2 contents]); |
675 EXPECT_EQ(static_cast<id>(io_surfaces[3].get()), [content_layer_3 contents]); | 499 EXPECT_EQ(static_cast<id>(io_surfaces[3].get()), [content_layer_3 contents]); |
676 EXPECT_EQ(static_cast<id>(io_surfaces[4].get()), [content_layer_4 contents]); | 500 EXPECT_EQ(static_cast<id>(io_surfaces[4].get()), [content_layer_4 contents]); |
677 } | 501 } |
678 | 502 |
679 // Verify that sorting contexts are allocated appropriately. | 503 // Verify that sorting contexts are allocated appropriately. |
680 TEST_F(CALayerTreeTest, SortingContexts) { | 504 TEST_F(CALayerTreeTest, SortingContexts) { |
681 bool is_clipped = false; | 505 CALayerProperties properties; |
682 gfx::Rect clip_rect; | 506 properties.is_clipped = false; |
683 int sorting_context_ids[3] = {3, -1, 0}; | 507 properties.clip_rect = gfx::Rect(); |
684 gfx::RectF contents_rect(0, 0, 1, 1); | 508 properties.rect = gfx::Rect(0, 0, 256, 256); |
685 gfx::Rect rect(0, 0, 256, 256); | |
686 gfx::Transform transform; | |
687 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | |
688 unsigned edge_aa_mask = 0; | |
689 float opacity = 1.0f; | |
690 float scale_factor = 1.0f; | |
691 unsigned filter = GL_LINEAR; | |
692 | 509 |
693 // We'll use the IOSurface contents to identify the content layers. | 510 // We'll use the IOSurface contents to identify the content layers. |
694 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[3]; | 511 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[3]; |
695 for (size_t i = 0; i < 3; ++i) { | 512 for (size_t i = 0; i < 3; ++i) { |
696 io_surfaces[i].reset(gfx::CreateIOSurface( | 513 io_surfaces[i].reset(gfx::CreateIOSurface( |
697 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); | 514 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); |
698 } | 515 } |
699 | 516 |
| 517 int sorting_context_ids[3] = {3, -1, 0}; |
| 518 |
700 // Schedule and commit the layers. | 519 // Schedule and commit the layers. |
701 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( | 520 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( |
702 new ui::CARendererLayerTree); | 521 new ui::CARendererLayerTree); |
703 for (size_t i = 0; i < 3; ++i) { | 522 for (size_t i = 0; i < 3; ++i) { |
704 bool result = ca_layer_tree->ScheduleCALayer( | 523 properties.sorting_context_id = sorting_context_ids[i]; |
705 is_clipped, | 524 properties.io_surface = io_surfaces[i]; |
706 clip_rect, | 525 bool result = ScheduleCALayer(ca_layer_tree.get(), &properties); |
707 sorting_context_ids[i], | |
708 transform, | |
709 io_surfaces[i], | |
710 nullptr, | |
711 contents_rect, | |
712 rect, | |
713 background_color, | |
714 edge_aa_mask, | |
715 opacity, | |
716 filter); | |
717 EXPECT_TRUE(result); | 526 EXPECT_TRUE(result); |
718 } | 527 } |
719 ca_layer_tree->CommitScheduledCALayers(superlayer_, nullptr, scale_factor); | 528 ca_layer_tree->CommitScheduledCALayers(superlayer_, nullptr, |
| 529 properties.scale_factor); |
720 | 530 |
721 // Validate the root layer. | 531 // Validate the root layer. |
722 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 532 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
723 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 533 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
724 | 534 |
725 // Validate that we have 3 sorting context layers. | 535 // Validate that we have 3 sorting context layers. |
726 EXPECT_EQ(3u, [[root_layer sublayers] count]); | 536 EXPECT_EQ(3u, [[root_layer sublayers] count]); |
727 CALayer* clip_and_sorting_layer_0 = [[root_layer sublayers] objectAtIndex:0]; | 537 CALayer* clip_and_sorting_layer_0 = [[root_layer sublayers] objectAtIndex:0]; |
728 CALayer* clip_and_sorting_layer_1 = [[root_layer sublayers] objectAtIndex:1]; | 538 CALayer* clip_and_sorting_layer_1 = [[root_layer sublayers] objectAtIndex:1]; |
729 CALayer* clip_and_sorting_layer_2 = [[root_layer sublayers] objectAtIndex:2]; | 539 CALayer* clip_and_sorting_layer_2 = [[root_layer sublayers] objectAtIndex:2]; |
(...skipping 18 matching lines...) Expand all Loading... |
748 CALayer* content_layer_2 = [[transform_layer_2 sublayers] objectAtIndex:0]; | 558 CALayer* content_layer_2 = [[transform_layer_2 sublayers] objectAtIndex:0]; |
749 | 559 |
750 // Validate that the layers come out in order. | 560 // Validate that the layers come out in order. |
751 EXPECT_EQ(static_cast<id>(io_surfaces[0].get()), [content_layer_0 contents]); | 561 EXPECT_EQ(static_cast<id>(io_surfaces[0].get()), [content_layer_0 contents]); |
752 EXPECT_EQ(static_cast<id>(io_surfaces[1].get()), [content_layer_1 contents]); | 562 EXPECT_EQ(static_cast<id>(io_surfaces[1].get()), [content_layer_1 contents]); |
753 EXPECT_EQ(static_cast<id>(io_surfaces[2].get()), [content_layer_2 contents]); | 563 EXPECT_EQ(static_cast<id>(io_surfaces[2].get()), [content_layer_2 contents]); |
754 } | 564 } |
755 | 565 |
756 // Verify that sorting contexts must all have the same clipping properties. | 566 // Verify that sorting contexts must all have the same clipping properties. |
757 TEST_F(CALayerTreeTest, SortingContextMustHaveConsistentClip) { | 567 TEST_F(CALayerTreeTest, SortingContextMustHaveConsistentClip) { |
758 base::ScopedCFTypeRef<IOSurfaceRef> io_surface; | 568 CALayerProperties properties; |
759 gfx::RectF contents_rect(0, 0, 1, 1); | |
760 gfx::Rect rect(0, 0, 256, 256); | |
761 gfx::Transform transform; | |
762 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | |
763 unsigned edge_aa_mask = 0; | |
764 float opacity = 1.0f; | |
765 unsigned filter = GL_LINEAR; | |
766 | 569 |
767 // Vary the clipping parameters within sorting contexts. | 570 // Vary the clipping parameters within sorting contexts. |
768 bool is_clippeds[3] = { true, true, false}; | 571 bool is_clippeds[3] = { true, true, false}; |
769 gfx::Rect clip_rects[3] = { | 572 gfx::Rect clip_rects[3] = { |
770 gfx::Rect(0, 0, 16, 16), | 573 gfx::Rect(0, 0, 16, 16), |
771 gfx::Rect(4, 8, 16, 32), | 574 gfx::Rect(4, 8, 16, 32), |
772 gfx::Rect(0, 0, 16, 16) | 575 gfx::Rect(0, 0, 16, 16) |
773 }; | 576 }; |
774 | 577 |
775 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( | 578 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree( |
776 new ui::CARendererLayerTree); | 579 new ui::CARendererLayerTree); |
777 // First send the various clip parameters to sorting context zero. This is | 580 // First send the various clip parameters to sorting context zero. This is |
778 // legitimate. | 581 // legitimate. |
779 for (size_t i = 0; i < 3; ++i) { | 582 for (size_t i = 0; i < 3; ++i) { |
780 int sorting_context_id = 0; | 583 properties.is_clipped = is_clippeds[i]; |
781 bool result = ca_layer_tree->ScheduleCALayer( | 584 properties.clip_rect = clip_rects[i]; |
782 is_clippeds[i], | 585 |
783 clip_rects[i], | 586 bool result = ScheduleCALayer(ca_layer_tree.get(), &properties); |
784 sorting_context_id, | |
785 transform, | |
786 io_surface, | |
787 nullptr, | |
788 contents_rect, | |
789 rect, | |
790 background_color, | |
791 edge_aa_mask, | |
792 opacity, | |
793 filter); | |
794 EXPECT_TRUE(result); | 587 EXPECT_TRUE(result); |
795 } | 588 } |
| 589 |
796 // Next send the various clip parameters to a non-zero sorting context. This | 590 // Next send the various clip parameters to a non-zero sorting context. This |
797 // will fail when we try to change the clip within the sorting context. | 591 // will fail when we try to change the clip within the sorting context. |
798 for (size_t i = 0; i < 3; ++i) { | 592 for (size_t i = 0; i < 3; ++i) { |
799 int sorting_context_id = 3; | 593 properties.sorting_context_id = 3; |
800 bool result = ca_layer_tree->ScheduleCALayer( | 594 properties.is_clipped = is_clippeds[i]; |
801 is_clippeds[i], | 595 properties.clip_rect = clip_rects[i]; |
802 clip_rects[i], | 596 |
803 sorting_context_id, | 597 bool result = ScheduleCALayer(ca_layer_tree.get(), &properties); |
804 transform, | |
805 io_surface, | |
806 nullptr, | |
807 contents_rect, | |
808 rect, | |
809 background_color, | |
810 edge_aa_mask, | |
811 opacity, | |
812 filter); | |
813 if (i == 0) | 598 if (i == 0) |
814 EXPECT_TRUE(result); | 599 EXPECT_TRUE(result); |
815 else | 600 else |
816 EXPECT_FALSE(result); | 601 EXPECT_FALSE(result); |
817 } | 602 } |
818 // Try once more with the original clip and verify it works. | 603 // Try once more with the original clip and verify it works. |
819 { | 604 { |
820 int sorting_context_id = 3; | 605 properties.is_clipped = is_clippeds[0]; |
821 bool result = ca_layer_tree->ScheduleCALayer( | 606 properties.clip_rect = clip_rects[0]; |
822 is_clippeds[0], | 607 |
823 clip_rects[0], | 608 bool result = ScheduleCALayer(ca_layer_tree.get(), &properties); |
824 sorting_context_id, | |
825 transform, | |
826 io_surface, | |
827 nullptr, | |
828 contents_rect, | |
829 rect, | |
830 background_color, | |
831 edge_aa_mask, | |
832 opacity, | |
833 filter); | |
834 EXPECT_TRUE(result); | 609 EXPECT_TRUE(result); |
835 } | 610 } |
836 } | 611 } |
837 | 612 |
838 // Test updating each layer's properties. | 613 // Test updating each layer's properties. |
839 TEST_F(CALayerTreeTest, AVLayer) { | 614 TEST_F(CALayerTreeTest, AVLayer) { |
840 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( | 615 CALayerProperties properties; |
841 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); | 616 properties.io_surface = gfx::CreateIOSurface( |
842 | 617 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR); |
843 bool is_clipped = true; | |
844 gfx::Rect clip_rect(2, 4, 8, 16); | |
845 int sorting_context_id = 0; | |
846 gfx::Transform transform; | |
847 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); | |
848 gfx::Rect rect(16, 32, 64, 128); | |
849 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); | |
850 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; | |
851 float opacity = 0.5f; | |
852 float scale_factor = 1.0f; | |
853 bool result = false; | |
854 unsigned filter = GL_LINEAR; | |
855 | 618 |
856 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; | 619 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; |
857 CALayer* root_layer = nil; | 620 CALayer* root_layer = nil; |
858 CALayer* clip_and_sorting_layer = nil; | 621 CALayer* clip_and_sorting_layer = nil; |
859 CALayer* transform_layer = nil; | 622 CALayer* transform_layer = nil; |
860 CALayer* content_layer1 = nil; | 623 CALayer* content_layer1 = nil; |
861 CALayer* content_layer2 = nil; | 624 CALayer* content_layer2 = nil; |
862 CALayer* content_layer3 = nil; | 625 CALayer* content_layer3 = nil; |
863 | 626 |
864 // Validate the initial values. | 627 // Validate the initial values. |
865 { | 628 { |
866 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 629 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
867 new ui::CARendererLayerTree); | |
868 result = new_ca_layer_tree->ScheduleCALayer( | |
869 is_clipped, | |
870 clip_rect, | |
871 sorting_context_id, | |
872 transform, | |
873 io_surface, | |
874 nullptr, | |
875 contents_rect, | |
876 rect, background_color, | |
877 edge_aa_mask, | |
878 opacity, | |
879 filter); | |
880 EXPECT_TRUE(result); | |
881 new_ca_layer_tree->CommitScheduledCALayers( | |
882 superlayer_, std::move(ca_layer_tree), scale_factor); | |
883 std::swap(new_ca_layer_tree, ca_layer_tree); | |
884 | 630 |
885 // Validate the tree structure. | 631 // Validate the tree structure. |
886 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 632 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
887 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 633 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
888 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 634 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
889 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 635 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
890 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 636 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
891 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 637 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
892 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 638 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
893 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; | 639 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; |
894 | 640 |
895 // Validate the content layer. | 641 // Validate the content layer. |
896 EXPECT_FALSE([content_layer1 | 642 EXPECT_FALSE([content_layer1 |
897 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 643 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
898 } | 644 } |
899 | 645 |
900 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), | 646 properties.io_surface.reset(gfx::CreateIOSurface( |
901 gfx::BufferFormat::YUV_420_BIPLANAR)); | 647 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); |
902 | 648 |
903 // Pass another frame. | 649 // Pass another frame. |
904 { | 650 { |
905 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 651 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
906 new ui::CARendererLayerTree); | |
907 result = new_ca_layer_tree->ScheduleCALayer( | |
908 is_clipped, | |
909 clip_rect, | |
910 sorting_context_id, | |
911 transform, | |
912 io_surface, | |
913 nullptr, | |
914 contents_rect, | |
915 rect, | |
916 background_color, | |
917 edge_aa_mask, | |
918 opacity, | |
919 filter); | |
920 EXPECT_TRUE(result); | |
921 new_ca_layer_tree->CommitScheduledCALayers( | |
922 superlayer_, std::move(ca_layer_tree), scale_factor); | |
923 std::swap(new_ca_layer_tree, ca_layer_tree); | |
924 | 652 |
925 // Validate the tree structure. | 653 // Validate the tree structure. |
926 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 654 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
927 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 655 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
928 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 656 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
929 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 657 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
930 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 658 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
931 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 659 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
932 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 660 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
933 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; | 661 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; |
934 | 662 |
935 // Validate the content layer. | 663 // Validate the content layer. |
936 EXPECT_FALSE([content_layer2 | 664 EXPECT_FALSE([content_layer2 |
937 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 665 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
938 EXPECT_EQ(content_layer2, content_layer1); | 666 EXPECT_EQ(content_layer2, content_layer1); |
939 } | 667 } |
940 | 668 |
941 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), | 669 properties.io_surface.reset(gfx::CreateIOSurface( |
942 gfx::BufferFormat::YUV_420_BIPLANAR)); | 670 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); |
943 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | 671 CVPixelBufferCreateWithIOSurface(nullptr, properties.io_surface, nullptr, |
944 CVPixelBufferCreateWithIOSurface( | 672 properties.cv_pixel_buffer.InitializeInto()); |
945 nullptr, io_surface, nullptr, cv_pixel_buffer.InitializeInto()); | |
946 | 673 |
947 // Pass a frame with a CVPixelBuffer | 674 // Pass a frame with a CVPixelBuffer |
948 { | 675 { |
949 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 676 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
950 new ui::CARendererLayerTree); | |
951 result = new_ca_layer_tree->ScheduleCALayer( | |
952 is_clipped, | |
953 clip_rect, | |
954 sorting_context_id, | |
955 transform, | |
956 io_surface, | |
957 cv_pixel_buffer, | |
958 contents_rect, | |
959 rect, | |
960 background_color, | |
961 edge_aa_mask, | |
962 opacity, | |
963 filter); | |
964 EXPECT_TRUE(result); | |
965 new_ca_layer_tree->CommitScheduledCALayers( | |
966 superlayer_, std::move(ca_layer_tree), scale_factor); | |
967 std::swap(new_ca_layer_tree, ca_layer_tree); | |
968 | 677 |
969 // Validate the tree structure. | 678 // Validate the tree structure. |
970 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 679 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
971 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 680 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
972 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 681 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
973 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 682 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
974 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 683 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
975 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 684 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
976 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 685 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
977 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; | 686 content_layer2 = [[transform_layer sublayers] objectAtIndex:0]; |
978 | 687 |
979 // Validate the content layer. | 688 // Validate the content layer. |
980 EXPECT_TRUE([content_layer2 | 689 EXPECT_TRUE([content_layer2 |
981 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 690 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
982 EXPECT_NE(content_layer2, content_layer1); | 691 EXPECT_NE(content_layer2, content_layer1); |
983 } | 692 } |
984 | 693 |
985 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), | 694 properties.io_surface.reset(gfx::CreateIOSurface( |
986 gfx::BufferFormat::YUV_420_BIPLANAR)); | 695 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); |
987 cv_pixel_buffer.reset(); | 696 properties.cv_pixel_buffer.reset(); |
988 | 697 |
989 // Pass a frame that is clipped. | 698 // Pass a frame that is clipped. |
990 contents_rect = gfx::RectF(0, 0, 1, 0.9); | 699 properties.contents_rect = gfx::RectF(0, 0, 1, 0.9); |
991 { | 700 { |
992 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 701 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
993 new ui::CARendererLayerTree); | |
994 result = new_ca_layer_tree->ScheduleCALayer( | |
995 is_clipped, | |
996 clip_rect, | |
997 sorting_context_id, | |
998 transform, | |
999 io_surface, | |
1000 nullptr, | |
1001 contents_rect, | |
1002 rect, | |
1003 background_color, | |
1004 edge_aa_mask, | |
1005 opacity, | |
1006 filter); | |
1007 EXPECT_TRUE(result); | |
1008 new_ca_layer_tree->CommitScheduledCALayers( | |
1009 superlayer_, std::move(ca_layer_tree), scale_factor); | |
1010 std::swap(new_ca_layer_tree, ca_layer_tree); | |
1011 | 702 |
1012 // Validate the tree structure. | 703 // Validate the tree structure. |
1013 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 704 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
1014 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 705 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
1015 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 706 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
1016 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 707 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
1017 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 708 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
1018 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 709 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
1019 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 710 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
1020 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; | 711 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; |
1021 | 712 |
1022 // Validate the content layer. | 713 // Validate the content layer. |
1023 EXPECT_FALSE([content_layer3 | 714 EXPECT_FALSE([content_layer3 |
1024 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 715 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
1025 EXPECT_NE(content_layer3, content_layer2); | 716 EXPECT_NE(content_layer3, content_layer2); |
1026 } | 717 } |
1027 } | 718 } |
1028 | 719 |
1029 // Test fullscreen low power detection. | 720 // Test fullscreen low power detection. |
1030 TEST_F(CALayerTreeTest, FullscreenLowPower) { | 721 TEST_F(CALayerTreeTest, FullscreenLowPower) { |
1031 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(gfx::CreateIOSurface( | 722 CALayerProperties properties; |
1032 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR)); | 723 properties.io_surface = gfx::CreateIOSurface( |
| 724 gfx::Size(256, 256), gfx::BufferFormat::YUV_420_BIPLANAR); |
| 725 properties.is_clipped = false; |
| 726 CVPixelBufferCreateWithIOSurface(nullptr, properties.io_surface, nullptr, |
| 727 properties.cv_pixel_buffer.InitializeInto()); |
1033 | 728 |
1034 bool is_clipped = false; | 729 CALayerProperties properties_black; |
1035 gfx::Rect clip_rect(0, 0, 1, 1); | 730 properties_black.is_clipped = false; |
1036 int sorting_context_id = 0; | 731 properties_black.background_color = SK_ColorBLACK; |
1037 gfx::Transform transform; | 732 CALayerProperties properties_white; |
1038 transform.Translate(10, 20); | 733 properties_white.is_clipped = false; |
1039 transform.Scale(0.5, 2.0); | 734 properties_white.background_color = SK_ColorWHITE; |
1040 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); | |
1041 gfx::Rect rect(16, 32, 64, 128); | |
1042 unsigned background_color = SkColorSetARGB(0, 0, 0, 0); | |
1043 unsigned edge_aa_mask = 0; | |
1044 float opacity = 1.0f; | |
1045 float scale_factor = 1.0f; | |
1046 bool result = false; | |
1047 unsigned filter = GL_LINEAR; | |
1048 | 735 |
1049 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; | 736 std::unique_ptr<ui::CARendererLayerTree> ca_layer_tree; |
1050 | 737 |
1051 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | |
1052 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr, | |
1053 cv_pixel_buffer.InitializeInto()); | |
1054 | |
1055 // Test a configuration with no background. | 738 // Test a configuration with no background. |
1056 { | 739 { |
1057 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 740 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
1058 new ui::CARendererLayerTree); | 741 new ui::CARendererLayerTree); |
1059 result = new_ca_layer_tree->ScheduleCALayer( | 742 bool result = ScheduleCALayer(new_ca_layer_tree.get(), &properties); |
1060 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | |
1061 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, | |
1062 opacity, filter); | |
1063 EXPECT_TRUE(result); | 743 EXPECT_TRUE(result); |
1064 new_ca_layer_tree->CommitScheduledCALayers( | 744 new_ca_layer_tree->CommitScheduledCALayers( |
1065 superlayer_, std::move(ca_layer_tree), scale_factor); | 745 superlayer_, std::move(ca_layer_tree), properties.scale_factor); |
1066 bool fullscreen_low_power_valid = | 746 bool fullscreen_low_power_valid = |
1067 new_ca_layer_tree->CommitFullscreenLowPowerLayer( | 747 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
1068 fullscreen_low_power_layer_); | 748 fullscreen_low_power_layer_); |
1069 std::swap(new_ca_layer_tree, ca_layer_tree); | 749 std::swap(new_ca_layer_tree, ca_layer_tree); |
1070 | 750 |
1071 // Validate the tree structure. | 751 // Validate the tree structure. |
1072 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 752 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
1073 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 753 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
1074 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 754 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
1075 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 755 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
1076 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 756 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
1077 CALayer* transform_layer = | 757 CALayer* transform_layer = |
1078 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 758 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
1079 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 759 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
1080 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 760 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
1081 | 761 |
1082 // Validate the content layer and fullscreen low power mode. | 762 // Validate the content layer and fullscreen low power mode. |
1083 EXPECT_TRUE([content_layer | 763 EXPECT_TRUE([content_layer |
1084 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 764 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
1085 EXPECT_TRUE(fullscreen_low_power_valid); | 765 EXPECT_TRUE(fullscreen_low_power_valid); |
1086 } | 766 } |
1087 | 767 |
1088 // Test a configuration with a black background. | 768 // Test a configuration with a black background. |
1089 { | 769 { |
1090 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 770 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
1091 new ui::CARendererLayerTree); | 771 new ui::CARendererLayerTree); |
1092 result = new_ca_layer_tree->ScheduleCALayer( | 772 bool result = ScheduleCALayer(new_ca_layer_tree.get(), &properties_black); |
1093 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, | 773 EXPECT_TRUE(result); |
1094 contents_rect, rect, SK_ColorBLACK, edge_aa_mask, opacity, filter); | 774 result = ScheduleCALayer(new_ca_layer_tree.get(), &properties); |
1095 result = new_ca_layer_tree->ScheduleCALayer( | |
1096 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | |
1097 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, | |
1098 opacity, filter); | |
1099 EXPECT_TRUE(result); | 775 EXPECT_TRUE(result); |
1100 new_ca_layer_tree->CommitScheduledCALayers( | 776 new_ca_layer_tree->CommitScheduledCALayers( |
1101 superlayer_, std::move(ca_layer_tree), scale_factor); | 777 superlayer_, std::move(ca_layer_tree), properties.scale_factor); |
1102 bool fullscreen_low_power_valid = | 778 bool fullscreen_low_power_valid = |
1103 new_ca_layer_tree->CommitFullscreenLowPowerLayer( | 779 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
1104 fullscreen_low_power_layer_); | 780 fullscreen_low_power_layer_); |
1105 std::swap(new_ca_layer_tree, ca_layer_tree); | 781 std::swap(new_ca_layer_tree, ca_layer_tree); |
1106 | 782 |
1107 // Validate the tree structure. | 783 // Validate the tree structure. |
1108 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 784 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
1109 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 785 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
1110 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 786 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
1111 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 787 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
1112 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 788 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
1113 CALayer* transform_layer = | 789 CALayer* transform_layer = |
1114 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 790 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
1115 EXPECT_EQ(2u, [[transform_layer sublayers] count]); | 791 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
1116 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; | 792 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; |
1117 | 793 |
1118 // Validate the content layer and fullscreen low power mode. | 794 // Validate the content layer and fullscreen low power mode. |
1119 EXPECT_TRUE([content_layer | 795 EXPECT_TRUE([content_layer |
1120 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 796 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
1121 EXPECT_TRUE(fullscreen_low_power_valid); | 797 EXPECT_TRUE(fullscreen_low_power_valid); |
1122 } | 798 } |
1123 | 799 |
1124 // Test a configuration with a white background. It will fail. | 800 // Test a configuration with a white background. It will fail. |
1125 { | 801 { |
1126 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 802 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
1127 new ui::CARendererLayerTree); | 803 new ui::CARendererLayerTree); |
1128 result = new_ca_layer_tree->ScheduleCALayer( | 804 bool result = ScheduleCALayer(new_ca_layer_tree.get(), &properties_white); |
1129 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, | 805 EXPECT_TRUE(result); |
1130 contents_rect, rect, SK_ColorWHITE, edge_aa_mask, opacity, filter); | 806 result = ScheduleCALayer(new_ca_layer_tree.get(), &properties); |
1131 result = new_ca_layer_tree->ScheduleCALayer( | |
1132 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | |
1133 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, | |
1134 opacity, filter); | |
1135 EXPECT_TRUE(result); | 807 EXPECT_TRUE(result); |
1136 new_ca_layer_tree->CommitScheduledCALayers( | 808 new_ca_layer_tree->CommitScheduledCALayers( |
1137 superlayer_, std::move(ca_layer_tree), scale_factor); | 809 superlayer_, std::move(ca_layer_tree), properties.scale_factor); |
1138 bool fullscreen_low_power_valid = | 810 bool fullscreen_low_power_valid = |
1139 new_ca_layer_tree->CommitFullscreenLowPowerLayer( | 811 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
1140 fullscreen_low_power_layer_); | 812 fullscreen_low_power_layer_); |
1141 std::swap(new_ca_layer_tree, ca_layer_tree); | 813 std::swap(new_ca_layer_tree, ca_layer_tree); |
1142 | 814 |
1143 // Validate the tree structure. | 815 // Validate the tree structure. |
1144 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 816 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
1145 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 817 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
1146 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 818 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
1147 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 819 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
1148 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 820 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
1149 CALayer* transform_layer = | 821 CALayer* transform_layer = |
1150 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 822 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
1151 EXPECT_EQ(2u, [[transform_layer sublayers] count]); | 823 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
1152 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; | 824 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:1]; |
1153 | 825 |
1154 // Validate the content layer and fullscreen low power mode. | 826 // Validate the content layer and fullscreen low power mode. |
1155 EXPECT_TRUE([content_layer | 827 EXPECT_TRUE([content_layer |
1156 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 828 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
1157 EXPECT_FALSE(fullscreen_low_power_valid); | 829 EXPECT_FALSE(fullscreen_low_power_valid); |
1158 } | 830 } |
1159 | 831 |
1160 // Test a configuration with a black foreground. It too will fail. | 832 // Test a configuration with a black foreground. It too will fail. |
1161 { | 833 { |
1162 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 834 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
1163 new ui::CARendererLayerTree); | 835 new ui::CARendererLayerTree); |
1164 result = new_ca_layer_tree->ScheduleCALayer( | 836 bool result = ScheduleCALayer(new_ca_layer_tree.get(), &properties); |
1165 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | 837 EXPECT_TRUE(result); |
1166 cv_pixel_buffer, contents_rect, rect, background_color, edge_aa_mask, | 838 result = ScheduleCALayer(new_ca_layer_tree.get(), &properties_black); |
1167 opacity, filter); | |
1168 result = new_ca_layer_tree->ScheduleCALayer( | |
1169 is_clipped, clip_rect, sorting_context_id, transform, nullptr, nullptr, | |
1170 contents_rect, rect, SK_ColorBLACK, edge_aa_mask, opacity, filter); | |
1171 EXPECT_TRUE(result); | 839 EXPECT_TRUE(result); |
1172 new_ca_layer_tree->CommitScheduledCALayers( | 840 new_ca_layer_tree->CommitScheduledCALayers( |
1173 superlayer_, std::move(ca_layer_tree), scale_factor); | 841 superlayer_, std::move(ca_layer_tree), properties.scale_factor); |
1174 bool fullscreen_low_power_valid = | 842 bool fullscreen_low_power_valid = |
1175 new_ca_layer_tree->CommitFullscreenLowPowerLayer( | 843 new_ca_layer_tree->CommitFullscreenLowPowerLayer( |
1176 fullscreen_low_power_layer_); | 844 fullscreen_low_power_layer_); |
1177 std::swap(new_ca_layer_tree, ca_layer_tree); | 845 std::swap(new_ca_layer_tree, ca_layer_tree); |
1178 | 846 |
1179 // Validate the tree structure. | 847 // Validate the tree structure. |
1180 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 848 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
1181 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 849 CALayer* root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
1182 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 850 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
1183 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 851 CALayer* clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
1184 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 852 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
1185 CALayer* transform_layer = | 853 CALayer* transform_layer = |
1186 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 854 [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
1187 EXPECT_EQ(2u, [[transform_layer sublayers] count]); | 855 EXPECT_EQ(2u, [[transform_layer sublayers] count]); |
1188 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 856 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
1189 | 857 |
1190 // Validate the content layer and fullscreen low power mode. | 858 // Validate the content layer and fullscreen low power mode. |
1191 EXPECT_TRUE([content_layer | 859 EXPECT_TRUE([content_layer |
1192 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 860 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
1193 EXPECT_FALSE(fullscreen_low_power_valid); | 861 EXPECT_FALSE(fullscreen_low_power_valid); |
1194 } | 862 } |
1195 } | 863 } |
1196 | 864 |
1197 } // namespace gpu | 865 } // namespace gpu |
OLD | NEW |