blob: 96ca40baf136e02c81d56dde849a20abc76c1ddf [file] [log] [blame]
[email protected]ba0f8d92014-03-21 18:41:101// Copyright 2014 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.
4
5#include "cc/layers/render_surface_impl.h"
6
ajumad9432e32015-11-30 19:43:447#include "cc/layers/append_quads_data.h"
8#include "cc/quads/render_pass_draw_quad.h"
9#include "cc/test/fake_mask_layer_impl.h"
[email protected]ba0f8d92014-03-21 18:41:1010#include "cc/test/layer_test_common.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace cc {
14namespace {
15
16TEST(RenderSurfaceLayerImplTest, Occlusion) {
17 gfx::Size layer_size(1000, 1000);
18 gfx::Size viewport_size(1000, 1000);
19
20 LayerTestCommon::LayerImplTest impl;
21
22 LayerImpl* owning_layer_impl = impl.AddChildToRoot<LayerImpl>();
[email protected]ba0f8d92014-03-21 18:41:1023 owning_layer_impl->SetBounds(layer_size);
[email protected]ba0f8d92014-03-21 18:41:1024 owning_layer_impl->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:2625 owning_layer_impl->SetForceRenderSurface(true);
[email protected]ba0f8d92014-03-21 18:41:1026
27 impl.CalcDrawProps(viewport_size);
28
29 RenderSurfaceImpl* render_surface_impl = owning_layer_impl->render_surface();
30 ASSERT_TRUE(render_surface_impl);
31
32 {
33 SCOPED_TRACE("No occlusion");
34 gfx::Rect occluded;
35 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
36
37 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
38 gfx::Rect(layer_size));
39 EXPECT_EQ(1u, impl.quad_list().size());
40 }
41
42 {
43 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:4344 gfx::Rect occluded(owning_layer_impl->visible_layer_rect());
[email protected]ba0f8d92014-03-21 18:41:1045 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
46
47 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
48 EXPECT_EQ(impl.quad_list().size(), 0u);
49 }
50
51 {
52 SCOPED_TRACE("Partial occlusion");
53 gfx::Rect occluded(200, 0, 800, 1000);
54 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
55
56 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:1157 LayerTestCommon::VerifyQuadsAreOccluded(
58 impl.quad_list(), occluded, &partially_occluded_count);
[email protected]ba0f8d92014-03-21 18:41:1059 // The layer outputs one quad, which is partially occluded.
60 EXPECT_EQ(1u, impl.quad_list().size());
61 EXPECT_EQ(1u, partially_occluded_count);
62 }
63}
64
ajumad9432e32015-11-30 19:43:4465TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
66 gfx::Size layer_size(1000, 1000);
67 gfx::Size viewport_size(1000, 1000);
68
69 LayerTestCommon::LayerImplTest impl;
70 scoped_ptr<LayerImpl> root =
71 LayerImpl::Create(impl.host_impl()->active_tree(), 2);
72 root->SetHasRenderSurface(true);
73 scoped_ptr<LayerImpl> surface =
74 LayerImpl::Create(impl.host_impl()->active_tree(), 3);
75 surface->SetBounds(layer_size);
76 surface->SetHasRenderSurface(true);
77
78 gfx::Transform scale;
79 scale.Scale(2, 2);
80 surface->SetTransform(scale);
81
82 surface->SetMaskLayer(
83 FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4));
84 surface->mask_layer()->SetDrawsContent(true);
85 surface->mask_layer()->SetBounds(layer_size);
86
87 scoped_ptr<LayerImpl> child =
88 LayerImpl::Create(impl.host_impl()->active_tree(), 5);
89 child->SetDrawsContent(true);
90 child->SetBounds(layer_size);
91
92 surface->AddChild(std::move(child));
93 root->AddChild(std::move(surface));
94 impl.host_impl()->active_tree()->SetRootLayer(std::move(root));
95
96 impl.host_impl()->SetViewportSize(viewport_size);
97 impl.host_impl()->active_tree()->BuildPropertyTreesForTesting();
98 impl.host_impl()->active_tree()->UpdateDrawProperties(false);
99
100 LayerImpl* surface_raw =
101 impl.host_impl()->active_tree()->root_layer()->children()[0].get();
102 RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface();
103 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
104 AppendQuadsData append_quads_data;
105 render_surface_impl->AppendQuads(
106 render_pass.get(), render_surface_impl->draw_transform(), Occlusion(),
107 SK_ColorBLACK, 1.f, surface_raw->mask_layer(), &append_quads_data,
108 RenderPassId(1, 1));
109
110 const RenderPassDrawQuad* quad =
111 RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
112 EXPECT_EQ(gfx::Vector2dF(1.f, 1.f), quad->mask_uv_scale);
113 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
114}
115
[email protected]ba0f8d92014-03-21 18:41:10116} // namespace
117} // namespace cc