Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / layers / texture_layer_impl_unittest.cc
blob27efd971502dc2a2012ae7955392532d052cf4d7
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"
12 namespace cc {
13 namespace {
15 void IgnoreCallback(uint32 sync_point,
16 bool lost,
17 BlockingTaskRunner* main_thread_task_runner) {
20 TEST(TextureLayerImplTest, VisibleOpaqueRegion) {
21 const gfx::Size layer_bounds(100, 100);
22 const gfx::Rect layer_rect(layer_bounds);
23 const Region layer_region(layer_rect);
25 LayerTestCommon::LayerImplTest impl;
27 TextureLayerImpl* layer = impl.AddChildToRoot<TextureLayerImpl>();
28 layer->SetBounds(layer_bounds);
29 layer->draw_properties().visible_layer_rect = layer_rect;
30 layer->SetBlendBackgroundColor(true);
32 // Verify initial conditions.
33 EXPECT_FALSE(layer->contents_opaque());
34 EXPECT_EQ(0u, layer->background_color());
35 EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
37 // Opaque background.
38 layer->SetBackgroundColor(SK_ColorWHITE);
39 EXPECT_EQ(layer_region.ToString(), layer->VisibleOpaqueRegion().ToString());
41 // Transparent background.
42 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255));
43 EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
46 TEST(TextureLayerImplTest, Occlusion) {
47 gfx::Size layer_size(1000, 1000);
48 gfx::Size viewport_size(1000, 1000);
50 LayerTestCommon::LayerImplTest impl;
52 gpu::Mailbox mailbox;
53 impl.output_surface()->context_provider()->ContextGL()->GenMailboxCHROMIUM(
54 mailbox.name);
55 TextureMailbox texture_mailbox(mailbox, GL_TEXTURE_2D, 0);
57 TextureLayerImpl* texture_layer_impl =
58 impl.AddChildToRoot<TextureLayerImpl>();
59 texture_layer_impl->SetBounds(layer_size);
60 texture_layer_impl->SetDrawsContent(true);
61 texture_layer_impl->SetTextureMailbox(
62 texture_mailbox,
63 SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));
65 impl.CalcDrawProps(viewport_size);
68 SCOPED_TRACE("No occlusion");
69 gfx::Rect occluded;
70 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
72 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
73 gfx::Rect(layer_size));
74 EXPECT_EQ(1u, impl.quad_list().size());
78 SCOPED_TRACE("Full occlusion");
79 gfx::Rect occluded(texture_layer_impl->visible_layer_rect());
80 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
82 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
83 EXPECT_EQ(impl.quad_list().size(), 0u);
87 SCOPED_TRACE("Partial occlusion");
88 gfx::Rect occluded(200, 0, 800, 1000);
89 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
91 size_t partially_occluded_count = 0;
92 LayerTestCommon::VerifyQuadsAreOccluded(
93 impl.quad_list(), occluded, &partially_occluded_count);
94 // The layer outputs one quad, which is partially occluded.
95 EXPECT_EQ(1u, impl.quad_list().size());
96 EXPECT_EQ(1u, partially_occluded_count);
100 } // namespace
101 } // namespace cc