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

Side by Side Diff: ppapi/tests/test_compositor.cc

Issue 324983005: [PPAPI] Add browser tests for compositor API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@compositor_api_impl_new
Patch Set: Fix review issues Created 6 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
OLDNEW
(Empty)
1 // Copyright (c) 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 "ppapi/tests/test_compositor.h"
6
7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "ppapi/c/ppb_opengles2.h"
14 #include "ppapi/cpp/compositor.h"
15 #include "ppapi/cpp/compositor_layer.h"
16 #include "ppapi/cpp/image_data.h"
17 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
18 #include "ppapi/lib/gl/include/GLES2/gl2.h"
19 #include "ppapi/lib/gl/include/GLES2/gl2ext.h"
20 #include "ppapi/tests/test_utils.h"
21
22 namespace {
23
24 const float kMatrix[16] = {
25 1.0f, 0.0f, 0.0f, 0.0f,
26 0.0f, 1.0f, 0.0f, 0.0f,
27 0.0f, 0.0f, 1.0f, 0.0f,
28 0.0f, 0.0f, 0.0f, 1.0f,
29 };
30
31 } // namespace
32
33 REGISTER_TEST_CASE(Compositor);
34
35 #define VERIFY(r) do { \
36 std::string result = (r); \
37 if (result != "") \
38 return result; \
39 } while (false)
40
41 bool TestCompositor::Init() {
42 if (!CheckTestingInterface())
43 return false;
44
45 if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface()))
46 return false;
47
48 return true;
49 }
50
51 void TestCompositor::RunTests(const std::string& filter) {
52 RUN_CALLBACK_TEST(TestCompositor, Release, filter);
53 RUN_CALLBACK_TEST(TestCompositor, ReleaseWithoutCommit, filter);
54 RUN_CALLBACK_TEST(TestCompositor, CommitTwoTimesWithoutChange, filter);
55 RUN_CALLBACK_TEST(TestCompositor, General, filter);
56
57 RUN_CALLBACK_TEST(TestCompositor, ReleaseUnbound, filter);
58 RUN_CALLBACK_TEST(TestCompositor, ReleaseWithoutCommitUnbound, filter);
59 RUN_CALLBACK_TEST(TestCompositor, CommitTwoTimesWithoutChangeUnbound, filter);
60 RUN_CALLBACK_TEST(TestCompositor, GeneralUnbound, filter);
61
62 RUN_CALLBACK_TEST(TestCompositor, BindUnbind, filter);
63 }
64
65 std::string TestCompositor::TestRelease() {
66 return TestReleaseInternal(true);
67 }
68
69 std::string TestCompositor::TestReleaseWithoutCommit() {
70 return TestReleaseWithoutCommitInternal(true);
71 }
72
73 std::string TestCompositor::TestCommitTwoTimesWithoutChange() {
74 return TestCommitTwoTimesWithoutChangeInternal(true);
75 }
76
77 std::string TestCompositor::TestGeneral() {
78 return TestGeneralInternal(true);
79 }
80
81 std::string TestCompositor::TestReleaseUnbound() {
82 return TestReleaseInternal(false);
83 }
84
85 std::string TestCompositor::TestReleaseWithoutCommitUnbound() {
86 return TestReleaseWithoutCommitInternal(false);
87 }
88
89 std::string TestCompositor::TestCommitTwoTimesWithoutChangeUnbound() {
90 return TestCommitTwoTimesWithoutChangeInternal(false);
91 }
92
93 std::string TestCompositor::TestGeneralUnbound() {
94 return TestGeneralInternal(false);
95 }
96
97 std::string TestCompositor::TestBindUnbind() {
98 // Setup GLES2
99 const int32_t attribs[] = {
100 PP_GRAPHICS3DATTRIB_WIDTH, 16,
101 PP_GRAPHICS3DATTRIB_HEIGHT, 16,
102 PP_GRAPHICS3DATTRIB_NONE
103 };
104 pp::Graphics3D graphics_3d(instance_, attribs);
105 ASSERT_FALSE(graphics_3d.is_null());
106 glSetCurrentContextPPAPI(graphics_3d.pp_resource());
107
108 pp::Compositor compositor = pp::Compositor(instance_);
109 ASSERT_FALSE(compositor.is_null());
110
111 // Add layers on an unbound compositor.
112 pp::CompositorLayer color_layer = compositor.AddLayer();
113 ASSERT_FALSE(color_layer.is_null());
114
115 VERIFY(SetColorLayer(color_layer, PP_OK));
116
117 uint32_t texture = 0;
118 VERIFY(CreateTexture(&texture));
119 pp::CompositorLayer texture_layer = compositor.AddLayer();
120 ASSERT_FALSE(texture_layer.is_null());
121 TestCompletionCallback texture_release_callback(instance_->pp_instance(),
122 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
123 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
124 texture_layer.SetTexture(graphics_3d, texture, pp::Size(100, 100),
125 texture_release_callback.GetCallback()));
126
127 pp::ImageData image;
128 VERIFY(CreateImage(&image));
129 pp::CompositorLayer image_layer = compositor.AddLayer();
130 TestCompletionCallback image_release_callback(instance_->pp_instance(),
131 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
132 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
133 image_layer.SetImage(image, pp::Size(100, 100),
134 image_release_callback.GetCallback()));
135
136 // Commit layers to the chromium compositor.
137 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
138 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
139 CHECK_CALLBACK_BEHAVIOR(callback);
140 ASSERT_EQ(PP_OK, callback.result());
141
142 // Bind the compositor and call CommitLayers() again.
143 ASSERT_TRUE(instance_->BindGraphics(compositor));
144 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
145 CHECK_CALLBACK_BEHAVIOR(callback);
146 ASSERT_EQ(PP_OK, callback.result());
147
148 // Unbind the compositor and call CommitLayers() again.
149 ASSERT_TRUE(instance_->BindGraphics(pp::Compositor()));
150 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
151 CHECK_CALLBACK_BEHAVIOR(callback);
152 ASSERT_EQ(PP_OK, callback.result());
153
154 // Reset layers and call CommitLayers() again.
155 ASSERT_EQ(PP_OK, compositor.ResetLayers());
156 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
157 CHECK_CALLBACK_BEHAVIOR(callback);
158 ASSERT_EQ(PP_OK, callback.result());
159
160 texture_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
161 ASSERT_EQ(PP_OK, texture_release_callback.result());
162 ReleaseTexture(texture);
163
164 image_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
165 ASSERT_EQ(PP_OK, image_release_callback.result());
166
167 // Reset
168 glSetCurrentContextPPAPI(0);
169
170 PASS();
171 }
172
173 std::string TestCompositor::TestReleaseInternal(bool bind) {
174 // Setup GLES2
175 const int32_t attribs[] = {
176 PP_GRAPHICS3DATTRIB_WIDTH, 16,
177 PP_GRAPHICS3DATTRIB_HEIGHT, 16,
178 PP_GRAPHICS3DATTRIB_NONE
179 };
180 pp::Graphics3D graphics_3d(instance_, attribs);
181 ASSERT_FALSE(graphics_3d.is_null());
182 glSetCurrentContextPPAPI(graphics_3d.pp_resource());
183
184 pp::Compositor compositor = pp::Compositor(instance_);
185 ASSERT_FALSE(compositor.is_null());
186
187 // Bind the compositor to the instance
188 if (bind)
189 ASSERT_TRUE(instance_->BindGraphics(compositor));
190
191 pp::CompositorLayer color_layer = compositor.AddLayer();
192 ASSERT_FALSE(color_layer.is_null());
193
194 VERIFY(SetColorLayer(color_layer, PP_OK));
195
196 uint32_t texture = 0;
197 VERIFY(CreateTexture(&texture));
198 pp::CompositorLayer texture_layer = compositor.AddLayer();
199 ASSERT_FALSE(texture_layer.is_null());
200 TestCompletionCallback texture_release_callback(instance_->pp_instance(),
201 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
202 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
203 texture_layer.SetTexture(graphics_3d, texture, pp::Size(100, 100),
204 texture_release_callback.GetCallback()));
205
206 pp::ImageData image;
207 VERIFY(CreateImage(&image));
208 pp::CompositorLayer image_layer = compositor.AddLayer();
209 TestCompletionCallback image_release_callback(instance_->pp_instance(),
210 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:17:59 Done.
211 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
212 image_layer.SetImage(image, pp::Size(100, 100),
213 image_release_callback.GetCallback()));
214
215 // Commit layers to the chromium compositor.
216 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
217 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
218 CHECK_CALLBACK_BEHAVIOR(callback);
219 ASSERT_EQ(PP_OK, callback.result());
220
221 // Release the compositor, and then release_callback will be aborted.
222 compositor = pp::Compositor();
223
224 texture_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
225 ASSERT_EQ(PP_ERROR_ABORTED, texture_release_callback.result());
226 ReleaseTexture(texture);
227
228 image_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
229 ASSERT_EQ(PP_ERROR_ABORTED, image_release_callback.result());
230
231 // Reset
232 glSetCurrentContextPPAPI(0);
233
234 PASS();
235 }
236
237 std::string TestCompositor::TestReleaseWithoutCommitInternal(bool bind) {
238 // Setup GLES2
239 const int32_t attribs[] = {
240 PP_GRAPHICS3DATTRIB_WIDTH, 16,
241 PP_GRAPHICS3DATTRIB_HEIGHT, 16,
242 PP_GRAPHICS3DATTRIB_NONE
243 };
244 pp::Graphics3D graphics_3d(instance_, attribs);
245 ASSERT_FALSE(graphics_3d.is_null());
246 glSetCurrentContextPPAPI(graphics_3d.pp_resource());
247
248 pp::Compositor compositor = pp::Compositor(instance_);
249 ASSERT_FALSE(compositor.is_null());
250
251 // Bind the compositor to the instance
252 if (bind)
253 ASSERT_TRUE(instance_->BindGraphics(compositor));
254
255 pp::CompositorLayer color_layer = compositor.AddLayer();
256 ASSERT_FALSE(color_layer.is_null());
257
258 VERIFY(SetColorLayer(color_layer, PP_OK));
259
260 uint32_t texture = 0;
261 VERIFY(CreateTexture(&texture));
262 pp::CompositorLayer texture_layer = compositor.AddLayer();
263 ASSERT_FALSE(texture_layer.is_null());
264 TestCompletionCallback texture_release_callback(instance_->pp_instance(),
265 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
266 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
267 texture_layer.SetTexture(graphics_3d, texture, pp::Size(100, 100),
268 texture_release_callback.GetCallback()));
269
270 pp::ImageData image;
271 VERIFY(CreateImage(&image));
272 pp::CompositorLayer image_layer = compositor.AddLayer();
273 TestCompletionCallback image_release_callback(instance_->pp_instance(),
274 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:17:59 Done.
275 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
276 image_layer.SetImage(image, pp::Size(100, 100),
277 image_release_callback.GetCallback()));
278
279 // Release the compositor, and then release_callback will be aborted.
280 compositor = pp::Compositor();
281
282 // All release_callbacks should be called.
283 texture_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
284 ASSERT_EQ(PP_ERROR_ABORTED, texture_release_callback.result());
285 ReleaseTexture(texture);
286
287 image_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
288 ASSERT_EQ(PP_ERROR_ABORTED, image_release_callback.result());
289
290 // The layer associated to the compositor will become invalidated.
291 VERIFY(SetColorLayer(color_layer, PP_ERROR_BADRESOURCE));
292
293 // Reset
294 glSetCurrentContextPPAPI(0);
295
296 PASS();
297 }
298
299 std::string TestCompositor::TestCommitTwoTimesWithoutChangeInternal(bool bind) {
300 pp::Compositor compositor(instance_);
301 ASSERT_FALSE(compositor.is_null());
302 if (bind)
303 ASSERT_TRUE(instance_->BindGraphics(compositor));
304 pp::CompositorLayer layer = compositor.AddLayer();
305 ASSERT_FALSE(layer.is_null());
306 VERIFY(SetColorLayer(layer, PP_OK));
307
308 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
309 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
310 CHECK_CALLBACK_BEHAVIOR(callback);
311 ASSERT_EQ(PP_OK, callback.result());
312
313 // CommitLayers() without any change.
314 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
315 CHECK_CALLBACK_BEHAVIOR(callback);
316 ASSERT_EQ(PP_OK, callback.result());
317
318 PASS();
319 }
320
321 std::string TestCompositor::TestGeneralInternal(bool bind) {
322 // Setup GLES2
323 const int32_t attribs[] = {
324 PP_GRAPHICS3DATTRIB_WIDTH, 16,
325 PP_GRAPHICS3DATTRIB_HEIGHT, 16,
326 PP_GRAPHICS3DATTRIB_NONE
327 };
328 pp::Graphics3D graphics_3d(instance_, attribs);
329 ASSERT_FALSE(graphics_3d.is_null());
330 glSetCurrentContextPPAPI(graphics_3d.pp_resource());
331
332 // All functions should work with a bound compositor
333 pp::Compositor compositor(instance_);
334 ASSERT_FALSE(compositor.is_null());
335 if (bind)
336 ASSERT_TRUE(instance_->BindGraphics(compositor));
337
338 pp::CompositorLayer color_layer = compositor.AddLayer();
339 ASSERT_FALSE(color_layer.is_null());
340 VERIFY(SetColorLayer(color_layer, PP_OK));
341
342 uint32_t texture = 0;
343 VERIFY(CreateTexture(&texture));
344 pp::CompositorLayer texture_layer = compositor.AddLayer();
345 ASSERT_FALSE(texture_layer.is_null());
346 TestCompletionCallback texture_release_callback(instance_->pp_instance(),
347 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
348 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
349 texture_layer.SetTexture(graphics_3d, texture, pp::Size(100, 100),
350 texture_release_callback.GetCallback()));
351
352 pp::ImageData image;
353 VERIFY(CreateImage(&image));
354 pp::CompositorLayer image_layer = compositor.AddLayer();
355 TestCompletionCallback image_release_callback(instance_->pp_instance(),
356 PP_REQUIRED);
raymes 2014/06/20 02:57:20 nit:indentation
Peng 2014/06/20 03:18:00 Done.
357 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
358 image_layer.SetImage(image, pp::Size(100, 100),
359 image_release_callback.GetCallback()));
360
361 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
362 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
363 CHECK_CALLBACK_BEHAVIOR(callback);
364 ASSERT_EQ(PP_OK, callback.result());
365
366 // After ResetLayers(), all layers should be invalidated.
367 ASSERT_EQ(PP_OK, compositor.ResetLayers());
368 VERIFY(SetColorLayer(color_layer, PP_ERROR_BADRESOURCE));
369
370 // Commit empty layer stack to the chromium compositor, and then the texture
371 // and the image will be released by the chromium compositor soon.
372 callback.WaitForResult(compositor.CommitLayers(callback.GetCallback()));
373 CHECK_CALLBACK_BEHAVIOR(callback);
374 ASSERT_EQ(PP_OK, callback.result());
375
376 texture_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
377 ASSERT_EQ(PP_OK, texture_release_callback.result());
378 ReleaseTexture(texture);
379
380 image_release_callback.WaitForResult(PP_OK_COMPLETIONPENDING);
381 ASSERT_EQ(PP_OK, image_release_callback.result());
382
383 // Reset
384 glSetCurrentContextPPAPI(0);
385
386 PASS();
raymes 2014/06/20 02:57:20 Most of the code up to and including comitting the
Peng 2014/06/20 03:18:00 Yes. The code of those testes are similar. There a
387 }
388
389 std::string TestCompositor::CreateTexture(uint32_t* texture) {
390 glGenTextures(1, texture);
391 ASSERT_NE(0, *texture);
392 glBindTexture(GL_TEXTURE_2D, *texture);
393 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 400, 400, 0,
394 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
395 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
396 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
397 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
398 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
399 glBindTexture(GL_TEXTURE_2D, 0);
400
401 return std::string();
402 }
403
404 std::string TestCompositor::ReleaseTexture(uint32_t texture) {
405 ASSERT_NE(0u, texture);
406 glDeleteTextures(1, &texture);
407
408 return std::string();
409 }
410
411 std::string TestCompositor::CreateImage(pp::ImageData* image) {
412 *image = pp::ImageData(instance_, PP_IMAGEDATAFORMAT_RGBA_PREMUL,
413 pp::Size(400, 400), false);
414 ASSERT_FALSE(image->is_null());
415
416 return std::string();
417 }
418
419 std::string TestCompositor::SetColorLayer(
420 pp::CompositorLayer layer, int32_t result) {
421 ASSERT_EQ(result, layer.SetColor(255, 255, 255, 255, pp::Size(100, 100)));
422 ASSERT_EQ(result, layer.SetClipRect(pp::Rect(0, 0, 50, 50)));
423 ASSERT_EQ(result, layer.SetTransform(kMatrix));
424 ASSERT_EQ(result, layer.SetOpacity(128));
425
426 return std::string();
427 }
428
429
OLDNEW
« ppapi/proxy/compositor_resource.cc ('K') | « ppapi/tests/test_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698