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

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

Issue 11053003: Migrate Graphics2D to new design. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years 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 | « ppapi/tests/test_graphics_2d.h ('k') | ppapi/thunk/interfaces_ppb_public_stable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/tests/test_graphics_2d.h" 5 #include "ppapi/tests/test_graphics_2d.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <set> 10 #include <set>
11 11
12 #include "ppapi/c/dev/ppb_testing_dev.h" 12 #include "ppapi/c/dev/ppb_testing_dev.h"
13 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/ppb_graphics_2d.h" 14 #include "ppapi/c/ppb_graphics_2d.h"
15 #include "ppapi/cpp/completion_callback.h" 15 #include "ppapi/cpp/completion_callback.h"
16 #include "ppapi/cpp/dev/graphics_2d_dev.h" 16 #include "ppapi/cpp/dev/graphics_2d_dev.h"
17 #include "ppapi/cpp/graphics_2d.h" 17 #include "ppapi/cpp/graphics_2d.h"
18 #include "ppapi/cpp/image_data.h" 18 #include "ppapi/cpp/image_data.h"
19 #include "ppapi/cpp/instance.h" 19 #include "ppapi/cpp/instance.h"
20 #include "ppapi/cpp/module.h" 20 #include "ppapi/cpp/module.h"
21 #include "ppapi/cpp/rect.h" 21 #include "ppapi/cpp/rect.h"
22 #include "ppapi/tests/test_utils.h"
22 #include "ppapi/tests/testing_instance.h" 23 #include "ppapi/tests/testing_instance.h"
23 24
24 REGISTER_TEST_CASE(Graphics2D); 25 REGISTER_TEST_CASE(Graphics2D);
25 26
26 namespace { 27 namespace {
27 28
28 // A NOP flush callback for use in various tests. 29 // A NOP flush callback for use in various tests.
29 void FlushCallbackNOP(void* data, int32_t result) { 30 void FlushCallbackNOP(void* data, int32_t result) {
30 } 31 }
31 32
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 uint32_t color) const { 83 uint32_t color) const {
83 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 84 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
84 dc.size(), false); 85 dc.size(), false);
85 if (readback.is_null()) 86 if (readback.is_null())
86 return false; 87 return false;
87 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) 88 if (!ReadImageData(dc, &readback, pp::Point(0, 0)))
88 return false; 89 return false;
89 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color); 90 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color);
90 } 91 }
91 92
93 bool TestGraphics2D::ResourceHealthCheck(pp::Instance* instance,
94 pp::Graphics2D* context) {
95 TestCompletionCallback callback(instance->pp_instance(), callback_type());
96 callback.WaitForResult(context->Flush(callback));
97 if (callback.result() < 0)
98 return callback.result() != PP_ERROR_FAILED;
99 else if (callback.result() == 0)
100 return false;
101 return true;
102 }
103
104 bool TestGraphics2D::ResourceHealthCheckForC(pp::Instance* instance,
105 PP_Resource graphics_2d) {
106 TestCompletionCallback callback(instance->pp_instance(), callback_type());
107 callback.WaitForResult(graphics_2d_interface_->Flush(
108 graphics_2d, callback.GetCallback().pp_completion_callback()));
109 if (callback.result() < 0)
110 return callback.result() != PP_ERROR_FAILED;
111 else if (callback.result() == 0)
112 return false;
113 return true;
114 }
115
92 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { 116 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) {
93 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); 117 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
94 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this, flags); 118 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this, flags);
95 int32_t rv = context->Flush(cc); 119 int32_t rv = context->Flush(cc);
96 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 120 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
97 return false; 121 return false;
98 if (rv == PP_OK) 122 if (rv == PP_OK)
99 return true; 123 return true;
100 if (rv != PP_OK_COMPLETIONPENDING) 124 if (rv != PP_OK_COMPLETIONPENDING)
101 return false; 125 return false;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (testing_interface_->ReadImageData(null_context.pp_resource(), 277 if (testing_interface_->ReadImageData(null_context.pp_resource(),
254 image.pp_resource(), 278 image.pp_resource(),
255 &zero_zero)) 279 &zero_zero))
256 return "ReadImageData succeeded with a NULL resource"; 280 return "ReadImageData succeeded with a NULL resource";
257 281
258 PASS(); 282 PASS();
259 } 283 }
260 284
261 std::string TestGraphics2D::TestInvalidSize() { 285 std::string TestGraphics2D::TestInvalidSize() {
262 pp::Graphics2D a(instance_, pp::Size(16, 0), false); 286 pp::Graphics2D a(instance_, pp::Size(16, 0), false);
263 if (!a.is_null()) 287 if (ResourceHealthCheck(instance_, &a))
264 return "0 height accepted"; 288 return "0 height accepted";
265 289
266 pp::Graphics2D b(instance_, pp::Size(0, 16), false); 290 pp::Graphics2D b(instance_, pp::Size(0, 16), false);
267 if (!b.is_null()) 291 if (ResourceHealthCheck(instance_, &b))
268 return "0 width accepted"; 292 return "0 height accepted";
269 293
270 // Need to use the C API since pp::Size prevents negative sizes. 294 // Need to use the C API since pp::Size prevents negative sizes.
271 PP_Size size; 295 PP_Size size;
272 size.width = 16; 296 size.width = 16;
273 size.height = -16; 297 size.height = -16;
274 ASSERT_FALSE(!!graphics_2d_interface_->Create( 298 PP_Resource graphics = graphics_2d_interface_->Create(
275 instance_->pp_instance(), &size, PP_FALSE)); 299 instance_->pp_instance(), &size, PP_FALSE);
300 ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
276 301
277 size.width = -16; 302 size.width = -16;
278 size.height = 16; 303 size.height = 16;
279 ASSERT_FALSE(!!graphics_2d_interface_->Create( 304 graphics = graphics_2d_interface_->Create(
280 instance_->pp_instance(), &size, PP_FALSE)); 305 instance_->pp_instance(), &size, PP_FALSE);
306 ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
307
308 // Overflow to negative size
309 size.width = std::numeric_limits<int32_t>::max();
310 size.height = std::numeric_limits<int32_t>::max();
311 graphics = graphics_2d_interface_->Create(
312 instance_->pp_instance(), &size, PP_FALSE);
313 ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
281 314
282 PASS(); 315 PASS();
283 } 316 }
284 317
285 std::string TestGraphics2D::TestHumongous() { 318 std::string TestGraphics2D::TestHumongous() {
286 pp::Graphics2D a(instance_, pp::Size(100000, 100000), false); 319 pp::Graphics2D a(instance_, pp::Size(100000, 100000), false);
287 if (!a.is_null()) 320 if (ResourceHealthCheck(instance_, &a))
288 return "Humongous device created"; 321 return "Humongous device created";
289 PASS(); 322 PASS();
290 } 323 }
291 324
292 std::string TestGraphics2D::TestInitToZero() { 325 std::string TestGraphics2D::TestInitToZero() {
293 const int w = 15, h = 17; 326 const int w = 15, h = 17;
294 pp::Graphics2D dc(instance_, pp::Size(w, h), false); 327 pp::Graphics2D dc(instance_, pp::Size(w, h), false);
295 if (dc.is_null()) 328 if (dc.is_null())
296 return "Failure creating a boring device"; 329 return "Failure creating a boring device";
297 330
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 842
810 // Now doing more replace contents should re-use older IDs if the cache is 843 // Now doing more replace contents should re-use older IDs if the cache is
811 // working. 844 // working.
812 imageres = ReplaceContentsAndReturnID(&dc, size); 845 imageres = ReplaceContentsAndReturnID(&dc, size);
813 ASSERT_TRUE(resources.find(imageres) != resources.end()); 846 ASSERT_TRUE(resources.find(imageres) != resources.end());
814 imageres = ReplaceContentsAndReturnID(&dc, size); 847 imageres = ReplaceContentsAndReturnID(&dc, size);
815 ASSERT_TRUE(resources.find(imageres) != resources.end()); 848 ASSERT_TRUE(resources.find(imageres) != resources.end());
816 849
817 PASS(); 850 PASS();
818 } 851 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_graphics_2d.h ('k') | ppapi/thunk/interfaces_ppb_public_stable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698