1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_layer_tree_host_impl_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_proxy.h"
16 #include "cc/test/fake_rendering_stats_instrumentation.h"
17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/test/layer_test_common.h"
19 #include "cc/test/render_pass_test_common.h"
20 #include "cc/test/render_pass_test_utils.h"
21 #include "cc/test/test_shared_bitmap_manager.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/frame_time.h"
28 #include "ui/gfx/transform.h"
33 class DelegatedRendererLayerImplTest
: public testing::Test
{
35 DelegatedRendererLayerImplTest()
37 always_impl_thread_and_main_thread_blocked_(&proxy_
) {
38 LayerTreeSettings settings
;
39 settings
.minimum_occlusion_tracking_size
= gfx::Size();
42 new FakeLayerTreeHostImpl(settings
, &proxy_
, &shared_bitmap_manager_
));
43 host_impl_
->InitializeRenderer(
44 FakeOutputSurface::Create3d().PassAs
<OutputSurface
>());
45 host_impl_
->SetViewportSize(gfx::Size(10, 10));
50 DebugScopedSetImplThreadAndMainThreadBlocked
51 always_impl_thread_and_main_thread_blocked_
;
52 TestSharedBitmapManager shared_bitmap_manager_
;
53 scoped_ptr
<LayerTreeHostImpl
> host_impl_
;
56 class DelegatedRendererLayerImplTestSimple
57 : public DelegatedRendererLayerImplTest
{
59 DelegatedRendererLayerImplTestSimple()
60 : DelegatedRendererLayerImplTest() {
61 scoped_ptr
<LayerImpl
> root_layer
= SolidColorLayerImpl::Create(
62 host_impl_
->active_tree(), 1).PassAs
<LayerImpl
>();
63 scoped_ptr
<LayerImpl
> layer_before
= SolidColorLayerImpl::Create(
64 host_impl_
->active_tree(), 2).PassAs
<LayerImpl
>();
65 scoped_ptr
<LayerImpl
> layer_after
= SolidColorLayerImpl::Create(
66 host_impl_
->active_tree(), 3).PassAs
<LayerImpl
>();
67 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
68 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 4);
70 host_impl_
->SetViewportSize(gfx::Size(100, 100));
71 root_layer
->SetBounds(gfx::Size(100, 100));
73 layer_before
->SetPosition(gfx::Point(20, 20));
74 layer_before
->SetBounds(gfx::Size(14, 14));
75 layer_before
->SetContentBounds(gfx::Size(14, 14));
76 layer_before
->SetDrawsContent(true);
77 layer_before
->SetForceRenderSurface(true);
79 layer_after
->SetPosition(gfx::Point(5, 5));
80 layer_after
->SetBounds(gfx::Size(15, 15));
81 layer_after
->SetContentBounds(gfx::Size(15, 15));
82 layer_after
->SetDrawsContent(true);
83 layer_after
->SetForceRenderSurface(true);
85 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
86 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
87 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
88 delegated_renderer_layer
->SetDrawsContent(true);
89 gfx::Transform transform
;
90 transform
.Translate(1.0, 1.0);
91 delegated_renderer_layer
->SetTransform(transform
);
93 RenderPassList delegated_render_passes
;
94 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
96 gfx::Rect(6, 6, 6, 6),
97 gfx::Transform(1, 0, 0, 1, 5, 6));
98 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
99 TestRenderPass
* pass2
= AddRenderPass(&delegated_render_passes
,
100 RenderPass::Id(9, 7),
101 gfx::Rect(7, 7, 7, 7),
102 gfx::Transform(1, 0, 0, 1, 7, 8));
103 AddQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
104 AddRenderPassQuad(pass2
, pass1
);
105 TestRenderPass
* pass3
= AddRenderPass(&delegated_render_passes
,
106 RenderPass::Id(9, 8),
107 gfx::Rect(0, 0, 8, 8),
108 gfx::Transform(1, 0, 0, 1, 9, 10));
109 AddRenderPassQuad(pass3
, pass2
);
110 delegated_renderer_layer
->SetFrameDataForRenderPasses(
111 1.f
, &delegated_render_passes
);
113 // The RenderPasses should be taken by the layer.
114 EXPECT_EQ(0u, delegated_render_passes
.size());
116 root_layer_
= root_layer
.get();
117 layer_before_
= layer_before
.get();
118 layer_after_
= layer_after
.get();
119 delegated_renderer_layer_
= delegated_renderer_layer
.get();
121 // Force the delegated RenderPasses to come before the RenderPass from
123 layer_after
->AddChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
124 root_layer
->AddChild(layer_after
.Pass());
126 // Get the RenderPass generated by layer_before to come before the delegated
128 root_layer
->AddChild(layer_before
.Pass());
129 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
133 LayerImpl
* root_layer_
;
134 LayerImpl
* layer_before_
;
135 LayerImpl
* layer_after_
;
136 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
139 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsContributingRenderPasses
) {
140 LayerTreeHostImpl::FrameData frame
;
141 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
143 // Each non-DelegatedRendererLayer added one RenderPass. The
144 // DelegatedRendererLayer added two contributing passes.
145 ASSERT_EQ(5u, frame
.render_passes
.size());
147 // The DelegatedRendererLayer should have added its contributing RenderPasses
149 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
150 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
151 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
152 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
153 // And all other RenderPasses should be non-delegated.
154 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
155 EXPECT_EQ(0, frame
.render_passes
[0]->id
.index
);
156 EXPECT_NE(4, frame
.render_passes
[3]->id
.layer_id
);
157 EXPECT_EQ(0, frame
.render_passes
[3]->id
.index
);
158 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
159 EXPECT_EQ(0, frame
.render_passes
[4]->id
.index
);
161 // The DelegatedRendererLayer should have added its RenderPasses to the frame
163 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
164 frame
.render_passes
[1]->output_rect
.ToString());
165 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
166 frame
.render_passes
[2]->output_rect
.ToString());
168 host_impl_
->DrawLayers(&frame
);
169 host_impl_
->DidDrawAllLayers(frame
);
172 TEST_F(DelegatedRendererLayerImplTestSimple
,
173 AddsQuadsToContributingRenderPasses
) {
174 LayerTreeHostImpl::FrameData frame
;
175 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
177 // Each non-DelegatedRendererLayer added one RenderPass. The
178 // DelegatedRendererLayer added two contributing passes.
179 ASSERT_EQ(5u, frame
.render_passes
.size());
181 // The DelegatedRendererLayer should have added its contributing RenderPasses
183 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
184 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
185 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
186 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
188 // The DelegatedRendererLayer should have added copies of its quads to
189 // contributing RenderPasses.
190 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
191 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
192 frame
.render_passes
[1]->quad_list
[0]->rect
.ToString());
194 // Verify it added the right quads.
195 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
196 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
197 frame
.render_passes
[2]->quad_list
[0]->rect
.ToString());
198 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
199 frame
.render_passes
[2]->quad_list
[1]->rect
.ToString());
200 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
201 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
202 frame
.render_passes
[1]->quad_list
[0]->rect
.ToString());
204 host_impl_
->DrawLayers(&frame
);
205 host_impl_
->DidDrawAllLayers(frame
);
208 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsQuadsToTargetRenderPass
) {
209 LayerTreeHostImpl::FrameData frame
;
210 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
212 // Each non-DelegatedRendererLayer added one RenderPass. The
213 // DelegatedRendererLayer added two contributing passes.
214 ASSERT_EQ(5u, frame
.render_passes
.size());
216 // The layer's target is the RenderPass from layer_after_.
217 EXPECT_EQ(RenderPass::Id(3, 0), frame
.render_passes
[3]->id
);
219 // The DelegatedRendererLayer should have added copies of quads in its root
220 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
221 ASSERT_EQ(2u, frame
.render_passes
[3]->quad_list
.size());
223 // Verify it added the right quads.
224 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
225 frame
.render_passes
[3]->quad_list
[0]->rect
.ToString());
227 // Its target layer should have a quad as well.
228 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
229 frame
.render_passes
[3]->quad_list
[1]->rect
.ToString());
231 host_impl_
->DrawLayers(&frame
);
232 host_impl_
->DidDrawAllLayers(frame
);
235 TEST_F(DelegatedRendererLayerImplTestSimple
,
236 QuadsFromRootRenderPassAreModifiedForTheTarget
) {
237 LayerTreeHostImpl::FrameData frame
;
238 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
240 // Each non-DelegatedRendererLayer added one RenderPass. The
241 // DelegatedRendererLayer added two contributing passes.
242 ASSERT_EQ(5u, frame
.render_passes
.size());
244 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
245 // has a translation transform of 1,1. So its root RenderPass' quads should
246 // all be transformed by that combined amount.
247 gfx::Transform transform
;
248 transform
.Translate(4.0, 4.0);
249 EXPECT_TRANSFORMATION_MATRIX_EQ(
250 transform
, frame
.render_passes
[3]->quad_list
[0]->quadTransform());
252 // Quads from non-root RenderPasses should not be shifted though.
253 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
254 EXPECT_TRANSFORMATION_MATRIX_EQ(
255 gfx::Transform(), frame
.render_passes
[2]->quad_list
[0]->quadTransform());
256 EXPECT_TRANSFORMATION_MATRIX_EQ(
257 gfx::Transform(), frame
.render_passes
[2]->quad_list
[1]->quadTransform());
258 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
259 EXPECT_TRANSFORMATION_MATRIX_EQ(
260 gfx::Transform(), frame
.render_passes
[1]->quad_list
[0]->quadTransform());
262 host_impl_
->DrawLayers(&frame
);
263 host_impl_
->DidDrawAllLayers(frame
);
266 TEST_F(DelegatedRendererLayerImplTestSimple
, RenderPassTransformIsModified
) {
267 LayerTreeHostImpl::FrameData frame
;
268 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
270 // The delegated layer has a surface between it and the root.
271 EXPECT_TRUE(delegated_renderer_layer_
->render_target()->parent());
273 // Each non-DelegatedRendererLayer added one RenderPass. The
274 // DelegatedRendererLayer added two contributing passes.
275 ASSERT_EQ(5u, frame
.render_passes
.size());
277 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
278 // render pass' transforms to the root should be shifted by this amount.
279 gfx::Transform transform
;
280 transform
.Translate(9.0, 9.0);
282 // The first contributing surface has a translation of 5, 6.
283 gfx::Transform
five_six(1, 0, 0, 1, 5, 6);
285 // The second contributing surface has a translation of 7, 8.
286 gfx::Transform
seven_eight(1, 0, 0, 1, 7, 8);
288 EXPECT_TRANSFORMATION_MATRIX_EQ(
289 transform
* five_six
, frame
.render_passes
[1]->transform_to_root_target
);
290 EXPECT_TRANSFORMATION_MATRIX_EQ(
291 transform
* seven_eight
,
292 frame
.render_passes
[2]->transform_to_root_target
);
294 host_impl_
->DrawLayers(&frame
);
295 host_impl_
->DidDrawAllLayers(frame
);
298 TEST_F(DelegatedRendererLayerImplTestSimple
, DoesNotOwnARenderSurface
) {
299 LayerTreeHostImpl::FrameData frame
;
300 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
302 // If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
303 // has no need to be a RenderSurface for the quads it carries.
304 EXPECT_FALSE(delegated_renderer_layer_
->render_surface());
306 host_impl_
->DrawLayers(&frame
);
307 host_impl_
->DidDrawAllLayers(frame
);
310 TEST_F(DelegatedRendererLayerImplTestSimple
, DoesOwnARenderSurfaceForOpacity
) {
311 delegated_renderer_layer_
->SetOpacity(0.5f
);
313 LayerTreeHostImpl::FrameData frame
;
314 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
316 // This test case has quads from multiple layers in the delegated renderer, so
317 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
319 EXPECT_TRUE(delegated_renderer_layer_
->render_surface());
321 host_impl_
->DrawLayers(&frame
);
322 host_impl_
->DidDrawAllLayers(frame
);
325 TEST_F(DelegatedRendererLayerImplTestSimple
,
326 DoesOwnARenderSurfaceForTransform
) {
327 gfx::Transform rotation
;
328 rotation
.RotateAboutZAxis(30.0);
329 delegated_renderer_layer_
->SetTransform(rotation
);
331 LayerTreeHostImpl::FrameData frame
;
332 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
334 // This test case has quads from multiple layers in the delegated renderer, so
335 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
337 EXPECT_TRUE(delegated_renderer_layer_
->render_surface());
339 host_impl_
->DrawLayers(&frame
);
340 host_impl_
->DidDrawAllLayers(frame
);
343 class DelegatedRendererLayerImplTestOwnSurface
344 : public DelegatedRendererLayerImplTestSimple
{
346 DelegatedRendererLayerImplTestOwnSurface()
347 : DelegatedRendererLayerImplTestSimple() {
348 delegated_renderer_layer_
->SetForceRenderSurface(true);
352 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsRenderPasses
) {
353 LayerTreeHostImpl::FrameData frame
;
354 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
356 // Each non-DelegatedRendererLayer added one RenderPass. The
357 // DelegatedRendererLayer added two contributing passes and its owned surface
359 ASSERT_EQ(6u, frame
.render_passes
.size());
361 // The DelegatedRendererLayer should have added its contributing RenderPasses
363 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
364 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
365 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
366 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
367 // The DelegatedRendererLayer should have added a RenderPass for its surface
369 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
370 EXPECT_EQ(0, frame
.render_passes
[3]->id
.index
);
371 // And all other RenderPasses should be non-delegated.
372 EXPECT_NE(4, frame
.render_passes
[0]->id
.layer_id
);
373 EXPECT_EQ(0, frame
.render_passes
[0]->id
.index
);
374 EXPECT_NE(4, frame
.render_passes
[4]->id
.layer_id
);
375 EXPECT_EQ(0, frame
.render_passes
[4]->id
.index
);
376 EXPECT_NE(4, frame
.render_passes
[5]->id
.layer_id
);
377 EXPECT_EQ(0, frame
.render_passes
[5]->id
.index
);
379 // The DelegatedRendererLayer should have added its RenderPasses to the frame
381 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
382 frame
.render_passes
[1]->output_rect
.ToString());
383 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
384 frame
.render_passes
[2]->output_rect
.ToString());
386 host_impl_
->DrawLayers(&frame
);
387 host_impl_
->DidDrawAllLayers(frame
);
390 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
391 AddsQuadsToContributingRenderPasses
) {
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 and its owned surface
398 ASSERT_EQ(6u, frame
.render_passes
.size());
400 // The DelegatedRendererLayer should have added its contributing RenderPasses
402 EXPECT_EQ(4, frame
.render_passes
[1]->id
.layer_id
);
403 EXPECT_EQ(1, frame
.render_passes
[1]->id
.index
);
404 EXPECT_EQ(4, frame
.render_passes
[2]->id
.layer_id
);
405 EXPECT_EQ(2, frame
.render_passes
[2]->id
.index
);
407 // The DelegatedRendererLayer should have added copies of its quads to
408 // contributing RenderPasses.
409 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
410 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
411 frame
.render_passes
[1]->quad_list
[0]->rect
.ToString());
413 // Verify it added the right quads.
414 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
415 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
416 frame
.render_passes
[2]->quad_list
[0]->rect
.ToString());
417 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
418 frame
.render_passes
[2]->quad_list
[1]->rect
.ToString());
419 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
420 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
421 frame
.render_passes
[1]->quad_list
[0]->rect
.ToString());
423 host_impl_
->DrawLayers(&frame
);
424 host_impl_
->DidDrawAllLayers(frame
);
427 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsQuadsToTargetRenderPass
) {
428 LayerTreeHostImpl::FrameData frame
;
429 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
431 // Each non-DelegatedRendererLayer added one RenderPass. The
432 // DelegatedRendererLayer added two contributing passes and its owned surface
434 ASSERT_EQ(6u, frame
.render_passes
.size());
436 // The layer's target is the RenderPass owned by itself.
437 EXPECT_EQ(RenderPass::Id(4, 0), frame
.render_passes
[3]->id
);
439 // The DelegatedRendererLayer should have added copies of quads in its root
440 // RenderPass to its target RenderPass.
441 // The layer_after also adds one quad.
442 ASSERT_EQ(1u, frame
.render_passes
[3]->quad_list
.size());
444 // Verify it added the right quads.
445 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
446 frame
.render_passes
[3]->quad_list
[0]->rect
.ToString());
448 host_impl_
->DrawLayers(&frame
);
449 host_impl_
->DidDrawAllLayers(frame
);
452 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
453 QuadsFromRootRenderPassAreNotModifiedForTheTarget
) {
454 LayerTreeHostImpl::FrameData frame
;
455 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
457 // Each non-DelegatedRendererLayer added one RenderPass. The
458 // DelegatedRendererLayer added two contributing passes and its owned surface
460 ASSERT_EQ(6u, frame
.render_passes
.size());
462 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
463 // RenderPass' quads do not need to be translated at all.
464 EXPECT_TRANSFORMATION_MATRIX_EQ(
465 gfx::Transform(), frame
.render_passes
[3]->quad_list
[0]->quadTransform());
467 // Quads from non-root RenderPasses should not be shifted either.
468 ASSERT_EQ(2u, frame
.render_passes
[2]->quad_list
.size());
469 EXPECT_TRANSFORMATION_MATRIX_EQ(
470 gfx::Transform(), frame
.render_passes
[2]->quad_list
[0]->quadTransform());
471 EXPECT_TRANSFORMATION_MATRIX_EQ(
472 gfx::Transform(), frame
.render_passes
[2]->quad_list
[1]->quadTransform());
473 ASSERT_EQ(1u, frame
.render_passes
[1]->quad_list
.size());
474 EXPECT_TRANSFORMATION_MATRIX_EQ(
475 gfx::Transform(), frame
.render_passes
[1]->quad_list
[0]->quadTransform());
477 host_impl_
->DrawLayers(&frame
);
478 host_impl_
->DidDrawAllLayers(frame
);
481 class DelegatedRendererLayerImplTestTransform
482 : public DelegatedRendererLayerImplTest
{
484 DelegatedRendererLayerImplTestTransform()
485 : root_delegated_render_pass_is_clipped_(false),
486 delegated_device_scale_factor_(2.f
) {}
489 host_impl_
->SetDeviceScaleFactor(2.f
);
491 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::Create(
492 host_impl_
->active_tree(), 1);
493 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
494 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
496 host_impl_
->SetViewportSize(gfx::Size(200, 200));
497 root_layer
->SetBounds(gfx::Size(100, 100));
499 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
500 delegated_renderer_layer
->SetBounds(gfx::Size(75, 75));
501 delegated_renderer_layer
->SetContentBounds(gfx::Size(75, 75));
502 delegated_renderer_layer
->SetDrawsContent(true);
503 gfx::Transform transform
;
504 transform
.Scale(2.0, 2.0);
505 transform
.Translate(8.0, 8.0);
506 delegated_renderer_layer
->SetTransform(transform
);
508 RenderPassList delegated_render_passes
;
510 gfx::Size
child_pass_content_bounds(7, 7);
511 gfx::Rect
child_pass_rect(20, 20, 7, 7);
512 gfx::Transform child_pass_transform
;
513 child_pass_transform
.Scale(0.8f
, 0.8f
);
514 child_pass_transform
.Translate(9.0, 9.0);
515 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
516 bool child_pass_clipped
= false;
519 TestRenderPass
* pass
= AddRenderPass(
520 &delegated_render_passes
,
521 RenderPass::Id(10, 7),
524 SharedQuadState
* shared_quad_state
=
525 pass
->CreateAndAppendSharedQuadState();
526 shared_quad_state
->SetAll(child_pass_transform
,
527 child_pass_content_bounds
,
529 child_pass_clip_rect
,
532 SkXfermode::kSrcOver_Mode
,
535 SolidColorDrawQuad
* color_quad
;
536 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
537 color_quad
->SetNew(shared_quad_state
,
538 gfx::Rect(20, 20, 3, 7),
539 gfx::Rect(20, 20, 3, 7),
543 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
544 color_quad
->SetNew(shared_quad_state
,
545 gfx::Rect(23, 20, 4, 7),
546 gfx::Rect(23, 20, 4, 7),
551 gfx::Size
root_pass_content_bounds(100, 100);
552 gfx::Rect
root_pass_rect(0, 0, 100, 100);
553 gfx::Transform root_pass_transform
;
554 root_pass_transform
.Scale(1.5, 1.5);
555 root_pass_transform
.Translate(7.0, 7.0);
556 gfx::Rect
root_pass_clip_rect(10, 10, 35, 35);
557 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
559 TestRenderPass
* pass
= AddRenderPass(
560 &delegated_render_passes
,
561 RenderPass::Id(9, 6),
564 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
565 shared_quad_state
->SetAll(root_pass_transform
,
566 root_pass_content_bounds
,
571 SkXfermode::kSrcOver_Mode
,
574 RenderPassDrawQuad
* render_pass_quad
=
575 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
576 render_pass_quad
->SetNew(
578 gfx::Rect(5, 5, 7, 7), // quad_rect
579 gfx::Rect(5, 5, 7, 7), // visible_rect
580 RenderPass::Id(10, 7), // render_pass_id
582 0, // mask_resource_id
583 child_pass_rect
, // contents_changed_since_last_frame
584 gfx::RectF(), // mask_uv_rect
585 FilterOperations(), // filters
586 FilterOperations()); // background_filters
588 SolidColorDrawQuad
* color_quad
;
589 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
590 color_quad
->SetNew(shared_quad_state
,
591 gfx::Rect(0, 0, 10, 10),
592 gfx::Rect(0, 0, 10, 10),
596 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
597 color_quad
->SetNew(shared_quad_state
,
598 gfx::Rect(0, 10, 10, 10),
599 gfx::Rect(0, 10, 10, 10),
603 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
604 color_quad
->SetNew(shared_quad_state
,
605 gfx::Rect(10, 0, 10, 10),
606 gfx::Rect(10, 0, 10, 10),
610 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
611 color_quad
->SetNew(shared_quad_state
,
612 gfx::Rect(10, 10, 10, 10),
613 gfx::Rect(10, 10, 10, 10),
617 delegated_renderer_layer
->SetFrameDataForRenderPasses(
618 delegated_device_scale_factor_
, &delegated_render_passes
);
620 // The RenderPasses should be taken by the layer.
621 EXPECT_EQ(0u, delegated_render_passes
.size());
623 root_layer_
= root_layer
.get();
624 delegated_renderer_layer_
= delegated_renderer_layer
.get();
626 root_layer
->AddChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
627 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
630 void VerifyRenderPasses(
631 const LayerTreeHostImpl::FrameData
& frame
,
632 size_t num_render_passes
,
633 const SharedQuadState
** root_delegated_shared_quad_state
,
634 const SharedQuadState
** contrib_delegated_shared_quad_state
) {
635 ASSERT_EQ(num_render_passes
, frame
.render_passes
.size());
636 // The contributing render pass in the DelegatedRendererLayer.
637 EXPECT_EQ(2, frame
.render_passes
[0]->id
.layer_id
);
638 EXPECT_EQ(1, frame
.render_passes
[0]->id
.index
);
639 // The root render pass.
640 EXPECT_EQ(1, frame
.render_passes
.back()->id
.layer_id
);
641 EXPECT_EQ(0, frame
.render_passes
.back()->id
.index
);
643 const QuadList
& contrib_delegated_quad_list
=
644 frame
.render_passes
[0]->quad_list
;
645 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
647 const QuadList
& root_delegated_quad_list
=
648 frame
.render_passes
[1]->quad_list
;
649 ASSERT_EQ(5u, root_delegated_quad_list
.size());
651 // All quads in a render pass should share the same state.
652 *contrib_delegated_shared_quad_state
=
653 contrib_delegated_quad_list
[0]->shared_quad_state
;
654 EXPECT_EQ(*contrib_delegated_shared_quad_state
,
655 contrib_delegated_quad_list
[1]->shared_quad_state
);
657 *root_delegated_shared_quad_state
=
658 root_delegated_quad_list
[0]->shared_quad_state
;
659 EXPECT_EQ(*root_delegated_shared_quad_state
,
660 root_delegated_quad_list
[1]->shared_quad_state
);
661 EXPECT_EQ(*root_delegated_shared_quad_state
,
662 root_delegated_quad_list
[2]->shared_quad_state
);
663 EXPECT_EQ(*root_delegated_shared_quad_state
,
664 root_delegated_quad_list
[3]->shared_quad_state
);
665 EXPECT_EQ(*root_delegated_shared_quad_state
,
666 root_delegated_quad_list
[4]->shared_quad_state
);
668 EXPECT_NE(*contrib_delegated_shared_quad_state
,
669 *root_delegated_shared_quad_state
);
673 LayerImpl
* root_layer_
;
674 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
675 bool root_delegated_render_pass_is_clipped_
;
676 float delegated_device_scale_factor_
;
679 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_NoSurface
) {
680 root_delegated_render_pass_is_clipped_
= false;
683 LayerTreeHostImpl::FrameData frame
;
684 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
686 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
687 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
691 &root_delegated_shared_quad_state
,
692 &contrib_delegated_shared_quad_state
);
694 // When the quads don't have a clip of their own, the clip rect is set to
695 // the drawable_content_rect of the delegated renderer layer.
696 EXPECT_EQ(delegated_renderer_layer_
->drawable_content_rect().ToString(),
697 root_delegated_shared_quad_state
->clip_rect
.ToString());
699 // Even though the quads in the root pass have no clip of their own, they
700 // inherit the clip rect from the delegated renderer layer if it does not
702 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
704 gfx::Transform expected
;
705 // Device scale factor.
706 expected
.Scale(2.0, 2.0);
707 // This is the transform from the layer's space to its target.
708 expected
.Translate(20, 20);
709 expected
.Scale(2.0, 2.0);
710 expected
.Translate(8.0, 8.0);
711 // This is the transform within the source frame.
712 // Inverse device scale factor to go from physical space to layer space.
713 expected
.Scale(0.5, 0.5);
714 expected
.Scale(1.5, 1.5);
715 expected
.Translate(7.0, 7.0);
716 EXPECT_TRANSFORMATION_MATRIX_EQ(
717 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
719 // The contributing render pass should not be transformed from its input.
720 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
721 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
722 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
723 expected
.MakeIdentity();
724 expected
.Scale(0.8f
, 0.8f
);
725 expected
.Translate(9.0, 9.0);
726 EXPECT_TRANSFORMATION_MATRIX_EQ(
728 contrib_delegated_shared_quad_state
->content_to_target_transform
);
730 host_impl_
->DrawLayers(&frame
);
731 host_impl_
->DidDrawAllLayers(frame
);
734 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_NoSurface
) {
735 root_delegated_render_pass_is_clipped_
= true;
738 LayerTreeHostImpl::FrameData frame
;
739 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
741 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
742 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
746 &root_delegated_shared_quad_state
,
747 &contrib_delegated_shared_quad_state
);
749 // Since the quads have a clip_rect it should be modified by delegated
750 // renderer layer's draw_transform.
751 // The position of the resulting clip_rect is:
752 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
753 // layer scale (2) + layer position (20) = 46
754 // The device scale is 2, so everything gets doubled, giving 92.
756 // The size is 35x35 scaled by the device scale.
757 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
758 root_delegated_shared_quad_state
->clip_rect
.ToString());
760 // The quads had a clip and it should be preserved.
761 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
763 gfx::Transform expected
;
764 // Device scale factor.
765 expected
.Scale(2.0, 2.0);
766 // This is the transform from the layer's space to its target.
767 expected
.Translate(20, 20);
768 expected
.Scale(2.0, 2.0);
769 expected
.Translate(8.0, 8.0);
770 // This is the transform within the source frame.
771 // Inverse device scale factor to go from physical space to layer space.
772 expected
.Scale(0.5, 0.5);
773 expected
.Scale(1.5, 1.5);
774 expected
.Translate(7.0, 7.0);
775 EXPECT_TRANSFORMATION_MATRIX_EQ(
776 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
778 // The contributing render pass should not be transformed from its input.
779 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
780 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
781 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
782 expected
.MakeIdentity();
783 expected
.Scale(0.8f
, 0.8f
);
784 expected
.Translate(9.0, 9.0);
785 EXPECT_TRANSFORMATION_MATRIX_EQ(
787 contrib_delegated_shared_quad_state
->content_to_target_transform
);
789 host_impl_
->DrawLayers(&frame
);
790 host_impl_
->DidDrawAllLayers(frame
);
793 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_Surface
) {
794 root_delegated_render_pass_is_clipped_
= false;
797 delegated_renderer_layer_
->SetForceRenderSurface(true);
799 LayerTreeHostImpl::FrameData frame
;
800 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
802 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
803 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
807 &root_delegated_shared_quad_state
,
808 &contrib_delegated_shared_quad_state
);
810 // When the layer owns a surface, then its position and translation are not
811 // a part of its draw transform.
812 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
813 root_delegated_shared_quad_state
->clip_rect
.ToString());
815 // Since the layer owns a surface it doesn't need to clip its quads, so
816 // unclipped quads remain unclipped.
817 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
819 gfx::Transform expected
;
820 // This is the transform within the source frame.
821 expected
.Scale(1.5, 1.5);
822 expected
.Translate(7.0, 7.0);
823 EXPECT_TRANSFORMATION_MATRIX_EQ(
824 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
826 // The contributing render pass should not be transformed from its input.
827 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
828 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
829 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
830 expected
.MakeIdentity();
831 expected
.Scale(0.8f
, 0.8f
);
832 expected
.Translate(9.0, 9.0);
833 EXPECT_TRANSFORMATION_MATRIX_EQ(
835 contrib_delegated_shared_quad_state
->content_to_target_transform
);
837 host_impl_
->DrawLayers(&frame
);
838 host_impl_
->DidDrawAllLayers(frame
);
841 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_Surface
) {
842 root_delegated_render_pass_is_clipped_
= true;
845 delegated_renderer_layer_
->SetForceRenderSurface(true);
847 LayerTreeHostImpl::FrameData frame
;
848 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
850 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
851 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
855 &root_delegated_shared_quad_state
,
856 &contrib_delegated_shared_quad_state
);
858 // When the layer owns a surface, then its position and translation are not
859 // a part of its draw transform. The clip_rect should be preserved.
860 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
861 root_delegated_shared_quad_state
->clip_rect
.ToString());
863 // The quads had a clip and it should be preserved.
864 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
866 gfx::Transform expected
;
867 // This is the transform within the source frame.
868 expected
.Scale(1.5, 1.5);
869 expected
.Translate(7.0, 7.0);
870 EXPECT_TRANSFORMATION_MATRIX_EQ(
871 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
873 // The contributing render pass should not be transformed from its input.
874 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
875 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
876 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
877 expected
.MakeIdentity();
878 expected
.Scale(0.8f
, 0.8f
);
879 expected
.Translate(9.0, 9.0);
880 EXPECT_TRANSFORMATION_MATRIX_EQ(
882 contrib_delegated_shared_quad_state
->content_to_target_transform
);
884 host_impl_
->DrawLayers(&frame
);
885 host_impl_
->DidDrawAllLayers(frame
);
888 TEST_F(DelegatedRendererLayerImplTestTransform
, MismatchedDeviceScaleFactor
) {
889 root_delegated_render_pass_is_clipped_
= true;
890 delegated_device_scale_factor_
= 1.3f
;
894 LayerTreeHostImpl::FrameData frame
;
895 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
897 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
898 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
899 VerifyRenderPasses(frame
,
901 &root_delegated_shared_quad_state
,
902 &contrib_delegated_shared_quad_state
);
904 // The parent tree's device scale factor is 2.0, but the child has submitted a
905 // frame with a device scale factor of 1.3. Absent any better option, the
906 // only thing we can do is scale from 1.3 -> 2.0.
908 gfx::Transform expected
;
909 // Device scale factor (from parent).
910 expected
.Scale(2.0, 2.0);
911 // This is the transform from the layer's space to its target.
912 expected
.Translate(20, 20);
913 expected
.Scale(2.0, 2.0);
914 expected
.Translate(8.0, 8.0);
915 // This is the transform within the source frame.
916 // Inverse device scale factor (from child).
917 expected
.Scale(1.0f
/ 1.3f
, 1.0f
/ 1.3f
);
918 expected
.Scale(1.5, 1.5);
919 expected
.Translate(7.0, 7.0);
920 EXPECT_TRANSFORMATION_MATRIX_EQ(
921 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
923 host_impl_
->DrawLayers(&frame
);
924 host_impl_
->DidDrawAllLayers(frame
);
927 class DelegatedRendererLayerImplTestClip
928 : public DelegatedRendererLayerImplTest
{
931 scoped_ptr
<LayerImpl
> root_layer
=
932 LayerImpl::Create(host_impl_
->active_tree(), 1);
933 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
934 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 2);
935 scoped_ptr
<LayerImpl
> clip_layer
=
936 LayerImpl::Create(host_impl_
->active_tree(), 3);
937 scoped_ptr
<LayerImpl
> origin_layer
=
938 LayerImpl::Create(host_impl_
->active_tree(), 4);
940 host_impl_
->SetViewportSize(gfx::Size(100, 100));
941 root_layer
->SetBounds(gfx::Size(100, 100));
943 delegated_renderer_layer
->SetPosition(gfx::Point(20, 20));
944 delegated_renderer_layer
->SetBounds(gfx::Size(50, 50));
945 delegated_renderer_layer
->SetContentBounds(gfx::Size(50, 50));
946 delegated_renderer_layer
->SetDrawsContent(true);
948 RenderPassList delegated_render_passes
;
950 gfx::Size
child_pass_content_bounds(7, 7);
951 gfx::Rect
child_pass_rect(20, 20, 7, 7);
952 gfx::Transform child_pass_transform
;
953 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
954 bool child_pass_clipped
= false;
957 TestRenderPass
* pass
= AddRenderPass(
958 &delegated_render_passes
,
959 RenderPass::Id(10, 7),
962 SharedQuadState
* shared_quad_state
=
963 pass
->CreateAndAppendSharedQuadState();
964 shared_quad_state
->SetAll(child_pass_transform
,
965 child_pass_content_bounds
,
967 child_pass_clip_rect
,
970 SkXfermode::kSrcOver_Mode
,
973 SolidColorDrawQuad
* color_quad
;
974 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
975 color_quad
->SetNew(shared_quad_state
,
976 gfx::Rect(20, 20, 3, 7),
977 gfx::Rect(20, 20, 3, 7),
981 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
982 color_quad
->SetNew(shared_quad_state
,
983 gfx::Rect(23, 20, 4, 7),
984 gfx::Rect(23, 20, 4, 7),
989 gfx::Size
root_pass_content_bounds(50, 50);
990 gfx::Rect
root_pass_rect(0, 0, 50, 50);
991 gfx::Transform root_pass_transform
;
992 gfx::Rect
root_pass_clip_rect(5, 5, 40, 40);
993 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
995 TestRenderPass
* pass
= AddRenderPass(
996 &delegated_render_passes
,
997 RenderPass::Id(9, 6),
1000 SharedQuadState
* shared_quad_state
= pass
->CreateAndAppendSharedQuadState();
1001 shared_quad_state
->SetAll(root_pass_transform
,
1002 root_pass_content_bounds
,
1004 root_pass_clip_rect
,
1007 SkXfermode::kSrcOver_Mode
,
1010 RenderPassDrawQuad
* render_pass_quad
=
1011 pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1012 render_pass_quad
->SetNew(
1014 gfx::Rect(5, 5, 7, 7), // quad_rect
1015 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1016 RenderPass::Id(10, 7), // render_pass_id
1017 false, // is_replica
1018 0, // mask_resource_id
1019 child_pass_rect
, // contents_changed_since_last_frame
1020 gfx::RectF(), // mask_uv_rect
1021 FilterOperations(), // filters
1022 FilterOperations()); // background_filters
1024 SolidColorDrawQuad
* color_quad
;
1025 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1026 color_quad
->SetNew(shared_quad_state
,
1027 gfx::Rect(0, 0, 10, 10),
1028 gfx::Rect(0, 0, 10, 10),
1032 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1033 color_quad
->SetNew(shared_quad_state
,
1034 gfx::Rect(0, 10, 10, 10),
1035 gfx::Rect(0, 10, 10, 10),
1039 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1040 color_quad
->SetNew(shared_quad_state
,
1041 gfx::Rect(10, 0, 10, 10),
1042 gfx::Rect(10, 0, 10, 10),
1046 color_quad
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1047 color_quad
->SetNew(shared_quad_state
,
1048 gfx::Rect(10, 10, 10, 10),
1049 gfx::Rect(10, 10, 10, 10),
1053 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1054 1.f
, &delegated_render_passes
);
1056 // The RenderPasses should be taken by the layer.
1057 EXPECT_EQ(0u, delegated_render_passes
.size());
1059 root_layer_
= root_layer
.get();
1060 delegated_renderer_layer_
= delegated_renderer_layer
.get();
1062 if (clip_delegated_renderer_layer_
) {
1063 gfx::Rect
clip_rect(21, 27, 23, 21);
1065 clip_layer
->SetPosition(clip_rect
.origin());
1066 clip_layer
->SetBounds(clip_rect
.size());
1067 clip_layer
->SetContentBounds(clip_rect
.size());
1068 clip_layer
->SetMasksToBounds(true);
1070 origin_layer
->SetPosition(
1071 gfx::PointAtOffsetFromOrigin(-clip_rect
.OffsetFromOrigin()));
1073 origin_layer
->AddChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
1074 clip_layer
->AddChild(origin_layer
.Pass());
1075 root_layer
->AddChild(clip_layer
.Pass());
1077 root_layer
->AddChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
1080 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1084 LayerImpl
* root_layer_
;
1085 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
1086 bool root_delegated_render_pass_is_clipped_
;
1087 bool clip_delegated_renderer_layer_
;
1090 TEST_F(DelegatedRendererLayerImplTestClip
,
1091 QuadsUnclipped_LayerUnclipped_NoSurface
) {
1092 root_delegated_render_pass_is_clipped_
= false;
1093 clip_delegated_renderer_layer_
= false;
1096 LayerTreeHostImpl::FrameData frame
;
1097 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1099 ASSERT_EQ(2u, frame
.render_passes
.size());
1100 const QuadList
& contrib_delegated_quad_list
=
1101 frame
.render_passes
[0]->quad_list
;
1102 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1103 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1104 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1105 const SharedQuadState
* root_delegated_shared_quad_state
=
1106 root_delegated_quad_list
[0]->shared_quad_state
;
1108 // When the quads don't have a clip of their own, the clip rect is set to
1109 // the drawable_content_rect of the delegated renderer layer.
1110 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1111 root_delegated_shared_quad_state
->clip_rect
.ToString());
1112 // Quads are clipped to the delegated renderer layer.
1113 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1115 host_impl_
->DrawLayers(&frame
);
1116 host_impl_
->DidDrawAllLayers(frame
);
1119 TEST_F(DelegatedRendererLayerImplTestClip
,
1120 QuadsClipped_LayerUnclipped_NoSurface
) {
1121 root_delegated_render_pass_is_clipped_
= true;
1122 clip_delegated_renderer_layer_
= false;
1125 LayerTreeHostImpl::FrameData frame
;
1126 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1128 ASSERT_EQ(2u, frame
.render_passes
.size());
1129 const QuadList
& contrib_delegated_quad_list
=
1130 frame
.render_passes
[0]->quad_list
;
1131 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1132 const QuadList
& root_delegated_quad_list
=
1133 frame
.render_passes
[1]->quad_list
;
1134 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1135 const SharedQuadState
* root_delegated_shared_quad_state
=
1136 root_delegated_quad_list
[0]->shared_quad_state
;
1138 // When the quads have a clip of their own, it is used.
1139 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1140 root_delegated_shared_quad_state
->clip_rect
.ToString());
1141 // Quads came with a clip rect.
1142 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1144 host_impl_
->DrawLayers(&frame
);
1145 host_impl_
->DidDrawAllLayers(frame
);
1148 TEST_F(DelegatedRendererLayerImplTestClip
,
1149 QuadsUnclipped_LayerClipped_NoSurface
) {
1150 root_delegated_render_pass_is_clipped_
= false;
1151 clip_delegated_renderer_layer_
= true;
1154 LayerTreeHostImpl::FrameData frame
;
1155 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1157 ASSERT_EQ(2u, frame
.render_passes
.size());
1158 const QuadList
& contrib_delegated_quad_list
=
1159 frame
.render_passes
[0]->quad_list
;
1160 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1161 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1162 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1163 const SharedQuadState
* root_delegated_shared_quad_state
=
1164 root_delegated_quad_list
[0]->shared_quad_state
;
1166 // When the quads don't have a clip of their own, the clip rect is set to
1167 // the drawable_content_rect of the delegated renderer layer. When the layer
1168 // is clipped, that should be seen in the quads' clip_rect.
1169 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1170 root_delegated_shared_quad_state
->clip_rect
.ToString());
1171 // Quads are clipped to the delegated renderer layer.
1172 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1174 host_impl_
->DrawLayers(&frame
);
1175 host_impl_
->DidDrawAllLayers(frame
);
1178 TEST_F(DelegatedRendererLayerImplTestClip
,
1179 QuadsClipped_LayerClipped_NoSurface
) {
1180 root_delegated_render_pass_is_clipped_
= true;
1181 clip_delegated_renderer_layer_
= true;
1184 LayerTreeHostImpl::FrameData frame
;
1185 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1187 ASSERT_EQ(2u, frame
.render_passes
.size());
1188 const QuadList
& contrib_delegated_quad_list
=
1189 frame
.render_passes
[0]->quad_list
;
1190 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1191 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1192 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1193 const SharedQuadState
* root_delegated_shared_quad_state
=
1194 root_delegated_quad_list
[0]->shared_quad_state
;
1196 // When the quads have a clip of their own, it is used, but it is
1197 // combined with the clip rect of the delegated renderer layer.
1198 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1199 root_delegated_shared_quad_state
->clip_rect
.ToString());
1200 // Quads came with a clip rect.
1201 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1203 host_impl_
->DrawLayers(&frame
);
1204 host_impl_
->DidDrawAllLayers(frame
);
1207 TEST_F(DelegatedRendererLayerImplTestClip
,
1208 QuadsUnclipped_LayerUnclipped_Surface
) {
1209 root_delegated_render_pass_is_clipped_
= false;
1210 clip_delegated_renderer_layer_
= false;
1213 delegated_renderer_layer_
->SetForceRenderSurface(true);
1215 LayerTreeHostImpl::FrameData frame
;
1216 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1218 ASSERT_EQ(3u, 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
= frame
.render_passes
[1]->quad_list
;
1223 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1224 const SharedQuadState
* root_delegated_shared_quad_state
=
1225 root_delegated_quad_list
[0]->shared_quad_state
;
1227 // When the layer owns a surface, the quads don't need to be clipped
1228 // further than they already specify. If they aren't clipped, then their
1229 // clip rect is ignored, and they are not set as clipped.
1230 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1232 host_impl_
->DrawLayers(&frame
);
1233 host_impl_
->DidDrawAllLayers(frame
);
1236 TEST_F(DelegatedRendererLayerImplTestClip
,
1237 QuadsClipped_LayerUnclipped_Surface
) {
1238 root_delegated_render_pass_is_clipped_
= true;
1239 clip_delegated_renderer_layer_
= false;
1242 delegated_renderer_layer_
->SetForceRenderSurface(true);
1244 LayerTreeHostImpl::FrameData frame
;
1245 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1247 ASSERT_EQ(3u, frame
.render_passes
.size());
1248 const QuadList
& contrib_delegated_quad_list
=
1249 frame
.render_passes
[0]->quad_list
;
1250 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1251 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1252 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1253 const SharedQuadState
* root_delegated_shared_quad_state
=
1254 root_delegated_quad_list
[0]->shared_quad_state
;
1256 // When the quads have a clip of their own, it is used.
1257 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1258 root_delegated_shared_quad_state
->clip_rect
.ToString());
1259 // Quads came with a clip rect.
1260 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1262 host_impl_
->DrawLayers(&frame
);
1263 host_impl_
->DidDrawAllLayers(frame
);
1266 TEST_F(DelegatedRendererLayerImplTestClip
,
1267 QuadsUnclipped_LayerClipped_Surface
) {
1268 root_delegated_render_pass_is_clipped_
= false;
1269 clip_delegated_renderer_layer_
= true;
1272 delegated_renderer_layer_
->SetForceRenderSurface(true);
1274 LayerTreeHostImpl::FrameData frame
;
1275 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1277 ASSERT_EQ(3u, frame
.render_passes
.size());
1278 const QuadList
& contrib_delegated_quad_list
=
1279 frame
.render_passes
[0]->quad_list
;
1280 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1281 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1282 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1283 const SharedQuadState
* root_delegated_shared_quad_state
=
1284 root_delegated_quad_list
[0]->shared_quad_state
;
1286 // When the layer owns a surface, the quads don't need to be clipped
1287 // further than they already specify. If they aren't clipped, then their
1288 // clip rect is ignored, and they are not set as clipped.
1289 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1291 host_impl_
->DrawLayers(&frame
);
1292 host_impl_
->DidDrawAllLayers(frame
);
1295 TEST_F(DelegatedRendererLayerImplTestClip
, QuadsClipped_LayerClipped_Surface
) {
1296 root_delegated_render_pass_is_clipped_
= true;
1297 clip_delegated_renderer_layer_
= true;
1300 delegated_renderer_layer_
->SetForceRenderSurface(true);
1302 LayerTreeHostImpl::FrameData frame
;
1303 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1305 ASSERT_EQ(3u, frame
.render_passes
.size());
1306 const QuadList
& contrib_delegated_quad_list
=
1307 frame
.render_passes
[0]->quad_list
;
1308 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1309 const QuadList
& root_delegated_quad_list
= frame
.render_passes
[1]->quad_list
;
1310 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1311 const SharedQuadState
* root_delegated_shared_quad_state
=
1312 root_delegated_quad_list
[0]->shared_quad_state
;
1314 // When the quads have a clip of their own, it is used, but it is
1315 // combined with the clip rect of the delegated renderer layer. If the
1316 // layer owns a surface, then it does not have a clip rect of its own.
1317 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1318 root_delegated_shared_quad_state
->clip_rect
.ToString());
1319 // Quads came with a clip rect.
1320 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1322 host_impl_
->DrawLayers(&frame
);
1323 host_impl_
->DidDrawAllLayers(frame
);
1326 TEST_F(DelegatedRendererLayerImplTest
, InvalidRenderPassDrawQuad
) {
1327 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::Create(
1328 host_impl_
->active_tree(), 1).PassAs
<LayerImpl
>();
1329 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer
=
1330 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 4);
1332 host_impl_
->SetViewportSize(gfx::Size(100, 100));
1334 delegated_renderer_layer
->SetPosition(gfx::Point(3, 3));
1335 delegated_renderer_layer
->SetBounds(gfx::Size(10, 10));
1336 delegated_renderer_layer
->SetContentBounds(gfx::Size(10, 10));
1337 delegated_renderer_layer
->SetDrawsContent(true);
1339 RenderPassList delegated_render_passes
;
1340 TestRenderPass
* pass1
= AddRenderPass(
1341 &delegated_render_passes
,
1342 RenderPass::Id(9, 6),
1343 gfx::Rect(0, 0, 10, 10),
1345 AddQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
1347 // This render pass isn't part of the frame.
1348 scoped_ptr
<TestRenderPass
> missing_pass(TestRenderPass::Create());
1349 missing_pass
->SetNew(RenderPass::Id(9, 7),
1350 gfx::Rect(7, 7, 7, 7),
1351 gfx::Rect(7, 7, 7, 7),
1354 // But a render pass quad refers to it.
1355 AddRenderPassQuad(pass1
, missing_pass
.get());
1357 delegated_renderer_layer
->SetFrameDataForRenderPasses(
1358 1.f
, &delegated_render_passes
);
1360 // The RenderPasses should be taken by the layer.
1361 EXPECT_EQ(0u, delegated_render_passes
.size());
1363 root_layer
->AddChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
1364 host_impl_
->active_tree()->SetRootLayer(root_layer
.Pass());
1366 LayerTreeHostImpl::FrameData frame
;
1367 EXPECT_EQ(DRAW_SUCCESS
, host_impl_
->PrepareToDraw(&frame
));
1369 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1370 ASSERT_EQ(1u, frame
.render_passes
.size());
1371 ASSERT_EQ(1u, frame
.render_passes
[0]->quad_list
.size());
1372 EXPECT_EQ(DrawQuad::SOLID_COLOR
,
1373 frame
.render_passes
[0]->quad_list
[0]->material
);
1375 host_impl_
->DrawLayers(&frame
);
1376 host_impl_
->DidDrawAllLayers(frame
);
1379 TEST_F(DelegatedRendererLayerImplTest
, Occlusion
) {
1380 gfx::Size
layer_size(1000, 1000);
1381 gfx::Size
viewport_size(1000, 1000);
1382 gfx::Rect
quad_rect(200, 300, 400, 500);
1384 gfx::Transform transform
;
1385 transform
.Translate(11.0, 0.0);
1387 LayerTestCommon::LayerImplTest impl
;
1389 FakeDelegatedRendererLayerImpl
* delegated_renderer_layer_impl
=
1390 impl
.AddChildToRoot
<FakeDelegatedRendererLayerImpl
>();
1391 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1392 delegated_renderer_layer_impl
->SetContentBounds(layer_size
);
1393 delegated_renderer_layer_impl
->SetDrawsContent(true);
1395 RenderPassList delegated_render_passes
;
1396 // pass2 is just the size of the quad. It contributes to |pass1| with a
1397 // translation of (11,0).
1398 RenderPass::Id pass2_id
=
1399 delegated_renderer_layer_impl
->FirstContributingRenderPassId();
1400 TestRenderPass
* pass2
=
1401 AddRenderPass(&delegated_render_passes
, pass2_id
, quad_rect
, transform
);
1402 AddQuad(pass2
, gfx::Rect(quad_rect
.size()), SK_ColorRED
);
1403 // |pass1| covers the whole layer.
1404 RenderPass::Id pass1_id
= RenderPass::Id(impl
.root_layer()->id(), 0);
1405 TestRenderPass
* pass1
= AddRenderPass(&delegated_render_passes
,
1407 gfx::Rect(layer_size
),
1409 AddRenderPassQuad(pass1
, pass2
, 0, FilterOperations(), transform
);
1410 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1411 1.f
, &delegated_render_passes
);
1413 impl
.CalcDrawProps(viewport_size
);
1415 // The |quad_rect| translated by the |transform|.
1416 gfx::Rect quad_screen_rect
= quad_rect
+ gfx::Vector2d(11, 0);
1419 SCOPED_TRACE("No occlusion");
1423 SCOPED_TRACE("Root render pass");
1424 impl
.AppendQuadsForPassWithOcclusion(
1425 delegated_renderer_layer_impl
, pass1_id
, occluded
);
1426 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
1428 ASSERT_EQ(1u, impl
.quad_list().size());
1429 EXPECT_EQ(DrawQuad::RENDER_PASS
, impl
.quad_list()[0]->material
);
1432 SCOPED_TRACE("Contributing render pass");
1433 impl
.AppendQuadsForPassWithOcclusion(
1434 delegated_renderer_layer_impl
, pass2_id
, occluded
);
1435 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
1436 gfx::Rect(quad_rect
.size()));
1437 ASSERT_EQ(1u, impl
.quad_list().size());
1438 EXPECT_EQ(DrawQuad::SOLID_COLOR
, impl
.quad_list()[0]->material
);
1443 SCOPED_TRACE("Full occlusion");
1445 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_content_rect());
1447 SCOPED_TRACE("Root render pass");
1448 impl
.AppendQuadsForPassWithOcclusion(
1449 delegated_renderer_layer_impl
, pass1_id
, occluded
);
1450 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
1452 EXPECT_EQ(impl
.quad_list().size(), 0u);
1455 gfx::Rect
occluded(delegated_renderer_layer_impl
->visible_content_rect());
1456 // Move the occlusion to where it is in the contributing surface.
1457 occluded
-= quad_rect
.OffsetFromOrigin();
1459 SCOPED_TRACE("Contributing render pass");
1460 impl
.AppendQuadsForPassWithOcclusion(
1461 delegated_renderer_layer_impl
, pass2_id
, occluded
);
1462 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
1464 EXPECT_EQ(impl
.quad_list().size(), 0u);
1469 SCOPED_TRACE("Partial occlusion");
1471 gfx::Rect
occluded(0, 0, 500, 1000);
1473 SCOPED_TRACE("Root render pass");
1474 impl
.AppendQuadsForPassWithOcclusion(
1475 delegated_renderer_layer_impl
, pass1_id
, occluded
);
1476 size_t partially_occluded_count
= 0;
1477 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
1481 &partially_occluded_count
);
1482 // The layer outputs one quad, which is partially occluded.
1483 EXPECT_EQ(1u, impl
.quad_list().size());
1484 EXPECT_EQ(1u, partially_occluded_count
);
1487 gfx::Rect
occluded(0, 0, 500, 1000);
1488 // Move the occlusion to where it is in the contributing surface.
1489 occluded
-= quad_rect
.OffsetFromOrigin() + gfx::Vector2d(11, 0);
1491 SCOPED_TRACE("Contributing render pass");
1492 impl
.AppendQuadsForPassWithOcclusion(
1493 delegated_renderer_layer_impl
, pass2_id
, occluded
);
1494 size_t partially_occluded_count
= 0;
1495 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
1497 gfx::Rect(quad_rect
.size()),
1499 &partially_occluded_count
);
1500 // The layer outputs one quad, which is partially occluded.
1501 EXPECT_EQ(1u, impl
.quad_list().size());
1502 EXPECT_EQ(1u, partially_occluded_count
);
1503 // The quad in the contributing surface is at (211,300) in the root.
1504 // The occlusion extends to 500 in the x-axis, pushing the left of the
1505 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1506 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1507 impl
.quad_list()[0]->visible_rect
.ToString());
1512 TEST_F(DelegatedRendererLayerImplTest
, PushPropertiesTo
) {
1513 gfx::Size
layer_size(1000, 1000);
1515 scoped_ptr
<FakeDelegatedRendererLayerImpl
> delegated_renderer_layer_impl
=
1516 FakeDelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 5);
1517 delegated_renderer_layer_impl
->SetBounds(layer_size
);
1518 delegated_renderer_layer_impl
->SetContentBounds(layer_size
);
1519 delegated_renderer_layer_impl
->SetDrawsContent(true);
1521 RenderPassList delegated_render_passes
;
1522 // |pass1| covers the whole layer.
1523 RenderPass::Id pass1_id
= RenderPass::Id(5, 0);
1524 AddRenderPass(&delegated_render_passes
,
1526 gfx::Rect(layer_size
),
1528 delegated_renderer_layer_impl
->SetFrameDataForRenderPasses(
1529 2.f
, &delegated_render_passes
);
1530 EXPECT_EQ(0.5f
, delegated_renderer_layer_impl
->inverse_device_scale_factor());
1532 scoped_ptr
<DelegatedRendererLayerImpl
> other_layer
=
1533 DelegatedRendererLayerImpl::Create(host_impl_
->active_tree(), 6);
1535 delegated_renderer_layer_impl
->PushPropertiesTo(other_layer
.get());
1537 EXPECT_EQ(0.5f
, other_layer
->inverse_device_scale_factor());