blob: 6422ffa19fd4cdba9fb156743aba961d88686378 [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
chrishtr7e3aaf22017-05-04 15:04:0132 RenderSurfaceImpl* render_surface_impl = GetRenderSurface(owning_layer_impl);
[email protected]ba0f8d92014-03-21 18:41:1033 ASSERT_TRUE(render_surface_impl);
34
35 {
36 SCOPED_TRACE("No occlusion");
37 gfx::Rect occluded;
38 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
39
40 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
41 gfx::Rect(layer_size));
42 EXPECT_EQ(1u, impl.quad_list().size());
43 }
44
45 {
46 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:4347 gfx::Rect occluded(owning_layer_impl->visible_layer_rect());
[email protected]ba0f8d92014-03-21 18:41:1048 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
49
50 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
51 EXPECT_EQ(impl.quad_list().size(), 0u);
52 }
53
54 {
55 SCOPED_TRACE("Partial occlusion");
56 gfx::Rect occluded(200, 0, 800, 1000);
57 impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded);
58
59 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:1160 LayerTestCommon::VerifyQuadsAreOccluded(
61 impl.quad_list(), occluded, &partially_occluded_count);
[email protected]ba0f8d92014-03-21 18:41:1062 // The layer outputs one quad, which is partially occluded.
63 EXPECT_EQ(1u, impl.quad_list().size());
64 EXPECT_EQ(1u, partially_occluded_count);
65 }
66}
67
ajumad9432e32015-11-30 19:43:4468TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
69 gfx::Size layer_size(1000, 1000);
70 gfx::Size viewport_size(1000, 1000);
ericrk664405a2017-05-04 20:58:3771 float scale_factor = 2;
sunxdbb0b3ae92017-04-05 21:13:2072 scoped_refptr<FakeRasterSource> raster_source =
73 FakeRasterSource::CreateFilledSolidColor(layer_size);
ajumad9432e32015-11-30 19:43:4474
revemanb2b99a3b2017-04-06 23:39:0875 LayerTreeSettings settings;
76 settings.layer_transforms_should_scale_layer_contents = true;
77 LayerTestCommon::LayerImplTest impl(settings);
danakj60bc3bc2016-04-09 00:24:4878 std::unique_ptr<LayerImpl> root =
ajumad9432e32015-11-30 19:43:4479 LayerImpl::Create(impl.host_impl()->active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:4880 std::unique_ptr<LayerImpl> surface =
ajumad9432e32015-11-30 19:43:4481 LayerImpl::Create(impl.host_impl()->active_tree(), 3);
82 surface->SetBounds(layer_size);
ajuma35b24f62017-01-27 21:23:0983 surface->test_properties()->force_render_surface = true;
ajumad9432e32015-11-30 19:43:4484
85 gfx::Transform scale;
ericrk664405a2017-05-04 20:58:3786 scale.Scale(scale_factor, scale_factor);
jaydasika10d43fc2016-08-18 04:06:0487 surface->test_properties()->transform = scale;
ajumad9432e32015-11-30 19:43:4488
ericrk664405a2017-05-04 20:58:3789 std::unique_ptr<FakeMaskLayerImpl> mask_layer = FakeMaskLayerImpl::Create(
sunxdbb0b3ae92017-04-05 21:13:2090 impl.host_impl()->active_tree(), 4, raster_source,
ericrk664405a2017-05-04 20:58:3791 Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
92 mask_layer->set_resource_size(
93 gfx::ScaleToCeiledSize(layer_size, scale_factor));
94 mask_layer->SetDrawsContent(true);
95 mask_layer->SetBounds(layer_size);
96 surface->test_properties()->SetMaskLayer(std::move(mask_layer));
ajumad9432e32015-11-30 19:43:4497
danakj60bc3bc2016-04-09 00:24:4898 std::unique_ptr<LayerImpl> child =
ajumad9432e32015-11-30 19:43:4499 LayerImpl::Create(impl.host_impl()->active_tree(), 5);
100 child->SetDrawsContent(true);
101 child->SetBounds(layer_size);
102
jaydasika89f7b5a2016-06-22 02:08:39103 surface->test_properties()->AddChild(std::move(child));
104 root->test_properties()->AddChild(std::move(surface));
jaydasikabf1875a2016-06-28 03:39:59105 impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
ajumad9432e32015-11-30 19:43:44106
107 impl.host_impl()->SetViewportSize(viewport_size);
jaydasika4340ea02016-06-06 19:44:26108 impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumad9432e32015-11-30 19:43:44109 impl.host_impl()->active_tree()->UpdateDrawProperties(false);
110
jaydasikafc66cfb2016-06-10 04:34:22111 LayerImpl* surface_raw = impl.host_impl()
112 ->active_tree()
jaydasikabf1875a2016-06-28 03:39:59113 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:22114 ->test_properties()
115 ->children[0];
chrishtr7e3aaf22017-05-04 15:04:01116 RenderSurfaceImpl* render_surface_impl = GetRenderSurface(surface_raw);
danakj60bc3bc2016-04-09 00:24:48117 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
ajumad9432e32015-11-30 19:43:44118 AppendQuadsData append_quads_data;
ajuma3e64b9d52016-11-22 18:38:19119 render_surface_impl->AppendQuads(render_pass.get(), &append_quads_data);
ajumad9432e32015-11-30 19:43:44120
sunxdbb0b3ae92017-04-05 21:13:20121 DCHECK(render_pass->quad_list.front());
ajumad9432e32015-11-30 19:43:44122 const RenderPassDrawQuad* quad =
123 RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
sunxdbb0b3ae92017-04-05 21:13:20124 EXPECT_EQ(gfx::RectF(0, 0, 1, 1), quad->mask_uv_rect);
ajumad9432e32015-11-30 19:43:44125 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
126}
127
[email protected]ba0f8d92014-03-21 18:41:10128} // namespace
129} // namespace cc