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.
5 #include "cc/layers/texture_layer_impl.h"
7 #include "cc/output/context_provider.h"
8 #include "cc/output/output_surface.h"
9 #include "cc/test/layer_test_common.h"
10 #include "testing/gtest/include/gtest/gtest.h"
15 void IgnoreCallback(uint32 sync_point
, bool lost
) {}
17 TEST(TextureLayerImplTest
, Occlusion
) {
18 gfx::Size
layer_size(1000, 1000);
19 gfx::Size
viewport_size(1000, 1000);
21 LayerTestCommon::LayerImplTest impl
;
24 impl
.output_surface()->context_provider()->ContextGL()->GenMailboxCHROMIUM(
26 TextureMailbox
texture_mailbox(mailbox
, GL_TEXTURE_2D
, 0);
28 TextureLayerImpl
* texture_layer_impl
=
29 impl
.AddChildToRoot
<TextureLayerImpl
>();
30 texture_layer_impl
->SetBounds(layer_size
);
31 texture_layer_impl
->SetContentBounds(layer_size
);
32 texture_layer_impl
->SetDrawsContent(true);
33 texture_layer_impl
->SetTextureMailbox(
35 SingleReleaseCallback::Create(base::Bind(&IgnoreCallback
)));
37 impl
.CalcDrawProps(viewport_size
);
40 SCOPED_TRACE("No occlusion");
42 impl
.AppendQuadsWithOcclusion(texture_layer_impl
, occluded
);
44 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
45 gfx::Rect(layer_size
));
46 EXPECT_EQ(1u, impl
.quad_list().size());
50 SCOPED_TRACE("Full occlusion");
51 gfx::Rect
occluded(texture_layer_impl
->visible_content_rect());
52 impl
.AppendQuadsWithOcclusion(texture_layer_impl
, occluded
);
54 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
55 EXPECT_EQ(impl
.quad_list().size(), 0u);
59 SCOPED_TRACE("Partial occlusion");
60 gfx::Rect
occluded(200, 0, 800, 1000);
61 impl
.AppendQuadsWithOcclusion(texture_layer_impl
, occluded
);
63 size_t partially_occluded_count
= 0;
64 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
66 gfx::Rect(layer_size
),
68 &partially_occluded_count
);
69 // The layer outputs one quad, which is partially occluded.
70 EXPECT_EQ(1u, impl
.quad_list().size());
71 EXPECT_EQ(1u, partially_occluded_count
);