blob: 72e522adfc251d9a584321e413c8b56a45734443 [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);
74 root->SetHasRenderSurface(true);
danakj60bc3bc2016-04-09 00:24:4875 std::unique_ptr<LayerImpl> surface =
ajumad9432e32015-11-30 19:43:4476 LayerImpl::Create(impl.host_impl()->active_tree(), 3);
77 surface->SetBounds(layer_size);
78 surface->SetHasRenderSurface(true);
79
80 gfx::Transform scale;
81 scale.Scale(2, 2);
82 surface->SetTransform(scale);
83
ajuma1d4026a32016-06-14 13:18:5084 surface->test_properties()->SetMaskLayer(
ajumad9432e32015-11-30 19:43:4485 FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4));
ajuma1d4026a32016-06-14 13:18:5086 surface->test_properties()->mask_layer->SetDrawsContent(true);
87 surface->test_properties()->mask_layer->SetBounds(layer_size);
ajumad9432e32015-11-30 19:43:4488
danakj60bc3bc2016-04-09 00:24:4889 std::unique_ptr<LayerImpl> child =
ajumad9432e32015-11-30 19:43:4490 LayerImpl::Create(impl.host_impl()->active_tree(), 5);
91 child->SetDrawsContent(true);
92 child->SetBounds(layer_size);
93
jaydasika89f7b5a2016-06-22 02:08:3994 surface->test_properties()->AddChild(std::move(child));
95 root->test_properties()->AddChild(std::move(surface));
jaydasikabf1875a2016-06-28 03:39:5996 impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
ajumad9432e32015-11-30 19:43:4497
98 impl.host_impl()->SetViewportSize(viewport_size);
jaydasika4340ea02016-06-06 19:44:2699 impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumad9432e32015-11-30 19:43:44100 impl.host_impl()->active_tree()->UpdateDrawProperties(false);
101
jaydasikafc66cfb2016-06-10 04:34:22102 LayerImpl* surface_raw = impl.host_impl()
103 ->active_tree()
jaydasikabf1875a2016-06-28 03:39:59104 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:22105 ->test_properties()
106 ->children[0];
ajumad9432e32015-11-30 19:43:44107 RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface();
danakj60bc3bc2016-04-09 00:24:48108 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
ajumad9432e32015-11-30 19:43:44109 AppendQuadsData append_quads_data;
110 render_surface_impl->AppendQuads(
111 render_pass.get(), render_surface_impl->draw_transform(), Occlusion(),
ajuma1d4026a32016-06-14 13:18:50112 SK_ColorBLACK, 1.f, render_surface_impl->MaskLayer(), &append_quads_data,
ajumad9432e32015-11-30 19:43:44113 RenderPassId(1, 1));
114
115 const RenderPassDrawQuad* quad =
116 RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
senorblancodfcb3622016-01-27 21:48:01117 EXPECT_EQ(gfx::Vector2dF(0.0005f, 0.0005f), quad->mask_uv_scale);
ajumad9432e32015-11-30 19:43:44118 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
119}
120
[email protected]ba0f8d92014-03-21 18:41:10121} // namespace
122} // namespace cc