[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 1 | // 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 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 9 | #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] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 12 | #include "cc/test/layer_test_common.h" |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
| 15 | namespace cc { |
| 16 | namespace { |
| 17 | |
| 18 | TEST(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] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 25 | owning_layer_impl->SetBounds(layer_size); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 26 | owning_layer_impl->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 27 | owning_layer_impl->test_properties()->force_render_surface = true; |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 28 | |
| 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"); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 46 | gfx::Rect occluded(owning_layer_impl->visible_layer_rect()); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 47 | 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; |
hartmanng | 53af0fe | 2014-09-22 20:26:11 | [diff] [blame] | 59 | LayerTestCommon::VerifyQuadsAreOccluded( |
| 60 | impl.quad_list(), occluded, &partially_occluded_count); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 61 | // 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 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 67 | TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) { |
| 68 | gfx::Size layer_size(1000, 1000); |
| 69 | gfx::Size viewport_size(1000, 1000); |
| 70 | |
| 71 | LayerTestCommon::LayerImplTest impl; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 72 | std::unique_ptr<LayerImpl> root = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 73 | LayerImpl::Create(impl.host_impl()->active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 74 | std::unique_ptr<LayerImpl> surface = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 75 | LayerImpl::Create(impl.host_impl()->active_tree(), 3); |
| 76 | surface->SetBounds(layer_size); |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame^] | 77 | surface->test_properties()->force_render_surface = true; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 78 | |
| 79 | gfx::Transform scale; |
| 80 | scale.Scale(2, 2); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 81 | surface->test_properties()->transform = scale; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 82 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 83 | surface->test_properties()->SetMaskLayer( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 84 | FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4)); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 85 | surface->test_properties()->mask_layer->SetDrawsContent(true); |
| 86 | surface->test_properties()->mask_layer->SetBounds(layer_size); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 87 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 88 | std::unique_ptr<LayerImpl> child = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 89 | LayerImpl::Create(impl.host_impl()->active_tree(), 5); |
| 90 | child->SetDrawsContent(true); |
| 91 | child->SetBounds(layer_size); |
| 92 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 93 | surface->test_properties()->AddChild(std::move(child)); |
| 94 | root->test_properties()->AddChild(std::move(surface)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 95 | impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root)); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 96 | |
| 97 | impl.host_impl()->SetViewportSize(viewport_size); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 98 | impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 99 | impl.host_impl()->active_tree()->UpdateDrawProperties(false); |
| 100 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 101 | LayerImpl* surface_raw = impl.host_impl() |
| 102 | ->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 103 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 104 | ->test_properties() |
| 105 | ->children[0]; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 106 | RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 107 | std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 108 | AppendQuadsData append_quads_data; |
ajuma | 3e64b9d5 | 2016-11-22 18:38:19 | [diff] [blame] | 109 | render_surface_impl->AppendQuads(render_pass.get(), &append_quads_data); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 110 | |
| 111 | const RenderPassDrawQuad* quad = |
| 112 | RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front()); |
senorblanco | dfcb362 | 2016-01-27 21:48:01 | [diff] [blame] | 113 | EXPECT_EQ(gfx::Vector2dF(0.0005f, 0.0005f), quad->mask_uv_scale); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 114 | EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale); |
| 115 | } |
| 116 | |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 117 | } // namespace |
| 118 | } // namespace cc |