[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 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7 | #include "cc/layers/append_quads_data.h" |
| 8 | #include "cc/quads/render_pass_draw_quad.h" |
| 9 | #include "cc/test/fake_mask_layer_impl.h" |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 10 | #include "cc/test/layer_test_common.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
| 13 | namespace cc { |
| 14 | namespace { |
| 15 | |
| 16 | TEST(RenderSurfaceLayerImplTest, Occlusion) { |
| 17 | gfx::Size layer_size(1000, 1000); |
| 18 | gfx::Size viewport_size(1000, 1000); |
| 19 | |
| 20 | LayerTestCommon::LayerImplTest impl; |
| 21 | |
| 22 | LayerImpl* owning_layer_impl = impl.AddChildToRoot<LayerImpl>(); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 23 | owning_layer_impl->SetBounds(layer_size); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 24 | owning_layer_impl->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 25 | owning_layer_impl->SetForceRenderSurface(true); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 26 | |
| 27 | impl.CalcDrawProps(viewport_size); |
| 28 | |
| 29 | RenderSurfaceImpl* render_surface_impl = owning_layer_impl->render_surface(); |
| 30 | ASSERT_TRUE(render_surface_impl); |
| 31 | |
| 32 | { |
| 33 | SCOPED_TRACE("No occlusion"); |
| 34 | gfx::Rect occluded; |
| 35 | impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded); |
| 36 | |
| 37 | LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
| 38 | gfx::Rect(layer_size)); |
| 39 | EXPECT_EQ(1u, impl.quad_list().size()); |
| 40 | } |
| 41 | |
| 42 | { |
| 43 | SCOPED_TRACE("Full occlusion"); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 44 | gfx::Rect occluded(owning_layer_impl->visible_layer_rect()); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 45 | impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded); |
| 46 | |
| 47 | LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); |
| 48 | EXPECT_EQ(impl.quad_list().size(), 0u); |
| 49 | } |
| 50 | |
| 51 | { |
| 52 | SCOPED_TRACE("Partial occlusion"); |
| 53 | gfx::Rect occluded(200, 0, 800, 1000); |
| 54 | impl.AppendSurfaceQuadsWithOcclusion(render_surface_impl, occluded); |
| 55 | |
| 56 | size_t partially_occluded_count = 0; |
hartmanng | 53af0fe | 2014-09-22 20:26:11 | [diff] [blame] | 57 | LayerTestCommon::VerifyQuadsAreOccluded( |
| 58 | impl.quad_list(), occluded, &partially_occluded_count); |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 59 | // The layer outputs one quad, which is partially occluded. |
| 60 | EXPECT_EQ(1u, impl.quad_list().size()); |
| 61 | EXPECT_EQ(1u, partially_occluded_count); |
| 62 | } |
| 63 | } |
| 64 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 65 | TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) { |
| 66 | gfx::Size layer_size(1000, 1000); |
| 67 | gfx::Size viewport_size(1000, 1000); |
| 68 | |
| 69 | LayerTestCommon::LayerImplTest impl; |
| 70 | scoped_ptr<LayerImpl> root = |
| 71 | LayerImpl::Create(impl.host_impl()->active_tree(), 2); |
| 72 | root->SetHasRenderSurface(true); |
| 73 | scoped_ptr<LayerImpl> surface = |
| 74 | LayerImpl::Create(impl.host_impl()->active_tree(), 3); |
| 75 | surface->SetBounds(layer_size); |
| 76 | surface->SetHasRenderSurface(true); |
| 77 | |
| 78 | gfx::Transform scale; |
| 79 | scale.Scale(2, 2); |
| 80 | surface->SetTransform(scale); |
| 81 | |
| 82 | surface->SetMaskLayer( |
| 83 | FakeMaskLayerImpl::Create(impl.host_impl()->active_tree(), 4)); |
| 84 | surface->mask_layer()->SetDrawsContent(true); |
| 85 | surface->mask_layer()->SetBounds(layer_size); |
| 86 | |
| 87 | scoped_ptr<LayerImpl> child = |
| 88 | LayerImpl::Create(impl.host_impl()->active_tree(), 5); |
| 89 | child->SetDrawsContent(true); |
| 90 | child->SetBounds(layer_size); |
| 91 | |
| 92 | surface->AddChild(std::move(child)); |
| 93 | root->AddChild(std::move(surface)); |
| 94 | impl.host_impl()->active_tree()->SetRootLayer(std::move(root)); |
| 95 | |
| 96 | impl.host_impl()->SetViewportSize(viewport_size); |
| 97 | impl.host_impl()->active_tree()->BuildPropertyTreesForTesting(); |
| 98 | impl.host_impl()->active_tree()->UpdateDrawProperties(false); |
| 99 | |
| 100 | LayerImpl* surface_raw = |
| 101 | impl.host_impl()->active_tree()->root_layer()->children()[0].get(); |
| 102 | RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface(); |
| 103 | scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 104 | AppendQuadsData append_quads_data; |
| 105 | render_surface_impl->AppendQuads( |
| 106 | render_pass.get(), render_surface_impl->draw_transform(), Occlusion(), |
| 107 | SK_ColorBLACK, 1.f, surface_raw->mask_layer(), &append_quads_data, |
| 108 | RenderPassId(1, 1)); |
| 109 | |
| 110 | const RenderPassDrawQuad* quad = |
| 111 | RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front()); |
| 112 | EXPECT_EQ(gfx::Vector2dF(1.f, 1.f), quad->mask_uv_scale); |
| 113 | EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale); |
| 114 | } |
| 115 | |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 116 | } // namespace |
| 117 | } // namespace cc |