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/delegated_renderer_layer_impl.h"
7 #include "cc/append_quads_data.h"
8 #include "cc/layer_tree_host_impl.h"
9 #include "cc/layer_tree_impl.h"
10 #include "cc/quad_sink.h"
11 #include "cc/render_pass_draw_quad.h"
12 #include "cc/scoped_ptr_vector.h"
13 #include "cc/single_thread_proxy.h"
14 #include "cc/solid_color_draw_quad.h"
15 #include "cc/solid_color_layer_impl.h"
16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_layer_tree_host_impl_client.h"
18 #include "cc/test/fake_output_surface.h"
19 #include "cc/test/fake_proxy.h"
20 #include "cc/test/fake_web_graphics_context_3d.h"
21 #include "cc/test/geometry_test_utils.h"
22 #include "cc/test/mock_quad_culler.h"
23 #include "cc/test/render_pass_test_common.h"
24 #include "cc/test/render_pass_test_utils.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/transform.h"
31 class DelegatedRendererLayerImplTest
: public testing::Test
{
33 DelegatedRendererLayerImplTest()
34 : proxy_(scoped_ptr
<Thread
>(NULL
))
35 , always_impl_thread_and_main_thread_blocked_(&proxy_
) {
36 LayerTreeSettings settings
;
37 settings
.minimumOcclusionTrackingSize
= gfx::Size();
39 host_impl_
= LayerTreeHostImpl::create(settings
, &client_
, &proxy_
);
40 host_impl_
->initializeRenderer(createFakeOutputSurface());
41 host_impl_
->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
46 FakeLayerTreeHostImplClient client_
;
47 DebugScopedSetImplThreadAndMainThreadBlocked
48 always_impl_thread_and_main_thread_blocked_
;
49 scoped_ptr
<LayerTreeHostImpl
> host_impl_
;
52 class DelegatedRendererLayerImplTestSimple
53 : public DelegatedRendererLayerImplTest
{
55 DelegatedRendererLayerImplTestSimple()
56 : DelegatedRendererLayerImplTest() {
57 scoped_ptr
<LayerImpl
> root_layer
= SolidColorLayerImpl::create(
58 host_impl_
->activeTree(), 1).PassAs
<LayerImpl
>();
59 scoped_ptr
<LayerImpl
> layer_before
= SolidColorLayerImpl::create(
60 host_impl_
->activeTree(), 2).PassAs
<LayerImpl
>();
61 scoped_ptr
<LayerImpl
> layer_after
= SolidColorLayerImpl::create(
62 host_impl_
->activeTree(), 3).PassAs
<LayerImpl
>();
63 scoped_ptr
<DelegatedRendererLayerImpl
> delegated_renderer_layer
=
64 DelegatedRendererLayerImpl::Create(host_impl_
->activeTree(), 4);
66 host_impl_
->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
67 root_layer
->setBounds(gfx::Size(100, 100));
69 layer_before
->setPosition(gfx::Point(20, 20));
70 layer_before
->setBounds(gfx::Size(14, 14));
71 layer_before
->setContentBounds(gfx::Size(14, 14));
72 layer_before
->setDrawsContent(true);
73 layer_before
->setForceRenderSurface(true);
75 layer_after
->setPosition(gfx::Point(5, 5));
76 layer_after
->setBounds(gfx::Size(15, 15));
77 layer_after
->setContentBounds(gfx::Size(15, 15));
78 layer_after
->setDrawsContent(true);
79 layer_after
->setForceRenderSurface(true);
81 delegated_renderer_layer
->setPosition(gfx::Point(3, 3));
82 delegated_renderer_layer
->setBounds(gfx::Size(10, 10));
83 delegated_renderer_layer
->setContentBounds(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 ScopedPtrVector
<RenderPass
> delegated_render_passes
;
90 TestRenderPass
* pass1
= addRenderPass(
91 delegated_render_passes
,
93 gfx::Rect(6, 6, 6, 6),
95 addQuad(pass1
, gfx::Rect(0, 0, 6, 6), 33u);
96 TestRenderPass
* pass2
= addRenderPass(
97 delegated_render_passes
,
99 gfx::Rect(7, 7, 7, 7),
101 addQuad(pass2
, gfx::Rect(0, 0, 7, 7), 22u);
102 addRenderPassQuad(pass2
, pass1
);
103 TestRenderPass
* pass3
= addRenderPass(
104 delegated_render_passes
,
105 RenderPass::Id(9, 8),
106 gfx::Rect(0, 0, 8, 8),
108 addRenderPassQuad(pass3
, pass2
);
109 delegated_renderer_layer
->SetRenderPasses(delegated_render_passes
);
111 // The RenderPasses should be taken by the layer.
112 EXPECT_EQ(0u, delegated_render_passes
.size());
114 root_layer_
= root_layer
.get();
115 layer_before_
= layer_before
.get();
116 layer_after_
= layer_after
.get();
117 delegated_renderer_layer_
= delegated_renderer_layer
.get();
119 // Force the delegated RenderPasses to come before the RenderPass from
121 layer_after
->addChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
122 root_layer
->addChild(layer_after
.Pass());
124 // Get the RenderPass generated by layer_before to come before the delegated
126 root_layer
->addChild(layer_before
.Pass());
127 host_impl_
->activeTree()->SetRootLayer(root_layer
.Pass());
131 LayerImpl
* root_layer_
;
132 LayerImpl
* layer_before_
;
133 LayerImpl
* layer_after_
;
134 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
137 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsContributingRenderPasses
) {
138 LayerTreeHostImpl::FrameData frame
;
139 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
141 // Each non-DelegatedRendererLayer added one RenderPass. The
142 // DelegatedRendererLayer added two contributing passes.
143 ASSERT_EQ(5u, frame
.renderPasses
.size());
145 // The DelegatedRendererLayer should have added its contributing RenderPasses
147 EXPECT_EQ(4, frame
.renderPasses
[1]->id
.layer_id
);
148 EXPECT_EQ(1, frame
.renderPasses
[1]->id
.index
);
149 EXPECT_EQ(4, frame
.renderPasses
[2]->id
.layer_id
);
150 EXPECT_EQ(2, frame
.renderPasses
[2]->id
.index
);
151 // And all other RenderPasses should be non-delegated.
152 EXPECT_NE(4, frame
.renderPasses
[0]->id
.layer_id
);
153 EXPECT_EQ(0, frame
.renderPasses
[0]->id
.index
);
154 EXPECT_NE(4, frame
.renderPasses
[3]->id
.layer_id
);
155 EXPECT_EQ(0, frame
.renderPasses
[3]->id
.index
);
156 EXPECT_NE(4, frame
.renderPasses
[4]->id
.layer_id
);
157 EXPECT_EQ(0, frame
.renderPasses
[4]->id
.index
);
159 // The DelegatedRendererLayer should have added its RenderPasses to the frame
161 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
162 frame
.renderPasses
[1]->output_rect
.ToString());
163 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
164 frame
.renderPasses
[2]->output_rect
.ToString());
166 host_impl_
->drawLayers(frame
);
167 host_impl_
->didDrawAllLayers(frame
);
170 TEST_F(DelegatedRendererLayerImplTestSimple
,
171 AddsQuadsToContributingRenderPasses
) {
172 LayerTreeHostImpl::FrameData frame
;
173 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
175 // Each non-DelegatedRendererLayer added one RenderPass. The
176 // DelegatedRendererLayer added two contributing passes.
177 ASSERT_EQ(5u, frame
.renderPasses
.size());
179 // The DelegatedRendererLayer should have added its contributing RenderPasses
181 EXPECT_EQ(4, frame
.renderPasses
[1]->id
.layer_id
);
182 EXPECT_EQ(1, frame
.renderPasses
[1]->id
.index
);
183 EXPECT_EQ(4, frame
.renderPasses
[2]->id
.layer_id
);
184 EXPECT_EQ(2, frame
.renderPasses
[2]->id
.index
);
186 // The DelegatedRendererLayer should have added copies of its quads to
187 // contributing RenderPasses.
188 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
189 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
190 frame
.renderPasses
[1]->quad_list
[0]->rect
.ToString());
192 // Verify it added the right quads.
193 ASSERT_EQ(2u, frame
.renderPasses
[2]->quad_list
.size());
194 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
195 frame
.renderPasses
[2]->quad_list
[0]->rect
.ToString());
196 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
197 frame
.renderPasses
[2]->quad_list
[1]->rect
.ToString());
198 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
199 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
200 frame
.renderPasses
[1]->quad_list
[0]->rect
.ToString());
202 host_impl_
->drawLayers(frame
);
203 host_impl_
->didDrawAllLayers(frame
);
206 TEST_F(DelegatedRendererLayerImplTestSimple
, AddsQuadsToTargetRenderPass
) {
207 LayerTreeHostImpl::FrameData frame
;
208 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
210 // Each non-DelegatedRendererLayer added one RenderPass. The
211 // DelegatedRendererLayer added two contributing passes.
212 ASSERT_EQ(5u, frame
.renderPasses
.size());
214 // The layer's target is the RenderPass from m_layer_after.
215 EXPECT_EQ(RenderPass::Id(3, 0), frame
.renderPasses
[3]->id
);
217 // The DelegatedRendererLayer should have added copies of quads in its root
218 // RenderPass to its target RenderPass. The m_layer_after also adds one quad.
219 ASSERT_EQ(2u, frame
.renderPasses
[3]->quad_list
.size());
221 // Verify it added the right quads.
222 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
223 frame
.renderPasses
[3]->quad_list
[0]->rect
.ToString());
225 // Its target layer should have a quad as well.
226 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
227 frame
.renderPasses
[3]->quad_list
[1]->rect
.ToString());
229 host_impl_
->drawLayers(frame
);
230 host_impl_
->didDrawAllLayers(frame
);
233 TEST_F(DelegatedRendererLayerImplTestSimple
,
234 QuadsFromRootRenderPassAreModifiedForTheTarget
) {
235 LayerTreeHostImpl::FrameData frame
;
236 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
238 // Each non-DelegatedRendererLayer added one RenderPass. The
239 // DelegatedRendererLayer added two contributing passes.
240 ASSERT_EQ(5u, frame
.renderPasses
.size());
242 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
243 // has a translation transform of 1,1. So its root RenderPass' quads should
244 // all be transformed by that combined amount.
245 // The DelegatedRendererLayer has a size of 10x10, but the root delegated
246 // RenderPass has a size of 8x8, so any quads should be scaled by 10/8.
247 gfx::Transform transform
;
248 transform
.Translate(4.0, 4.0);
249 transform
.Scale(10.0 / 8.0, 10.0 / 8.0);
250 EXPECT_TRANSFORMATION_MATRIX_EQ(
251 transform
, frame
.renderPasses
[3]->quad_list
[0]->quadTransform());
253 // Quads from non-root RenderPasses should not be shifted though.
254 ASSERT_EQ(2u, frame
.renderPasses
[2]->quad_list
.size());
255 EXPECT_TRANSFORMATION_MATRIX_EQ(
256 gfx::Transform(), frame
.renderPasses
[2]->quad_list
[0]->quadTransform());
257 EXPECT_TRANSFORMATION_MATRIX_EQ(
258 gfx::Transform(), frame
.renderPasses
[2]->quad_list
[1]->quadTransform());
259 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
260 EXPECT_TRANSFORMATION_MATRIX_EQ(
261 gfx::Transform(), frame
.renderPasses
[1]->quad_list
[0]->quadTransform());
263 host_impl_
->drawLayers(frame
);
264 host_impl_
->didDrawAllLayers(frame
);
267 TEST_F(DelegatedRendererLayerImplTestSimple
, DoesNotOwnARenderSurface
) {
268 LayerTreeHostImpl::FrameData frame
;
269 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
271 // If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
272 // has no need to be a renderSurface for the quads it carries.
273 EXPECT_FALSE(delegated_renderer_layer_
->renderSurface());
275 host_impl_
->drawLayers(frame
);
276 host_impl_
->didDrawAllLayers(frame
);
279 TEST_F(DelegatedRendererLayerImplTestSimple
, DoesOwnARenderSurfaceForOpacity
) {
280 delegated_renderer_layer_
->setOpacity(0.5f
);
282 LayerTreeHostImpl::FrameData frame
;
283 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
285 // This test case has quads from multiple layers in the delegated renderer, so
286 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
288 EXPECT_TRUE(delegated_renderer_layer_
->renderSurface());
290 host_impl_
->drawLayers(frame
);
291 host_impl_
->didDrawAllLayers(frame
);
294 TEST_F(DelegatedRendererLayerImplTestSimple
,
295 DoesOwnARenderSurfaceForTransform
) {
296 gfx::Transform rotation
;
297 rotation
.RotateAboutZAxis(30.0);
298 delegated_renderer_layer_
->setTransform(rotation
);
300 LayerTreeHostImpl::FrameData frame
;
301 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
303 // This test case has quads from multiple layers in the delegated renderer, so
304 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
306 EXPECT_TRUE(delegated_renderer_layer_
->renderSurface());
308 host_impl_
->drawLayers(frame
);
309 host_impl_
->didDrawAllLayers(frame
);
312 class DelegatedRendererLayerImplTestOwnSurface
313 : public DelegatedRendererLayerImplTestSimple
{
315 DelegatedRendererLayerImplTestOwnSurface()
316 : DelegatedRendererLayerImplTestSimple() {
317 delegated_renderer_layer_
->setForceRenderSurface(true);
321 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsRenderPasses
) {
322 LayerTreeHostImpl::FrameData frame
;
323 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
325 // Each non-DelegatedRendererLayer added one RenderPass. The
326 // DelegatedRendererLayer added two contributing passes and its owned surface
328 ASSERT_EQ(6u, frame
.renderPasses
.size());
330 // The DelegatedRendererLayer should have added its contributing RenderPasses
332 EXPECT_EQ(4, frame
.renderPasses
[1]->id
.layer_id
);
333 EXPECT_EQ(1, frame
.renderPasses
[1]->id
.index
);
334 EXPECT_EQ(4, frame
.renderPasses
[2]->id
.layer_id
);
335 EXPECT_EQ(2, frame
.renderPasses
[2]->id
.index
);
336 // The DelegatedRendererLayer should have added a RenderPass for its surface
338 EXPECT_EQ(4, frame
.renderPasses
[1]->id
.layer_id
);
339 EXPECT_EQ(0, frame
.renderPasses
[3]->id
.index
);
340 // And all other RenderPasses should be non-delegated.
341 EXPECT_NE(4, frame
.renderPasses
[0]->id
.layer_id
);
342 EXPECT_EQ(0, frame
.renderPasses
[0]->id
.index
);
343 EXPECT_NE(4, frame
.renderPasses
[4]->id
.layer_id
);
344 EXPECT_EQ(0, frame
.renderPasses
[4]->id
.index
);
345 EXPECT_NE(4, frame
.renderPasses
[5]->id
.layer_id
);
346 EXPECT_EQ(0, frame
.renderPasses
[5]->id
.index
);
348 // The DelegatedRendererLayer should have added its RenderPasses to the frame
350 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
351 frame
.renderPasses
[1]->output_rect
.ToString());
352 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
353 frame
.renderPasses
[2]->output_rect
.ToString());
355 host_impl_
->drawLayers(frame
);
356 host_impl_
->didDrawAllLayers(frame
);
359 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
360 AddsQuadsToContributingRenderPasses
) {
361 LayerTreeHostImpl::FrameData frame
;
362 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
364 // Each non-DelegatedRendererLayer added one RenderPass. The
365 // DelegatedRendererLayer added two contributing passes and its owned surface
367 ASSERT_EQ(6u, frame
.renderPasses
.size());
369 // The DelegatedRendererLayer should have added its contributing RenderPasses
371 EXPECT_EQ(4, frame
.renderPasses
[1]->id
.layer_id
);
372 EXPECT_EQ(1, frame
.renderPasses
[1]->id
.index
);
373 EXPECT_EQ(4, frame
.renderPasses
[2]->id
.layer_id
);
374 EXPECT_EQ(2, frame
.renderPasses
[2]->id
.index
);
376 // The DelegatedRendererLayer should have added copies of its quads to
377 // contributing RenderPasses.
378 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
379 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
380 frame
.renderPasses
[1]->quad_list
[0]->rect
.ToString());
382 // Verify it added the right quads.
383 ASSERT_EQ(2u, frame
.renderPasses
[2]->quad_list
.size());
384 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
385 frame
.renderPasses
[2]->quad_list
[0]->rect
.ToString());
386 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
387 frame
.renderPasses
[2]->quad_list
[1]->rect
.ToString());
388 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
389 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
390 frame
.renderPasses
[1]->quad_list
[0]->rect
.ToString());
392 host_impl_
->drawLayers(frame
);
393 host_impl_
->didDrawAllLayers(frame
);
396 TEST_F(DelegatedRendererLayerImplTestOwnSurface
, AddsQuadsToTargetRenderPass
) {
397 LayerTreeHostImpl::FrameData frame
;
398 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
400 // Each non-DelegatedRendererLayer added one RenderPass. The
401 // DelegatedRendererLayer added two contributing passes and its owned surface
403 ASSERT_EQ(6u, frame
.renderPasses
.size());
405 // The layer's target is the RenderPass owned by itself.
406 EXPECT_EQ(RenderPass::Id(4, 0), frame
.renderPasses
[3]->id
);
408 // The DelegatedRendererLayer should have added copies of quads in its root
409 // RenderPass to its target RenderPass.
410 // The m_layer_after also adds one quad.
411 ASSERT_EQ(1u, frame
.renderPasses
[3]->quad_list
.size());
413 // Verify it added the right quads.
414 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
415 frame
.renderPasses
[3]->quad_list
[0]->rect
.ToString());
417 host_impl_
->drawLayers(frame
);
418 host_impl_
->didDrawAllLayers(frame
);
421 TEST_F(DelegatedRendererLayerImplTestOwnSurface
,
422 QuadsFromRootRenderPassAreNotModifiedForTheTarget
) {
423 LayerTreeHostImpl::FrameData frame
;
424 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
426 // Each non-DelegatedRendererLayer added one RenderPass. The
427 // DelegatedRendererLayer added two contributing passes and its owned surface
429 ASSERT_EQ(6u, frame
.renderPasses
.size());
431 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
432 // RenderPass' quads do not need to be translated at all. However, they are
433 // scaled from the frame's size (8x8) to the layer's bounds (10x10).
434 gfx::Transform transform
;
435 transform
.Scale(10.0 / 8.0, 10.0 / 8.0);
436 EXPECT_TRANSFORMATION_MATRIX_EQ(
437 transform
, frame
.renderPasses
[3]->quad_list
[0]->quadTransform());
439 // Quads from non-root RenderPasses should not be shifted either.
440 ASSERT_EQ(2u, frame
.renderPasses
[2]->quad_list
.size());
441 EXPECT_TRANSFORMATION_MATRIX_EQ(
442 gfx::Transform(), frame
.renderPasses
[2]->quad_list
[0]->quadTransform());
443 EXPECT_TRANSFORMATION_MATRIX_EQ(
444 gfx::Transform(), frame
.renderPasses
[2]->quad_list
[1]->quadTransform());
445 ASSERT_EQ(1u, frame
.renderPasses
[1]->quad_list
.size());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(
447 gfx::Transform(), frame
.renderPasses
[1]->quad_list
[0]->quadTransform());
449 host_impl_
->drawLayers(frame
);
450 host_impl_
->didDrawAllLayers(frame
);
453 class DelegatedRendererLayerImplTestTransform
454 : public DelegatedRendererLayerImplTest
{
457 scoped_ptr
<LayerImpl
> root_layer
= LayerImpl::create(
458 host_impl_
->activeTree(), 1);
459 scoped_ptr
<DelegatedRendererLayerImpl
> delegated_renderer_layer
=
460 DelegatedRendererLayerImpl::Create(host_impl_
->activeTree(), 2);
462 host_impl_
->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
463 root_layer
->setBounds(gfx::Size(100, 100));
465 delegated_renderer_layer
->setPosition(gfx::Point(20, 20));
466 delegated_renderer_layer
->setBounds(gfx::Size(30, 30));
467 delegated_renderer_layer
->setContentBounds(gfx::Size(30, 30));
468 delegated_renderer_layer
->setDrawsContent(true);
469 gfx::Transform transform
;
470 transform
.Scale(2.0, 2.0);
471 transform
.Translate(8.0, 8.0);
472 delegated_renderer_layer
->setTransform(transform
);
474 ScopedPtrVector
<RenderPass
> delegated_render_passes
;
476 gfx::Rect
child_pass_rect(20, 20, 7, 7);
477 gfx::Transform child_pass_transform
;
478 child_pass_transform
.Scale(0.8, 0.8);
479 child_pass_transform
.Translate(9.0, 9.0);
480 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
481 bool child_pass_clipped
= false;
484 TestRenderPass
* pass
= addRenderPass(
485 delegated_render_passes
,
486 RenderPass::Id(10, 7),
489 MockQuadCuller
quad_sink(pass
->quad_list
, pass
->shared_quad_state_list
);
490 AppendQuadsData
data(pass
->id
);
491 SharedQuadState
* shared_quad_state
= quad_sink
.useSharedQuadState(
492 SharedQuadState::Create());
493 shared_quad_state
->SetAll(
494 child_pass_transform
,
496 child_pass_clip_rect
,
500 scoped_ptr
<SolidColorDrawQuad
> color_quad
;
501 color_quad
= SolidColorDrawQuad::Create();
502 color_quad
->SetNew(shared_quad_state
, gfx::Rect(20, 20, 3, 7), 1u);
503 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
505 color_quad
= SolidColorDrawQuad::Create();
506 color_quad
->SetNew(shared_quad_state
, gfx::Rect(23, 20, 4, 7), 1u);
507 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
510 gfx::Rect
root_pass_rect(0, 0, 50, 50);
511 gfx::Transform root_pass_transform
;
512 root_pass_transform
.Scale(1.5, 1.5);
513 root_pass_transform
.Translate(7.0, 7.0);
514 gfx::Rect
root_pass_clip_rect(10, 10, 35, 35);
515 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
517 TestRenderPass
* pass
= addRenderPass(
518 delegated_render_passes
,
519 RenderPass::Id(9, 6),
522 MockQuadCuller
quad_sink(pass
->quad_list
, pass
->shared_quad_state_list
);
523 AppendQuadsData
data(pass
->id
);
524 SharedQuadState
* shared_quad_state
= quad_sink
.useSharedQuadState(SharedQuadState::Create());
525 shared_quad_state
->SetAll(
532 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
533 RenderPassDrawQuad::Create();
534 render_pass_quad
->SetNew(
536 gfx::Rect(5, 5, 7, 7), // rect
537 RenderPass::Id(10, 7), // render_pass_id
539 0, // mask_resource_id
540 child_pass_rect
, // contents_changed_since_last_frame
541 gfx::RectF(), // mask_uv_rect
542 WebKit::WebFilterOperations(), // filters
543 skia::RefPtr
<SkImageFilter
>(), // filter
544 WebKit::WebFilterOperations()); // background_filters
545 quad_sink
.append(render_pass_quad
.PassAs
<DrawQuad
>(), data
);
547 scoped_ptr
<SolidColorDrawQuad
> color_quad
;
548 color_quad
= SolidColorDrawQuad::Create();
549 color_quad
->SetNew(shared_quad_state
, gfx::Rect(0, 0, 10, 10), 1u);
550 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
552 color_quad
= SolidColorDrawQuad::Create();
553 color_quad
->SetNew(shared_quad_state
, gfx::Rect(0, 10, 10, 10), 2u);
554 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
556 color_quad
= SolidColorDrawQuad::Create();
557 color_quad
->SetNew(shared_quad_state
, gfx::Rect(10, 0, 10, 10), 3u);
558 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
560 color_quad
= SolidColorDrawQuad::Create();
561 color_quad
->SetNew(shared_quad_state
, gfx::Rect(10, 10, 10, 10), 4u);
562 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
564 delegated_renderer_layer
->SetRenderPasses(delegated_render_passes
);
566 // The RenderPasses should be taken by the layer.
567 EXPECT_EQ(0u, delegated_render_passes
.size());
569 root_layer_
= root_layer
.get();
570 delegated_renderer_layer_
= delegated_renderer_layer
.get();
572 root_layer
->addChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
573 host_impl_
->activeTree()->SetRootLayer(root_layer
.Pass());
576 void VerifyRenderPasses(
577 const LayerTreeHostImpl::FrameData
& frame
,
578 size_t num_render_passes
,
579 const SharedQuadState
** root_delegated_shared_quad_state
,
580 const SharedQuadState
** contrib_delegated_shared_quad_state
) {
581 ASSERT_EQ(num_render_passes
, frame
.renderPasses
.size());
582 // The contributing render pass in the DelegatedRendererLayer.
583 EXPECT_EQ(2, frame
.renderPasses
[0]->id
.layer_id
);
584 EXPECT_EQ(1, frame
.renderPasses
[0]->id
.index
);
585 // The root render pass.
586 EXPECT_EQ(1, frame
.renderPasses
.back()->id
.layer_id
);
587 EXPECT_EQ(0, frame
.renderPasses
.back()->id
.index
);
589 const QuadList
& contrib_delegated_quad_list
=
590 frame
.renderPasses
[0]->quad_list
;
591 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
593 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
594 ASSERT_EQ(5u, root_delegated_quad_list
.size());
596 // All quads in a render pass should share the same state.
597 *contrib_delegated_shared_quad_state
=
598 contrib_delegated_quad_list
[0]->shared_quad_state
;
599 EXPECT_EQ(*contrib_delegated_shared_quad_state
,
600 contrib_delegated_quad_list
[1]->shared_quad_state
);
602 *root_delegated_shared_quad_state
=
603 root_delegated_quad_list
[0]->shared_quad_state
;
604 EXPECT_EQ(*root_delegated_shared_quad_state
,
605 root_delegated_quad_list
[1]->shared_quad_state
);
606 EXPECT_EQ(*root_delegated_shared_quad_state
,
607 root_delegated_quad_list
[2]->shared_quad_state
);
608 EXPECT_EQ(*root_delegated_shared_quad_state
,
609 root_delegated_quad_list
[3]->shared_quad_state
);
610 EXPECT_EQ(*root_delegated_shared_quad_state
,
611 root_delegated_quad_list
[4]->shared_quad_state
);
613 EXPECT_NE(*contrib_delegated_shared_quad_state
,
614 *root_delegated_shared_quad_state
);
618 LayerImpl
* root_layer_
;
619 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
620 bool root_delegated_render_pass_is_clipped_
;
623 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_NoSurface
) {
624 root_delegated_render_pass_is_clipped_
= false;
627 LayerTreeHostImpl::FrameData frame
;
628 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
630 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
631 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
635 &root_delegated_shared_quad_state
,
636 &contrib_delegated_shared_quad_state
);
638 // When the quads don't have a clip of their own, the clip rect is set to
639 // the drawableContentRect of the delegated renderer layer.
640 EXPECT_EQ(gfx::Rect(21, 21, 60, 60).ToString(),
641 root_delegated_shared_quad_state
->clip_rect
.ToString());
643 // Even though the quads in the root pass have no clip of their own, they
644 // inherit the clip rect from the delegated renderer layer if it does not
646 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
648 gfx::Transform expected
;
649 // This is the transform from the layer's space to its target.
650 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5
651 expected
.Translate(5.0, 5.0);
652 expected
.Scale(2.0, 2.0);
653 expected
.Translate(8.0, 8.0);
654 // The frame has size 50x50 but the layer's bounds are 30x30.
655 expected
.Scale(30.0 / 50.0, 30.0 / 50.0);
656 // This is the transform within the source frame.
657 expected
.Scale(1.5, 1.5);
658 expected
.Translate(7.0, 7.0);
659 EXPECT_TRANSFORMATION_MATRIX_EQ(
660 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
662 // The contributing render pass should not be transformed from its input.
663 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
664 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
665 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
666 expected
.MakeIdentity();
667 expected
.Scale(0.8, 0.8);
668 expected
.Translate(9.0, 9.0);
669 EXPECT_TRANSFORMATION_MATRIX_EQ(
671 contrib_delegated_shared_quad_state
->content_to_target_transform
);
673 host_impl_
->drawLayers(frame
);
674 host_impl_
->didDrawAllLayers(frame
);
677 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_NoSurface
) {
678 root_delegated_render_pass_is_clipped_
= true;
681 LayerTreeHostImpl::FrameData frame
;
682 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
684 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
685 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
689 &root_delegated_shared_quad_state
,
690 &contrib_delegated_shared_quad_state
);
692 // Since the quads have a clip_rect it should be modified by delegated
693 // renderer layer's drawTransform.
694 // The position of the resulting clip_rect is:
695 // (clip rect position (10) * scale to layer (30/50) + translate (8)) *
696 // layer scale (2) + layer position (20) = 48
697 // But the layer is centered, so: 48 - (width / 2) = 48 - 30 / 2 = 33
699 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from
700 // a frame at 50x50: 35 * 2 (layer's scale) * 30 / 50 = 42.
701 EXPECT_EQ(gfx::Rect(33, 33, 42, 42).ToString(),
702 root_delegated_shared_quad_state
->clip_rect
.ToString());
704 // The quads had a clip and it should be preserved.
705 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
707 gfx::Transform expected
;
708 // This is the transform from the layer's space to its target.
709 // The position (20) - the width / scale (30 / 2) = 20 - 15 = 5
710 expected
.Translate(5.0, 5.0);
711 expected
.Scale(2.0, 2.0);
712 expected
.Translate(8.0, 8.0);
713 // The frame has size 50x50 but the layer's bounds are 30x30.
714 expected
.Scale(30.0 / 50.0, 30.0 / 50.0);
715 // This is the transform within the source frame.
716 expected
.Scale(1.5, 1.5);
717 expected
.Translate(7.0, 7.0);
718 EXPECT_TRANSFORMATION_MATRIX_EQ(
719 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
721 // The contributing render pass should not be transformed from its input.
722 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
723 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
724 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
725 expected
.MakeIdentity();
726 expected
.Scale(0.8, 0.8);
727 expected
.Translate(9.0, 9.0);
728 EXPECT_TRANSFORMATION_MATRIX_EQ(
730 contrib_delegated_shared_quad_state
->content_to_target_transform
);
732 host_impl_
->drawLayers(frame
);
733 host_impl_
->didDrawAllLayers(frame
);
736 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsUnclipped_Surface
) {
737 root_delegated_render_pass_is_clipped_
= false;
740 delegated_renderer_layer_
->setForceRenderSurface(true);
742 LayerTreeHostImpl::FrameData frame
;
743 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
745 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
746 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
750 &root_delegated_shared_quad_state
,
751 &contrib_delegated_shared_quad_state
);
753 // When the layer owns a surface, then its position and translation are not
754 // a part of its draw transform.
755 // The position of the resulting clip_rect is:
756 // (clip rect position (10) * scale to layer (30/50)) * layer scale (2) = 12
757 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from
758 // a frame at 50x50: 35 * 2 (layer's scale) * 30 / 50 = 42.
759 EXPECT_EQ(gfx::Rect(12, 12, 42, 42).ToString(),
760 root_delegated_shared_quad_state
->clip_rect
.ToString());
762 // Since the layer owns a surface it doesn't need to clip its quads, so
763 // unclipped quads remain unclipped.
764 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
766 gfx::Transform expected
;
767 expected
.Scale(2.0, 2.0);
768 // The frame has size 50x50 but the layer's bounds are 30x30.
769 expected
.Scale(30.0 / 50.0, 30.0 / 50.0);
770 // This is the transform within the source frame.
771 expected
.Scale(1.5, 1.5);
772 expected
.Translate(7.0, 7.0);
773 EXPECT_TRANSFORMATION_MATRIX_EQ(
774 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
776 // The contributing render pass should not be transformed from its input.
777 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
778 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
779 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
780 expected
.MakeIdentity();
781 expected
.Scale(0.8, 0.8);
782 expected
.Translate(9.0, 9.0);
783 EXPECT_TRANSFORMATION_MATRIX_EQ(
785 contrib_delegated_shared_quad_state
->content_to_target_transform
);
787 host_impl_
->drawLayers(frame
);
788 host_impl_
->didDrawAllLayers(frame
);
791 TEST_F(DelegatedRendererLayerImplTestTransform
, QuadsClipped_Surface
) {
792 root_delegated_render_pass_is_clipped_
= true;
795 delegated_renderer_layer_
->setForceRenderSurface(true);
797 LayerTreeHostImpl::FrameData frame
;
798 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
800 const SharedQuadState
* root_delegated_shared_quad_state
= NULL
;
801 const SharedQuadState
* contrib_delegated_shared_quad_state
= NULL
;
805 &root_delegated_shared_quad_state
,
806 &contrib_delegated_shared_quad_state
);
808 // When the layer owns a surface, then its position and translation are not
809 // a part of its draw transform.
810 // The position of the resulting clip_rect is:
811 // (clip rect position (10) * scale to layer (30/50)) * layer scale (2) = 12
812 // The size is 35x35 scaled to fit inside the layer's bounds at 30x30 from
813 // a frame at 50x50: 35 * 2 (layer's scale) * 30 / 50 = 42.
814 EXPECT_EQ(gfx::Rect(12, 12, 42, 42).ToString(),
815 root_delegated_shared_quad_state
->clip_rect
.ToString());
817 // The quads had a clip and it should be preserved.
818 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
820 gfx::Transform expected
;
821 expected
.Scale(2.0, 2.0);
822 // The frame has size 50x50 but the layer's bounds are 30x30.
823 expected
.Scale(30.0 / 50.0, 30.0 / 50.0);
824 // This is the transform within the source frame.
825 expected
.Scale(1.5, 1.5);
826 expected
.Translate(7.0, 7.0);
827 EXPECT_TRANSFORMATION_MATRIX_EQ(
828 expected
, root_delegated_shared_quad_state
->content_to_target_transform
);
830 // The contributing render pass should not be transformed from its input.
831 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
832 contrib_delegated_shared_quad_state
->clip_rect
.ToString());
833 EXPECT_FALSE(contrib_delegated_shared_quad_state
->is_clipped
);
834 expected
.MakeIdentity();
835 expected
.Scale(0.8, 0.8);
836 expected
.Translate(9.0, 9.0);
837 EXPECT_TRANSFORMATION_MATRIX_EQ(
839 contrib_delegated_shared_quad_state
->content_to_target_transform
);
841 host_impl_
->drawLayers(frame
);
842 host_impl_
->didDrawAllLayers(frame
);
845 class DelegatedRendererLayerImplTestClip
846 : public DelegatedRendererLayerImplTest
{
849 scoped_ptr
<LayerImpl
> root_layer
=
850 LayerImpl::create(host_impl_
->activeTree(), 1);
851 scoped_ptr
<DelegatedRendererLayerImpl
> delegated_renderer_layer
=
852 DelegatedRendererLayerImpl::Create(host_impl_
->activeTree(), 2);
853 scoped_ptr
<LayerImpl
> clip_layer
=
854 LayerImpl::create(host_impl_
->activeTree(), 3);
855 scoped_ptr
<LayerImpl
> origin_layer
=
856 LayerImpl::create(host_impl_
->activeTree(), 4);
858 host_impl_
->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
859 root_layer
->setBounds(gfx::Size(100, 100));
861 delegated_renderer_layer
->setPosition(gfx::Point(20, 20));
862 delegated_renderer_layer
->setBounds(gfx::Size(50, 50));
863 delegated_renderer_layer
->setContentBounds(gfx::Size(50, 50));
864 delegated_renderer_layer
->setDrawsContent(true);
866 ScopedPtrVector
<RenderPass
> delegated_render_passes
;
868 gfx::Rect
child_pass_rect(20, 20, 7, 7);
869 gfx::Transform child_pass_transform
;
870 gfx::Rect
child_pass_clip_rect(21, 21, 3, 3);
871 bool child_pass_clipped
= false;
874 TestRenderPass
* pass
= addRenderPass(
875 delegated_render_passes
,
876 RenderPass::Id(10, 7),
879 MockQuadCuller
quad_sink(pass
->quad_list
, pass
->shared_quad_state_list
);
880 AppendQuadsData
data(pass
->id
);
881 SharedQuadState
* shared_quad_state
=
882 quad_sink
.useSharedQuadState(SharedQuadState::Create());
883 shared_quad_state
->SetAll(
884 child_pass_transform
,
886 child_pass_clip_rect
,
890 scoped_ptr
<SolidColorDrawQuad
> color_quad
;
891 color_quad
= SolidColorDrawQuad::Create();
892 color_quad
->SetNew(shared_quad_state
, gfx::Rect(20, 20, 3, 7), 1u);
893 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
895 color_quad
= SolidColorDrawQuad::Create();
896 color_quad
->SetNew(shared_quad_state
, gfx::Rect(23, 20, 4, 7), 1u);
897 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
900 gfx::Rect
root_pass_rect(0, 0, 50, 50);
901 gfx::Transform root_pass_transform
;
902 gfx::Rect
root_pass_clip_rect(5, 5, 40, 40);
903 bool root_pass_clipped
= root_delegated_render_pass_is_clipped_
;
905 TestRenderPass
* pass
= addRenderPass(
906 delegated_render_passes
,
907 RenderPass::Id(9, 6),
910 MockQuadCuller
quad_sink(pass
->quad_list
, pass
->shared_quad_state_list
);
911 AppendQuadsData
data(pass
->id
);
912 SharedQuadState
* shared_quad_state
=
913 quad_sink
.useSharedQuadState(SharedQuadState::Create());
914 shared_quad_state
->SetAll(root_pass_transform
, root_pass_rect
, root_pass_clip_rect
, root_pass_clipped
, 1);
916 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
917 RenderPassDrawQuad::Create();
918 render_pass_quad
->SetNew(
920 gfx::Rect(5, 5, 7, 7), // rect
921 RenderPass::Id(10, 7), // render_pass_id
923 0, // mask_resource_id
924 child_pass_rect
, // contents_changed_since_last_frame
925 gfx::RectF(), // mask_uv_rect
926 WebKit::WebFilterOperations(), // filters
927 skia::RefPtr
<SkImageFilter
>(), // filter
928 WebKit::WebFilterOperations()); // background_filters
929 quad_sink
.append(render_pass_quad
.PassAs
<DrawQuad
>(), data
);
931 scoped_ptr
<SolidColorDrawQuad
> color_quad
;
932 color_quad
= SolidColorDrawQuad::Create();
933 color_quad
->SetNew(shared_quad_state
, gfx::Rect(0, 0, 10, 10), 1u);
934 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
936 color_quad
= SolidColorDrawQuad::Create();
937 color_quad
->SetNew(shared_quad_state
, gfx::Rect(0, 10, 10, 10), 2u);
938 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
940 color_quad
= SolidColorDrawQuad::Create();
941 color_quad
->SetNew(shared_quad_state
, gfx::Rect(10, 0, 10, 10), 3u);
942 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
944 color_quad
= SolidColorDrawQuad::Create();
945 color_quad
->SetNew(shared_quad_state
, gfx::Rect(10, 10, 10, 10), 4u);
946 quad_sink
.append(color_quad
.PassAs
<DrawQuad
>(), data
);
948 delegated_renderer_layer
->SetRenderPasses(delegated_render_passes
);
950 // The RenderPasses should be taken by the layer.
951 EXPECT_EQ(0u, delegated_render_passes
.size());
953 root_layer_
= root_layer
.get();
954 delegated_renderer_layer_
= delegated_renderer_layer
.get();
956 if (clip_delegated_renderer_layer_
) {
957 gfx::Rect
clip_rect(21, 27, 23, 21);
959 clip_layer
->setPosition(clip_rect
.origin());
960 clip_layer
->setBounds(clip_rect
.size());
961 clip_layer
->setContentBounds(clip_rect
.size());
962 clip_layer
->setMasksToBounds(true);
964 origin_layer
->setPosition(
965 gfx::PointAtOffsetFromOrigin(-clip_rect
.OffsetFromOrigin()));
967 origin_layer
->addChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
968 clip_layer
->addChild(origin_layer
.Pass());
969 root_layer
->addChild(clip_layer
.Pass());
971 root_layer
->addChild(delegated_renderer_layer
.PassAs
<LayerImpl
>());
974 host_impl_
->activeTree()->SetRootLayer(root_layer
.Pass());
978 LayerImpl
* root_layer_
;
979 DelegatedRendererLayerImpl
* delegated_renderer_layer_
;
980 bool root_delegated_render_pass_is_clipped_
;
981 bool clip_delegated_renderer_layer_
;
984 TEST_F(DelegatedRendererLayerImplTestClip
,
985 QuadsUnclipped_LayerUnclipped_NoSurface
) {
986 root_delegated_render_pass_is_clipped_
= false;
987 clip_delegated_renderer_layer_
= false;
990 LayerTreeHostImpl::FrameData frame
;
991 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
993 ASSERT_EQ(2u, frame
.renderPasses
.size());
994 const QuadList
& contrib_delegated_quad_list
=
995 frame
.renderPasses
[0]->quad_list
;
996 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
997 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
998 ASSERT_EQ(5u, root_delegated_quad_list
.size());
999 const SharedQuadState
* root_delegated_shared_quad_state
=
1000 root_delegated_quad_list
[0]->shared_quad_state
;
1001 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1002 contrib_delegated_quad_list
[0]->shared_quad_state
;
1004 // When the quads don't have a clip of their own, the clip rect is set to
1005 // the drawableContentRect of the delegated renderer layer.
1006 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1007 root_delegated_shared_quad_state
->clip_rect
.ToString());
1008 // Quads are clipped to the delegated renderer layer.
1009 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1011 host_impl_
->drawLayers(frame
);
1012 host_impl_
->didDrawAllLayers(frame
);
1015 TEST_F(DelegatedRendererLayerImplTestClip
,
1016 QuadsClipped_LayerUnclipped_NoSurface
) {
1017 root_delegated_render_pass_is_clipped_
= true;
1018 clip_delegated_renderer_layer_
= false;
1021 LayerTreeHostImpl::FrameData frame
;
1022 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1024 ASSERT_EQ(2u, frame
.renderPasses
.size());
1025 const QuadList
& contrib_delegated_quad_list
=
1026 frame
.renderPasses
[0]->quad_list
;
1027 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1028 const QuadList
& root_delegated_quad_list
=
1029 frame
.renderPasses
[1]->quad_list
;
1030 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1031 const SharedQuadState
* root_delegated_shared_quad_state
=
1032 root_delegated_quad_list
[0]->shared_quad_state
;
1033 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1034 contrib_delegated_quad_list
[0]->shared_quad_state
;
1036 // When the quads have a clip of their own, it is used.
1037 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1038 root_delegated_shared_quad_state
->clip_rect
.ToString());
1039 // Quads came with a clip rect.
1040 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1042 host_impl_
->drawLayers(frame
);
1043 host_impl_
->didDrawAllLayers(frame
);
1046 TEST_F(DelegatedRendererLayerImplTestClip
,
1047 QuadsUnclipped_LayerClipped_NoSurface
) {
1048 root_delegated_render_pass_is_clipped_
= false;
1049 clip_delegated_renderer_layer_
= true;
1052 LayerTreeHostImpl::FrameData frame
;
1053 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1055 ASSERT_EQ(2u, frame
.renderPasses
.size());
1056 const QuadList
& contrib_delegated_quad_list
=
1057 frame
.renderPasses
[0]->quad_list
;
1058 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1059 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1060 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1061 const SharedQuadState
* root_delegated_shared_quad_state
=
1062 root_delegated_quad_list
[0]->shared_quad_state
;
1063 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1064 contrib_delegated_quad_list
[0]->shared_quad_state
;
1066 // When the quads don't have a clip of their own, the clip rect is set to
1067 // the drawableContentRect of the delegated renderer layer. When the layer
1068 // is clipped, that should be seen in the quads' clip_rect.
1069 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1070 root_delegated_shared_quad_state
->clip_rect
.ToString());
1071 // Quads are clipped to the delegated renderer layer.
1072 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1074 host_impl_
->drawLayers(frame
);
1075 host_impl_
->didDrawAllLayers(frame
);
1078 TEST_F(DelegatedRendererLayerImplTestClip
,
1079 QuadsClipped_LayerClipped_NoSurface
) {
1080 root_delegated_render_pass_is_clipped_
= true;
1081 clip_delegated_renderer_layer_
= true;
1084 LayerTreeHostImpl::FrameData frame
;
1085 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1087 ASSERT_EQ(2u, frame
.renderPasses
.size());
1088 const QuadList
& contrib_delegated_quad_list
=
1089 frame
.renderPasses
[0]->quad_list
;
1090 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1091 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1092 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1093 const SharedQuadState
* root_delegated_shared_quad_state
=
1094 root_delegated_quad_list
[0]->shared_quad_state
;
1095 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1096 contrib_delegated_quad_list
[0]->shared_quad_state
;
1098 // When the quads have a clip of their own, it is used, but it is
1099 // combined with the clip rect of the delegated renderer layer.
1100 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1101 root_delegated_shared_quad_state
->clip_rect
.ToString());
1102 // Quads came with a clip rect.
1103 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1105 host_impl_
->drawLayers(frame
);
1106 host_impl_
->didDrawAllLayers(frame
);
1109 TEST_F(DelegatedRendererLayerImplTestClip
,
1110 QuadsUnclipped_LayerUnclipped_Surface
) {
1111 root_delegated_render_pass_is_clipped_
= false;
1112 clip_delegated_renderer_layer_
= false;
1115 delegated_renderer_layer_
->setForceRenderSurface(true);
1117 LayerTreeHostImpl::FrameData frame
;
1118 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1120 ASSERT_EQ(3u, frame
.renderPasses
.size());
1121 const QuadList
& contrib_delegated_quad_list
=
1122 frame
.renderPasses
[0]->quad_list
;
1123 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1124 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1125 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1126 const SharedQuadState
* root_delegated_shared_quad_state
=
1127 root_delegated_quad_list
[0]->shared_quad_state
;
1128 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1129 contrib_delegated_quad_list
[0]->shared_quad_state
;
1131 // When the layer owns a surface, the quads don't need to be clipped
1132 // further than they already specify. If they aren't clipped, then their
1133 // clip rect is ignored, and they are not set as clipped.
1134 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1136 host_impl_
->drawLayers(frame
);
1137 host_impl_
->didDrawAllLayers(frame
);
1140 TEST_F(DelegatedRendererLayerImplTestClip
,
1141 QuadsClipped_LayerUnclipped_Surface
) {
1142 root_delegated_render_pass_is_clipped_
= true;
1143 clip_delegated_renderer_layer_
= false;
1146 delegated_renderer_layer_
->setForceRenderSurface(true);
1148 LayerTreeHostImpl::FrameData frame
;
1149 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1151 ASSERT_EQ(3u, frame
.renderPasses
.size());
1152 const QuadList
& contrib_delegated_quad_list
= frame
.renderPasses
[0]->quad_list
;
1153 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1154 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1155 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1156 const SharedQuadState
* root_delegated_shared_quad_state
= root_delegated_quad_list
[0]->shared_quad_state
;
1157 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1158 contrib_delegated_quad_list
[0]->shared_quad_state
;
1160 // When the quads have a clip of their own, it is used.
1161 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1162 root_delegated_shared_quad_state
->clip_rect
.ToString());
1163 // Quads came with a clip rect.
1164 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1166 host_impl_
->drawLayers(frame
);
1167 host_impl_
->didDrawAllLayers(frame
);
1170 TEST_F(DelegatedRendererLayerImplTestClip
,
1171 QuadsUnclipped_LayerClipped_Surface
) {
1172 root_delegated_render_pass_is_clipped_
= false;
1173 clip_delegated_renderer_layer_
= true;
1176 delegated_renderer_layer_
->setForceRenderSurface(true);
1178 LayerTreeHostImpl::FrameData frame
;
1179 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1181 ASSERT_EQ(3u, frame
.renderPasses
.size());
1182 const QuadList
& contrib_delegated_quad_list
=
1183 frame
.renderPasses
[0]->quad_list
;
1184 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1185 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1186 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1187 const SharedQuadState
* root_delegated_shared_quad_state
=
1188 root_delegated_quad_list
[0]->shared_quad_state
;
1189 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1190 contrib_delegated_quad_list
[0]->shared_quad_state
;
1192 // When the layer owns a surface, the quads don't need to be clipped
1193 // further than they already specify. If they aren't clipped, then their
1194 // clip rect is ignored, and they are not set as clipped.
1195 EXPECT_FALSE(root_delegated_shared_quad_state
->is_clipped
);
1197 host_impl_
->drawLayers(frame
);
1198 host_impl_
->didDrawAllLayers(frame
);
1201 TEST_F(DelegatedRendererLayerImplTestClip
, QuadsClipped_LayerClipped_Surface
) {
1202 root_delegated_render_pass_is_clipped_
= true;
1203 clip_delegated_renderer_layer_
= true;
1206 delegated_renderer_layer_
->setForceRenderSurface(true);
1208 LayerTreeHostImpl::FrameData frame
;
1209 EXPECT_TRUE(host_impl_
->prepareToDraw(frame
));
1211 ASSERT_EQ(3u, frame
.renderPasses
.size());
1212 const QuadList
& contrib_delegated_quad_list
=
1213 frame
.renderPasses
[0]->quad_list
;
1214 ASSERT_EQ(2u, contrib_delegated_quad_list
.size());
1215 const QuadList
& root_delegated_quad_list
= frame
.renderPasses
[1]->quad_list
;
1216 ASSERT_EQ(5u, root_delegated_quad_list
.size());
1217 const SharedQuadState
* root_delegated_shared_quad_state
=
1218 root_delegated_quad_list
[0]->shared_quad_state
;
1219 const SharedQuadState
* contrib_delegated_shared_quad_state
=
1220 contrib_delegated_quad_list
[0]->shared_quad_state
;
1222 // When the quads have a clip of their own, it is used, but it is
1223 // combined with the clip rect of the delegated renderer layer. If the
1224 // layer owns a surface, then it does not have a clip rect of its own.
1225 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1226 root_delegated_shared_quad_state
->clip_rect
.ToString());
1227 // Quads came with a clip rect.
1228 EXPECT_TRUE(root_delegated_shared_quad_state
->is_clipped
);
1230 host_impl_
->drawLayers(frame
);
1231 host_impl_
->didDrawAllLayers(frame
);