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

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

Issue 2008153002: Add initial implementation of cc::Surfaces backend for exo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/gfx/gpu_memory_buffer.h" 11 #include "ui/gfx/gpu_memory_buffer.h"
12 12
13 namespace exo { 13 namespace exo {
14 namespace { 14 namespace {
15 15
16 using SurfaceTest = test::ExoTestBase; 16 class SurfaceTest : public test::ExoTestBase,
17 public ::testing::WithParamInterface<bool> {
18 void SetUp() override {
19 Surface::SetUseSurfaceLayer(GetParam());
20 test::ExoTestBase::SetUp();
21 }
22 };
17 23
18 void ReleaseBuffer(int* release_buffer_call_count) { 24 void ReleaseBuffer(int* release_buffer_call_count) {
19 (*release_buffer_call_count)++; 25 (*release_buffer_call_count)++;
20 } 26 }
21 27
22 TEST_F(SurfaceTest, Attach) { 28 TEST_P(SurfaceTest, Attach) {
23 gfx::Size buffer_size(256, 256); 29 gfx::Size buffer_size(256, 256);
24 std::unique_ptr<Buffer> buffer( 30 std::unique_ptr<Buffer> buffer(
25 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 31 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
26 32
27 // Set the release callback that will be run when buffer is no longer in use. 33 // Set the release callback that will be run when buffer is no longer in use.
28 int release_buffer_call_count = 0; 34 int release_buffer_call_count = 0;
29 buffer->set_release_callback( 35 buffer->set_release_callback(
30 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count))); 36 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count)));
31 37
32 std::unique_ptr<Surface> surface(new Surface); 38 std::unique_ptr<Surface> surface(new Surface);
33 39
34 // Attach the buffer to surface1. 40 // Attach the buffer to surface1.
35 surface->Attach(buffer.get()); 41 surface->Attach(buffer.get());
36 surface->Commit(); 42 surface->Commit();
37 43
38 // Commit without calling Attach() should have no effect. 44 // Commit without calling Attach() should have no effect.
39 surface->Commit(); 45 surface->Commit();
40 EXPECT_EQ(0, release_buffer_call_count); 46 EXPECT_EQ(0, release_buffer_call_count);
41 47
42 // Attach a null buffer to surface, this should release the previously 48 // Attach a null buffer to surface, this should release the previously
43 // attached buffer. 49 // attached buffer.
44 surface->Attach(nullptr); 50 surface->Attach(nullptr);
45 surface->Commit(); 51 surface->Commit();
46 ASSERT_EQ(1, release_buffer_call_count); 52 ASSERT_EQ(1, release_buffer_call_count);
47 } 53 }
48 54
49 TEST_F(SurfaceTest, Damage) { 55 TEST_P(SurfaceTest, Damage) {
50 gfx::Size buffer_size(256, 256); 56 gfx::Size buffer_size(256, 256);
51 std::unique_ptr<Buffer> buffer( 57 std::unique_ptr<Buffer> buffer(
52 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 58 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
53 std::unique_ptr<Surface> surface(new Surface); 59 std::unique_ptr<Surface> surface(new Surface);
54 60
55 // Attach the buffer to the surface. This will update the pending bounds of 61 // Attach the buffer to the surface. This will update the pending bounds of
56 // the surface to the buffer size. 62 // the surface to the buffer size.
57 surface->Attach(buffer.get()); 63 surface->Attach(buffer.get());
58 64
59 // Mark areas inside the bounds of the surface as damaged. This should result 65 // Mark areas inside the bounds of the surface as damaged. This should result
60 // in pending damage. 66 // in pending damage.
61 surface->Damage(gfx::Rect(0, 0, 10, 10)); 67 surface->Damage(gfx::Rect(0, 0, 10, 10));
62 surface->Damage(gfx::Rect(10, 10, 10, 10)); 68 surface->Damage(gfx::Rect(10, 10, 10, 10));
63 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(0, 0, 10, 10))); 69 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(0, 0, 10, 10)));
64 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(10, 10, 10, 10))); 70 EXPECT_TRUE(surface->HasPendingDamageForTesting(gfx::Rect(10, 10, 10, 10)));
65 EXPECT_FALSE(surface->HasPendingDamageForTesting(gfx::Rect(5, 5, 10, 10))); 71 EXPECT_FALSE(surface->HasPendingDamageForTesting(gfx::Rect(5, 5, 10, 10)));
66 } 72 }
67 73
68 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) { 74 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) {
69 *result = frame_time; 75 *result = frame_time;
70 } 76 }
71 77
72 TEST_F(SurfaceTest, RequestFrameCallback) { 78 TEST_P(SurfaceTest, RequestFrameCallback) {
73 std::unique_ptr<Surface> surface(new Surface); 79 std::unique_ptr<Surface> surface(new Surface);
74 80
75 base::TimeTicks frame_time; 81 base::TimeTicks frame_time;
76 surface->RequestFrameCallback( 82 surface->RequestFrameCallback(
77 base::Bind(&SetFrameTime, base::Unretained(&frame_time))); 83 base::Bind(&SetFrameTime, base::Unretained(&frame_time)));
78 surface->Commit(); 84 surface->Commit();
79 85
80 // Callback should not run synchronously. 86 // Callback should not run synchronously.
81 EXPECT_TRUE(frame_time.is_null()); 87 EXPECT_TRUE(frame_time.is_null());
82 } 88 }
83 89
84 TEST_F(SurfaceTest, SetOpaqueRegion) { 90 TEST_P(SurfaceTest, SetOpaqueRegion) {
85 std::unique_ptr<Surface> surface(new Surface); 91 std::unique_ptr<Surface> surface(new Surface);
86 92
87 // Setting a non-empty opaque region should succeed. 93 // Setting a non-empty opaque region should succeed.
88 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeWH(256, 256))); 94 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeWH(256, 256)));
89 95
90 // Setting an empty opaque region should succeed. 96 // Setting an empty opaque region should succeed.
91 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeEmpty())); 97 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeEmpty()));
92 } 98 }
93 99
94 TEST_F(SurfaceTest, SetInputRegion) { 100 TEST_P(SurfaceTest, SetInputRegion) {
95 std::unique_ptr<Surface> surface(new Surface); 101 std::unique_ptr<Surface> surface(new Surface);
96 102
97 // Setting a non-empty input region should succeed. 103 // Setting a non-empty input region should succeed.
98 surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256))); 104 surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256)));
99 105
100 // Setting an empty input region should succeed. 106 // Setting an empty input region should succeed.
101 surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty())); 107 surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty()));
102 } 108 }
103 109
104 TEST_F(SurfaceTest, SetBufferScale) { 110 TEST_P(SurfaceTest, SetBufferScale) {
105 gfx::Size buffer_size(512, 512); 111 gfx::Size buffer_size(512, 512);
106 std::unique_ptr<Buffer> buffer( 112 std::unique_ptr<Buffer> buffer(
107 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 113 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
108 std::unique_ptr<Surface> surface(new Surface); 114 std::unique_ptr<Surface> surface(new Surface);
109 115
110 // This will update the bounds of the surface and take the buffer scale into 116 // This will update the bounds of the surface and take the buffer scale into
111 // account. 117 // account.
112 const float kBufferScale = 2.0f; 118 const float kBufferScale = 2.0f;
113 surface->Attach(buffer.get()); 119 surface->Attach(buffer.get());
114 surface->SetBufferScale(kBufferScale); 120 surface->SetBufferScale(kBufferScale);
115 surface->Commit(); 121 surface->Commit();
116 EXPECT_EQ( 122 EXPECT_EQ(
117 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(), 123 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(),
118 surface->bounds().size().ToString()); 124 surface->bounds().size().ToString());
119 } 125 }
120 126
121 TEST_F(SurfaceTest, SetViewport) { 127 TEST_P(SurfaceTest, SetViewport) {
122 gfx::Size buffer_size(1, 1); 128 gfx::Size buffer_size(1, 1);
123 std::unique_ptr<Buffer> buffer( 129 std::unique_ptr<Buffer> buffer(
124 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 130 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
125 std::unique_ptr<Surface> surface(new Surface); 131 std::unique_ptr<Surface> surface(new Surface);
126 132
127 // This will update the bounds of the surface and take the viewport into 133 // This will update the bounds of the surface and take the viewport into
128 // account. 134 // account.
129 surface->Attach(buffer.get()); 135 surface->Attach(buffer.get());
130 gfx::Size viewport(256, 256); 136 gfx::Size viewport(256, 256);
131 surface->SetViewport(viewport); 137 surface->SetViewport(viewport);
132 surface->Commit(); 138 surface->Commit();
133 EXPECT_EQ(viewport.ToString(), surface->bounds().size().ToString()); 139 EXPECT_EQ(viewport.ToString(), surface->bounds().size().ToString());
134 } 140 }
135 141
136 TEST_F(SurfaceTest, SetCrop) { 142 TEST_P(SurfaceTest, SetCrop) {
137 gfx::Size buffer_size(16, 16); 143 gfx::Size buffer_size(16, 16);
138 std::unique_ptr<Buffer> buffer( 144 std::unique_ptr<Buffer> buffer(
139 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 145 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
140 std::unique_ptr<Surface> surface(new Surface); 146 std::unique_ptr<Surface> surface(new Surface);
141 147
142 surface->Attach(buffer.get()); 148 surface->Attach(buffer.get());
143 gfx::Size crop_size(12, 12); 149 gfx::Size crop_size(12, 12);
144 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size))); 150 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size)));
145 surface->Commit(); 151 surface->Commit();
146 EXPECT_EQ(crop_size.ToString(), surface->bounds().size().ToString()); 152 EXPECT_EQ(crop_size.ToString(), surface->bounds().size().ToString());
147 } 153 }
148 154
149 TEST_F(SurfaceTest, SetOnlyVisibleOnSecureOutput) { 155 TEST_P(SurfaceTest, SetOnlyVisibleOnSecureOutput) {
156 // SurfaceLayer doesn't have texture mailbox, so it can't be tested this
157 // way.
158 if (GetParam())
159 return;
150 gfx::Size buffer_size(1, 1); 160 gfx::Size buffer_size(1, 1);
151 std::unique_ptr<Buffer> buffer( 161 std::unique_ptr<Buffer> buffer(
152 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 162 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
153 std::unique_ptr<Surface> surface(new Surface); 163 std::unique_ptr<Surface> surface(new Surface);
154 164
155 surface->Attach(buffer.get()); 165 surface->Attach(buffer.get());
156 surface->SetOnlyVisibleOnSecureOutput(true); 166 surface->SetOnlyVisibleOnSecureOutput(true);
157 surface->Commit(); 167 surface->Commit();
158 168
159 cc::TextureMailbox mailbox; 169 cc::TextureMailbox mailbox;
160 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 170 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
161 bool rv = surface->layer()->PrepareTextureMailbox(&mailbox, &release_callback, 171 bool rv = surface->layer()->PrepareTextureMailbox(&mailbox, &release_callback,
162 false); 172 false);
163 ASSERT_TRUE(rv); 173 ASSERT_TRUE(rv);
164 174
165 EXPECT_TRUE(mailbox.secure_output_only()); 175 EXPECT_TRUE(mailbox.secure_output_only());
166 release_callback->Run(gpu::SyncToken(), false); 176 release_callback->Run(gpu::SyncToken(), false);
167 } 177 }
168 178
169 TEST_F(SurfaceTest, SetBlendMode) { 179 TEST_P(SurfaceTest, SetBlendMode) {
170 gfx::Size buffer_size(1, 1); 180 gfx::Size buffer_size(1, 1);
171 std::unique_ptr<Buffer> buffer( 181 std::unique_ptr<Buffer> buffer(
172 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 182 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
173 std::unique_ptr<Surface> surface(new Surface); 183 std::unique_ptr<Surface> surface(new Surface);
174 184
175 surface->Attach(buffer.get()); 185 surface->Attach(buffer.get());
176 surface->SetBlendMode(SkXfermode::kSrc_Mode); 186 surface->SetBlendMode(SkXfermode::kSrc_Mode);
177 surface->Commit(); 187 surface->Commit();
178 188
179 EXPECT_TRUE(surface->layer()->fills_bounds_opaquely()); 189 EXPECT_TRUE(surface->layer()->fills_bounds_opaquely());
180 } 190 }
181 191
182 TEST_F(SurfaceTest, SetAlpha) { 192 TEST_P(SurfaceTest, SetAlpha) {
183 gfx::Size buffer_size(1, 1); 193 gfx::Size buffer_size(1, 1);
184 std::unique_ptr<Buffer> buffer( 194 std::unique_ptr<Buffer> buffer(
185 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 195 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
186 std::unique_ptr<Surface> surface(new Surface); 196 std::unique_ptr<Surface> surface(new Surface);
187 197
188 surface->Attach(buffer.get()); 198 surface->Attach(buffer.get());
189 surface->SetAlpha(0.5f); 199 surface->SetAlpha(0.5f);
190 surface->Commit(); 200 surface->Commit();
191 } 201 }
192 202
193 TEST_F(SurfaceTest, Commit) { 203 TEST_P(SurfaceTest, Commit) {
194 std::unique_ptr<Surface> surface(new Surface); 204 std::unique_ptr<Surface> surface(new Surface);
195 205
196 // Calling commit without a buffer should succeed. 206 // Calling commit without a buffer should succeed.
197 surface->Commit(); 207 surface->Commit();
198 } 208 }
199 209
210 INSTANTIATE_TEST_CASE_P(, SurfaceTest, ::testing::Bool());
211
200 } // namespace 212 } // namespace
201 } // namespace exo 213 } // 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