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_utils.h"
19 #include "cc/test/test_shared_bitmap_manager.h"
20 #include "cc/test/test_task_graph_runner.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/transform.h"
31 class DelegatedRendererLayerImplTest
: public testing::Test
{
33 DelegatedRendererLayerImplTest()
35 always_impl_thread_and_main_thread_blocked_(&proxy_
) {
36 LayerTreeSettings settings
;
37 settings
.minimum_occlusion_tracking_size
= gfx::Size();
39 host_impl_
.reset(new FakeLayerTreeHostImpl(
40 settings
, &proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
));
41 host_impl_
->InitializeRenderer(FakeOutputSurface::Create3d());
42 host_impl_
->SetViewportSize(gfx::Size(10, 10));
47 DebugScopedSetImplThreadAndMainThreadBlocked
48 always_impl_thread_and_main_thread_blocked_
;
49 TestSharedBitmapManager shared_bitmap_manager_
;
50 TestTaskGraphRunner task_graph_runner_
;
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
->SetDrawsContent(true);
75 layer_before
->SetHasRenderSurface(true);
77 layer_after
->SetPosition(gfx::Point(5, 5));
78 layer_after
->SetBounds(gfx::Size(15, 15));
79 layer_after
->SetDrawsContent(true);
80 layer_after
->SetHasRenderSurface(true);
82 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
83 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
84 delegated_renderer_layer
->SetDrawsContent(true);
85 gfx::Transform transform
;
86 transform
.Translate(1.0, 1.0);
87 delegated_renderer_layer
->SetTransform(transform
);
89 RenderPassList delegated_render_passes
;
91 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
92 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
93 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
95 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
96 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
97 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
98 AddRenderPassQuad(pass2
, pass1
);
100 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
101 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
102 AddRenderPassQuad(pass3
, pass2
);
103 delegated_renderer_layer
->SetFrameDataForRenderPasses(
104 1.f
, delegated_render_passes
);
106 root_layer_
= root_layer
.get();
107 layer_before_
= layer_before
.get();
108 layer_after_
= layer_after
.get();
109 delegated_renderer_layer_
= delegated_renderer_layer
.get();
111 // Force the delegated RenderPasses to come before the RenderPass from
113 layer_after
->AddChild(delegated_renderer_layer
.Pass());
114 root_layer
->AddChild(layer_after
.Pass());
116 // Get the RenderPass generated by layer_before to come before the delegated
118 root_layer
->AddChild(layer_before
.Pass());
119 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
123 LayerImpl
* root_layer_
;
124 LayerImpl
* layer_before_
;
125 LayerImpl
* layer_after_
;
126 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
129 TEST_F(DelegatedRendererLayerImplTest
,
130 ChangeContributingRenderPassForNewFrame
) {
131 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
133 scoped_ptr
<LayerImpl
> root_layer
=
134 SolidColorLayerImpl::Create(host_impl_
->active_tree(), 1);
135 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
136 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
138 host_impl_
->SetViewportSize(gfx::Size(100, 100));
139 root_layer
->SetBounds(gfx::Size(100, 100));
140 root_layer
->SetHasRenderSurface(true);
142 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
143 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
144 delegated_renderer_layer
->SetDrawsContent(true);
145 delegated_renderer_layer
->SetHasRenderSurface(true);
146 gfx::Transform transform
;
147 transform
.Translate(1.0, 1.0);
148 delegated_renderer_layer
->SetTransform(transform
);
150 RenderPassList delegated_render_passes
;
152 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
153 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
154 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
156 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
157 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
158 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
159 AddRenderPassQuad(pass2
, pass1
);
161 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
162 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
163 AddRenderPassQuad(pass3
, pass2
);
164 delegated_renderer_layer
->SetFrameDataForRenderPasses(
165 1.f
, delegated_render_passes
);
167 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
169 root_layer
->AddChild(delegated_renderer_layer
.Pass());
171 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
173 LayerTreeHostImpl::FrameData frame
;
174 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
176 // Root layer has one render pass, and delegated renderer layer has two
177 // contributing render passes and its own render pass.
178 ASSERT_EQ(4u, frame
.render_passes
.size());
180 host_impl_
->DrawLayers(&frame
);
181 host_impl_
->DidDrawAllLayers(frame
);
184 // New frame makes delegated renderer layer loses its contributing render
186 RenderPassList delegated_render_passes
;
187 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
188 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
189 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
190 1.f
, delegated_render_passes
);
192 // Force damage to redraw a new frame.
193 host_impl_
->SetViewportDamage(gfx::Rect(10, 10));
195 LayerTreeHostImpl::FrameData frame
;
196 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
198 // Each non-DelegatedRendererLayer added one RenderPass. The
199 // DelegatedRendererLayer added two contributing passes.
200 ASSERT_EQ(1u, frame
.render_passes
.size());
202 host_impl_
->DrawLayers(&frame
);
203 host_impl_
->DidDrawAllLayers(frame
);
207 TEST_F(DelegatedRendererLayerImplTest
,
208 ChangeContributingRenderPassNonFullTreeSync
) {
209 FakeDelegatedRendererLayerImpl
* fake_delegated_renderer_layer_impl
;
211 host_impl_
->CreatePendingTree();
212 scoped_ptr
<LayerImpl
> root_layer
=
213 SolidColorLayerImpl::Create(host_impl_
->pending_tree(), 1);
214 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
215 FakeDelegatedRendererLayerImpl::Create(host_impl_
->pending_tree(), 2);
217 host_impl_
->SetViewportSize(gfx::Size(100, 100));
218 root_layer
->SetBounds(gfx::Size(100, 100));
219 root_layer
->SetHasRenderSurface(true);
221 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
222 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
223 delegated_renderer_layer
->SetDrawsContent(true);
224 delegated_renderer_layer
->SetHasRenderSurface(true);
225 gfx::Transform transform
;
226 transform
.Translate(1.0, 1.0);
227 delegated_renderer_layer
->SetTransform(transform
);
229 RenderPassList delegated_render_passes
;
231 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
232 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
233 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
235 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 7),
236 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
237 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
238 AddRenderPassQuad(pass2
, pass1
);
240 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
241 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
242 AddRenderPassQuad(pass3
, pass2
);
243 delegated_renderer_layer
->SetFrameDataForRenderPasses(
244 1.f
, delegated_render_passes
);
246 fake_delegated_renderer_layer_impl
= delegated_renderer_layer
.get();
248 root_layer
->AddChild(delegated_renderer_layer
.Pass());
250 host_impl_
->pending_tree()->SetRootLayer(root_layer
.Pass());
251 host_impl_
->ActivateSyncTree();
253 LayerTreeHostImpl::FrameData frame
;
254 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
256 // Root layer has one render pass, and delegated renderer layer has two
257 // contributing render passes and its own render pass.
258 ASSERT_EQ(4u, frame
.render_passes
.size());
260 host_impl_
->DrawLayers(&frame
);
261 host_impl_
->DidDrawAllLayers(frame
);
264 // Remove contributing render passes from the delegated renderer layer.
265 host_impl_
->CreatePendingTree();
266 host_impl_
->pending_tree()->set_needs_full_tree_sync(false);
267 RenderPassList delegated_render_passes
;
268 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 8),
269 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
271 fake_delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
272 1.f
, delegated_render_passes
);
274 // Force damage to redraw a new frame.
276 host_impl_
->ActivateSyncTree();
277 host_impl_
->SetViewportDamage(gfx::Rect(100, 100));
278 LayerTreeHostImpl::FrameData frame
;
279 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
281 // Root layer has one render pass, and delegated renderer layer no longer
282 // has contributing render passes.
283 ASSERT_EQ(1u, frame
.render_passes
.size());
285 host_impl_
->DrawLayers(&frame
);
286 host_impl_
->DidDrawAllLayers(frame
);
290 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsContributingRenderPasses
) {
291 LayerTreeHostImpl::FrameData frame
;
292 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
294 // Each non-DelegatedRendererLayer added one RenderPass. The
295 // DelegatedRendererLayer added two contributing passes.
296 ASSERT_EQ(5u, frame
.render_passes
.size());
298 // The DelegatedRendererLayer should have added its contributing RenderPasses
300 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
301 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
302 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
303 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
304 // And all other RenderPasses should be non-delegated.
305 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
306 EXPECT_EQ(0u, frame
.render_passes
[0]->id
.index
);
307 EXPECT_NE(4, frame
.render_passes
[3]->id
.layer_id
);
308 EXPECT_EQ(0u, frame
.render_passes
[3]->id
.index
);
309 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
310 EXPECT_EQ(0u, frame
.render_passes
[4]->id
.index
);
312 // The DelegatedRendererLayer should have added its RenderPasses to the frame
314 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
315 frame
.render_passes
[1]->output_rect
.ToString());
316 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
317 frame
.render_passes
[2]->output_rect
.ToString());
319 host_impl_
->DrawLayers(&frame
);
320 host_impl_
->DidDrawAllLayers(frame
);
323 TEST_F(DelegatedRendererLayerImplTestSimple
,
324 AddsQuadsToContributingRenderPasses
) {
325 LayerTreeHostImpl::FrameData frame
;
326 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
328 // Each non-DelegatedRendererLayer added one RenderPass. The
329 // DelegatedRendererLayer added two contributing passes.
330 ASSERT_EQ(5u, frame
.render_passes
.size());
332 // The DelegatedRendererLayer should have added its contributing RenderPasses
334 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
335 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
336 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
337 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
339 // The DelegatedRendererLayer should have added copies of its quads to
340 // contributing RenderPasses.
341 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
342 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
343 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
345 // Verify it added the right quads.
346 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
347 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
348 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
349 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
350 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
351 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
352 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
353 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
355 host_impl_
->DrawLayers(&frame
);
356 host_impl_
->DidDrawAllLayers(frame
);
359 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsQuadsToTargetRenderPass
) {
360 LayerTreeHostImpl::FrameData frame
;
361 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
363 // Each non-DelegatedRendererLayer added one RenderPass. The
364 // DelegatedRendererLayer added two contributing passes.
365 ASSERT_EQ(5u, frame
.render_passes
.size());
367 // The layer's target is the RenderPass from layer_after_.
368 EXPECT_EQ(RenderPassId(3, 0), frame
.render_passes
[3]->id
);
370 // The DelegatedRendererLayer should have added copies of quads in its root
371 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
372 ASSERT_EQ(2u, frame
.render_passes
[3]->quad_list
.size());
374 // Verify it added the right quads.
375 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
376 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
378 // Its target layer should have a quad as well.
379 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
380 frame
.render_passes
[3]->quad_list
.ElementAt(1)->rect
.ToString());
382 host_impl_
->DrawLayers(&frame
);
383 host_impl_
->DidDrawAllLayers(frame
);
386 TEST_F(DelegatedRendererLayerImplTestSimple
,
387 QuadsFromRootRenderPassAreModifiedForTheTarget
) {
388 LayerTreeHostImpl::FrameData frame
;
389 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
391 // Each non-DelegatedRendererLayer added one RenderPass. The
392 // DelegatedRendererLayer added two contributing passes.
393 ASSERT_EQ(5u, frame
.render_passes
.size());
395 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
396 // has a translation transform of 1,1. So its root RenderPass' quads should
397 // all be transformed by that combined amount.
398 gfx::Transform transform
;
399 transform
.Translate(4.0, 4.0);
400 EXPECT_TRANSFORMATION_MATRIX_EQ(
401 transform
, frame
.render_passes
[3]
403 ->shared_quad_state
->quad_to_target_transform
);
405 // Quads from non-root RenderPasses should not be shifted though.
406 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
408 EXPECT_TRANSFORMATION_MATRIX_EQ(
409 gfx::Transform(), frame
.render_passes
[2]
411 ->shared_quad_state
->quad_to_target_transform
);
412 EXPECT_TRANSFORMATION_MATRIX_EQ(
413 gfx::Transform(), frame
.render_passes
[2]
414 ->quad_list
.ElementAt(1)
415 ->shared_quad_state
->quad_to_target_transform
);
416 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
417 EXPECT_TRANSFORMATION_MATRIX_EQ(
418 gfx::Transform(), frame
.render_passes
[1]
420 ->shared_quad_state
->quad_to_target_transform
);
422 host_impl_
->DrawLayers(&frame
);
423 host_impl_
->DidDrawAllLayers(frame
);
426 TEST_F(DelegatedRendererLayerImplTestSimple
, RenderPassTransformIsModified
) {
427 LayerTreeHostImpl::FrameData frame
;
428 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
430 // The delegated layer has a surface between it and the root.
431 EXPECT_TRUE(delegated_renderer_layer_
->render_target()->parent());
433 // Each non-DelegatedRendererLayer added one RenderPass. The
434 // DelegatedRendererLayer added two contributing passes.
435 ASSERT_EQ(5u, frame
.render_passes
.size());
437 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
438 // render pass' transforms to the root should be shifted by this amount.
439 gfx::Transform transform
;
440 transform
.Translate(9.0, 9.0);
442 // The first contributing surface has a translation of 5, 6.
443 gfx::Transform
five_six(1, 0, 0, 1, 5, 6);
445 // The second contributing surface has a translation of 7, 8.
446 gfx::Transform
seven_eight(1, 0, 0, 1, 7, 8);
448 EXPECT_TRANSFORMATION_MATRIX_EQ(
449 transform
* five_six
, frame
.render_passes
[1]->transform_to_root_target
);
450 EXPECT_TRANSFORMATION_MATRIX_EQ(
451 transform
* seven_eight
,
452 frame
.render_passes
[2]->transform_to_root_target
);
454 host_impl_
->DrawLayers(&frame
);
455 host_impl_
->DidDrawAllLayers(frame
);
458 class DelegatedRendererLayerImplTestOwnSurface
459 : public DelegatedRendererLayerImplTestSimple
{
461 DelegatedRendererLayerImplTestOwnSurface()
462 : DelegatedRendererLayerImplTestSimple() {
463 delegated_renderer_layer_
->SetHasRenderSurface(true);
467 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsRenderPasses
) {
468 LayerTreeHostImpl::FrameData frame
;
469 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
471 // Each non-DelegatedRendererLayer added one RenderPass. The
472 // DelegatedRendererLayer added two contributing passes and its owned surface
474 ASSERT_EQ(6u, frame
.render_passes
.size());
476 // The DelegatedRendererLayer should have added its contributing RenderPasses
478 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
479 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
480 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
481 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
482 // The DelegatedRendererLayer should have added a RenderPass for its surface
484 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
485 EXPECT_EQ(0u, frame
.render_passes
[3]->id
.index
);
486 // And all other RenderPasses should be non-delegated.
487 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
488 EXPECT_EQ(0u, frame
.render_passes
[0]->id
.index
);
489 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
490 EXPECT_EQ(0u, frame
.render_passes
[4]->id
.index
);
491 EXPECT_NE(4, frame
.render_passes
[5]->id
.layer_id
);
492 EXPECT_EQ(0u, frame
.render_passes
[5]->id
.index
);
494 // The DelegatedRendererLayer should have added its RenderPasses to the frame
496 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
497 frame
.render_passes
[1]->output_rect
.ToString());
498 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
499 frame
.render_passes
[2]->output_rect
.ToString());
501 host_impl_
->DrawLayers(&frame
);
502 host_impl_
->DidDrawAllLayers(frame
);
505 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
506 AddsQuadsToContributingRenderPasses
) {
507 LayerTreeHostImpl::FrameData frame
;
508 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
510 // Each non-DelegatedRendererLayer added one RenderPass. The
511 // DelegatedRendererLayer added two contributing passes and its owned surface
513 ASSERT_EQ(6u, frame
.render_passes
.size());
515 // The DelegatedRendererLayer should have added its contributing RenderPasses
517 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
518 EXPECT_EQ(1u, frame
.render_passes
[1]->id
.index
);
519 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
520 EXPECT_EQ(2u, frame
.render_passes
[2]->id
.index
);
522 // The DelegatedRendererLayer should have added copies of its quads to
523 // contributing RenderPasses.
524 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
525 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
526 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
528 // Verify it added the right quads.
529 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
531 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
532 frame
.render_passes
[2]->quad_list
.front()->rect
.ToString());
533 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
534 frame
.render_passes
[2]->quad_list
.ElementAt(1)->rect
.ToString());
535 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
536 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
537 frame
.render_passes
[1]->quad_list
.front()->rect
.ToString());
539 host_impl_
->DrawLayers(&frame
);
540 host_impl_
->DidDrawAllLayers(frame
);
543 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsQuadsToTargetRenderPass
) {
544 LayerTreeHostImpl::FrameData frame
;
545 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
547 // Each non-DelegatedRendererLayer added one RenderPass. The
548 // DelegatedRendererLayer added two contributing passes and its owned surface
550 ASSERT_EQ(6u, frame
.render_passes
.size());
552 // The layer's target is the RenderPass owned by itself.
553 EXPECT_EQ(RenderPassId(4, 0), frame
.render_passes
[3]->id
);
555 // The DelegatedRendererLayer should have added copies of quads in its root
556 // RenderPass to its target RenderPass.
557 // The layer_after also adds one quad.
558 ASSERT_EQ(1u, frame
.render_passes
[3]->quad_list
.size());
560 // Verify it added the right quads.
561 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
562 frame
.render_passes
[3]->quad_list
.front()->rect
.ToString());
564 host_impl_
->DrawLayers(&frame
);
565 host_impl_
->DidDrawAllLayers(frame
);
568 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
569 QuadsFromRootRenderPassAreNotModifiedForTheTarget
) {
570 LayerTreeHostImpl::FrameData frame
;
571 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
573 // Each non-DelegatedRendererLayer added one RenderPass. The
574 // DelegatedRendererLayer added two contributing passes and its owned surface
576 ASSERT_EQ(6u, frame
.render_passes
.size());
578 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
579 // RenderPass' quads do not need to be translated at all.
580 EXPECT_TRANSFORMATION_MATRIX_EQ(
581 gfx::Transform(), frame
.render_passes
[3]
583 ->shared_quad_state
->quad_to_target_transform
);
585 // Quads from non-root RenderPasses should not be shifted either.
586 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
588 EXPECT_TRANSFORMATION_MATRIX_EQ(
589 gfx::Transform(), frame
.render_passes
[2]
591 ->shared_quad_state
->quad_to_target_transform
);
592 EXPECT_TRANSFORMATION_MATRIX_EQ(
593 gfx::Transform(), frame
.render_passes
[2]
594 ->quad_list
.ElementAt(1)
595 ->shared_quad_state
->quad_to_target_transform
);
596 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
597 EXPECT_TRANSFORMATION_MATRIX_EQ(
598 gfx::Transform(), frame
.render_passes
[1]
600 ->shared_quad_state
->quad_to_target_transform
);
602 host_impl_
->DrawLayers(&frame
);
603 host_impl_
->DidDrawAllLayers(frame
);
606 class DelegatedRendererLayerImplTestTransform
607 : public DelegatedRendererLayerImplTest
{
609 DelegatedRendererLayerImplTestTransform()
610 : root_delegated_render_pass_is_clipped_(false),
611 delegated_device_scale_factor_(2.f
) {}
614 host_impl_
->SetDeviceScaleFactor(2.f
);
616 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::Create(
617 host_impl_
->active_tree(), 1);
618 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
619 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
621 host_impl_
->SetViewportSize(gfx::Size(200, 200));
622 root_layer
->SetBounds(gfx::Size(100, 100));
623 root_layer
->SetHasRenderSurface(true);
625 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
626 delegated_renderer_layer
->SetBounds(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_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;
645 AddRenderPass(&delegated_render_passes
, RenderPassId(10, 7),
646 child_pass_rect
, gfx::Transform());
647 SharedQuadState
* shared_quad_state
=
648 pass
->CreateAndAppendSharedQuadState();
649 shared_quad_state
->SetAll(child_pass_transform
, child_pass_bounds
,
650 child_pass_rect
, child_pass_clip_rect
,
651 child_pass_clipped
, 1.f
,
652 SkXfermode::kSrcOver_Mode
, 0);
654 SolidColorDrawQuad
* color_quad
;
655 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
656 color_quad
->SetNew(shared_quad_state
,
657 gfx::Rect(20, 20, 3, 7),
658 gfx::Rect(20, 20, 3, 7),
662 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
663 color_quad
->SetNew(shared_quad_state
,
664 gfx::Rect(23, 20, 4, 7),
665 gfx::Rect(23, 20, 4, 7),
670 gfx::Size
root_pass_bounds(100, 100);
671 gfx::Rect
root_pass_rect(0, 0, 100, 100);
672 gfx::Transform root_pass_transform
;
673 root_pass_transform
.Scale(1.5, 1.5);
674 root_pass_transform
.Translate(7.0, 7.0);
675 gfx::Rect
root_pass_clip_rect(10, 10, 35, 35);
676 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
679 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
680 root_pass_rect
, gfx::Transform());
681 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
682 shared_quad_state
->SetAll(root_pass_transform
, root_pass_bounds
,
683 root_pass_rect
, root_pass_clip_rect
,
684 root_pass_clipped
, 1.f
, SkXfermode::kSrcOver_Mode
,
687 RenderPassDrawQuad
* render_pass_quad
=
688 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
689 render_pass_quad
->SetNew(shared_quad_state
,
690 gfx::Rect(5, 5, 7, 7), // quad_rect
691 gfx::Rect(5, 5, 7, 7), // visible_rect
692 RenderPassId(10, 7), // render_pass_id
693 0, // mask_resource_id
694 gfx::Vector2dF(), // mask_uv_scale
695 gfx::Size(), // mask_texture_size
696 FilterOperations(), // filters
697 gfx::Vector2dF(), // filters_scale
698 FilterOperations()); // background_filters
700 SolidColorDrawQuad
* color_quad
;
701 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
702 color_quad
->SetNew(shared_quad_state
,
703 gfx::Rect(0, 0, 10, 10),
704 gfx::Rect(0, 0, 10, 10),
708 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
709 color_quad
->SetNew(shared_quad_state
,
710 gfx::Rect(0, 10, 10, 10),
711 gfx::Rect(0, 10, 10, 10),
715 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
716 color_quad
->SetNew(shared_quad_state
,
717 gfx::Rect(10, 0, 10, 10),
718 gfx::Rect(10, 0, 10, 10),
722 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
723 color_quad
->SetNew(shared_quad_state
,
724 gfx::Rect(10, 10, 10, 10),
725 gfx::Rect(10, 10, 10, 10),
729 delegated_renderer_layer
->SetFrameDataForRenderPasses(
730 delegated_device_scale_factor_
, delegated_render_passes
);
732 root_layer_
= root_layer
.get();
733 delegated_renderer_layer_
= delegated_renderer_layer
.get();
735 root_layer
->AddChild(delegated_renderer_layer
.Pass());
736 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
739 void VerifyRenderPasses(
740 const LayerTreeHostImpl::FrameData
& frame
,
741 size_t num_render_passes
,
742 const SharedQuadState
** root_delegated_shared_quad_state
,
743 const SharedQuadState
** contrib_delegated_shared_quad_state
) {
744 ASSERT_EQ(num_render_passes
, frame
.render_passes
.size());
745 // The contributing render pass in the DelegatedRendererLayer.
746 EXPECT_EQ(2, frame
.render_passes
[0]->id
.layer_id
);
747 EXPECT_EQ(1u, frame
.render_passes
[0]->id
.index
);
748 // The root render pass.
749 EXPECT_EQ(1, frame
.render_passes
.back()->id
.layer_id
);
750 EXPECT_EQ(0u, frame
.render_passes
.back()->id
.index
);
752 const QuadList
& contrib_delegated_quad_list
=
753 frame
.render_passes
[0]->quad_list
;
754 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
756 const QuadList
& root_delegated_quad_list
=
757 frame
.render_passes
[1]->quad_list
;
758 ASSERT_EQ(5u, root_delegated_quad_list
.size());
760 // All quads in a render pass should share the same state.
761 *contrib_delegated_shared_quad_state
=
762 contrib_delegated_quad_list
.front()->shared_quad_state
;
763 EXPECT_EQ(*contrib_delegated_shared_quad_state
,
764 contrib_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
766 *root_delegated_shared_quad_state
=
767 root_delegated_quad_list
.front()->shared_quad_state
;
768 EXPECT_EQ(*root_delegated_shared_quad_state
,
769 root_delegated_quad_list
.ElementAt(1)->shared_quad_state
);
770 EXPECT_EQ(*root_delegated_shared_quad_state
,
771 root_delegated_quad_list
.ElementAt(2)->shared_quad_state
);
772 EXPECT_EQ(*root_delegated_shared_quad_state
,
773 root_delegated_quad_list
.ElementAt(3)->shared_quad_state
);
774 EXPECT_EQ(*root_delegated_shared_quad_state
,
775 root_delegated_quad_list
.ElementAt(4)->shared_quad_state
);
777 EXPECT_NE(*contrib_delegated_shared_quad_state
,
778 *root_delegated_shared_quad_state
);
782 LayerImpl
* root_layer_
;
783 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
784 bool root_delegated_render_pass_is_clipped_
;
785 float delegated_device_scale_factor_
;
788 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_NoSurface
) {
789 root_delegated_render_pass_is_clipped_
= false;
792 LayerTreeHostImpl::FrameData frame
;
793 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
795 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
796 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
800 &root_delegated_shared_quad_state
,
801 &contrib_delegated_shared_quad_state
);
803 // When the quads don't have a clip of their own, the clip rect is set to
804 // the drawable_content_rect of the delegated renderer layer.
805 EXPECT_EQ(delegated_renderer_layer_
->drawable_content_rect().ToString(),
806 root_delegated_shared_quad_state
->clip_rect
.ToString());
808 // Even though the quads in the root pass have no clip of their own, they
809 // inherit the clip rect from the delegated renderer layer if it does not
811 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
813 gfx::Transform expected
;
814 // Device scale factor.
815 expected
.Scale(2.0, 2.0);
816 // This is the transform from the layer's space to its target.
817 expected
.Translate(20, 20);
818 expected
.Scale(2.0, 2.0);
819 expected
.Translate(8.0, 8.0);
820 // This is the transform within the source frame.
821 // Inverse device scale factor to go from physical space to layer space.
822 expected
.Scale(0.5, 0.5);
823 expected
.Scale(1.5, 1.5);
824 expected
.Translate(7.0, 7.0);
825 EXPECT_TRANSFORMATION_MATRIX_EQ(
826 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
828 // The contributing render pass should not be transformed from its input.
829 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
830 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
831 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
832 expected
.MakeIdentity();
833 expected
.Scale(0.8f
, 0.8f
);
834 expected
.Translate(9.0, 9.0);
835 EXPECT_TRANSFORMATION_MATRIX_EQ(
836 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
838 host_impl_
->DrawLayers(&frame
);
839 host_impl_
->DidDrawAllLayers(frame
);
842 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_NoSurface
) {
843 root_delegated_render_pass_is_clipped_
= true;
846 LayerTreeHostImpl::FrameData frame
;
847 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
849 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
850 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
854 &root_delegated_shared_quad_state
,
855 &contrib_delegated_shared_quad_state
);
857 // Since the quads have a clip_rect it should be modified by delegated
858 // renderer layer's draw_transform.
859 // The position of the resulting clip_rect is:
860 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
861 // layer scale (2) + layer position (20) = 46
862 // The device scale is 2, so everything gets doubled, giving 92.
864 // The size is 35x35 scaled by the device scale.
865 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
866 root_delegated_shared_quad_state
->clip_rect
.ToString());
868 // The quads had a clip and it should be preserved.
869 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
871 gfx::Transform expected
;
872 // Device scale factor.
873 expected
.Scale(2.0, 2.0);
874 // This is the transform from the layer's space to its target.
875 expected
.Translate(20, 20);
876 expected
.Scale(2.0, 2.0);
877 expected
.Translate(8.0, 8.0);
878 // This is the transform within the source frame.
879 // Inverse device scale factor to go from physical space to layer space.
880 expected
.Scale(0.5, 0.5);
881 expected
.Scale(1.5, 1.5);
882 expected
.Translate(7.0, 7.0);
883 EXPECT_TRANSFORMATION_MATRIX_EQ(
884 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
886 // The contributing render pass should not be transformed from its input.
887 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
888 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
889 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
890 expected
.MakeIdentity();
891 expected
.Scale(0.8f
, 0.8f
);
892 expected
.Translate(9.0, 9.0);
893 EXPECT_TRANSFORMATION_MATRIX_EQ(
894 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
896 host_impl_
->DrawLayers(&frame
);
897 host_impl_
->DidDrawAllLayers(frame
);
900 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_Surface
) {
901 root_delegated_render_pass_is_clipped_
= false;
904 delegated_renderer_layer_
->SetHasRenderSurface(true);
906 LayerTreeHostImpl::FrameData frame
;
907 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
909 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
910 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
914 &root_delegated_shared_quad_state
,
915 &contrib_delegated_shared_quad_state
);
917 // When the layer owns a surface, then its translation is not part of its
918 // draw transform, but its scale is.
919 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
920 root_delegated_shared_quad_state
->clip_rect
.ToString());
922 // Since the layer owns a surface it doesn't need to clip its quads, so
923 // unclipped quads remain unclipped.
924 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
926 gfx::Transform expected
;
927 // This is the transform within the source frame scaled by the delegated
928 // render layer transform.
929 expected
.Scale(3.0, 3.0);
930 expected
.Translate(7.0, 7.0);
931 EXPECT_TRANSFORMATION_MATRIX_EQ(
932 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
934 // The contributing render pass should not be transformed from its input.
935 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
936 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
937 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
938 expected
.MakeIdentity();
939 expected
.Scale(0.8f
, 0.8f
);
940 expected
.Translate(9.0, 9.0);
941 EXPECT_TRANSFORMATION_MATRIX_EQ(
942 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
944 host_impl_
->DrawLayers(&frame
);
945 host_impl_
->DidDrawAllLayers(frame
);
948 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_Surface
) {
949 root_delegated_render_pass_is_clipped_
= true;
952 delegated_renderer_layer_
->SetHasRenderSurface(true);
954 LayerTreeHostImpl::FrameData frame
;
955 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
957 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
958 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
962 &root_delegated_shared_quad_state
,
963 &contrib_delegated_shared_quad_state
);
965 // When the layer owns a surface, then its translation is not part of its
966 // draw transform, but its scale is.
967 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
968 root_delegated_shared_quad_state
->clip_rect
.ToString());
970 // The quads had a clip and it should be preserved.
971 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
973 gfx::Transform expected
;
974 // This is the transform within the source frame scaled by the delegated
975 // render layer transform.
976 expected
.Scale(3.0, 3.0);
977 expected
.Translate(7.0, 7.0);
978 EXPECT_TRANSFORMATION_MATRIX_EQ(
979 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
981 // The contributing render pass should not be transformed from its input.
982 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
983 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
984 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
985 expected
.MakeIdentity();
986 expected
.Scale(0.8f
, 0.8f
);
987 expected
.Translate(9.0, 9.0);
988 EXPECT_TRANSFORMATION_MATRIX_EQ(
989 expected
, contrib_delegated_shared_quad_state
->quad_to_target_transform
);
991 host_impl_
->DrawLayers(&frame
);
992 host_impl_
->DidDrawAllLayers(frame
);
995 TEST_F(DelegatedRendererLayerImplTestTransform
, MismatchedDeviceScaleFactor
) {
996 root_delegated_render_pass_is_clipped_
= true;
997 delegated_device_scale_factor_
= 1.3f
;
1001 LayerTreeHostImpl::FrameData frame
;
1002 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1004 const SharedQuadState
* root_delegated_shared_quad_state
= nullptr;
1005 const SharedQuadState
* contrib_delegated_shared_quad_state
= nullptr;
1006 VerifyRenderPasses(frame
,
1008 &root_delegated_shared_quad_state
,
1009 &contrib_delegated_shared_quad_state
);
1011 // The parent tree's device scale factor is 2.0, but the child has submitted a
1012 // frame with a device scale factor of 1.3. Absent any better option, the
1013 // only thing we can do is scale from 1.3 -> 2.0.
1015 gfx::Transform expected
;
1016 // Device scale factor (from parent).
1017 expected
.Scale(2.0, 2.0);
1018 // This is the transform from the layer's space to its target.
1019 expected
.Translate(20, 20);
1020 expected
.Scale(2.0, 2.0);
1021 expected
.Translate(8.0, 8.0);
1022 // This is the transform within the source frame.
1023 // Inverse device scale factor (from child).
1024 expected
.Scale(1.0f
/ 1.3f
, 1.0f
/ 1.3f
);
1025 expected
.Scale(1.5, 1.5);
1026 expected
.Translate(7.0, 7.0);
1027 EXPECT_TRANSFORMATION_MATRIX_EQ(
1028 expected
, root_delegated_shared_quad_state
->quad_to_target_transform
);
1030 host_impl_
->DrawLayers(&frame
);
1031 host_impl_
->DidDrawAllLayers(frame
);
1034 class DelegatedRendererLayerImplTestClip
1035 : public DelegatedRendererLayerImplTest
{
1038 scoped_ptr
<LayerImpl
> root_layer
=
1039 LayerImpl::Create(host_impl_
->active_tree(), 1);
1040 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
1041 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
1042 scoped_ptr
<LayerImpl
> clip_layer
=
1043 LayerImpl::Create(host_impl_
->active_tree(), 3);
1044 scoped_ptr
<LayerImpl
> origin_layer
=
1045 LayerImpl::Create(host_impl_
->active_tree(), 4);
1047 host_impl_
->SetViewportSize(gfx::Size(100, 100));
1048 root_layer
->SetBounds(gfx::Size(100, 100));
1049 root_layer
->SetHasRenderSurface(true);
1051 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
1052 delegated_renderer_layer
->SetBounds(gfx::Size(50, 50));
1053 delegated_renderer_layer
->SetDrawsContent(true);
1055 RenderPassList delegated_render_passes
;
1057 gfx::Size
child_pass_bounds(7, 7);
1058 gfx::Rect
child_pass_rect(20, 20, 7, 7);
1059 gfx::Transform child_pass_transform
;
1060 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
1061 bool child_pass_clipped
= false;
1065 AddRenderPass(&delegated_render_passes
, RenderPassId(10, 7),
1066 child_pass_rect
, gfx::Transform());
1067 SharedQuadState
* shared_quad_state
=
1068 pass
->CreateAndAppendSharedQuadState();
1069 shared_quad_state
->SetAll(child_pass_transform
, child_pass_bounds
,
1070 child_pass_rect
, child_pass_clip_rect
,
1071 child_pass_clipped
, 1.f
,
1072 SkXfermode::kSrcOver_Mode
, 0);
1074 SolidColorDrawQuad
* color_quad
;
1075 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1076 color_quad
->SetNew(shared_quad_state
,
1077 gfx::Rect(20, 20, 3, 7),
1078 gfx::Rect(20, 20, 3, 7),
1082 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1083 color_quad
->SetNew(shared_quad_state
,
1084 gfx::Rect(23, 20, 4, 7),
1085 gfx::Rect(23, 20, 4, 7),
1090 gfx::Size
root_pass_bounds(50, 50);
1091 gfx::Rect
root_pass_rect(0, 0, 50, 50);
1092 gfx::Transform root_pass_transform
;
1093 gfx::Rect
root_pass_clip_rect(5, 5, 40, 40);
1094 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
1097 AddRenderPass(&delegated_render_passes
, RenderPassId(9, 6),
1098 root_pass_rect
, gfx::Transform());
1099 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
1100 shared_quad_state
->SetAll(root_pass_transform
, root_pass_bounds
,
1101 root_pass_rect
, root_pass_clip_rect
,
1102 root_pass_clipped
, 1.f
, SkXfermode::kSrcOver_Mode
,
1105 RenderPassDrawQuad
* render_pass_quad
=
1106 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1107 render_pass_quad
->SetNew(shared_quad_state
,
1108 gfx::Rect(5, 5, 7, 7), // quad_rect
1109 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1110 RenderPassId(10, 7), // render_pass_id
1111 0, // mask_resource_id
1112 gfx::Vector2dF(), // mask_uv_scale
1113 gfx::Size(), // mask_texture_size,
1114 FilterOperations(), // filters
1115 gfx::Vector2dF(), // filters_scale
1116 FilterOperations()); // background_filters
1118 SolidColorDrawQuad
* color_quad
;
1119 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1120 color_quad
->SetNew(shared_quad_state
,
1121 gfx::Rect(0, 0, 10, 10),
1122 gfx::Rect(0, 0, 10, 10),
1126 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1127 color_quad
->SetNew(shared_quad_state
,
1128 gfx::Rect(0, 10, 10, 10),
1129 gfx::Rect(0, 10, 10, 10),
1133 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1134 color_quad
->SetNew(shared_quad_state
,
1135 gfx::Rect(10, 0, 10, 10),
1136 gfx::Rect(10, 0, 10, 10),
1140 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1141 color_quad
->SetNew(shared_quad_state
,
1142 gfx::Rect(10, 10, 10, 10),
1143 gfx::Rect(10, 10, 10, 10),
1147 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1148 1.f
, delegated_render_passes
);
1150 root_layer_
= root_layer
.get();
1151 delegated_renderer_layer_
= delegated_renderer_layer
.get();
1153 if (clip_delegated_renderer_layer_
) {
1154 gfx::Rect
clip_rect(21, 27, 23, 21);
1156 clip_layer
->SetPosition(clip_rect
.origin());
1157 clip_layer
->SetBounds(clip_rect
.size());
1158 clip_layer
->SetMasksToBounds(true);
1160 origin_layer
->SetPosition(
1161 gfx::PointAtOffsetFromOrigin(-clip_rect
.OffsetFromOrigin()));
1163 origin_layer
->AddChild(delegated_renderer_layer
.Pass());
1164 clip_layer
->AddChild(origin_layer
.Pass());
1165 root_layer
->AddChild(clip_layer
.Pass());
1167 root_layer
->AddChild(delegated_renderer_layer
.Pass());
1170 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1174 LayerImpl
* root_layer_
;
1175 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
1176 bool root_delegated_render_pass_is_clipped_
;
1177 bool clip_delegated_renderer_layer_
;
1180 TEST_F(DelegatedRendererLayerImplTestClip
,
1181 QuadsUnclipped_LayerUnclipped_NoSurface
) {
1182 root_delegated_render_pass_is_clipped_
= false;
1183 clip_delegated_renderer_layer_
= false;
1186 LayerTreeHostImpl::FrameData frame
;
1187 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1189 ASSERT_EQ(2u, frame
.render_passes
.size());
1190 const QuadList
& contrib_delegated_quad_list
=
1191 frame
.render_passes
[0]->quad_list
;
1192 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1193 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1194 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1195 const SharedQuadState
* root_delegated_shared_quad_state
=
1196 root_delegated_quad_list
.front()->shared_quad_state
;
1198 // When the quads don't have a clip of their own, the clip rect is set to
1199 // the drawable_content_rect of the delegated renderer layer.
1200 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1201 root_delegated_shared_quad_state
->clip_rect
.ToString());
1202 // Quads are clipped to the delegated renderer layer.
1203 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1205 host_impl_
->DrawLayers(&frame
);
1206 host_impl_
->DidDrawAllLayers(frame
);
1209 TEST_F(DelegatedRendererLayerImplTestClip
,
1210 QuadsClipped_LayerUnclipped_NoSurface
) {
1211 root_delegated_render_pass_is_clipped_
= true;
1212 clip_delegated_renderer_layer_
= false;
1215 LayerTreeHostImpl::FrameData frame
;
1216 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1218 ASSERT_EQ(2u, frame
.render_passes
.size());
1219 const QuadList
& contrib_delegated_quad_list
=
1220 frame
.render_passes
[0]->quad_list
;
1221 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1222 const QuadList
& root_delegated_quad_list
=
1223 frame
.render_passes
[1]->quad_list
;
1224 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1225 const SharedQuadState
* root_delegated_shared_quad_state
=
1226 root_delegated_quad_list
.front()->shared_quad_state
;
1228 // When the quads have a clip of their own, it is used.
1229 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1230 root_delegated_shared_quad_state
->clip_rect
.ToString());
1231 // Quads came with a clip rect.
1232 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1234 host_impl_
->DrawLayers(&frame
);
1235 host_impl_
->DidDrawAllLayers(frame
);
1238 TEST_F(DelegatedRendererLayerImplTestClip
,
1239 QuadsUnclipped_LayerClipped_NoSurface
) {
1240 root_delegated_render_pass_is_clipped_
= false;
1241 clip_delegated_renderer_layer_
= true;
1244 LayerTreeHostImpl::FrameData frame
;
1245 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1246 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1248 ASSERT_EQ(2u, frame
.render_passes
.size());
1249 const QuadList
& contrib_delegated_quad_list
=
1250 frame
.render_passes
[0]->quad_list
;
1251 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1252 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1253 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1254 const SharedQuadState
* root_delegated_shared_quad_state
=
1255 root_delegated_quad_list
.front()->shared_quad_state
;
1257 // When the quads don't have a clip of their own, the clip rect is set to
1258 // the drawable_content_rect of the delegated renderer layer. When the layer
1259 // is clipped, that should be seen in the quads' clip_rect.
1260 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1261 root_delegated_shared_quad_state
->clip_rect
.ToString());
1262 // Quads are clipped to the delegated renderer layer.
1263 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1265 host_impl_
->DrawLayers(&frame
);
1266 host_impl_
->DidDrawAllLayers(frame
);
1269 TEST_F(DelegatedRendererLayerImplTestClip
,
1270 QuadsClipped_LayerClipped_NoSurface
) {
1271 root_delegated_render_pass_is_clipped_
= true;
1272 clip_delegated_renderer_layer_
= true;
1275 LayerTreeHostImpl::FrameData frame
;
1276 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1277 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1279 ASSERT_EQ(2u, frame
.render_passes
.size());
1280 const QuadList
& contrib_delegated_quad_list
=
1281 frame
.render_passes
[0]->quad_list
;
1282 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1283 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1284 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1285 const SharedQuadState
* root_delegated_shared_quad_state
=
1286 root_delegated_quad_list
.front()->shared_quad_state
;
1288 // When the quads have a clip of their own, it is used, but it is
1289 // combined with the clip rect of the delegated renderer layer.
1290 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1291 root_delegated_shared_quad_state
->clip_rect
.ToString());
1292 // Quads came with a clip rect.
1293 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1295 host_impl_
->DrawLayers(&frame
);
1296 host_impl_
->DidDrawAllLayers(frame
);
1299 TEST_F(DelegatedRendererLayerImplTestClip
,
1300 QuadsUnclipped_LayerUnclipped_Surface
) {
1301 root_delegated_render_pass_is_clipped_
= false;
1302 clip_delegated_renderer_layer_
= false;
1305 delegated_renderer_layer_
->SetHasRenderSurface(true);
1307 LayerTreeHostImpl::FrameData frame
;
1308 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1310 ASSERT_EQ(3u, frame
.render_passes
.size());
1311 const QuadList
& contrib_delegated_quad_list
=
1312 frame
.render_passes
[0]->quad_list
;
1313 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1314 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1315 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1316 const SharedQuadState
* root_delegated_shared_quad_state
=
1317 root_delegated_quad_list
.front()->shared_quad_state
;
1319 // When the layer owns a surface, the quads don't need to be clipped
1320 // further than they already specify. If they aren't clipped, then their
1321 // clip rect is ignored, and they are not set as clipped.
1322 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1324 host_impl_
->DrawLayers(&frame
);
1325 host_impl_
->DidDrawAllLayers(frame
);
1328 TEST_F(DelegatedRendererLayerImplTestClip
,
1329 QuadsClipped_LayerUnclipped_Surface
) {
1330 root_delegated_render_pass_is_clipped_
= true;
1331 clip_delegated_renderer_layer_
= false;
1334 delegated_renderer_layer_
->SetHasRenderSurface(true);
1336 LayerTreeHostImpl::FrameData frame
;
1337 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1339 ASSERT_EQ(3u, frame
.render_passes
.size());
1340 const QuadList
& contrib_delegated_quad_list
=
1341 frame
.render_passes
[0]->quad_list
;
1342 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1343 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1344 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1345 const SharedQuadState
* root_delegated_shared_quad_state
=
1346 root_delegated_quad_list
.front()->shared_quad_state
;
1348 // When the quads have a clip of their own, it is used.
1349 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1350 root_delegated_shared_quad_state
->clip_rect
.ToString());
1351 // Quads came with a clip rect.
1352 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1354 host_impl_
->DrawLayers(&frame
);
1355 host_impl_
->DidDrawAllLayers(frame
);
1358 TEST_F(DelegatedRendererLayerImplTestClip
,
1359 QuadsUnclipped_LayerClipped_Surface
) {
1360 root_delegated_render_pass_is_clipped_
= false;
1361 clip_delegated_renderer_layer_
= true;
1364 delegated_renderer_layer_
->SetHasRenderSurface(true);
1366 LayerTreeHostImpl::FrameData frame
;
1367 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1368 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1370 ASSERT_EQ(3u, frame
.render_passes
.size());
1371 const QuadList
& contrib_delegated_quad_list
=
1372 frame
.render_passes
[0]->quad_list
;
1373 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1374 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1375 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1376 const SharedQuadState
* root_delegated_shared_quad_state
=
1377 root_delegated_quad_list
.front()->shared_quad_state
;
1379 // When the layer owns a surface, the quads don't need to be clipped
1380 // further than they already specify. If they aren't clipped, then their
1381 // clip rect is ignored, and they are not set as clipped.
1382 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1384 host_impl_
->DrawLayers(&frame
);
1385 host_impl_
->DidDrawAllLayers(frame
);
1388 TEST_F(DelegatedRendererLayerImplTestClip
, QuadsClipped_LayerClipped_Surface
) {
1389 root_delegated_render_pass_is_clipped_
= true;
1390 clip_delegated_renderer_layer_
= true;
1393 delegated_renderer_layer_
->SetHasRenderSurface(true);
1395 LayerTreeHostImpl::FrameData frame
;
1396 host_impl_
->active_tree()->BuildPropertyTreesForTesting();
1397 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1399 ASSERT_EQ(3u, frame
.render_passes
.size());
1400 const QuadList
& contrib_delegated_quad_list
=
1401 frame
.render_passes
[0]->quad_list
;
1402 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1403 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1404 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1405 const SharedQuadState
* root_delegated_shared_quad_state
=
1406 root_delegated_quad_list
.front()->shared_quad_state
;
1408 // When the quads have a clip of their own, it is used, but it is
1409 // combined with the clip rect of the delegated renderer layer. If the
1410 // layer owns a surface, then it does not have a clip rect of its own.
1411 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1412 root_delegated_shared_quad_state
->clip_rect
.ToString());
1413 // Quads came with a clip rect.
1414 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1416 host_impl_
->DrawLayers(&frame
);
1417 host_impl_
->DidDrawAllLayers(frame
);
1420 TEST_F(DelegatedRendererLayerImplTest
, Occlusion
) {
1421 gfx::Size
layer_size(1000, 1000);
1422 gfx::Size
viewport_size(1000, 1000);
1423 gfx::Rect
quad_screen_rect(211, 300, 400, 500);
1425 gfx::Transform transform
;
1426 transform
.Translate(211.0, 300.0);
1428 LayerTestCommon::LayerImplTest impl
;
1430 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1431 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1432 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1433 delegated_renderer_layer_impl
->SetDrawsContent(true);
1435 // Contributing render pass is offset by a transform and holds a quad that
1436 // covers it entirely.
1437 RenderPassList delegated_render_passes
;
1438 // pass2 is just the size of the quad. It contributes to |pass1| with a
1439 // translation of (211,300).
1440 RenderPassId pass2_id
=
1441 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1443 AddRenderPass(&delegated_render_passes
, pass2_id
,
1444 gfx::Rect(quad_screen_rect
.size()), transform
);
1445 AddQuad(pass2
, gfx::Rect(quad_screen_rect
.size()), SK_ColorRED
);
1446 // |pass1| covers the whole layer.
1447 RenderPassId pass1_id
= RenderPassId(impl
.root_layer()->id(), 0);
1448 RenderPass
* pass1
= AddRenderPass(&delegated_render_passes
, pass1_id
,
1449 gfx::Rect(layer_size
), gfx::Transform());
1450 AddRenderPassQuad(pass1
,
1455 SkXfermode::kSrcOver_Mode
);
1456 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1457 1.f
, delegated_render_passes
);
1459 impl
.CalcDrawProps(viewport_size
);
1462 SCOPED_TRACE("No occlusion");
1466 SCOPED_TRACE("Root render pass");
1467 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1469 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1471 ASSERT_EQ(1u, pass1
->quad_list
.size());
1472 EXPECT_EQ(DrawQuad::RENDER_PASS
, pass1
->quad_list
.front()->material
);
1475 SCOPED_TRACE("Contributing render pass");
1476 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1478 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1479 pass2
->quad_list
, gfx::Rect(quad_screen_rect
.size()));
1480 ASSERT_EQ(1u, pass2
->quad_list
.size());
1481 EXPECT_EQ(DrawQuad::SOLID_COLOR
, pass2
->quad_list
.front()->material
);
1486 SCOPED_TRACE("Full occlusion");
1488 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_layer_rect());
1490 SCOPED_TRACE("Root render pass");
1491 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1493 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1
->quad_list
,
1495 EXPECT_EQ(pass1
->quad_list
.size(), 0u);
1498 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_layer_rect());
1500 SCOPED_TRACE("Contributing render pass");
1501 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1503 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass2
->quad_list
,
1505 EXPECT_EQ(pass2
->quad_list
.size(), 0u);
1510 SCOPED_TRACE("Partial occlusion");
1512 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1514 SCOPED_TRACE("Root render pass");
1515 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass1
,
1516 occlusion_in_root_target
);
1517 size_t partially_occluded_count
= 0;
1518 LayerTestCommon::VerifyQuadsAreOccluded(pass1
->quad_list
,
1519 occlusion_in_root_target
,
1520 &partially_occluded_count
);
1521 // The layer outputs one quad, which is partially occluded.
1522 EXPECT_EQ(1u, pass1
->quad_list
.size());
1523 EXPECT_EQ(1u, partially_occluded_count
);
1526 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1527 // Move the occlusion to where it is in the contributing surface.
1528 gfx::Rect occlusion_in_target_of_delegated_quad
=
1529 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1531 SCOPED_TRACE("Contributing render pass");
1532 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1533 occlusion_in_root_target
);
1534 size_t partially_occluded_count
= 0;
1535 LayerTestCommon::VerifyQuadsAreOccluded(
1536 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1537 &partially_occluded_count
);
1538 // The layer outputs one quad, which is partially occluded.
1539 EXPECT_EQ(1u, pass2
->quad_list
.size());
1540 EXPECT_EQ(1u, partially_occluded_count
);
1541 // The quad in the contributing surface is at (211,300) in the root.
1542 // The occlusion extends to 500 in the x-axis, pushing the left of the
1543 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1544 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1545 pass2
->quad_list
.front()->visible_rect
.ToString());
1548 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1549 // Move the occlusion to where it is in the contributing surface.
1550 gfx::Rect occlusion_in_target_of_delegated_quad
=
1551 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1553 SCOPED_TRACE("Contributing render pass with transformed root");
1555 gfx::Transform layer_transform
;
1556 layer_transform
.Translate(11.0, 0.0);
1557 delegated_renderer_layer_impl
->SetTransform(layer_transform
);
1558 delegated_renderer_layer_impl
->layer_tree_impl()
1560 ->needs_rebuild
= true;
1562 occlusion_in_target_of_delegated_quad
+= gfx::Vector2d(11, 0);
1564 impl
.CalcDrawProps(viewport_size
);
1566 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1567 occlusion_in_root_target
);
1568 size_t partially_occluded_count
= 0;
1569 LayerTestCommon::VerifyQuadsAreOccluded(
1570 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1571 &partially_occluded_count
);
1572 // The layer outputs one quad, which is partially occluded.
1573 EXPECT_EQ(1u, pass2
->quad_list
.size());
1574 EXPECT_EQ(1u, partially_occluded_count
);
1575 // The quad in the contributing surface is at (222,300) in the transformed
1576 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1577 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1578 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1579 pass2
->quad_list
.front()->visible_rect
.ToString());
1584 TEST_F(DelegatedRendererLayerImplTest
, DeviceScaleFactorOcclusion
) {
1585 gfx::Size
layer_size(1000, 1000);
1586 gfx::Size
viewport_size(1000, 1000);
1587 gfx::Rect
quad_screen_rect(211, 300, 400, 500);
1589 gfx::Transform transform
;
1590 transform
.Translate(211.f
, 300.f
);
1592 LayerTestCommon::LayerImplTest impl
;
1594 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1595 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1596 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1597 delegated_renderer_layer_impl
->SetDrawsContent(true);
1599 // Contributing render pass is offset by a transform and holds a quad that
1600 // covers it entirely.
1601 RenderPassList delegated_render_passes
;
1602 // pass2 is just the size of the quad. It contributes to |pass1| with a
1603 // translation of (211,300).
1604 RenderPassId pass2_id
=
1605 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1607 AddRenderPass(&delegated_render_passes
, pass2_id
,
1608 gfx::Rect(quad_screen_rect
.size()), transform
);
1609 AddQuad(pass2
, gfx::Rect(quad_screen_rect
.size()), SK_ColorRED
);
1610 // |pass1| covers the whole layer.
1611 RenderPassId pass1_id
= RenderPassId(impl
.root_layer()->id(), 0);
1612 RenderPass
* pass1
= AddRenderPass(&delegated_render_passes
, pass1_id
,
1613 gfx::Rect(layer_size
), gfx::Transform());
1614 AddRenderPassQuad(pass1
, pass2
, 0, FilterOperations(), transform
,
1615 SkXfermode::kSrcOver_Mode
);
1616 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1617 1.2f
, delegated_render_passes
);
1620 SCOPED_TRACE("Partial occlusion");
1622 gfx::Rect
occlusion_in_root_target(0, 0, 500, 1000);
1623 // Move the occlusion to where it is in the contributing surface.
1624 gfx::Rect occlusion_in_target_of_delegated_quad
=
1625 occlusion_in_root_target
- quad_screen_rect
.OffsetFromOrigin();
1627 SCOPED_TRACE("Contributing render pass");
1628 impl
.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl
, pass2
,
1629 occlusion_in_root_target
);
1630 size_t partially_occluded_count
= 0;
1631 LayerTestCommon::VerifyQuadsAreOccluded(
1632 pass2
->quad_list
, occlusion_in_target_of_delegated_quad
,
1633 &partially_occluded_count
);
1634 // The layer outputs one quad, which is partially occluded.
1635 EXPECT_EQ(1u, pass2
->quad_list
.size());
1636 EXPECT_EQ(1u, partially_occluded_count
);
1637 // The quad in the contributing surface is at (211,300) in the root.
1638 // The occlusion extends to 500 * 1.2 (dsf) = 600 in the x-axis, pushing
1639 // the left of the visible part of the quad to 600 - 211 = 400 - 11 inside
1641 EXPECT_EQ(gfx::Rect(400 - 11, 0, 11, 500).ToString(),
1642 pass2
->quad_list
.front()->visible_rect
.ToString());
1647 TEST_F(DelegatedRendererLayerImplTest
, PushPropertiesTo
) {
1648 gfx::Size
layer_size(1000, 1000);
1650 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer_impl
=
1651 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 5);
1652 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1653 delegated_renderer_layer_impl
->SetDrawsContent(true);
1655 RenderPassList delegated_render_passes
;
1656 // |pass1| covers the whole layer.
1657 RenderPassId pass1_id
= RenderPassId(5, 0);
1658 AddRenderPass(&delegated_render_passes
,
1660 gfx::Rect(layer_size
),
1662 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1663 2.f
, delegated_render_passes
);
1664 EXPECT_EQ(0.5f
, delegated_renderer_layer_impl
->inverse_device_scale_factor());
1666 scoped_ptr
<DelegatedRendererLayerImpl
> other_layer
=
1667 DelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 6);
1669 delegated_renderer_layer_impl
->PushPropertiesTo(other_layer
.get());
1671 EXPECT_EQ(0.5f
, other_layer
->inverse_device_scale_factor());