OLD | NEW |
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 Loading... |
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 Loading... |
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)); |
281 | 307 |
282 PASS(); | 308 PASS(); |
283 } | 309 } |
284 | 310 |
285 std::string TestGraphics2D::TestHumongous() { | 311 std::string TestGraphics2D::TestHumongous() { |
286 pp::Graphics2D a(instance_, pp::Size(100000, 100000), false); | 312 pp::Graphics2D a(instance_, pp::Size(100000, 100000), false); |
287 if (!a.is_null()) | 313 if (ResourceHealthCheck(instance_, &a)) |
288 return "Humongous device created"; | 314 return "Humongous device created"; |
289 PASS(); | 315 PASS(); |
290 } | 316 } |
291 | 317 |
292 std::string TestGraphics2D::TestInitToZero() { | 318 std::string TestGraphics2D::TestInitToZero() { |
293 const int w = 15, h = 17; | 319 const int w = 15, h = 17; |
294 pp::Graphics2D dc(instance_, pp::Size(w, h), false); | 320 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
295 if (dc.is_null()) | 321 if (dc.is_null()) |
296 return "Failure creating a boring device"; | 322 return "Failure creating a boring device"; |
297 | 323 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 835 |
810 // Now doing more replace contents should re-use older IDs if the cache is | 836 // Now doing more replace contents should re-use older IDs if the cache is |
811 // working. | 837 // working. |
812 imageres = ReplaceContentsAndReturnID(&dc, size); | 838 imageres = ReplaceContentsAndReturnID(&dc, size); |
813 ASSERT_TRUE(resources.find(imageres) != resources.end()); | 839 ASSERT_TRUE(resources.find(imageres) != resources.end()); |
814 imageres = ReplaceContentsAndReturnID(&dc, size); | 840 imageres = ReplaceContentsAndReturnID(&dc, size); |
815 ASSERT_TRUE(resources.find(imageres) != resources.end()); | 841 ASSERT_TRUE(resources.find(imageres) != resources.end()); |
816 | 842 |
817 PASS(); | 843 PASS(); |
818 } | 844 } |
OLD | NEW |