[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); |
| 74 | root->SetHasRenderSurface(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 75 | std::unique_ptr<LayerImpl> surface = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 76 | 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 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 84 | surface->test_properties()->SetMaskLayer( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 85 | FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4)); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 86 | surface->test_properties()->mask_layer->SetDrawsContent(true); |
| 87 | surface->test_properties()->mask_layer->SetBounds(layer_size); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 88 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 89 | std::unique_ptr<LayerImpl> child = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 90 | LayerImpl::Create(impl.host_impl()->active_tree(), 5); |
| 91 | child->SetDrawsContent(true); |
| 92 | child->SetBounds(layer_size); |
| 93 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame^] | 94 | surface->test_properties()->AddChild(std::move(child)); |
| 95 | root->test_properties()->AddChild(std::move(surface)); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 96 | impl.host_impl()->active_tree()->SetRootLayer(std::move(root)); |
| 97 | |
| 98 | impl.host_impl()->SetViewportSize(viewport_size); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 99 | impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 100 | impl.host_impl()->active_tree()->UpdateDrawProperties(false); |
| 101 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 102 | LayerImpl* surface_raw = impl.host_impl() |
| 103 | ->active_tree() |
| 104 | ->root_layer() |
| 105 | ->test_properties() |
| 106 | ->children[0]; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 107 | RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 108 | std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 109 | AppendQuadsData append_quads_data; |
| 110 | render_surface_impl->AppendQuads( |
| 111 | render_pass.get(), render_surface_impl->draw_transform(), Occlusion(), |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 112 | SK_ColorBLACK, 1.f, render_surface_impl->MaskLayer(), &append_quads_data, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 113 | RenderPassId(1, 1)); |
| 114 | |
| 115 | const RenderPassDrawQuad* quad = |
| 116 | RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front()); |
senorblanco | dfcb362 | 2016-01-27 21:48:01 | [diff] [blame] | 117 | EXPECT_EQ(gfx::Vector2dF(0.0005f, 0.0005f), quad->mask_uv_scale); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 118 | EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale); |
| 119 | } |
| 120 | |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 121 | } // namespace |
| 122 | } // namespace cc |