Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer_impl_unittest.cc
blob5a797f9ad45c26e2ce733445199c9f8c123a63c4
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_layer_tree_host_impl_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_proxy.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/test/layer_test_common.h"
18 #include "cc/test/render_pass_test_common.h"
19 #include "cc/test/render_pass_test_utils.h"
20 #include "cc/test/test_shared_bitmap_manager.h"
21 #include "cc/test/test_web_graphics_context_3d.h"
22 #include "cc/trees/layer_tree_host_impl.h"
23 #include "cc/trees/layer_tree_impl.h"
24 #include "cc/trees/single_thread_proxy.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/frame_time.h"
27 #include "ui/gfx/transform.h"
29 namespace cc {
30 namespace {
32 class DelegatedRendererLayerImplTest : public testing::Test {
33 public:
34 DelegatedRendererLayerImplTest()
35 : proxy_(),
36 always_impl_thread_and_main_thread_blocked_(&proxy_) {
37 LayerTreeSettings settings;
38 settings.minimum_occlusion_tracking_size = gfx::Size();
40 host_impl_.reset(
41 new FakeLayerTreeHostImpl(settings, &proxy_, &shared_bitmap_manager_));
42 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
43 host_impl_->SetViewportSize(gfx::Size(10, 10));
46 protected:
47 FakeProxy proxy_;
48 DebugScopedSetImplThreadAndMainThreadBlocked
49 always_impl_thread_and_main_thread_blocked_;
50 TestSharedBitmapManager shared_bitmap_manager_;
51 scoped_ptr<LayerTreeHostImpl> host_impl_;
54 class DelegatedRendererLayerImplTestSimple
55 : public DelegatedRendererLayerImplTest {
56 public:
57 DelegatedRendererLayerImplTestSimple()
58 : DelegatedRendererLayerImplTest() {
59 scoped_ptr<LayerImpl> root_layer =
60 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
61 scoped_ptr<LayerImpl> layer_before =
62 SolidColorLayerImpl::Create(host_impl_->active_tree(), 2);
63 scoped_ptr<LayerImpl> layer_after =
64 SolidColorLayerImpl::Create(host_impl_->active_tree(), 3);
65 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
66 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
68 host_impl_->SetViewportSize(gfx::Size(100, 100));
69 root_layer->SetBounds(gfx::Size(100, 100));
71 layer_before->SetPosition(gfx::Point(20, 20));
72 layer_before->SetBounds(gfx::Size(14, 14));
73 layer_before->SetContentBounds(gfx::Size(14, 14));
74 layer_before->SetDrawsContent(true);
75 layer_before->SetForceRenderSurface(true);
77 layer_after->SetPosition(gfx::Point(5, 5));
78 layer_after->SetBounds(gfx::Size(15, 15));
79 layer_after->SetContentBounds(gfx::Size(15, 15));
80 layer_after->SetDrawsContent(true);
81 layer_after->SetForceRenderSurface(true);
83 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
84 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
85 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
86 delegated_renderer_layer->SetDrawsContent(true);
87 gfx::Transform transform;
88 transform.Translate(1.0, 1.0);
89 delegated_renderer_layer->SetTransform(transform);
91 RenderPassList delegated_render_passes;
92 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
93 RenderPassId(9, 6),
94 gfx::Rect(6, 6, 6, 6),
95 gfx::Transform(1, 0, 0, 1, 5, 6));
96 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
97 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
98 RenderPassId(9, 7),
99 gfx::Rect(7, 7, 7, 7),
100 gfx::Transform(1, 0, 0, 1, 7, 8));
101 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
102 AddRenderPassQuad(pass2, pass1);
103 TestRenderPass* pass3 = AddRenderPass(&delegated_render_passes,
104 RenderPassId(9, 8),
105 gfx::Rect(0, 0, 8, 8),
106 gfx::Transform(1, 0, 0, 1, 9, 10));
107 AddRenderPassQuad(pass3, pass2);
108 delegated_renderer_layer->SetFrameDataForRenderPasses(
109 1.f, &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
120 // layer_after.
121 layer_after->AddChild(delegated_renderer_layer.Pass());
122 root_layer->AddChild(layer_after.Pass());
124 // Get the RenderPass generated by layer_before to come before the delegated
125 // RenderPasses.
126 root_layer->AddChild(layer_before.Pass());
127 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
130 protected:
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_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
141 // Each non-DelegatedRendererLayer added one RenderPass. The
142 // DelegatedRendererLayer added two contributing passes.
143 ASSERT_EQ(5u, frame.render_passes.size());
145 // The DelegatedRendererLayer should have added its contributing RenderPasses
146 // to the frame.
147 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
148 EXPECT_EQ(1, frame.render_passes[1]->id.index);
149 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
150 EXPECT_EQ(2, frame.render_passes[2]->id.index);
151 // And all other RenderPasses should be non-delegated.
152 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
153 EXPECT_EQ(0, frame.render_passes[0]->id.index);
154 EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
155 EXPECT_EQ(0, frame.render_passes[3]->id.index);
156 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
157 EXPECT_EQ(0, frame.render_passes[4]->id.index);
159 // The DelegatedRendererLayer should have added its RenderPasses to the frame
160 // in order.
161 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
162 frame.render_passes[1]->output_rect.ToString());
163 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
164 frame.render_passes[2]->output_rect.ToString());
166 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
167 host_impl_->DidDrawAllLayers(frame);
170 TEST_F(DelegatedRendererLayerImplTestSimple,
171 AddsQuadsToContributingRenderPasses) {
172 LayerTreeHostImpl::FrameData frame;
173 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
175 // Each non-DelegatedRendererLayer added one RenderPass. The
176 // DelegatedRendererLayer added two contributing passes.
177 ASSERT_EQ(5u, frame.render_passes.size());
179 // The DelegatedRendererLayer should have added its contributing RenderPasses
180 // to the frame.
181 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
182 EXPECT_EQ(1, frame.render_passes[1]->id.index);
183 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
184 EXPECT_EQ(2, frame.render_passes[2]->id.index);
186 // The DelegatedRendererLayer should have added copies of its quads to
187 // contributing RenderPasses.
188 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
189 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
190 frame.render_passes[1]->quad_list.front()->rect.ToString());
192 // Verify it added the right quads.
193 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
194 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
195 frame.render_passes[2]->quad_list.front()->rect.ToString());
196 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
197 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
198 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
199 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
200 frame.render_passes[1]->quad_list.front()->rect.ToString());
202 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
203 host_impl_->DidDrawAllLayers(frame);
206 TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
207 LayerTreeHostImpl::FrameData frame;
208 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
210 // Each non-DelegatedRendererLayer added one RenderPass. The
211 // DelegatedRendererLayer added two contributing passes.
212 ASSERT_EQ(5u, frame.render_passes.size());
214 // The layer's target is the RenderPass from layer_after_.
215 EXPECT_EQ(RenderPassId(3, 0), frame.render_passes[3]->id);
217 // The DelegatedRendererLayer should have added copies of quads in its root
218 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
219 ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
221 // Verify it added the right quads.
222 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
223 frame.render_passes[3]->quad_list.front()->rect.ToString());
225 // Its target layer should have a quad as well.
226 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
227 frame.render_passes[3]->quad_list.ElementAt(1)->rect.ToString());
229 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
230 host_impl_->DidDrawAllLayers(frame);
233 TEST_F(DelegatedRendererLayerImplTestSimple,
234 QuadsFromRootRenderPassAreModifiedForTheTarget) {
235 LayerTreeHostImpl::FrameData frame;
236 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
238 // Each non-DelegatedRendererLayer added one RenderPass. The
239 // DelegatedRendererLayer added two contributing passes.
240 ASSERT_EQ(5u, frame.render_passes.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 gfx::Transform transform;
246 transform.Translate(4.0, 4.0);
247 EXPECT_TRANSFORMATION_MATRIX_EQ(
248 transform, frame.render_passes[3]->quad_list.front()->quadTransform());
250 // Quads from non-root RenderPasses should not be shifted though.
251 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
253 EXPECT_TRANSFORMATION_MATRIX_EQ(
254 gfx::Transform(),
255 frame.render_passes[2]->quad_list.front()->quadTransform());
256 EXPECT_TRANSFORMATION_MATRIX_EQ(
257 gfx::Transform(),
258 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
259 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
260 EXPECT_TRANSFORMATION_MATRIX_EQ(
261 gfx::Transform(),
262 frame.render_passes[1]->quad_list.front()->quadTransform());
264 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
265 host_impl_->DidDrawAllLayers(frame);
268 TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
269 LayerTreeHostImpl::FrameData frame;
270 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
272 // The delegated layer has a surface between it and the root.
273 EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
275 // Each non-DelegatedRendererLayer added one RenderPass. The
276 // DelegatedRendererLayer added two contributing passes.
277 ASSERT_EQ(5u, frame.render_passes.size());
279 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
280 // render pass' transforms to the root should be shifted by this amount.
281 gfx::Transform transform;
282 transform.Translate(9.0, 9.0);
284 // The first contributing surface has a translation of 5, 6.
285 gfx::Transform five_six(1, 0, 0, 1, 5, 6);
287 // The second contributing surface has a translation of 7, 8.
288 gfx::Transform seven_eight(1, 0, 0, 1, 7, 8);
290 EXPECT_TRANSFORMATION_MATRIX_EQ(
291 transform * five_six, frame.render_passes[1]->transform_to_root_target);
292 EXPECT_TRANSFORMATION_MATRIX_EQ(
293 transform * seven_eight,
294 frame.render_passes[2]->transform_to_root_target);
296 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
297 host_impl_->DidDrawAllLayers(frame);
300 TEST_F(DelegatedRendererLayerImplTestSimple, DoesNotOwnARenderSurface) {
301 LayerTreeHostImpl::FrameData frame;
302 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
304 // If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
305 // has no need to be a RenderSurface for the quads it carries.
306 EXPECT_FALSE(delegated_renderer_layer_->render_surface());
308 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
309 host_impl_->DidDrawAllLayers(frame);
312 TEST_F(DelegatedRendererLayerImplTestSimple, DoesOwnARenderSurfaceForOpacity) {
313 delegated_renderer_layer_->SetOpacity(0.5f);
315 LayerTreeHostImpl::FrameData frame;
316 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
317 host_impl_->active_tree()->root_layer());
318 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
320 // This test case has quads from multiple layers in the delegated renderer, so
321 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
322 // render surface.
323 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
325 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
326 host_impl_->DidDrawAllLayers(frame);
329 TEST_F(DelegatedRendererLayerImplTestSimple,
330 DoesOwnARenderSurfaceForTransform) {
331 gfx::Transform rotation;
332 rotation.RotateAboutZAxis(30.0);
333 delegated_renderer_layer_->SetTransform(rotation);
335 LayerTreeHostImpl::FrameData frame;
336 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
337 host_impl_->active_tree()->root_layer());
338 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
340 // This test case has quads from multiple layers in the delegated renderer, so
341 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
342 // render surface.
343 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
345 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
346 host_impl_->DidDrawAllLayers(frame);
349 class DelegatedRendererLayerImplTestOwnSurface
350 : public DelegatedRendererLayerImplTestSimple {
351 public:
352 DelegatedRendererLayerImplTestOwnSurface()
353 : DelegatedRendererLayerImplTestSimple() {
354 delegated_renderer_layer_->SetForceRenderSurface(true);
358 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
359 LayerTreeHostImpl::FrameData frame;
360 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
362 // Each non-DelegatedRendererLayer added one RenderPass. The
363 // DelegatedRendererLayer added two contributing passes and its owned surface
364 // added one pass.
365 ASSERT_EQ(6u, frame.render_passes.size());
367 // The DelegatedRendererLayer should have added its contributing RenderPasses
368 // to the frame.
369 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
370 EXPECT_EQ(1, frame.render_passes[1]->id.index);
371 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
372 EXPECT_EQ(2, frame.render_passes[2]->id.index);
373 // The DelegatedRendererLayer should have added a RenderPass for its surface
374 // to the frame.
375 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
376 EXPECT_EQ(0, frame.render_passes[3]->id.index);
377 // And all other RenderPasses should be non-delegated.
378 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
379 EXPECT_EQ(0, frame.render_passes[0]->id.index);
380 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
381 EXPECT_EQ(0, frame.render_passes[4]->id.index);
382 EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
383 EXPECT_EQ(0, frame.render_passes[5]->id.index);
385 // The DelegatedRendererLayer should have added its RenderPasses to the frame
386 // in order.
387 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
388 frame.render_passes[1]->output_rect.ToString());
389 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
390 frame.render_passes[2]->output_rect.ToString());
392 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
393 host_impl_->DidDrawAllLayers(frame);
396 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
397 AddsQuadsToContributingRenderPasses) {
398 LayerTreeHostImpl::FrameData frame;
399 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
401 // Each non-DelegatedRendererLayer added one RenderPass. The
402 // DelegatedRendererLayer added two contributing passes and its owned surface
403 // added one pass.
404 ASSERT_EQ(6u, frame.render_passes.size());
406 // The DelegatedRendererLayer should have added its contributing RenderPasses
407 // to the frame.
408 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
409 EXPECT_EQ(1, frame.render_passes[1]->id.index);
410 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
411 EXPECT_EQ(2, frame.render_passes[2]->id.index);
413 // The DelegatedRendererLayer should have added copies of its quads to
414 // contributing RenderPasses.
415 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
416 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
417 frame.render_passes[1]->quad_list.front()->rect.ToString());
419 // Verify it added the right quads.
420 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
422 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
423 frame.render_passes[2]->quad_list.front()->rect.ToString());
424 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
425 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
426 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
427 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
428 frame.render_passes[1]->quad_list.front()->rect.ToString());
430 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
431 host_impl_->DidDrawAllLayers(frame);
434 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
435 LayerTreeHostImpl::FrameData frame;
436 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
438 // Each non-DelegatedRendererLayer added one RenderPass. The
439 // DelegatedRendererLayer added two contributing passes and its owned surface
440 // added one pass.
441 ASSERT_EQ(6u, frame.render_passes.size());
443 // The layer's target is the RenderPass owned by itself.
444 EXPECT_EQ(RenderPassId(4, 0), frame.render_passes[3]->id);
446 // The DelegatedRendererLayer should have added copies of quads in its root
447 // RenderPass to its target RenderPass.
448 // The layer_after also adds one quad.
449 ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
451 // Verify it added the right quads.
452 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
453 frame.render_passes[3]->quad_list.front()->rect.ToString());
455 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
456 host_impl_->DidDrawAllLayers(frame);
459 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
460 QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
461 LayerTreeHostImpl::FrameData frame;
462 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
464 // Each non-DelegatedRendererLayer added one RenderPass. The
465 // DelegatedRendererLayer added two contributing passes and its owned surface
466 // added one pass.
467 ASSERT_EQ(6u, frame.render_passes.size());
469 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
470 // RenderPass' quads do not need to be translated at all.
471 EXPECT_TRANSFORMATION_MATRIX_EQ(
472 gfx::Transform(),
473 frame.render_passes[3]->quad_list.front()->quadTransform());
475 // Quads from non-root RenderPasses should not be shifted either.
476 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
478 EXPECT_TRANSFORMATION_MATRIX_EQ(
479 gfx::Transform(),
480 frame.render_passes[2]->quad_list.front()->quadTransform());
481 EXPECT_TRANSFORMATION_MATRIX_EQ(
482 gfx::Transform(),
483 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
484 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
485 EXPECT_TRANSFORMATION_MATRIX_EQ(
486 gfx::Transform(),
487 frame.render_passes[1]->quad_list.front()->quadTransform());
489 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
490 host_impl_->DidDrawAllLayers(frame);
493 class DelegatedRendererLayerImplTestTransform
494 : public DelegatedRendererLayerImplTest {
495 public:
496 DelegatedRendererLayerImplTestTransform()
497 : root_delegated_render_pass_is_clipped_(false),
498 delegated_device_scale_factor_(2.f) {}
500 void SetUpTest() {
501 host_impl_->SetDeviceScaleFactor(2.f);
503 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
504 host_impl_->active_tree(), 1);
505 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
506 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
508 host_impl_->SetViewportSize(gfx::Size(200, 200));
509 root_layer->SetBounds(gfx::Size(100, 100));
511 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
512 delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
513 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
514 delegated_renderer_layer->SetDrawsContent(true);
515 gfx::Transform transform;
516 transform.Scale(2.0, 2.0);
517 transform.Translate(8.0, 8.0);
518 delegated_renderer_layer->SetTransform(transform);
520 RenderPassList delegated_render_passes;
522 gfx::Size child_pass_content_bounds(7, 7);
523 gfx::Rect child_pass_rect(20, 20, 7, 7);
524 gfx::Transform child_pass_transform;
525 child_pass_transform.Scale(0.8f, 0.8f);
526 child_pass_transform.Translate(9.0, 9.0);
527 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
528 bool child_pass_clipped = false;
531 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
532 RenderPassId(10, 7),
533 child_pass_rect,
534 gfx::Transform());
535 SharedQuadState* shared_quad_state =
536 pass->CreateAndAppendSharedQuadState();
537 shared_quad_state->SetAll(child_pass_transform,
538 child_pass_content_bounds,
539 child_pass_rect,
540 child_pass_clip_rect,
541 child_pass_clipped,
542 1.f,
543 SkXfermode::kSrcOver_Mode,
546 SolidColorDrawQuad* color_quad;
547 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
548 color_quad->SetNew(shared_quad_state,
549 gfx::Rect(20, 20, 3, 7),
550 gfx::Rect(20, 20, 3, 7),
552 false);
554 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
555 color_quad->SetNew(shared_quad_state,
556 gfx::Rect(23, 20, 4, 7),
557 gfx::Rect(23, 20, 4, 7),
559 false);
562 gfx::Size root_pass_content_bounds(100, 100);
563 gfx::Rect root_pass_rect(0, 0, 100, 100);
564 gfx::Transform root_pass_transform;
565 root_pass_transform.Scale(1.5, 1.5);
566 root_pass_transform.Translate(7.0, 7.0);
567 gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
568 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
570 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
571 RenderPassId(9, 6),
572 root_pass_rect,
573 gfx::Transform());
574 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
575 shared_quad_state->SetAll(root_pass_transform,
576 root_pass_content_bounds,
577 root_pass_rect,
578 root_pass_clip_rect,
579 root_pass_clipped,
580 1.f,
581 SkXfermode::kSrcOver_Mode,
584 RenderPassDrawQuad* render_pass_quad =
585 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
586 render_pass_quad->SetNew(shared_quad_state,
587 gfx::Rect(5, 5, 7, 7), // quad_rect
588 gfx::Rect(5, 5, 7, 7), // visible_rect
589 RenderPassId(10, 7), // render_pass_id
590 0, // mask_resource_id
591 gfx::Vector2dF(), // mask_uv_scale
592 gfx::Size(), // mask_texture_size
593 FilterOperations(), // filters
594 gfx::Vector2dF(), // filters_scale
595 FilterOperations()); // background_filters
597 SolidColorDrawQuad* color_quad;
598 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
599 color_quad->SetNew(shared_quad_state,
600 gfx::Rect(0, 0, 10, 10),
601 gfx::Rect(0, 0, 10, 10),
603 false);
605 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
606 color_quad->SetNew(shared_quad_state,
607 gfx::Rect(0, 10, 10, 10),
608 gfx::Rect(0, 10, 10, 10),
610 false);
612 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
613 color_quad->SetNew(shared_quad_state,
614 gfx::Rect(10, 0, 10, 10),
615 gfx::Rect(10, 0, 10, 10),
617 false);
619 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
620 color_quad->SetNew(shared_quad_state,
621 gfx::Rect(10, 10, 10, 10),
622 gfx::Rect(10, 10, 10, 10),
624 false);
626 delegated_renderer_layer->SetFrameDataForRenderPasses(
627 delegated_device_scale_factor_, &delegated_render_passes);
629 // The RenderPasses should be taken by the layer.
630 EXPECT_EQ(0u, delegated_render_passes.size());
632 root_layer_ = root_layer.get();
633 delegated_renderer_layer_ = delegated_renderer_layer.get();
635 root_layer->AddChild(delegated_renderer_layer.Pass());
636 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
639 void VerifyRenderPasses(
640 const LayerTreeHostImpl::FrameData& frame,
641 size_t num_render_passes,
642 const SharedQuadState** root_delegated_shared_quad_state,
643 const SharedQuadState** contrib_delegated_shared_quad_state) {
644 ASSERT_EQ(num_render_passes, frame.render_passes.size());
645 // The contributing render pass in the DelegatedRendererLayer.
646 EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
647 EXPECT_EQ(1, frame.render_passes[0]->id.index);
648 // The root render pass.
649 EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
650 EXPECT_EQ(0, frame.render_passes.back()->id.index);
652 const QuadList& contrib_delegated_quad_list =
653 frame.render_passes[0]->quad_list;
654 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
656 const QuadList& root_delegated_quad_list =
657 frame.render_passes[1]->quad_list;
658 ASSERT_EQ(5u, root_delegated_quad_list.size());
660 // All quads in a render pass should share the same state.
661 *contrib_delegated_shared_quad_state =
662 contrib_delegated_quad_list.front()->shared_quad_state;
663 EXPECT_EQ(*contrib_delegated_shared_quad_state,
664 contrib_delegated_quad_list.ElementAt(1)->shared_quad_state);
666 *root_delegated_shared_quad_state =
667 root_delegated_quad_list.front()->shared_quad_state;
668 EXPECT_EQ(*root_delegated_shared_quad_state,
669 root_delegated_quad_list.ElementAt(1)->shared_quad_state);
670 EXPECT_EQ(*root_delegated_shared_quad_state,
671 root_delegated_quad_list.ElementAt(2)->shared_quad_state);
672 EXPECT_EQ(*root_delegated_shared_quad_state,
673 root_delegated_quad_list.ElementAt(3)->shared_quad_state);
674 EXPECT_EQ(*root_delegated_shared_quad_state,
675 root_delegated_quad_list.ElementAt(4)->shared_quad_state);
677 EXPECT_NE(*contrib_delegated_shared_quad_state,
678 *root_delegated_shared_quad_state);
681 protected:
682 LayerImpl* root_layer_;
683 DelegatedRendererLayerImpl* delegated_renderer_layer_;
684 bool root_delegated_render_pass_is_clipped_;
685 float delegated_device_scale_factor_;
688 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
689 root_delegated_render_pass_is_clipped_ = false;
690 SetUpTest();
692 LayerTreeHostImpl::FrameData frame;
693 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
695 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
696 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
697 VerifyRenderPasses(
698 frame,
700 &root_delegated_shared_quad_state,
701 &contrib_delegated_shared_quad_state);
703 // When the quads don't have a clip of their own, the clip rect is set to
704 // the drawable_content_rect of the delegated renderer layer.
705 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
706 root_delegated_shared_quad_state->clip_rect.ToString());
708 // Even though the quads in the root pass have no clip of their own, they
709 // inherit the clip rect from the delegated renderer layer if it does not
710 // own a surface.
711 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
713 gfx::Transform expected;
714 // Device scale factor.
715 expected.Scale(2.0, 2.0);
716 // This is the transform from the layer's space to its target.
717 expected.Translate(20, 20);
718 expected.Scale(2.0, 2.0);
719 expected.Translate(8.0, 8.0);
720 // This is the transform within the source frame.
721 // Inverse device scale factor to go from physical space to layer space.
722 expected.Scale(0.5, 0.5);
723 expected.Scale(1.5, 1.5);
724 expected.Translate(7.0, 7.0);
725 EXPECT_TRANSFORMATION_MATRIX_EQ(
726 expected, root_delegated_shared_quad_state->content_to_target_transform);
728 // The contributing render pass should not be transformed from its input.
729 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
730 contrib_delegated_shared_quad_state->clip_rect.ToString());
731 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
732 expected.MakeIdentity();
733 expected.Scale(0.8f, 0.8f);
734 expected.Translate(9.0, 9.0);
735 EXPECT_TRANSFORMATION_MATRIX_EQ(
736 expected,
737 contrib_delegated_shared_quad_state->content_to_target_transform);
739 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
740 host_impl_->DidDrawAllLayers(frame);
743 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
744 root_delegated_render_pass_is_clipped_ = true;
745 SetUpTest();
747 LayerTreeHostImpl::FrameData frame;
748 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
750 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
751 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
752 VerifyRenderPasses(
753 frame,
755 &root_delegated_shared_quad_state,
756 &contrib_delegated_shared_quad_state);
758 // Since the quads have a clip_rect it should be modified by delegated
759 // renderer layer's draw_transform.
760 // The position of the resulting clip_rect is:
761 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
762 // layer scale (2) + layer position (20) = 46
763 // The device scale is 2, so everything gets doubled, giving 92.
765 // The size is 35x35 scaled by the device scale.
766 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
767 root_delegated_shared_quad_state->clip_rect.ToString());
769 // The quads had a clip and it should be preserved.
770 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
772 gfx::Transform expected;
773 // Device scale factor.
774 expected.Scale(2.0, 2.0);
775 // This is the transform from the layer's space to its target.
776 expected.Translate(20, 20);
777 expected.Scale(2.0, 2.0);
778 expected.Translate(8.0, 8.0);
779 // This is the transform within the source frame.
780 // Inverse device scale factor to go from physical space to layer space.
781 expected.Scale(0.5, 0.5);
782 expected.Scale(1.5, 1.5);
783 expected.Translate(7.0, 7.0);
784 EXPECT_TRANSFORMATION_MATRIX_EQ(
785 expected, root_delegated_shared_quad_state->content_to_target_transform);
787 // The contributing render pass should not be transformed from its input.
788 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
789 contrib_delegated_shared_quad_state->clip_rect.ToString());
790 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
791 expected.MakeIdentity();
792 expected.Scale(0.8f, 0.8f);
793 expected.Translate(9.0, 9.0);
794 EXPECT_TRANSFORMATION_MATRIX_EQ(
795 expected,
796 contrib_delegated_shared_quad_state->content_to_target_transform);
798 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
799 host_impl_->DidDrawAllLayers(frame);
802 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
803 root_delegated_render_pass_is_clipped_ = false;
804 SetUpTest();
806 delegated_renderer_layer_->SetForceRenderSurface(true);
808 LayerTreeHostImpl::FrameData frame;
809 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
811 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
812 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
813 VerifyRenderPasses(
814 frame,
816 &root_delegated_shared_quad_state,
817 &contrib_delegated_shared_quad_state);
819 // When the layer owns a surface, then its position and translation are not
820 // a part of its draw transform.
821 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
822 root_delegated_shared_quad_state->clip_rect.ToString());
824 // Since the layer owns a surface it doesn't need to clip its quads, so
825 // unclipped quads remain unclipped.
826 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
828 gfx::Transform expected;
829 // This is the transform within the source frame.
830 expected.Scale(1.5, 1.5);
831 expected.Translate(7.0, 7.0);
832 EXPECT_TRANSFORMATION_MATRIX_EQ(
833 expected, root_delegated_shared_quad_state->content_to_target_transform);
835 // The contributing render pass should not be transformed from its input.
836 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
837 contrib_delegated_shared_quad_state->clip_rect.ToString());
838 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
839 expected.MakeIdentity();
840 expected.Scale(0.8f, 0.8f);
841 expected.Translate(9.0, 9.0);
842 EXPECT_TRANSFORMATION_MATRIX_EQ(
843 expected,
844 contrib_delegated_shared_quad_state->content_to_target_transform);
846 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
847 host_impl_->DidDrawAllLayers(frame);
850 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
851 root_delegated_render_pass_is_clipped_ = true;
852 SetUpTest();
854 delegated_renderer_layer_->SetForceRenderSurface(true);
856 LayerTreeHostImpl::FrameData frame;
857 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
859 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
860 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
861 VerifyRenderPasses(
862 frame,
864 &root_delegated_shared_quad_state,
865 &contrib_delegated_shared_quad_state);
867 // When the layer owns a surface, then its position and translation are not
868 // a part of its draw transform. The clip_rect should be preserved.
869 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
870 root_delegated_shared_quad_state->clip_rect.ToString());
872 // The quads had a clip and it should be preserved.
873 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
875 gfx::Transform expected;
876 // This is the transform within the source frame.
877 expected.Scale(1.5, 1.5);
878 expected.Translate(7.0, 7.0);
879 EXPECT_TRANSFORMATION_MATRIX_EQ(
880 expected, root_delegated_shared_quad_state->content_to_target_transform);
882 // The contributing render pass should not be transformed from its input.
883 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
884 contrib_delegated_shared_quad_state->clip_rect.ToString());
885 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
886 expected.MakeIdentity();
887 expected.Scale(0.8f, 0.8f);
888 expected.Translate(9.0, 9.0);
889 EXPECT_TRANSFORMATION_MATRIX_EQ(
890 expected,
891 contrib_delegated_shared_quad_state->content_to_target_transform);
893 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
894 host_impl_->DidDrawAllLayers(frame);
897 TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
898 root_delegated_render_pass_is_clipped_ = true;
899 delegated_device_scale_factor_ = 1.3f;
901 SetUpTest();
903 LayerTreeHostImpl::FrameData frame;
904 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
906 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
907 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
908 VerifyRenderPasses(frame,
910 &root_delegated_shared_quad_state,
911 &contrib_delegated_shared_quad_state);
913 // The parent tree's device scale factor is 2.0, but the child has submitted a
914 // frame with a device scale factor of 1.3. Absent any better option, the
915 // only thing we can do is scale from 1.3 -> 2.0.
917 gfx::Transform expected;
918 // Device scale factor (from parent).
919 expected.Scale(2.0, 2.0);
920 // This is the transform from the layer's space to its target.
921 expected.Translate(20, 20);
922 expected.Scale(2.0, 2.0);
923 expected.Translate(8.0, 8.0);
924 // This is the transform within the source frame.
925 // Inverse device scale factor (from child).
926 expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
927 expected.Scale(1.5, 1.5);
928 expected.Translate(7.0, 7.0);
929 EXPECT_TRANSFORMATION_MATRIX_EQ(
930 expected, root_delegated_shared_quad_state->content_to_target_transform);
932 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
933 host_impl_->DidDrawAllLayers(frame);
936 class DelegatedRendererLayerImplTestClip
937 : public DelegatedRendererLayerImplTest {
938 public:
939 void SetUpTest() {
940 scoped_ptr<LayerImpl> root_layer =
941 LayerImpl::Create(host_impl_->active_tree(), 1);
942 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
943 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
944 scoped_ptr<LayerImpl> clip_layer =
945 LayerImpl::Create(host_impl_->active_tree(), 3);
946 scoped_ptr<LayerImpl> origin_layer =
947 LayerImpl::Create(host_impl_->active_tree(), 4);
949 host_impl_->SetViewportSize(gfx::Size(100, 100));
950 root_layer->SetBounds(gfx::Size(100, 100));
952 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
953 delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
954 delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
955 delegated_renderer_layer->SetDrawsContent(true);
957 RenderPassList delegated_render_passes;
959 gfx::Size child_pass_content_bounds(7, 7);
960 gfx::Rect child_pass_rect(20, 20, 7, 7);
961 gfx::Transform child_pass_transform;
962 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
963 bool child_pass_clipped = false;
966 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
967 RenderPassId(10, 7),
968 child_pass_rect,
969 gfx::Transform());
970 SharedQuadState* shared_quad_state =
971 pass->CreateAndAppendSharedQuadState();
972 shared_quad_state->SetAll(child_pass_transform,
973 child_pass_content_bounds,
974 child_pass_rect,
975 child_pass_clip_rect,
976 child_pass_clipped,
977 1.f,
978 SkXfermode::kSrcOver_Mode,
981 SolidColorDrawQuad* color_quad;
982 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
983 color_quad->SetNew(shared_quad_state,
984 gfx::Rect(20, 20, 3, 7),
985 gfx::Rect(20, 20, 3, 7),
987 false);
989 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
990 color_quad->SetNew(shared_quad_state,
991 gfx::Rect(23, 20, 4, 7),
992 gfx::Rect(23, 20, 4, 7),
994 false);
997 gfx::Size root_pass_content_bounds(50, 50);
998 gfx::Rect root_pass_rect(0, 0, 50, 50);
999 gfx::Transform root_pass_transform;
1000 gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
1001 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
1003 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
1004 RenderPassId(9, 6),
1005 root_pass_rect,
1006 gfx::Transform());
1007 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
1008 shared_quad_state->SetAll(root_pass_transform,
1009 root_pass_content_bounds,
1010 root_pass_rect,
1011 root_pass_clip_rect,
1012 root_pass_clipped,
1013 1.f,
1014 SkXfermode::kSrcOver_Mode,
1017 RenderPassDrawQuad* render_pass_quad =
1018 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
1019 render_pass_quad->SetNew(shared_quad_state,
1020 gfx::Rect(5, 5, 7, 7), // quad_rect
1021 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1022 RenderPassId(10, 7), // render_pass_id
1023 0, // mask_resource_id
1024 gfx::Vector2dF(), // mask_uv_scale
1025 gfx::Size(), // mask_texture_size,
1026 FilterOperations(), // filters
1027 gfx::Vector2dF(), // filters_scale
1028 FilterOperations()); // background_filters
1030 SolidColorDrawQuad* color_quad;
1031 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1032 color_quad->SetNew(shared_quad_state,
1033 gfx::Rect(0, 0, 10, 10),
1034 gfx::Rect(0, 0, 10, 10),
1036 false);
1038 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1039 color_quad->SetNew(shared_quad_state,
1040 gfx::Rect(0, 10, 10, 10),
1041 gfx::Rect(0, 10, 10, 10),
1043 false);
1045 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1046 color_quad->SetNew(shared_quad_state,
1047 gfx::Rect(10, 0, 10, 10),
1048 gfx::Rect(10, 0, 10, 10),
1050 false);
1052 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1053 color_quad->SetNew(shared_quad_state,
1054 gfx::Rect(10, 10, 10, 10),
1055 gfx::Rect(10, 10, 10, 10),
1057 false);
1059 delegated_renderer_layer->SetFrameDataForRenderPasses(
1060 1.f, &delegated_render_passes);
1062 // The RenderPasses should be taken by the layer.
1063 EXPECT_EQ(0u, delegated_render_passes.size());
1065 root_layer_ = root_layer.get();
1066 delegated_renderer_layer_ = delegated_renderer_layer.get();
1068 if (clip_delegated_renderer_layer_) {
1069 gfx::Rect clip_rect(21, 27, 23, 21);
1071 clip_layer->SetPosition(clip_rect.origin());
1072 clip_layer->SetBounds(clip_rect.size());
1073 clip_layer->SetContentBounds(clip_rect.size());
1074 clip_layer->SetMasksToBounds(true);
1076 origin_layer->SetPosition(
1077 gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin()));
1079 origin_layer->AddChild(delegated_renderer_layer.Pass());
1080 clip_layer->AddChild(origin_layer.Pass());
1081 root_layer->AddChild(clip_layer.Pass());
1082 } else {
1083 root_layer->AddChild(delegated_renderer_layer.Pass());
1086 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1089 protected:
1090 LayerImpl* root_layer_;
1091 DelegatedRendererLayerImpl* delegated_renderer_layer_;
1092 bool root_delegated_render_pass_is_clipped_;
1093 bool clip_delegated_renderer_layer_;
1096 TEST_F(DelegatedRendererLayerImplTestClip,
1097 QuadsUnclipped_LayerUnclipped_NoSurface) {
1098 root_delegated_render_pass_is_clipped_ = false;
1099 clip_delegated_renderer_layer_ = false;
1100 SetUpTest();
1102 LayerTreeHostImpl::FrameData frame;
1103 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1105 ASSERT_EQ(2u, frame.render_passes.size());
1106 const QuadList& contrib_delegated_quad_list =
1107 frame.render_passes[0]->quad_list;
1108 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1109 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1110 ASSERT_EQ(5u, root_delegated_quad_list.size());
1111 const SharedQuadState* root_delegated_shared_quad_state =
1112 root_delegated_quad_list.front()->shared_quad_state;
1114 // When the quads don't have a clip of their own, the clip rect is set to
1115 // the drawable_content_rect of the delegated renderer layer.
1116 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1117 root_delegated_shared_quad_state->clip_rect.ToString());
1118 // Quads are clipped to the delegated renderer layer.
1119 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1121 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1122 host_impl_->DidDrawAllLayers(frame);
1125 TEST_F(DelegatedRendererLayerImplTestClip,
1126 QuadsClipped_LayerUnclipped_NoSurface) {
1127 root_delegated_render_pass_is_clipped_ = true;
1128 clip_delegated_renderer_layer_ = false;
1129 SetUpTest();
1131 LayerTreeHostImpl::FrameData frame;
1132 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1134 ASSERT_EQ(2u, frame.render_passes.size());
1135 const QuadList& contrib_delegated_quad_list =
1136 frame.render_passes[0]->quad_list;
1137 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1138 const QuadList& root_delegated_quad_list =
1139 frame.render_passes[1]->quad_list;
1140 ASSERT_EQ(5u, root_delegated_quad_list.size());
1141 const SharedQuadState* root_delegated_shared_quad_state =
1142 root_delegated_quad_list.front()->shared_quad_state;
1144 // When the quads have a clip of their own, it is used.
1145 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1146 root_delegated_shared_quad_state->clip_rect.ToString());
1147 // Quads came with a clip rect.
1148 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1150 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1151 host_impl_->DidDrawAllLayers(frame);
1154 TEST_F(DelegatedRendererLayerImplTestClip,
1155 QuadsUnclipped_LayerClipped_NoSurface) {
1156 root_delegated_render_pass_is_clipped_ = false;
1157 clip_delegated_renderer_layer_ = true;
1158 SetUpTest();
1160 LayerTreeHostImpl::FrameData frame;
1161 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1163 ASSERT_EQ(2u, frame.render_passes.size());
1164 const QuadList& contrib_delegated_quad_list =
1165 frame.render_passes[0]->quad_list;
1166 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1167 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1168 ASSERT_EQ(5u, root_delegated_quad_list.size());
1169 const SharedQuadState* root_delegated_shared_quad_state =
1170 root_delegated_quad_list.front()->shared_quad_state;
1172 // When the quads don't have a clip of their own, the clip rect is set to
1173 // the drawable_content_rect of the delegated renderer layer. When the layer
1174 // is clipped, that should be seen in the quads' clip_rect.
1175 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1176 root_delegated_shared_quad_state->clip_rect.ToString());
1177 // Quads are clipped to the delegated renderer layer.
1178 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1180 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1181 host_impl_->DidDrawAllLayers(frame);
1184 TEST_F(DelegatedRendererLayerImplTestClip,
1185 QuadsClipped_LayerClipped_NoSurface) {
1186 root_delegated_render_pass_is_clipped_ = true;
1187 clip_delegated_renderer_layer_ = true;
1188 SetUpTest();
1190 LayerTreeHostImpl::FrameData frame;
1191 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1193 ASSERT_EQ(2u, frame.render_passes.size());
1194 const QuadList& contrib_delegated_quad_list =
1195 frame.render_passes[0]->quad_list;
1196 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1197 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1198 ASSERT_EQ(5u, root_delegated_quad_list.size());
1199 const SharedQuadState* root_delegated_shared_quad_state =
1200 root_delegated_quad_list.front()->shared_quad_state;
1202 // When the quads have a clip of their own, it is used, but it is
1203 // combined with the clip rect of the delegated renderer layer.
1204 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1205 root_delegated_shared_quad_state->clip_rect.ToString());
1206 // Quads came with a clip rect.
1207 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1209 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1210 host_impl_->DidDrawAllLayers(frame);
1213 TEST_F(DelegatedRendererLayerImplTestClip,
1214 QuadsUnclipped_LayerUnclipped_Surface) {
1215 root_delegated_render_pass_is_clipped_ = false;
1216 clip_delegated_renderer_layer_ = false;
1217 SetUpTest();
1219 delegated_renderer_layer_->SetForceRenderSurface(true);
1221 LayerTreeHostImpl::FrameData frame;
1222 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1224 ASSERT_EQ(3u, frame.render_passes.size());
1225 const QuadList& contrib_delegated_quad_list =
1226 frame.render_passes[0]->quad_list;
1227 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1228 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1229 ASSERT_EQ(5u, root_delegated_quad_list.size());
1230 const SharedQuadState* root_delegated_shared_quad_state =
1231 root_delegated_quad_list.front()->shared_quad_state;
1233 // When the layer owns a surface, the quads don't need to be clipped
1234 // further than they already specify. If they aren't clipped, then their
1235 // clip rect is ignored, and they are not set as clipped.
1236 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1238 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1239 host_impl_->DidDrawAllLayers(frame);
1242 TEST_F(DelegatedRendererLayerImplTestClip,
1243 QuadsClipped_LayerUnclipped_Surface) {
1244 root_delegated_render_pass_is_clipped_ = true;
1245 clip_delegated_renderer_layer_ = false;
1246 SetUpTest();
1248 delegated_renderer_layer_->SetForceRenderSurface(true);
1250 LayerTreeHostImpl::FrameData frame;
1251 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1253 ASSERT_EQ(3u, frame.render_passes.size());
1254 const QuadList& contrib_delegated_quad_list =
1255 frame.render_passes[0]->quad_list;
1256 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1257 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1258 ASSERT_EQ(5u, root_delegated_quad_list.size());
1259 const SharedQuadState* root_delegated_shared_quad_state =
1260 root_delegated_quad_list.front()->shared_quad_state;
1262 // When the quads have a clip of their own, it is used.
1263 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1264 root_delegated_shared_quad_state->clip_rect.ToString());
1265 // Quads came with a clip rect.
1266 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1268 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1269 host_impl_->DidDrawAllLayers(frame);
1272 TEST_F(DelegatedRendererLayerImplTestClip,
1273 QuadsUnclipped_LayerClipped_Surface) {
1274 root_delegated_render_pass_is_clipped_ = false;
1275 clip_delegated_renderer_layer_ = true;
1276 SetUpTest();
1278 delegated_renderer_layer_->SetForceRenderSurface(true);
1280 LayerTreeHostImpl::FrameData frame;
1281 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1283 ASSERT_EQ(3u, frame.render_passes.size());
1284 const QuadList& contrib_delegated_quad_list =
1285 frame.render_passes[0]->quad_list;
1286 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1287 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1288 ASSERT_EQ(5u, root_delegated_quad_list.size());
1289 const SharedQuadState* root_delegated_shared_quad_state =
1290 root_delegated_quad_list.front()->shared_quad_state;
1292 // When the layer owns a surface, the quads don't need to be clipped
1293 // further than they already specify. If they aren't clipped, then their
1294 // clip rect is ignored, and they are not set as clipped.
1295 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1297 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1298 host_impl_->DidDrawAllLayers(frame);
1301 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) {
1302 root_delegated_render_pass_is_clipped_ = true;
1303 clip_delegated_renderer_layer_ = true;
1304 SetUpTest();
1306 delegated_renderer_layer_->SetForceRenderSurface(true);
1308 LayerTreeHostImpl::FrameData frame;
1309 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1311 ASSERT_EQ(3u, frame.render_passes.size());
1312 const QuadList& contrib_delegated_quad_list =
1313 frame.render_passes[0]->quad_list;
1314 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1315 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1316 ASSERT_EQ(5u, root_delegated_quad_list.size());
1317 const SharedQuadState* root_delegated_shared_quad_state =
1318 root_delegated_quad_list.front()->shared_quad_state;
1320 // When the quads have a clip of their own, it is used, but it is
1321 // combined with the clip rect of the delegated renderer layer. If the
1322 // layer owns a surface, then it does not have a clip rect of its own.
1323 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1324 root_delegated_shared_quad_state->clip_rect.ToString());
1325 // Quads came with a clip rect.
1326 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1328 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1329 host_impl_->DidDrawAllLayers(frame);
1332 TEST_F(DelegatedRendererLayerImplTest, InvalidRenderPassDrawQuad) {
1333 scoped_ptr<LayerImpl> root_layer =
1334 LayerImpl::Create(host_impl_->active_tree(), 1);
1335 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
1336 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
1338 host_impl_->SetViewportSize(gfx::Size(100, 100));
1340 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
1341 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
1342 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
1343 delegated_renderer_layer->SetDrawsContent(true);
1345 RenderPassList delegated_render_passes;
1346 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1347 RenderPassId(9, 6),
1348 gfx::Rect(0, 0, 10, 10),
1349 gfx::Transform());
1350 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
1352 // This render pass isn't part of the frame.
1353 scoped_ptr<TestRenderPass> missing_pass(TestRenderPass::Create());
1354 missing_pass->SetNew(RenderPassId(9, 7),
1355 gfx::Rect(7, 7, 7, 7),
1356 gfx::Rect(7, 7, 7, 7),
1357 gfx::Transform());
1359 // But a render pass quad refers to it.
1360 AddRenderPassQuad(pass1, missing_pass.get());
1362 delegated_renderer_layer->SetFrameDataForRenderPasses(
1363 1.f, &delegated_render_passes);
1365 // The RenderPasses should be taken by the layer.
1366 EXPECT_EQ(0u, delegated_render_passes.size());
1368 root_layer->AddChild(delegated_renderer_layer.Pass());
1369 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1371 LayerTreeHostImpl::FrameData frame;
1372 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1374 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1375 ASSERT_EQ(1u, frame.render_passes.size());
1376 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
1377 EXPECT_EQ(DrawQuad::SOLID_COLOR,
1378 frame.render_passes[0]->quad_list.front()->material);
1380 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1381 host_impl_->DidDrawAllLayers(frame);
1384 TEST_F(DelegatedRendererLayerImplTest, Occlusion) {
1385 gfx::Size layer_size(1000, 1000);
1386 gfx::Size viewport_size(1000, 1000);
1387 gfx::Rect quad_screen_rect(211, 300, 400, 500);
1389 gfx::Transform transform;
1390 transform.Translate(211.0, 300.0);
1392 LayerTestCommon::LayerImplTest impl;
1394 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
1395 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
1396 delegated_renderer_layer_impl->SetBounds(layer_size);
1397 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1398 delegated_renderer_layer_impl->SetDrawsContent(true);
1400 // Contributing render pass is offset by a transform and holds a quad that
1401 // covers it entirely.
1402 RenderPassList delegated_render_passes;
1403 // pass2 is just the size of the quad. It contributes to |pass1| with a
1404 // translation of (211,300).
1405 RenderPassId pass2_id =
1406 delegated_renderer_layer_impl->FirstContributingRenderPassId();
1407 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
1408 pass2_id,
1409 gfx::Rect(quad_screen_rect.size()),
1410 transform);
1411 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
1412 // |pass1| covers the whole layer.
1413 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
1414 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1415 pass1_id,
1416 gfx::Rect(layer_size),
1417 gfx::Transform());
1418 AddRenderPassQuad(pass1,
1419 pass2,
1421 FilterOperations(),
1422 transform,
1423 SkXfermode::kSrcOver_Mode);
1424 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1425 1.f, &delegated_render_passes);
1427 impl.CalcDrawProps(viewport_size);
1430 SCOPED_TRACE("No occlusion");
1431 gfx::Rect occluded;
1434 SCOPED_TRACE("Root render pass");
1435 impl.AppendQuadsForPassWithOcclusion(
1436 delegated_renderer_layer_impl, pass1_id, occluded);
1437 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1438 quad_screen_rect);
1439 ASSERT_EQ(1u, impl.quad_list().size());
1440 EXPECT_EQ(DrawQuad::RENDER_PASS, impl.quad_list().front()->material);
1443 SCOPED_TRACE("Contributing render pass");
1444 impl.AppendQuadsForPassWithOcclusion(
1445 delegated_renderer_layer_impl, pass2_id, occluded);
1446 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1447 impl.quad_list(), gfx::Rect(quad_screen_rect.size()));
1448 ASSERT_EQ(1u, impl.quad_list().size());
1449 EXPECT_EQ(DrawQuad::SOLID_COLOR, impl.quad_list().front()->material);
1454 SCOPED_TRACE("Full occlusion");
1456 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1458 SCOPED_TRACE("Root render pass");
1459 impl.AppendQuadsForPassWithOcclusion(
1460 delegated_renderer_layer_impl, pass1_id, occluded);
1461 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1462 gfx::Rect());
1463 EXPECT_EQ(impl.quad_list().size(), 0u);
1466 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1468 SCOPED_TRACE("Contributing render pass");
1469 impl.AppendQuadsForPassWithOcclusion(
1470 delegated_renderer_layer_impl, pass2_id, occluded);
1471 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1472 gfx::Rect());
1473 EXPECT_EQ(impl.quad_list().size(), 0u);
1478 SCOPED_TRACE("Partial occlusion");
1480 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1482 SCOPED_TRACE("Root render pass");
1483 impl.AppendQuadsForPassWithOcclusion(
1484 delegated_renderer_layer_impl, pass1_id, occlusion_in_root_target);
1485 size_t partially_occluded_count = 0;
1486 LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(),
1487 occlusion_in_root_target,
1488 &partially_occluded_count);
1489 // The layer outputs one quad, which is partially occluded.
1490 EXPECT_EQ(1u, impl.quad_list().size());
1491 EXPECT_EQ(1u, partially_occluded_count);
1494 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1495 // Move the occlusion to where it is in the contributing surface.
1496 gfx::Rect occlusion_in_target_of_delegated_quad =
1497 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1499 SCOPED_TRACE("Contributing render pass");
1500 impl.AppendQuadsForPassWithOcclusion(
1501 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
1502 size_t partially_occluded_count = 0;
1503 LayerTestCommon::VerifyQuadsAreOccluded(
1504 impl.quad_list(),
1505 occlusion_in_target_of_delegated_quad,
1506 &partially_occluded_count);
1507 // The layer outputs one quad, which is partially occluded.
1508 EXPECT_EQ(1u, impl.quad_list().size());
1509 EXPECT_EQ(1u, partially_occluded_count);
1510 // The quad in the contributing surface is at (211,300) in the root.
1511 // The occlusion extends to 500 in the x-axis, pushing the left of the
1512 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1513 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1514 impl.quad_list().front()->visible_rect.ToString());
1517 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1518 // Move the occlusion to where it is in the contributing surface.
1519 gfx::Rect occlusion_in_target_of_delegated_quad =
1520 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1522 SCOPED_TRACE("Contributing render pass with transformed root");
1524 gfx::Transform layer_transform;
1525 layer_transform.Translate(11.0, 0.0);
1526 delegated_renderer_layer_impl->SetTransform(layer_transform);
1528 occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0);
1530 impl.CalcDrawProps(viewport_size);
1532 impl.AppendQuadsForPassWithOcclusion(
1533 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
1534 size_t partially_occluded_count = 0;
1535 LayerTestCommon::VerifyQuadsAreOccluded(
1536 impl.quad_list(),
1537 occlusion_in_target_of_delegated_quad,
1538 &partially_occluded_count);
1539 // The layer outputs one quad, which is partially occluded.
1540 EXPECT_EQ(1u, impl.quad_list().size());
1541 EXPECT_EQ(1u, partially_occluded_count);
1542 // The quad in the contributing surface is at (222,300) in the transformed
1543 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1544 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1545 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1546 impl.quad_list().front()->visible_rect.ToString());
1551 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) {
1552 gfx::Size layer_size(1000, 1000);
1554 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl =
1555 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5);
1556 delegated_renderer_layer_impl->SetBounds(layer_size);
1557 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1558 delegated_renderer_layer_impl->SetDrawsContent(true);
1560 RenderPassList delegated_render_passes;
1561 // |pass1| covers the whole layer.
1562 RenderPassId pass1_id = RenderPassId(5, 0);
1563 AddRenderPass(&delegated_render_passes,
1564 pass1_id,
1565 gfx::Rect(layer_size),
1566 gfx::Transform());
1567 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1568 2.f, &delegated_render_passes);
1569 EXPECT_EQ(0.5f, delegated_renderer_layer_impl->inverse_device_scale_factor());
1571 scoped_ptr<DelegatedRendererLayerImpl> other_layer =
1572 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6);
1574 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get());
1576 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor());
1579 } // namespace
1580 } // namespace cc