danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [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/texture_layer_impl.h" |
| 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 9 | #include "cc/output/context_provider.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 10 | #include "cc/output/layer_tree_frame_sink.h" |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 11 | #include "cc/quads/draw_quad.h" |
jbauman | 0c1bf2113 | 2016-05-19 19:20:07 | [diff] [blame] | 12 | #include "cc/quads/texture_draw_quad.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 13 | #include "cc/test/fake_layer_tree_frame_sink.h" |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 14 | #include "cc/test/layer_test_common.h" |
danakj | ffc181a | 2016-07-22 22:48:43 | [diff] [blame] | 15 | #include "gpu/command_buffer/client/gles2_interface.h" |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
| 18 | namespace cc { |
| 19 | namespace { |
| 20 | |
dyen | cc16ed4d | 2015-11-03 20:03:04 | [diff] [blame] | 21 | void IgnoreCallback(const gpu::SyncToken& sync_token, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 22 | bool lost, |
dyen | cc16ed4d | 2015-11-03 20:03:04 | [diff] [blame] | 23 | BlockingTaskRunner* main_thread_task_runner) {} |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 24 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 25 | TEST(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.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 51 | TEST(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; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 58 | impl.layer_tree_frame_sink() |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 59 | ->context_provider() |
| 60 | ->ContextGL() |
| 61 | ->GenMailboxCHROMIUM(mailbox.name); |
dyen | e5db881b | 2016-03-01 19:47:03 | [diff] [blame] | 62 | 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.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 67 | |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 68 | TextureLayerImpl* texture_layer_impl = |
piman@chromium.org | 17e0843 | 2014-04-10 00:41:11 | [diff] [blame] | 69 | impl.AddChildToRoot<TextureLayerImpl>(); |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 70 | texture_layer_impl->SetBounds(layer_size); |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 71 | texture_layer_impl->SetDrawsContent(true); |
| 72 | texture_layer_impl->SetTextureMailbox( |
| 73 | texture_mailbox, |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 74 | SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback))); |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 75 | |
| 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"); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 90 | gfx::Rect occluded(texture_layer_impl->visible_layer_rect()); |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 91 | 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; |
hartmanng | 53af0fe | 2014-09-22 20:26:11 | [diff] [blame] | 103 | LayerTestCommon::VerifyQuadsAreOccluded( |
| 104 | impl.quad_list(), occluded, &partially_occluded_count); |
danakj@chromium.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 105 | // 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 | |
dcastagna | 1e6a2bc | 2016-03-22 21:30:50 | [diff] [blame] | 111 | TEST(TextureLayerImplTest, OutputIsSecure) { |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 112 | gfx::Size layer_size(1000, 1000); |
| 113 | gfx::Size viewport_size(1000, 1000); |
| 114 | |
| 115 | LayerTestCommon::LayerImplTest impl; |
| 116 | |
| 117 | gpu::Mailbox mailbox; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 118 | impl.layer_tree_frame_sink() |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 119 | ->context_provider() |
| 120 | ->ContextGL() |
| 121 | ->GenMailboxCHROMIUM(mailbox.name); |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 122 | TextureMailbox texture_mailbox( |
| 123 | mailbox, |
| 124 | gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123, |
| 125 | gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456), |
ccameron | 399d94a | 2016-06-22 03:08:58 | [diff] [blame] | 126 | GL_TEXTURE_2D, layer_size, false, true); |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 127 | |
| 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()); |
jbauman | 0c1bf2113 | 2016-05-19 19:20:07 | [diff] [blame] | 143 | ASSERT_EQ(DrawQuad::Material::TEXTURE_CONTENT, |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 144 | impl.quad_list().front()->material); |
jbauman | 0c1bf2113 | 2016-05-19 19:20:07 | [diff] [blame] | 145 | const TextureDrawQuad* quad = |
| 146 | TextureDrawQuad::MaterialCast(impl.quad_list().front()); |
| 147 | EXPECT_TRUE(quad->secure_output_only); |
dcastagna | 26563f4 | 2016-03-08 23:45:48 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
ericrk | 7cedb54 | 2016-11-02 19:03:44 | [diff] [blame] | 151 | TEST(TextureLayerImplTest, ResourceNotFreedOnGpuRasterToggle) { |
krasin | 360dee2 | 2016-12-20 22:07:03 | [diff] [blame] | 152 | bool released = false; |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 153 | LayerTestCommon::LayerImplTest impl( |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 154 | FakeLayerTreeFrameSink::Create3dForGpuRasterization()); |
ericrk | 7cedb54 | 2016-11-02 19:03:44 | [diff] [blame] | 155 | 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; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 161 | impl.layer_tree_frame_sink() |
ericrk | 7cedb54 | 2016-11-02 19:03:44 | [diff] [blame] | 162 | ->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); |
ericrk | 7cedb54 | 2016-11-02 19:03:44 | [diff] [blame] | 175 | 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.org | 654d97a3 | 2014-03-19 23:27:57 | [diff] [blame] | 195 | } // namespace |
| 196 | } // namespace cc |