Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer_impl_unittest.cc
blobce6ab56ac07aa18ab86abbebea450dd6a3d3b5a9
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/delegated_renderer_layer_impl.h"
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "cc/layers/solid_color_layer_impl.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/test/fake_delegated_renderer_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_layer_tree_host_impl_client.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_proxy.h"
16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/test/layer_test_common.h"
18 #include "cc/test/render_pass_test_common.h"
19 #include "cc/test/render_pass_test_utils.h"
20 #include "cc/test/test_shared_bitmap_manager.h"
21 #include "cc/test/test_web_graphics_context_3d.h"
22 #include "cc/trees/layer_tree_host_impl.h"
23 #include "cc/trees/layer_tree_impl.h"
24 #include "cc/trees/single_thread_proxy.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/frame_time.h"
27 #include "ui/gfx/transform.h"
29 namespace cc {
30 namespace {
32 class DelegatedRendererLayerImplTest : public testing::Test {
33 public:
34 DelegatedRendererLayerImplTest()
35 : proxy_(),
36 always_impl_thread_and_main_thread_blocked_(&proxy_) {
37 LayerTreeSettings settings;
38 settings.minimum_occlusion_tracking_size = gfx::Size();
40 host_impl_.reset(
41 new FakeLayerTreeHostImpl(settings, &proxy_, &shared_bitmap_manager_));
42 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
43 host_impl_->SetViewportSize(gfx::Size(10, 10));
46 protected:
47 FakeProxy proxy_;
48 DebugScopedSetImplThreadAndMainThreadBlocked
49 always_impl_thread_and_main_thread_blocked_;
50 TestSharedBitmapManager shared_bitmap_manager_;
51 scoped_ptr<LayerTreeHostImpl> host_impl_;
54 class DelegatedRendererLayerImplTestSimple
55 : public DelegatedRendererLayerImplTest {
56 public:
57 DelegatedRendererLayerImplTestSimple()
58 : DelegatedRendererLayerImplTest() {
59 scoped_ptr<LayerImpl> root_layer =
60 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
61 scoped_ptr<LayerImpl> layer_before =
62 SolidColorLayerImpl::Create(host_impl_->active_tree(), 2);
63 scoped_ptr<LayerImpl> layer_after =
64 SolidColorLayerImpl::Create(host_impl_->active_tree(), 3);
65 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
66 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
68 host_impl_->SetViewportSize(gfx::Size(100, 100));
69 root_layer->SetBounds(gfx::Size(100, 100));
70 root_layer->SetHasRenderSurface(true);
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->SetHasRenderSurface(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->SetHasRenderSurface(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 root_layer_ = root_layer.get();
113 layer_before_ = layer_before.get();
114 layer_after_ = layer_after.get();
115 delegated_renderer_layer_ = delegated_renderer_layer.get();
117 // Force the delegated RenderPasses to come before the RenderPass from
118 // layer_after.
119 layer_after->AddChild(delegated_renderer_layer.Pass());
120 root_layer->AddChild(layer_after.Pass());
122 // Get the RenderPass generated by layer_before to come before the delegated
123 // RenderPasses.
124 root_layer->AddChild(layer_before.Pass());
125 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
128 protected:
129 LayerImpl* root_layer_;
130 LayerImpl* layer_before_;
131 LayerImpl* layer_after_;
132 DelegatedRendererLayerImpl* delegated_renderer_layer_;
135 TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
136 LayerTreeHostImpl::FrameData frame;
137 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
139 // Each non-DelegatedRendererLayer added one RenderPass. The
140 // DelegatedRendererLayer added two contributing passes.
141 ASSERT_EQ(5u, frame.render_passes.size());
143 // The DelegatedRendererLayer should have added its contributing RenderPasses
144 // to the frame.
145 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
146 EXPECT_EQ(1, frame.render_passes[1]->id.index);
147 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
148 EXPECT_EQ(2, frame.render_passes[2]->id.index);
149 // And all other RenderPasses should be non-delegated.
150 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
151 EXPECT_EQ(0, frame.render_passes[0]->id.index);
152 EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
153 EXPECT_EQ(0, frame.render_passes[3]->id.index);
154 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
155 EXPECT_EQ(0, frame.render_passes[4]->id.index);
157 // The DelegatedRendererLayer should have added its RenderPasses to the frame
158 // in order.
159 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
160 frame.render_passes[1]->output_rect.ToString());
161 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
162 frame.render_passes[2]->output_rect.ToString());
164 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
165 host_impl_->DidDrawAllLayers(frame);
168 TEST_F(DelegatedRendererLayerImplTestSimple,
169 AddsQuadsToContributingRenderPasses) {
170 LayerTreeHostImpl::FrameData frame;
171 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
173 // Each non-DelegatedRendererLayer added one RenderPass. The
174 // DelegatedRendererLayer added two contributing passes.
175 ASSERT_EQ(5u, frame.render_passes.size());
177 // The DelegatedRendererLayer should have added its contributing RenderPasses
178 // to the frame.
179 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
180 EXPECT_EQ(1, frame.render_passes[1]->id.index);
181 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
182 EXPECT_EQ(2, frame.render_passes[2]->id.index);
184 // The DelegatedRendererLayer should have added copies of its quads to
185 // contributing RenderPasses.
186 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
187 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
188 frame.render_passes[1]->quad_list.front()->rect.ToString());
190 // Verify it added the right quads.
191 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
192 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
193 frame.render_passes[2]->quad_list.front()->rect.ToString());
194 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
195 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
196 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
197 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
198 frame.render_passes[1]->quad_list.front()->rect.ToString());
200 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
201 host_impl_->DidDrawAllLayers(frame);
204 TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
205 LayerTreeHostImpl::FrameData frame;
206 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
208 // Each non-DelegatedRendererLayer added one RenderPass. The
209 // DelegatedRendererLayer added two contributing passes.
210 ASSERT_EQ(5u, frame.render_passes.size());
212 // The layer's target is the RenderPass from layer_after_.
213 EXPECT_EQ(RenderPassId(3, 0), frame.render_passes[3]->id);
215 // The DelegatedRendererLayer should have added copies of quads in its root
216 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
217 ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
219 // Verify it added the right quads.
220 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
221 frame.render_passes[3]->quad_list.front()->rect.ToString());
223 // Its target layer should have a quad as well.
224 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
225 frame.render_passes[3]->quad_list.ElementAt(1)->rect.ToString());
227 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
228 host_impl_->DidDrawAllLayers(frame);
231 TEST_F(DelegatedRendererLayerImplTestSimple,
232 QuadsFromRootRenderPassAreModifiedForTheTarget) {
233 LayerTreeHostImpl::FrameData frame;
234 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
236 // Each non-DelegatedRendererLayer added one RenderPass. The
237 // DelegatedRendererLayer added two contributing passes.
238 ASSERT_EQ(5u, frame.render_passes.size());
240 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
241 // has a translation transform of 1,1. So its root RenderPass' quads should
242 // all be transformed by that combined amount.
243 gfx::Transform transform;
244 transform.Translate(4.0, 4.0);
245 EXPECT_TRANSFORMATION_MATRIX_EQ(
246 transform, frame.render_passes[3]->quad_list.front()->quadTransform());
248 // Quads from non-root RenderPasses should not be shifted though.
249 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
251 EXPECT_TRANSFORMATION_MATRIX_EQ(
252 gfx::Transform(),
253 frame.render_passes[2]->quad_list.front()->quadTransform());
254 EXPECT_TRANSFORMATION_MATRIX_EQ(
255 gfx::Transform(),
256 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
257 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
258 EXPECT_TRANSFORMATION_MATRIX_EQ(
259 gfx::Transform(),
260 frame.render_passes[1]->quad_list.front()->quadTransform());
262 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
263 host_impl_->DidDrawAllLayers(frame);
266 TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
267 LayerTreeHostImpl::FrameData frame;
268 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
270 // The delegated layer has a surface between it and the root.
271 EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
273 // Each non-DelegatedRendererLayer added one RenderPass. The
274 // DelegatedRendererLayer added two contributing passes.
275 ASSERT_EQ(5u, frame.render_passes.size());
277 // The DelegatedRendererLayer is at position 9,9 compared to the root, so all
278 // render pass' transforms to the root should be shifted by this amount.
279 gfx::Transform transform;
280 transform.Translate(9.0, 9.0);
282 // The first contributing surface has a translation of 5, 6.
283 gfx::Transform five_six(1, 0, 0, 1, 5, 6);
285 // The second contributing surface has a translation of 7, 8.
286 gfx::Transform seven_eight(1, 0, 0, 1, 7, 8);
288 EXPECT_TRANSFORMATION_MATRIX_EQ(
289 transform * five_six, frame.render_passes[1]->transform_to_root_target);
290 EXPECT_TRANSFORMATION_MATRIX_EQ(
291 transform * seven_eight,
292 frame.render_passes[2]->transform_to_root_target);
294 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
295 host_impl_->DidDrawAllLayers(frame);
298 class DelegatedRendererLayerImplTestOwnSurface
299 : public DelegatedRendererLayerImplTestSimple {
300 public:
301 DelegatedRendererLayerImplTestOwnSurface()
302 : DelegatedRendererLayerImplTestSimple() {
303 delegated_renderer_layer_->SetHasRenderSurface(true);
307 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
308 LayerTreeHostImpl::FrameData frame;
309 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
311 // Each non-DelegatedRendererLayer added one RenderPass. The
312 // DelegatedRendererLayer added two contributing passes and its owned surface
313 // added one pass.
314 ASSERT_EQ(6u, frame.render_passes.size());
316 // The DelegatedRendererLayer should have added its contributing RenderPasses
317 // to the frame.
318 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
319 EXPECT_EQ(1, frame.render_passes[1]->id.index);
320 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
321 EXPECT_EQ(2, frame.render_passes[2]->id.index);
322 // The DelegatedRendererLayer should have added a RenderPass for its surface
323 // to the frame.
324 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
325 EXPECT_EQ(0, frame.render_passes[3]->id.index);
326 // And all other RenderPasses should be non-delegated.
327 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
328 EXPECT_EQ(0, frame.render_passes[0]->id.index);
329 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
330 EXPECT_EQ(0, frame.render_passes[4]->id.index);
331 EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
332 EXPECT_EQ(0, frame.render_passes[5]->id.index);
334 // The DelegatedRendererLayer should have added its RenderPasses to the frame
335 // in order.
336 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
337 frame.render_passes[1]->output_rect.ToString());
338 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
339 frame.render_passes[2]->output_rect.ToString());
341 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
342 host_impl_->DidDrawAllLayers(frame);
345 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
346 AddsQuadsToContributingRenderPasses) {
347 LayerTreeHostImpl::FrameData frame;
348 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
350 // Each non-DelegatedRendererLayer added one RenderPass. The
351 // DelegatedRendererLayer added two contributing passes and its owned surface
352 // added one pass.
353 ASSERT_EQ(6u, frame.render_passes.size());
355 // The DelegatedRendererLayer should have added its contributing RenderPasses
356 // to the frame.
357 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
358 EXPECT_EQ(1, frame.render_passes[1]->id.index);
359 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
360 EXPECT_EQ(2, frame.render_passes[2]->id.index);
362 // The DelegatedRendererLayer should have added copies of its quads to
363 // contributing RenderPasses.
364 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
365 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
366 frame.render_passes[1]->quad_list.front()->rect.ToString());
368 // Verify it added the right quads.
369 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
371 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
372 frame.render_passes[2]->quad_list.front()->rect.ToString());
373 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
374 frame.render_passes[2]->quad_list.ElementAt(1)->rect.ToString());
375 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
376 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
377 frame.render_passes[1]->quad_list.front()->rect.ToString());
379 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
380 host_impl_->DidDrawAllLayers(frame);
383 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
384 LayerTreeHostImpl::FrameData frame;
385 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
387 // Each non-DelegatedRendererLayer added one RenderPass. The
388 // DelegatedRendererLayer added two contributing passes and its owned surface
389 // added one pass.
390 ASSERT_EQ(6u, frame.render_passes.size());
392 // The layer's target is the RenderPass owned by itself.
393 EXPECT_EQ(RenderPassId(4, 0), frame.render_passes[3]->id);
395 // The DelegatedRendererLayer should have added copies of quads in its root
396 // RenderPass to its target RenderPass.
397 // The layer_after also adds one quad.
398 ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
400 // Verify it added the right quads.
401 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
402 frame.render_passes[3]->quad_list.front()->rect.ToString());
404 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
405 host_impl_->DidDrawAllLayers(frame);
408 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
409 QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
410 LayerTreeHostImpl::FrameData frame;
411 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
413 // Each non-DelegatedRendererLayer added one RenderPass. The
414 // DelegatedRendererLayer added two contributing passes and its owned surface
415 // added one pass.
416 ASSERT_EQ(6u, frame.render_passes.size());
418 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
419 // RenderPass' quads do not need to be translated at all.
420 EXPECT_TRANSFORMATION_MATRIX_EQ(
421 gfx::Transform(),
422 frame.render_passes[3]->quad_list.front()->quadTransform());
424 // Quads from non-root RenderPasses should not be shifted either.
425 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
427 EXPECT_TRANSFORMATION_MATRIX_EQ(
428 gfx::Transform(),
429 frame.render_passes[2]->quad_list.front()->quadTransform());
430 EXPECT_TRANSFORMATION_MATRIX_EQ(
431 gfx::Transform(),
432 frame.render_passes[2]->quad_list.ElementAt(1)->quadTransform());
433 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
434 EXPECT_TRANSFORMATION_MATRIX_EQ(
435 gfx::Transform(),
436 frame.render_passes[1]->quad_list.front()->quadTransform());
438 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
439 host_impl_->DidDrawAllLayers(frame);
442 class DelegatedRendererLayerImplTestTransform
443 : public DelegatedRendererLayerImplTest {
444 public:
445 DelegatedRendererLayerImplTestTransform()
446 : root_delegated_render_pass_is_clipped_(false),
447 delegated_device_scale_factor_(2.f) {}
449 void SetUpTest() {
450 host_impl_->SetDeviceScaleFactor(2.f);
452 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
453 host_impl_->active_tree(), 1);
454 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
455 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
457 host_impl_->SetViewportSize(gfx::Size(200, 200));
458 root_layer->SetBounds(gfx::Size(100, 100));
459 root_layer->SetHasRenderSurface(true);
461 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
462 delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
463 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
464 delegated_renderer_layer->SetDrawsContent(true);
465 gfx::Transform transform;
466 transform.Scale(2.0, 2.0);
467 transform.Translate(8.0, 8.0);
468 delegated_renderer_layer->SetTransform(transform);
470 RenderPassList delegated_render_passes;
472 gfx::Size child_pass_content_bounds(7, 7);
473 gfx::Rect child_pass_rect(20, 20, 7, 7);
474 gfx::Transform child_pass_transform;
475 child_pass_transform.Scale(0.8f, 0.8f);
476 child_pass_transform.Translate(9.0, 9.0);
477 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
478 bool child_pass_clipped = false;
481 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
482 RenderPassId(10, 7),
483 child_pass_rect,
484 gfx::Transform());
485 SharedQuadState* shared_quad_state =
486 pass->CreateAndAppendSharedQuadState();
487 shared_quad_state->SetAll(child_pass_transform,
488 child_pass_content_bounds,
489 child_pass_rect,
490 child_pass_clip_rect,
491 child_pass_clipped,
492 1.f,
493 SkXfermode::kSrcOver_Mode,
496 SolidColorDrawQuad* color_quad;
497 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
498 color_quad->SetNew(shared_quad_state,
499 gfx::Rect(20, 20, 3, 7),
500 gfx::Rect(20, 20, 3, 7),
502 false);
504 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
505 color_quad->SetNew(shared_quad_state,
506 gfx::Rect(23, 20, 4, 7),
507 gfx::Rect(23, 20, 4, 7),
509 false);
512 gfx::Size root_pass_content_bounds(100, 100);
513 gfx::Rect root_pass_rect(0, 0, 100, 100);
514 gfx::Transform root_pass_transform;
515 root_pass_transform.Scale(1.5, 1.5);
516 root_pass_transform.Translate(7.0, 7.0);
517 gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
518 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
520 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
521 RenderPassId(9, 6),
522 root_pass_rect,
523 gfx::Transform());
524 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
525 shared_quad_state->SetAll(root_pass_transform,
526 root_pass_content_bounds,
527 root_pass_rect,
528 root_pass_clip_rect,
529 root_pass_clipped,
530 1.f,
531 SkXfermode::kSrcOver_Mode,
534 RenderPassDrawQuad* render_pass_quad =
535 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
536 render_pass_quad->SetNew(shared_quad_state,
537 gfx::Rect(5, 5, 7, 7), // quad_rect
538 gfx::Rect(5, 5, 7, 7), // visible_rect
539 RenderPassId(10, 7), // render_pass_id
540 0, // mask_resource_id
541 gfx::Vector2dF(), // mask_uv_scale
542 gfx::Size(), // mask_texture_size
543 FilterOperations(), // filters
544 gfx::Vector2dF(), // filters_scale
545 FilterOperations()); // background_filters
547 SolidColorDrawQuad* color_quad;
548 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
549 color_quad->SetNew(shared_quad_state,
550 gfx::Rect(0, 0, 10, 10),
551 gfx::Rect(0, 0, 10, 10),
553 false);
555 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
556 color_quad->SetNew(shared_quad_state,
557 gfx::Rect(0, 10, 10, 10),
558 gfx::Rect(0, 10, 10, 10),
560 false);
562 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
563 color_quad->SetNew(shared_quad_state,
564 gfx::Rect(10, 0, 10, 10),
565 gfx::Rect(10, 0, 10, 10),
567 false);
569 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
570 color_quad->SetNew(shared_quad_state,
571 gfx::Rect(10, 10, 10, 10),
572 gfx::Rect(10, 10, 10, 10),
574 false);
576 delegated_renderer_layer->SetFrameDataForRenderPasses(
577 delegated_device_scale_factor_, delegated_render_passes);
579 root_layer_ = root_layer.get();
580 delegated_renderer_layer_ = delegated_renderer_layer.get();
582 root_layer->AddChild(delegated_renderer_layer.Pass());
583 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
586 void VerifyRenderPasses(
587 const LayerTreeHostImpl::FrameData& frame,
588 size_t num_render_passes,
589 const SharedQuadState** root_delegated_shared_quad_state,
590 const SharedQuadState** contrib_delegated_shared_quad_state) {
591 ASSERT_EQ(num_render_passes, frame.render_passes.size());
592 // The contributing render pass in the DelegatedRendererLayer.
593 EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
594 EXPECT_EQ(1, frame.render_passes[0]->id.index);
595 // The root render pass.
596 EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
597 EXPECT_EQ(0, frame.render_passes.back()->id.index);
599 const QuadList& contrib_delegated_quad_list =
600 frame.render_passes[0]->quad_list;
601 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
603 const QuadList& root_delegated_quad_list =
604 frame.render_passes[1]->quad_list;
605 ASSERT_EQ(5u, root_delegated_quad_list.size());
607 // All quads in a render pass should share the same state.
608 *contrib_delegated_shared_quad_state =
609 contrib_delegated_quad_list.front()->shared_quad_state;
610 EXPECT_EQ(*contrib_delegated_shared_quad_state,
611 contrib_delegated_quad_list.ElementAt(1)->shared_quad_state);
613 *root_delegated_shared_quad_state =
614 root_delegated_quad_list.front()->shared_quad_state;
615 EXPECT_EQ(*root_delegated_shared_quad_state,
616 root_delegated_quad_list.ElementAt(1)->shared_quad_state);
617 EXPECT_EQ(*root_delegated_shared_quad_state,
618 root_delegated_quad_list.ElementAt(2)->shared_quad_state);
619 EXPECT_EQ(*root_delegated_shared_quad_state,
620 root_delegated_quad_list.ElementAt(3)->shared_quad_state);
621 EXPECT_EQ(*root_delegated_shared_quad_state,
622 root_delegated_quad_list.ElementAt(4)->shared_quad_state);
624 EXPECT_NE(*contrib_delegated_shared_quad_state,
625 *root_delegated_shared_quad_state);
628 protected:
629 LayerImpl* root_layer_;
630 DelegatedRendererLayerImpl* delegated_renderer_layer_;
631 bool root_delegated_render_pass_is_clipped_;
632 float delegated_device_scale_factor_;
635 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
636 root_delegated_render_pass_is_clipped_ = false;
637 SetUpTest();
639 LayerTreeHostImpl::FrameData frame;
640 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
642 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
643 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
644 VerifyRenderPasses(
645 frame,
647 &root_delegated_shared_quad_state,
648 &contrib_delegated_shared_quad_state);
650 // When the quads don't have a clip of their own, the clip rect is set to
651 // the drawable_content_rect of the delegated renderer layer.
652 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
653 root_delegated_shared_quad_state->clip_rect.ToString());
655 // Even though the quads in the root pass have no clip of their own, they
656 // inherit the clip rect from the delegated renderer layer if it does not
657 // own a surface.
658 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
660 gfx::Transform expected;
661 // Device scale factor.
662 expected.Scale(2.0, 2.0);
663 // This is the transform from the layer's space to its target.
664 expected.Translate(20, 20);
665 expected.Scale(2.0, 2.0);
666 expected.Translate(8.0, 8.0);
667 // This is the transform within the source frame.
668 // Inverse device scale factor to go from physical space to layer space.
669 expected.Scale(0.5, 0.5);
670 expected.Scale(1.5, 1.5);
671 expected.Translate(7.0, 7.0);
672 EXPECT_TRANSFORMATION_MATRIX_EQ(
673 expected, root_delegated_shared_quad_state->content_to_target_transform);
675 // The contributing render pass should not be transformed from its input.
676 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
677 contrib_delegated_shared_quad_state->clip_rect.ToString());
678 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
679 expected.MakeIdentity();
680 expected.Scale(0.8f, 0.8f);
681 expected.Translate(9.0, 9.0);
682 EXPECT_TRANSFORMATION_MATRIX_EQ(
683 expected,
684 contrib_delegated_shared_quad_state->content_to_target_transform);
686 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
687 host_impl_->DidDrawAllLayers(frame);
690 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
691 root_delegated_render_pass_is_clipped_ = true;
692 SetUpTest();
694 LayerTreeHostImpl::FrameData frame;
695 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
697 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
698 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
699 VerifyRenderPasses(
700 frame,
702 &root_delegated_shared_quad_state,
703 &contrib_delegated_shared_quad_state);
705 // Since the quads have a clip_rect it should be modified by delegated
706 // renderer layer's draw_transform.
707 // The position of the resulting clip_rect is:
708 // (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
709 // layer scale (2) + layer position (20) = 46
710 // The device scale is 2, so everything gets doubled, giving 92.
712 // The size is 35x35 scaled by the device scale.
713 EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
714 root_delegated_shared_quad_state->clip_rect.ToString());
716 // The quads had a clip and it should be preserved.
717 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
719 gfx::Transform expected;
720 // Device scale factor.
721 expected.Scale(2.0, 2.0);
722 // This is the transform from the layer's space to its target.
723 expected.Translate(20, 20);
724 expected.Scale(2.0, 2.0);
725 expected.Translate(8.0, 8.0);
726 // This is the transform within the source frame.
727 // Inverse device scale factor to go from physical space to layer space.
728 expected.Scale(0.5, 0.5);
729 expected.Scale(1.5, 1.5);
730 expected.Translate(7.0, 7.0);
731 EXPECT_TRANSFORMATION_MATRIX_EQ(
732 expected, root_delegated_shared_quad_state->content_to_target_transform);
734 // The contributing render pass should not be transformed from its input.
735 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
736 contrib_delegated_shared_quad_state->clip_rect.ToString());
737 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
738 expected.MakeIdentity();
739 expected.Scale(0.8f, 0.8f);
740 expected.Translate(9.0, 9.0);
741 EXPECT_TRANSFORMATION_MATRIX_EQ(
742 expected,
743 contrib_delegated_shared_quad_state->content_to_target_transform);
745 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
746 host_impl_->DidDrawAllLayers(frame);
749 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
750 root_delegated_render_pass_is_clipped_ = false;
751 SetUpTest();
753 delegated_renderer_layer_->SetHasRenderSurface(true);
755 LayerTreeHostImpl::FrameData frame;
756 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
758 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
759 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
760 VerifyRenderPasses(
761 frame,
763 &root_delegated_shared_quad_state,
764 &contrib_delegated_shared_quad_state);
766 // When the layer owns a surface, then its translation is not part of its
767 // draw transform, but its scale is.
768 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
769 root_delegated_shared_quad_state->clip_rect.ToString());
771 // Since the layer owns a surface it doesn't need to clip its quads, so
772 // unclipped quads remain unclipped.
773 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
775 gfx::Transform expected;
776 // This is the transform within the source frame scaled by the delegated
777 // render layer transform.
778 expected.Scale(3.0, 3.0);
779 expected.Translate(7.0, 7.0);
780 EXPECT_TRANSFORMATION_MATRIX_EQ(
781 expected, root_delegated_shared_quad_state->content_to_target_transform);
783 // The contributing render pass should not be transformed from its input.
784 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
785 contrib_delegated_shared_quad_state->clip_rect.ToString());
786 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
787 expected.MakeIdentity();
788 expected.Scale(0.8f, 0.8f);
789 expected.Translate(9.0, 9.0);
790 EXPECT_TRANSFORMATION_MATRIX_EQ(
791 expected,
792 contrib_delegated_shared_quad_state->content_to_target_transform);
794 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
795 host_impl_->DidDrawAllLayers(frame);
798 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
799 root_delegated_render_pass_is_clipped_ = true;
800 SetUpTest();
802 delegated_renderer_layer_->SetHasRenderSurface(true);
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 layer owns a surface, then its translation is not part of its
816 // draw transform, but its scale is.
817 EXPECT_EQ(gfx::Rect(20, 20, 70, 70).ToString(),
818 root_delegated_shared_quad_state->clip_rect.ToString());
820 // The quads had a clip and it should be preserved.
821 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
823 gfx::Transform expected;
824 // This is the transform within the source frame scaled by the delegated
825 // render layer transform.
826 expected.Scale(3.0, 3.0);
827 expected.Translate(7.0, 7.0);
828 EXPECT_TRANSFORMATION_MATRIX_EQ(
829 expected, root_delegated_shared_quad_state->content_to_target_transform);
831 // The contributing render pass should not be transformed from its input.
832 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
833 contrib_delegated_shared_quad_state->clip_rect.ToString());
834 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
835 expected.MakeIdentity();
836 expected.Scale(0.8f, 0.8f);
837 expected.Translate(9.0, 9.0);
838 EXPECT_TRANSFORMATION_MATRIX_EQ(
839 expected,
840 contrib_delegated_shared_quad_state->content_to_target_transform);
842 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
843 host_impl_->DidDrawAllLayers(frame);
846 TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
847 root_delegated_render_pass_is_clipped_ = true;
848 delegated_device_scale_factor_ = 1.3f;
850 SetUpTest();
852 LayerTreeHostImpl::FrameData frame;
853 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
855 const SharedQuadState* root_delegated_shared_quad_state = nullptr;
856 const SharedQuadState* contrib_delegated_shared_quad_state = nullptr;
857 VerifyRenderPasses(frame,
859 &root_delegated_shared_quad_state,
860 &contrib_delegated_shared_quad_state);
862 // The parent tree's device scale factor is 2.0, but the child has submitted a
863 // frame with a device scale factor of 1.3. Absent any better option, the
864 // only thing we can do is scale from 1.3 -> 2.0.
866 gfx::Transform expected;
867 // Device scale factor (from parent).
868 expected.Scale(2.0, 2.0);
869 // This is the transform from the layer's space to its target.
870 expected.Translate(20, 20);
871 expected.Scale(2.0, 2.0);
872 expected.Translate(8.0, 8.0);
873 // This is the transform within the source frame.
874 // Inverse device scale factor (from child).
875 expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
876 expected.Scale(1.5, 1.5);
877 expected.Translate(7.0, 7.0);
878 EXPECT_TRANSFORMATION_MATRIX_EQ(
879 expected, root_delegated_shared_quad_state->content_to_target_transform);
881 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
882 host_impl_->DidDrawAllLayers(frame);
885 class DelegatedRendererLayerImplTestClip
886 : public DelegatedRendererLayerImplTest {
887 public:
888 void SetUpTest() {
889 scoped_ptr<LayerImpl> root_layer =
890 LayerImpl::Create(host_impl_->active_tree(), 1);
891 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
892 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
893 scoped_ptr<LayerImpl> clip_layer =
894 LayerImpl::Create(host_impl_->active_tree(), 3);
895 scoped_ptr<LayerImpl> origin_layer =
896 LayerImpl::Create(host_impl_->active_tree(), 4);
898 host_impl_->SetViewportSize(gfx::Size(100, 100));
899 root_layer->SetBounds(gfx::Size(100, 100));
900 root_layer->SetHasRenderSurface(true);
902 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
903 delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
904 delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
905 delegated_renderer_layer->SetDrawsContent(true);
907 RenderPassList delegated_render_passes;
909 gfx::Size child_pass_content_bounds(7, 7);
910 gfx::Rect child_pass_rect(20, 20, 7, 7);
911 gfx::Transform child_pass_transform;
912 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
913 bool child_pass_clipped = false;
916 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
917 RenderPassId(10, 7),
918 child_pass_rect,
919 gfx::Transform());
920 SharedQuadState* shared_quad_state =
921 pass->CreateAndAppendSharedQuadState();
922 shared_quad_state->SetAll(child_pass_transform,
923 child_pass_content_bounds,
924 child_pass_rect,
925 child_pass_clip_rect,
926 child_pass_clipped,
927 1.f,
928 SkXfermode::kSrcOver_Mode,
931 SolidColorDrawQuad* color_quad;
932 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
933 color_quad->SetNew(shared_quad_state,
934 gfx::Rect(20, 20, 3, 7),
935 gfx::Rect(20, 20, 3, 7),
937 false);
939 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
940 color_quad->SetNew(shared_quad_state,
941 gfx::Rect(23, 20, 4, 7),
942 gfx::Rect(23, 20, 4, 7),
944 false);
947 gfx::Size root_pass_content_bounds(50, 50);
948 gfx::Rect root_pass_rect(0, 0, 50, 50);
949 gfx::Transform root_pass_transform;
950 gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
951 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
953 TestRenderPass* pass = AddRenderPass(&delegated_render_passes,
954 RenderPassId(9, 6),
955 root_pass_rect,
956 gfx::Transform());
957 SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
958 shared_quad_state->SetAll(root_pass_transform,
959 root_pass_content_bounds,
960 root_pass_rect,
961 root_pass_clip_rect,
962 root_pass_clipped,
963 1.f,
964 SkXfermode::kSrcOver_Mode,
967 RenderPassDrawQuad* render_pass_quad =
968 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
969 render_pass_quad->SetNew(shared_quad_state,
970 gfx::Rect(5, 5, 7, 7), // quad_rect
971 gfx::Rect(5, 5, 7, 7), // visible_quad_rect
972 RenderPassId(10, 7), // render_pass_id
973 0, // mask_resource_id
974 gfx::Vector2dF(), // mask_uv_scale
975 gfx::Size(), // mask_texture_size,
976 FilterOperations(), // filters
977 gfx::Vector2dF(), // filters_scale
978 FilterOperations()); // background_filters
980 SolidColorDrawQuad* color_quad;
981 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
982 color_quad->SetNew(shared_quad_state,
983 gfx::Rect(0, 0, 10, 10),
984 gfx::Rect(0, 0, 10, 10),
986 false);
988 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
989 color_quad->SetNew(shared_quad_state,
990 gfx::Rect(0, 10, 10, 10),
991 gfx::Rect(0, 10, 10, 10),
993 false);
995 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
996 color_quad->SetNew(shared_quad_state,
997 gfx::Rect(10, 0, 10, 10),
998 gfx::Rect(10, 0, 10, 10),
1000 false);
1002 color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
1003 color_quad->SetNew(shared_quad_state,
1004 gfx::Rect(10, 10, 10, 10),
1005 gfx::Rect(10, 10, 10, 10),
1007 false);
1009 delegated_renderer_layer->SetFrameDataForRenderPasses(
1010 1.f, delegated_render_passes);
1012 root_layer_ = root_layer.get();
1013 delegated_renderer_layer_ = delegated_renderer_layer.get();
1015 if (clip_delegated_renderer_layer_) {
1016 gfx::Rect clip_rect(21, 27, 23, 21);
1018 clip_layer->SetPosition(clip_rect.origin());
1019 clip_layer->SetBounds(clip_rect.size());
1020 clip_layer->SetContentBounds(clip_rect.size());
1021 clip_layer->SetMasksToBounds(true);
1023 origin_layer->SetPosition(
1024 gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin()));
1026 origin_layer->AddChild(delegated_renderer_layer.Pass());
1027 clip_layer->AddChild(origin_layer.Pass());
1028 root_layer->AddChild(clip_layer.Pass());
1029 } else {
1030 root_layer->AddChild(delegated_renderer_layer.Pass());
1033 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1036 protected:
1037 LayerImpl* root_layer_;
1038 DelegatedRendererLayerImpl* delegated_renderer_layer_;
1039 bool root_delegated_render_pass_is_clipped_;
1040 bool clip_delegated_renderer_layer_;
1043 TEST_F(DelegatedRendererLayerImplTestClip,
1044 QuadsUnclipped_LayerUnclipped_NoSurface) {
1045 root_delegated_render_pass_is_clipped_ = false;
1046 clip_delegated_renderer_layer_ = false;
1047 SetUpTest();
1049 LayerTreeHostImpl::FrameData frame;
1050 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1052 ASSERT_EQ(2u, frame.render_passes.size());
1053 const QuadList& contrib_delegated_quad_list =
1054 frame.render_passes[0]->quad_list;
1055 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1056 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1057 ASSERT_EQ(5u, root_delegated_quad_list.size());
1058 const SharedQuadState* root_delegated_shared_quad_state =
1059 root_delegated_quad_list.front()->shared_quad_state;
1061 // When the quads don't have a clip of their own, the clip rect is set to
1062 // the drawable_content_rect of the delegated renderer layer.
1063 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1064 root_delegated_shared_quad_state->clip_rect.ToString());
1065 // Quads are clipped to the delegated renderer layer.
1066 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1068 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1069 host_impl_->DidDrawAllLayers(frame);
1072 TEST_F(DelegatedRendererLayerImplTestClip,
1073 QuadsClipped_LayerUnclipped_NoSurface) {
1074 root_delegated_render_pass_is_clipped_ = true;
1075 clip_delegated_renderer_layer_ = false;
1076 SetUpTest();
1078 LayerTreeHostImpl::FrameData frame;
1079 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1081 ASSERT_EQ(2u, frame.render_passes.size());
1082 const QuadList& contrib_delegated_quad_list =
1083 frame.render_passes[0]->quad_list;
1084 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1085 const QuadList& root_delegated_quad_list =
1086 frame.render_passes[1]->quad_list;
1087 ASSERT_EQ(5u, root_delegated_quad_list.size());
1088 const SharedQuadState* root_delegated_shared_quad_state =
1089 root_delegated_quad_list.front()->shared_quad_state;
1091 // When the quads have a clip of their own, it is used.
1092 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1093 root_delegated_shared_quad_state->clip_rect.ToString());
1094 // Quads came with a clip rect.
1095 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1097 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1098 host_impl_->DidDrawAllLayers(frame);
1101 TEST_F(DelegatedRendererLayerImplTestClip,
1102 QuadsUnclipped_LayerClipped_NoSurface) {
1103 root_delegated_render_pass_is_clipped_ = false;
1104 clip_delegated_renderer_layer_ = true;
1105 SetUpTest();
1107 LayerTreeHostImpl::FrameData frame;
1108 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1110 ASSERT_EQ(2u, frame.render_passes.size());
1111 const QuadList& contrib_delegated_quad_list =
1112 frame.render_passes[0]->quad_list;
1113 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1114 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1115 ASSERT_EQ(5u, root_delegated_quad_list.size());
1116 const SharedQuadState* root_delegated_shared_quad_state =
1117 root_delegated_quad_list.front()->shared_quad_state;
1119 // When the quads don't have a clip of their own, the clip rect is set to
1120 // the drawable_content_rect of the delegated renderer layer. When the layer
1121 // is clipped, that should be seen in the quads' clip_rect.
1122 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1123 root_delegated_shared_quad_state->clip_rect.ToString());
1124 // Quads are clipped to the delegated renderer layer.
1125 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1127 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1128 host_impl_->DidDrawAllLayers(frame);
1131 TEST_F(DelegatedRendererLayerImplTestClip,
1132 QuadsClipped_LayerClipped_NoSurface) {
1133 root_delegated_render_pass_is_clipped_ = true;
1134 clip_delegated_renderer_layer_ = true;
1135 SetUpTest();
1137 LayerTreeHostImpl::FrameData frame;
1138 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1140 ASSERT_EQ(2u, frame.render_passes.size());
1141 const QuadList& contrib_delegated_quad_list =
1142 frame.render_passes[0]->quad_list;
1143 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1144 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1145 ASSERT_EQ(5u, root_delegated_quad_list.size());
1146 const SharedQuadState* root_delegated_shared_quad_state =
1147 root_delegated_quad_list.front()->shared_quad_state;
1149 // When the quads have a clip of their own, it is used, but it is
1150 // combined with the clip rect of the delegated renderer layer.
1151 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1152 root_delegated_shared_quad_state->clip_rect.ToString());
1153 // Quads came with a clip rect.
1154 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1156 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1157 host_impl_->DidDrawAllLayers(frame);
1160 TEST_F(DelegatedRendererLayerImplTestClip,
1161 QuadsUnclipped_LayerUnclipped_Surface) {
1162 root_delegated_render_pass_is_clipped_ = false;
1163 clip_delegated_renderer_layer_ = false;
1164 SetUpTest();
1166 delegated_renderer_layer_->SetHasRenderSurface(true);
1168 LayerTreeHostImpl::FrameData frame;
1169 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1171 ASSERT_EQ(3u, frame.render_passes.size());
1172 const QuadList& contrib_delegated_quad_list =
1173 frame.render_passes[0]->quad_list;
1174 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1175 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1176 ASSERT_EQ(5u, root_delegated_quad_list.size());
1177 const SharedQuadState* root_delegated_shared_quad_state =
1178 root_delegated_quad_list.front()->shared_quad_state;
1180 // When the layer owns a surface, the quads don't need to be clipped
1181 // further than they already specify. If they aren't clipped, then their
1182 // clip rect is ignored, and they are not set as clipped.
1183 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1185 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1186 host_impl_->DidDrawAllLayers(frame);
1189 TEST_F(DelegatedRendererLayerImplTestClip,
1190 QuadsClipped_LayerUnclipped_Surface) {
1191 root_delegated_render_pass_is_clipped_ = true;
1192 clip_delegated_renderer_layer_ = false;
1193 SetUpTest();
1195 delegated_renderer_layer_->SetHasRenderSurface(true);
1197 LayerTreeHostImpl::FrameData frame;
1198 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1200 ASSERT_EQ(3u, frame.render_passes.size());
1201 const QuadList& contrib_delegated_quad_list =
1202 frame.render_passes[0]->quad_list;
1203 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1204 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1205 ASSERT_EQ(5u, root_delegated_quad_list.size());
1206 const SharedQuadState* root_delegated_shared_quad_state =
1207 root_delegated_quad_list.front()->shared_quad_state;
1209 // When the quads have a clip of their own, it is used.
1210 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1211 root_delegated_shared_quad_state->clip_rect.ToString());
1212 // Quads came with a clip rect.
1213 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1215 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1216 host_impl_->DidDrawAllLayers(frame);
1219 TEST_F(DelegatedRendererLayerImplTestClip,
1220 QuadsUnclipped_LayerClipped_Surface) {
1221 root_delegated_render_pass_is_clipped_ = false;
1222 clip_delegated_renderer_layer_ = true;
1223 SetUpTest();
1225 delegated_renderer_layer_->SetHasRenderSurface(true);
1227 LayerTreeHostImpl::FrameData frame;
1228 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1230 ASSERT_EQ(3u, frame.render_passes.size());
1231 const QuadList& contrib_delegated_quad_list =
1232 frame.render_passes[0]->quad_list;
1233 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1234 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1235 ASSERT_EQ(5u, root_delegated_quad_list.size());
1236 const SharedQuadState* root_delegated_shared_quad_state =
1237 root_delegated_quad_list.front()->shared_quad_state;
1239 // When the layer owns a surface, the quads don't need to be clipped
1240 // further than they already specify. If they aren't clipped, then their
1241 // clip rect is ignored, and they are not set as clipped.
1242 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1244 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1245 host_impl_->DidDrawAllLayers(frame);
1248 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) {
1249 root_delegated_render_pass_is_clipped_ = true;
1250 clip_delegated_renderer_layer_ = true;
1251 SetUpTest();
1253 delegated_renderer_layer_->SetHasRenderSurface(true);
1255 LayerTreeHostImpl::FrameData frame;
1256 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1258 ASSERT_EQ(3u, frame.render_passes.size());
1259 const QuadList& contrib_delegated_quad_list =
1260 frame.render_passes[0]->quad_list;
1261 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1262 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1263 ASSERT_EQ(5u, root_delegated_quad_list.size());
1264 const SharedQuadState* root_delegated_shared_quad_state =
1265 root_delegated_quad_list.front()->shared_quad_state;
1267 // When the quads have a clip of their own, it is used, but it is
1268 // combined with the clip rect of the delegated renderer layer. If the
1269 // layer owns a surface, then it does not have a clip rect of its own.
1270 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1271 root_delegated_shared_quad_state->clip_rect.ToString());
1272 // Quads came with a clip rect.
1273 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1275 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1276 host_impl_->DidDrawAllLayers(frame);
1279 TEST_F(DelegatedRendererLayerImplTest, InvalidRenderPassDrawQuad) {
1280 scoped_ptr<LayerImpl> root_layer =
1281 LayerImpl::Create(host_impl_->active_tree(), 1);
1282 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
1283 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
1285 host_impl_->SetViewportSize(gfx::Size(100, 100));
1286 root_layer->SetHasRenderSurface(true);
1288 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
1289 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
1290 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
1291 delegated_renderer_layer->SetDrawsContent(true);
1293 RenderPassList delegated_render_passes;
1294 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1295 RenderPassId(9, 6),
1296 gfx::Rect(0, 0, 10, 10),
1297 gfx::Transform());
1298 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
1300 // This render pass isn't part of the frame.
1301 scoped_ptr<TestRenderPass> missing_pass(TestRenderPass::Create());
1302 missing_pass->SetNew(RenderPassId(9, 7),
1303 gfx::Rect(7, 7, 7, 7),
1304 gfx::Rect(7, 7, 7, 7),
1305 gfx::Transform());
1307 // But a render pass quad refers to it.
1308 AddRenderPassQuad(pass1, missing_pass.get());
1310 delegated_renderer_layer->SetFrameDataForRenderPasses(
1311 1.f, delegated_render_passes);
1313 root_layer->AddChild(delegated_renderer_layer.Pass());
1314 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1316 LayerTreeHostImpl::FrameData frame;
1317 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
1319 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1320 ASSERT_EQ(1u, frame.render_passes.size());
1321 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
1322 EXPECT_EQ(DrawQuad::SOLID_COLOR,
1323 frame.render_passes[0]->quad_list.front()->material);
1325 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now());
1326 host_impl_->DidDrawAllLayers(frame);
1329 TEST_F(DelegatedRendererLayerImplTest, Occlusion) {
1330 gfx::Size layer_size(1000, 1000);
1331 gfx::Size viewport_size(1000, 1000);
1332 gfx::Rect quad_screen_rect(211, 300, 400, 500);
1334 gfx::Transform transform;
1335 transform.Translate(211.0, 300.0);
1337 LayerTestCommon::LayerImplTest impl;
1339 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl =
1340 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>();
1341 delegated_renderer_layer_impl->SetBounds(layer_size);
1342 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1343 delegated_renderer_layer_impl->SetDrawsContent(true);
1345 // Contributing render pass is offset by a transform and holds a quad that
1346 // covers it entirely.
1347 RenderPassList delegated_render_passes;
1348 // pass2 is just the size of the quad. It contributes to |pass1| with a
1349 // translation of (211,300).
1350 RenderPassId pass2_id =
1351 delegated_renderer_layer_impl->FirstContributingRenderPassId();
1352 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
1353 pass2_id,
1354 gfx::Rect(quad_screen_rect.size()),
1355 transform);
1356 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED);
1357 // |pass1| covers the whole layer.
1358 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0);
1359 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
1360 pass1_id,
1361 gfx::Rect(layer_size),
1362 gfx::Transform());
1363 AddRenderPassQuad(pass1,
1364 pass2,
1366 FilterOperations(),
1367 transform,
1368 SkXfermode::kSrcOver_Mode);
1369 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1370 1.f, delegated_render_passes);
1372 impl.CalcDrawProps(viewport_size);
1375 SCOPED_TRACE("No occlusion");
1376 gfx::Rect occluded;
1379 SCOPED_TRACE("Root render pass");
1380 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1381 occluded);
1382 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1->quad_list,
1383 quad_screen_rect);
1384 ASSERT_EQ(1u, pass1->quad_list.size());
1385 EXPECT_EQ(DrawQuad::RENDER_PASS, pass1->quad_list.front()->material);
1388 SCOPED_TRACE("Contributing render pass");
1389 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1390 occluded);
1391 LayerTestCommon::VerifyQuadsExactlyCoverRect(
1392 pass2->quad_list, gfx::Rect(quad_screen_rect.size()));
1393 ASSERT_EQ(1u, pass2->quad_list.size());
1394 EXPECT_EQ(DrawQuad::SOLID_COLOR, pass2->quad_list.front()->material);
1399 SCOPED_TRACE("Full occlusion");
1401 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1403 SCOPED_TRACE("Root render pass");
1404 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1405 occluded);
1406 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass1->quad_list,
1407 gfx::Rect());
1408 EXPECT_EQ(pass1->quad_list.size(), 0u);
1411 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect());
1413 SCOPED_TRACE("Contributing render pass");
1414 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1415 occluded);
1416 LayerTestCommon::VerifyQuadsExactlyCoverRect(pass2->quad_list,
1417 gfx::Rect());
1418 EXPECT_EQ(pass2->quad_list.size(), 0u);
1423 SCOPED_TRACE("Partial occlusion");
1425 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1427 SCOPED_TRACE("Root render pass");
1428 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass1,
1429 occlusion_in_root_target);
1430 size_t partially_occluded_count = 0;
1431 LayerTestCommon::VerifyQuadsAreOccluded(pass1->quad_list,
1432 occlusion_in_root_target,
1433 &partially_occluded_count);
1434 // The layer outputs one quad, which is partially occluded.
1435 EXPECT_EQ(1u, pass1->quad_list.size());
1436 EXPECT_EQ(1u, partially_occluded_count);
1439 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1440 // Move the occlusion to where it is in the contributing surface.
1441 gfx::Rect occlusion_in_target_of_delegated_quad =
1442 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1444 SCOPED_TRACE("Contributing render pass");
1445 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1446 occlusion_in_root_target);
1447 size_t partially_occluded_count = 0;
1448 LayerTestCommon::VerifyQuadsAreOccluded(
1449 pass2->quad_list, occlusion_in_target_of_delegated_quad,
1450 &partially_occluded_count);
1451 // The layer outputs one quad, which is partially occluded.
1452 EXPECT_EQ(1u, pass2->quad_list.size());
1453 EXPECT_EQ(1u, partially_occluded_count);
1454 // The quad in the contributing surface is at (211,300) in the root.
1455 // The occlusion extends to 500 in the x-axis, pushing the left of the
1456 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad.
1457 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(),
1458 pass2->quad_list.front()->visible_rect.ToString());
1461 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000);
1462 // Move the occlusion to where it is in the contributing surface.
1463 gfx::Rect occlusion_in_target_of_delegated_quad =
1464 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin();
1466 SCOPED_TRACE("Contributing render pass with transformed root");
1468 gfx::Transform layer_transform;
1469 layer_transform.Translate(11.0, 0.0);
1470 delegated_renderer_layer_impl->SetTransform(layer_transform);
1472 occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0);
1474 impl.CalcDrawProps(viewport_size);
1476 impl.AppendQuadsForPassWithOcclusion(delegated_renderer_layer_impl, pass2,
1477 occlusion_in_root_target);
1478 size_t partially_occluded_count = 0;
1479 LayerTestCommon::VerifyQuadsAreOccluded(
1480 pass2->quad_list, occlusion_in_target_of_delegated_quad,
1481 &partially_occluded_count);
1482 // The layer outputs one quad, which is partially occluded.
1483 EXPECT_EQ(1u, pass2->quad_list.size());
1484 EXPECT_EQ(1u, partially_occluded_count);
1485 // The quad in the contributing surface is at (222,300) in the transformed
1486 // root. The occlusion extends to 500 in the x-axis, pushing the left of
1487 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad.
1488 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(),
1489 pass2->quad_list.front()->visible_rect.ToString());
1494 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) {
1495 gfx::Size layer_size(1000, 1000);
1497 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl =
1498 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5);
1499 delegated_renderer_layer_impl->SetBounds(layer_size);
1500 delegated_renderer_layer_impl->SetContentBounds(layer_size);
1501 delegated_renderer_layer_impl->SetDrawsContent(true);
1503 RenderPassList delegated_render_passes;
1504 // |pass1| covers the whole layer.
1505 RenderPassId pass1_id = RenderPassId(5, 0);
1506 AddRenderPass(&delegated_render_passes,
1507 pass1_id,
1508 gfx::Rect(layer_size),
1509 gfx::Transform());
1510 delegated_renderer_layer_impl->SetFrameDataForRenderPasses(
1511 2.f, delegated_render_passes);
1512 EXPECT_EQ(0.5f, delegated_renderer_layer_impl->inverse_device_scale_factor());
1514 scoped_ptr<DelegatedRendererLayerImpl> other_layer =
1515 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6);
1517 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get());
1519 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor());
1522 } // namespace
1523 } // namespace cc