OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 bool TestGraphics2D::Init() { | 36 bool TestGraphics2D::Init() { |
37 graphics_2d_interface_ = reinterpret_cast<PPB_Graphics2D const*>( | 37 graphics_2d_interface_ = reinterpret_cast<PPB_Graphics2D const*>( |
38 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_2D_INTERFACE)); | 38 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_2D_INTERFACE)); |
39 image_data_interface_ = reinterpret_cast<PPB_ImageData const*>( | 39 image_data_interface_ = reinterpret_cast<PPB_ImageData const*>( |
40 pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE)); | 40 pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE)); |
41 return graphics_2d_interface_ && image_data_interface_ && | 41 return graphics_2d_interface_ && image_data_interface_ && |
42 InitTestingInterface(); | 42 InitTestingInterface(); |
43 } | 43 } |
44 | 44 |
45 void TestGraphics2D::RunTest() { | 45 void TestGraphics2D::RunTest() { |
46 instance_->LogTest("InvalidResource", TestInvalidResource()); | 46 RUN_TEST(InvalidResource); |
47 instance_->LogTest("InvalidSize", TestInvalidSize()); | 47 RUN_TEST(InvalidSize); |
48 instance_->LogTest("Humongous", TestHumongous()); | 48 RUN_TEST(Humongous); |
49 instance_->LogTest("InitToZero", TestInitToZero()); | 49 RUN_TEST(InitToZero); |
50 instance_->LogTest("Describe", TestDescribe()); | 50 RUN_TEST(Describe); |
51 instance_->LogTest("Paint", TestPaint()); | 51 RUN_TEST_FORCEASYNC_AND_NOT(Paint); |
52 //instance_->LogTest("Scroll", TestScroll()); // TODO(brettw) implement. | 52 // RUN_TEST_FORCEASYNC_AND_NOT(Scroll); // TODO(brettw) implement. |
53 instance_->LogTest("Replace", TestReplace()); | 53 RUN_TEST_FORCEASYNC_AND_NOT(Replace); |
54 instance_->LogTest("Flush", TestFlush()); | 54 RUN_TEST_FORCEASYNC_AND_NOT(Flush); |
55 } | 55 } |
56 | 56 |
57 void TestGraphics2D::QuitMessageLoop() { | 57 void TestGraphics2D::QuitMessageLoop() { |
58 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 58 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
59 } | 59 } |
60 | 60 |
61 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, | 61 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, |
62 pp::ImageData* image, | 62 pp::ImageData* image, |
63 const pp::Point& top_left) const { | 63 const pp::Point& top_left) const { |
64 return pp::PPBoolToBool(testing_interface_->ReadImageData( | 64 return pp::PPBoolToBool(testing_interface_->ReadImageData( |
65 dc.pp_resource(), | 65 dc.pp_resource(), |
66 image->pp_resource(), | 66 image->pp_resource(), |
67 &top_left.pp_point())); | 67 &top_left.pp_point())); |
68 } | 68 } |
69 | 69 |
70 bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc, | 70 bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc, |
71 uint32_t color) const { | 71 uint32_t color) const { |
72 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 72 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
73 dc.size(), false); | 73 dc.size(), false); |
74 if (readback.is_null()) | 74 if (readback.is_null()) |
75 return false; | 75 return false; |
76 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) | 76 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) |
77 return false; | 77 return false; |
78 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color); | 78 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color); |
79 } | 79 } |
80 | 80 |
81 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { | 81 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { |
82 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this); | 82 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); |
| 83 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this, flags); |
83 int32_t rv = context->Flush(cc); | 84 int32_t rv = context->Flush(cc); |
| 85 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 86 return false; |
84 if (rv == PP_OK) | 87 if (rv == PP_OK) |
85 return true; | 88 return true; |
86 if (rv != PP_OK_COMPLETIONPENDING) | 89 if (rv != PP_OK_COMPLETIONPENDING) |
87 return false; | 90 return false; |
88 testing_interface_->RunMessageLoop(instance_->pp_instance()); | 91 testing_interface_->RunMessageLoop(instance_->pp_instance()); |
89 return true; | 92 return true; |
90 } | 93 } |
91 | 94 |
92 void TestGraphics2D::FillRectInImage(pp::ImageData* image, | 95 void TestGraphics2D::FillRectInImage(pp::ImageData* image, |
93 const pp::Rect& rect, | 96 const pp::Rect& rect, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 205 |
203 // ReplaceContents. | 206 // ReplaceContents. |
204 graphics_2d_interface_->ReplaceContents(image.pp_resource(), | 207 graphics_2d_interface_->ReplaceContents(image.pp_resource(), |
205 image.pp_resource()); | 208 image.pp_resource()); |
206 graphics_2d_interface_->ReplaceContents(null_context.pp_resource(), | 209 graphics_2d_interface_->ReplaceContents(null_context.pp_resource(), |
207 image.pp_resource()); | 210 image.pp_resource()); |
208 | 211 |
209 // Flush. | 212 // Flush. |
210 if (graphics_2d_interface_->Flush( | 213 if (graphics_2d_interface_->Flush( |
211 image.pp_resource(), | 214 image.pp_resource(), |
212 PP_MakeCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) | 215 PP_MakeOptionalCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) |
213 return "Flush succeeded with a different resource"; | 216 return "Flush succeeded with a different resource"; |
214 if (graphics_2d_interface_->Flush( | 217 if (graphics_2d_interface_->Flush( |
215 null_context.pp_resource(), | 218 null_context.pp_resource(), |
216 PP_MakeCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) | 219 PP_MakeOptionalCompletionCallback(&FlushCallbackNOP, NULL)) == PP_OK) |
217 return "Flush succeeded with a NULL resource"; | 220 return "Flush succeeded with a NULL resource"; |
218 | 221 |
219 // ReadImageData. | 222 // ReadImageData. |
220 if (testing_interface_->ReadImageData(image.pp_resource(), | 223 if (testing_interface_->ReadImageData(image.pp_resource(), |
221 image.pp_resource(), | 224 image.pp_resource(), |
222 &zero_zero)) | 225 &zero_zero)) |
223 return "ReadImageData succeeded with a different resource"; | 226 return "ReadImageData succeeded with a different resource"; |
224 if (testing_interface_->ReadImageData(null_context.pp_resource(), | 227 if (testing_interface_->ReadImageData(null_context.pp_resource(), |
225 image.pp_resource(), | 228 image.pp_resource(), |
226 &zero_zero)) | 229 &zero_zero)) |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 return "Flush succeeded from the main thread with no callback."; | 522 return "Flush succeeded from the main thread with no callback."; |
520 | 523 |
521 // Test flushing with no operations still issues a callback. | 524 // Test flushing with no operations still issues a callback. |
522 // (This may also hang if the browser never issues the callback). | 525 // (This may also hang if the browser never issues the callback). |
523 pp::Graphics2D dc_nopaints(instance_, pp::Size(w, h), false); | 526 pp::Graphics2D dc_nopaints(instance_, pp::Size(w, h), false); |
524 if (dc.is_null()) | 527 if (dc.is_null()) |
525 return "Failure creating the nopaint device"; | 528 return "Failure creating the nopaint device"; |
526 if (!FlushAndWaitForDone(&dc_nopaints)) | 529 if (!FlushAndWaitForDone(&dc_nopaints)) |
527 return "Couldn't flush the nopaint device"; | 530 return "Couldn't flush the nopaint device"; |
528 | 531 |
| 532 int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); |
| 533 |
529 // Test that multiple flushes fail if we don't get a callback in between. | 534 // Test that multiple flushes fail if we don't get a callback in between. |
530 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 535 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL, |
| 536 flags)); |
| 537 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 538 return "Flush must complete asynchronously."; |
531 if (rv != PP_OK && rv != PP_OK_COMPLETIONPENDING) | 539 if (rv != PP_OK && rv != PP_OK_COMPLETIONPENDING) |
532 return "Couldn't flush first time for multiple flush test."; | 540 return "Couldn't flush first time for multiple flush test."; |
533 | 541 |
534 if (rv != PP_OK) { | 542 if (rv == PP_OK_COMPLETIONPENDING) { |
535 // If the first flush would block, then a second should fail. | 543 // If the first flush completes asynchronously, then a second should fail. |
536 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 544 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL, |
537 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) | 545 flags)); |
538 return "Second flush succeeded before callback ran."; | 546 if (force_async_) { |
| 547 if (rv != PP_OK_COMPLETIONPENDING) |
| 548 return "Second flush must fail asynchronously."; |
| 549 } else { |
| 550 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) |
| 551 return "Second flush succeeded before callback ran."; |
| 552 } |
539 } | 553 } |
540 | 554 |
541 PASS(); | 555 PASS(); |
542 } | 556 } |
OLD | NEW |