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_impl_proxy.h"
13 #include "cc/test/fake_layer_tree_host_impl.h"
14 #include "cc/test/fake_layer_tree_host_impl_client.h"
15 #include "cc/test/fake_output_surface.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_task_graph_runner.h"
22 #include "cc/test/test_web_graphics_context_3d.h"
23 #include "cc/trees/layer_tree_host_impl.h"
24 #include "cc/trees/layer_tree_impl.h"
25 #include "cc/trees/single_thread_proxy.h"
26 #include "testing/gtest/include/gtest/gtest.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();
40 host_impl_
.reset(new FakeLayerTreeHostImpl(
41 settings
, &proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
));
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 TestTaskGraphRunner task_graph_runner_
;
52 scoped_ptr
<LayerTreeHostImpl
> host_impl_
;
55 class DelegatedRendererLayerImplTestSimple
56 : public DelegatedRendererLayerImplTest
{
58 DelegatedRendererLayerImplTestSimple()
59 : DelegatedRendererLayerImplTest() {
60 scoped_ptr
<LayerImpl
> root_layer
=
61 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 1);
62 scoped_ptr
<LayerImpl
> layer_before
=
63 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 2);
64 scoped_ptr
<LayerImpl
> layer_after
=
65 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 3);
66 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
67 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 4);
69 host_impl_
->SetViewportSize(gfx::Size(100, 100));
70 root_layer
->SetBounds(gfx::Size(100, 100));
71 root_layer
->SetHasRenderSurface(true);
73 layer_before
->SetPosition(gfx::Point(20, 20));
74 layer_before
->SetBounds(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
->SetDrawsContent(true);
81 layer_after
->SetHasRenderSurface(true);
83 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
84 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
85 delegated_renderer_layer
->SetDrawsContent(true);
86 gfx::Transform transform
;
87 transform
.Translate(1.0, 1.0);
88 delegated_renderer_layer
->SetTransform(transform
);
90 RenderPassList delegated_render_passes
;
91 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
93 gfx::Rect(6, 6, 6, 6),
94 gfx::Transform(1, 0, 0, 1, 5, 6));
95 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
96 TestRenderPass
* pass2
= AddRenderPass(&delegated_render_passes
,
98 gfx::Rect(7, 7, 7, 7),
99 gfx::Transform(1, 0, 0, 1, 7, 8));
100 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
101 AddRenderPassQuad(pass2
, pass1
);
102 TestRenderPass
* pass3
= AddRenderPass(&delegated_render_passes
,
104 gfx::Rect(0, 0, 8, 8),
105 gfx::Transform(1, 0, 0, 1, 9, 10));
106 AddRenderPassQuad(pass3
, pass2
);
107 delegated_renderer_layer
->SetFrameDataForRenderPasses(
108 1.f
, delegated_render_passes
);
110 root_layer_
= root_layer
.get();
111 layer_before_
= layer_before
.get();
112 layer_after_
= layer_after
.get();
113 delegated_renderer_layer_
= delegated_renderer_layer
.get();
115 // Force the delegated RenderPasses to come before the RenderPass from
117 layer_after
->AddChild(delegated_renderer_layer
.Pass());
118 root_layer
->AddChild(layer_after
.Pass());
120 // Get the RenderPass generated by layer_before to come before the delegated
122 root_layer
->AddChild(layer_before
.Pass());
123 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
127 LayerImpl
* root_layer_
;
128 LayerImpl
* layer_before_
;
129 LayerImpl
* layer_after_
;
130 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
133 TEST_F(DelegatedRendererLayerImplTest
,
134 ChangeContributingRenderPassForNewFrame
) {
135 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
137 scoped_ptr
<LayerImpl
> root_layer
=
138 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 1);
139 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
140 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
142 host_impl_
->SetViewportSize(gfx::Size(100, 100));
143 root_layer
->SetBounds(gfx::Size(100, 100));
144 root_layer
->SetHasRenderSurface(true);
146 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
147 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
148 delegated_renderer_layer
->SetDrawsContent(true);
149 delegated_renderer_layer
->SetHasRenderSurface(true);
150 gfx::Transform transform
;
151 transform
.Translate(1.0, 1.0);
152 delegated_renderer_layer
->SetTransform(transform
);
154 RenderPassList delegated_render_passes
;
155 TestRenderPass
* pass1
=
156 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
157 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
158 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
159 TestRenderPass
* pass2
=
160 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
161 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
162 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
163 AddRenderPassQuad(pass2
, pass1
);
164 TestRenderPass
* pass3
=
165 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
166 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
167 AddRenderPassQuad(pass3
, pass2
);
168 delegated_renderer_layer
->SetFrameDataForRenderPasses(
169 1.f
, delegated_render_passes
);
171 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
173 root_layer
->AddChild(delegated_renderer_layer
.Pass());
175 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
177 LayerTreeHostImpl::FrameData frame
;
178 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
180 // Root layer has one render pass, and delegated renderer layer has two
181 // contributing render passes and its own render pass.
182 ASSERT_EQ(4u, frame
.render_passes
.size());
184 host_impl_
->DrawLayers(&frame
);
185 host_impl_
->DidDrawAllLayers(frame
);
188 // New frame makes delegated renderer layer loses its contributing render
190 RenderPassList delegated_render_passes
;
191 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
192 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
193 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
194 1.f
, delegated_render_passes
);
196 // Force damage to redraw a new frame.
197 host_impl_
->SetViewportDamage(gfx::Rect(10, 10));
199 LayerTreeHostImpl::FrameData frame
;
200 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
202 // Each non-DelegatedRendererLayer added one RenderPass. The
203 // DelegatedRendererLayer added two contributing passes.
204 ASSERT_EQ(1u, frame
.render_passes
.size());
206 host_impl_
->DrawLayers(&frame
);
207 host_impl_
->DidDrawAllLayers(frame
);
211 TEST_F(DelegatedRendererLayerImplTest
,
212 ChangeContributingRenderPassNonFullTreeSync
) {
213 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
215 host_impl_
->CreatePendingTree();
216 scoped_ptr
<LayerImpl
> root_layer
=
217 SolidColorLayerImpl::Create(host_impl_
->pending_tree(), 1);
218 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
219 FakeDelegatedRendererLayerImpl::Create(host_impl_
->pending_tree(), 2);
221 host_impl_
->SetViewportSize(gfx::Size(100, 100));
222 root_layer
->SetBounds(gfx::Size(100, 100));
223 root_layer
->SetHasRenderSurface(true);
225 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
226 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
227 delegated_renderer_layer
->SetDrawsContent(true);
228 delegated_renderer_layer
->SetHasRenderSurface(true);
229 gfx::Transform transform
;
230 transform
.Translate(1.0, 1.0);
231 delegated_renderer_layer
->SetTransform(transform
);
233 RenderPassList delegated_render_passes
;
234 TestRenderPass
* pass1
=
235 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
236 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
237 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
238 TestRenderPass
* pass2
=
239 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
240 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
241 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
242 AddRenderPassQuad(pass2
, pass1
);
243 TestRenderPass
* pass3
=
244 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
245 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
246 AddRenderPassQuad(pass3
, pass2
);
247 delegated_renderer_layer
->SetFrameDataForRenderPasses(
248 1.f
, delegated_render_passes
);
250 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
252 root_layer
->AddChild(delegated_renderer_layer
.Pass());
254 host_impl_
->pending_tree()->SetRootLayer(root_layer
.Pass());
255 host_impl_
->ActivateSyncTree();
257 LayerTreeHostImpl::FrameData frame
;
258 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
260 // Root layer has one render pass, and delegated renderer layer has two
261 // contributing render passes and its own render pass.
262 ASSERT_EQ(4u, frame
.render_passes
.size());
264 host_impl_
->DrawLayers(&frame
);
265 host_impl_
->DidDrawAllLayers(frame
);
268 // Remove contributing render passes from the delegated renderer layer.
269 host_impl_
->CreatePendingTree();
270 host_impl_
->pending_tree()->set_needs_full_tree_sync(false);
271 RenderPassList delegated_render_passes
;
272 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
273 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
275 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
276 1.f
, delegated_render_passes
);
278 // Force damage to redraw a new frame.
280 host_impl_
->ActivateSyncTree();
281 host_impl_
->SetViewportDamage(gfx::Rect(100, 100));
282 LayerTreeHostImpl::FrameData frame
;
283 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
285 // Root layer has one render pass, and delegated renderer layer no longer
286 // has contributing render passes.
287 ASSERT_EQ(1u, frame
.render_passes
.size());
289 host_impl_
->DrawLayers(&frame
);
290 host_impl_
->DidDrawAllLayers(frame
);
294 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsContributingRenderPasses
) {
295 LayerTreeHostImpl::FrameData frame
;
296 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
298 // Each non-DelegatedRendererLayer added one RenderPass. The
299 // DelegatedRendererLayer added two contributing passes.
300 ASSERT_EQ(5u, frame
.render_passes
.size());
302 // The DelegatedRendererLayer should have added its contributing RenderPasses
304 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
305 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
306 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
307 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
308 // And all other RenderPasses should be non-delegated.
309 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
310 EXPECT_EQ(0u, frame
.render_passes
[0]->id
.index
);
311 EXPECT_NE(4, frame
.render_passes
[3]->id
.layer_id
);
312 EXPECT_EQ(0u, frame
.render_passes
[3]->id
.index
);
313 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
314 EXPECT_EQ(0u, frame
.render_passes
[4]->id
.index
);
316 // The DelegatedRendererLayer should have added its RenderPasses to the frame
318 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
319 frame
.render_passes
[1]->output_rect
.ToString());
320 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
321 frame
.render_passes
[2]->output_rect
.ToString());
323 host_impl_
->DrawLayers(&frame
);
324 host_impl_
->DidDrawAllLayers(frame
);
327 TEST_F(DelegatedRendererLayerImplTestSimple
,
328 AddsQuadsToContributingRenderPasses
) {
329 LayerTreeHostImpl::FrameData frame
;
330 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
332 // Each non-DelegatedRendererLayer added one RenderPass. The
333 // DelegatedRendererLayer added two contributing passes.
334 ASSERT_EQ(5u, frame
.render_passes
.size());
336 // The DelegatedRendererLayer should have added its contributing RenderPasses
338 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
339 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
340 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
341 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
343 // The DelegatedRendererLayer should have added copies of its quads to
344 // contributing RenderPasses.
345 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
346 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
347 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
349 // Verify it added the right quads.
350 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
351 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
352 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
353 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
354 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
355 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
356 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
357 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
359 host_impl_
->DrawLayers(&frame
);
360 host_impl_
->DidDrawAllLayers(frame
);
363 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsQuadsToTargetRenderPass
) {
364 LayerTreeHostImpl::FrameData frame
;
365 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
367 // Each non-DelegatedRendererLayer added one RenderPass. The
368 // DelegatedRendererLayer added two contributing passes.
369 ASSERT_EQ(5u, frame
.render_passes
.size());
371 // The layer's target is the RenderPass from layer_after_.
372 EXPECT_EQ(RenderPassId(3, 0), frame
.render_passes
[3]->id
);
374 // The DelegatedRendererLayer should have added copies of quads in its root
375 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
376 ASSERT_EQ(2u, frame
.render_passes
[3]->quad_list
.size());
378 // Verify it added the right quads.
379 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
380 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
382 // Its target layer should have a quad as well.
383 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
384 frame
.render_passes
[3]->quad_list
.ElementAt(1)->rect
.ToString());
386 host_impl_
->DrawLayers(&frame
);
387 host_impl_
->DidDrawAllLayers(frame
);
390 TEST_F(DelegatedRendererLayerImplTestSimple
,
391 QuadsFromRootRenderPassAreModifiedForTheTarget
) {
392 LayerTreeHostImpl::FrameData frame
;
393 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
395 // Each non-DelegatedRendererLayer added one RenderPass. The
396 // DelegatedRendererLayer added two contributing passes.
397 ASSERT_EQ(5u, frame
.render_passes
.size());
399 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
400 // has a translation transform of 1,1. So its root RenderPass' quads should
401 // all be transformed by that combined amount.
402 gfx::Transform transform
;
403 transform
.Translate(4.0, 4.0);
404 EXPECT_TRANSFORMATION_MATRIX_EQ(
405 transform
, frame
.render_passes
[3]
407 ->shared_quad_state
->quad_to_target_transform
);
409 // Quads from non-root RenderPasses should not be shifted though.
410 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
412 EXPECT_TRANSFORMATION_MATRIX_EQ(
413 gfx::Transform(), frame
.render_passes
[2]
415 ->shared_quad_state
->quad_to_target_transform
);
416 EXPECT_TRANSFORMATION_MATRIX_EQ(
417 gfx::Transform(), frame
.render_passes
[2]
418 ->quad_list
.ElementAt(1)
419 ->shared_quad_state
->quad_to_target_transform
);
420 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
421 EXPECT_TRANSFORMATION_MATRIX_EQ(
422 gfx::Transform(), frame
.render_passes
[1]
424 ->shared_quad_state
->quad_to_target_transform
);
426 host_impl_
->DrawLayers(&frame
);
427 host_impl_
->DidDrawAllLayers(frame
);
430 TEST_F(DelegatedRendererLayerImplTestSimple
, RenderPassTransformIsModified
) {
431 LayerTreeHostImpl::FrameData frame
;
432 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
434 // The delegated layer has a surface between it and the root.
435 EXPECT_TRUE(delegated_renderer_layer_
->render_target()->parent());
437 // Each non-DelegatedRendererLayer added one RenderPass. The
438 // DelegatedRendererLayer added two contributing passes.
439 ASSERT_EQ(5u, frame
.render_passes
.size());
441 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
442 // render pass' transforms to the root should be shifted by this amount.
443 gfx::Transform transform
;
444 transform
.Translate(9.0, 9.0);
446 // The first contributing surface has a translation of 5, 6.
447 gfx::Transform
five_six(1, 0, 0, 1, 5, 6);
449 // The second contributing surface has a translation of 7, 8.
450 gfx::Transform
seven_eight(1, 0, 0, 1, 7, 8);
452 EXPECT_TRANSFORMATION_MATRIX_EQ(
453 transform
* five_six
, frame
.render_passes
[1]->transform_to_root_target
);
454 EXPECT_TRANSFORMATION_MATRIX_EQ(
455 transform
* seven_eight
,
456 frame
.render_passes
[2]->transform_to_root_target
);
458 host_impl_
->DrawLayers(&frame
);
459 host_impl_
->DidDrawAllLayers(frame
);
462 class DelegatedRendererLayerImplTestOwnSurface
463 : public DelegatedRendererLayerImplTestSimple
{
465 DelegatedRendererLayerImplTestOwnSurface()
466 : DelegatedRendererLayerImplTestSimple() {
467 delegated_renderer_layer_
->SetHasRenderSurface(true);
471 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsRenderPasses
) {
472 LayerTreeHostImpl::FrameData frame
;
473 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
475 // Each non-DelegatedRendererLayer added one RenderPass. The
476 // DelegatedRendererLayer added two contributing passes and its owned surface
478 ASSERT_EQ(6u, frame
.render_passes
.size());
480 // The DelegatedRendererLayer should have added its contributing RenderPasses
482 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
483 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
484 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
485 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
486 // The DelegatedRendererLayer should have added a RenderPass for its surface
488 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
489 EXPECT_EQ(0u, frame
.render_passes
[3]->id
.index
);
490 // And all other RenderPasses should be non-delegated.
491 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
492 EXPECT_EQ(0u, frame
.render_passes
[0]->id
.index
);
493 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
494 EXPECT_EQ(0u, frame
.render_passes
[4]->id
.index
);
495 EXPECT_NE(4, frame
.render_passes
[5]->id
.layer_id
);
496 EXPECT_EQ(0u, frame
.render_passes
[5]->id
.index
);
498 // The DelegatedRendererLayer should have added its RenderPasses to the frame
500 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
501 frame
.render_passes
[1]->output_rect
.ToString());
502 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
503 frame
.render_passes
[2]->output_rect
.ToString());
505 host_impl_
->DrawLayers(&frame
);
506 host_impl_
->DidDrawAllLayers(frame
);
509 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
510 AddsQuadsToContributingRenderPasses
) {
511 LayerTreeHostImpl::FrameData frame
;
512 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
514 // Each non-DelegatedRendererLayer added one RenderPass. The
515 // DelegatedRendererLayer added two contributing passes and its owned surface
517 ASSERT_EQ(6u, frame
.render_passes
.size());
519 // The DelegatedRendererLayer should have added its contributing RenderPasses
521 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
522 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
523 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
524 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
526 // The DelegatedRendererLayer should have added copies of its quads to
527 // contributing RenderPasses.
528 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
529 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
530 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
532 // Verify it added the right quads.
533 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
535 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
536 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
537 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
538 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
539 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
540 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
541 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
543 host_impl_
->DrawLayers(&frame
);
544 host_impl_
->DidDrawAllLayers(frame
);
547 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsQuadsToTargetRenderPass
) {
548 LayerTreeHostImpl::FrameData frame
;
549 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
551 // Each non-DelegatedRendererLayer added one RenderPass. The
552 // DelegatedRendererLayer added two contributing passes and its owned surface
554 ASSERT_EQ(6u, frame
.render_passes
.size());
556 // The layer's target is the RenderPass owned by itself.
557 EXPECT_EQ(RenderPassId(4, 0), frame
.render_passes
[3]->id
);
559 // The DelegatedRendererLayer should have added copies of quads in its root
560 // RenderPass to its target RenderPass.
561 // The layer_after also adds one quad.
562 ASSERT_EQ(1u, frame
.render_passes
[3]->quad_list
.size());
564 // Verify it added the right quads.
565 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
566 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
568 host_impl_
->DrawLayers(&frame
);
569 host_impl_
->DidDrawAllLayers(frame
);
572 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
573 QuadsFromRootRenderPassAreNotModifiedForTheTarget
) {
574 LayerTreeHostImpl::FrameData frame
;
575 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
577 // Each non-DelegatedRendererLayer added one RenderPass. The
578 // DelegatedRendererLayer added two contributing passes and its owned surface
580 ASSERT_EQ(6u, frame
.render_passes
.size());
582 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
583 // RenderPass' quads do not need to be translated at all.
584 EXPECT_TRANSFORMATION_MATRIX_EQ(
585 gfx::Transform(), frame
.render_passes
[3]
587 ->shared_quad_state
->quad_to_target_transform
);
589 // Quads from non-root RenderPasses should not be shifted either.
590 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
592 EXPECT_TRANSFORMATION_MATRIX_EQ(
593 gfx::Transform(), frame
.render_passes
[2]
595 ->shared_quad_state
->quad_to_target_transform
);
596 EXPECT_TRANSFORMATION_MATRIX_EQ(
597 gfx::Transform(), frame
.render_passes
[2]
598 ->quad_list
.ElementAt(1)
599 ->shared_quad_state
->quad_to_target_transform
);
600 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
601 EXPECT_TRANSFORMATION_MATRIX_EQ(
602 gfx::Transform(), frame
.render_passes
[1]
604 ->shared_quad_state
->quad_to_target_transform
);
606 host_impl_
->DrawLayers(&frame
);
607 host_impl_
->DidDrawAllLayers(frame
);
610 class DelegatedRendererLayerImplTestTransform
611 : public DelegatedRendererLayerImplTest
{
613 DelegatedRendererLayerImplTestTransform()
614 : root_delegated_render_pass_is_clipped_(false),
615 delegated_device_scale_factor_(2.f
) {}
618 host_impl_
->SetDeviceScaleFactor(2.f
);
620 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::Create(
621 host_impl_
->active_tree(), 1);
622 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
623 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
625 host_impl_
->SetViewportSize(gfx::Size(200, 200));
626 root_layer
->SetBounds(gfx::Size(100, 100));
627 root_layer
->SetHasRenderSurface(true);
629 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
630 delegated_renderer_layer
->SetBounds(gfx::Size(75, 75));
631 delegated_renderer_layer
->SetDrawsContent(true);
632 gfx::Transform transform
;
633 transform
.Scale(2.0, 2.0);
634 transform
.Translate(8.0, 8.0);
635 delegated_renderer_layer
->SetTransform(transform
);
637 RenderPassList delegated_render_passes
;
639 gfx::Size
child_pass_bounds(7, 7);
640 gfx::Rect
child_pass_rect(20, 20, 7, 7);
641 gfx::Transform child_pass_transform
;
642 child_pass_transform
.Scale(0.8f
, 0.8f
);
643 child_pass_transform
.Translate(9.0, 9.0);
644 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
645 bool child_pass_clipped
= false;
648 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
652 SharedQuadState
* shared_quad_state
=
653 pass
->CreateAndAppendSharedQuadState();
654 shared_quad_state
->SetAll(child_pass_transform
, child_pass_bounds
,
655 child_pass_rect
, child_pass_clip_rect
,
656 child_pass_clipped
, 1.f
,
657 SkXfermode::kSrcOver_Mode
, 0);
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_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
, root_pass_bounds
,
689 root_pass_rect
, root_pass_clip_rect
,
690 root_pass_clipped
, 1.f
, SkXfermode::kSrcOver_Mode
,
693 RenderPassDrawQuad
* render_pass_quad
=
694 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
695 render_pass_quad
->SetNew(shared_quad_state
,
696 gfx::Rect(5, 5, 7, 7), // quad_rect
697 gfx::Rect(5, 5, 7, 7), // visible_rect
698 RenderPassId(10, 7), // render_pass_id
699 0, // mask_resource_id
700 gfx::Vector2dF(), // mask_uv_scale
701 gfx::Size(), // mask_texture_size
702 FilterOperations(), // filters
703 gfx::Vector2dF(), // filters_scale
704 FilterOperations()); // background_filters
706 SolidColorDrawQuad
* color_quad
;
707 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
708 color_quad
->SetNew(shared_quad_state
,
709 gfx::Rect(0, 0, 10, 10),
710 gfx::Rect(0, 0, 10, 10),
714 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
715 color_quad
->SetNew(shared_quad_state
,
716 gfx::Rect(0, 10, 10, 10),
717 gfx::Rect(0, 10, 10, 10),
721 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
722 color_quad
->SetNew(shared_quad_state
,
723 gfx::Rect(10, 0, 10, 10),
724 gfx::Rect(10, 0, 10, 10),
728 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
729 color_quad
->SetNew(shared_quad_state
,
730 gfx::Rect(10, 10, 10, 10),
731 gfx::Rect(10, 10, 10, 10),
735 delegated_renderer_layer
->SetFrameDataForRenderPasses(
736 delegated_device_scale_factor_
, delegated_render_passes
);
738 root_layer_
= root_layer
.get();
739 delegated_renderer_layer_
= delegated_renderer_layer
.get();
741 root_layer
->AddChild(delegated_renderer_layer
.Pass());
742 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
745 void VerifyRenderPasses(
746 const LayerTreeHostImpl::FrameData
& frame
,
747 size_t num_render_passes
,
748 const SharedQuadState
** root_delegated_shared_quad_state
,
749 const SharedQuadState
** contrib_delegated_shared_quad_state
) {
750 ASSERT_EQ(num_render_passes
, frame
.render_passes
.size());
751 // The contributing render pass in the DelegatedRendererLayer.
752 EXPECT_EQ(2, frame
.render_passes
[0]->id
.layer_id
);
753 EXPECT_EQ(1u, frame
.render_passes
[0]->id
.index
);
754 // The root render pass.
755 EXPECT_EQ(1, frame
.render_passes
.back()->id
.layer_id
);
756 EXPECT_EQ(0u, frame
.render_passes
.back()->id
.index
);
758 const QuadList
& contrib_delegated_quad_list
=
759 frame
.render_passes
[0]->quad_list
;
760 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
762 const QuadList
& root_delegated_quad_list
=
763 frame
.render_passes
[1]->quad_list
;
764 ASSERT_EQ(5u, root_delegated_quad_list
.size());
766 // All quads in a render pass should share the same state.
767 *contrib_delegated_shared_quad_state
=
768 contrib_delegated_quad_list
.front()->shared_quad_state
;
769 EXPECT_EQ(*contrib_delegated_shared_quad_state
,
770 contrib_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
772 *root_delegated_shared_quad_state
=
773 root_delegated_quad_list
.front()->shared_quad_state
;
774 EXPECT_EQ(*root_delegated_shared_quad_state
,
775 root_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
776 EXPECT_EQ(*root_delegated_shared_quad_state
,
777 root_delegated_quad_list
.ElementAt(2)->shared_quad_state
);
778 EXPECT_EQ(*root_delegated_shared_quad_state
,
779 root_delegated_quad_list
.ElementAt(3)->shared_quad_state
);
780 EXPECT_EQ(*root_delegated_shared_quad_state
,
781 root_delegated_quad_list
.ElementAt(4)->shared_quad_state
);
783 EXPECT_NE(*contrib_delegated_shared_quad_state
,
784 *root_delegated_shared_quad_state
);
788 LayerImpl
* root_layer_
;
789 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
790 bool root_delegated_render_pass_is_clipped_
;
791 float delegated_device_scale_factor_
;
794 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_NoSurface
) {
795 root_delegated_render_pass_is_clipped_
= false;
798 LayerTreeHostImpl::FrameData frame
;
799 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
801 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
802 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
806 &root_delegated_shared_quad_state
,
807 &contrib_delegated_shared_quad_state
);
809 // When the quads don't have a clip of their own, the clip rect is set to
810 // the drawable_content_rect of the delegated renderer layer.
811 EXPECT_EQ(delegated_renderer_layer_
->drawable_content_rect().ToString(),
812 root_delegated_shared_quad_state
->clip_rect
.ToString());
814 // Even though the quads in the root pass have no clip of their own, they
815 // inherit the clip rect from the delegated renderer layer if it does not
817 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
819 gfx::Transform expected
;
820 // Device scale factor.
821 expected
.Scale(2.0, 2.0);
822 // This is the transform from the layer's space to its target.
823 expected
.Translate(20, 20);
824 expected
.Scale(2.0, 2.0);
825 expected
.Translate(8.0, 8.0);
826 // This is the transform within the source frame.
827 // Inverse device scale factor to go from physical space to layer space.
828 expected
.Scale(0.5, 0.5);
829 expected
.Scale(1.5, 1.5);
830 expected
.Translate(7.0, 7.0);
831 EXPECT_TRANSFORMATION_MATRIX_EQ(
832 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
834 // The contributing render pass should not be transformed from its input.
835 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
836 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
837 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
838 expected
.MakeIdentity();
839 expected
.Scale(0.8f
, 0.8f
);
840 expected
.Translate(9.0, 9.0);
841 EXPECT_TRANSFORMATION_MATRIX_EQ(
842 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
844 host_impl_
->DrawLayers(&frame
);
845 host_impl_
->DidDrawAllLayers(frame
);
848 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_NoSurface
) {
849 root_delegated_render_pass_is_clipped_
= true;
852 LayerTreeHostImpl::FrameData frame
;
853 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
855 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
856 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
860 &root_delegated_shared_quad_state
,
861 &contrib_delegated_shared_quad_state
);
863 // Since the quads have a clip_rect it should be modified by delegated
864 // renderer layer's draw_transform.
865 // The position of the resulting clip_rect is:
866 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
867 // layer scale (2) + layer position (20) = 46
868 // The device scale is 2, so everything gets doubled, giving 92.
870 // The size is 35x35 scaled by the device scale.
871 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
872 root_delegated_shared_quad_state
->clip_rect
.ToString());
874 // The quads had a clip and it should be preserved.
875 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
877 gfx::Transform expected
;
878 // Device scale factor.
879 expected
.Scale(2.0, 2.0);
880 // This is the transform from the layer's space to its target.
881 expected
.Translate(20, 20);
882 expected
.Scale(2.0, 2.0);
883 expected
.Translate(8.0, 8.0);
884 // This is the transform within the source frame.
885 // Inverse device scale factor to go from physical space to layer space.
886 expected
.Scale(0.5, 0.5);
887 expected
.Scale(1.5, 1.5);
888 expected
.Translate(7.0, 7.0);
889 EXPECT_TRANSFORMATION_MATRIX_EQ(
890 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
892 // The contributing render pass should not be transformed from its input.
893 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
894 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
895 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
896 expected
.MakeIdentity();
897 expected
.Scale(0.8f
, 0.8f
);
898 expected
.Translate(9.0, 9.0);
899 EXPECT_TRANSFORMATION_MATRIX_EQ(
900 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
902 host_impl_
->DrawLayers(&frame
);
903 host_impl_
->DidDrawAllLayers(frame
);
906 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_Surface
) {
907 root_delegated_render_pass_is_clipped_
= false;
910 delegated_renderer_layer_
->SetHasRenderSurface(true);
912 LayerTreeHostImpl::FrameData frame
;
913 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
915 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
916 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
920 &root_delegated_shared_quad_state
,
921 &contrib_delegated_shared_quad_state
);
923 // When the layer owns a surface, then its translation is not part of its
924 // draw transform, but its scale is.
925 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
926 root_delegated_shared_quad_state
->clip_rect
.ToString());
928 // Since the layer owns a surface it doesn't need to clip its quads, so
929 // unclipped quads remain unclipped.
930 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
932 gfx::Transform expected
;
933 // This is the transform within the source frame scaled by the delegated
934 // render layer transform.
935 expected
.Scale(3.0, 3.0);
936 expected
.Translate(7.0, 7.0);
937 EXPECT_TRANSFORMATION_MATRIX_EQ(
938 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
940 // The contributing render pass should not be transformed from its input.
941 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
942 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
943 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
944 expected
.MakeIdentity();
945 expected
.Scale(0.8f
, 0.8f
);
946 expected
.Translate(9.0, 9.0);
947 EXPECT_TRANSFORMATION_MATRIX_EQ(
948 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
950 host_impl_
->DrawLayers(&frame
);
951 host_impl_
->DidDrawAllLayers(frame
);
954 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_Surface
) {
955 root_delegated_render_pass_is_clipped_
= true;
958 delegated_renderer_layer_
->SetHasRenderSurface(true);
960 LayerTreeHostImpl::FrameData frame
;
961 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
963 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
964 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
968 &root_delegated_shared_quad_state
,
969 &contrib_delegated_shared_quad_state
);
971 // When the layer owns a surface, then its translation is not part of its
972 // draw transform, but its scale is.
973 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
974 root_delegated_shared_quad_state
->clip_rect
.ToString());
976 // The quads had a clip and it should be preserved.
977 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
979 gfx::Transform expected
;
980 // This is the transform within the source frame scaled by the delegated
981 // render layer transform.
982 expected
.Scale(3.0, 3.0);
983 expected
.Translate(7.0, 7.0);
984 EXPECT_TRANSFORMATION_MATRIX_EQ(
985 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
987 // The contributing render pass should not be transformed from its input.
988 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
989 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
990 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
991 expected
.MakeIdentity();
992 expected
.Scale(0.8f
, 0.8f
);
993 expected
.Translate(9.0, 9.0);
994 EXPECT_TRANSFORMATION_MATRIX_EQ(
995 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
997 host_impl_
->DrawLayers(&frame
);
998 host_impl_
->DidDrawAllLayers(frame
);
1001 TEST_F(DelegatedRendererLayerImplTestTransform
, MismatchedDeviceScaleFactor
) {
1002 root_delegated_render_pass_is_clipped_
= true;
1003 delegated_device_scale_factor_
= 1.3f
;
1007 LayerTreeHostImpl::FrameData frame
;
1008 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1010 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
1011 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
1012 VerifyRenderPasses(frame
,
1014 &root_delegated_shared_quad_state
,
1015 &contrib_delegated_shared_quad_state
);
1017 // The parent tree's device scale factor is 2.0, but the child has submitted a
1018 // frame with a device scale factor of 1.3. Absent any better option, the
1019 // only thing we can do is scale from 1.3 -> 2.0.
1021 gfx::Transform expected
;
1022 // Device scale factor (from parent).
1023 expected
.Scale(2.0, 2.0);
1024 // This is the transform from the layer's space to its target.
1025 expected
.Translate(20, 20);
1026 expected
.Scale(2.0, 2.0);
1027 expected
.Translate(8.0, 8.0);
1028 // This is the transform within the source frame.
1029 // Inverse device scale factor (from child).
1030 expected
.Scale(1.0f
/ 1.3f
, 1.0f
/ 1.3f
);
1031 expected
.Scale(1.5, 1.5);
1032 expected
.Translate(7.0, 7.0);
1033 EXPECT_TRANSFORMATION_MATRIX_EQ(
1034 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
1036 host_impl_
->DrawLayers(&frame
);
1037 host_impl_
->DidDrawAllLayers(frame
);
1040 class DelegatedRendererLayerImplTestClip
1041 : public DelegatedRendererLayerImplTest
{
1044 scoped_ptr
<LayerImpl
> root_layer
=
1045 LayerImpl::Create(host_impl_
->active_tree(), 1);
1046 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
1047 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
1048 scoped_ptr
<LayerImpl
> clip_layer
=
1049 LayerImpl::Create(host_impl_
->active_tree(), 3);
1050 scoped_ptr
<LayerImpl
> origin_layer
=
1051 LayerImpl::Create(host_impl_
->active_tree(), 4);
1053 host_impl_
->SetViewportSize(gfx::Size(100, 100));
1054 root_layer
->SetBounds(gfx::Size(100, 100));
1055 root_layer
->SetHasRenderSurface(true);
1057 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
1058 delegated_renderer_layer
->SetBounds(gfx::Size(50, 50));
1059 delegated_renderer_layer
->SetDrawsContent(true);
1061 RenderPassList delegated_render_passes
;
1063 gfx::Size
child_pass_bounds(7, 7);
1064 gfx::Rect
child_pass_rect(20, 20, 7, 7);
1065 gfx::Transform child_pass_transform
;
1066 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
1067 bool child_pass_clipped
= false;
1070 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
1071 RenderPassId(10, 7),
1074 SharedQuadState
* shared_quad_state
=
1075 pass
->CreateAndAppendSharedQuadState();
1076 shared_quad_state
->SetAll(child_pass_transform
, child_pass_bounds
,
1077 child_pass_rect
, child_pass_clip_rect
,
1078 child_pass_clipped
, 1.f
,
1079 SkXfermode::kSrcOver_Mode
, 0);
1081 SolidColorDrawQuad
* color_quad
;
1082 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1083 color_quad
->SetNew(shared_quad_state
,
1084 gfx::Rect(20, 20, 3, 7),
1085 gfx::Rect(20, 20, 3, 7),
1089 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1090 color_quad
->SetNew(shared_quad_state
,
1091 gfx::Rect(23, 20, 4, 7),
1092 gfx::Rect(23, 20, 4, 7),
1097 gfx::Size
root_pass_bounds(50, 50);
1098 gfx::Rect
root_pass_rect(0, 0, 50, 50);
1099 gfx::Transform root_pass_transform
;
1100 gfx::Rect
root_pass_clip_rect(5, 5, 40, 40);
1101 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
1103 TestRenderPass
* pass
= AddRenderPass(&delegated_render_passes
,
1107 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
1108 shared_quad_state
->SetAll(root_pass_transform
, root_pass_bounds
,
1109 root_pass_rect
, root_pass_clip_rect
,
1110 root_pass_clipped
, 1.f
, SkXfermode::kSrcOver_Mode
,
1113 RenderPassDrawQuad
* render_pass_quad
=
1114 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1115 render_pass_quad
->SetNew(shared_quad_state
,
1116 gfx::Rect(5, 5, 7, 7), // quad_rect
1117 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1118 RenderPassId(10, 7), // render_pass_id
1119 0, // mask_resource_id
1120 gfx::Vector2dF(), // mask_uv_scale
1121 gfx::Size(), // mask_texture_size,
1122 FilterOperations(), // filters
1123 gfx::Vector2dF(), // filters_scale
1124 FilterOperations()); // background_filters
1126 SolidColorDrawQuad
* color_quad
;
1127 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1128 color_quad
->SetNew(shared_quad_state
,
1129 gfx::Rect(0, 0, 10, 10),
1130 gfx::Rect(0, 0, 10, 10),
1134 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1135 color_quad
->SetNew(shared_quad_state
,
1136 gfx::Rect(0, 10, 10, 10),
1137 gfx::Rect(0, 10, 10, 10),
1141 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1142 color_quad
->SetNew(shared_quad_state
,
1143 gfx::Rect(10, 0, 10, 10),
1144 gfx::Rect(10, 0, 10, 10),
1148 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1149 color_quad
->SetNew(shared_quad_state
,
1150 gfx::Rect(10, 10, 10, 10),
1151 gfx::Rect(10, 10, 10, 10),
1155 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1156 1.f
, delegated_render_passes
);
1158 root_layer_
= root_layer
.get();
1159 delegated_renderer_layer_
= delegated_renderer_layer
.get();
1161 if (clip_delegated_renderer_layer_
) {
1162 gfx::Rect
clip_rect(21, 27, 23, 21);
1164 clip_layer
->SetPosition(clip_rect
.origin());
1165 clip_layer
->SetBounds(clip_rect
.size());
1166 clip_layer
->SetMasksToBounds(true);
1168 origin_layer
->SetPosition(
1169 gfx::PointAtOffsetFromOrigin(-clip_rect
.OffsetFromOrigin()));
1171 origin_layer
->AddChild(delegated_renderer_layer
.Pass());
1172 clip_layer
->AddChild(origin_layer
.Pass());
1173 root_layer
->AddChild(clip_layer
.Pass());
1175 root_layer
->AddChild(delegated_renderer_layer
.Pass());
1178 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1182 LayerImpl
* root_layer_
;
1183 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
1184 bool root_delegated_render_pass_is_clipped_
;
1185 bool clip_delegated_renderer_layer_
;
1188 TEST_F(DelegatedRendererLayerImplTestClip
,
1189 QuadsUnclipped_LayerUnclipped_NoSurface
) {
1190 root_delegated_render_pass_is_clipped_
= false;
1191 clip_delegated_renderer_layer_
= false;
1194 LayerTreeHostImpl::FrameData frame
;
1195 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1197 ASSERT_EQ(2u, frame
.render_passes
.size());
1198 const QuadList
& contrib_delegated_quad_list
=
1199 frame
.render_passes
[0]->quad_list
;
1200 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1201 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1202 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1203 const SharedQuadState
* root_delegated_shared_quad_state
=
1204 root_delegated_quad_list
.front()->shared_quad_state
;
1206 // When the quads don't have a clip of their own, the clip rect is set to
1207 // the drawable_content_rect of the delegated renderer layer.
1208 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1209 root_delegated_shared_quad_state
->clip_rect
.ToString());
1210 // Quads are clipped to the delegated renderer layer.
1211 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1213 host_impl_
->DrawLayers(&frame
);
1214 host_impl_
->DidDrawAllLayers(frame
);
1217 TEST_F(DelegatedRendererLayerImplTestClip
,
1218 QuadsClipped_LayerUnclipped_NoSurface
) {
1219 root_delegated_render_pass_is_clipped_
= true;
1220 clip_delegated_renderer_layer_
= false;
1223 LayerTreeHostImpl::FrameData frame
;
1224 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1226 ASSERT_EQ(2u, frame
.render_passes
.size());
1227 const QuadList
& contrib_delegated_quad_list
=
1228 frame
.render_passes
[0]->quad_list
;
1229 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1230 const QuadList
& root_delegated_quad_list
=
1231 frame
.render_passes
[1]->quad_list
;
1232 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1233 const SharedQuadState
* root_delegated_shared_quad_state
=
1234 root_delegated_quad_list
.front()->shared_quad_state
;
1236 // When the quads have a clip of their own, it is used.
1237 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1238 root_delegated_shared_quad_state
->clip_rect
.ToString());
1239 // Quads came with a clip rect.
1240 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1242 host_impl_
->DrawLayers(&frame
);
1243 host_impl_
->DidDrawAllLayers(frame
);
1246 TEST_F(DelegatedRendererLayerImplTestClip
,
1247 QuadsUnclipped_LayerClipped_NoSurface
) {
1248 root_delegated_render_pass_is_clipped_
= false;
1249 clip_delegated_renderer_layer_
= true;
1252 LayerTreeHostImpl::FrameData frame
;
1253 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1254 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1256 ASSERT_EQ(2u, frame
.render_passes
.size());
1257 const QuadList
& contrib_delegated_quad_list
=
1258 frame
.render_passes
[0]->quad_list
;
1259 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1260 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1261 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1262 const SharedQuadState
* root_delegated_shared_quad_state
=
1263 root_delegated_quad_list
.front()->shared_quad_state
;
1265 // When the quads don't have a clip of their own, the clip rect is set to
1266 // the drawable_content_rect of the delegated renderer layer. When the layer
1267 // is clipped, that should be seen in the quads' clip_rect.
1268 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1269 root_delegated_shared_quad_state
->clip_rect
.ToString());
1270 // Quads are clipped to the delegated renderer layer.
1271 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1273 host_impl_
->DrawLayers(&frame
);
1274 host_impl_
->DidDrawAllLayers(frame
);
1277 TEST_F(DelegatedRendererLayerImplTestClip
,
1278 QuadsClipped_LayerClipped_NoSurface
) {
1279 root_delegated_render_pass_is_clipped_
= true;
1280 clip_delegated_renderer_layer_
= true;
1283 LayerTreeHostImpl::FrameData frame
;
1284 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1285 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1287 ASSERT_EQ(2u, frame
.render_passes
.size());
1288 const QuadList
& contrib_delegated_quad_list
=
1289 frame
.render_passes
[0]->quad_list
;
1290 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1291 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1292 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1293 const SharedQuadState
* root_delegated_shared_quad_state
=
1294 root_delegated_quad_list
.front()->shared_quad_state
;
1296 // When the quads have a clip of their own, it is used, but it is
1297 // combined with the clip rect of the delegated renderer layer.
1298 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1299 root_delegated_shared_quad_state
->clip_rect
.ToString());
1300 // Quads came with a clip rect.
1301 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1303 host_impl_
->DrawLayers(&frame
);
1304 host_impl_
->DidDrawAllLayers(frame
);
1307 TEST_F(DelegatedRendererLayerImplTestClip
,
1308 QuadsUnclipped_LayerUnclipped_Surface
) {
1309 root_delegated_render_pass_is_clipped_
= false;
1310 clip_delegated_renderer_layer_
= false;
1313 delegated_renderer_layer_
->SetHasRenderSurface(true);
1315 LayerTreeHostImpl::FrameData frame
;
1316 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1318 ASSERT_EQ(3u, frame
.render_passes
.size());
1319 const QuadList
& contrib_delegated_quad_list
=
1320 frame
.render_passes
[0]->quad_list
;
1321 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1322 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1323 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1324 const SharedQuadState
* root_delegated_shared_quad_state
=
1325 root_delegated_quad_list
.front()->shared_quad_state
;
1327 // When the layer owns a surface, the quads don't need to be clipped
1328 // further than they already specify. If they aren't clipped, then their
1329 // clip rect is ignored, and they are not set as clipped.
1330 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1332 host_impl_
->DrawLayers(&frame
);
1333 host_impl_
->DidDrawAllLayers(frame
);
1336 TEST_F(DelegatedRendererLayerImplTestClip
,
1337 QuadsClipped_LayerUnclipped_Surface
) {
1338 root_delegated_render_pass_is_clipped_
= true;
1339 clip_delegated_renderer_layer_
= false;
1342 delegated_renderer_layer_
->SetHasRenderSurface(true);
1344 LayerTreeHostImpl::FrameData frame
;
1345 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1347 ASSERT_EQ(3u, frame
.render_passes
.size());
1348 const QuadList
& contrib_delegated_quad_list
=
1349 frame
.render_passes
[0]->quad_list
;
1350 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1351 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1352 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1353 const SharedQuadState
* root_delegated_shared_quad_state
=
1354 root_delegated_quad_list
.front()->shared_quad_state
;
1356 // When the quads have a clip of their own, it is used.
1357 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1358 root_delegated_shared_quad_state
->clip_rect
.ToString());
1359 // Quads came with a clip rect.
1360 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1362 host_impl_
->DrawLayers(&frame
);
1363 host_impl_
->DidDrawAllLayers(frame
);
1366 TEST_F(DelegatedRendererLayerImplTestClip
,
1367 QuadsUnclipped_LayerClipped_Surface
) {
1368 root_delegated_render_pass_is_clipped_
= false;
1369 clip_delegated_renderer_layer_
= true;
1372 delegated_renderer_layer_
->SetHasRenderSurface(true);
1374 LayerTreeHostImpl::FrameData frame
;
1375 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1376 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1378 ASSERT_EQ(3u, frame
.render_passes
.size());
1379 const QuadList
& contrib_delegated_quad_list
=
1380 frame
.render_passes
[0]->quad_list
;
1381 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1382 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1383 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1384 const SharedQuadState
* root_delegated_shared_quad_state
=
1385 root_delegated_quad_list
.front()->shared_quad_state
;
1387 // When the layer owns a surface, the quads don't need to be clipped
1388 // further than they already specify. If they aren't clipped, then their
1389 // clip rect is ignored, and they are not set as clipped.
1390 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1392 host_impl_
->DrawLayers(&frame
);
1393 host_impl_
->DidDrawAllLayers(frame
);
1396 TEST_F(DelegatedRendererLayerImplTestClip
, QuadsClipped_LayerClipped_Surface
) {
1397 root_delegated_render_pass_is_clipped_
= true;
1398 clip_delegated_renderer_layer_
= true;
1401 delegated_renderer_layer_
->SetHasRenderSurface(true);
1403 LayerTreeHostImpl::FrameData frame
;
1404 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1405 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1407 ASSERT_EQ(3u, frame
.render_passes
.size());
1408 const QuadList
& contrib_delegated_quad_list
=
1409 frame
.render_passes
[0]->quad_list
;
1410 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1411 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1412 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1413 const SharedQuadState
* root_delegated_shared_quad_state
=
1414 root_delegated_quad_list
.front()->shared_quad_state
;
1416 // When the quads have a clip of their own, it is used, but it is
1417 // combined with the clip rect of the delegated renderer layer. If the
1418 // layer owns a surface, then it does not have a clip rect of its own.
1419 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1420 root_delegated_shared_quad_state
->clip_rect
.ToString());
1421 // Quads came with a clip rect.
1422 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1424 host_impl_
->DrawLayers(&frame
);
1425 host_impl_
->DidDrawAllLayers(frame
);
1428 TEST_F(DelegatedRendererLayerImplTest
, Occlusion
) {
1429 gfx::Size
layer_size(1000, 1000);
1430 gfx::Size
viewport_size(1000, 1000);
1431 gfx::Rect
quad_screen_rect(211, 300, 400, 500);
1433 gfx::Transform transform
;
1434 transform
.Translate(211.0, 300.0);
1436 LayerTestCommon::LayerImplTest impl
;
1438 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1439 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1440 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1441 delegated_renderer_layer_impl
->SetDrawsContent(true);
1443 // Contributing render pass is offset by a transform and holds a quad that
1444 // covers it entirely.
1445 RenderPassList delegated_render_passes
;
1446 // pass2 is just the size of the quad. It contributes to |pass1| with a
1447 // translation of (211,300).
1448 RenderPassId pass2_id
=
1449 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1450 TestRenderPass
* pass2
= AddRenderPass(&delegated_render_passes
,
1452 gfx::Rect(quad_screen_rect
.size()),
1454 AddQuad(pass2
, gfx::Rect(quad_screen_rect
.size()), SK_ColorRED
);
1455 // |pass1| covers the whole layer.
1456 RenderPassId pass1_id
= RenderPassId(impl
.root_layer()->id(), 0);
1457 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
1459 gfx::Rect(layer_size
),
1461 AddRenderPassQuad(pass1
,
1466 SkXfermode::kSrcOver_Mode
);
1467 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1468 1.f
, delegated_render_passes
);
1470 impl
.CalcDrawProps(viewport_size
);
1473 SCOPED_TRACE("No occlusion");
1477 SCOPED_TRACE("Root render pass");
1478 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1480 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1482 ASSERT_EQ(1u, pass1
->quad_list
.size());
1483 EXPECT_EQ(DrawQuad::RENDER_PASS
, pass1
->quad_list
.front()->material
);
1486 SCOPED_TRACE("Contributing render pass");
1487 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1489 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1490 pass2
->quad_list
, gfx::Rect(quad_screen_rect
.size()));
1491 ASSERT_EQ(1u, pass2
->quad_list
.size());
1492 EXPECT_EQ(DrawQuad::SOLID_COLOR
, pass2
->quad_list
.front()->material
);
1497 SCOPED_TRACE("Full occlusion");
1499 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_layer_rect());
1501 SCOPED_TRACE("Root render pass");
1502 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1504 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1506 EXPECT_EQ(pass1
->quad_list
.size(), 0u);
1509 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_layer_rect());
1511 SCOPED_TRACE("Contributing render pass");
1512 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1514 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass2
->quad_list
,
1516 EXPECT_EQ(pass2
->quad_list
.size(), 0u);
1521 SCOPED_TRACE("Partial occlusion");
1523 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1525 SCOPED_TRACE("Root render pass");
1526 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1527 occlusion_in_root_target
);
1528 size_t partially_occluded_count
= 0;
1529 LayerTestCommon::VerifyQuadsAreOccluded(pass1
->quad_list
,
1530 occlusion_in_root_target
,
1531 &partially_occluded_count
);
1532 // The layer outputs one quad, which is partially occluded.
1533 EXPECT_EQ(1u, pass1
->quad_list
.size());
1534 EXPECT_EQ(1u, partially_occluded_count
);
1537 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1538 // Move the occlusion to where it is in the contributing surface.
1539 gfx::Rect occlusion_in_target_of_delegated_quad
=
1540 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1542 SCOPED_TRACE("Contributing render pass");
1543 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1544 occlusion_in_root_target
);
1545 size_t partially_occluded_count
= 0;
1546 LayerTestCommon::VerifyQuadsAreOccluded(
1547 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1548 &partially_occluded_count
);
1549 // The layer outputs one quad, which is partially occluded.
1550 EXPECT_EQ(1u, pass2
->quad_list
.size());
1551 EXPECT_EQ(1u, partially_occluded_count
);
1552 // The quad in the contributing surface is at (211,300) in the root.
1553 // The occlusion extends to 500 in the x-axis, pushing the left of the
1554 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1555 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1556 pass2
->quad_list
.front()->visible_rect
.ToString());
1559 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1560 // Move the occlusion to where it is in the contributing surface.
1561 gfx::Rect occlusion_in_target_of_delegated_quad
=
1562 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1564 SCOPED_TRACE("Contributing render pass with transformed root");
1566 gfx::Transform layer_transform
;
1567 layer_transform
.Translate(11.0, 0.0);
1568 delegated_renderer_layer_impl
->SetTransform(layer_transform
);
1569 delegated_renderer_layer_impl
->layer_tree_impl()
1571 ->needs_rebuild
= true;
1573 occlusion_in_target_of_delegated_quad
+= gfx::Vector2d(11, 0);
1575 impl
.CalcDrawProps(viewport_size
);
1577 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1578 occlusion_in_root_target
);
1579 size_t partially_occluded_count
= 0;
1580 LayerTestCommon::VerifyQuadsAreOccluded(
1581 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1582 &partially_occluded_count
);
1583 // The layer outputs one quad, which is partially occluded.
1584 EXPECT_EQ(1u, pass2
->quad_list
.size());
1585 EXPECT_EQ(1u, partially_occluded_count
);
1586 // The quad in the contributing surface is at (222,300) in the transformed
1587 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1588 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1589 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1590 pass2
->quad_list
.front()->visible_rect
.ToString());
1595 TEST_F(DelegatedRendererLayerImplTest
, DeviceScaleFactorOcclusion
) {
1596 gfx::Size
layer_size(1000, 1000);
1597 gfx::Size
viewport_size(1000, 1000);
1598 gfx::Rect
quad_screen_rect(211, 300, 400, 500);
1600 gfx::Transform transform
;
1601 transform
.Translate(211.f
, 300.f
);
1603 LayerTestCommon::LayerImplTest impl
;
1605 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1606 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1607 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1608 delegated_renderer_layer_impl
->SetDrawsContent(true);
1610 // Contributing render pass is offset by a transform and holds a quad that
1611 // covers it entirely.
1612 RenderPassList delegated_render_passes
;
1613 // pass2 is just the size of the quad. It contributes to |pass1| with a
1614 // translation of (211,300).
1615 RenderPassId pass2_id
=
1616 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1617 TestRenderPass
* pass2
=
1618 AddRenderPass(&delegated_render_passes
, pass2_id
,
1619 gfx::Rect(quad_screen_rect
.size()), transform
);
1620 AddQuad(pass2
, gfx::Rect(quad_screen_rect
.size()), SK_ColorRED
);
1621 // |pass1| covers the whole layer.
1622 RenderPassId pass1_id
= RenderPassId(impl
.root_layer()->id(), 0);
1623 TestRenderPass
* pass1
=
1624 AddRenderPass(&delegated_render_passes
, pass1_id
, gfx::Rect(layer_size
),
1626 AddRenderPassQuad(pass1
, pass2
, 0, FilterOperations(), transform
,
1627 SkXfermode::kSrcOver_Mode
);
1628 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1629 1.2f
, delegated_render_passes
);
1632 SCOPED_TRACE("Partial occlusion");
1634 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1635 // Move the occlusion to where it is in the contributing surface.
1636 gfx::Rect occlusion_in_target_of_delegated_quad
=
1637 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1639 SCOPED_TRACE("Contributing render pass");
1640 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1641 occlusion_in_root_target
);
1642 size_t partially_occluded_count
= 0;
1643 LayerTestCommon::VerifyQuadsAreOccluded(
1644 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1645 &partially_occluded_count
);
1646 // The layer outputs one quad, which is partially occluded.
1647 EXPECT_EQ(1u, pass2
->quad_list
.size());
1648 EXPECT_EQ(1u, partially_occluded_count
);
1649 // The quad in the contributing surface is at (211,300) in the root.
1650 // The occlusion extends to 500 * 1.2 (dsf) = 600 in the x-axis, pushing
1651 // the left of the visible part of the quad to 600 - 211 = 400 - 11 inside
1653 EXPECT_EQ(gfx::Rect(400 - 11, 0, 11, 500).ToString(),
1654 pass2
->quad_list
.front()->visible_rect
.ToString());
1659 TEST_F(DelegatedRendererLayerImplTest
, PushPropertiesTo
) {
1660 gfx::Size
layer_size(1000, 1000);
1662 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer_impl
=
1663 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 5);
1664 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1665 delegated_renderer_layer_impl
->SetDrawsContent(true);
1667 RenderPassList delegated_render_passes
;
1668 // |pass1| covers the whole layer.
1669 RenderPassId pass1_id
= RenderPassId(5, 0);
1670 AddRenderPass(&delegated_render_passes
,
1672 gfx::Rect(layer_size
),
1674 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1675 2.f
, delegated_render_passes
);
1676 EXPECT_EQ(0.5f
, delegated_renderer_layer_impl
->inverse_device_scale_factor());
1678 scoped_ptr
<DelegatedRendererLayerImpl
> other_layer
=
1679 DelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 6);
1681 delegated_renderer_layer_impl
->PushPropertiesTo(other_layer
.get());
1683 EXPECT_EQ(0.5f
, other_layer
->inverse_device_scale_factor());