1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_layer_tree_host_impl_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_proxy.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/test/layer_test_common.h"
18 #include "cc/test/render_pass_test_common.h"
19 #include "cc/test/render_pass_test_utils.h"
20 #include "cc/test/test_shared_bitmap_manager.h"
21 #include "cc/test/test_web_graphics_context_3d.h"
22 #include "cc/trees/layer_tree_host_impl.h"
23 #include "cc/trees/layer_tree_impl.h"
24 #include "cc/trees/single_thread_proxy.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/frame_time.h"
27 #include "ui/gfx/transform.h"
32 class DelegatedRendererLayerImplTest
: public testing::Test
{
34 DelegatedRendererLayerImplTest()
36 always_impl_thread_and_main_thread_blocked_(&proxy_
) {
37 LayerTreeSettings settings
;
38 settings
.minimum_occlusion_tracking_size
= gfx::Size();
41 new FakeLayerTreeHostImpl(settings
, &proxy_
, &shared_bitmap_manager_
));
42 host_impl_
->InitializeRenderer(FakeOutputSurface::Create3d());
43 host_impl_
->SetViewportSize(gfx::Size(10, 10));
48 DebugScopedSetImplThreadAndMainThreadBlocked
49 always_impl_thread_and_main_thread_blocked_
;
50 TestSharedBitmapManager shared_bitmap_manager_
;
51 scoped_ptr
<LayerTreeHostImpl
> host_impl_
;
54 class DelegatedRendererLayerImplTestSimple
55 : public DelegatedRendererLayerImplTest
{
57 DelegatedRendererLayerImplTestSimple()
58 : DelegatedRendererLayerImplTest() {
59 scoped_ptr
<LayerImpl
> root_layer
=
60 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 1);
61 scoped_ptr
<LayerImpl
> layer_before
=
62 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 2);
63 scoped_ptr
<LayerImpl
> layer_after
=
64 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 3);
65 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
66 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 4);
68 host_impl_
->SetViewportSize(gfx::Size(100, 100));
69 root_layer
->SetBounds(gfx::Size(100, 100));
70 root_layer
->SetHasRenderSurface(true);
72 layer_before
->SetPosition(gfx::Point(20, 20));
73 layer_before
->SetBounds(gfx::Size(14, 14));
74 layer_before
->SetContentBounds(gfx::Size(14, 14));
75 layer_before
->SetDrawsContent(true);
76 layer_before
->SetHasRenderSurface(true);
78 layer_after
->SetPosition(gfx::Point(5, 5));
79 layer_after
->SetBounds(gfx::Size(15, 15));
80 layer_after
->SetContentBounds(gfx::Size(15, 15));
81 layer_after
->SetDrawsContent(true);
82 layer_after
->SetHasRenderSurface(true);
84 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
85 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
86 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
87 delegated_renderer_layer
->SetDrawsContent(true);
88 gfx::Transform transform
;
89 transform
.Translate(1.0, 1.0);
90 delegated_renderer_layer
->SetTransform(transform
);
92 RenderPassList delegated_render_passes
;
93 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
95 gfx::Rect(6, 6, 6, 6),
96 gfx::Transform(1, 0, 0, 1, 5, 6));
97 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
98 TestRenderPass
* pass2
= AddRenderPass(&delegated_render_passes
,
100 gfx::Rect(7, 7, 7, 7),
101 gfx::Transform(1, 0, 0, 1, 7, 8));
102 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
103 AddRenderPassQuad(pass2
, pass1
);
104 TestRenderPass
* pass3
= AddRenderPass(&delegated_render_passes
,
106 gfx::Rect(0, 0, 8, 8),
107 gfx::Transform(1, 0, 0, 1, 9, 10));
108 AddRenderPassQuad(pass3
, pass2
);
109 delegated_renderer_layer
->SetFrameDataForRenderPasses(
110 1.f
, delegated_render_passes
);
112 root_layer_
= root_layer
.get();
113 layer_before_
= layer_before
.get();
114 layer_after_
= layer_after
.get();
115 delegated_renderer_layer_
= delegated_renderer_layer
.get();
117 // Force the delegated RenderPasses to come before the RenderPass from
119 layer_after
->AddChild(delegated_renderer_layer
.Pass());
120 root_layer
->AddChild(layer_after
.Pass());
122 // Get the RenderPass generated by layer_before to come before the delegated
124 root_layer
->AddChild(layer_before
.Pass());
125 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
129 LayerImpl
* root_layer_
;
130 LayerImpl
* layer_before_
;
131 LayerImpl
* layer_after_
;
132 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
135 TEST_F(DelegatedRendererLayerImplTest
,
136 ChangeContributingRenderPassForNewFrame
) {
137 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
139 scoped_ptr
<LayerImpl
> root_layer
=
140 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 1);
141 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
142 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
144 host_impl_
->SetViewportSize(gfx::Size(100, 100));
145 root_layer
->SetBounds(gfx::Size(100, 100));
146 root_layer
->SetHasRenderSurface(true);
148 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
149 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
150 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
151 delegated_renderer_layer
->SetDrawsContent(true);
152 delegated_renderer_layer
->SetHasRenderSurface(true);
153 gfx::Transform transform
;
154 transform
.Translate(1.0, 1.0);
155 delegated_renderer_layer
->SetTransform(transform
);
157 RenderPassList delegated_render_passes
;
158 TestRenderPass
* pass1
=
159 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
160 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
161 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
162 TestRenderPass
* pass2
=
163 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
164 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
165 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
166 AddRenderPassQuad(pass2
, pass1
);
167 TestRenderPass
* pass3
=
168 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
169 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
170 AddRenderPassQuad(pass3
, pass2
);
171 delegated_renderer_layer
->SetFrameDataForRenderPasses(
172 1.f
, delegated_render_passes
);
174 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
176 root_layer
->AddChild(delegated_renderer_layer
.Pass());
178 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
180 LayerTreeHostImpl::FrameData frame
;
181 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
183 // Root layer has one render pass, and delegated renderer layer has two
184 // contributing render passes and its own render pass.
185 ASSERT_EQ(4u, frame
.render_passes
.size());
187 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
188 host_impl_
->DidDrawAllLayers(frame
);
191 // New frame makes delegated renderer layer loses its contributing render
193 RenderPassList delegated_render_passes
;
194 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
195 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
196 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
197 1.f
, delegated_render_passes
);
199 // Force damage to redraw a new frame.
200 host_impl_
->SetViewportDamage(gfx::Rect(10, 10));
202 LayerTreeHostImpl::FrameData frame
;
203 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
205 // Each non-DelegatedRendererLayer added one RenderPass. The
206 // DelegatedRendererLayer added two contributing passes.
207 ASSERT_EQ(1u, frame
.render_passes
.size());
209 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
210 host_impl_
->DidDrawAllLayers(frame
);
214 TEST_F(DelegatedRendererLayerImplTest
,
215 ChangeContributingRenderPassNonFullTreeSync
) {
216 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
218 host_impl_
->CreatePendingTree();
219 scoped_ptr
<LayerImpl
> root_layer
=
220 SolidColorLayerImpl::Create(host_impl_
->pending_tree(), 1);
221 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
222 FakeDelegatedRendererLayerImpl::Create(host_impl_
->pending_tree(), 2);
224 host_impl_
->SetViewportSize(gfx::Size(100, 100));
225 root_layer
->SetBounds(gfx::Size(100, 100));
226 root_layer
->SetHasRenderSurface(true);
228 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
229 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
230 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
231 delegated_renderer_layer
->SetDrawsContent(true);
232 delegated_renderer_layer
->SetHasRenderSurface(true);
233 gfx::Transform transform
;
234 transform
.Translate(1.0, 1.0);
235 delegated_renderer_layer
->SetTransform(transform
);
237 RenderPassList delegated_render_passes
;
238 TestRenderPass
* pass1
=
239 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
240 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
241 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
242 TestRenderPass
* pass2
=
243 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
244 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
245 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
246 AddRenderPassQuad(pass2
, pass1
);
247 TestRenderPass
* pass3
=
248 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
249 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
250 AddRenderPassQuad(pass3
, pass2
);
251 delegated_renderer_layer
->SetFrameDataForRenderPasses(
252 1.f
, delegated_render_passes
);
254 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
256 root_layer
->AddChild(delegated_renderer_layer
.Pass());
258 host_impl_
->pending_tree()->SetRootLayer(root_layer
.Pass());
259 host_impl_
->ActivateSyncTree();
261 LayerTreeHostImpl::FrameData frame
;
262 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
264 // Root layer has one render pass, and delegated renderer layer has two
265 // contributing render passes and its own render pass.
266 ASSERT_EQ(4u, frame
.render_passes
.size());
268 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
269 host_impl_
->DidDrawAllLayers(frame
);
272 // Remove contributing render passes from the delegated renderer layer.
273 host_impl_
->CreatePendingTree();
274 host_impl_
->pending_tree()->set_needs_full_tree_sync(false);
275 RenderPassList delegated_render_passes
;
276 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
277 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
279 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
280 1.f
, delegated_render_passes
);
282 // Force damage to redraw a new frame.
284 host_impl_
->ActivateSyncTree();
285 host_impl_
->SetViewportDamage(gfx::Rect(100, 100));
286 LayerTreeHostImpl::FrameData frame
;
287 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
289 // Root layer has one render pass, and delegated renderer layer no longer
290 // has contributing render passes.
291 ASSERT_EQ(1u, frame
.render_passes
.size());
293 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
294 host_impl_
->DidDrawAllLayers(frame
);
298 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsContributingRenderPasses
) {
299 LayerTreeHostImpl::FrameData frame
;
300 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
302 // Each non-DelegatedRendererLayer added one RenderPass. The
303 // DelegatedRendererLayer added two contributing passes.
304 ASSERT_EQ(5u, frame
.render_passes
.size());
306 // The DelegatedRendererLayer should have added its contributing RenderPasses
308 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
309 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
310 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
311 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
312 // And all other RenderPasses should be non-delegated.
313 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
314 EXPECT_EQ(0, frame
.render_passes
[0]->id
.index
);
315 EXPECT_NE(4, frame
.render_passes
[3]->id
.layer_id
);
316 EXPECT_EQ(0, frame
.render_passes
[3]->id
.index
);
317 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
318 EXPECT_EQ(0, frame
.render_passes
[4]->id
.index
);
320 // The DelegatedRendererLayer should have added its RenderPasses to the frame
322 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
323 frame
.render_passes
[1]->output_rect
.ToString());
324 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
325 frame
.render_passes
[2]->output_rect
.ToString());
327 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
328 host_impl_
->DidDrawAllLayers(frame
);
331 TEST_F(DelegatedRendererLayerImplTestSimple
,
332 AddsQuadsToContributingRenderPasses
) {
333 LayerTreeHostImpl::FrameData frame
;
334 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
336 // Each non-DelegatedRendererLayer added one RenderPass. The
337 // DelegatedRendererLayer added two contributing passes.
338 ASSERT_EQ(5u, frame
.render_passes
.size());
340 // The DelegatedRendererLayer should have added its contributing RenderPasses
342 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
343 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
344 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
345 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
347 // The DelegatedRendererLayer should have added copies of its quads to
348 // contributing RenderPasses.
349 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
350 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
351 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
353 // Verify it added the right quads.
354 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
355 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
356 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
357 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
358 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
359 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
360 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
361 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
363 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
364 host_impl_
->DidDrawAllLayers(frame
);
367 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsQuadsToTargetRenderPass
) {
368 LayerTreeHostImpl::FrameData frame
;
369 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
371 // Each non-DelegatedRendererLayer added one RenderPass. The
372 // DelegatedRendererLayer added two contributing passes.
373 ASSERT_EQ(5u, frame
.render_passes
.size());
375 // The layer's target is the RenderPass from layer_after_.
376 EXPECT_EQ(RenderPassId(3, 0), frame
.render_passes
[3]->id
);
378 // The DelegatedRendererLayer should have added copies of quads in its root
379 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
380 ASSERT_EQ(2u, frame
.render_passes
[3]->quad_list
.size());
382 // Verify it added the right quads.
383 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
384 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
386 // Its target layer should have a quad as well.
387 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
388 frame
.render_passes
[3]->quad_list
.ElementAt(1)->rect
.ToString());
390 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
391 host_impl_
->DidDrawAllLayers(frame
);
394 TEST_F(DelegatedRendererLayerImplTestSimple
,
395 QuadsFromRootRenderPassAreModifiedForTheTarget
) {
396 LayerTreeHostImpl::FrameData frame
;
397 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
399 // Each non-DelegatedRendererLayer added one RenderPass. The
400 // DelegatedRendererLayer added two contributing passes.
401 ASSERT_EQ(5u, frame
.render_passes
.size());
403 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
404 // has a translation transform of 1,1. So its root RenderPass' quads should
405 // all be transformed by that combined amount.
406 gfx::Transform transform
;
407 transform
.Translate(4.0, 4.0);
408 EXPECT_TRANSFORMATION_MATRIX_EQ(
409 transform
, frame
.render_passes
[3]->quad_list
.front()->quadTransform());
411 // Quads from non-root RenderPasses should not be shifted though.
412 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
414 EXPECT_TRANSFORMATION_MATRIX_EQ(
416 frame
.render_passes
[2]->quad_list
.front()->quadTransform());
417 EXPECT_TRANSFORMATION_MATRIX_EQ(
419 frame
.render_passes
[2]->quad_list
.ElementAt(1)->quadTransform());
420 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
421 EXPECT_TRANSFORMATION_MATRIX_EQ(
423 frame
.render_passes
[1]->quad_list
.front()->quadTransform());
425 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
426 host_impl_
->DidDrawAllLayers(frame
);
429 TEST_F(DelegatedRendererLayerImplTestSimple
, RenderPassTransformIsModified
) {
430 LayerTreeHostImpl::FrameData frame
;
431 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
433 // The delegated layer has a surface between it and the root.
434 EXPECT_TRUE(delegated_renderer_layer_
->render_target()->parent());
436 // Each non-DelegatedRendererLayer added one RenderPass. The
437 // DelegatedRendererLayer added two contributing passes.
438 ASSERT_EQ(5u, frame
.render_passes
.size());
440 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
441 // render pass' transforms to the root should be shifted by this amount.
442 gfx::Transform transform
;
443 transform
.Translate(9.0, 9.0);
445 // The first contributing surface has a translation of 5, 6.
446 gfx::Transform
five_six(1, 0, 0, 1, 5, 6);
448 // The second contributing surface has a translation of 7, 8.
449 gfx::Transform
seven_eight(1, 0, 0, 1, 7, 8);
451 EXPECT_TRANSFORMATION_MATRIX_EQ(
452 transform
* five_six
, frame
.render_passes
[1]->transform_to_root_target
);
453 EXPECT_TRANSFORMATION_MATRIX_EQ(
454 transform
* seven_eight
,
455 frame
.render_passes
[2]->transform_to_root_target
);
457 host_impl_
->DrawLayers(&frame
, base::TimeTicks::Now());
458 host_impl_
->DidDrawAllLayers(frame
);
461 class DelegatedRendererLayerImplTestOwnSurface
462 : public DelegatedRendererLayerImplTestSimple
{
464 DelegatedRendererLayerImplTestOwnSurface()
465 : DelegatedRendererLayerImplTestSimple() {
466 delegated_renderer_layer_
->SetHasRenderSurface(true);
470 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsRenderPasses
) {
471 LayerTreeHostImpl::FrameData frame
;
472 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
474 // Each non-DelegatedRendererLayer added one RenderPass. The
475 // DelegatedRendererLayer added two contributing passes and its owned surface
477 ASSERT_EQ(6u, frame
.render_passes
.size());
479 // The DelegatedRendererLayer should have added its contributing RenderPasses
481 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
482 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
483 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
484 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
485 // The DelegatedRendererLayer should have added a RenderPass for its surface
487 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
488 EXPECT_EQ(0, frame
.render_passes
[3]->id
.index
);
489 // And all other RenderPasses should be non-delegated.
490 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
491 EXPECT_EQ(0, frame
.render_passes
[0]->id
.index
);
492 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
493 EXPECT_EQ(0, frame
.render_passes
[4]->id
.index
);
494 EXPECT_NE(4, frame
.render_passes
[5]->id
.layer_id
);
495 EXPECT_EQ(0, frame
.render_passes
[5]->id
.index
);
497 // The DelegatedRendererLayer should have added its RenderPasses to the frame
499 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
500 frame
.render_passes
[1]->output_rect
.ToString());
501 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
502 frame
.render_passes
[2]->output_rect
.ToString());
504 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
505 host_impl_
->DidDrawAllLayers(frame
);
508 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
509 AddsQuadsToContributingRenderPasses
) {
510 LayerTreeHostImpl::FrameData frame
;
511 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
513 // Each non-DelegatedRendererLayer added one RenderPass. The
514 // DelegatedRendererLayer added two contributing passes and its owned surface
516 ASSERT_EQ(6u, frame
.render_passes
.size());
518 // The DelegatedRendererLayer should have added its contributing RenderPasses
520 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
521 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
522 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
523 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
525 // The DelegatedRendererLayer should have added copies of its quads to
526 // contributing RenderPasses.
527 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
528 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
529 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
531 // Verify it added the right quads.
532 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
534 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
535 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
536 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
537 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
538 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
539 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
540 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
542 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
543 host_impl_
->DidDrawAllLayers(frame
);
546 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsQuadsToTargetRenderPass
) {
547 LayerTreeHostImpl::FrameData frame
;
548 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
550 // Each non-DelegatedRendererLayer added one RenderPass. The
551 // DelegatedRendererLayer added two contributing passes and its owned surface
553 ASSERT_EQ(6u, frame
.render_passes
.size());
555 // The layer's target is the RenderPass owned by itself.
556 EXPECT_EQ(RenderPassId(4, 0), frame
.render_passes
[3]->id
);
558 // The DelegatedRendererLayer should have added copies of quads in its root
559 // RenderPass to its target RenderPass.
560 // The layer_after also adds one quad.
561 ASSERT_EQ(1u, frame
.render_passes
[3]->quad_list
.size());
563 // Verify it added the right quads.
564 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
565 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
567 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
568 host_impl_
->DidDrawAllLayers(frame
);
571 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
572 QuadsFromRootRenderPassAreNotModifiedForTheTarget
) {
573 LayerTreeHostImpl::FrameData frame
;
574 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
576 // Each non-DelegatedRendererLayer added one RenderPass. The
577 // DelegatedRendererLayer added two contributing passes and its owned surface
579 ASSERT_EQ(6u, frame
.render_passes
.size());
581 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
582 // RenderPass' quads do not need to be translated at all.
583 EXPECT_TRANSFORMATION_MATRIX_EQ(
585 frame
.render_passes
[3]->quad_list
.front()->quadTransform());
587 // Quads from non-root RenderPasses should not be shifted either.
588 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
590 EXPECT_TRANSFORMATION_MATRIX_EQ(
592 frame
.render_passes
[2]->quad_list
.front()->quadTransform());
593 EXPECT_TRANSFORMATION_MATRIX_EQ(
595 frame
.render_passes
[2]->quad_list
.ElementAt(1)->quadTransform());
596 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
597 EXPECT_TRANSFORMATION_MATRIX_EQ(
599 frame
.render_passes
[1]->quad_list
.front()->quadTransform());
601 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
602 host_impl_
->DidDrawAllLayers(frame
);
605 class DelegatedRendererLayerImplTestTransform
606 : public DelegatedRendererLayerImplTest
{
608 DelegatedRendererLayerImplTestTransform()
609 : root_delegated_render_pass_is_clipped_(false),
610 delegated_device_scale_factor_(2.f
) {}
613 host_impl_
->SetDeviceScaleFactor(2.f
);
615 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::Create(
616 host_impl_
->active_tree(), 1);
617 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
618 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
620 host_impl_
->SetViewportSize(gfx::Size(200, 200));
621 root_layer
->SetBounds(gfx::Size(100, 100));
622 root_layer
->SetHasRenderSurface(true);
624 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
625 delegated_renderer_layer
->SetBounds(gfx::Size(75, 75));
626 delegated_renderer_layer
->SetContentBounds(gfx::Size(75, 75));
627 delegated_renderer_layer
->SetDrawsContent(true);
628 gfx::Transform transform
;
629 transform
.Scale(2.0, 2.0);
630 transform
.Translate(8.0, 8.0);
631 delegated_renderer_layer
->SetTransform(transform
);
633 RenderPassList delegated_render_passes
;
635 gfx::Size
child_pass_content_bounds(7, 7);
636 gfx::Rect
child_pass_rect(20, 20, 7, 7);
637 gfx::Transform child_pass_transform
;
638 child_pass_transform
.Scale(0.8f
, 0.8f
);
639 child_pass_transform
.Translate(9.0, 9.0);
640 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
641 bool child_pass_clipped
= false;
644 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
648 SharedQuadState
* shared_quad_state
=
649 pass
->CreateAndAppendSharedQuadState();
650 shared_quad_state
->SetAll(child_pass_transform
,
651 child_pass_content_bounds
,
653 child_pass_clip_rect
,
656 SkXfermode::kSrcOver_Mode
,
659 SolidColorDrawQuad
* color_quad
;
660 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
661 color_quad
->SetNew(shared_quad_state
,
662 gfx::Rect(20, 20, 3, 7),
663 gfx::Rect(20, 20, 3, 7),
667 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
668 color_quad
->SetNew(shared_quad_state
,
669 gfx::Rect(23, 20, 4, 7),
670 gfx::Rect(23, 20, 4, 7),
675 gfx::Size
root_pass_content_bounds(100, 100);
676 gfx::Rect
root_pass_rect(0, 0, 100, 100);
677 gfx::Transform root_pass_transform
;
678 root_pass_transform
.Scale(1.5, 1.5);
679 root_pass_transform
.Translate(7.0, 7.0);
680 gfx::Rect
root_pass_clip_rect(10, 10, 35, 35);
681 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
683 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
687 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
688 shared_quad_state
->SetAll(root_pass_transform
,
689 root_pass_content_bounds
,
694 SkXfermode::kSrcOver_Mode
,
697 RenderPassDrawQuad
* render_pass_quad
=
698 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
699 render_pass_quad
->SetNew(shared_quad_state
,
700 gfx::Rect(5, 5, 7, 7), // quad_rect
701 gfx::Rect(5, 5, 7, 7), // visible_rect
702 RenderPassId(10, 7), // render_pass_id
703 0, // mask_resource_id
704 gfx::Vector2dF(), // mask_uv_scale
705 gfx::Size(), // mask_texture_size
706 FilterOperations(), // filters
707 gfx::Vector2dF(), // filters_scale
708 FilterOperations()); // background_filters
710 SolidColorDrawQuad
* color_quad
;
711 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
712 color_quad
->SetNew(shared_quad_state
,
713 gfx::Rect(0, 0, 10, 10),
714 gfx::Rect(0, 0, 10, 10),
718 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
719 color_quad
->SetNew(shared_quad_state
,
720 gfx::Rect(0, 10, 10, 10),
721 gfx::Rect(0, 10, 10, 10),
725 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
726 color_quad
->SetNew(shared_quad_state
,
727 gfx::Rect(10, 0, 10, 10),
728 gfx::Rect(10, 0, 10, 10),
732 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
733 color_quad
->SetNew(shared_quad_state
,
734 gfx::Rect(10, 10, 10, 10),
735 gfx::Rect(10, 10, 10, 10),
739 delegated_renderer_layer
->SetFrameDataForRenderPasses(
740 delegated_device_scale_factor_
, delegated_render_passes
);
742 root_layer_
= root_layer
.get();
743 delegated_renderer_layer_
= delegated_renderer_layer
.get();
745 root_layer
->AddChild(delegated_renderer_layer
.Pass());
746 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
749 void VerifyRenderPasses(
750 const LayerTreeHostImpl::FrameData
& frame
,
751 size_t num_render_passes
,
752 const SharedQuadState
** root_delegated_shared_quad_state
,
753 const SharedQuadState
** contrib_delegated_shared_quad_state
) {
754 ASSERT_EQ(num_render_passes
, frame
.render_passes
.size());
755 // The contributing render pass in the DelegatedRendererLayer.
756 EXPECT_EQ(2, frame
.render_passes
[0]->id
.layer_id
);
757 EXPECT_EQ(1, frame
.render_passes
[0]->id
.index
);
758 // The root render pass.
759 EXPECT_EQ(1, frame
.render_passes
.back()->id
.layer_id
);
760 EXPECT_EQ(0, frame
.render_passes
.back()->id
.index
);
762 const QuadList
& contrib_delegated_quad_list
=
763 frame
.render_passes
[0]->quad_list
;
764 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
766 const QuadList
& root_delegated_quad_list
=
767 frame
.render_passes
[1]->quad_list
;
768 ASSERT_EQ(5u, root_delegated_quad_list
.size());
770 // All quads in a render pass should share the same state.
771 *contrib_delegated_shared_quad_state
=
772 contrib_delegated_quad_list
.front()->shared_quad_state
;
773 EXPECT_EQ(*contrib_delegated_shared_quad_state
,
774 contrib_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
776 *root_delegated_shared_quad_state
=
777 root_delegated_quad_list
.front()->shared_quad_state
;
778 EXPECT_EQ(*root_delegated_shared_quad_state
,
779 root_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
780 EXPECT_EQ(*root_delegated_shared_quad_state
,
781 root_delegated_quad_list
.ElementAt(2)->shared_quad_state
);
782 EXPECT_EQ(*root_delegated_shared_quad_state
,
783 root_delegated_quad_list
.ElementAt(3)->shared_quad_state
);
784 EXPECT_EQ(*root_delegated_shared_quad_state
,
785 root_delegated_quad_list
.ElementAt(4)->shared_quad_state
);
787 EXPECT_NE(*contrib_delegated_shared_quad_state
,
788 *root_delegated_shared_quad_state
);
792 LayerImpl
* root_layer_
;
793 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
794 bool root_delegated_render_pass_is_clipped_
;
795 float delegated_device_scale_factor_
;
798 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_NoSurface
) {
799 root_delegated_render_pass_is_clipped_
= false;
802 LayerTreeHostImpl::FrameData frame
;
803 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
805 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
806 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
810 &root_delegated_shared_quad_state
,
811 &contrib_delegated_shared_quad_state
);
813 // When the quads don't have a clip of their own, the clip rect is set to
814 // the drawable_content_rect of the delegated renderer layer.
815 EXPECT_EQ(delegated_renderer_layer_
->drawable_content_rect().ToString(),
816 root_delegated_shared_quad_state
->clip_rect
.ToString());
818 // Even though the quads in the root pass have no clip of their own, they
819 // inherit the clip rect from the delegated renderer layer if it does not
821 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
823 gfx::Transform expected
;
824 // Device scale factor.
825 expected
.Scale(2.0, 2.0);
826 // This is the transform from the layer's space to its target.
827 expected
.Translate(20, 20);
828 expected
.Scale(2.0, 2.0);
829 expected
.Translate(8.0, 8.0);
830 // This is the transform within the source frame.
831 // Inverse device scale factor to go from physical space to layer space.
832 expected
.Scale(0.5, 0.5);
833 expected
.Scale(1.5, 1.5);
834 expected
.Translate(7.0, 7.0);
835 EXPECT_TRANSFORMATION_MATRIX_EQ(
836 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
838 // The contributing render pass should not be transformed from its input.
839 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
840 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
841 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
842 expected
.MakeIdentity();
843 expected
.Scale(0.8f
, 0.8f
);
844 expected
.Translate(9.0, 9.0);
845 EXPECT_TRANSFORMATION_MATRIX_EQ(
847 contrib_delegated_shared_quad_state
->content_to_target_transform
);
849 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
850 host_impl_
->DidDrawAllLayers(frame
);
853 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_NoSurface
) {
854 root_delegated_render_pass_is_clipped_
= true;
857 LayerTreeHostImpl::FrameData frame
;
858 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
860 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
861 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
865 &root_delegated_shared_quad_state
,
866 &contrib_delegated_shared_quad_state
);
868 // Since the quads have a clip_rect it should be modified by delegated
869 // renderer layer's draw_transform.
870 // The position of the resulting clip_rect is:
871 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
872 // layer scale (2) + layer position (20) = 46
873 // The device scale is 2, so everything gets doubled, giving 92.
875 // The size is 35x35 scaled by the device scale.
876 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
877 root_delegated_shared_quad_state
->clip_rect
.ToString());
879 // The quads had a clip and it should be preserved.
880 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
882 gfx::Transform expected
;
883 // Device scale factor.
884 expected
.Scale(2.0, 2.0);
885 // This is the transform from the layer's space to its target.
886 expected
.Translate(20, 20);
887 expected
.Scale(2.0, 2.0);
888 expected
.Translate(8.0, 8.0);
889 // This is the transform within the source frame.
890 // Inverse device scale factor to go from physical space to layer space.
891 expected
.Scale(0.5, 0.5);
892 expected
.Scale(1.5, 1.5);
893 expected
.Translate(7.0, 7.0);
894 EXPECT_TRANSFORMATION_MATRIX_EQ(
895 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
897 // The contributing render pass should not be transformed from its input.
898 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
899 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
900 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
901 expected
.MakeIdentity();
902 expected
.Scale(0.8f
, 0.8f
);
903 expected
.Translate(9.0, 9.0);
904 EXPECT_TRANSFORMATION_MATRIX_EQ(
906 contrib_delegated_shared_quad_state
->content_to_target_transform
);
908 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
909 host_impl_
->DidDrawAllLayers(frame
);
912 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_Surface
) {
913 root_delegated_render_pass_is_clipped_
= false;
916 delegated_renderer_layer_
->SetHasRenderSurface(true);
918 LayerTreeHostImpl::FrameData frame
;
919 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
921 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
922 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
926 &root_delegated_shared_quad_state
,
927 &contrib_delegated_shared_quad_state
);
929 // When the layer owns a surface, then its translation is not part of its
930 // draw transform, but its scale is.
931 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
932 root_delegated_shared_quad_state
->clip_rect
.ToString());
934 // Since the layer owns a surface it doesn't need to clip its quads, so
935 // unclipped quads remain unclipped.
936 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
938 gfx::Transform expected
;
939 // This is the transform within the source frame scaled by the delegated
940 // render layer transform.
941 expected
.Scale(3.0, 3.0);
942 expected
.Translate(7.0, 7.0);
943 EXPECT_TRANSFORMATION_MATRIX_EQ(
944 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
946 // The contributing render pass should not be transformed from its input.
947 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
948 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
949 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
950 expected
.MakeIdentity();
951 expected
.Scale(0.8f
, 0.8f
);
952 expected
.Translate(9.0, 9.0);
953 EXPECT_TRANSFORMATION_MATRIX_EQ(
955 contrib_delegated_shared_quad_state
->content_to_target_transform
);
957 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
958 host_impl_
->DidDrawAllLayers(frame
);
961 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_Surface
) {
962 root_delegated_render_pass_is_clipped_
= true;
965 delegated_renderer_layer_
->SetHasRenderSurface(true);
967 LayerTreeHostImpl::FrameData frame
;
968 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
970 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
971 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
975 &root_delegated_shared_quad_state
,
976 &contrib_delegated_shared_quad_state
);
978 // When the layer owns a surface, then its translation is not part of its
979 // draw transform, but its scale is.
980 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
981 root_delegated_shared_quad_state
->clip_rect
.ToString());
983 // The quads had a clip and it should be preserved.
984 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
986 gfx::Transform expected
;
987 // This is the transform within the source frame scaled by the delegated
988 // render layer transform.
989 expected
.Scale(3.0, 3.0);
990 expected
.Translate(7.0, 7.0);
991 EXPECT_TRANSFORMATION_MATRIX_EQ(
992 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
994 // The contributing render pass should not be transformed from its input.
995 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
996 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
997 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
998 expected
.MakeIdentity();
999 expected
.Scale(0.8f
, 0.8f
);
1000 expected
.Translate(9.0, 9.0);
1001 EXPECT_TRANSFORMATION_MATRIX_EQ(
1003 contrib_delegated_shared_quad_state
->content_to_target_transform
);
1005 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1006 host_impl_
->DidDrawAllLayers(frame
);
1009 TEST_F(DelegatedRendererLayerImplTestTransform
, MismatchedDeviceScaleFactor
) {
1010 root_delegated_render_pass_is_clipped_
= true;
1011 delegated_device_scale_factor_
= 1.3f
;
1015 LayerTreeHostImpl::FrameData frame
;
1016 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1018 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
1019 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
1020 VerifyRenderPasses(frame
,
1022 &root_delegated_shared_quad_state
,
1023 &contrib_delegated_shared_quad_state
);
1025 // The parent tree's device scale factor is 2.0, but the child has submitted a
1026 // frame with a device scale factor of 1.3. Absent any better option, the
1027 // only thing we can do is scale from 1.3 -> 2.0.
1029 gfx::Transform expected
;
1030 // Device scale factor (from parent).
1031 expected
.Scale(2.0, 2.0);
1032 // This is the transform from the layer's space to its target.
1033 expected
.Translate(20, 20);
1034 expected
.Scale(2.0, 2.0);
1035 expected
.Translate(8.0, 8.0);
1036 // This is the transform within the source frame.
1037 // Inverse device scale factor (from child).
1038 expected
.Scale(1.0f
/ 1.3f
, 1.0f
/ 1.3f
);
1039 expected
.Scale(1.5, 1.5);
1040 expected
.Translate(7.0, 7.0);
1041 EXPECT_TRANSFORMATION_MATRIX_EQ(
1042 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
1044 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1045 host_impl_
->DidDrawAllLayers(frame
);
1048 class DelegatedRendererLayerImplTestClip
1049 : public DelegatedRendererLayerImplTest
{
1052 scoped_ptr
<LayerImpl
> root_layer
=
1053 LayerImpl::Create(host_impl_
->active_tree(), 1);
1054 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
1055 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
1056 scoped_ptr
<LayerImpl
> clip_layer
=
1057 LayerImpl::Create(host_impl_
->active_tree(), 3);
1058 scoped_ptr
<LayerImpl
> origin_layer
=
1059 LayerImpl::Create(host_impl_
->active_tree(), 4);
1061 host_impl_
->SetViewportSize(gfx::Size(100, 100));
1062 root_layer
->SetBounds(gfx::Size(100, 100));
1063 root_layer
->SetHasRenderSurface(true);
1065 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
1066 delegated_renderer_layer
->SetBounds(gfx::Size(50, 50));
1067 delegated_renderer_layer
->SetContentBounds(gfx::Size(50, 50));
1068 delegated_renderer_layer
->SetDrawsContent(true);
1070 RenderPassList delegated_render_passes
;
1072 gfx::Size
child_pass_content_bounds(7, 7);
1073 gfx::Rect
child_pass_rect(20, 20, 7, 7);
1074 gfx::Transform child_pass_transform
;
1075 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
1076 bool child_pass_clipped
= false;
1079 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
1080 RenderPassId(10, 7),
1083 SharedQuadState
* shared_quad_state
=
1084 pass
->CreateAndAppendSharedQuadState();
1085 shared_quad_state
->SetAll(child_pass_transform
,
1086 child_pass_content_bounds
,
1088 child_pass_clip_rect
,
1091 SkXfermode::kSrcOver_Mode
,
1094 SolidColorDrawQuad
* color_quad
;
1095 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1096 color_quad
->SetNew(shared_quad_state
,
1097 gfx::Rect(20, 20, 3, 7),
1098 gfx::Rect(20, 20, 3, 7),
1102 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1103 color_quad
->SetNew(shared_quad_state
,
1104 gfx::Rect(23, 20, 4, 7),
1105 gfx::Rect(23, 20, 4, 7),
1110 gfx::Size
root_pass_content_bounds(50, 50);
1111 gfx::Rect
root_pass_rect(0, 0, 50, 50);
1112 gfx::Transform root_pass_transform
;
1113 gfx::Rect
root_pass_clip_rect(5, 5, 40, 40);
1114 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
1116 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
1120 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
1121 shared_quad_state
->SetAll(root_pass_transform
,
1122 root_pass_content_bounds
,
1124 root_pass_clip_rect
,
1127 SkXfermode::kSrcOver_Mode
,
1130 RenderPassDrawQuad
* render_pass_quad
=
1131 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1132 render_pass_quad
->SetNew(shared_quad_state
,
1133 gfx::Rect(5, 5, 7, 7), // quad_rect
1134 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1135 RenderPassId(10, 7), // render_pass_id
1136 0, // mask_resource_id
1137 gfx::Vector2dF(), // mask_uv_scale
1138 gfx::Size(), // mask_texture_size,
1139 FilterOperations(), // filters
1140 gfx::Vector2dF(), // filters_scale
1141 FilterOperations()); // background_filters
1143 SolidColorDrawQuad
* color_quad
;
1144 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1145 color_quad
->SetNew(shared_quad_state
,
1146 gfx::Rect(0, 0, 10, 10),
1147 gfx::Rect(0, 0, 10, 10),
1151 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1152 color_quad
->SetNew(shared_quad_state
,
1153 gfx::Rect(0, 10, 10, 10),
1154 gfx::Rect(0, 10, 10, 10),
1158 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1159 color_quad
->SetNew(shared_quad_state
,
1160 gfx::Rect(10, 0, 10, 10),
1161 gfx::Rect(10, 0, 10, 10),
1165 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1166 color_quad
->SetNew(shared_quad_state
,
1167 gfx::Rect(10, 10, 10, 10),
1168 gfx::Rect(10, 10, 10, 10),
1172 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1173 1.f
, delegated_render_passes
);
1175 root_layer_
= root_layer
.get();
1176 delegated_renderer_layer_
= delegated_renderer_layer
.get();
1178 if (clip_delegated_renderer_layer_
) {
1179 gfx::Rect
clip_rect(21, 27, 23, 21);
1181 clip_layer
->SetPosition(clip_rect
.origin());
1182 clip_layer
->SetBounds(clip_rect
.size());
1183 clip_layer
->SetContentBounds(clip_rect
.size());
1184 clip_layer
->SetMasksToBounds(true);
1186 origin_layer
->SetPosition(
1187 gfx::PointAtOffsetFromOrigin(-clip_rect
.OffsetFromOrigin()));
1189 origin_layer
->AddChild(delegated_renderer_layer
.Pass());
1190 clip_layer
->AddChild(origin_layer
.Pass());
1191 root_layer
->AddChild(clip_layer
.Pass());
1193 root_layer
->AddChild(delegated_renderer_layer
.Pass());
1196 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1200 LayerImpl
* root_layer_
;
1201 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
1202 bool root_delegated_render_pass_is_clipped_
;
1203 bool clip_delegated_renderer_layer_
;
1206 TEST_F(DelegatedRendererLayerImplTestClip
,
1207 QuadsUnclipped_LayerUnclipped_NoSurface
) {
1208 root_delegated_render_pass_is_clipped_
= false;
1209 clip_delegated_renderer_layer_
= false;
1212 LayerTreeHostImpl::FrameData frame
;
1213 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1215 ASSERT_EQ(2u, frame
.render_passes
.size());
1216 const QuadList
& contrib_delegated_quad_list
=
1217 frame
.render_passes
[0]->quad_list
;
1218 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1219 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1220 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1221 const SharedQuadState
* root_delegated_shared_quad_state
=
1222 root_delegated_quad_list
.front()->shared_quad_state
;
1224 // When the quads don't have a clip of their own, the clip rect is set to
1225 // the drawable_content_rect of the delegated renderer layer.
1226 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1227 root_delegated_shared_quad_state
->clip_rect
.ToString());
1228 // Quads are clipped to the delegated renderer layer.
1229 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1231 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1232 host_impl_
->DidDrawAllLayers(frame
);
1235 TEST_F(DelegatedRendererLayerImplTestClip
,
1236 QuadsClipped_LayerUnclipped_NoSurface
) {
1237 root_delegated_render_pass_is_clipped_
= true;
1238 clip_delegated_renderer_layer_
= false;
1241 LayerTreeHostImpl::FrameData frame
;
1242 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1244 ASSERT_EQ(2u, frame
.render_passes
.size());
1245 const QuadList
& contrib_delegated_quad_list
=
1246 frame
.render_passes
[0]->quad_list
;
1247 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1248 const QuadList
& root_delegated_quad_list
=
1249 frame
.render_passes
[1]->quad_list
;
1250 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1251 const SharedQuadState
* root_delegated_shared_quad_state
=
1252 root_delegated_quad_list
.front()->shared_quad_state
;
1254 // When the quads have a clip of their own, it is used.
1255 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1256 root_delegated_shared_quad_state
->clip_rect
.ToString());
1257 // Quads came with a clip rect.
1258 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1260 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1261 host_impl_
->DidDrawAllLayers(frame
);
1264 TEST_F(DelegatedRendererLayerImplTestClip
,
1265 QuadsUnclipped_LayerClipped_NoSurface
) {
1266 root_delegated_render_pass_is_clipped_
= false;
1267 clip_delegated_renderer_layer_
= true;
1270 LayerTreeHostImpl::FrameData frame
;
1271 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1273 ASSERT_EQ(2u, frame
.render_passes
.size());
1274 const QuadList
& contrib_delegated_quad_list
=
1275 frame
.render_passes
[0]->quad_list
;
1276 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1277 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1278 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1279 const SharedQuadState
* root_delegated_shared_quad_state
=
1280 root_delegated_quad_list
.front()->shared_quad_state
;
1282 // When the quads don't have a clip of their own, the clip rect is set to
1283 // the drawable_content_rect of the delegated renderer layer. When the layer
1284 // is clipped, that should be seen in the quads' clip_rect.
1285 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1286 root_delegated_shared_quad_state
->clip_rect
.ToString());
1287 // Quads are clipped to the delegated renderer layer.
1288 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1290 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1291 host_impl_
->DidDrawAllLayers(frame
);
1294 TEST_F(DelegatedRendererLayerImplTestClip
,
1295 QuadsClipped_LayerClipped_NoSurface
) {
1296 root_delegated_render_pass_is_clipped_
= true;
1297 clip_delegated_renderer_layer_
= true;
1300 LayerTreeHostImpl::FrameData frame
;
1301 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1303 ASSERT_EQ(2u, frame
.render_passes
.size());
1304 const QuadList
& contrib_delegated_quad_list
=
1305 frame
.render_passes
[0]->quad_list
;
1306 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1307 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1308 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1309 const SharedQuadState
* root_delegated_shared_quad_state
=
1310 root_delegated_quad_list
.front()->shared_quad_state
;
1312 // When the quads have a clip of their own, it is used, but it is
1313 // combined with the clip rect of the delegated renderer layer.
1314 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1315 root_delegated_shared_quad_state
->clip_rect
.ToString());
1316 // Quads came with a clip rect.
1317 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1319 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1320 host_impl_
->DidDrawAllLayers(frame
);
1323 TEST_F(DelegatedRendererLayerImplTestClip
,
1324 QuadsUnclipped_LayerUnclipped_Surface
) {
1325 root_delegated_render_pass_is_clipped_
= false;
1326 clip_delegated_renderer_layer_
= false;
1329 delegated_renderer_layer_
->SetHasRenderSurface(true);
1331 LayerTreeHostImpl::FrameData frame
;
1332 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1334 ASSERT_EQ(3u, frame
.render_passes
.size());
1335 const QuadList
& contrib_delegated_quad_list
=
1336 frame
.render_passes
[0]->quad_list
;
1337 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1338 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1339 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1340 const SharedQuadState
* root_delegated_shared_quad_state
=
1341 root_delegated_quad_list
.front()->shared_quad_state
;
1343 // When the layer owns a surface, the quads don't need to be clipped
1344 // further than they already specify. If they aren't clipped, then their
1345 // clip rect is ignored, and they are not set as clipped.
1346 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1348 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1349 host_impl_
->DidDrawAllLayers(frame
);
1352 TEST_F(DelegatedRendererLayerImplTestClip
,
1353 QuadsClipped_LayerUnclipped_Surface
) {
1354 root_delegated_render_pass_is_clipped_
= true;
1355 clip_delegated_renderer_layer_
= false;
1358 delegated_renderer_layer_
->SetHasRenderSurface(true);
1360 LayerTreeHostImpl::FrameData frame
;
1361 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1363 ASSERT_EQ(3u, frame
.render_passes
.size());
1364 const QuadList
& contrib_delegated_quad_list
=
1365 frame
.render_passes
[0]->quad_list
;
1366 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1367 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1368 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1369 const SharedQuadState
* root_delegated_shared_quad_state
=
1370 root_delegated_quad_list
.front()->shared_quad_state
;
1372 // When the quads have a clip of their own, it is used.
1373 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1374 root_delegated_shared_quad_state
->clip_rect
.ToString());
1375 // Quads came with a clip rect.
1376 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1378 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1379 host_impl_
->DidDrawAllLayers(frame
);
1382 TEST_F(DelegatedRendererLayerImplTestClip
,
1383 QuadsUnclipped_LayerClipped_Surface
) {
1384 root_delegated_render_pass_is_clipped_
= false;
1385 clip_delegated_renderer_layer_
= true;
1388 delegated_renderer_layer_
->SetHasRenderSurface(true);
1390 LayerTreeHostImpl::FrameData frame
;
1391 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1393 ASSERT_EQ(3u, frame
.render_passes
.size());
1394 const QuadList
& contrib_delegated_quad_list
=
1395 frame
.render_passes
[0]->quad_list
;
1396 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1397 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1398 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1399 const SharedQuadState
* root_delegated_shared_quad_state
=
1400 root_delegated_quad_list
.front()->shared_quad_state
;
1402 // When the layer owns a surface, the quads don't need to be clipped
1403 // further than they already specify. If they aren't clipped, then their
1404 // clip rect is ignored, and they are not set as clipped.
1405 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1407 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1408 host_impl_
->DidDrawAllLayers(frame
);
1411 TEST_F(DelegatedRendererLayerImplTestClip
, QuadsClipped_LayerClipped_Surface
) {
1412 root_delegated_render_pass_is_clipped_
= true;
1413 clip_delegated_renderer_layer_
= true;
1416 delegated_renderer_layer_
->SetHasRenderSurface(true);
1418 LayerTreeHostImpl::FrameData frame
;
1419 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1421 ASSERT_EQ(3u, frame
.render_passes
.size());
1422 const QuadList
& contrib_delegated_quad_list
=
1423 frame
.render_passes
[0]->quad_list
;
1424 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1425 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1426 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1427 const SharedQuadState
* root_delegated_shared_quad_state
=
1428 root_delegated_quad_list
.front()->shared_quad_state
;
1430 // When the quads have a clip of their own, it is used, but it is
1431 // combined with the clip rect of the delegated renderer layer. If the
1432 // layer owns a surface, then it does not have a clip rect of its own.
1433 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1434 root_delegated_shared_quad_state
->clip_rect
.ToString());
1435 // Quads came with a clip rect.
1436 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1438 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1439 host_impl_
->DidDrawAllLayers(frame
);
1442 TEST_F(DelegatedRendererLayerImplTest
, InvalidRenderPassDrawQuad
) {
1443 scoped_ptr
<LayerImpl
> root_layer
=
1444 LayerImpl::Create(host_impl_
->active_tree(), 1);
1445 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
1446 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 4);
1448 host_impl_
->SetViewportSize(gfx::Size(100, 100));
1449 root_layer
->SetHasRenderSurface(true);
1451 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
1452 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
1453 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
1454 delegated_renderer_layer
->SetDrawsContent(true);
1456 RenderPassList delegated_render_passes
;
1457 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
1459 gfx::Rect(0, 0, 10, 10),
1461 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
1463 // This render pass isn't part of the frame.
1464 scoped_ptr
<TestRenderPass
> missing_pass(TestRenderPass::Create());
1465 missing_pass
->SetNew(RenderPassId(9, 7),
1466 gfx::Rect(7, 7, 7, 7),
1467 gfx::Rect(7, 7, 7, 7),
1470 // But a render pass quad refers to it.
1471 AddRenderPassQuad(pass1
, missing_pass
.get());
1473 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1474 1.f
, delegated_render_passes
);
1476 root_layer
->AddChild(delegated_renderer_layer
.Pass());
1477 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1479 LayerTreeHostImpl::FrameData frame
;
1480 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1482 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1483 ASSERT_EQ(1u, frame
.render_passes
.size());
1484 ASSERT_EQ(1u, frame
.render_passes
[0]->quad_list
.size());
1485 EXPECT_EQ(DrawQuad::SOLID_COLOR
,
1486 frame
.render_passes
[0]->quad_list
.front()->material
);
1488 host_impl_
->DrawLayers(&frame
, gfx::FrameTime::Now());
1489 host_impl_
->DidDrawAllLayers(frame
);
1492 TEST_F(DelegatedRendererLayerImplTest
, Occlusion
) {
1493 gfx::Size
layer_size(1000, 1000);
1494 gfx::Size
viewport_size(1000, 1000);
1495 gfx::Rect
quad_screen_rect(211, 300, 400, 500);
1497 gfx::Transform transform
;
1498 transform
.Translate(211.0, 300.0);
1500 LayerTestCommon::LayerImplTest impl
;
1502 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1503 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1504 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1505 delegated_renderer_layer_impl
->SetContentBounds(layer_size
);
1506 delegated_renderer_layer_impl
->SetDrawsContent(true);
1508 // Contributing render pass is offset by a transform and holds a quad that
1509 // covers it entirely.
1510 RenderPassList delegated_render_passes
;
1511 // pass2 is just the size of the quad. It contributes to |pass1| with a
1512 // translation of (211,300).
1513 RenderPassId pass2_id
=
1514 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1515 TestRenderPass
* pass2
= AddRenderPass(&delegated_render_passes
,
1517 gfx::Rect(quad_screen_rect
.size()),
1519 AddQuad(pass2
, gfx::Rect(quad_screen_rect
.size()), SK_ColorRED
);
1520 // |pass1| covers the whole layer.
1521 RenderPassId pass1_id
= RenderPassId(impl
.root_layer()->id(), 0);
1522 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
1524 gfx::Rect(layer_size
),
1526 AddRenderPassQuad(pass1
,
1531 SkXfermode::kSrcOver_Mode
);
1532 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1533 1.f
, delegated_render_passes
);
1535 impl
.CalcDrawProps(viewport_size
);
1538 SCOPED_TRACE("No occlusion");
1542 SCOPED_TRACE("Root render pass");
1543 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1545 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1547 ASSERT_EQ(1u, pass1
->quad_list
.size());
1548 EXPECT_EQ(DrawQuad::RENDER_PASS
, pass1
->quad_list
.front()->material
);
1551 SCOPED_TRACE("Contributing render pass");
1552 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1554 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1555 pass2
->quad_list
, gfx::Rect(quad_screen_rect
.size()));
1556 ASSERT_EQ(1u, pass2
->quad_list
.size());
1557 EXPECT_EQ(DrawQuad::SOLID_COLOR
, pass2
->quad_list
.front()->material
);
1562 SCOPED_TRACE("Full occlusion");
1564 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_content_rect());
1566 SCOPED_TRACE("Root render pass");
1567 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1569 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1571 EXPECT_EQ(pass1
->quad_list
.size(), 0u);
1574 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_content_rect());
1576 SCOPED_TRACE("Contributing render pass");
1577 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1579 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass2
->quad_list
,
1581 EXPECT_EQ(pass2
->quad_list
.size(), 0u);
1586 SCOPED_TRACE("Partial occlusion");
1588 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1590 SCOPED_TRACE("Root render pass");
1591 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1592 occlusion_in_root_target
);
1593 size_t partially_occluded_count
= 0;
1594 LayerTestCommon::VerifyQuadsAreOccluded(pass1
->quad_list
,
1595 occlusion_in_root_target
,
1596 &partially_occluded_count
);
1597 // The layer outputs one quad, which is partially occluded.
1598 EXPECT_EQ(1u, pass1
->quad_list
.size());
1599 EXPECT_EQ(1u, partially_occluded_count
);
1602 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1603 // Move the occlusion to where it is in the contributing surface.
1604 gfx::Rect occlusion_in_target_of_delegated_quad
=
1605 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1607 SCOPED_TRACE("Contributing render pass");
1608 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1609 occlusion_in_root_target
);
1610 size_t partially_occluded_count
= 0;
1611 LayerTestCommon::VerifyQuadsAreOccluded(
1612 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1613 &partially_occluded_count
);
1614 // The layer outputs one quad, which is partially occluded.
1615 EXPECT_EQ(1u, pass2
->quad_list
.size());
1616 EXPECT_EQ(1u, partially_occluded_count
);
1617 // The quad in the contributing surface is at (211,300) in the root.
1618 // The occlusion extends to 500 in the x-axis, pushing the left of the
1619 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1620 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1621 pass2
->quad_list
.front()->visible_rect
.ToString());
1624 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1625 // Move the occlusion to where it is in the contributing surface.
1626 gfx::Rect occlusion_in_target_of_delegated_quad
=
1627 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1629 SCOPED_TRACE("Contributing render pass with transformed root");
1631 gfx::Transform layer_transform
;
1632 layer_transform
.Translate(11.0, 0.0);
1633 delegated_renderer_layer_impl
->SetTransform(layer_transform
);
1635 occlusion_in_target_of_delegated_quad
+= gfx::Vector2d(11, 0);
1637 impl
.CalcDrawProps(viewport_size
);
1639 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1640 occlusion_in_root_target
);
1641 size_t partially_occluded_count
= 0;
1642 LayerTestCommon::VerifyQuadsAreOccluded(
1643 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1644 &partially_occluded_count
);
1645 // The layer outputs one quad, which is partially occluded.
1646 EXPECT_EQ(1u, pass2
->quad_list
.size());
1647 EXPECT_EQ(1u, partially_occluded_count
);
1648 // The quad in the contributing surface is at (222,300) in the transformed
1649 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1650 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1651 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1652 pass2
->quad_list
.front()->visible_rect
.ToString());
1657 TEST_F(DelegatedRendererLayerImplTest
, PushPropertiesTo
) {
1658 gfx::Size
layer_size(1000, 1000);
1660 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer_impl
=
1661 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 5);
1662 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1663 delegated_renderer_layer_impl
->SetContentBounds(layer_size
);
1664 delegated_renderer_layer_impl
->SetDrawsContent(true);
1666 RenderPassList delegated_render_passes
;
1667 // |pass1| covers the whole layer.
1668 RenderPassId pass1_id
= RenderPassId(5, 0);
1669 AddRenderPass(&delegated_render_passes
,
1671 gfx::Rect(layer_size
),
1673 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1674 2.f
, delegated_render_passes
);
1675 EXPECT_EQ(0.5f
, delegated_renderer_layer_impl
->inverse_device_scale_factor());
1677 scoped_ptr
<DelegatedRendererLayerImpl
> other_layer
=
1678 DelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 6);
1680 delegated_renderer_layer_impl
->PushPropertiesTo(other_layer
.get());
1682 EXPECT_EQ(0.5f
, other_layer
->inverse_device_scale_factor());