OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_testing_dev.h" | 9 #include "ppapi/c/dev/ppb_testing_dev.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 instance_->LogTest("Humongous", TestHumongous()); | 56 instance_->LogTest("Humongous", TestHumongous()); |
57 instance_->LogTest("InitToZero", TestInitToZero()); | 57 instance_->LogTest("InitToZero", TestInitToZero()); |
58 instance_->LogTest("Describe", TestDescribe()); | 58 instance_->LogTest("Describe", TestDescribe()); |
59 instance_->LogTest("Paint", TestPaint()); | 59 instance_->LogTest("Paint", TestPaint()); |
60 //instance_->LogTest("Scroll", TestScroll()); // TODO(brettw) implement. | 60 //instance_->LogTest("Scroll", TestScroll()); // TODO(brettw) implement. |
61 instance_->LogTest("Replace", TestReplace()); | 61 instance_->LogTest("Replace", TestReplace()); |
62 instance_->LogTest("Flush", TestFlush()); | 62 instance_->LogTest("Flush", TestFlush()); |
63 } | 63 } |
64 | 64 |
65 void TestGraphics2D::QuitMessageLoop() { | 65 void TestGraphics2D::QuitMessageLoop() { |
66 testing_interface_->QuitMessageLoop(); | 66 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
67 } | 67 } |
68 | 68 |
69 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, | 69 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, |
70 pp::ImageData* image, | 70 pp::ImageData* image, |
71 const pp::Point& top_left) const { | 71 const pp::Point& top_left) const { |
72 return pp::PPBoolToBool(testing_interface_->ReadImageData( | 72 return pp::PPBoolToBool(testing_interface_->ReadImageData( |
73 dc.pp_resource(), | 73 dc.pp_resource(), |
74 image->pp_resource(), | 74 image->pp_resource(), |
75 &top_left.pp_point())); | 75 &top_left.pp_point())); |
76 } | 76 } |
77 | 77 |
78 bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc, | 78 bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc, |
79 uint32_t color) const { | 79 uint32_t color) const { |
80 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 80 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
81 dc.size(), false); | 81 dc.size(), false); |
82 if (readback.is_null()) | 82 if (readback.is_null()) |
83 return false; | 83 return false; |
84 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) | 84 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) |
85 return false; | 85 return false; |
86 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color); | 86 return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color); |
87 } | 87 } |
88 | 88 |
89 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { | 89 bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) { |
90 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this); | 90 pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this); |
91 int32_t rv = context->Flush(cc); | 91 int32_t rv = context->Flush(cc); |
92 if (rv == PP_OK) | 92 if (rv == PP_OK) |
93 return true; | 93 return true; |
94 if (rv != PP_ERROR_WOULDBLOCK) | 94 if (rv != PP_ERROR_WOULDBLOCK) |
95 return false; | 95 return false; |
96 testing_interface_->RunMessageLoop(); | 96 testing_interface_->RunMessageLoop(instance_->pp_instance()); |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 void TestGraphics2D::FillRectInImage(pp::ImageData* image, | 100 void TestGraphics2D::FillRectInImage(pp::ImageData* image, |
101 const pp::Rect& rect, | 101 const pp::Rect& rect, |
102 uint32_t color) const { | 102 uint32_t color) const { |
103 for (int y = rect.y(); y < rect.bottom(); y++) { | 103 for (int y = rect.y(); y < rect.bottom(); y++) { |
104 uint32_t* row = image->GetAddr32(pp::Point(rect.x(), y)); | 104 uint32_t* row = image->GetAddr32(pp::Point(rect.x(), y)); |
105 for (int pixel = 0; pixel < rect.width(); pixel++) | 105 for (int pixel = 0; pixel < rect.width(); pixel++) |
106 row[pixel] = color; | 106 row[pixel] = color; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 539 |
540 if (rv != PP_OK) { | 540 if (rv != PP_OK) { |
541 // If the first flush would block, then a second should fail. | 541 // If the first flush would block, then a second should fail. |
542 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 542 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); |
543 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) | 543 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) |
544 return "Second flush succeeded before callback ran."; | 544 return "Second flush succeeded before callback ran."; |
545 } | 545 } |
546 | 546 |
547 PASS(); | 547 PASS(); |
548 } | 548 } |
OLD | NEW |