blob: 3282d307d0be369a93fd716ae482d1210592ad4b [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
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
ajumad9432e32015-11-30 19:43:449#include "cc/layers/append_quads_data.h"
10#include "cc/quads/render_pass_draw_quad.h"
11#include "cc/test/fake_mask_layer_impl.h"
[email protected]ba0f8d92014-03-21 18:41:1012#include "cc/test/layer_test_common.h"
13#include "testing/gtest/include/gtest/gtest.h"
14
15namespace cc {
16namespace {
17
18TEST(RenderSurfaceLayerImplTest, Occlusion) {
19 gfx::Size layer_size(1000, 1000);
20 gfx::Size viewport_size(1000, 1000);
21
22 LayerTestCommon::LayerImplTest impl;
23
24 LayerImpl* owning_layer_impl = impl.AddChildToRoot<LayerImpl>();
[email protected]ba0f8d92014-03-21 18:41:1025 owning_layer_impl->SetBounds(layer_size);
[email protected]ba0f8d92014-03-21 18:41:1026 owning_layer_impl->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:3627 owning_layer_impl->test_properties()->force_render_surface = true;
[email protected]ba0f8d92014-03-21 18:41:1028
29 impl.CalcDrawProps(viewport_size);
30
31 RenderSurfaceImpl* render_surface_impl = owning_layer_impl->render_surface();
32 ASSERT_TRUE(render_surface_impl);
33
34 {
35 SCOPED_TRACE("No occlusion");
36 gfx::Rect occluded;
37 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
38
39 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
40 gfx::Rect(layer_size));
41 EXPECT_EQ(1u, impl.quad_list().size());
42 }
43
44 {
45 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:4346 gfx::Rect occluded(owning_layer_impl->visible_layer_rect());
[email protected]ba0f8d92014-03-21 18:41:1047 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
48
49 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
50 EXPECT_EQ(impl.quad_list().size(), 0u);
51 }
52
53 {
54 SCOPED_TRACE("Partial occlusion");
55 gfx::Rect occluded(200, 0, 800, 1000);
56 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
57
58 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:1159 LayerTestCommon::VerifyQuadsAreOccluded(
60 impl.quad_list(), occluded, &partially_occluded_count);
[email protected]ba0f8d92014-03-21 18:41:1061 // The layer outputs one quad, which is partially occluded.
62 EXPECT_EQ(1u, impl.quad_list().size());
63 EXPECT_EQ(1u, partially_occluded_count);
64 }
65}
66
ajumad9432e32015-11-30 19:43:4467TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
68 gfx::Size layer_size(1000, 1000);
69 gfx::Size viewport_size(1000, 1000);
70
71 LayerTestCommon::LayerImplTest impl;
danakj60bc3bc2016-04-09 00:24:4872 std::unique_ptr<LayerImpl> root =
ajumad9432e32015-11-30 19:43:4473 LayerImpl::Create(impl.host_impl()->active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:4874 std::unique_ptr<LayerImpl> surface =
ajumad9432e32015-11-30 19:43:4475 LayerImpl::Create(impl.host_impl()->active_tree(), 3);
76 surface->SetBounds(layer_size);
ajuma35b24f62017-01-27 21:23:0977 surface->test_properties()->force_render_surface = true;
ajumad9432e32015-11-30 19:43:4478
79 gfx::Transform scale;
80 scale.Scale(2, 2);
jaydasika10d43fc2016-08-18 04:06:0481 surface->test_properties()->transform = scale;
ajumad9432e32015-11-30 19:43:4482
ajuma1d4026a32016-06-14 13:18:5083 surface->test_properties()->SetMaskLayer(
ajumad9432e32015-11-30 19:43:4484 FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4));
ajuma1d4026a32016-06-14 13:18:5085 surface->test_properties()->mask_layer->SetDrawsContent(true);
86 surface->test_properties()->mask_layer->SetBounds(layer_size);
ajumad9432e32015-11-30 19:43:4487
danakj60bc3bc2016-04-09 00:24:4888 std::unique_ptr<LayerImpl> child =
ajumad9432e32015-11-30 19:43:4489 LayerImpl::Create(impl.host_impl()->active_tree(), 5);
90 child->SetDrawsContent(true);
91 child->SetBounds(layer_size);
92
jaydasika89f7b5a2016-06-22 02:08:3993 surface->test_properties()->AddChild(std::move(child));
94 root->test_properties()->AddChild(std::move(surface));
jaydasikabf1875a2016-06-28 03:39:5995 impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
ajumad9432e32015-11-30 19:43:4496
97 impl.host_impl()->SetViewportSize(viewport_size);
jaydasika4340ea02016-06-06 19:44:2698 impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumad9432e32015-11-30 19:43:4499 impl.host_impl()->active_tree()->UpdateDrawProperties(false);
100
jaydasikafc66cfb2016-06-10 04:34:22101 LayerImpl* surface_raw = impl.host_impl()
102 ->active_tree()
jaydasikabf1875a2016-06-28 03:39:59103 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:22104 ->test_properties()
105 ->children[0];
ajumad9432e32015-11-30 19:43:44106 RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface();
danakj60bc3bc2016-04-09 00:24:48107 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
ajumad9432e32015-11-30 19:43:44108 AppendQuadsData append_quads_data;
ajuma3e64b9d52016-11-22 18:38:19109 render_surface_impl->AppendQuads(render_pass.get(), &append_quads_data);
ajumad9432e32015-11-30 19:43:44110
111 const RenderPassDrawQuad* quad =
112 RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
senorblancodfcb3622016-01-27 21:48:01113 EXPECT_EQ(gfx::Vector2dF(0.0005f, 0.0005f), quad->mask_uv_scale);
ajumad9432e32015-11-30 19:43:44114 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
115}
116
[email protected]ba0f8d92014-03-21 18:41:10117} // namespace
118} // namespace cc