[go: nahoru, domu]

blob: aa44f9337432554ae4e60896b8856b55cca73d46 [file] [log] [blame]
danakj@chromium.org654d97a32014-03-19 23:27:571// 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/texture_layer_impl.h"
6
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj@chromium.org654d97a32014-03-19 23:27:579#include "cc/output/context_provider.h"
danakjc7afae52017-06-20 21:12:4110#include "cc/output/layer_tree_frame_sink.h"
dcastagna26563f42016-03-08 23:45:4811#include "cc/quads/draw_quad.h"
jbauman0c1bf21132016-05-19 19:20:0712#include "cc/quads/texture_draw_quad.h"
danakjc7afae52017-06-20 21:12:4113#include "cc/test/fake_layer_tree_frame_sink.h"
danakj@chromium.org654d97a32014-03-19 23:27:5714#include "cc/test/layer_test_common.h"
danakjffc181a2016-07-22 22:48:4315#include "gpu/command_buffer/client/gles2_interface.h"
danakj@chromium.org654d97a32014-03-19 23:27:5716#include "testing/gtest/include/gtest/gtest.h"
17
18namespace cc {
19namespace {
20
dyencc16ed4d2015-11-03 20:03:0421void IgnoreCallback(const gpu::SyncToken& sync_token,
skyostil3976a3f2014-09-04 22:07:2322 bool lost,
dyencc16ed4d2015-11-03 20:03:0423 BlockingTaskRunner* main_thread_task_runner) {}
danakj@chromium.org654d97a32014-03-19 23:27:5724
danakj64767d902015-06-19 00:10:4325TEST(TextureLayerImplTest, VisibleOpaqueRegion) {
26 const gfx::Size layer_bounds(100, 100);
27 const gfx::Rect layer_rect(layer_bounds);
28 const Region layer_region(layer_rect);
29
30 LayerTestCommon::LayerImplTest impl;
31
32 TextureLayerImpl* layer = impl.AddChildToRoot<TextureLayerImpl>();
33 layer->SetBounds(layer_bounds);
34 layer->draw_properties().visible_layer_rect = layer_rect;
35 layer->SetBlendBackgroundColor(true);
36
37 // Verify initial conditions.
38 EXPECT_FALSE(layer->contents_opaque());
39 EXPECT_EQ(0u, layer->background_color());
40 EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
41
42 // Opaque background.
43 layer->SetBackgroundColor(SK_ColorWHITE);
44 EXPECT_EQ(layer_region.ToString(), layer->VisibleOpaqueRegion().ToString());
45
46 // Transparent background.
47 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255));
48 EXPECT_EQ(Region().ToString(), layer->VisibleOpaqueRegion().ToString());
49}
50
danakj@chromium.org654d97a32014-03-19 23:27:5751TEST(TextureLayerImplTest, Occlusion) {
52 gfx::Size layer_size(1000, 1000);
53 gfx::Size viewport_size(1000, 1000);
54
55 LayerTestCommon::LayerImplTest impl;
56
57 gpu::Mailbox mailbox;
danakjc7afae52017-06-20 21:12:4158 impl.layer_tree_frame_sink()
danakj1120f4c2016-09-15 02:05:3259 ->context_provider()
60 ->ContextGL()
61 ->GenMailboxCHROMIUM(mailbox.name);
dyene5db881b2016-03-01 19:47:0362 TextureMailbox texture_mailbox(
63 mailbox,
64 gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123,
65 gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
66 GL_TEXTURE_2D);
danakj@chromium.org654d97a32014-03-19 23:27:5767
danakj@chromium.org654d97a32014-03-19 23:27:5768 TextureLayerImpl* texture_layer_impl =
piman@chromium.org17e08432014-04-10 00:41:1169 impl.AddChildToRoot<TextureLayerImpl>();
danakj@chromium.org654d97a32014-03-19 23:27:5770 texture_layer_impl->SetBounds(layer_size);
danakj@chromium.org654d97a32014-03-19 23:27:5771 texture_layer_impl->SetDrawsContent(true);
72 texture_layer_impl->SetTextureMailbox(
73 texture_mailbox,
skyostil3976a3f2014-09-04 22:07:2374 SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));
danakj@chromium.org654d97a32014-03-19 23:27:5775
76 impl.CalcDrawProps(viewport_size);
77
78 {
79 SCOPED_TRACE("No occlusion");
80 gfx::Rect occluded;
81 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
82
83 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
84 gfx::Rect(layer_size));
85 EXPECT_EQ(1u, impl.quad_list().size());
86 }
87
88 {
89 SCOPED_TRACE("Full occlusion");
danakj64767d902015-06-19 00:10:4390 gfx::Rect occluded(texture_layer_impl->visible_layer_rect());
danakj@chromium.org654d97a32014-03-19 23:27:5791 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
92
93 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
94 EXPECT_EQ(impl.quad_list().size(), 0u);
95 }
96
97 {
98 SCOPED_TRACE("Partial occlusion");
99 gfx::Rect occluded(200, 0, 800, 1000);
100 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
101
102 size_t partially_occluded_count = 0;
hartmanng53af0fe2014-09-22 20:26:11103 LayerTestCommon::VerifyQuadsAreOccluded(
104 impl.quad_list(), occluded, &partially_occluded_count);
danakj@chromium.org654d97a32014-03-19 23:27:57105 // The layer outputs one quad, which is partially occluded.
106 EXPECT_EQ(1u, impl.quad_list().size());
107 EXPECT_EQ(1u, partially_occluded_count);
108 }
109}
110
dcastagna1e6a2bc2016-03-22 21:30:50111TEST(TextureLayerImplTest, OutputIsSecure) {
dcastagna26563f42016-03-08 23:45:48112 gfx::Size layer_size(1000, 1000);
113 gfx::Size viewport_size(1000, 1000);
114
115 LayerTestCommon::LayerImplTest impl;
116
117 gpu::Mailbox mailbox;
danakjc7afae52017-06-20 21:12:41118 impl.layer_tree_frame_sink()
danakj1120f4c2016-09-15 02:05:32119 ->context_provider()
120 ->ContextGL()
121 ->GenMailboxCHROMIUM(mailbox.name);
dcastagna26563f42016-03-08 23:45:48122 TextureMailbox texture_mailbox(
123 mailbox,
124 gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123,
125 gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
ccameron399d94a2016-06-22 03:08:58126 GL_TEXTURE_2D, layer_size, false, true);
dcastagna26563f42016-03-08 23:45:48127
128 TextureLayerImpl* texture_layer_impl =
129 impl.AddChildToRoot<TextureLayerImpl>();
130 texture_layer_impl->SetBounds(layer_size);
131 texture_layer_impl->SetDrawsContent(true);
132 texture_layer_impl->SetTextureMailbox(
133 texture_mailbox,
134 SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));
135
136 impl.CalcDrawProps(viewport_size);
137
138 {
139 gfx::Rect occluded;
140 impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
141
142 EXPECT_EQ(1u, impl.quad_list().size());
jbauman0c1bf21132016-05-19 19:20:07143 ASSERT_EQ(DrawQuad::Material::TEXTURE_CONTENT,
dcastagna26563f42016-03-08 23:45:48144 impl.quad_list().front()->material);
jbauman0c1bf21132016-05-19 19:20:07145 const TextureDrawQuad* quad =
146 TextureDrawQuad::MaterialCast(impl.quad_list().front());
147 EXPECT_TRUE(quad->secure_output_only);
dcastagna26563f42016-03-08 23:45:48148 }
149}
150
ericrk7cedb542016-11-02 19:03:44151TEST(TextureLayerImplTest, ResourceNotFreedOnGpuRasterToggle) {
krasin360dee22016-12-20 22:07:03152 bool released = false;
ericrk41a1579e2017-02-10 20:56:28153 LayerTestCommon::LayerImplTest impl(
danakjc7afae52017-06-20 21:12:41154 FakeLayerTreeFrameSink::Create3dForGpuRasterization());
ericrk7cedb542016-11-02 19:03:44155 impl.host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
156
157 gfx::Size layer_size(1000, 1000);
158 gfx::Size viewport_size(1000, 1000);
159
160 gpu::Mailbox mailbox;
danakjc7afae52017-06-20 21:12:41161 impl.layer_tree_frame_sink()
ericrk7cedb542016-11-02 19:03:44162 ->context_provider()
163 ->ContextGL()
164 ->GenMailboxCHROMIUM(mailbox.name);
165 TextureMailbox texture_mailbox(
166 mailbox,
167 gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123,
168 gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
169 GL_TEXTURE_2D);
170
171 TextureLayerImpl* texture_layer_impl =
172 impl.AddChildToRoot<TextureLayerImpl>();
173 texture_layer_impl->SetBounds(layer_size);
174 texture_layer_impl->SetDrawsContent(true);
ericrk7cedb542016-11-02 19:03:44175 texture_layer_impl->SetTextureMailbox(
176 texture_mailbox,
177 SingleReleaseCallbackImpl::Create(base::Bind(
178 [](bool* released, const gpu::SyncToken& sync_token, bool lost,
179 BlockingTaskRunner* main_thread_task_runner) { *released = true; },
180 base::Unretained(&released))));
181
182 impl.CalcDrawProps(viewport_size);
183
184 // Gpu rasterization is disabled by default.
185 EXPECT_FALSE(impl.host_impl()->use_gpu_rasterization());
186 EXPECT_FALSE(released);
187 // Toggling the gpu rasterization clears all tilings on both trees.
188 impl.host_impl()->SetHasGpuRasterizationTrigger(true);
189 impl.host_impl()->SetContentIsSuitableForGpuRasterization(true);
190 impl.host_impl()->CommitComplete();
191 EXPECT_TRUE(impl.host_impl()->use_gpu_rasterization());
192 EXPECT_FALSE(released);
193}
194
danakj@chromium.org654d97a32014-03-19 23:27:57195} // namespace
196} // namespace cc