blob: 351d2acbbb6f9fa747089e1f5c49bc701a71813a [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"
sunxdbb0b3ae92017-04-05 21:13:2012#include "cc/test/fake_raster_source.h"
[email protected]ba0f8d92014-03-21 18:41:1013#include "cc/test/layer_test_common.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16namespace cc {
17namespace {
18
19TEST(RenderSurfaceLayerImplTest, Occlusion) {
20 gfx::Size layer_size(1000, 1000);
21 gfx::Size viewport_size(1000, 1000);
22
23 LayerTestCommon::LayerImplTest impl;
24
25 LayerImpl* owning_layer_impl = impl.AddChildToRoot<LayerImpl>();
[email protected]ba0f8d92014-03-21 18:41:1026 owning_layer_impl->SetBounds(layer_size);
[email protected]ba0f8d92014-03-21 18:41:1027 owning_layer_impl->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:3628 owning_layer_impl->test_properties()->force_render_surface = true;
[email protected]ba0f8d92014-03-21 18:41:1029
30 impl.CalcDrawProps(viewport_size);
31
ajumaac2d30792017-02-24 23:00:3132 RenderSurfaceImpl* render_surface_impl =
33 owning_layer_impl->GetRenderSurface();
[email protected]ba0f8d92014-03-21 18:41:1034 ASSERT_TRUE(render_surface_impl);
35
36 {
37 SCOPED_TRACE("No occlusion");
38 gfx::Rect occluded;
39 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
40
41 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
42 gfx::Rect(layer_size));
43 EXPECT_EQ(1u, impl.quad_list().size());
44 }
45
46 {
47 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:4348 gfx::Rect occluded(owning_layer_impl->visible_layer_rect());
[email protected]ba0f8d92014-03-21 18:41:1049 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
50
51 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
52 EXPECT_EQ(impl.quad_list().size(), 0u);
53 }
54
55 {
56 SCOPED_TRACE("Partial occlusion");
57 gfx::Rect occluded(200, 0, 800, 1000);
58 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
59
60 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:1161 LayerTestCommon::VerifyQuadsAreOccluded(
62 impl.quad_list(), occluded, &partially_occluded_count);
[email protected]ba0f8d92014-03-21 18:41:1063 // The layer outputs one quad, which is partially occluded.
64 EXPECT_EQ(1u, impl.quad_list().size());
65 EXPECT_EQ(1u, partially_occluded_count);
66 }
67}
68
ajumad9432e32015-11-30 19:43:4469TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
70 gfx::Size layer_size(1000, 1000);
71 gfx::Size viewport_size(1000, 1000);
sunxdbb0b3ae92017-04-05 21:13:2072 scoped_refptr<FakeRasterSource> raster_source =
73 FakeRasterSource::CreateFilledSolidColor(layer_size);
ajumad9432e32015-11-30 19:43:4474
75 LayerTestCommon::LayerImplTest impl;
danakj60bc3bc2016-04-09 00:24:4876 std::unique_ptr<LayerImpl> root =
ajumad9432e32015-11-30 19:43:4477 LayerImpl::Create(impl.host_impl()->active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:4878 std::unique_ptr<LayerImpl> surface =
ajumad9432e32015-11-30 19:43:4479 LayerImpl::Create(impl.host_impl()->active_tree(), 3);
80 surface->SetBounds(layer_size);
ajuma35b24f62017-01-27 21:23:0981 surface->test_properties()->force_render_surface = true;
ajumad9432e32015-11-30 19:43:4482
83 gfx::Transform scale;
84 scale.Scale(2, 2);
jaydasika10d43fc2016-08-18 04:06:0485 surface->test_properties()->transform = scale;
ajumad9432e32015-11-30 19:43:4486
sunxdbb0b3ae92017-04-05 21:13:2087 surface->test_properties()->SetMaskLayer(FakeMaskLayerImpl::Create(
88 impl.host_impl()->active_tree(), 4, raster_source,
89 Layer::LayerMaskType::SINGLE_TEXTURE_MASK));
ajuma1d4026a32016-06-14 13:18:5090 surface->test_properties()->mask_layer->SetDrawsContent(true);
91 surface->test_properties()->mask_layer->SetBounds(layer_size);
ajumad9432e32015-11-30 19:43:4492
danakj60bc3bc2016-04-09 00:24:4893 std::unique_ptr<LayerImpl> child =
ajumad9432e32015-11-30 19:43:4494 LayerImpl::Create(impl.host_impl()->active_tree(), 5);
95 child->SetDrawsContent(true);
96 child->SetBounds(layer_size);
97
jaydasika89f7b5a2016-06-22 02:08:3998 surface->test_properties()->AddChild(std::move(child));
99 root->test_properties()->AddChild(std::move(surface));
jaydasikabf1875a2016-06-28 03:39:59100 impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
ajumad9432e32015-11-30 19:43:44101
102 impl.host_impl()->SetViewportSize(viewport_size);
jaydasika4340ea02016-06-06 19:44:26103 impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumad9432e32015-11-30 19:43:44104 impl.host_impl()->active_tree()->UpdateDrawProperties(false);
105
jaydasikafc66cfb2016-06-10 04:34:22106 LayerImpl* surface_raw = impl.host_impl()
107 ->active_tree()
jaydasikabf1875a2016-06-28 03:39:59108 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:22109 ->test_properties()
110 ->children[0];
ajumaac2d30792017-02-24 23:00:31111 RenderSurfaceImpl* render_surface_impl = surface_raw->GetRenderSurface();
danakj60bc3bc2016-04-09 00:24:48112 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
ajumad9432e32015-11-30 19:43:44113 AppendQuadsData append_quads_data;
ajuma3e64b9d52016-11-22 18:38:19114 render_surface_impl->AppendQuads(render_pass.get(), &append_quads_data);
ajumad9432e32015-11-30 19:43:44115
sunxdbb0b3ae92017-04-05 21:13:20116 DCHECK(render_pass->quad_list.front());
ajumad9432e32015-11-30 19:43:44117 const RenderPassDrawQuad* quad =
118 RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
sunxdbb0b3ae92017-04-05 21:13:20119 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), quad->mask_uv_rect);
ajumad9432e32015-11-30 19:43:44120 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
121}
122
[email protected]ba0f8d92014-03-21 18:41:10123} // namespace
124} // namespace cc