Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: components/exo/surface_unittest.cc

Issue 2066493004: exo: Remove TextureLayer implementation of Surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add todo, format Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/surface.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "components/exo/buffer.h" 6 #include "components/exo/buffer.h"
7 #include "components/exo/surface.h" 7 #include "components/exo/surface.h"
8 #include "components/exo/test/exo_test_base.h" 8 #include "components/exo/test/exo_test_base.h"
9 #include "components/exo/test/exo_test_helper.h" 9 #include "components/exo/test/exo_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/compositor/layer_tree_owner.h" 11 #include "ui/compositor/layer_tree_owner.h"
12 #include "ui/gfx/gpu_memory_buffer.h" 12 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/wm/core/window_util.h" 13 #include "ui/wm/core/window_util.h"
14 14
15 namespace exo { 15 namespace exo {
16 namespace { 16 namespace {
17 17
18 class SurfaceTest : public test::ExoTestBase, 18 using SurfaceTest = test::ExoTestBase;
19 public ::testing::WithParamInterface<bool> {
20 void SetUp() override {
21 Surface::SetUseSurfaceLayer(GetParam());
22 test::ExoTestBase::SetUp();
23 }
24 };
25 19
26 void ReleaseBuffer(int* release_buffer_call_count) { 20 void ReleaseBuffer(int* release_buffer_call_count) {
27 (*release_buffer_call_count)++; 21 (*release_buffer_call_count)++;
28 } 22 }
29 23
30 TEST_P(SurfaceTest, Attach) { 24 TEST_F(SurfaceTest, Attach) {
31 gfx::Size buffer_size(256, 256); 25 gfx::Size buffer_size(256, 256);
32 std::unique_ptr<Buffer> buffer( 26 std::unique_ptr<Buffer> buffer(
33 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 27 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
34 28
35 // Set the release callback that will be run when buffer is no longer in use. 29 // Set the release callback that will be run when buffer is no longer in use.
36 int release_buffer_call_count = 0; 30 int release_buffer_call_count = 0;
37 buffer->set_release_callback( 31 buffer->set_release_callback(
38 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count))); 32 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count)));
39 33
40 std::unique_ptr<Surface> surface(new Surface); 34 std::unique_ptr<Surface> surface(new Surface);
41 35
42 // Attach the buffer to surface1. 36 // Attach the buffer to surface1.
43 surface->Attach(buffer.get()); 37 surface->Attach(buffer.get());
44 surface->Commit(); 38 surface->Commit();
45 39
46 // Commit without calling Attach() should have no effect. 40 // Commit without calling Attach() should have no effect.
47 surface->Commit(); 41 surface->Commit();
48 EXPECT_EQ(0, release_buffer_call_count); 42 EXPECT_EQ(0, release_buffer_call_count);
49 43
50 // Attach a null buffer to surface, this should release the previously 44 // Attach a null buffer to surface, this should release the previously
51 // attached buffer. 45 // attached buffer.
52 surface->Attach(nullptr); 46 surface->Attach(nullptr);
53 surface->Commit(); 47 surface->Commit();
54 ASSERT_EQ(1, release_buffer_call_count); 48 ASSERT_EQ(1, release_buffer_call_count);
55 } 49 }
56 50
57 TEST_P(SurfaceTest, Damage) { 51 TEST_F(SurfaceTest, Damage) {
58 gfx::Size buffer_size(256, 256); 52 gfx::Size buffer_size(256, 256);
59 std::unique_ptr<Buffer> buffer( 53 std::unique_ptr<Buffer> buffer(
60 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 54 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
61 std::unique_ptr<Surface> surface(new Surface); 55 std::unique_ptr<Surface> surface(new Surface);
62 56
63 // Attach the buffer to the surface. This will update the pending bounds of 57 // Attach the buffer to the surface. This will update the pending bounds of
64 // the surface to the buffer size. 58 // the surface to the buffer size.
65 surface->Attach(buffer.get()); 59 surface->Attach(buffer.get());
66 60
67 // Mark areas inside the bounds of the surface as damaged. This should result 61 // Mark areas inside the bounds of the surface as damaged. This should result
68 // in pending damage. 62 // in pending damage.
69 surface->Damage(gfx::Rect(0, 0, 10, 10)); 63 surface->Damage(gfx::Rect(0, 0, 10, 10));
70 surface->Damage(gfx::Rect(10, 10, 10, 10)); 64 surface->Damage(gfx::Rect(10, 10, 10, 10));
71 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(0, 0, 10, 10))); 65 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(0, 0, 10, 10)));
72 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(10, 10, 10, 10))); 66 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(10, 10, 10, 10)));
73 EXPECT_FALSE(surface->HasPendingDamageForTesting(gfx::Rect(5, 5, 10, 10))); 67 EXPECT_FALSE(surface->HasPendingDamageForTesting(gfx::Rect(5, 5, 10, 10)));
74 } 68 }
75 69
76 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) { 70 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) {
77 *result = frame_time; 71 *result = frame_time;
78 } 72 }
79 73
80 TEST_P(SurfaceTest, RequestFrameCallback) { 74 TEST_F(SurfaceTest, RequestFrameCallback) {
81 std::unique_ptr<Surface> surface(new Surface); 75 std::unique_ptr<Surface> surface(new Surface);
82 76
83 base::TimeTicks frame_time; 77 base::TimeTicks frame_time;
84 surface->RequestFrameCallback( 78 surface->RequestFrameCallback(
85 base::Bind(&SetFrameTime, base::Unretained(&frame_time))); 79 base::Bind(&SetFrameTime, base::Unretained(&frame_time)));
86 surface->Commit(); 80 surface->Commit();
87 81
88 // Callback should not run synchronously. 82 // Callback should not run synchronously.
89 EXPECT_TRUE(frame_time.is_null()); 83 EXPECT_TRUE(frame_time.is_null());
90 } 84 }
91 85
92 TEST_P(SurfaceTest, SetOpaqueRegion) { 86 TEST_F(SurfaceTest, SetOpaqueRegion) {
93 std::unique_ptr<Surface> surface(new Surface); 87 std::unique_ptr<Surface> surface(new Surface);
94 88
95 // Setting a non-empty opaque region should succeed. 89 // Setting a non-empty opaque region should succeed.
96 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeWH(256, 256))); 90 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeWH(256, 256)));
97 91
98 // Setting an empty opaque region should succeed. 92 // Setting an empty opaque region should succeed.
99 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeEmpty())); 93 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeEmpty()));
100 } 94 }
101 95
102 TEST_P(SurfaceTest, SetInputRegion) { 96 TEST_F(SurfaceTest, SetInputRegion) {
103 std::unique_ptr<Surface> surface(new Surface); 97 std::unique_ptr<Surface> surface(new Surface);
104 98
105 // Setting a non-empty input region should succeed. 99 // Setting a non-empty input region should succeed.
106 surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256))); 100 surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256)));
107 101
108 // Setting an empty input region should succeed. 102 // Setting an empty input region should succeed.
109 surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty())); 103 surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty()));
110 } 104 }
111 105
112 TEST_P(SurfaceTest, SetBufferScale) { 106 TEST_F(SurfaceTest, SetBufferScale) {
113 gfx::Size buffer_size(512, 512); 107 gfx::Size buffer_size(512, 512);
114 std::unique_ptr<Buffer> buffer( 108 std::unique_ptr<Buffer> buffer(
115 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 109 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
116 std::unique_ptr<Surface> surface(new Surface); 110 std::unique_ptr<Surface> surface(new Surface);
117 111
118 // This will update the bounds of the surface and take the buffer scale into 112 // This will update the bounds of the surface and take the buffer scale into
119 // account. 113 // account.
120 const float kBufferScale = 2.0f; 114 const float kBufferScale = 2.0f;
121 surface->Attach(buffer.get()); 115 surface->Attach(buffer.get());
122 surface->SetBufferScale(kBufferScale); 116 surface->SetBufferScale(kBufferScale);
123 surface->Commit(); 117 surface->Commit();
124 EXPECT_EQ( 118 EXPECT_EQ(
125 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(), 119 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(),
126 surface->window()->bounds().size().ToString()); 120 surface->window()->bounds().size().ToString());
127 } 121 }
128 122
129 TEST_P(SurfaceTest, RecreateLayer) { 123 TEST_F(SurfaceTest, RecreateLayer) {
130 gfx::Size buffer_size(512, 512); 124 gfx::Size buffer_size(512, 512);
131 std::unique_ptr<Buffer> buffer( 125 std::unique_ptr<Buffer> buffer(
132 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 126 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
133 std::unique_ptr<Surface> surface(new Surface); 127 std::unique_ptr<Surface> surface(new Surface);
134 128
135 surface->Attach(buffer.get()); 129 surface->Attach(buffer.get());
136 surface->Commit(); 130 surface->Commit();
137 131
138 EXPECT_EQ(buffer_size, surface->window()->bounds().size()); 132 EXPECT_EQ(buffer_size, surface->window()->bounds().size());
139 EXPECT_EQ(buffer_size, surface->window()->layer()->bounds().size()); 133 EXPECT_EQ(buffer_size, surface->window()->layer()->bounds().size());
140 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner = 134 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner =
141 ::wm::RecreateLayers(surface->window(), nullptr); 135 ::wm::RecreateLayers(surface->window(), nullptr);
142 EXPECT_EQ(buffer_size, surface->window()->bounds().size()); 136 EXPECT_EQ(buffer_size, surface->window()->bounds().size());
143 EXPECT_EQ(buffer_size, surface->window()->layer()->bounds().size()); 137 EXPECT_EQ(buffer_size, surface->window()->layer()->bounds().size());
144 EXPECT_EQ(buffer_size, old_layer_owner->root()->bounds().size()); 138 EXPECT_EQ(buffer_size, old_layer_owner->root()->bounds().size());
145 EXPECT_TRUE(surface->window()->layer()->has_external_content()); 139 EXPECT_TRUE(surface->window()->layer()->has_external_content());
146 EXPECT_TRUE(old_layer_owner->root()->has_external_content()); 140 EXPECT_TRUE(old_layer_owner->root()->has_external_content());
147 } 141 }
148 142
149 TEST_P(SurfaceTest, SetViewport) { 143 TEST_F(SurfaceTest, SetViewport) {
150 gfx::Size buffer_size(1, 1); 144 gfx::Size buffer_size(1, 1);
151 std::unique_ptr<Buffer> buffer( 145 std::unique_ptr<Buffer> buffer(
152 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 146 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
153 std::unique_ptr<Surface> surface(new Surface); 147 std::unique_ptr<Surface> surface(new Surface);
154 148
155 // This will update the bounds of the surface and take the viewport into 149 // This will update the bounds of the surface and take the viewport into
156 // account. 150 // account.
157 surface->Attach(buffer.get()); 151 surface->Attach(buffer.get());
158 gfx::Size viewport(256, 256); 152 gfx::Size viewport(256, 256);
159 surface->SetViewport(viewport); 153 surface->SetViewport(viewport);
160 surface->Commit(); 154 surface->Commit();
161 EXPECT_EQ(viewport.ToString(), surface->window()->bounds().size().ToString()); 155 EXPECT_EQ(viewport.ToString(), surface->window()->bounds().size().ToString());
162 156
163 // This will update the bounds of the surface and take the viewport2 into 157 // This will update the bounds of the surface and take the viewport2 into
164 // account. 158 // account.
165 gfx::Size viewport2(512, 512); 159 gfx::Size viewport2(512, 512);
166 surface->SetViewport(viewport2); 160 surface->SetViewport(viewport2);
167 surface->Commit(); 161 surface->Commit();
168 EXPECT_EQ(viewport2.ToString(), 162 EXPECT_EQ(viewport2.ToString(),
169 surface->window()->bounds().size().ToString()); 163 surface->window()->bounds().size().ToString());
170 } 164 }
171 165
172 TEST_P(SurfaceTest, SetCrop) { 166 TEST_F(SurfaceTest, SetCrop) {
173 gfx::Size buffer_size(16, 16); 167 gfx::Size buffer_size(16, 16);
174 std::unique_ptr<Buffer> buffer( 168 std::unique_ptr<Buffer> buffer(
175 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 169 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
176 std::unique_ptr<Surface> surface(new Surface); 170 std::unique_ptr<Surface> surface(new Surface);
177 171
178 surface->Attach(buffer.get()); 172 surface->Attach(buffer.get());
179 gfx::Size crop_size(12, 12); 173 gfx::Size crop_size(12, 12);
180 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size))); 174 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size)));
181 surface->Commit(); 175 surface->Commit();
182 EXPECT_EQ(crop_size.ToString(), 176 EXPECT_EQ(crop_size.ToString(),
183 surface->window()->bounds().size().ToString()); 177 surface->window()->bounds().size().ToString());
184 } 178 }
185 179
186 TEST_P(SurfaceTest, SetOnlyVisibleOnSecureOutput) { 180 TEST_F(SurfaceTest, SetBlendMode) {
187 // SurfaceLayer doesn't have texture mailbox, so it can't be tested this
188 // way.
189 if (GetParam())
190 return;
191 gfx::Size buffer_size(1, 1); 181 gfx::Size buffer_size(1, 1);
192 std::unique_ptr<Buffer> buffer( 182 std::unique_ptr<Buffer> buffer(
193 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 183 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
194 std::unique_ptr<Surface> surface(new Surface);
195
196 surface->Attach(buffer.get());
197 surface->SetOnlyVisibleOnSecureOutput(true);
198 surface->Commit();
199
200 cc::TextureMailbox mailbox;
201 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
202 bool rv = surface->window()->layer()->PrepareTextureMailbox(
203 &mailbox, &release_callback, false);
204 ASSERT_TRUE(rv);
205
206 EXPECT_TRUE(mailbox.secure_output_only());
207 release_callback->Run(gpu::SyncToken(), false);
208 }
209
210 TEST_P(SurfaceTest, SetBlendMode) {
211 gfx::Size buffer_size(1, 1);
212 std::unique_ptr<Buffer> buffer(
213 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
214 std::unique_ptr<Surface> surface(new Surface); 184 std::unique_ptr<Surface> surface(new Surface);
215 185
216 surface->Attach(buffer.get()); 186 surface->Attach(buffer.get());
217 surface->SetBlendMode(SkXfermode::kSrc_Mode); 187 surface->SetBlendMode(SkXfermode::kSrc_Mode);
218 surface->Commit(); 188 surface->Commit();
219 189
220 EXPECT_TRUE(surface->window()->layer()->fills_bounds_opaquely()); 190 EXPECT_TRUE(surface->window()->layer()->fills_bounds_opaquely());
221 } 191 }
222 192
223 TEST_P(SurfaceTest, SetAlpha) { 193 TEST_F(SurfaceTest, SetAlpha) {
224 gfx::Size buffer_size(1, 1); 194 gfx::Size buffer_size(1, 1);
225 std::unique_ptr<Buffer> buffer( 195 std::unique_ptr<Buffer> buffer(
226 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 196 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
227 std::unique_ptr<Surface> surface(new Surface); 197 std::unique_ptr<Surface> surface(new Surface);
228 198
229 surface->Attach(buffer.get()); 199 surface->Attach(buffer.get());
230 surface->SetAlpha(0.5f); 200 surface->SetAlpha(0.5f);
231 surface->Commit(); 201 surface->Commit();
232 } 202 }
233 203
234 TEST_P(SurfaceTest, Commit) { 204 TEST_F(SurfaceTest, Commit) {
235 std::unique_ptr<Surface> surface(new Surface); 205 std::unique_ptr<Surface> surface(new Surface);
236 206
237 // Calling commit without a buffer should succeed. 207 // Calling commit without a buffer should succeed.
238 surface->Commit(); 208 surface->Commit();
239 } 209 }
240 210
241 INSTANTIATE_TEST_CASE_P(, SurfaceTest, ::testing::Bool());
242
243 } // namespace 211 } // namespace
244 } // namespace exo 212 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/surface.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698