The DisplayVirtualKeyboard function on Windows 8 and beyond should not be displaying...
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer_impl_unittest.cc
blobe66cc76642ff5762e36bd75ed610e26e5fde24c7
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_layer_tree_host_impl_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_proxy.h"
16 #include "cc/test/fake_rendering_stats_instrumentation.h"
17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/test/layer_test_common.h"
19 #include "cc/test/render_pass_test_common.h"
20 #include "cc/test/render_pass_test_utils.h"
21 #include "cc/test/test_shared_bitmap_manager.h"
22 #include "cc/test/test_web_graphics_context_3d.h"
23 #include "cc/trees/layer_tree_host_impl.h"
24 #include "cc/trees/layer_tree_impl.h"
25 #include "cc/trees/single_thread_proxy.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gfx/frame_time.h"
28 #include "ui/gfx/transform.h"
30 namespace cc {
31 namespace {
33 class DelegatedRendererLayerImplTest : public testing::Test {
34 public:
35 DelegatedRendererLayerImplTest()
36 : proxy_(),
37 always_impl_thread_and_main_thread_blocked_(&proxy_) {
38 LayerTreeSettings settings;
39 settings.minimum_occlusion_tracking_size = gfx::Size();
41 host_impl_.reset(
42 new FakeLayerTreeHostImpl(settings, &proxy_, &shared_bitmap_manager_));
43 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
44 host_impl_->SetViewportSize(gfx::Size(10, 10));
47 protected:
48 FakeProxy proxy_;
49 DebugScopedSetImplThreadAndMainThreadBlocked
50 always_impl_thread_and_main_thread_blocked_;
51 TestSharedBitmapManager shared_bitmap_manager_;
52 scoped_ptr<LayerTreeHostImpl> host_impl_;
55 class DelegatedRendererLayerImplTestSimple
56 : public DelegatedRendererLayerImplTest {
57 public:
58 DelegatedRendererLayerImplTestSimple()
59 : DelegatedRendererLayerImplTest() {
60 scoped_ptr<LayerImpl> root_layer =
61 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
62 scoped_ptr<LayerImpl> layer_before =
63 SolidColorLayerImpl::Create(host_impl_->active_tree(), 2);
64 scoped_ptr<LayerImpl> layer_after =
65 SolidColorLayerImpl::Create(host_impl_->active_tree(), 3);
66 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
67 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
69 host_impl_->SetViewportSize(gfx::Size(100, 100));
70 root_layer->SetBounds(gfx::Size(100, 100));
72 layer_before->SetPosition(gfx::Point(20, 20));
73 layer_before->SetBounds(gfx::Size(14, 14));
74 layer_before->SetContentBounds(gfx::Size(14, 14));
75 layer_before->SetDrawsContent(true);
76 layer_before->SetForceRenderSurface(true);
78 layer_after->SetPosition(gfx::Point(5, 5));
79 layer_after->SetBounds(gfx::Size(15, 15));
80 layer_after->SetContentBounds(gfx::Size(15, 15));
81 layer_after->SetDrawsContent(true);
82 layer_after->SetForceRenderSurface(true);
84 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
85 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
86 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
87 delegated_renderer_layer->SetDrawsContent(true);
88 gfx::Transform transform;
89 transform.Translate(1.0, 1.0);
90 delegated_renderer_layer->SetTransform(transform);
92 RenderPassList delegated_render_passes;
93 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
94 RenderPassId(9, 6),
95 gfx::Rect(6, 6, 6, 6),
96 gfx::Transform(1, 0, 0, 1, 5, 6));
97 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
98 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
99 RenderPassId(9, 7),
100 gfx::Rect(7, 7, 7, 7),
101 gfx::Transform(1, 0, 0, 1, 7, 8));
102 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
103 AddRenderPassQuad(pass2, pass1);
104 TestRenderPass* pass3 = AddRenderPass(&delegated_render_passes,
105 RenderPassId(9, 8),
106 gfx::Rect(0, 0, 8, 8),
107 gfx::Transform(1, 0, 0, 1, 9, 10));
108 AddRenderPassQuad(pass3, pass2);
109 delegated_renderer_layer->SetFrameDataForRenderPasses(
110 1.f, &delegated_render_passes);
112 // The RenderPasses should be taken by the layer.
113 EXPECT_EQ(0u, delegated_render_passes.size());
115 root_layer_ = root_layer.get();
116 layer_before_ = layer_before.get();
117 layer_after_ = layer_after.get();
118 delegated_renderer_layer_ = delegated_renderer_layer.get();
120 // Force the delegated RenderPasses to come before the RenderPass from
121 // layer_after.
122 layer_after->AddChild(delegated_renderer_layer.Pass());
123 root_layer->AddChild(layer_after.Pass());
125 // Get the RenderPass generated by layer_before to come before the delegated
126 // RenderPasses.
127 root_layer->AddChild(layer_before.Pass());
128 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
131 protected:
132 LayerImpl* root_layer_;
133 LayerImpl* layer_before_;
134 LayerImpl* layer_after_;
135 DelegatedRendererLayerImpl* delegated_renderer_layer_;
138 TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
139 LayerTreeHostImpl::FrameData frame;
140 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
142 // Each non-DelegatedRendererLayer added one RenderPass. The
143 // DelegatedRendererLayer added two contributing passes.
144 ASSERT_EQ(5u, frame.render_passes.size());
146 // The DelegatedRendererLayer should have added its contributing RenderPasses
147 // to the frame.
148 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
149 EXPECT_EQ(1, frame.render_passes[1]->id.index);
150 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
151 EXPECT_EQ(2, frame.render_passes[2]->id.index);
152 // And all other RenderPasses should be non-delegated.
153 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
154 EXPECT_EQ(0, frame.render_passes[0]->id.index);
155 EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
156 EXPECT_EQ(0, frame.render_passes[3]->id.index);
157 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
158 EXPECT_EQ(0, frame.render_passes[4]->id.index);
160 // The DelegatedRendererLayer should have added its RenderPasses to the frame
161 // in order.
162 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
163 frame.render_passes[1]->output_rect.ToString());
164 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
165 frame.render_passes[2]->output_rect.ToString());
167 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
168 host_impl_->DidDrawAllLayers(frame);
171 TEST_F(DelegatedRendererLayerImplTestSimple,
172 AddsQuadsToContributingRenderPasses) {
173 LayerTreeHostImpl::FrameData frame;
174 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
176 // Each non-DelegatedRendererLayer added one RenderPass. The
177 // DelegatedRendererLayer added two contributing passes.
178 ASSERT_EQ(5u, frame.render_passes.size());
180 // The DelegatedRendererLayer should have added its contributing RenderPasses
181 // to the frame.
182 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
183 EXPECT_EQ(1, frame.render_passes[1]->id.index);
184 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
185 EXPECT_EQ(2, frame.render_passes[2]->id.index);
187 // The DelegatedRendererLayer should have added copies of its quads to
188 // contributing RenderPasses.
189 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
190 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
191 frame.render_passes[1]->quad_list.front()->rect.ToString());
193 // Verify it added the right quads.
194 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
195 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
196 frame.render_passes[2]->quad_list.front()->rect.ToString());
197 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
198 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
199 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
200 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
201 frame.render_passes[1]->quad_list.front()->rect.ToString());
203 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
204 host_impl_->DidDrawAllLayers(frame);
207 TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
208 LayerTreeHostImpl::FrameData frame;
209 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
211 // Each non-DelegatedRendererLayer added one RenderPass. The
212 // DelegatedRendererLayer added two contributing passes.
213 ASSERT_EQ(5u, frame.render_passes.size());
215 // The layer's target is the RenderPass from layer_after_.
216 EXPECT_EQ(RenderPassId(3, 0), frame.render_passes[3]->id);
218 // The DelegatedRendererLayer should have added copies of quads in its root
219 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
220 ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
222 // Verify it added the right quads.
223 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
224 frame.render_passes[3]->quad_list.front()->rect.ToString());
226 // Its target layer should have a quad as well.
227 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
228 frame.render_passes[3]->quad_list.ElementAt(1)->rect.ToString());
230 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
231 host_impl_->DidDrawAllLayers(frame);
234 TEST_F(DelegatedRendererLayerImplTestSimple,
235 QuadsFromRootRenderPassAreModifiedForTheTarget) {
236 LayerTreeHostImpl::FrameData frame;
237 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
239 // Each non-DelegatedRendererLayer added one RenderPass. The
240 // DelegatedRendererLayer added two contributing passes.
241 ASSERT_EQ(5u, frame.render_passes.size());
243 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
244 // has a translation transform of 1,1. So its root RenderPass' quads should
245 // all be transformed by that combined amount.
246 gfx::Transform transform;
247 transform.Translate(4.0, 4.0);
248 EXPECT_TRANSFORMATION_MATRIX_EQ(
249 transform, frame.render_passes[3]->quad_list.front()->quadTransform());
251 // Quads from non-root RenderPasses should not be shifted though.
252 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
254 EXPECT_TRANSFORMATION_MATRIX_EQ(
255 gfx::Transform(),
256 frame.render_passes[2]->quad_list.front()->quadTransform());
257 EXPECT_TRANSFORMATION_MATRIX_EQ(
258 gfx::Transform(),
259 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
260 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
261 EXPECT_TRANSFORMATION_MATRIX_EQ(
262 gfx::Transform(),
263 frame.render_passes[1]->quad_list.front()->quadTransform());
265 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
266 host_impl_->DidDrawAllLayers(frame);
269 TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
270 LayerTreeHostImpl::FrameData frame;
271 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
273 // The delegated layer has a surface between it and the root.
274 EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
276 // Each non-DelegatedRendererLayer added one RenderPass. The
277 // DelegatedRendererLayer added two contributing passes.
278 ASSERT_EQ(5u, frame.render_passes.size());
280 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
281 // render pass' transforms to the root should be shifted by this amount.
282 gfx::Transform transform;
283 transform.Translate(9.0, 9.0);
285 // The first contributing surface has a translation of 5, 6.
286 gfx::Transform five_six(1, 0, 0, 1, 5, 6);
288 // The second contributing surface has a translation of 7, 8.
289 gfx::Transform seven_eight(1, 0, 0, 1, 7, 8);
291 EXPECT_TRANSFORMATION_MATRIX_EQ(
292 transform * five_six, frame.render_passes[1]->transform_to_root_target);
293 EXPECT_TRANSFORMATION_MATRIX_EQ(
294 transform * seven_eight,
295 frame.render_passes[2]->transform_to_root_target);
297 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
298 host_impl_->DidDrawAllLayers(frame);
301 TEST_F(DelegatedRendererLayerImplTestSimple, DoesNotOwnARenderSurface) {
302 LayerTreeHostImpl::FrameData frame;
303 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
305 // If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
306 // has no need to be a RenderSurface for the quads it carries.
307 EXPECT_FALSE(delegated_renderer_layer_->render_surface());
309 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
310 host_impl_->DidDrawAllLayers(frame);
313 TEST_F(DelegatedRendererLayerImplTestSimple, DoesOwnARenderSurfaceForOpacity) {
314 delegated_renderer_layer_->SetOpacity(0.5f);
316 LayerTreeHostImpl::FrameData frame;
317 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
318 host_impl_->active_tree()->root_layer());
319 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
321 // This test case has quads from multiple layers in the delegated renderer, so
322 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
323 // render surface.
324 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
326 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
327 host_impl_->DidDrawAllLayers(frame);
330 TEST_F(DelegatedRendererLayerImplTestSimple,
331 DoesOwnARenderSurfaceForTransform) {
332 gfx::Transform rotation;
333 rotation.RotateAboutZAxis(30.0);
334 delegated_renderer_layer_->SetTransform(rotation);
336 LayerTreeHostImpl::FrameData frame;
337 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(
338 host_impl_->active_tree()->root_layer());
339 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
341 // This test case has quads from multiple layers in the delegated renderer, so
342 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
343 // render surface.
344 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
346 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
347 host_impl_->DidDrawAllLayers(frame);
350 class DelegatedRendererLayerImplTestOwnSurface
351 : public DelegatedRendererLayerImplTestSimple {
352 public:
353 DelegatedRendererLayerImplTestOwnSurface()
354 : DelegatedRendererLayerImplTestSimple() {
355 delegated_renderer_layer_->SetForceRenderSurface(true);
359 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
360 LayerTreeHostImpl::FrameData frame;
361 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
363 // Each non-DelegatedRendererLayer added one RenderPass. The
364 // DelegatedRendererLayer added two contributing passes and its owned surface
365 // added one pass.
366 ASSERT_EQ(6u, frame.render_passes.size());
368 // The DelegatedRendererLayer should have added its contributing RenderPasses
369 // to the frame.
370 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
371 EXPECT_EQ(1, frame.render_passes[1]->id.index);
372 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
373 EXPECT_EQ(2, frame.render_passes[2]->id.index);
374 // The DelegatedRendererLayer should have added a RenderPass for its surface
375 // to the frame.
376 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
377 EXPECT_EQ(0, frame.render_passes[3]->id.index);
378 // And all other RenderPasses should be non-delegated.
379 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
380 EXPECT_EQ(0, frame.render_passes[0]->id.index);
381 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
382 EXPECT_EQ(0, frame.render_passes[4]->id.index);
383 EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
384 EXPECT_EQ(0, frame.render_passes[5]->id.index);
386 // The DelegatedRendererLayer should have added its RenderPasses to the frame
387 // in order.
388 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
389 frame.render_passes[1]->output_rect.ToString());
390 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
391 frame.render_passes[2]->output_rect.ToString());
393 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
394 host_impl_->DidDrawAllLayers(frame);
397 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
398 AddsQuadsToContributingRenderPasses) {
399 LayerTreeHostImpl::FrameData frame;
400 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
402 // Each non-DelegatedRendererLayer added one RenderPass. The
403 // DelegatedRendererLayer added two contributing passes and its owned surface
404 // added one pass.
405 ASSERT_EQ(6u, frame.render_passes.size());
407 // The DelegatedRendererLayer should have added its contributing RenderPasses
408 // to the frame.
409 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
410 EXPECT_EQ(1, frame.render_passes[1]->id.index);
411 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
412 EXPECT_EQ(2, frame.render_passes[2]->id.index);
414 // The DelegatedRendererLayer should have added copies of its quads to
415 // contributing RenderPasses.
416 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
417 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
418 frame.render_passes[1]->quad_list.front()->rect.ToString());
420 // Verify it added the right quads.
421 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
423 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
424 frame.render_passes[2]->quad_list.front()->rect.ToString());
425 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
426 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
427 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
428 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
429 frame.render_passes[1]->quad_list.front()->rect.ToString());
431 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
432 host_impl_->DidDrawAllLayers(frame);
435 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
436 LayerTreeHostImpl::FrameData frame;
437 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
439 // Each non-DelegatedRendererLayer added one RenderPass. The
440 // DelegatedRendererLayer added two contributing passes and its owned surface
441 // added one pass.
442 ASSERT_EQ(6u, frame.render_passes.size());
444 // The layer's target is the RenderPass owned by itself.
445 EXPECT_EQ(RenderPassId(4, 0), frame.render_passes[3]->id);
447 // The DelegatedRendererLayer should have added copies of quads in its root
448 // RenderPass to its target RenderPass.
449 // The layer_after also adds one quad.
450 ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
452 // Verify it added the right quads.
453 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
454 frame.render_passes[3]->quad_list.front()->rect.ToString());
456 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
457 host_impl_->DidDrawAllLayers(frame);
460 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
461 QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
462 LayerTreeHostImpl::FrameData frame;
463 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
465 // Each non-DelegatedRendererLayer added one RenderPass. The
466 // DelegatedRendererLayer added two contributing passes and its owned surface
467 // added one pass.
468 ASSERT_EQ(6u, frame.render_passes.size());
470 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
471 // RenderPass' quads do not need to be translated at all.
472 EXPECT_TRANSFORMATION_MATRIX_EQ(
473 gfx::Transform(),
474 frame.render_passes[3]->quad_list.front()->quadTransform());
476 // Quads from non-root RenderPasses should not be shifted either.
477 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
479 EXPECT_TRANSFORMATION_MATRIX_EQ(
480 gfx::Transform(),
481 frame.render_passes[2]->quad_list.front()->quadTransform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(
483 gfx::Transform(),
484 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
485 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
486 EXPECT_TRANSFORMATION_MATRIX_EQ(
487 gfx::Transform(),
488 frame.render_passes[1]->quad_list.front()->quadTransform());
490 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
491 host_impl_->DidDrawAllLayers(frame);
494 class DelegatedRendererLayerImplTestTransform
495 : public DelegatedRendererLayerImplTest {
496 public:
497 DelegatedRendererLayerImplTestTransform()
498 : root_delegated_render_pass_is_clipped_(false),
499 delegated_device_scale_factor_(2.f) {}
501 void SetUpTest() {
502 host_impl_->SetDeviceScaleFactor(2.f);
504 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
505 host_impl_->active_tree(), 1);
506 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
507 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
509 host_impl_->SetViewportSize(gfx::Size(200, 200));
510 root_layer->SetBounds(gfx::Size(100, 100));
512 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
513 delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
514 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
515 delegated_renderer_layer->SetDrawsContent(true);
516 gfx::Transform transform;
517 transform.Scale(2.0, 2.0);
518 transform.Translate(8.0, 8.0);
519 delegated_renderer_layer->SetTransform(transform);
521 RenderPassList delegated_render_passes;
523 gfx::Size child_pass_content_bounds(7, 7);
524 gfx::Rect child_pass_rect(20, 20, 7, 7);
525 gfx::Transform child_pass_transform;
526 child_pass_transform.Scale(0.8f, 0.8f);
527 child_pass_transform.Translate(9.0, 9.0);
528 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
529 bool child_pass_clipped = false;
532 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
533 RenderPassId(10, 7),
534 child_pass_rect,
535 gfx::Transform());
536 SharedQuadState* shared_quad_state =
537 pass->CreateAndAppendSharedQuadState();
538 shared_quad_state->SetAll(child_pass_transform,
539 child_pass_content_bounds,
540 child_pass_rect,
541 child_pass_clip_rect,
542 child_pass_clipped,
543 1.f,
544 SkXfermode::kSrcOver_Mode,
547 SolidColorDrawQuad* color_quad;
548 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
549 color_quad->SetNew(shared_quad_state,
550 gfx::Rect(20, 20, 3, 7),
551 gfx::Rect(20, 20, 3, 7),
553 false);
555 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
556 color_quad->SetNew(shared_quad_state,
557 gfx::Rect(23, 20, 4, 7),
558 gfx::Rect(23, 20, 4, 7),
560 false);
563 gfx::Size root_pass_content_bounds(100, 100);
564 gfx::Rect root_pass_rect(0, 0, 100, 100);
565 gfx::Transform root_pass_transform;
566 root_pass_transform.Scale(1.5, 1.5);
567 root_pass_transform.Translate(7.0, 7.0);
568 gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
569 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
571 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
572 RenderPassId(9, 6),
573 root_pass_rect,
574 gfx::Transform());
575 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
576 shared_quad_state->SetAll(root_pass_transform,
577 root_pass_content_bounds,
578 root_pass_rect,
579 root_pass_clip_rect,
580 root_pass_clipped,
581 1.f,
582 SkXfermode::kSrcOver_Mode,
585 RenderPassDrawQuad* render_pass_quad =
586 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
587 render_pass_quad->SetNew(shared_quad_state,
588 gfx::Rect(5, 5, 7, 7), // quad_rect
589 gfx::Rect(5, 5, 7, 7), // visible_rect
590 RenderPassId(10, 7), // render_pass_id
591 0, // mask_resource_id
592 gfx::Vector2dF(), // mask_uv_scale
593 gfx::Size(), // mask_texture_size
594 FilterOperations(), // filters
595 gfx::Vector2dF(), // filters_scale
596 FilterOperations()); // background_filters
598 SolidColorDrawQuad* color_quad;
599 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
600 color_quad->SetNew(shared_quad_state,
601 gfx::Rect(0, 0, 10, 10),
602 gfx::Rect(0, 0, 10, 10),
604 false);
606 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
607 color_quad->SetNew(shared_quad_state,
608 gfx::Rect(0, 10, 10, 10),
609 gfx::Rect(0, 10, 10, 10),
611 false);
613 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
614 color_quad->SetNew(shared_quad_state,
615 gfx::Rect(10, 0, 10, 10),
616 gfx::Rect(10, 0, 10, 10),
618 false);
620 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
621 color_quad->SetNew(shared_quad_state,
622 gfx::Rect(10, 10, 10, 10),
623 gfx::Rect(10, 10, 10, 10),
625 false);
627 delegated_renderer_layer->SetFrameDataForRenderPasses(
628 delegated_device_scale_factor_, &delegated_render_passes);
630 // The RenderPasses should be taken by the layer.
631 EXPECT_EQ(0u, delegated_render_passes.size());
633 root_layer_ = root_layer.get();
634 delegated_renderer_layer_ = delegated_renderer_layer.get();
636 root_layer->AddChild(delegated_renderer_layer.Pass());
637 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
640 void VerifyRenderPasses(
641 const LayerTreeHostImpl::FrameData& frame,
642 size_t num_render_passes,
643 const SharedQuadState** root_delegated_shared_quad_state,
644 const SharedQuadState** contrib_delegated_shared_quad_state) {
645 ASSERT_EQ(num_render_passes, frame.render_passes.size());
646 // The contributing render pass in the DelegatedRendererLayer.
647 EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
648 EXPECT_EQ(1, frame.render_passes[0]->id.index);
649 // The root render pass.
650 EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
651 EXPECT_EQ(0, frame.render_passes.back()->id.index);
653 const QuadList& contrib_delegated_quad_list =
654 frame.render_passes[0]->quad_list;
655 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
657 const QuadList& root_delegated_quad_list =
658 frame.render_passes[1]->quad_list;
659 ASSERT_EQ(5u, root_delegated_quad_list.size());
661 // All quads in a render pass should share the same state.
662 *contrib_delegated_shared_quad_state =
663 contrib_delegated_quad_list.front()->shared_quad_state;
664 EXPECT_EQ(*contrib_delegated_shared_quad_state,
665 contrib_delegated_quad_list.ElementAt(1)->shared_quad_state);
667 *root_delegated_shared_quad_state =
668 root_delegated_quad_list.front()->shared_quad_state;
669 EXPECT_EQ(*root_delegated_shared_quad_state,
670 root_delegated_quad_list.ElementAt(1)->shared_quad_state);
671 EXPECT_EQ(*root_delegated_shared_quad_state,
672 root_delegated_quad_list.ElementAt(2)->shared_quad_state);
673 EXPECT_EQ(*root_delegated_shared_quad_state,
674 root_delegated_quad_list.ElementAt(3)->shared_quad_state);
675 EXPECT_EQ(*root_delegated_shared_quad_state,
676 root_delegated_quad_list.ElementAt(4)->shared_quad_state);
678 EXPECT_NE(*contrib_delegated_shared_quad_state,
679 *root_delegated_shared_quad_state);
682 protected:
683 LayerImpl* root_layer_;
684 DelegatedRendererLayerImpl* delegated_renderer_layer_;
685 bool root_delegated_render_pass_is_clipped_;
686 float delegated_device_scale_factor_;
689 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
690 root_delegated_render_pass_is_clipped_ = false;
691 SetUpTest();
693 LayerTreeHostImpl::FrameData frame;
694 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
696 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
697 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
698 VerifyRenderPasses(
699 frame,
701 &root_delegated_shared_quad_state,
702 &contrib_delegated_shared_quad_state);
704 // When the quads don't have a clip of their own, the clip rect is set to
705 // the drawable_content_rect of the delegated renderer layer.
706 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
707 root_delegated_shared_quad_state->clip_rect.ToString());
709 // Even though the quads in the root pass have no clip of their own, they
710 // inherit the clip rect from the delegated renderer layer if it does not
711 // own a surface.
712 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
714 gfx::Transform expected;
715 // Device scale factor.
716 expected.Scale(2.0, 2.0);
717 // This is the transform from the layer's space to its target.
718 expected.Translate(20, 20);
719 expected.Scale(2.0, 2.0);
720 expected.Translate(8.0, 8.0);
721 // This is the transform within the source frame.
722 // Inverse device scale factor to go from physical space to layer space.
723 expected.Scale(0.5, 0.5);
724 expected.Scale(1.5, 1.5);
725 expected.Translate(7.0, 7.0);
726 EXPECT_TRANSFORMATION_MATRIX_EQ(
727 expected, root_delegated_shared_quad_state->content_to_target_transform);
729 // The contributing render pass should not be transformed from its input.
730 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
731 contrib_delegated_shared_quad_state->clip_rect.ToString());
732 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
733 expected.MakeIdentity();
734 expected.Scale(0.8f, 0.8f);
735 expected.Translate(9.0, 9.0);
736 EXPECT_TRANSFORMATION_MATRIX_EQ(
737 expected,
738 contrib_delegated_shared_quad_state->content_to_target_transform);
740 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
741 host_impl_->DidDrawAllLayers(frame);
744 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
745 root_delegated_render_pass_is_clipped_ = true;
746 SetUpTest();
748 LayerTreeHostImpl::FrameData frame;
749 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
751 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
752 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
753 VerifyRenderPasses(
754 frame,
756 &root_delegated_shared_quad_state,
757 &contrib_delegated_shared_quad_state);
759 // Since the quads have a clip_rect it should be modified by delegated
760 // renderer layer's draw_transform.
761 // The position of the resulting clip_rect is:
762 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
763 // layer scale (2) + layer position (20) = 46
764 // The device scale is 2, so everything gets doubled, giving 92.
766 // The size is 35x35 scaled by the device scale.
767 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
768 root_delegated_shared_quad_state->clip_rect.ToString());
770 // The quads had a clip and it should be preserved.
771 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
773 gfx::Transform expected;
774 // Device scale factor.
775 expected.Scale(2.0, 2.0);
776 // This is the transform from the layer's space to its target.
777 expected.Translate(20, 20);
778 expected.Scale(2.0, 2.0);
779 expected.Translate(8.0, 8.0);
780 // This is the transform within the source frame.
781 // Inverse device scale factor to go from physical space to layer space.
782 expected.Scale(0.5, 0.5);
783 expected.Scale(1.5, 1.5);
784 expected.Translate(7.0, 7.0);
785 EXPECT_TRANSFORMATION_MATRIX_EQ(
786 expected, root_delegated_shared_quad_state->content_to_target_transform);
788 // The contributing render pass should not be transformed from its input.
789 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
790 contrib_delegated_shared_quad_state->clip_rect.ToString());
791 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
792 expected.MakeIdentity();
793 expected.Scale(0.8f, 0.8f);
794 expected.Translate(9.0, 9.0);
795 EXPECT_TRANSFORMATION_MATRIX_EQ(
796 expected,
797 contrib_delegated_shared_quad_state->content_to_target_transform);
799 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
800 host_impl_->DidDrawAllLayers(frame);
803 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
804 root_delegated_render_pass_is_clipped_ = false;
805 SetUpTest();
807 delegated_renderer_layer_->SetForceRenderSurface(true);
809 LayerTreeHostImpl::FrameData frame;
810 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
812 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
813 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
814 VerifyRenderPasses(
815 frame,
817 &root_delegated_shared_quad_state,
818 &contrib_delegated_shared_quad_state);
820 // When the layer owns a surface, then its position and translation are not
821 // a part of its draw transform.
822 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
823 root_delegated_shared_quad_state->clip_rect.ToString());
825 // Since the layer owns a surface it doesn't need to clip its quads, so
826 // unclipped quads remain unclipped.
827 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
829 gfx::Transform expected;
830 // This is the transform within the source frame.
831 expected.Scale(1.5, 1.5);
832 expected.Translate(7.0, 7.0);
833 EXPECT_TRANSFORMATION_MATRIX_EQ(
834 expected, root_delegated_shared_quad_state->content_to_target_transform);
836 // The contributing render pass should not be transformed from its input.
837 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
838 contrib_delegated_shared_quad_state->clip_rect.ToString());
839 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
840 expected.MakeIdentity();
841 expected.Scale(0.8f, 0.8f);
842 expected.Translate(9.0, 9.0);
843 EXPECT_TRANSFORMATION_MATRIX_EQ(
844 expected,
845 contrib_delegated_shared_quad_state->content_to_target_transform);
847 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
848 host_impl_->DidDrawAllLayers(frame);
851 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
852 root_delegated_render_pass_is_clipped_ = true;
853 SetUpTest();
855 delegated_renderer_layer_->SetForceRenderSurface(true);
857 LayerTreeHostImpl::FrameData frame;
858 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
860 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
861 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
862 VerifyRenderPasses(
863 frame,
865 &root_delegated_shared_quad_state,
866 &contrib_delegated_shared_quad_state);
868 // When the layer owns a surface, then its position and translation are not
869 // a part of its draw transform. The clip_rect should be preserved.
870 EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
871 root_delegated_shared_quad_state->clip_rect.ToString());
873 // The quads had a clip and it should be preserved.
874 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
876 gfx::Transform expected;
877 // This is the transform within the source frame.
878 expected.Scale(1.5, 1.5);
879 expected.Translate(7.0, 7.0);
880 EXPECT_TRANSFORMATION_MATRIX_EQ(
881 expected, root_delegated_shared_quad_state->content_to_target_transform);
883 // The contributing render pass should not be transformed from its input.
884 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
885 contrib_delegated_shared_quad_state->clip_rect.ToString());
886 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
887 expected.MakeIdentity();
888 expected.Scale(0.8f, 0.8f);
889 expected.Translate(9.0, 9.0);
890 EXPECT_TRANSFORMATION_MATRIX_EQ(
891 expected,
892 contrib_delegated_shared_quad_state->content_to_target_transform);
894 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
895 host_impl_->DidDrawAllLayers(frame);
898 TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
899 root_delegated_render_pass_is_clipped_ = true;
900 delegated_device_scale_factor_ = 1.3f;
902 SetUpTest();
904 LayerTreeHostImpl::FrameData frame;
905 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
907 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
908 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
909 VerifyRenderPasses(frame,
911 &root_delegated_shared_quad_state,
912 &contrib_delegated_shared_quad_state);
914 // The parent tree's device scale factor is 2.0, but the child has submitted a
915 // frame with a device scale factor of 1.3. Absent any better option, the
916 // only thing we can do is scale from 1.3 -> 2.0.
918 gfx::Transform expected;
919 // Device scale factor (from parent).
920 expected.Scale(2.0, 2.0);
921 // This is the transform from the layer's space to its target.
922 expected.Translate(20, 20);
923 expected.Scale(2.0, 2.0);
924 expected.Translate(8.0, 8.0);
925 // This is the transform within the source frame.
926 // Inverse device scale factor (from child).
927 expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
928 expected.Scale(1.5, 1.5);
929 expected.Translate(7.0, 7.0);
930 EXPECT_TRANSFORMATION_MATRIX_EQ(
931 expected, root_delegated_shared_quad_state->content_to_target_transform);
933 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
934 host_impl_->DidDrawAllLayers(frame);
937 class DelegatedRendererLayerImplTestClip
938 : public DelegatedRendererLayerImplTest {
939 public:
940 void SetUpTest() {
941 scoped_ptr<LayerImpl> root_layer =
942 LayerImpl::Create(host_impl_->active_tree(), 1);
943 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
944 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
945 scoped_ptr<LayerImpl> clip_layer =
946 LayerImpl::Create(host_impl_->active_tree(), 3);
947 scoped_ptr<LayerImpl> origin_layer =
948 LayerImpl::Create(host_impl_->active_tree(), 4);
950 host_impl_->SetViewportSize(gfx::Size(100, 100));
951 root_layer->SetBounds(gfx::Size(100, 100));
953 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
954 delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
955 delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
956 delegated_renderer_layer->SetDrawsContent(true);
958 RenderPassList delegated_render_passes;
960 gfx::Size child_pass_content_bounds(7, 7);
961 gfx::Rect child_pass_rect(20, 20, 7, 7);
962 gfx::Transform child_pass_transform;
963 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
964 bool child_pass_clipped = false;
967 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
968 RenderPassId(10, 7),
969 child_pass_rect,
970 gfx::Transform());
971 SharedQuadState* shared_quad_state =
972 pass->CreateAndAppendSharedQuadState();
973 shared_quad_state->SetAll(child_pass_transform,
974 child_pass_content_bounds,
975 child_pass_rect,
976 child_pass_clip_rect,
977 child_pass_clipped,
978 1.f,
979 SkXfermode::kSrcOver_Mode,
982 SolidColorDrawQuad* color_quad;
983 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
984 color_quad->SetNew(shared_quad_state,
985 gfx::Rect(20, 20, 3, 7),
986 gfx::Rect(20, 20, 3, 7),
988 false);
990 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
991 color_quad->SetNew(shared_quad_state,
992 gfx::Rect(23, 20, 4, 7),
993 gfx::Rect(23, 20, 4, 7),
995 false);
998 gfx::Size root_pass_content_bounds(50, 50);
999 gfx::Rect root_pass_rect(0, 0, 50, 50);
1000 gfx::Transform root_pass_transform;
1001 gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
1002 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
1004 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
1005 RenderPassId(9, 6),
1006 root_pass_rect,
1007 gfx::Transform());
1008 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
1009 shared_quad_state->SetAll(root_pass_transform,
1010 root_pass_content_bounds,
1011 root_pass_rect,
1012 root_pass_clip_rect,
1013 root_pass_clipped,
1014 1.f,
1015 SkXfermode::kSrcOver_Mode,
1018 RenderPassDrawQuad* render_pass_quad =
1019 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
1020 render_pass_quad->SetNew(shared_quad_state,
1021 gfx::Rect(5, 5, 7, 7), // quad_rect
1022 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1023 RenderPassId(10, 7), // render_pass_id
1024 0, // mask_resource_id
1025 gfx::Vector2dF(), // mask_uv_scale
1026 gfx::Size(), // mask_texture_size,
1027 FilterOperations(), // filters
1028 gfx::Vector2dF(), // filters_scale
1029 FilterOperations()); // background_filters
1031 SolidColorDrawQuad* color_quad;
1032 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1033 color_quad->SetNew(shared_quad_state,
1034 gfx::Rect(0, 0, 10, 10),
1035 gfx::Rect(0, 0, 10, 10),
1037 false);
1039 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1040 color_quad->SetNew(shared_quad_state,
1041 gfx::Rect(0, 10, 10, 10),
1042 gfx::Rect(0, 10, 10, 10),
1044 false);
1046 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1047 color_quad->SetNew(shared_quad_state,
1048 gfx::Rect(10, 0, 10, 10),
1049 gfx::Rect(10, 0, 10, 10),
1051 false);
1053 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1054 color_quad->SetNew(shared_quad_state,
1055 gfx::Rect(10, 10, 10, 10),
1056 gfx::Rect(10, 10, 10, 10),
1058 false);
1060 delegated_renderer_layer->SetFrameDataForRenderPasses(
1061 1.f, &delegated_render_passes);
1063 // The RenderPasses should be taken by the layer.
1064 EXPECT_EQ(0u, delegated_render_passes.size());
1066 root_layer_ = root_layer.get();
1067 delegated_renderer_layer_ = delegated_renderer_layer.get();
1069 if (clip_delegated_renderer_layer_) {
1070 gfx::Rect clip_rect(21, 27, 23, 21);
1072 clip_layer->SetPosition(clip_rect.origin());
1073 clip_layer->SetBounds(clip_rect.size());
1074 clip_layer->SetContentBounds(clip_rect.size());
1075 clip_layer->SetMasksToBounds(true);
1077 origin_layer->SetPosition(
1078 gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin()));
1080 origin_layer->AddChild(delegated_renderer_layer.Pass());
1081 clip_layer->AddChild(origin_layer.Pass());
1082 root_layer->AddChild(clip_layer.Pass());
1083 } else {
1084 root_layer->AddChild(delegated_renderer_layer.Pass());
1087 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1090 protected:
1091 LayerImpl* root_layer_;
1092 DelegatedRendererLayerImpl* delegated_renderer_layer_;
1093 bool root_delegated_render_pass_is_clipped_;
1094 bool clip_delegated_renderer_layer_;
1097 TEST_F(DelegatedRendererLayerImplTestClip,
1098 QuadsUnclipped_LayerUnclipped_NoSurface) {
1099 root_delegated_render_pass_is_clipped_ = false;
1100 clip_delegated_renderer_layer_ = false;
1101 SetUpTest();
1103 LayerTreeHostImpl::FrameData frame;
1104 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1106 ASSERT_EQ(2u, frame.render_passes.size());
1107 const QuadList& contrib_delegated_quad_list =
1108 frame.render_passes[0]->quad_list;
1109 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1110 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1111 ASSERT_EQ(5u, root_delegated_quad_list.size());
1112 const SharedQuadState* root_delegated_shared_quad_state =
1113 root_delegated_quad_list.front()->shared_quad_state;
1115 // When the quads don't have a clip of their own, the clip rect is set to
1116 // the drawable_content_rect of the delegated renderer layer.
1117 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1118 root_delegated_shared_quad_state->clip_rect.ToString());
1119 // Quads are clipped to the delegated renderer layer.
1120 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1122 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1123 host_impl_->DidDrawAllLayers(frame);
1126 TEST_F(DelegatedRendererLayerImplTestClip,
1127 QuadsClipped_LayerUnclipped_NoSurface) {
1128 root_delegated_render_pass_is_clipped_ = true;
1129 clip_delegated_renderer_layer_ = false;
1130 SetUpTest();
1132 LayerTreeHostImpl::FrameData frame;
1133 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1135 ASSERT_EQ(2u, frame.render_passes.size());
1136 const QuadList& contrib_delegated_quad_list =
1137 frame.render_passes[0]->quad_list;
1138 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1139 const QuadList& root_delegated_quad_list =
1140 frame.render_passes[1]->quad_list;
1141 ASSERT_EQ(5u, root_delegated_quad_list.size());
1142 const SharedQuadState* root_delegated_shared_quad_state =
1143 root_delegated_quad_list.front()->shared_quad_state;
1145 // When the quads have a clip of their own, it is used.
1146 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1147 root_delegated_shared_quad_state->clip_rect.ToString());
1148 // Quads came with a clip rect.
1149 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1151 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1152 host_impl_->DidDrawAllLayers(frame);
1155 TEST_F(DelegatedRendererLayerImplTestClip,
1156 QuadsUnclipped_LayerClipped_NoSurface) {
1157 root_delegated_render_pass_is_clipped_ = false;
1158 clip_delegated_renderer_layer_ = true;
1159 SetUpTest();
1161 LayerTreeHostImpl::FrameData frame;
1162 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1164 ASSERT_EQ(2u, frame.render_passes.size());
1165 const QuadList& contrib_delegated_quad_list =
1166 frame.render_passes[0]->quad_list;
1167 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1168 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1169 ASSERT_EQ(5u, root_delegated_quad_list.size());
1170 const SharedQuadState* root_delegated_shared_quad_state =
1171 root_delegated_quad_list.front()->shared_quad_state;
1173 // When the quads don't have a clip of their own, the clip rect is set to
1174 // the drawable_content_rect of the delegated renderer layer. When the layer
1175 // is clipped, that should be seen in the quads' clip_rect.
1176 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1177 root_delegated_shared_quad_state->clip_rect.ToString());
1178 // Quads are clipped to the delegated renderer layer.
1179 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1181 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1182 host_impl_->DidDrawAllLayers(frame);
1185 TEST_F(DelegatedRendererLayerImplTestClip,
1186 QuadsClipped_LayerClipped_NoSurface) {
1187 root_delegated_render_pass_is_clipped_ = true;
1188 clip_delegated_renderer_layer_ = true;
1189 SetUpTest();
1191 LayerTreeHostImpl::FrameData frame;
1192 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1194 ASSERT_EQ(2u, frame.render_passes.size());
1195 const QuadList& contrib_delegated_quad_list =
1196 frame.render_passes[0]->quad_list;
1197 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1198 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1199 ASSERT_EQ(5u, root_delegated_quad_list.size());
1200 const SharedQuadState* root_delegated_shared_quad_state =
1201 root_delegated_quad_list.front()->shared_quad_state;
1203 // When the quads have a clip of their own, it is used, but it is
1204 // combined with the clip rect of the delegated renderer layer.
1205 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1206 root_delegated_shared_quad_state->clip_rect.ToString());
1207 // Quads came with a clip rect.
1208 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1210 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1211 host_impl_->DidDrawAllLayers(frame);
1214 TEST_F(DelegatedRendererLayerImplTestClip,
1215 QuadsUnclipped_LayerUnclipped_Surface) {
1216 root_delegated_render_pass_is_clipped_ = false;
1217 clip_delegated_renderer_layer_ = false;
1218 SetUpTest();
1220 delegated_renderer_layer_->SetForceRenderSurface(true);
1222 LayerTreeHostImpl::FrameData frame;
1223 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1225 ASSERT_EQ(3u, frame.render_passes.size());
1226 const QuadList& contrib_delegated_quad_list =
1227 frame.render_passes[0]->quad_list;
1228 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1229 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1230 ASSERT_EQ(5u, root_delegated_quad_list.size());
1231 const SharedQuadState* root_delegated_shared_quad_state =
1232 root_delegated_quad_list.front()->shared_quad_state;
1234 // When the layer owns a surface, the quads don't need to be clipped
1235 // further than they already specify. If they aren't clipped, then their
1236 // clip rect is ignored, and they are not set as clipped.
1237 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1239 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1240 host_impl_->DidDrawAllLayers(frame);
1243 TEST_F(DelegatedRendererLayerImplTestClip,
1244 QuadsClipped_LayerUnclipped_Surface) {
1245 root_delegated_render_pass_is_clipped_ = true;
1246 clip_delegated_renderer_layer_ = false;
1247 SetUpTest();
1249 delegated_renderer_layer_->SetForceRenderSurface(true);
1251 LayerTreeHostImpl::FrameData frame;
1252 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1254 ASSERT_EQ(3u, frame.render_passes.size());
1255 const QuadList& contrib_delegated_quad_list =
1256 frame.render_passes[0]->quad_list;
1257 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1258 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1259 ASSERT_EQ(5u, root_delegated_quad_list.size());
1260 const SharedQuadState* root_delegated_shared_quad_state =
1261 root_delegated_quad_list.front()->shared_quad_state;
1263 // When the quads have a clip of their own, it is used.
1264 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1265 root_delegated_shared_quad_state->clip_rect.ToString());
1266 // Quads came with a clip rect.
1267 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1269 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1270 host_impl_->DidDrawAllLayers(frame);
1273 TEST_F(DelegatedRendererLayerImplTestClip,
1274 QuadsUnclipped_LayerClipped_Surface) {
1275 root_delegated_render_pass_is_clipped_ = false;
1276 clip_delegated_renderer_layer_ = true;
1277 SetUpTest();
1279 delegated_renderer_layer_->SetForceRenderSurface(true);
1281 LayerTreeHostImpl::FrameData frame;
1282 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1284 ASSERT_EQ(3u, frame.render_passes.size());
1285 const QuadList& contrib_delegated_quad_list =
1286 frame.render_passes[0]->quad_list;
1287 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1288 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1289 ASSERT_EQ(5u, root_delegated_quad_list.size());
1290 const SharedQuadState* root_delegated_shared_quad_state =
1291 root_delegated_quad_list.front()->shared_quad_state;
1293 // When the layer owns a surface, the quads don't need to be clipped
1294 // further than they already specify. If they aren't clipped, then their
1295 // clip rect is ignored, and they are not set as clipped.
1296 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1298 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1299 host_impl_->DidDrawAllLayers(frame);
1302 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) {
1303 root_delegated_render_pass_is_clipped_ = true;
1304 clip_delegated_renderer_layer_ = true;
1305 SetUpTest();
1307 delegated_renderer_layer_->SetForceRenderSurface(true);
1309 LayerTreeHostImpl::FrameData frame;
1310 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1312 ASSERT_EQ(3u, frame.render_passes.size());
1313 const QuadList& contrib_delegated_quad_list =
1314 frame.render_passes[0]->quad_list;
1315 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1316 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1317 ASSERT_EQ(5u, root_delegated_quad_list.size());
1318 const SharedQuadState* root_delegated_shared_quad_state =
1319 root_delegated_quad_list.front()->shared_quad_state;
1321 // When the quads have a clip of their own, it is used, but it is
1322 // combined with the clip rect of the delegated renderer layer. If the
1323 // layer owns a surface, then it does not have a clip rect of its own.
1324 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1325 root_delegated_shared_quad_state->clip_rect.ToString());
1326 // Quads came with a clip rect.
1327 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1329 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1330 host_impl_->DidDrawAllLayers(frame);
1333 TEST_F(DelegatedRendererLayerImplTest, InvalidRenderPassDrawQuad) {
1334 scoped_ptr<LayerImpl> root_layer =
1335 LayerImpl::Create(host_impl_->active_tree(), 1);
1336 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
1337 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
1339 host_impl_->SetViewportSize(gfx::Size(100, 100));
1341 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
1342 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
1343 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
1344 delegated_renderer_layer->SetDrawsContent(true);
1346 RenderPassList delegated_render_passes;
1347 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1348 RenderPassId(9, 6),
1349 gfx::Rect(0, 0, 10, 10),
1350 gfx::Transform());
1351 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
1353 // This render pass isn't part of the frame.
1354 scoped_ptr<TestRenderPass> missing_pass(TestRenderPass::Create());
1355 missing_pass->SetNew(RenderPassId(9, 7),
1356 gfx::Rect(7, 7, 7, 7),
1357 gfx::Rect(7, 7, 7, 7),
1358 gfx::Transform());
1360 // But a render pass quad refers to it.
1361 AddRenderPassQuad(pass1, missing_pass.get());
1363 delegated_renderer_layer->SetFrameDataForRenderPasses(
1364 1.f, &delegated_render_passes);
1366 // The RenderPasses should be taken by the layer.
1367 EXPECT_EQ(0u, delegated_render_passes.size());
1369 root_layer->AddChild(delegated_renderer_layer.Pass());
1370 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1372 LayerTreeHostImpl::FrameData frame;
1373 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1375 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1376 ASSERT_EQ(1u, frame.render_passes.size());
1377 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
1378 EXPECT_EQ(DrawQuad::SOLID_COLOR,
1379 frame.render_passes[0]->quad_list.front()->material);
1381 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1382 host_impl_->DidDrawAllLayers(frame);
1385 TEST_F(DelegatedRendererLayerImplTest, Occlusion) {
1386 gfx::Size layer_size(1000, 1000);
1387 gfx::Size viewport_size(1000, 1000);
1388 gfx::Rect quad_screen_rect(211, 300, 400, 500);
1390 gfx::Transform transform;
1391 transform.Translate(211.0, 300.0);
1393 LayerTestCommon::LayerImplTest impl;
1395 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
1396 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
1397 delegated_renderer_layer_impl->SetBounds(layer_size);
1398 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1399 delegated_renderer_layer_impl->SetDrawsContent(true);
1401 // Contributing render pass is offset by a transform and holds a quad that
1402 // covers it entirely.
1403 RenderPassList delegated_render_passes;
1404 // pass2 is just the size of the quad. It contributes to |pass1| with a
1405 // translation of (211,300).
1406 RenderPassId pass2_id =
1407 delegated_renderer_layer_impl->FirstContributingRenderPassId();
1408 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
1409 pass2_id,
1410 gfx::Rect(quad_screen_rect.size()),
1411 transform);
1412 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
1413 // |pass1| covers the whole layer.
1414 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
1415 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1416 pass1_id,
1417 gfx::Rect(layer_size),
1418 gfx::Transform());
1419 AddRenderPassQuad(pass1, pass2, 0, FilterOperations(), transform);
1420 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1421 1.f, &delegated_render_passes);
1423 impl.CalcDrawProps(viewport_size);
1426 SCOPED_TRACE("No occlusion");
1427 gfx::Rect occluded;
1430 SCOPED_TRACE("Root render pass");
1431 impl.AppendQuadsForPassWithOcclusion(
1432 delegated_renderer_layer_impl, pass1_id, occluded);
1433 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1434 quad_screen_rect);
1435 ASSERT_EQ(1u, impl.quad_list().size());
1436 EXPECT_EQ(DrawQuad::RENDER_PASS, impl.quad_list().front()->material);
1439 SCOPED_TRACE("Contributing render pass");
1440 impl.AppendQuadsForPassWithOcclusion(
1441 delegated_renderer_layer_impl, pass2_id, occluded);
1442 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1443 impl.quad_list(), gfx::Rect(quad_screen_rect.size()));
1444 ASSERT_EQ(1u, impl.quad_list().size());
1445 EXPECT_EQ(DrawQuad::SOLID_COLOR, impl.quad_list().front()->material);
1450 SCOPED_TRACE("Full occlusion");
1452 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1454 SCOPED_TRACE("Root render pass");
1455 impl.AppendQuadsForPassWithOcclusion(
1456 delegated_renderer_layer_impl, pass1_id, occluded);
1457 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1458 gfx::Rect());
1459 EXPECT_EQ(impl.quad_list().size(), 0u);
1462 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1464 SCOPED_TRACE("Contributing render pass");
1465 impl.AppendQuadsForPassWithOcclusion(
1466 delegated_renderer_layer_impl, pass2_id, occluded);
1467 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
1468 gfx::Rect());
1469 EXPECT_EQ(impl.quad_list().size(), 0u);
1474 SCOPED_TRACE("Partial occlusion");
1476 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1478 SCOPED_TRACE("Root render pass");
1479 impl.AppendQuadsForPassWithOcclusion(
1480 delegated_renderer_layer_impl, pass1_id, occlusion_in_root_target);
1481 size_t partially_occluded_count = 0;
1482 LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(),
1483 occlusion_in_root_target,
1484 &partially_occluded_count);
1485 // The layer outputs one quad, which is partially occluded.
1486 EXPECT_EQ(1u, impl.quad_list().size());
1487 EXPECT_EQ(1u, partially_occluded_count);
1490 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1491 // Move the occlusion to where it is in the contributing surface.
1492 gfx::Rect occlusion_in_target_of_delegated_quad =
1493 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1495 SCOPED_TRACE("Contributing render pass");
1496 impl.AppendQuadsForPassWithOcclusion(
1497 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
1498 size_t partially_occluded_count = 0;
1499 LayerTestCommon::VerifyQuadsAreOccluded(
1500 impl.quad_list(),
1501 occlusion_in_target_of_delegated_quad,
1502 &partially_occluded_count);
1503 // The layer outputs one quad, which is partially occluded.
1504 EXPECT_EQ(1u, impl.quad_list().size());
1505 EXPECT_EQ(1u, partially_occluded_count);
1506 // The quad in the contributing surface is at (211,300) in the root.
1507 // The occlusion extends to 500 in the x-axis, pushing the left of the
1508 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1509 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1510 impl.quad_list().front()->visible_rect.ToString());
1513 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1514 // Move the occlusion to where it is in the contributing surface.
1515 gfx::Rect occlusion_in_target_of_delegated_quad =
1516 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1518 SCOPED_TRACE("Contributing render pass with transformed root");
1520 gfx::Transform layer_transform;
1521 layer_transform.Translate(11.0, 0.0);
1522 delegated_renderer_layer_impl->SetTransform(layer_transform);
1524 occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0);
1526 impl.CalcDrawProps(viewport_size);
1528 impl.AppendQuadsForPassWithOcclusion(
1529 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target);
1530 size_t partially_occluded_count = 0;
1531 LayerTestCommon::VerifyQuadsAreOccluded(
1532 impl.quad_list(),
1533 occlusion_in_target_of_delegated_quad,
1534 &partially_occluded_count);
1535 // The layer outputs one quad, which is partially occluded.
1536 EXPECT_EQ(1u, impl.quad_list().size());
1537 EXPECT_EQ(1u, partially_occluded_count);
1538 // The quad in the contributing surface is at (222,300) in the transformed
1539 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1540 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1541 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1542 impl.quad_list().front()->visible_rect.ToString());
1547 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) {
1548 gfx::Size layer_size(1000, 1000);
1550 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl =
1551 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5);
1552 delegated_renderer_layer_impl->SetBounds(layer_size);
1553 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1554 delegated_renderer_layer_impl->SetDrawsContent(true);
1556 RenderPassList delegated_render_passes;
1557 // |pass1| covers the whole layer.
1558 RenderPassId pass1_id = RenderPassId(5, 0);
1559 AddRenderPass(&delegated_render_passes,
1560 pass1_id,
1561 gfx::Rect(layer_size),
1562 gfx::Transform());
1563 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1564 2.f, &delegated_render_passes);
1565 EXPECT_EQ(0.5f, delegated_renderer_layer_impl->inverse_device_scale_factor());
1567 scoped_ptr<DelegatedRendererLayerImpl> other_layer =
1568 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6);
1570 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get());
1572 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor());
1575 } // namespace
1576 } // namespace cc