Adding a logging class to cast.
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer_impl_unittest.cc
blob58fa36692e68674f6ac0fbd5c277b78a7285f204
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/debug/test_web_graphics_context_3d.h"
9 #include "cc/layers/append_quads_data.h"
10 #include "cc/layers/quad_sink.h"
11 #include "cc/layers/solid_color_layer_impl.h"
12 #include "cc/quads/render_pass_draw_quad.h"
13 #include "cc/quads/solid_color_draw_quad.h"
14 #include "cc/test/fake_delegated_renderer_layer_impl.h"
15 #include "cc/test/fake_layer_tree_host_impl.h"
16 #include "cc/test/fake_layer_tree_host_impl_client.h"
17 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_proxy.h"
19 #include "cc/test/fake_rendering_stats_instrumentation.h"
20 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/mock_quad_culler.h"
22 #include "cc/test/render_pass_test_common.h"
23 #include "cc/test/render_pass_test_utils.h"
24 #include "cc/trees/layer_tree_host_impl.h"
25 #include "cc/trees/layer_tree_impl.h"
26 #include "cc/trees/single_thread_proxy.h"
27 #include "testing/gtest/include/gtest/gtest.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(settings, &proxy_));
42 host_impl_->InitializeRenderer(CreateFakeOutputSurface());
43 host_impl_->SetViewportSize(gfx::Size(10, 10));
46 protected:
47 FakeProxy proxy_;
48 DebugScopedSetImplThreadAndMainThreadBlocked
49 always_impl_thread_and_main_thread_blocked_;
50 scoped_ptr<LayerTreeHostImpl> host_impl_;
53 class DelegatedRendererLayerImplTestSimple
54 : public DelegatedRendererLayerImplTest {
55 public:
56 DelegatedRendererLayerImplTestSimple()
57 : DelegatedRendererLayerImplTest() {
58 scoped_ptr<LayerImpl> root_layer = SolidColorLayerImpl::Create(
59 host_impl_->active_tree(), 1).PassAs<LayerImpl>();
60 scoped_ptr<LayerImpl> layer_before = SolidColorLayerImpl::Create(
61 host_impl_->active_tree(), 2).PassAs<LayerImpl>();
62 scoped_ptr<LayerImpl> layer_after = SolidColorLayerImpl::Create(
63 host_impl_->active_tree(), 3).PassAs<LayerImpl>();
64 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
65 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
67 host_impl_->SetViewportSize(gfx::Size(100, 100));
68 root_layer->SetBounds(gfx::Size(100, 100));
70 layer_before->SetPosition(gfx::Point(20, 20));
71 layer_before->SetBounds(gfx::Size(14, 14));
72 layer_before->SetContentBounds(gfx::Size(14, 14));
73 layer_before->SetDrawsContent(true);
74 layer_before->SetForceRenderSurface(true);
76 layer_after->SetPosition(gfx::Point(5, 5));
77 layer_after->SetBounds(gfx::Size(15, 15));
78 layer_after->SetContentBounds(gfx::Size(15, 15));
79 layer_after->SetDrawsContent(true);
80 layer_after->SetForceRenderSurface(true);
82 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
83 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
84 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
85 delegated_renderer_layer->SetDrawsContent(true);
86 gfx::Transform transform;
87 transform.Translate(1.0, 1.0);
88 delegated_renderer_layer->SetTransform(transform);
90 ScopedPtrVector<RenderPass> delegated_render_passes;
91 TestRenderPass* pass1 = AddRenderPass(
92 &delegated_render_passes,
93 RenderPass::Id(9, 6),
94 gfx::Rect(6, 6, 6, 6),
95 gfx::Transform());
96 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
97 TestRenderPass* pass2 = AddRenderPass(
98 &delegated_render_passes,
99 RenderPass::Id(9, 7),
100 gfx::Rect(7, 7, 7, 7),
101 gfx::Transform());
102 AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
103 AddRenderPassQuad(pass2, pass1);
104 TestRenderPass* pass3 = AddRenderPass(
105 &delegated_render_passes,
106 RenderPass::Id(9, 8),
107 gfx::Rect(0, 0, 8, 8),
108 gfx::Transform());
109 AddRenderPassQuad(pass3, pass2);
110 delegated_renderer_layer->SetFrameDataForRenderPasses(
111 &delegated_render_passes);
113 // The RenderPasses should be taken by the layer.
114 EXPECT_EQ(0u, delegated_render_passes.size());
116 root_layer_ = root_layer.get();
117 layer_before_ = layer_before.get();
118 layer_after_ = layer_after.get();
119 delegated_renderer_layer_ = delegated_renderer_layer.get();
121 // Force the delegated RenderPasses to come before the RenderPass from
122 // layer_after.
123 layer_after->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
124 root_layer->AddChild(layer_after.Pass());
126 // Get the RenderPass generated by layer_before to come before the delegated
127 // RenderPasses.
128 root_layer->AddChild(layer_before.Pass());
129 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
132 protected:
133 LayerImpl* root_layer_;
134 LayerImpl* layer_before_;
135 LayerImpl* layer_after_;
136 DelegatedRendererLayerImpl* delegated_renderer_layer_;
139 TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
140 LayerTreeHostImpl::FrameData frame;
141 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
143 // Each non-DelegatedRendererLayer added one RenderPass. The
144 // DelegatedRendererLayer added two contributing passes.
145 ASSERT_EQ(5u, frame.render_passes.size());
147 // The DelegatedRendererLayer should have added its contributing RenderPasses
148 // to the frame.
149 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
150 EXPECT_EQ(1, frame.render_passes[1]->id.index);
151 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
152 EXPECT_EQ(2, frame.render_passes[2]->id.index);
153 // And all other RenderPasses should be non-delegated.
154 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
155 EXPECT_EQ(0, frame.render_passes[0]->id.index);
156 EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
157 EXPECT_EQ(0, frame.render_passes[3]->id.index);
158 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
159 EXPECT_EQ(0, frame.render_passes[4]->id.index);
161 // The DelegatedRendererLayer should have added its RenderPasses to the frame
162 // in order.
163 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
164 frame.render_passes[1]->output_rect.ToString());
165 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
166 frame.render_passes[2]->output_rect.ToString());
168 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
169 host_impl_->DidDrawAllLayers(frame);
172 TEST_F(DelegatedRendererLayerImplTestSimple,
173 AddsQuadsToContributingRenderPasses) {
174 LayerTreeHostImpl::FrameData frame;
175 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
177 // Each non-DelegatedRendererLayer added one RenderPass. The
178 // DelegatedRendererLayer added two contributing passes.
179 ASSERT_EQ(5u, frame.render_passes.size());
181 // The DelegatedRendererLayer should have added its contributing RenderPasses
182 // to the frame.
183 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
184 EXPECT_EQ(1, frame.render_passes[1]->id.index);
185 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
186 EXPECT_EQ(2, frame.render_passes[2]->id.index);
188 // The DelegatedRendererLayer should have added copies of its quads to
189 // contributing RenderPasses.
190 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
191 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
192 frame.render_passes[1]->quad_list[0]->rect.ToString());
194 // Verify it added the right quads.
195 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
196 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
197 frame.render_passes[2]->quad_list[0]->rect.ToString());
198 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
199 frame.render_passes[2]->quad_list[1]->rect.ToString());
200 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
201 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
202 frame.render_passes[1]->quad_list[0]->rect.ToString());
204 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
205 host_impl_->DidDrawAllLayers(frame);
208 TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
209 LayerTreeHostImpl::FrameData frame;
210 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
212 // Each non-DelegatedRendererLayer added one RenderPass. The
213 // DelegatedRendererLayer added two contributing passes.
214 ASSERT_EQ(5u, frame.render_passes.size());
216 // The layer's target is the RenderPass from layer_after_.
217 EXPECT_EQ(RenderPass::Id(3, 0), frame.render_passes[3]->id);
219 // The DelegatedRendererLayer should have added copies of quads in its root
220 // RenderPass to its target RenderPass. The layer_after_ also adds one quad.
221 ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
223 // Verify it added the right quads.
224 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
225 frame.render_passes[3]->quad_list[0]->rect.ToString());
227 // Its target layer should have a quad as well.
228 EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
229 frame.render_passes[3]->quad_list[1]->rect.ToString());
231 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
232 host_impl_->DidDrawAllLayers(frame);
235 TEST_F(DelegatedRendererLayerImplTestSimple,
236 QuadsFromRootRenderPassAreModifiedForTheTarget) {
237 LayerTreeHostImpl::FrameData frame;
238 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
240 // Each non-DelegatedRendererLayer added one RenderPass. The
241 // DelegatedRendererLayer added two contributing passes.
242 ASSERT_EQ(5u, frame.render_passes.size());
244 // The DelegatedRendererLayer is at position 3,3 compared to its target, and
245 // has a translation transform of 1,1. So its root RenderPass' quads should
246 // all be transformed by that combined amount.
247 // The DelegatedRendererLayer has a size of 10x10, but the root delegated
248 // RenderPass has a size of 8x8, so any quads should be scaled by 10/8.
249 gfx::Transform transform;
250 transform.Translate(4.0, 4.0);
251 transform.Scale(10.0 / 8.0, 10.0 / 8.0);
252 EXPECT_TRANSFORMATION_MATRIX_EQ(
253 transform, frame.render_passes[3]->quad_list[0]->quadTransform());
255 // Quads from non-root RenderPasses should not be shifted though.
256 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
257 EXPECT_TRANSFORMATION_MATRIX_EQ(
258 gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
259 EXPECT_TRANSFORMATION_MATRIX_EQ(
260 gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
261 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
262 EXPECT_TRANSFORMATION_MATRIX_EQ(
263 gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
265 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
266 host_impl_->DidDrawAllLayers(frame);
269 TEST_F(DelegatedRendererLayerImplTestSimple, DoesNotOwnARenderSurface) {
270 LayerTreeHostImpl::FrameData frame;
271 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
273 // If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
274 // has no need to be a RenderSurface for the quads it carries.
275 EXPECT_FALSE(delegated_renderer_layer_->render_surface());
277 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
278 host_impl_->DidDrawAllLayers(frame);
281 TEST_F(DelegatedRendererLayerImplTestSimple, DoesOwnARenderSurfaceForOpacity) {
282 delegated_renderer_layer_->SetOpacity(0.5f);
284 LayerTreeHostImpl::FrameData frame;
285 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
287 // This test case has quads from multiple layers in the delegated renderer, so
288 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
289 // render surface.
290 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
292 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
293 host_impl_->DidDrawAllLayers(frame);
296 TEST_F(DelegatedRendererLayerImplTestSimple,
297 DoesOwnARenderSurfaceForTransform) {
298 gfx::Transform rotation;
299 rotation.RotateAboutZAxis(30.0);
300 delegated_renderer_layer_->SetTransform(rotation);
302 LayerTreeHostImpl::FrameData frame;
303 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
305 // This test case has quads from multiple layers in the delegated renderer, so
306 // if the DelegatedRendererLayer has opacity < 1, it should end up with a
307 // render surface.
308 EXPECT_TRUE(delegated_renderer_layer_->render_surface());
310 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
311 host_impl_->DidDrawAllLayers(frame);
314 class DelegatedRendererLayerImplTestOwnSurface
315 : public DelegatedRendererLayerImplTestSimple {
316 public:
317 DelegatedRendererLayerImplTestOwnSurface()
318 : DelegatedRendererLayerImplTestSimple() {
319 delegated_renderer_layer_->SetForceRenderSurface(true);
323 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
324 LayerTreeHostImpl::FrameData frame;
325 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
327 // Each non-DelegatedRendererLayer added one RenderPass. The
328 // DelegatedRendererLayer added two contributing passes and its owned surface
329 // added one pass.
330 ASSERT_EQ(6u, frame.render_passes.size());
332 // The DelegatedRendererLayer should have added its contributing RenderPasses
333 // to the frame.
334 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
335 EXPECT_EQ(1, frame.render_passes[1]->id.index);
336 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
337 EXPECT_EQ(2, frame.render_passes[2]->id.index);
338 // The DelegatedRendererLayer should have added a RenderPass for its surface
339 // to the frame.
340 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
341 EXPECT_EQ(0, frame.render_passes[3]->id.index);
342 // And all other RenderPasses should be non-delegated.
343 EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
344 EXPECT_EQ(0, frame.render_passes[0]->id.index);
345 EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
346 EXPECT_EQ(0, frame.render_passes[4]->id.index);
347 EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
348 EXPECT_EQ(0, frame.render_passes[5]->id.index);
350 // The DelegatedRendererLayer should have added its RenderPasses to the frame
351 // in order.
352 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
353 frame.render_passes[1]->output_rect.ToString());
354 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
355 frame.render_passes[2]->output_rect.ToString());
357 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
358 host_impl_->DidDrawAllLayers(frame);
361 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
362 AddsQuadsToContributingRenderPasses) {
363 LayerTreeHostImpl::FrameData frame;
364 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
366 // Each non-DelegatedRendererLayer added one RenderPass. The
367 // DelegatedRendererLayer added two contributing passes and its owned surface
368 // added one pass.
369 ASSERT_EQ(6u, frame.render_passes.size());
371 // The DelegatedRendererLayer should have added its contributing RenderPasses
372 // to the frame.
373 EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
374 EXPECT_EQ(1, frame.render_passes[1]->id.index);
375 EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
376 EXPECT_EQ(2, frame.render_passes[2]->id.index);
378 // The DelegatedRendererLayer should have added copies of its quads to
379 // contributing RenderPasses.
380 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
381 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
382 frame.render_passes[1]->quad_list[0]->rect.ToString());
384 // Verify it added the right quads.
385 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
386 EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
387 frame.render_passes[2]->quad_list[0]->rect.ToString());
388 EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
389 frame.render_passes[2]->quad_list[1]->rect.ToString());
390 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
391 EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
392 frame.render_passes[1]->quad_list[0]->rect.ToString());
394 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
395 host_impl_->DidDrawAllLayers(frame);
398 TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
399 LayerTreeHostImpl::FrameData frame;
400 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
402 // Each non-DelegatedRendererLayer added one RenderPass. The
403 // DelegatedRendererLayer added two contributing passes and its owned surface
404 // added one pass.
405 ASSERT_EQ(6u, frame.render_passes.size());
407 // The layer's target is the RenderPass owned by itself.
408 EXPECT_EQ(RenderPass::Id(4, 0), frame.render_passes[3]->id);
410 // The DelegatedRendererLayer should have added copies of quads in its root
411 // RenderPass to its target RenderPass.
412 // The layer_after also adds one quad.
413 ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
415 // Verify it added the right quads.
416 EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
417 frame.render_passes[3]->quad_list[0]->rect.ToString());
419 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
420 host_impl_->DidDrawAllLayers(frame);
423 TEST_F(DelegatedRendererLayerImplTestOwnSurface,
424 QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
425 LayerTreeHostImpl::FrameData frame;
426 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
428 // Each non-DelegatedRendererLayer added one RenderPass. The
429 // DelegatedRendererLayer added two contributing passes and its owned surface
430 // added one pass.
431 ASSERT_EQ(6u, frame.render_passes.size());
433 // Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
434 // RenderPass' quads do not need to be translated at all. However, they are
435 // scaled from the frame's size (8x8) to the layer's bounds (10x10).
436 gfx::Transform transform;
437 transform.Scale(10.0 / 8.0, 10.0 / 8.0);
438 EXPECT_TRANSFORMATION_MATRIX_EQ(
439 transform, frame.render_passes[3]->quad_list[0]->quadTransform());
441 // Quads from non-root RenderPasses should not be shifted either.
442 ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
443 EXPECT_TRANSFORMATION_MATRIX_EQ(
444 gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
445 EXPECT_TRANSFORMATION_MATRIX_EQ(
446 gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
447 ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(
449 gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
451 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
452 host_impl_->DidDrawAllLayers(frame);
455 class DelegatedRendererLayerImplTestTransform
456 : public DelegatedRendererLayerImplTest {
457 public:
458 void SetUpTest() {
459 host_impl_->SetDeviceScaleFactor(2.f);
461 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
462 host_impl_->active_tree(), 1);
463 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
464 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
466 host_impl_->SetViewportSize(gfx::Size(200, 200));
467 root_layer->SetBounds(gfx::Size(100, 100));
469 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
470 delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
471 delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
472 delegated_renderer_layer->SetDrawsContent(true);
473 gfx::Transform transform;
474 transform.Scale(2.0, 2.0);
475 transform.Translate(8.0, 8.0);
476 delegated_renderer_layer->SetTransform(transform);
478 ScopedPtrVector<RenderPass> delegated_render_passes;
480 gfx::Size child_pass_content_bounds(7, 7);
481 gfx::Rect child_pass_rect(20, 20, 7, 7);
482 gfx::Transform child_pass_transform;
483 child_pass_transform.Scale(0.8f, 0.8f);
484 child_pass_transform.Translate(9.0, 9.0);
485 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
486 bool child_pass_clipped = false;
489 TestRenderPass* pass = AddRenderPass(
490 &delegated_render_passes,
491 RenderPass::Id(10, 7),
492 child_pass_rect,
493 gfx::Transform());
494 MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
495 AppendQuadsData data(pass->id);
496 SharedQuadState* shared_quad_state = quad_sink.UseSharedQuadState(
497 SharedQuadState::Create());
498 shared_quad_state->SetAll(
499 child_pass_transform,
500 child_pass_content_bounds,
501 child_pass_rect,
502 child_pass_clip_rect,
503 child_pass_clipped,
504 1.f);
506 scoped_ptr<SolidColorDrawQuad> color_quad;
507 color_quad = SolidColorDrawQuad::Create();
508 color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false);
509 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
511 color_quad = SolidColorDrawQuad::Create();
512 color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false);
513 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
516 gfx::Size root_pass_content_bounds(100, 100);
517 gfx::Rect root_pass_rect(0, 0, 100, 100);
518 gfx::Transform root_pass_transform;
519 root_pass_transform.Scale(1.5, 1.5);
520 root_pass_transform.Translate(7.0, 7.0);
521 gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
522 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
524 TestRenderPass* pass = AddRenderPass(
525 &delegated_render_passes,
526 RenderPass::Id(9, 6),
527 root_pass_rect,
528 gfx::Transform());
529 MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
530 AppendQuadsData data(pass->id);
531 SharedQuadState* shared_quad_state =
532 quad_sink.UseSharedQuadState(SharedQuadState::Create());
533 shared_quad_state->SetAll(
534 root_pass_transform,
535 root_pass_content_bounds,
536 root_pass_rect,
537 root_pass_clip_rect,
538 root_pass_clipped,
539 1.f);
541 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
542 RenderPassDrawQuad::Create();
543 render_pass_quad->SetNew(
544 shared_quad_state,
545 gfx::Rect(5, 5, 7, 7), // rect
546 RenderPass::Id(10, 7), // render_pass_id
547 false, // is_replica
548 0, // mask_resource_id
549 child_pass_rect, // contents_changed_since_last_frame
550 gfx::RectF(), // mask_uv_rect
551 FilterOperations(), // filters
552 FilterOperations()); // background_filters
553 quad_sink.Append(render_pass_quad.PassAs<DrawQuad>(), &data);
555 scoped_ptr<SolidColorDrawQuad> color_quad;
556 color_quad = SolidColorDrawQuad::Create();
557 color_quad->SetNew(shared_quad_state, gfx::Rect(0, 0, 10, 10), 1u, false);
558 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
560 color_quad = SolidColorDrawQuad::Create();
561 color_quad->SetNew(shared_quad_state, gfx::Rect(0, 10, 10, 10), 2u, false);
562 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
564 color_quad = SolidColorDrawQuad::Create();
565 color_quad->SetNew(shared_quad_state, gfx::Rect(10, 0, 10, 10), 3u, false);
566 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
568 color_quad = SolidColorDrawQuad::Create();
569 color_quad->SetNew(shared_quad_state, gfx::Rect(10, 10, 10, 10), 4u, false);
570 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
572 delegated_renderer_layer->SetFrameDataForRenderPasses(
573 &delegated_render_passes);
575 // The RenderPasses should be taken by the layer.
576 EXPECT_EQ(0u, delegated_render_passes.size());
578 root_layer_ = root_layer.get();
579 delegated_renderer_layer_ = delegated_renderer_layer.get();
581 root_layer->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
582 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
585 void VerifyRenderPasses(
586 const LayerTreeHostImpl::FrameData& frame,
587 size_t num_render_passes,
588 const SharedQuadState** root_delegated_shared_quad_state,
589 const SharedQuadState** contrib_delegated_shared_quad_state) {
590 ASSERT_EQ(num_render_passes, frame.render_passes.size());
591 // The contributing render pass in the DelegatedRendererLayer.
592 EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
593 EXPECT_EQ(1, frame.render_passes[0]->id.index);
594 // The root render pass.
595 EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
596 EXPECT_EQ(0, frame.render_passes.back()->id.index);
598 const QuadList& contrib_delegated_quad_list =
599 frame.render_passes[0]->quad_list;
600 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
602 const QuadList& root_delegated_quad_list =
603 frame.render_passes[1]->quad_list;
604 ASSERT_EQ(5u, root_delegated_quad_list.size());
606 // All quads in a render pass should share the same state.
607 *contrib_delegated_shared_quad_state =
608 contrib_delegated_quad_list[0]->shared_quad_state;
609 EXPECT_EQ(*contrib_delegated_shared_quad_state,
610 contrib_delegated_quad_list[1]->shared_quad_state);
612 *root_delegated_shared_quad_state =
613 root_delegated_quad_list[0]->shared_quad_state;
614 EXPECT_EQ(*root_delegated_shared_quad_state,
615 root_delegated_quad_list[1]->shared_quad_state);
616 EXPECT_EQ(*root_delegated_shared_quad_state,
617 root_delegated_quad_list[2]->shared_quad_state);
618 EXPECT_EQ(*root_delegated_shared_quad_state,
619 root_delegated_quad_list[3]->shared_quad_state);
620 EXPECT_EQ(*root_delegated_shared_quad_state,
621 root_delegated_quad_list[4]->shared_quad_state);
623 EXPECT_NE(*contrib_delegated_shared_quad_state,
624 *root_delegated_shared_quad_state);
627 protected:
628 LayerImpl* root_layer_;
629 DelegatedRendererLayerImpl* delegated_renderer_layer_;
630 bool root_delegated_render_pass_is_clipped_;
633 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
634 root_delegated_render_pass_is_clipped_ = false;
635 SetUpTest();
637 LayerTreeHostImpl::FrameData frame;
638 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
640 const SharedQuadState* root_delegated_shared_quad_state = NULL;
641 const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
642 VerifyRenderPasses(
643 frame,
645 &root_delegated_shared_quad_state,
646 &contrib_delegated_shared_quad_state);
648 // When the quads don't have a clip of their own, the clip rect is set to
649 // the drawable_content_rect of the delegated renderer layer.
650 EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
651 root_delegated_shared_quad_state->clip_rect.ToString());
653 // Even though the quads in the root pass have no clip of their own, they
654 // inherit the clip rect from the delegated renderer layer if it does not
655 // own a surface.
656 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
658 gfx::Transform expected;
659 // Device scale factor is 2.
660 expected.Scale(2.0, 2.0);
661 // This is the transform from the layer's space to its target.
662 // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5
663 expected.Translate(-17.5, -17.5);
664 expected.Scale(2.0, 2.0);
665 expected.Translate(8.0, 8.0);
666 // The frame has size 100x100 but the layer's bounds are 75x75.
667 expected.Scale(75.0 / 100.0, 75.0 / 100.0);
668 // This is the transform within the source frame.
669 expected.Scale(1.5, 1.5);
670 expected.Translate(7.0, 7.0);
671 EXPECT_TRANSFORMATION_MATRIX_EQ(
672 expected, root_delegated_shared_quad_state->content_to_target_transform);
674 // The contributing render pass should not be transformed from its input.
675 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
676 contrib_delegated_shared_quad_state->clip_rect.ToString());
677 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
678 expected.MakeIdentity();
679 expected.Scale(0.8f, 0.8f);
680 expected.Translate(9.0, 9.0);
681 EXPECT_TRANSFORMATION_MATRIX_EQ(
682 expected,
683 contrib_delegated_shared_quad_state->content_to_target_transform);
685 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
686 host_impl_->DidDrawAllLayers(frame);
689 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
690 root_delegated_render_pass_is_clipped_ = true;
691 SetUpTest();
693 LayerTreeHostImpl::FrameData frame;
694 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
696 const SharedQuadState* root_delegated_shared_quad_state = NULL;
697 const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
698 VerifyRenderPasses(
699 frame,
701 &root_delegated_shared_quad_state,
702 &contrib_delegated_shared_quad_state);
704 // Since the quads have a clip_rect it should be modified by delegated
705 // renderer layer's draw_transform.
706 // The position of the resulting clip_rect is:
707 // (clip rect position (10) * scale to layer (75/100) + translate (8)) *
708 // layer scale (2) + layer position (20) = 51
709 // But the layer is centered, so: 51 - (75 / 2) = 51 - 75 / 2 = 13.5
710 // The device scale is 2, so everything gets doubled, giving 27.
712 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
713 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5. The device
714 // scale doubles this to 105.
715 EXPECT_EQ(gfx::Rect(27, 27, 105, 105).ToString(),
716 root_delegated_shared_quad_state->clip_rect.ToString());
718 // The quads had a clip and it should be preserved.
719 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
721 gfx::Transform expected;
722 // Device scale factor is 2.
723 expected.Scale(2.0, 2.0);
724 // This is the transform from the layer's space to its target.
725 // The position (20) - the width / scale (75 / 2) = 20 - 37.5 = -17.5
726 expected.Translate(-17.5, -17.5);
727 expected.Scale(2.0, 2.0);
728 expected.Translate(8.0, 8.0);
729 // The frame has size 100x100 but the layer's bounds are 75x75.
730 expected.Scale(75.0 / 100.0, 75.0 / 100.0);
731 // This is the transform within the source frame.
732 expected.Scale(1.5, 1.5);
733 expected.Translate(7.0, 7.0);
734 EXPECT_TRANSFORMATION_MATRIX_EQ(
735 expected, root_delegated_shared_quad_state->content_to_target_transform);
737 // The contributing render pass should not be transformed from its input.
738 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
739 contrib_delegated_shared_quad_state->clip_rect.ToString());
740 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
741 expected.MakeIdentity();
742 expected.Scale(0.8f, 0.8f);
743 expected.Translate(9.0, 9.0);
744 EXPECT_TRANSFORMATION_MATRIX_EQ(
745 expected,
746 contrib_delegated_shared_quad_state->content_to_target_transform);
748 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
749 host_impl_->DidDrawAllLayers(frame);
752 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
753 root_delegated_render_pass_is_clipped_ = false;
754 SetUpTest();
756 delegated_renderer_layer_->SetForceRenderSurface(true);
758 LayerTreeHostImpl::FrameData frame;
759 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
761 const SharedQuadState* root_delegated_shared_quad_state = NULL;
762 const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
763 VerifyRenderPasses(
764 frame,
766 &root_delegated_shared_quad_state,
767 &contrib_delegated_shared_quad_state);
769 // When the layer owns a surface, then its position and translation are not
770 // a part of its draw transform.
771 // The position of the resulting clip_rect is:
772 // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15
773 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
774 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5.
775 EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(),
776 root_delegated_shared_quad_state->clip_rect.ToString());
778 // Since the layer owns a surface it doesn't need to clip its quads, so
779 // unclipped quads remain unclipped.
780 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
782 gfx::Transform expected;
783 // Device scale factor is 2.
784 expected.Scale(2.0, 2.0);
785 // The frame has size 100x100 but the layer's bounds are 75x75.
786 expected.Scale(75.0 / 100.0, 75.0 / 100.0);
787 // This is the transform within the source frame.
788 expected.Scale(1.5, 1.5);
789 expected.Translate(7.0, 7.0);
790 EXPECT_TRANSFORMATION_MATRIX_EQ(
791 expected, root_delegated_shared_quad_state->content_to_target_transform);
793 // The contributing render pass should not be transformed from its input.
794 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
795 contrib_delegated_shared_quad_state->clip_rect.ToString());
796 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
797 expected.MakeIdentity();
798 expected.Scale(0.8f, 0.8f);
799 expected.Translate(9.0, 9.0);
800 EXPECT_TRANSFORMATION_MATRIX_EQ(
801 expected,
802 contrib_delegated_shared_quad_state->content_to_target_transform);
804 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
805 host_impl_->DidDrawAllLayers(frame);
808 TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
809 root_delegated_render_pass_is_clipped_ = true;
810 SetUpTest();
812 delegated_renderer_layer_->SetForceRenderSurface(true);
814 LayerTreeHostImpl::FrameData frame;
815 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
817 const SharedQuadState* root_delegated_shared_quad_state = NULL;
818 const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
819 VerifyRenderPasses(
820 frame,
822 &root_delegated_shared_quad_state,
823 &contrib_delegated_shared_quad_state);
825 // When the layer owns a surface, then its position and translation are not
826 // a part of its draw transform.
827 // The position of the resulting clip_rect is:
828 // (clip rect position (10) * scale to layer (75/100)) * device scale (2) = 15
829 // The size is 35x35 scaled to fit inside the layer's bounds at 75x75 from
830 // a frame at 100x100: 35 * 2 (device scale) * 75 / 100 = 52.5.
831 EXPECT_EQ(gfx::Rect(15, 15, 53, 53).ToString(),
832 root_delegated_shared_quad_state->clip_rect.ToString());
834 // The quads had a clip and it should be preserved.
835 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
837 gfx::Transform expected;
838 // Device scale factor is 2.
839 expected.Scale(2.0, 2.0);
840 // The frame has size 100x100 but the layer's bounds are 75x75.
841 expected.Scale(75.0 / 100.0, 75.0 / 100.0);
842 // This is the transform within the source frame.
843 expected.Scale(1.5, 1.5);
844 expected.Translate(7.0, 7.0);
845 EXPECT_TRANSFORMATION_MATRIX_EQ(
846 expected, root_delegated_shared_quad_state->content_to_target_transform);
848 // The contributing render pass should not be transformed from its input.
849 EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
850 contrib_delegated_shared_quad_state->clip_rect.ToString());
851 EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
852 expected.MakeIdentity();
853 expected.Scale(0.8f, 0.8f);
854 expected.Translate(9.0, 9.0);
855 EXPECT_TRANSFORMATION_MATRIX_EQ(
856 expected,
857 contrib_delegated_shared_quad_state->content_to_target_transform);
859 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
860 host_impl_->DidDrawAllLayers(frame);
863 class DelegatedRendererLayerImplTestClip
864 : public DelegatedRendererLayerImplTest {
865 public:
866 void SetUpTest() {
867 scoped_ptr<LayerImpl> root_layer =
868 LayerImpl::Create(host_impl_->active_tree(), 1);
869 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
870 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
871 scoped_ptr<LayerImpl> clip_layer =
872 LayerImpl::Create(host_impl_->active_tree(), 3);
873 scoped_ptr<LayerImpl> origin_layer =
874 LayerImpl::Create(host_impl_->active_tree(), 4);
876 host_impl_->SetViewportSize(gfx::Size(100, 100));
877 root_layer->SetBounds(gfx::Size(100, 100));
879 delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
880 delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
881 delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
882 delegated_renderer_layer->SetDrawsContent(true);
884 ScopedPtrVector<RenderPass> delegated_render_passes;
886 gfx::Size child_pass_content_bounds(7, 7);
887 gfx::Rect child_pass_rect(20, 20, 7, 7);
888 gfx::Transform child_pass_transform;
889 gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
890 bool child_pass_clipped = false;
893 TestRenderPass* pass = AddRenderPass(
894 &delegated_render_passes,
895 RenderPass::Id(10, 7),
896 child_pass_rect,
897 gfx::Transform());
898 MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
899 AppendQuadsData data(pass->id);
900 SharedQuadState* shared_quad_state =
901 quad_sink.UseSharedQuadState(SharedQuadState::Create());
902 shared_quad_state->SetAll(
903 child_pass_transform,
904 child_pass_content_bounds,
905 child_pass_rect,
906 child_pass_clip_rect,
907 child_pass_clipped,
908 1.f);
910 scoped_ptr<SolidColorDrawQuad> color_quad;
911 color_quad = SolidColorDrawQuad::Create();
912 color_quad->SetNew(shared_quad_state, gfx::Rect(20, 20, 3, 7), 1u, false);
913 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
915 color_quad = SolidColorDrawQuad::Create();
916 color_quad->SetNew(shared_quad_state, gfx::Rect(23, 20, 4, 7), 1u, false);
917 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
920 gfx::Size root_pass_content_bounds(50, 50);
921 gfx::Rect root_pass_rect(0, 0, 50, 50);
922 gfx::Transform root_pass_transform;
923 gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
924 bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
926 TestRenderPass* pass = AddRenderPass(
927 &delegated_render_passes,
928 RenderPass::Id(9, 6),
929 root_pass_rect,
930 gfx::Transform());
931 MockQuadCuller quad_sink(&pass->quad_list, &pass->shared_quad_state_list);
932 AppendQuadsData data(pass->id);
933 SharedQuadState* shared_quad_state =
934 quad_sink.UseSharedQuadState(SharedQuadState::Create());
935 shared_quad_state->SetAll(root_pass_transform,
936 root_pass_content_bounds,
937 root_pass_rect,
938 root_pass_clip_rect,
939 root_pass_clipped,
940 1.f);
942 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
943 RenderPassDrawQuad::Create();
944 render_pass_quad->SetNew(
945 shared_quad_state,
946 gfx::Rect(5, 5, 7, 7), // rect
947 RenderPass::Id(10, 7), // render_pass_id
948 false, // is_replica
949 0, // mask_resource_id
950 child_pass_rect, // contents_changed_since_last_frame
951 gfx::RectF(), // mask_uv_rect
952 FilterOperations(), // filters
953 FilterOperations()); // background_filters
954 quad_sink.Append(render_pass_quad.PassAs<DrawQuad>(), &data);
956 scoped_ptr<SolidColorDrawQuad> color_quad;
957 color_quad = SolidColorDrawQuad::Create();
958 color_quad->SetNew(shared_quad_state, gfx::Rect(0, 0, 10, 10), 1u, false);
959 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
961 color_quad = SolidColorDrawQuad::Create();
962 color_quad->SetNew(shared_quad_state, gfx::Rect(0, 10, 10, 10), 2u, false);
963 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
965 color_quad = SolidColorDrawQuad::Create();
966 color_quad->SetNew(shared_quad_state, gfx::Rect(10, 0, 10, 10), 3u, false);
967 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
969 color_quad = SolidColorDrawQuad::Create();
970 color_quad->SetNew(shared_quad_state, gfx::Rect(10, 10, 10, 10), 4u, false);
971 quad_sink.Append(color_quad.PassAs<DrawQuad>(), &data);
973 delegated_renderer_layer->SetFrameDataForRenderPasses(
974 &delegated_render_passes);
976 // The RenderPasses should be taken by the layer.
977 EXPECT_EQ(0u, delegated_render_passes.size());
979 root_layer_ = root_layer.get();
980 delegated_renderer_layer_ = delegated_renderer_layer.get();
982 if (clip_delegated_renderer_layer_) {
983 gfx::Rect clip_rect(21, 27, 23, 21);
985 clip_layer->SetPosition(clip_rect.origin());
986 clip_layer->SetBounds(clip_rect.size());
987 clip_layer->SetContentBounds(clip_rect.size());
988 clip_layer->SetMasksToBounds(true);
990 origin_layer->SetPosition(
991 gfx::PointAtOffsetFromOrigin(-clip_rect.OffsetFromOrigin()));
993 origin_layer->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
994 clip_layer->AddChild(origin_layer.Pass());
995 root_layer->AddChild(clip_layer.Pass());
996 } else {
997 root_layer->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
1000 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1003 protected:
1004 LayerImpl* root_layer_;
1005 DelegatedRendererLayerImpl* delegated_renderer_layer_;
1006 bool root_delegated_render_pass_is_clipped_;
1007 bool clip_delegated_renderer_layer_;
1010 TEST_F(DelegatedRendererLayerImplTestClip,
1011 QuadsUnclipped_LayerUnclipped_NoSurface) {
1012 root_delegated_render_pass_is_clipped_ = false;
1013 clip_delegated_renderer_layer_ = false;
1014 SetUpTest();
1016 LayerTreeHostImpl::FrameData frame;
1017 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1019 ASSERT_EQ(2u, frame.render_passes.size());
1020 const QuadList& contrib_delegated_quad_list =
1021 frame.render_passes[0]->quad_list;
1022 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1023 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1024 ASSERT_EQ(5u, root_delegated_quad_list.size());
1025 const SharedQuadState* root_delegated_shared_quad_state =
1026 root_delegated_quad_list[0]->shared_quad_state;
1028 // When the quads don't have a clip of their own, the clip rect is set to
1029 // the drawable_content_rect of the delegated renderer layer.
1030 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
1031 root_delegated_shared_quad_state->clip_rect.ToString());
1032 // Quads are clipped to the delegated renderer layer.
1033 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1035 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1036 host_impl_->DidDrawAllLayers(frame);
1039 TEST_F(DelegatedRendererLayerImplTestClip,
1040 QuadsClipped_LayerUnclipped_NoSurface) {
1041 root_delegated_render_pass_is_clipped_ = true;
1042 clip_delegated_renderer_layer_ = false;
1043 SetUpTest();
1045 LayerTreeHostImpl::FrameData frame;
1046 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1048 ASSERT_EQ(2u, frame.render_passes.size());
1049 const QuadList& contrib_delegated_quad_list =
1050 frame.render_passes[0]->quad_list;
1051 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1052 const QuadList& root_delegated_quad_list =
1053 frame.render_passes[1]->quad_list;
1054 ASSERT_EQ(5u, root_delegated_quad_list.size());
1055 const SharedQuadState* root_delegated_shared_quad_state =
1056 root_delegated_quad_list[0]->shared_quad_state;
1058 // When the quads have a clip of their own, it is used.
1059 EXPECT_EQ(gfx::Rect(25, 25, 40, 40).ToString(),
1060 root_delegated_shared_quad_state->clip_rect.ToString());
1061 // Quads came with a clip rect.
1062 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1064 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1065 host_impl_->DidDrawAllLayers(frame);
1068 TEST_F(DelegatedRendererLayerImplTestClip,
1069 QuadsUnclipped_LayerClipped_NoSurface) {
1070 root_delegated_render_pass_is_clipped_ = false;
1071 clip_delegated_renderer_layer_ = true;
1072 SetUpTest();
1074 LayerTreeHostImpl::FrameData frame;
1075 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1077 ASSERT_EQ(2u, frame.render_passes.size());
1078 const QuadList& contrib_delegated_quad_list =
1079 frame.render_passes[0]->quad_list;
1080 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1081 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1082 ASSERT_EQ(5u, root_delegated_quad_list.size());
1083 const SharedQuadState* root_delegated_shared_quad_state =
1084 root_delegated_quad_list[0]->shared_quad_state;
1086 // When the quads don't have a clip of their own, the clip rect is set to
1087 // the drawable_content_rect of the delegated renderer layer. When the layer
1088 // is clipped, that should be seen in the quads' clip_rect.
1089 EXPECT_EQ(gfx::Rect(21, 27, 23, 21).ToString(),
1090 root_delegated_shared_quad_state->clip_rect.ToString());
1091 // Quads are clipped to the delegated renderer layer.
1092 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1094 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1095 host_impl_->DidDrawAllLayers(frame);
1098 TEST_F(DelegatedRendererLayerImplTestClip,
1099 QuadsClipped_LayerClipped_NoSurface) {
1100 root_delegated_render_pass_is_clipped_ = true;
1101 clip_delegated_renderer_layer_ = true;
1102 SetUpTest();
1104 LayerTreeHostImpl::FrameData frame;
1105 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1107 ASSERT_EQ(2u, frame.render_passes.size());
1108 const QuadList& contrib_delegated_quad_list =
1109 frame.render_passes[0]->quad_list;
1110 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1111 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1112 ASSERT_EQ(5u, root_delegated_quad_list.size());
1113 const SharedQuadState* root_delegated_shared_quad_state =
1114 root_delegated_quad_list[0]->shared_quad_state;
1116 // When the quads have a clip of their own, it is used, but it is
1117 // combined with the clip rect of the delegated renderer layer.
1118 EXPECT_EQ(gfx::Rect(25, 27, 19, 21).ToString(),
1119 root_delegated_shared_quad_state->clip_rect.ToString());
1120 // Quads came with a clip rect.
1121 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1123 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1124 host_impl_->DidDrawAllLayers(frame);
1127 TEST_F(DelegatedRendererLayerImplTestClip,
1128 QuadsUnclipped_LayerUnclipped_Surface) {
1129 root_delegated_render_pass_is_clipped_ = false;
1130 clip_delegated_renderer_layer_ = false;
1131 SetUpTest();
1133 delegated_renderer_layer_->SetForceRenderSurface(true);
1135 LayerTreeHostImpl::FrameData frame;
1136 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1138 ASSERT_EQ(3u, frame.render_passes.size());
1139 const QuadList& contrib_delegated_quad_list =
1140 frame.render_passes[0]->quad_list;
1141 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1142 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1143 ASSERT_EQ(5u, root_delegated_quad_list.size());
1144 const SharedQuadState* root_delegated_shared_quad_state =
1145 root_delegated_quad_list[0]->shared_quad_state;
1147 // When the layer owns a surface, the quads don't need to be clipped
1148 // further than they already specify. If they aren't clipped, then their
1149 // clip rect is ignored, and they are not set as clipped.
1150 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1152 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1153 host_impl_->DidDrawAllLayers(frame);
1156 TEST_F(DelegatedRendererLayerImplTestClip,
1157 QuadsClipped_LayerUnclipped_Surface) {
1158 root_delegated_render_pass_is_clipped_ = true;
1159 clip_delegated_renderer_layer_ = false;
1160 SetUpTest();
1162 delegated_renderer_layer_->SetForceRenderSurface(true);
1164 LayerTreeHostImpl::FrameData frame;
1165 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1167 ASSERT_EQ(3u, frame.render_passes.size());
1168 const QuadList& contrib_delegated_quad_list =
1169 frame.render_passes[0]->quad_list;
1170 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1171 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1172 ASSERT_EQ(5u, root_delegated_quad_list.size());
1173 const SharedQuadState* root_delegated_shared_quad_state =
1174 root_delegated_quad_list[0]->shared_quad_state;
1176 // When the quads have a clip of their own, it is used.
1177 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1178 root_delegated_shared_quad_state->clip_rect.ToString());
1179 // Quads came with a clip rect.
1180 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1182 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1183 host_impl_->DidDrawAllLayers(frame);
1186 TEST_F(DelegatedRendererLayerImplTestClip,
1187 QuadsUnclipped_LayerClipped_Surface) {
1188 root_delegated_render_pass_is_clipped_ = false;
1189 clip_delegated_renderer_layer_ = true;
1190 SetUpTest();
1192 delegated_renderer_layer_->SetForceRenderSurface(true);
1194 LayerTreeHostImpl::FrameData frame;
1195 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1197 ASSERT_EQ(3u, frame.render_passes.size());
1198 const QuadList& contrib_delegated_quad_list =
1199 frame.render_passes[0]->quad_list;
1200 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1201 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1202 ASSERT_EQ(5u, root_delegated_quad_list.size());
1203 const SharedQuadState* root_delegated_shared_quad_state =
1204 root_delegated_quad_list[0]->shared_quad_state;
1206 // When the layer owns a surface, the quads don't need to be clipped
1207 // further than they already specify. If they aren't clipped, then their
1208 // clip rect is ignored, and they are not set as clipped.
1209 EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
1211 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1212 host_impl_->DidDrawAllLayers(frame);
1215 TEST_F(DelegatedRendererLayerImplTestClip, QuadsClipped_LayerClipped_Surface) {
1216 root_delegated_render_pass_is_clipped_ = true;
1217 clip_delegated_renderer_layer_ = true;
1218 SetUpTest();
1220 delegated_renderer_layer_->SetForceRenderSurface(true);
1222 LayerTreeHostImpl::FrameData frame;
1223 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1225 ASSERT_EQ(3u, frame.render_passes.size());
1226 const QuadList& contrib_delegated_quad_list =
1227 frame.render_passes[0]->quad_list;
1228 ASSERT_EQ(2u, contrib_delegated_quad_list.size());
1229 const QuadList& root_delegated_quad_list = frame.render_passes[1]->quad_list;
1230 ASSERT_EQ(5u, root_delegated_quad_list.size());
1231 const SharedQuadState* root_delegated_shared_quad_state =
1232 root_delegated_quad_list[0]->shared_quad_state;
1234 // When the quads have a clip of their own, it is used, but it is
1235 // combined with the clip rect of the delegated renderer layer. If the
1236 // layer owns a surface, then it does not have a clip rect of its own.
1237 EXPECT_EQ(gfx::Rect(5, 5, 40, 40).ToString(),
1238 root_delegated_shared_quad_state->clip_rect.ToString());
1239 // Quads came with a clip rect.
1240 EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
1242 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1243 host_impl_->DidDrawAllLayers(frame);
1246 TEST_F(DelegatedRendererLayerImplTest, InvalidRenderPassDrawQuad) {
1247 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
1248 host_impl_->active_tree(), 1).PassAs<LayerImpl>();
1249 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
1250 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
1252 host_impl_->SetViewportSize(gfx::Size(100, 100));
1254 delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
1255 delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
1256 delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
1257 delegated_renderer_layer->SetDrawsContent(true);
1259 ScopedPtrVector<RenderPass> delegated_render_passes;
1260 TestRenderPass* pass1 = AddRenderPass(
1261 &delegated_render_passes,
1262 RenderPass::Id(9, 6),
1263 gfx::Rect(0, 0, 10, 10),
1264 gfx::Transform());
1265 AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
1267 // This render pass isn't part of the frame.
1268 scoped_ptr<TestRenderPass> missing_pass(TestRenderPass::Create());
1269 missing_pass->SetNew(RenderPass::Id(9, 7),
1270 gfx::Rect(7, 7, 7, 7),
1271 gfx::Rect(7, 7, 7, 7),
1272 gfx::Transform());
1274 // But a render pass quad refers to it.
1275 AddRenderPassQuad(pass1, missing_pass.get());
1277 delegated_renderer_layer->SetFrameDataForRenderPasses(
1278 &delegated_render_passes);
1280 // The RenderPasses should be taken by the layer.
1281 EXPECT_EQ(0u, delegated_render_passes.size());
1283 root_layer->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
1284 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
1286 LayerTreeHostImpl::FrameData frame;
1287 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1289 // The DelegatedRendererLayerImpl should drop the bad RenderPassDrawQuad.
1290 ASSERT_EQ(1u, frame.render_passes.size());
1291 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
1292 EXPECT_EQ(DrawQuad::SOLID_COLOR,
1293 frame.render_passes[0]->quad_list[0]->material);
1295 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1296 host_impl_->DidDrawAllLayers(frame);
1299 } // namespace
1300 } // namespace cc