Disable flaky SelectFileDialogExtensionBrowserTest tests
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer_impl_unittest.cc
blob947c657f0fb4207f35cb51e9b1b86375f99fcc7e
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_impl_proxy.h"
13 #include "cc/test/fake_layer_tree_host_impl.h"
14 #include "cc/test/fake_layer_tree_host_impl_client.h"
15 #include "cc/test/fake_output_surface.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/test/layer_test_common.h"
18 #include "cc/test/render_pass_test_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_task_graph_runner.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(new FakeLayerTreeHostImpl(
42 settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_));
43 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
44 host_impl_->SetViewportSize(gfx::Size(10, 10));
47 protected:
48 FakeImplProxy proxy_;
49 DebugScopedSetImplThreadAndMainThreadBlocked
50 always_impl_thread_and_main_thread_blocked_;
51 TestSharedBitmapManager shared_bitmap_manager_;
52 TestTaskGraphRunner task_graph_runner_;
53 scoped_ptr<LayerTreeHostImpl> host_impl_;
56 class DelegatedRendererLayerImplTestSimple
57 : public DelegatedRendererLayerImplTest {
58 public:
59 DelegatedRendererLayerImplTestSimple()
60 : DelegatedRendererLayerImplTest() {
61 scoped_ptr<LayerImpl> root_layer =
62 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
63 scoped_ptr<LayerImpl> layer_before =
64 SolidColorLayerImpl::Create(host_impl_->active_tree(), 2);
65 scoped_ptr<LayerImpl> layer_after =
66 SolidColorLayerImpl::Create(host_impl_->active_tree(), 3);
67 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
68 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
70 host_impl_->SetViewportSize(gfx::Size(100, 100));
71 root_layer->SetBounds(gfx::Size(100, 100));
72 root_layer->SetHasRenderSurface(true);
74 layer_before->SetPosition(gfx::Point(20, 20));
75 layer_before->SetBounds(gfx::Size(14, 14));
76 layer_before->SetContentBounds(gfx::Size(14, 14));
77 layer_before->SetDrawsContent(true);
78 layer_before->SetHasRenderSurface(true);
80 layer_after->SetPosition(gfx::Point(5, 5));
81 layer_after->SetBounds(gfx::Size(15, 15));
82 layer_after->SetContentBounds(gfx::Size(15, 15));
83 layer_after->SetDrawsContent(true);
84 layer_after->SetHasRenderSurface(true);
86 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
87 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
88 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
89 delegated_renderer_layer->SetDrawsContent(true);
90 gfx::Transform transform;
91 transform.Translate(1.0, 1.0);
92 delegated_renderer_layer->SetTransform(transform);
94 RenderPassList delegated_render_passes;
95 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
96 RenderPassId(9, 6),
97 gfx::Rect(6, 6, 6, 6),
98 gfx::Transform(1, 0, 0, 1, 5, 6));
99 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
100 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
101 RenderPassId(9, 7),
102 gfx::Rect(7, 7, 7, 7),
103 gfx::Transform(1, 0, 0, 1, 7, 8));
104 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
105 AddRenderPassQuad(pass2, pass1);
106 TestRenderPass* pass3 = AddRenderPass(&delegated_render_passes,
107 RenderPassId(9, 8),
108 gfx::Rect(0, 0, 8, 8),
109 gfx::Transform(1, 0, 0, 1, 9, 10));
110 AddRenderPassQuad(pass3, pass2);
111 delegated_renderer_layer->SetFrameDataForRenderPasses(
112 1.f, delegated_render_passes);
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(DelegatedRendererLayerImplTest,
138 ChangeContributingRenderPassForNewFrame) {
139 FakeDelegatedRendererLayerImpl* fake_delegated_renderer_layer_impl;
141 scoped_ptr<LayerImpl> root_layer =
142 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
143 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
144 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
146 host_impl_->SetViewportSize(gfx::Size(100, 100));
147 root_layer->SetBounds(gfx::Size(100, 100));
148 root_layer->SetHasRenderSurface(true);
150 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
151 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
152 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
153 delegated_renderer_layer->SetDrawsContent(true);
154 delegated_renderer_layer->SetHasRenderSurface(true);
155 gfx::Transform transform;
156 transform.Translate(1.0, 1.0);
157 delegated_renderer_layer->SetTransform(transform);
159 RenderPassList delegated_render_passes;
160 TestRenderPass* pass1 =
161 AddRenderPass(&delegated_render_passes, RenderPassId(9, 6),
162 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
163 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
164 TestRenderPass* pass2 =
165 AddRenderPass(&delegated_render_passes, RenderPassId(9, 7),
166 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
167 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
168 AddRenderPassQuad(pass2, pass1);
169 TestRenderPass* pass3 =
170 AddRenderPass(&delegated_render_passes, RenderPassId(9, 8),
171 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
172 AddRenderPassQuad(pass3, pass2);
173 delegated_renderer_layer->SetFrameDataForRenderPasses(
174 1.f, delegated_render_passes);
176 fake_delegated_renderer_layer_impl = delegated_renderer_layer.get();
178 root_layer->AddChild(delegated_renderer_layer.Pass());
180 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
182 LayerTreeHostImpl::FrameData frame;
183 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
185 // Root layer has one render pass, and delegated renderer layer has two
186 // contributing render passes and its own render pass.
187 ASSERT_EQ(4u, frame.render_passes.size());
189 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
190 host_impl_->DidDrawAllLayers(frame);
193 // New frame makes delegated renderer layer loses its contributing render
194 // passes.
195 RenderPassList delegated_render_passes;
196 AddRenderPass(&delegated_render_passes, RenderPassId(9, 8),
197 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
198 fake_delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
199 1.f, delegated_render_passes);
201 // Force damage to redraw a new frame.
202 host_impl_->SetViewportDamage(gfx::Rect(10, 10));
204 LayerTreeHostImpl::FrameData frame;
205 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
207 // Each non-DelegatedRendererLayer added one RenderPass. The
208 // DelegatedRendererLayer added two contributing passes.
209 ASSERT_EQ(1u, frame.render_passes.size());
211 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
212 host_impl_->DidDrawAllLayers(frame);
216 TEST_F(DelegatedRendererLayerImplTest,
217 ChangeContributingRenderPassNonFullTreeSync) {
218 FakeDelegatedRendererLayerImpl* fake_delegated_renderer_layer_impl;
220 host_impl_->CreatePendingTree();
221 scoped_ptr<LayerImpl> root_layer =
222 SolidColorLayerImpl::Create(host_impl_->pending_tree(), 1);
223 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
224 FakeDelegatedRendererLayerImpl::Create(host_impl_->pending_tree(), 2);
226 host_impl_->SetViewportSize(gfx::Size(100, 100));
227 root_layer->SetBounds(gfx::Size(100, 100));
228 root_layer->SetHasRenderSurface(true);
230 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
231 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
232 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
233 delegated_renderer_layer->SetDrawsContent(true);
234 delegated_renderer_layer->SetHasRenderSurface(true);
235 gfx::Transform transform;
236 transform.Translate(1.0, 1.0);
237 delegated_renderer_layer->SetTransform(transform);
239 RenderPassList delegated_render_passes;
240 TestRenderPass* pass1 =
241 AddRenderPass(&delegated_render_passes, RenderPassId(9, 6),
242 gfx::Rect(6, 6, 6, 6), gfx::Transform(1, 0, 0, 1, 5, 6));
243 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
244 TestRenderPass* pass2 =
245 AddRenderPass(&delegated_render_passes, RenderPassId(9, 7),
246 gfx::Rect(7, 7, 7, 7), gfx::Transform(1, 0, 0, 1, 7, 8));
247 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
248 AddRenderPassQuad(pass2, pass1);
249 TestRenderPass* pass3 =
250 AddRenderPass(&delegated_render_passes, RenderPassId(9, 8),
251 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
252 AddRenderPassQuad(pass3, pass2);
253 delegated_renderer_layer->SetFrameDataForRenderPasses(
254 1.f, delegated_render_passes);
256 fake_delegated_renderer_layer_impl = delegated_renderer_layer.get();
258 root_layer->AddChild(delegated_renderer_layer.Pass());
260 host_impl_->pending_tree()->SetRootLayer(root_layer.Pass());
261 host_impl_->ActivateSyncTree();
263 LayerTreeHostImpl::FrameData frame;
264 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
266 // Root layer has one render pass, and delegated renderer layer has two
267 // contributing render passes and its own render pass.
268 ASSERT_EQ(4u, frame.render_passes.size());
270 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
271 host_impl_->DidDrawAllLayers(frame);
274 // Remove contributing render passes from the delegated renderer layer.
275 host_impl_->CreatePendingTree();
276 host_impl_->pending_tree()->set_needs_full_tree_sync(false);
277 RenderPassList delegated_render_passes;
278 AddRenderPass(&delegated_render_passes, RenderPassId(9, 8),
279 gfx::Rect(0, 0, 8, 8), gfx::Transform(1, 0, 0, 1, 9, 10));
281 fake_delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
282 1.f, delegated_render_passes);
284 // Force damage to redraw a new frame.
286 host_impl_->ActivateSyncTree();
287 host_impl_->SetViewportDamage(gfx::Rect(100, 100));
288 LayerTreeHostImpl::FrameData frame;
289 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
291 // Root layer has one render pass, and delegated renderer layer no longer
292 // has contributing render passes.
293 ASSERT_EQ(1u, frame.render_passes.size());
295 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
296 host_impl_->DidDrawAllLayers(frame);
300 TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
301 LayerTreeHostImpl::FrameData frame;
302 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
304 // Each non-DelegatedRendererLayer added one RenderPass. The
305 // DelegatedRendererLayer added two contributing passes.
306 ASSERT_EQ(5u, frame.render_passes.size());
308 // The DelegatedRendererLayer should have added its contributing RenderPasses
309 // to the frame.
310 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
311 EXPECT_EQ(1, frame.render_passes[1]->id.index);
312 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
313 EXPECT_EQ(2, frame.render_passes[2]->id.index);
314 // And all other RenderPasses should be non-delegated.
315 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
316 EXPECT_EQ(0, frame.render_passes[0]->id.index);
317 EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
318 EXPECT_EQ(0, frame.render_passes[3]->id.index);
319 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
320 EXPECT_EQ(0, frame.render_passes[4]->id.index);
322 // The DelegatedRendererLayer should have added its RenderPasses to the frame
323 // in order.
324 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
325 frame.render_passes[1]->output_rect.ToString());
326 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
327 frame.render_passes[2]->output_rect.ToString());
329 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
330 host_impl_->DidDrawAllLayers(frame);
333 TEST_F(DelegatedRendererLayerImplTestSimple,
334 AddsQuadsToContributingRenderPasses) {
335 LayerTreeHostImpl::FrameData frame;
336 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
338 // Each non-DelegatedRendererLayer added one RenderPass. The
339 // DelegatedRendererLayer added two contributing passes.
340 ASSERT_EQ(5u, frame.render_passes.size());
342 // The DelegatedRendererLayer should have added its contributing RenderPasses
343 // to the frame.
344 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
345 EXPECT_EQ(1, frame.render_passes[1]->id.index);
346 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
347 EXPECT_EQ(2, frame.render_passes[2]->id.index);
349 // The DelegatedRendererLayer should have added copies of its quads to
350 // contributing RenderPasses.
351 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
352 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
353 frame.render_passes[1]->quad_list.front()->rect.ToString());
355 // Verify it added the right quads.
356 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
357 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
358 frame.render_passes[2]->quad_list.front()->rect.ToString());
359 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
360 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
361 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
362 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
363 frame.render_passes[1]->quad_list.front()->rect.ToString());
365 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
366 host_impl_->DidDrawAllLayers(frame);
369 TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
370 LayerTreeHostImpl::FrameData frame;
371 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
373 // Each non-DelegatedRendererLayer added one RenderPass. The
374 // DelegatedRendererLayer added two contributing passes.
375 ASSERT_EQ(5u, frame.render_passes.size());
377 // The layer's target is the RenderPass from layer_after_.
378 EXPECT_EQ(RenderPassId(3, 0), frame.render_passes[3]->id);
380 // The DelegatedRendererLayer should have added copies of quads in its root
381 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
382 ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
384 // Verify it added the right quads.
385 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
386 frame.render_passes[3]->quad_list.front()->rect.ToString());
388 // Its target layer should have a quad as well.
389 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
390 frame.render_passes[3]->quad_list.ElementAt(1)->rect.ToString());
392 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
393 host_impl_->DidDrawAllLayers(frame);
396 TEST_F(DelegatedRendererLayerImplTestSimple,
397 QuadsFromRootRenderPassAreModifiedForTheTarget) {
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.
403 ASSERT_EQ(5u, frame.render_passes.size());
405 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
406 // has a translation transform of 1,1. So its root RenderPass' quads should
407 // all be transformed by that combined amount.
408 gfx::Transform transform;
409 transform.Translate(4.0, 4.0);
410 EXPECT_TRANSFORMATION_MATRIX_EQ(
411 transform, frame.render_passes[3]->quad_list.front()->quadTransform());
413 // Quads from non-root RenderPasses should not be shifted though.
414 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
416 EXPECT_TRANSFORMATION_MATRIX_EQ(
417 gfx::Transform(),
418 frame.render_passes[2]->quad_list.front()->quadTransform());
419 EXPECT_TRANSFORMATION_MATRIX_EQ(
420 gfx::Transform(),
421 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
422 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
423 EXPECT_TRANSFORMATION_MATRIX_EQ(
424 gfx::Transform(),
425 frame.render_passes[1]->quad_list.front()->quadTransform());
427 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
428 host_impl_->DidDrawAllLayers(frame);
431 TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
432 LayerTreeHostImpl::FrameData frame;
433 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
435 // The delegated layer has a surface between it and the root.
436 EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
438 // Each non-DelegatedRendererLayer added one RenderPass. The
439 // DelegatedRendererLayer added two contributing passes.
440 ASSERT_EQ(5u, frame.render_passes.size());
442 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
443 // render pass' transforms to the root should be shifted by this amount.
444 gfx::Transform transform;
445 transform.Translate(9.0, 9.0);
447 // The first contributing surface has a translation of 5, 6.
448 gfx::Transform five_six(1, 0, 0, 1, 5, 6);
450 // The second contributing surface has a translation of 7, 8.
451 gfx::Transform seven_eight(1, 0, 0, 1, 7, 8);
453 EXPECT_TRANSFORMATION_MATRIX_EQ(
454 transform * five_six, frame.render_passes[1]->transform_to_root_target);
455 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 transform * seven_eight,
457 frame.render_passes[2]->transform_to_root_target);
459 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
460 host_impl_->DidDrawAllLayers(frame);
463 class DelegatedRendererLayerImplTestOwnSurface
464 : public DelegatedRendererLayerImplTestSimple {
465 public:
466 DelegatedRendererLayerImplTestOwnSurface()
467 : DelegatedRendererLayerImplTestSimple() {
468 delegated_renderer_layer_->SetHasRenderSurface(true);
472 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
473 LayerTreeHostImpl::FrameData frame;
474 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
476 // Each non-DelegatedRendererLayer added one RenderPass. The
477 // DelegatedRendererLayer added two contributing passes and its owned surface
478 // added one pass.
479 ASSERT_EQ(6u, frame.render_passes.size());
481 // The DelegatedRendererLayer should have added its contributing RenderPasses
482 // to the frame.
483 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
484 EXPECT_EQ(1, frame.render_passes[1]->id.index);
485 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
486 EXPECT_EQ(2, frame.render_passes[2]->id.index);
487 // The DelegatedRendererLayer should have added a RenderPass for its surface
488 // to the frame.
489 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
490 EXPECT_EQ(0, frame.render_passes[3]->id.index);
491 // And all other RenderPasses should be non-delegated.
492 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
493 EXPECT_EQ(0, frame.render_passes[0]->id.index);
494 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
495 EXPECT_EQ(0, frame.render_passes[4]->id.index);
496 EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
497 EXPECT_EQ(0, frame.render_passes[5]->id.index);
499 // The DelegatedRendererLayer should have added its RenderPasses to the frame
500 // in order.
501 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
502 frame.render_passes[1]->output_rect.ToString());
503 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
504 frame.render_passes[2]->output_rect.ToString());
506 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
507 host_impl_->DidDrawAllLayers(frame);
510 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
511 AddsQuadsToContributingRenderPasses) {
512 LayerTreeHostImpl::FrameData frame;
513 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
515 // Each non-DelegatedRendererLayer added one RenderPass. The
516 // DelegatedRendererLayer added two contributing passes and its owned surface
517 // added one pass.
518 ASSERT_EQ(6u, frame.render_passes.size());
520 // The DelegatedRendererLayer should have added its contributing RenderPasses
521 // to the frame.
522 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
523 EXPECT_EQ(1, frame.render_passes[1]->id.index);
524 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
525 EXPECT_EQ(2, frame.render_passes[2]->id.index);
527 // The DelegatedRendererLayer should have added copies of its quads to
528 // contributing RenderPasses.
529 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
530 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
531 frame.render_passes[1]->quad_list.front()->rect.ToString());
533 // Verify it added the right quads.
534 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
536 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
537 frame.render_passes[2]->quad_list.front()->rect.ToString());
538 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
539 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
540 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
541 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
542 frame.render_passes[1]->quad_list.front()->rect.ToString());
544 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
545 host_impl_->DidDrawAllLayers(frame);
548 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
549 LayerTreeHostImpl::FrameData frame;
550 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
552 // Each non-DelegatedRendererLayer added one RenderPass. The
553 // DelegatedRendererLayer added two contributing passes and its owned surface
554 // added one pass.
555 ASSERT_EQ(6u, frame.render_passes.size());
557 // The layer's target is the RenderPass owned by itself.
558 EXPECT_EQ(RenderPassId(4, 0), frame.render_passes[3]->id);
560 // The DelegatedRendererLayer should have added copies of quads in its root
561 // RenderPass to its target RenderPass.
562 // The layer_after also adds one quad.
563 ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
565 // Verify it added the right quads.
566 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
567 frame.render_passes[3]->quad_list.front()->rect.ToString());
569 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
570 host_impl_->DidDrawAllLayers(frame);
573 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
574 QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
575 LayerTreeHostImpl::FrameData frame;
576 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
578 // Each non-DelegatedRendererLayer added one RenderPass. The
579 // DelegatedRendererLayer added two contributing passes and its owned surface
580 // added one pass.
581 ASSERT_EQ(6u, frame.render_passes.size());
583 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
584 // RenderPass' quads do not need to be translated at all.
585 EXPECT_TRANSFORMATION_MATRIX_EQ(
586 gfx::Transform(),
587 frame.render_passes[3]->quad_list.front()->quadTransform());
589 // Quads from non-root RenderPasses should not be shifted either.
590 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
592 EXPECT_TRANSFORMATION_MATRIX_EQ(
593 gfx::Transform(),
594 frame.render_passes[2]->quad_list.front()->quadTransform());
595 EXPECT_TRANSFORMATION_MATRIX_EQ(
596 gfx::Transform(),
597 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
598 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
599 EXPECT_TRANSFORMATION_MATRIX_EQ(
600 gfx::Transform(),
601 frame.render_passes[1]->quad_list.front()->quadTransform());
603 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
604 host_impl_->DidDrawAllLayers(frame);
607 class DelegatedRendererLayerImplTestTransform
608 : public DelegatedRendererLayerImplTest {
609 public:
610 DelegatedRendererLayerImplTestTransform()
611 : root_delegated_render_pass_is_clipped_(false),
612 delegated_device_scale_factor_(2.f) {}
614 void SetUpTest() {
615 host_impl_->SetDeviceScaleFactor(2.f);
617 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
618 host_impl_->active_tree(), 1);
619 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
620 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
622 host_impl_->SetViewportSize(gfx::Size(200, 200));
623 root_layer->SetBounds(gfx::Size(100, 100));
624 root_layer->SetHasRenderSurface(true);
626 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
627 delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
628 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
629 delegated_renderer_layer->SetDrawsContent(true);
630 gfx::Transform transform;
631 transform.Scale(2.0, 2.0);
632 transform.Translate(8.0, 8.0);
633 delegated_renderer_layer->SetTransform(transform);
635 RenderPassList delegated_render_passes;
637 gfx::Size child_pass_content_bounds(7, 7);
638 gfx::Rect child_pass_rect(20, 20, 7, 7);
639 gfx::Transform child_pass_transform;
640 child_pass_transform.Scale(0.8f, 0.8f);
641 child_pass_transform.Translate(9.0, 9.0);
642 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
643 bool child_pass_clipped = false;
646 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
647 RenderPassId(10, 7),
648 child_pass_rect,
649 gfx::Transform());
650 SharedQuadState* shared_quad_state =
651 pass->CreateAndAppendSharedQuadState();
652 shared_quad_state->SetAll(child_pass_transform,
653 child_pass_content_bounds,
654 child_pass_rect,
655 child_pass_clip_rect,
656 child_pass_clipped,
657 1.f,
658 SkXfermode::kSrcOver_Mode,
661 SolidColorDrawQuad* color_quad;
662 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
663 color_quad->SetNew(shared_quad_state,
664 gfx::Rect(20, 20, 3, 7),
665 gfx::Rect(20, 20, 3, 7),
667 false);
669 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
670 color_quad->SetNew(shared_quad_state,
671 gfx::Rect(23, 20, 4, 7),
672 gfx::Rect(23, 20, 4, 7),
674 false);
677 gfx::Size root_pass_content_bounds(100, 100);
678 gfx::Rect root_pass_rect(0, 0, 100, 100);
679 gfx::Transform root_pass_transform;
680 root_pass_transform.Scale(1.5, 1.5);
681 root_pass_transform.Translate(7.0, 7.0);
682 gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
683 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
685 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
686 RenderPassId(9, 6),
687 root_pass_rect,
688 gfx::Transform());
689 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
690 shared_quad_state->SetAll(root_pass_transform,
691 root_pass_content_bounds,
692 root_pass_rect,
693 root_pass_clip_rect,
694 root_pass_clipped,
695 1.f,
696 SkXfermode::kSrcOver_Mode,
699 RenderPassDrawQuad* render_pass_quad =
700 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
701 render_pass_quad->SetNew(shared_quad_state,
702 gfx::Rect(5, 5, 7, 7), // quad_rect
703 gfx::Rect(5, 5, 7, 7), // visible_rect
704 RenderPassId(10, 7), // render_pass_id
705 0, // mask_resource_id
706 gfx::Vector2dF(), // mask_uv_scale
707 gfx::Size(), // mask_texture_size
708 FilterOperations(), // filters
709 gfx::Vector2dF(), // filters_scale
710 FilterOperations()); // background_filters
712 SolidColorDrawQuad* color_quad;
713 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
714 color_quad->SetNew(shared_quad_state,
715 gfx::Rect(0, 0, 10, 10),
716 gfx::Rect(0, 0, 10, 10),
718 false);
720 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
721 color_quad->SetNew(shared_quad_state,
722 gfx::Rect(0, 10, 10, 10),
723 gfx::Rect(0, 10, 10, 10),
725 false);
727 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
728 color_quad->SetNew(shared_quad_state,
729 gfx::Rect(10, 0, 10, 10),
730 gfx::Rect(10, 0, 10, 10),
732 false);
734 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
735 color_quad->SetNew(shared_quad_state,
736 gfx::Rect(10, 10, 10, 10),
737 gfx::Rect(10, 10, 10, 10),
739 false);
741 delegated_renderer_layer->SetFrameDataForRenderPasses(
742 delegated_device_scale_factor_, delegated_render_passes);
744 root_layer_ = root_layer.get();
745 delegated_renderer_layer_ = delegated_renderer_layer.get();
747 root_layer->AddChild(delegated_renderer_layer.Pass());
748 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
751 void VerifyRenderPasses(
752 const LayerTreeHostImpl::FrameData& frame,
753 size_t num_render_passes,
754 const SharedQuadState** root_delegated_shared_quad_state,
755 const SharedQuadState** contrib_delegated_shared_quad_state) {
756 ASSERT_EQ(num_render_passes, frame.render_passes.size());
757 // The contributing render pass in the DelegatedRendererLayer.
758 EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
759 EXPECT_EQ(1, frame.render_passes[0]->id.index);
760 // The root render pass.
761 EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
762 EXPECT_EQ(0, frame.render_passes.back()->id.index);
764 const QuadList& contrib_delegated_quad_list =
765 frame.render_passes[0]->quad_list;
766 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
768 const QuadList& root_delegated_quad_list =
769 frame.render_passes[1]->quad_list;
770 ASSERT_EQ(5u, root_delegated_quad_list.size());
772 // All quads in a render pass should share the same state.
773 *contrib_delegated_shared_quad_state =
774 contrib_delegated_quad_list.front()->shared_quad_state;
775 EXPECT_EQ(*contrib_delegated_shared_quad_state,
776 contrib_delegated_quad_list.ElementAt(1)->shared_quad_state);
778 *root_delegated_shared_quad_state =
779 root_delegated_quad_list.front()->shared_quad_state;
780 EXPECT_EQ(*root_delegated_shared_quad_state,
781 root_delegated_quad_list.ElementAt(1)->shared_quad_state);
782 EXPECT_EQ(*root_delegated_shared_quad_state,
783 root_delegated_quad_list.ElementAt(2)->shared_quad_state);
784 EXPECT_EQ(*root_delegated_shared_quad_state,
785 root_delegated_quad_list.ElementAt(3)->shared_quad_state);
786 EXPECT_EQ(*root_delegated_shared_quad_state,
787 root_delegated_quad_list.ElementAt(4)->shared_quad_state);
789 EXPECT_NE(*contrib_delegated_shared_quad_state,
790 *root_delegated_shared_quad_state);
793 protected:
794 LayerImpl* root_layer_;
795 DelegatedRendererLayerImpl* delegated_renderer_layer_;
796 bool root_delegated_render_pass_is_clipped_;
797 float delegated_device_scale_factor_;
800 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
801 root_delegated_render_pass_is_clipped_ = false;
802 SetUpTest();
804 LayerTreeHostImpl::FrameData frame;
805 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
807 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
808 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
809 VerifyRenderPasses(
810 frame,
812 &root_delegated_shared_quad_state,
813 &contrib_delegated_shared_quad_state);
815 // When the quads don't have a clip of their own, the clip rect is set to
816 // the drawable_content_rect of the delegated renderer layer.
817 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
818 root_delegated_shared_quad_state->clip_rect.ToString());
820 // Even though the quads in the root pass have no clip of their own, they
821 // inherit the clip rect from the delegated renderer layer if it does not
822 // own a surface.
823 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
825 gfx::Transform expected;
826 // Device scale factor.
827 expected.Scale(2.0, 2.0);
828 // This is the transform from the layer's space to its target.
829 expected.Translate(20, 20);
830 expected.Scale(2.0, 2.0);
831 expected.Translate(8.0, 8.0);
832 // This is the transform within the source frame.
833 // Inverse device scale factor to go from physical space to layer space.
834 expected.Scale(0.5, 0.5);
835 expected.Scale(1.5, 1.5);
836 expected.Translate(7.0, 7.0);
837 EXPECT_TRANSFORMATION_MATRIX_EQ(
838 expected, root_delegated_shared_quad_state->content_to_target_transform);
840 // The contributing render pass should not be transformed from its input.
841 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
842 contrib_delegated_shared_quad_state->clip_rect.ToString());
843 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
844 expected.MakeIdentity();
845 expected.Scale(0.8f, 0.8f);
846 expected.Translate(9.0, 9.0);
847 EXPECT_TRANSFORMATION_MATRIX_EQ(
848 expected,
849 contrib_delegated_shared_quad_state->content_to_target_transform);
851 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
852 host_impl_->DidDrawAllLayers(frame);
855 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
856 root_delegated_render_pass_is_clipped_ = true;
857 SetUpTest();
859 LayerTreeHostImpl::FrameData frame;
860 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
862 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
863 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
864 VerifyRenderPasses(
865 frame,
867 &root_delegated_shared_quad_state,
868 &contrib_delegated_shared_quad_state);
870 // Since the quads have a clip_rect it should be modified by delegated
871 // renderer layer's draw_transform.
872 // The position of the resulting clip_rect is:
873 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
874 // layer scale (2) + layer position (20) = 46
875 // The device scale is 2, so everything gets doubled, giving 92.
877 // The size is 35x35 scaled by the device scale.
878 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
879 root_delegated_shared_quad_state->clip_rect.ToString());
881 // The quads had a clip and it should be preserved.
882 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
884 gfx::Transform expected;
885 // Device scale factor.
886 expected.Scale(2.0, 2.0);
887 // This is the transform from the layer's space to its target.
888 expected.Translate(20, 20);
889 expected.Scale(2.0, 2.0);
890 expected.Translate(8.0, 8.0);
891 // This is the transform within the source frame.
892 // Inverse device scale factor to go from physical space to layer space.
893 expected.Scale(0.5, 0.5);
894 expected.Scale(1.5, 1.5);
895 expected.Translate(7.0, 7.0);
896 EXPECT_TRANSFORMATION_MATRIX_EQ(
897 expected, root_delegated_shared_quad_state->content_to_target_transform);
899 // The contributing render pass should not be transformed from its input.
900 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
901 contrib_delegated_shared_quad_state->clip_rect.ToString());
902 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
903 expected.MakeIdentity();
904 expected.Scale(0.8f, 0.8f);
905 expected.Translate(9.0, 9.0);
906 EXPECT_TRANSFORMATION_MATRIX_EQ(
907 expected,
908 contrib_delegated_shared_quad_state->content_to_target_transform);
910 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
911 host_impl_->DidDrawAllLayers(frame);
914 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
915 root_delegated_render_pass_is_clipped_ = false;
916 SetUpTest();
918 delegated_renderer_layer_->SetHasRenderSurface(true);
920 LayerTreeHostImpl::FrameData frame;
921 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
923 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
924 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
925 VerifyRenderPasses(
926 frame,
928 &root_delegated_shared_quad_state,
929 &contrib_delegated_shared_quad_state);
931 // When the layer owns a surface, then its translation is not part of its
932 // draw transform, but its scale is.
933 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
934 root_delegated_shared_quad_state->clip_rect.ToString());
936 // Since the layer owns a surface it doesn't need to clip its quads, so
937 // unclipped quads remain unclipped.
938 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
940 gfx::Transform expected;
941 // This is the transform within the source frame scaled by the delegated
942 // render layer transform.
943 expected.Scale(3.0, 3.0);
944 expected.Translate(7.0, 7.0);
945 EXPECT_TRANSFORMATION_MATRIX_EQ(
946 expected, root_delegated_shared_quad_state->content_to_target_transform);
948 // The contributing render pass should not be transformed from its input.
949 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
950 contrib_delegated_shared_quad_state->clip_rect.ToString());
951 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
952 expected.MakeIdentity();
953 expected.Scale(0.8f, 0.8f);
954 expected.Translate(9.0, 9.0);
955 EXPECT_TRANSFORMATION_MATRIX_EQ(
956 expected,
957 contrib_delegated_shared_quad_state->content_to_target_transform);
959 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
960 host_impl_->DidDrawAllLayers(frame);
963 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
964 root_delegated_render_pass_is_clipped_ = true;
965 SetUpTest();
967 delegated_renderer_layer_->SetHasRenderSurface(true);
969 LayerTreeHostImpl::FrameData frame;
970 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
972 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
973 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
974 VerifyRenderPasses(
975 frame,
977 &root_delegated_shared_quad_state,
978 &contrib_delegated_shared_quad_state);
980 // When the layer owns a surface, then its translation is not part of its
981 // draw transform, but its scale is.
982 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
983 root_delegated_shared_quad_state->clip_rect.ToString());
985 // The quads had a clip and it should be preserved.
986 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
988 gfx::Transform expected;
989 // This is the transform within the source frame scaled by the delegated
990 // render layer transform.
991 expected.Scale(3.0, 3.0);
992 expected.Translate(7.0, 7.0);
993 EXPECT_TRANSFORMATION_MATRIX_EQ(
994 expected, root_delegated_shared_quad_state->content_to_target_transform);
996 // The contributing render pass should not be transformed from its input.
997 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
998 contrib_delegated_shared_quad_state->clip_rect.ToString());
999 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
1000 expected.MakeIdentity();
1001 expected.Scale(0.8f, 0.8f);
1002 expected.Translate(9.0, 9.0);
1003 EXPECT_TRANSFORMATION_MATRIX_EQ(
1004 expected,
1005 contrib_delegated_shared_quad_state->content_to_target_transform);
1007 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1008 host_impl_->DidDrawAllLayers(frame);
1011 TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
1012 root_delegated_render_pass_is_clipped_ = true;
1013 delegated_device_scale_factor_ = 1.3f;
1015 SetUpTest();
1017 LayerTreeHostImpl::FrameData frame;
1018 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1020 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
1021 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
1022 VerifyRenderPasses(frame,
1024 &root_delegated_shared_quad_state,
1025 &contrib_delegated_shared_quad_state);
1027 // The parent tree's device scale factor is 2.0, but the child has submitted a
1028 // frame with a device scale factor of 1.3. Absent any better option, the
1029 // only thing we can do is scale from 1.3 -> 2.0.
1031 gfx::Transform expected;
1032 // Device scale factor (from parent).
1033 expected.Scale(2.0, 2.0);
1034 // This is the transform from the layer's space to its target.
1035 expected.Translate(20, 20);
1036 expected.Scale(2.0, 2.0);
1037 expected.Translate(8.0, 8.0);
1038 // This is the transform within the source frame.
1039 // Inverse device scale factor (from child).
1040 expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
1041 expected.Scale(1.5, 1.5);
1042 expected.Translate(7.0, 7.0);
1043 EXPECT_TRANSFORMATION_MATRIX_EQ(
1044 expected, root_delegated_shared_quad_state->content_to_target_transform);
1046 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1047 host_impl_->DidDrawAllLayers(frame);
1050 class DelegatedRendererLayerImplTestClip
1051 : public DelegatedRendererLayerImplTest {
1052 public:
1053 void SetUpTest() {
1054 scoped_ptr<LayerImpl> root_layer =
1055 LayerImpl::Create(host_impl_->active_tree(), 1);
1056 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
1057 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
1058 scoped_ptr<LayerImpl> clip_layer =
1059 LayerImpl::Create(host_impl_->active_tree(), 3);
1060 scoped_ptr<LayerImpl> origin_layer =
1061 LayerImpl::Create(host_impl_->active_tree(), 4);
1063 host_impl_->SetViewportSize(gfx::Size(100, 100));
1064 root_layer->SetBounds(gfx::Size(100, 100));
1065 root_layer->SetHasRenderSurface(true);
1067 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
1068 delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
1069 delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
1070 delegated_renderer_layer->SetDrawsContent(true);
1072 RenderPassList delegated_render_passes;
1074 gfx::Size child_pass_content_bounds(7, 7);
1075 gfx::Rect child_pass_rect(20, 20, 7, 7);
1076 gfx::Transform child_pass_transform;
1077 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
1078 bool child_pass_clipped = false;
1081 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
1082 RenderPassId(10, 7),
1083 child_pass_rect,
1084 gfx::Transform());
1085 SharedQuadState* shared_quad_state =
1086 pass->CreateAndAppendSharedQuadState();
1087 shared_quad_state->SetAll(child_pass_transform,
1088 child_pass_content_bounds,
1089 child_pass_rect,
1090 child_pass_clip_rect,
1091 child_pass_clipped,
1092 1.f,
1093 SkXfermode::kSrcOver_Mode,
1096 SolidColorDrawQuad* color_quad;
1097 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1098 color_quad->SetNew(shared_quad_state,
1099 gfx::Rect(20, 20, 3, 7),
1100 gfx::Rect(20, 20, 3, 7),
1102 false);
1104 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1105 color_quad->SetNew(shared_quad_state,
1106 gfx::Rect(23, 20, 4, 7),
1107 gfx::Rect(23, 20, 4, 7),
1109 false);
1112 gfx::Size root_pass_content_bounds(50, 50);
1113 gfx::Rect root_pass_rect(0, 0, 50, 50);
1114 gfx::Transform root_pass_transform;
1115 gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
1116 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
1118 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
1119 RenderPassId(9, 6),
1120 root_pass_rect,
1121 gfx::Transform());
1122 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
1123 shared_quad_state->SetAll(root_pass_transform,
1124 root_pass_content_bounds,
1125 root_pass_rect,
1126 root_pass_clip_rect,
1127 root_pass_clipped,
1128 1.f,
1129 SkXfermode::kSrcOver_Mode,
1132 RenderPassDrawQuad* render_pass_quad =
1133 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
1134 render_pass_quad->SetNew(shared_quad_state,
1135 gfx::Rect(5, 5, 7, 7), // quad_rect
1136 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
1137 RenderPassId(10, 7), // render_pass_id
1138 0, // mask_resource_id
1139 gfx::Vector2dF(), // mask_uv_scale
1140 gfx::Size(), // mask_texture_size,
1141 FilterOperations(), // filters
1142 gfx::Vector2dF(), // filters_scale
1143 FilterOperations()); // background_filters
1145 SolidColorDrawQuad* color_quad;
1146 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1147 color_quad->SetNew(shared_quad_state,
1148 gfx::Rect(0, 0, 10, 10),
1149 gfx::Rect(0, 0, 10, 10),
1151 false);
1153 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1154 color_quad->SetNew(shared_quad_state,
1155 gfx::Rect(0, 10, 10, 10),
1156 gfx::Rect(0, 10, 10, 10),
1158 false);
1160 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1161 color_quad->SetNew(shared_quad_state,
1162 gfx::Rect(10, 0, 10, 10),
1163 gfx::Rect(10, 0, 10, 10),
1165 false);
1167 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1168 color_quad->SetNew(shared_quad_state,
1169 gfx::Rect(10, 10, 10, 10),
1170 gfx::Rect(10, 10, 10, 10),
1172 false);
1174 delegated_renderer_layer->SetFrameDataForRenderPasses(
1175 1.f, delegated_render_passes);
1177 root_layer_ = root_layer.get();
1178 delegated_renderer_layer_ = delegated_renderer_layer.get();
1180 if (clip_delegated_renderer_layer_) {
1181 gfx::Rect clip_rect(21, 27, 23, 21);
1183 clip_layer->SetPosition(clip_rect.origin());
1184 clip_layer->SetBounds(clip_rect.size());
1185 clip_layer->SetContentBounds(clip_rect.size());
1186 clip_layer->SetMasksToBounds(true);
1188 origin_layer->SetPosition(
1189 gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin()));
1191 origin_layer->AddChild(delegated_renderer_layer.Pass());
1192 clip_layer->AddChild(origin_layer.Pass());
1193 root_layer->AddChild(clip_layer.Pass());
1194 } else {
1195 root_layer->AddChild(delegated_renderer_layer.Pass());
1198 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1201 protected:
1202 LayerImpl* root_layer_;
1203 DelegatedRendererLayerImpl* delegated_renderer_layer_;
1204 bool root_delegated_render_pass_is_clipped_;
1205 bool clip_delegated_renderer_layer_;
1208 TEST_F(DelegatedRendererLayerImplTestClip,
1209 QuadsUnclipped_LayerUnclipped_NoSurface) {
1210 root_delegated_render_pass_is_clipped_ = false;
1211 clip_delegated_renderer_layer_ = false;
1212 SetUpTest();
1214 LayerTreeHostImpl::FrameData frame;
1215 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1217 ASSERT_EQ(2u, frame.render_passes.size());
1218 const QuadList& contrib_delegated_quad_list =
1219 frame.render_passes[0]->quad_list;
1220 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1221 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1222 ASSERT_EQ(5u, root_delegated_quad_list.size());
1223 const SharedQuadState* root_delegated_shared_quad_state =
1224 root_delegated_quad_list.front()->shared_quad_state;
1226 // When the quads don't have a clip of their own, the clip rect is set to
1227 // the drawable_content_rect of the delegated renderer layer.
1228 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1229 root_delegated_shared_quad_state->clip_rect.ToString());
1230 // Quads are clipped to the delegated renderer layer.
1231 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1233 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1234 host_impl_->DidDrawAllLayers(frame);
1237 TEST_F(DelegatedRendererLayerImplTestClip,
1238 QuadsClipped_LayerUnclipped_NoSurface) {
1239 root_delegated_render_pass_is_clipped_ = true;
1240 clip_delegated_renderer_layer_ = false;
1241 SetUpTest();
1243 LayerTreeHostImpl::FrameData frame;
1244 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1246 ASSERT_EQ(2u, frame.render_passes.size());
1247 const QuadList& contrib_delegated_quad_list =
1248 frame.render_passes[0]->quad_list;
1249 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1250 const QuadList& root_delegated_quad_list =
1251 frame.render_passes[1]->quad_list;
1252 ASSERT_EQ(5u, root_delegated_quad_list.size());
1253 const SharedQuadState* root_delegated_shared_quad_state =
1254 root_delegated_quad_list.front()->shared_quad_state;
1256 // When the quads have a clip of their own, it is used.
1257 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1258 root_delegated_shared_quad_state->clip_rect.ToString());
1259 // Quads came with a clip rect.
1260 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1262 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1263 host_impl_->DidDrawAllLayers(frame);
1266 TEST_F(DelegatedRendererLayerImplTestClip,
1267 QuadsUnclipped_LayerClipped_NoSurface) {
1268 root_delegated_render_pass_is_clipped_ = false;
1269 clip_delegated_renderer_layer_ = true;
1270 SetUpTest();
1272 LayerTreeHostImpl::FrameData frame;
1273 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1275 ASSERT_EQ(2u, frame.render_passes.size());
1276 const QuadList& contrib_delegated_quad_list =
1277 frame.render_passes[0]->quad_list;
1278 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1279 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1280 ASSERT_EQ(5u, root_delegated_quad_list.size());
1281 const SharedQuadState* root_delegated_shared_quad_state =
1282 root_delegated_quad_list.front()->shared_quad_state;
1284 // When the quads don't have a clip of their own, the clip rect is set to
1285 // the drawable_content_rect of the delegated renderer layer. When the layer
1286 // is clipped, that should be seen in the quads' clip_rect.
1287 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1288 root_delegated_shared_quad_state->clip_rect.ToString());
1289 // Quads are clipped to the delegated renderer layer.
1290 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1292 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1293 host_impl_->DidDrawAllLayers(frame);
1296 TEST_F(DelegatedRendererLayerImplTestClip,
1297 QuadsClipped_LayerClipped_NoSurface) {
1298 root_delegated_render_pass_is_clipped_ = true;
1299 clip_delegated_renderer_layer_ = true;
1300 SetUpTest();
1302 LayerTreeHostImpl::FrameData frame;
1303 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1305 ASSERT_EQ(2u, frame.render_passes.size());
1306 const QuadList& contrib_delegated_quad_list =
1307 frame.render_passes[0]->quad_list;
1308 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1309 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1310 ASSERT_EQ(5u, root_delegated_quad_list.size());
1311 const SharedQuadState* root_delegated_shared_quad_state =
1312 root_delegated_quad_list.front()->shared_quad_state;
1314 // When the quads have a clip of their own, it is used, but it is
1315 // combined with the clip rect of the delegated renderer layer.
1316 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1317 root_delegated_shared_quad_state->clip_rect.ToString());
1318 // Quads came with a clip rect.
1319 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1321 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1322 host_impl_->DidDrawAllLayers(frame);
1325 TEST_F(DelegatedRendererLayerImplTestClip,
1326 QuadsUnclipped_LayerUnclipped_Surface) {
1327 root_delegated_render_pass_is_clipped_ = false;
1328 clip_delegated_renderer_layer_ = false;
1329 SetUpTest();
1331 delegated_renderer_layer_->SetHasRenderSurface(true);
1333 LayerTreeHostImpl::FrameData frame;
1334 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1336 ASSERT_EQ(3u, frame.render_passes.size());
1337 const QuadList& contrib_delegated_quad_list =
1338 frame.render_passes[0]->quad_list;
1339 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1340 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1341 ASSERT_EQ(5u, root_delegated_quad_list.size());
1342 const SharedQuadState* root_delegated_shared_quad_state =
1343 root_delegated_quad_list.front()->shared_quad_state;
1345 // When the layer owns a surface, the quads don't need to be clipped
1346 // further than they already specify. If they aren't clipped, then their
1347 // clip rect is ignored, and they are not set as clipped.
1348 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1350 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1351 host_impl_->DidDrawAllLayers(frame);
1354 TEST_F(DelegatedRendererLayerImplTestClip,
1355 QuadsClipped_LayerUnclipped_Surface) {
1356 root_delegated_render_pass_is_clipped_ = true;
1357 clip_delegated_renderer_layer_ = false;
1358 SetUpTest();
1360 delegated_renderer_layer_->SetHasRenderSurface(true);
1362 LayerTreeHostImpl::FrameData frame;
1363 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1365 ASSERT_EQ(3u, frame.render_passes.size());
1366 const QuadList& contrib_delegated_quad_list =
1367 frame.render_passes[0]->quad_list;
1368 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1369 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1370 ASSERT_EQ(5u, root_delegated_quad_list.size());
1371 const SharedQuadState* root_delegated_shared_quad_state =
1372 root_delegated_quad_list.front()->shared_quad_state;
1374 // When the quads have a clip of their own, it is used.
1375 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1376 root_delegated_shared_quad_state->clip_rect.ToString());
1377 // Quads came with a clip rect.
1378 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1380 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1381 host_impl_->DidDrawAllLayers(frame);
1384 TEST_F(DelegatedRendererLayerImplTestClip,
1385 QuadsUnclipped_LayerClipped_Surface) {
1386 root_delegated_render_pass_is_clipped_ = false;
1387 clip_delegated_renderer_layer_ = true;
1388 SetUpTest();
1390 delegated_renderer_layer_->SetHasRenderSurface(true);
1392 LayerTreeHostImpl::FrameData frame;
1393 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1395 ASSERT_EQ(3u, frame.render_passes.size());
1396 const QuadList& contrib_delegated_quad_list =
1397 frame.render_passes[0]->quad_list;
1398 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1399 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1400 ASSERT_EQ(5u, root_delegated_quad_list.size());
1401 const SharedQuadState* root_delegated_shared_quad_state =
1402 root_delegated_quad_list.front()->shared_quad_state;
1404 // When the layer owns a surface, the quads don't need to be clipped
1405 // further than they already specify. If they aren't clipped, then their
1406 // clip rect is ignored, and they are not set as clipped.
1407 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1409 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1410 host_impl_->DidDrawAllLayers(frame);
1413 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) {
1414 root_delegated_render_pass_is_clipped_ = true;
1415 clip_delegated_renderer_layer_ = true;
1416 SetUpTest();
1418 delegated_renderer_layer_->SetHasRenderSurface(true);
1420 LayerTreeHostImpl::FrameData frame;
1421 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1423 ASSERT_EQ(3u, frame.render_passes.size());
1424 const QuadList& contrib_delegated_quad_list =
1425 frame.render_passes[0]->quad_list;
1426 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1427 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1428 ASSERT_EQ(5u, root_delegated_quad_list.size());
1429 const SharedQuadState* root_delegated_shared_quad_state =
1430 root_delegated_quad_list.front()->shared_quad_state;
1432 // When the quads have a clip of their own, it is used, but it is
1433 // combined with the clip rect of the delegated renderer layer. If the
1434 // layer owns a surface, then it does not have a clip rect of its own.
1435 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1436 root_delegated_shared_quad_state->clip_rect.ToString());
1437 // Quads came with a clip rect.
1438 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1440 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1441 host_impl_->DidDrawAllLayers(frame);
1444 TEST_F(DelegatedRendererLayerImplTest, Occlusion) {
1445 gfx::Size layer_size(1000, 1000);
1446 gfx::Size viewport_size(1000, 1000);
1447 gfx::Rect quad_screen_rect(211, 300, 400, 500);
1449 gfx::Transform transform;
1450 transform.Translate(211.0, 300.0);
1452 LayerTestCommon::LayerImplTest impl;
1454 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
1455 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
1456 delegated_renderer_layer_impl->SetBounds(layer_size);
1457 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1458 delegated_renderer_layer_impl->SetDrawsContent(true);
1460 // Contributing render pass is offset by a transform and holds a quad that
1461 // covers it entirely.
1462 RenderPassList delegated_render_passes;
1463 // pass2 is just the size of the quad. It contributes to |pass1| with a
1464 // translation of (211,300).
1465 RenderPassId pass2_id =
1466 delegated_renderer_layer_impl->FirstContributingRenderPassId();
1467 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
1468 pass2_id,
1469 gfx::Rect(quad_screen_rect.size()),
1470 transform);
1471 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
1472 // |pass1| covers the whole layer.
1473 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
1474 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1475 pass1_id,
1476 gfx::Rect(layer_size),
1477 gfx::Transform());
1478 AddRenderPassQuad(pass1,
1479 pass2,
1481 FilterOperations(),
1482 transform,
1483 SkXfermode::kSrcOver_Mode);
1484 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1485 1.f, delegated_render_passes);
1487 impl.CalcDrawProps(viewport_size);
1490 SCOPED_TRACE("No occlusion");
1491 gfx::Rect occluded;
1494 SCOPED_TRACE("Root render pass");
1495 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1496 occluded);
1497 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1->quad_list,
1498 quad_screen_rect);
1499 ASSERT_EQ(1u, pass1->quad_list.size());
1500 EXPECT_EQ(DrawQuad::RENDER_PASS, pass1->quad_list.front()->material);
1503 SCOPED_TRACE("Contributing render pass");
1504 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1505 occluded);
1506 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1507 pass2->quad_list, gfx::Rect(quad_screen_rect.size()));
1508 ASSERT_EQ(1u, pass2->quad_list.size());
1509 EXPECT_EQ(DrawQuad::SOLID_COLOR, pass2->quad_list.front()->material);
1514 SCOPED_TRACE("Full occlusion");
1516 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1518 SCOPED_TRACE("Root render pass");
1519 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1520 occluded);
1521 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1->quad_list,
1522 gfx::Rect());
1523 EXPECT_EQ(pass1->quad_list.size(), 0u);
1526 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1528 SCOPED_TRACE("Contributing render pass");
1529 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1530 occluded);
1531 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass2->quad_list,
1532 gfx::Rect());
1533 EXPECT_EQ(pass2->quad_list.size(), 0u);
1538 SCOPED_TRACE("Partial occlusion");
1540 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1542 SCOPED_TRACE("Root render pass");
1543 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1544 occlusion_in_root_target);
1545 size_t partially_occluded_count = 0;
1546 LayerTestCommon::VerifyQuadsAreOccluded(pass1->quad_list,
1547 occlusion_in_root_target,
1548 &partially_occluded_count);
1549 // The layer outputs one quad, which is partially occluded.
1550 EXPECT_EQ(1u, pass1->quad_list.size());
1551 EXPECT_EQ(1u, partially_occluded_count);
1554 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1555 // Move the occlusion to where it is in the contributing surface.
1556 gfx::Rect occlusion_in_target_of_delegated_quad =
1557 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1559 SCOPED_TRACE("Contributing render pass");
1560 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1561 occlusion_in_root_target);
1562 size_t partially_occluded_count = 0;
1563 LayerTestCommon::VerifyQuadsAreOccluded(
1564 pass2->quad_list, occlusion_in_target_of_delegated_quad,
1565 &partially_occluded_count);
1566 // The layer outputs one quad, which is partially occluded.
1567 EXPECT_EQ(1u, pass2->quad_list.size());
1568 EXPECT_EQ(1u, partially_occluded_count);
1569 // The quad in the contributing surface is at (211,300) in the root.
1570 // The occlusion extends to 500 in the x-axis, pushing the left of the
1571 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1572 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1573 pass2->quad_list.front()->visible_rect.ToString());
1576 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1577 // Move the occlusion to where it is in the contributing surface.
1578 gfx::Rect occlusion_in_target_of_delegated_quad =
1579 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1581 SCOPED_TRACE("Contributing render pass with transformed root");
1583 gfx::Transform layer_transform;
1584 layer_transform.Translate(11.0, 0.0);
1585 delegated_renderer_layer_impl->SetTransform(layer_transform);
1587 occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0);
1589 impl.CalcDrawProps(viewport_size);
1591 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1592 occlusion_in_root_target);
1593 size_t partially_occluded_count = 0;
1594 LayerTestCommon::VerifyQuadsAreOccluded(
1595 pass2->quad_list, occlusion_in_target_of_delegated_quad,
1596 &partially_occluded_count);
1597 // The layer outputs one quad, which is partially occluded.
1598 EXPECT_EQ(1u, pass2->quad_list.size());
1599 EXPECT_EQ(1u, partially_occluded_count);
1600 // The quad in the contributing surface is at (222,300) in the transformed
1601 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1602 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1603 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1604 pass2->quad_list.front()->visible_rect.ToString());
1609 TEST_F(DelegatedRendererLayerImplTest, DeviceScaleFactorOcclusion) {
1610 gfx::Size layer_size(1000, 1000);
1611 gfx::Size viewport_size(1000, 1000);
1612 gfx::Rect quad_screen_rect(211, 300, 400, 500);
1614 gfx::Transform transform;
1615 transform.Translate(211.f, 300.f);
1617 LayerTestCommon::LayerImplTest impl;
1619 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
1620 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
1621 delegated_renderer_layer_impl->SetBounds(layer_size);
1622 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1623 delegated_renderer_layer_impl->SetDrawsContent(true);
1625 // Contributing render pass is offset by a transform and holds a quad that
1626 // covers it entirely.
1627 RenderPassList delegated_render_passes;
1628 // pass2 is just the size of the quad. It contributes to |pass1| with a
1629 // translation of (211,300).
1630 RenderPassId pass2_id =
1631 delegated_renderer_layer_impl->FirstContributingRenderPassId();
1632 TestRenderPass* pass2 =
1633 AddRenderPass(&delegated_render_passes, pass2_id,
1634 gfx::Rect(quad_screen_rect.size()), transform);
1635 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
1636 // |pass1| covers the whole layer.
1637 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
1638 TestRenderPass* pass1 =
1639 AddRenderPass(&delegated_render_passes, pass1_id, gfx::Rect(layer_size),
1640 gfx::Transform());
1641 AddRenderPassQuad(pass1, pass2, 0, FilterOperations(), transform,
1642 SkXfermode::kSrcOver_Mode);
1643 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1644 1.2f, delegated_render_passes);
1647 SCOPED_TRACE("Partial occlusion");
1649 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1650 // Move the occlusion to where it is in the contributing surface.
1651 gfx::Rect occlusion_in_target_of_delegated_quad =
1652 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1654 SCOPED_TRACE("Contributing render pass");
1655 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1656 occlusion_in_root_target);
1657 size_t partially_occluded_count = 0;
1658 LayerTestCommon::VerifyQuadsAreOccluded(
1659 pass2->quad_list, occlusion_in_target_of_delegated_quad,
1660 &partially_occluded_count);
1661 // The layer outputs one quad, which is partially occluded.
1662 EXPECT_EQ(1u, pass2->quad_list.size());
1663 EXPECT_EQ(1u, partially_occluded_count);
1664 // The quad in the contributing surface is at (211,300) in the root.
1665 // The occlusion extends to 500 * 1.2 (dsf) = 600 in the x-axis, pushing
1666 // the left of the visible part of the quad to 600 - 211 = 400 - 11 inside
1667 // the quad.
1668 EXPECT_EQ(gfx::Rect(400 - 11, 0, 11, 500).ToString(),
1669 pass2->quad_list.front()->visible_rect.ToString());
1674 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) {
1675 gfx::Size layer_size(1000, 1000);
1677 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl =
1678 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5);
1679 delegated_renderer_layer_impl->SetBounds(layer_size);
1680 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1681 delegated_renderer_layer_impl->SetDrawsContent(true);
1683 RenderPassList delegated_render_passes;
1684 // |pass1| covers the whole layer.
1685 RenderPassId pass1_id = RenderPassId(5, 0);
1686 AddRenderPass(&delegated_render_passes,
1687 pass1_id,
1688 gfx::Rect(layer_size),
1689 gfx::Transform());
1690 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1691 2.f, delegated_render_passes);
1692 EXPECT_EQ(0.5f, delegated_renderer_layer_impl->inverse_device_scale_factor());
1694 scoped_ptr<DelegatedRendererLayerImpl> other_layer =
1695 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6);
1697 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get());
1699 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor());
1702 } // namespace
1703 } // namespace cc