| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(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); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool TestGraphics2D::IsSquareInDC(const pp::Graphics2D& dc, | 165 bool TestGraphics2D::IsSquareInDC(const pp::Graphics2D& dc, |
| 166 uint32_t background_color, | 166 uint32_t background_color, |
| 167 const pp::Rect& square, | 167 const pp::Rect& square, |
| 168 uint32_t square_color) const { | 168 uint32_t square_color) const { |
| 169 pp::ImageData readback(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 169 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 170 dc.size(), false); | 170 dc.size(), false); |
| 171 if (readback.is_null()) | 171 if (readback.is_null()) |
| 172 return false; | 172 return false; |
| 173 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) | 173 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) |
| 174 return false; | 174 return false; |
| 175 return IsSquareInImage(readback, background_color, square, square_color); | 175 return IsSquareInImage(readback, background_color, square, square_color); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Test all the functions with an invalid handle. Most of these just check for | 178 // Test all the functions with an invalid handle. Most of these just check for |
| 179 // a crash since the browser don't return a value. | 179 // a crash since the browser don't return a value. |
| 180 std::string TestGraphics2D::TestInvalidResource() { | 180 std::string TestGraphics2D::TestInvalidResource() { |
| 181 pp::Graphics2D null_context; | 181 pp::Graphics2D null_context; |
| 182 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(16, 16), true); | 182 pp::ImageData image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 183 pp::Size(16, 16), true); |
| 183 | 184 |
| 184 // Describe. | 185 // Describe. |
| 185 PP_Size size; | 186 PP_Size size; |
| 186 PP_Bool opaque; | 187 PP_Bool opaque; |
| 187 graphics_2d_interface_->Describe(image.pp_resource(), &size, &opaque); | 188 graphics_2d_interface_->Describe(image.pp_resource(), &size, &opaque); |
| 188 graphics_2d_interface_->Describe(null_context.pp_resource(), | 189 graphics_2d_interface_->Describe(null_context.pp_resource(), |
| 189 &size, &opaque); | 190 &size, &opaque); |
| 190 | 191 |
| 191 // PaintImageData. | 192 // PaintImageData. |
| 192 PP_Point zero_zero; | 193 PP_Point zero_zero; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return "ReadImageData succeeded with a different resource"; | 231 return "ReadImageData succeeded with a different resource"; |
| 231 if (testing_interface_->ReadImageData(null_context.pp_resource(), | 232 if (testing_interface_->ReadImageData(null_context.pp_resource(), |
| 232 image.pp_resource(), | 233 image.pp_resource(), |
| 233 &zero_zero)) | 234 &zero_zero)) |
| 234 return "ReadImageData succeeded with a NULL resource"; | 235 return "ReadImageData succeeded with a NULL resource"; |
| 235 | 236 |
| 236 return ""; | 237 return ""; |
| 237 } | 238 } |
| 238 | 239 |
| 239 std::string TestGraphics2D::TestInvalidSize() { | 240 std::string TestGraphics2D::TestInvalidSize() { |
| 240 pp::Graphics2D a(pp::Size(16, 0), false); | 241 pp::Graphics2D a(instance_, pp::Size(16, 0), false); |
| 241 if (!a.is_null()) | 242 if (!a.is_null()) |
| 242 return "0 height accepted"; | 243 return "0 height accepted"; |
| 243 | 244 |
| 244 pp::Graphics2D b(pp::Size(0, 16), false); | 245 pp::Graphics2D b(instance_, pp::Size(0, 16), false); |
| 245 if (!b.is_null()) | 246 if (!b.is_null()) |
| 246 return "0 width accepted"; | 247 return "0 width accepted"; |
| 247 | 248 |
| 248 // Need to use the C API since pp::Size prevents negative sizes. | 249 // Need to use the C API since pp::Size prevents negative sizes. |
| 249 PP_Size size; | 250 PP_Size size; |
| 250 size.width = 16; | 251 size.width = 16; |
| 251 size.height = -16; | 252 size.height = -16; |
| 252 ASSERT_FALSE(!!graphics_2d_interface_->Create( | 253 ASSERT_FALSE(!!graphics_2d_interface_->Create( |
| 253 pp::Module::Get()->pp_module(), &size, PP_FALSE)); | 254 pp::Module::Get()->pp_module(), &size, PP_FALSE)); |
| 254 | 255 |
| 255 size.width = -16; | 256 size.width = -16; |
| 256 size.height = 16; | 257 size.height = 16; |
| 257 ASSERT_FALSE(!!graphics_2d_interface_->Create( | 258 ASSERT_FALSE(!!graphics_2d_interface_->Create( |
| 258 pp::Module::Get()->pp_module(), &size, PP_FALSE)); | 259 pp::Module::Get()->pp_module(), &size, PP_FALSE)); |
| 259 | 260 |
| 260 return ""; | 261 return ""; |
| 261 } | 262 } |
| 262 | 263 |
| 263 std::string TestGraphics2D::TestHumongous() { | 264 std::string TestGraphics2D::TestHumongous() { |
| 264 pp::Graphics2D a(pp::Size(100000, 100000), false); | 265 pp::Graphics2D a(instance_, pp::Size(100000, 100000), false); |
| 265 if (!a.is_null()) | 266 if (!a.is_null()) |
| 266 return "Humongous device created"; | 267 return "Humongous device created"; |
| 267 return ""; | 268 return ""; |
| 268 } | 269 } |
| 269 | 270 |
| 270 std::string TestGraphics2D::TestInitToZero() { | 271 std::string TestGraphics2D::TestInitToZero() { |
| 271 const int w = 15, h = 17; | 272 const int w = 15, h = 17; |
| 272 pp::Graphics2D dc(pp::Size(w, h), false); | 273 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 273 if (dc.is_null()) | 274 if (dc.is_null()) |
| 274 return "Failure creating a boring device"; | 275 return "Failure creating a boring device"; |
| 275 | 276 |
| 276 // Make an image with nonzero data in it (so we can test that zeros were | 277 // Make an image with nonzero data in it (so we can test that zeros were |
| 277 // actually read versus ReadImageData being a NOP). | 278 // actually read versus ReadImageData being a NOP). |
| 278 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 279 pp::ImageData image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 280 pp::Size(w, h), true); |
| 279 if (image.is_null()) | 281 if (image.is_null()) |
| 280 return "Failure to allocate an image"; | 282 return "Failure to allocate an image"; |
| 281 memset(image.data(), 0xFF, image.stride() * image.size().height() * 4); | 283 memset(image.data(), 0xFF, image.stride() * image.size().height() * 4); |
| 282 | 284 |
| 283 // Read out the initial data from the device & check. | 285 // Read out the initial data from the device & check. |
| 284 if (!ReadImageData(dc, &image, pp::Point(0, 0))) | 286 if (!ReadImageData(dc, &image, pp::Point(0, 0))) |
| 285 return "Couldn't read image data"; | 287 return "Couldn't read image data"; |
| 286 if (!IsSquareInImage(image, 0, pp::Rect(0, 0, w, h), 0)) | 288 if (!IsSquareInImage(image, 0, pp::Rect(0, 0, w, h), 0)) |
| 287 return "Got a nonzero pixel"; | 289 return "Got a nonzero pixel"; |
| 288 | 290 |
| 289 return ""; | 291 return ""; |
| 290 } | 292 } |
| 291 | 293 |
| 292 std::string TestGraphics2D::TestDescribe() { | 294 std::string TestGraphics2D::TestDescribe() { |
| 293 const int w = 15, h = 17; | 295 const int w = 15, h = 17; |
| 294 pp::Graphics2D dc(pp::Size(w, h), false); | 296 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 295 if (dc.is_null()) | 297 if (dc.is_null()) |
| 296 return "Failure creating a boring device"; | 298 return "Failure creating a boring device"; |
| 297 | 299 |
| 298 PP_Size size; | 300 PP_Size size; |
| 299 size.width = -1; | 301 size.width = -1; |
| 300 size.height = -1; | 302 size.height = -1; |
| 301 PP_Bool is_always_opaque = PP_TRUE; | 303 PP_Bool is_always_opaque = PP_TRUE; |
| 302 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, | 304 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, |
| 303 &is_always_opaque)) | 305 &is_always_opaque)) |
| 304 return "Describe failed"; | 306 return "Describe failed"; |
| 305 if (size.width != w || size.height != h || is_always_opaque != PP_FALSE) | 307 if (size.width != w || size.height != h || is_always_opaque != PP_FALSE) |
| 306 return "Mismatch of data."; | 308 return "Mismatch of data."; |
| 307 | 309 |
| 308 return ""; | 310 return ""; |
| 309 } | 311 } |
| 310 | 312 |
| 311 std::string TestGraphics2D::TestPaint() { | 313 std::string TestGraphics2D::TestPaint() { |
| 312 const int w = 15, h = 17; | 314 const int w = 15, h = 17; |
| 313 pp::Graphics2D dc(pp::Size(w, h), false); | 315 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 314 if (dc.is_null()) | 316 if (dc.is_null()) |
| 315 return "Failure creating a boring device"; | 317 return "Failure creating a boring device"; |
| 316 | 318 |
| 317 // Make sure the device background is 0. | 319 // Make sure the device background is 0. |
| 318 if (!IsDCUniformColor(dc, 0)) | 320 if (!IsDCUniformColor(dc, 0)) |
| 319 return "Bad initial color"; | 321 return "Bad initial color"; |
| 320 | 322 |
| 321 // Fill the backing store with white. | 323 // Fill the backing store with white. |
| 322 const uint32_t background_color = 0xFFFFFFFF; | 324 const uint32_t background_color = 0xFFFFFFFF; |
| 323 pp::ImageData background(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), | 325 pp::ImageData background(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 324 false); | 326 pp::Size(w, h), false); |
| 325 FillRectInImage(&background, pp::Rect(0, 0, w, h), background_color); | 327 FillRectInImage(&background, pp::Rect(0, 0, w, h), background_color); |
| 326 dc.PaintImageData(background, pp::Point(0, 0)); | 328 dc.PaintImageData(background, pp::Point(0, 0)); |
| 327 if (!FlushAndWaitForDone(&dc)) | 329 if (!FlushAndWaitForDone(&dc)) |
| 328 return "Couldn't flush to fill backing store"; | 330 return "Couldn't flush to fill backing store"; |
| 329 | 331 |
| 330 // Make an image to paint with that's opaque white and enqueue a paint. | 332 // Make an image to paint with that's opaque white and enqueue a paint. |
| 331 const int fill_w = 2, fill_h = 3; | 333 const int fill_w = 2, fill_h = 3; |
| 332 pp::ImageData fill(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(fill_w, fill_h), | 334 pp::ImageData fill(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 333 true); | 335 pp::Size(fill_w, fill_h), true); |
| 334 if (fill.is_null()) | 336 if (fill.is_null()) |
| 335 return "Failure to allocate fill image"; | 337 return "Failure to allocate fill image"; |
| 336 FillRectInImage(&fill, pp::Rect(fill.size()), background_color); | 338 FillRectInImage(&fill, pp::Rect(fill.size()), background_color); |
| 337 const int paint_x = 4, paint_y = 5; | 339 const int paint_x = 4, paint_y = 5; |
| 338 dc.PaintImageData(fill, pp::Point(paint_x, paint_y)); | 340 dc.PaintImageData(fill, pp::Point(paint_x, paint_y)); |
| 339 | 341 |
| 340 // Validate that nothing has been actually painted. | 342 // Validate that nothing has been actually painted. |
| 341 if (!IsDCUniformColor(dc, background_color)) | 343 if (!IsDCUniformColor(dc, background_color)) |
| 342 return "Image updated before flush (or failure in readback)."; | 344 return "Image updated before flush (or failure in readback)."; |
| 343 | 345 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 364 pp::Rect(-second_paint_x, -second_paint_y, 1, 1)); | 366 pp::Rect(-second_paint_x, -second_paint_y, 1, 1)); |
| 365 if (!FlushAndWaitForDone(&dc)) | 367 if (!FlushAndWaitForDone(&dc)) |
| 366 return "Couldn't flush second paint"; | 368 return "Couldn't flush second paint"; |
| 367 | 369 |
| 368 // Now we should have a little bit of the image peeking out the top left. | 370 // Now we should have a little bit of the image peeking out the top left. |
| 369 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), | 371 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), |
| 370 fill_color)) | 372 fill_color)) |
| 371 return "Partially offscreen paint failed."; | 373 return "Partially offscreen paint failed."; |
| 372 | 374 |
| 373 // Now repaint that top left pixel by doing a subset of the source image. | 375 // Now repaint that top left pixel by doing a subset of the source image. |
| 374 pp::ImageData subset(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), false); | 376 pp::ImageData subset(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 377 pp::Size(w, h), false); |
| 375 uint32_t subset_color = 0x80808080; | 378 uint32_t subset_color = 0x80808080; |
| 376 const int subset_x = 2, subset_y = 1; | 379 const int subset_x = 2, subset_y = 1; |
| 377 *subset.GetAddr32(pp::Point(subset_x, subset_y)) = subset_color; | 380 *subset.GetAddr32(pp::Point(subset_x, subset_y)) = subset_color; |
| 378 dc.PaintImageData(subset, pp::Point(-subset_x, -subset_y), | 381 dc.PaintImageData(subset, pp::Point(-subset_x, -subset_y), |
| 379 pp::Rect(subset_x, subset_y, 1, 1)); | 382 pp::Rect(subset_x, subset_y, 1, 1)); |
| 380 if (!FlushAndWaitForDone(&dc)) | 383 if (!FlushAndWaitForDone(&dc)) |
| 381 return "Couldn't flush repaint"; | 384 return "Couldn't flush repaint"; |
| 382 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), | 385 if (!IsSquareInDC(dc, background_color, pp::Rect(0, 0, 1, 1), |
| 383 subset_color)) | 386 subset_color)) |
| 384 return "Subset paint failed."; | 387 return "Subset paint failed."; |
| 385 | 388 |
| 386 return ""; | 389 return ""; |
| 387 } | 390 } |
| 388 | 391 |
| 389 std::string TestGraphics2D::TestScroll() { | 392 std::string TestGraphics2D::TestScroll() { |
| 390 const int w = 115, h = 117; | 393 const int w = 115, h = 117; |
| 391 pp::Graphics2D dc(pp::Size(w, h), false); | 394 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 392 if (dc.is_null()) | 395 if (dc.is_null()) |
| 393 return "Failure creating a boring device."; | 396 return "Failure creating a boring device."; |
| 394 | 397 |
| 395 // Make sure the device background is 0. | 398 // Make sure the device background is 0. |
| 396 if (!IsDCUniformColor(dc, 0)) | 399 if (!IsDCUniformColor(dc, 0)) |
| 397 return "Bad initial color."; | 400 return "Bad initial color."; |
| 398 | 401 |
| 399 const int image_w = 15, image_h = 23; | 402 const int image_w = 15, image_h = 23; |
| 400 pp::ImageData test_image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 403 pp::ImageData test_image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 401 pp::Size(image_w, image_h), false); | 404 pp::Size(image_w, image_h), false); |
| 402 FillImageWithGradient(&test_image); | 405 FillImageWithGradient(&test_image); |
| 403 | 406 |
| 404 int image_x = 51, image_y = 72; | 407 int image_x = 51, image_y = 72; |
| 405 dc.PaintImageData(test_image, pp::Point(image_x, image_y)); | 408 dc.PaintImageData(test_image, pp::Point(image_x, image_y)); |
| 406 if (!FlushAndWaitForDone(&dc)) | 409 if (!FlushAndWaitForDone(&dc)) |
| 407 return "Couldn't flush to fill backing store."; | 410 return "Couldn't flush to fill backing store."; |
| 408 | 411 |
| 409 // TC1, Scroll image to a free space. | 412 // TC1, Scroll image to a free space. |
| 410 int dx = -40, dy = -48; | 413 int dx = -40, dy = -48; |
| 411 pp::Rect clip = pp::Rect(image_x, image_y, test_image.size().width(), | 414 pp::Rect clip = pp::Rect(image_x, image_y, test_image.size().width(), |
| 412 test_image.size().height()); | 415 test_image.size().height()); |
| 413 dc.Scroll(clip, pp::Point(dx, dy)); | 416 dc.Scroll(clip, pp::Point(dx, dy)); |
| 414 | 417 |
| 415 if (!FlushAndWaitForDone(&dc)) | 418 if (!FlushAndWaitForDone(&dc)) |
| 416 return "TC1, Couldn't flush to scroll."; | 419 return "TC1, Couldn't flush to scroll."; |
| 417 | 420 |
| 418 image_x += dx; | 421 image_x += dx; |
| 419 image_y += dy; | 422 image_y += dy; |
| 420 | 423 |
| 421 pp::ImageData readback(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 424 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 422 pp::Size(image_w, image_h), false); | 425 pp::Size(image_w, image_h), false); |
| 423 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) | 426 if (!ReadImageData(dc, &readback, pp::Point(image_x, image_y))) |
| 424 return "TC1, Couldn't read back image data."; | 427 return "TC1, Couldn't read back image data."; |
| 425 | 428 |
| 426 if (!CompareImages(test_image, readback)) | 429 if (!CompareImages(test_image, readback)) |
| 427 return "TC1, Read back image is not the same as test image."; | 430 return "TC1, Read back image is not the same as test image."; |
| 428 | 431 |
| 429 // TC2, Scroll image to an overlapping space. | 432 // TC2, Scroll image to an overlapping space. |
| 430 dx = 6; | 433 dx = 6; |
| 431 dy = 9; | 434 dy = 9; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 443 return "TC2, Couldn't read back image data."; | 446 return "TC2, Couldn't read back image data."; |
| 444 | 447 |
| 445 if (!CompareImages(test_image, readback)) | 448 if (!CompareImages(test_image, readback)) |
| 446 return "TC2, Read back image is not the same as test image."; | 449 return "TC2, Read back image is not the same as test image."; |
| 447 | 450 |
| 448 return ""; | 451 return ""; |
| 449 } | 452 } |
| 450 | 453 |
| 451 std::string TestGraphics2D::TestReplace() { | 454 std::string TestGraphics2D::TestReplace() { |
| 452 const int w = 15, h = 17; | 455 const int w = 15, h = 17; |
| 453 pp::Graphics2D dc(pp::Size(w, h), false); | 456 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 454 if (dc.is_null()) | 457 if (dc.is_null()) |
| 455 return "Failure creating a boring device"; | 458 return "Failure creating a boring device"; |
| 456 | 459 |
| 457 // Replacing with a different size image should fail. | 460 // Replacing with a different size image should fail. |
| 458 pp::ImageData weird_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 461 pp::ImageData weird_size(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 459 pp::Size(w - 1, h), true); | 462 pp::Size(w - 1, h), true); |
| 460 if (weird_size.is_null()) | 463 if (weird_size.is_null()) |
| 461 return "Failure allocating the weird sized image"; | 464 return "Failure allocating the weird sized image"; |
| 462 dc.ReplaceContents(&weird_size); | 465 dc.ReplaceContents(&weird_size); |
| 463 | 466 |
| 464 // Fill the background with blue but don't flush yet. | 467 // Fill the background with blue but don't flush yet. |
| 465 const int32_t background_color = 0xFF0000FF; | 468 const int32_t background_color = 0xFF0000FF; |
| 466 pp::ImageData background(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), | 469 pp::ImageData background(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 467 true); | 470 pp::Size(w, h), true); |
| 468 if (background.is_null()) | 471 if (background.is_null()) |
| 469 return "Failure to allocate background image"; | 472 return "Failure to allocate background image"; |
| 470 FillRectInImage(&background, pp::Rect(0, 0, w, h), background_color); | 473 FillRectInImage(&background, pp::Rect(0, 0, w, h), background_color); |
| 471 dc.PaintImageData(background, pp::Point(0, 0)); | 474 dc.PaintImageData(background, pp::Point(0, 0)); |
| 472 | 475 |
| 473 // Replace with a green background but don't flush yet. | 476 // Replace with a green background but don't flush yet. |
| 474 const int32_t swapped_color = 0xFF0000FF; | 477 const int32_t swapped_color = 0xFF0000FF; |
| 475 pp::ImageData swapped(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 478 pp::ImageData swapped(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 479 pp::Size(w, h), true); |
| 476 if (swapped.is_null()) | 480 if (swapped.is_null()) |
| 477 return "Failure to allocate swapped image"; | 481 return "Failure to allocate swapped image"; |
| 478 FillRectInImage(&swapped, pp::Rect(0, 0, w, h), swapped_color); | 482 FillRectInImage(&swapped, pp::Rect(0, 0, w, h), swapped_color); |
| 479 dc.ReplaceContents(&swapped); | 483 dc.ReplaceContents(&swapped); |
| 480 | 484 |
| 481 // The background should be unchanged since we didn't flush yet. | 485 // The background should be unchanged since we didn't flush yet. |
| 482 if (!IsDCUniformColor(dc, 0)) | 486 if (!IsDCUniformColor(dc, 0)) |
| 483 return "Image updated before flush (or failure in readback)."; | 487 return "Image updated before flush (or failure in readback)."; |
| 484 | 488 |
| 485 // Test the C++ wrapper. The size of the swapped image should be reset. | 489 // Test the C++ wrapper. The size of the swapped image should be reset. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 498 if (!IsDCUniformColor(dc, swapped_color)) | 502 if (!IsDCUniformColor(dc, swapped_color)) |
| 499 return "Flushed color incorrect (or failure in readback)."; | 503 return "Flushed color incorrect (or failure in readback)."; |
| 500 | 504 |
| 501 return ""; | 505 return ""; |
| 502 } | 506 } |
| 503 | 507 |
| 504 std::string TestGraphics2D::TestFlush() { | 508 std::string TestGraphics2D::TestFlush() { |
| 505 // Tests that synchronous flushes (NULL callback) fail on the main thread | 509 // Tests that synchronous flushes (NULL callback) fail on the main thread |
| 506 // (which is the current one). | 510 // (which is the current one). |
| 507 const int w = 15, h = 17; | 511 const int w = 15, h = 17; |
| 508 pp::Graphics2D dc(pp::Size(w, h), false); | 512 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 509 if (dc.is_null()) | 513 if (dc.is_null()) |
| 510 return "Failure creating a boring device"; | 514 return "Failure creating a boring device"; |
| 511 | 515 |
| 512 // Fill the background with blue but don't flush yet. | 516 // Fill the background with blue but don't flush yet. |
| 513 pp::ImageData background(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), | 517 pp::ImageData background(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 514 true); | 518 pp::Size(w, h), true); |
| 515 if (background.is_null()) | 519 if (background.is_null()) |
| 516 return "Failure to allocate background image"; | 520 return "Failure to allocate background image"; |
| 517 dc.PaintImageData(background, pp::Point(0, 0)); | 521 dc.PaintImageData(background, pp::Point(0, 0)); |
| 518 | 522 |
| 519 int32_t rv = dc.Flush(pp::CompletionCallback::Block()); | 523 int32_t rv = dc.Flush(pp::CompletionCallback::Block()); |
| 520 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) | 524 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) |
| 521 return "Flush succeeded from the main thread with no callback."; | 525 return "Flush succeeded from the main thread with no callback."; |
| 522 | 526 |
| 523 // Test flushing with no operations still issues a callback. | 527 // Test flushing with no operations still issues a callback. |
| 524 // (This may also hang if the browser never issues the callback). | 528 // (This may also hang if the browser never issues the callback). |
| 525 pp::Graphics2D dc_nopaints(pp::Size(w, h), false); | 529 pp::Graphics2D dc_nopaints(instance_, pp::Size(w, h), false); |
| 526 if (dc.is_null()) | 530 if (dc.is_null()) |
| 527 return "Failure creating the nopaint device"; | 531 return "Failure creating the nopaint device"; |
| 528 if (!FlushAndWaitForDone(&dc_nopaints)) | 532 if (!FlushAndWaitForDone(&dc_nopaints)) |
| 529 return "Couldn't flush the nopaint device"; | 533 return "Couldn't flush the nopaint device"; |
| 530 | 534 |
| 531 // Test that multiple flushes fail if we don't get a callback in between. | 535 // Test that multiple flushes fail if we don't get a callback in between. |
| 532 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 536 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); |
| 533 if (rv != PP_OK && rv != PP_ERROR_WOULDBLOCK) | 537 if (rv != PP_OK && rv != PP_ERROR_WOULDBLOCK) |
| 534 return "Couldn't flush first time for multiple flush test."; | 538 return "Couldn't flush first time for multiple flush test."; |
| 535 | 539 |
| 536 if (rv != PP_OK) { | 540 if (rv != PP_OK) { |
| 537 // If the first flush would block, then a second should fail. | 541 // If the first flush would block, then a second should fail. |
| 538 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); | 542 rv = dc_nopaints.Flush(pp::CompletionCallback(&FlushCallbackNOP, NULL)); |
| 539 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) | 543 if (rv == PP_OK || rv == PP_ERROR_WOULDBLOCK) |
| 540 return "Second flush succeeded before callback ran."; | 544 return "Second flush succeeded before callback ran."; |
| 541 } | 545 } |
| 542 | 546 |
| 543 return ""; | 547 return ""; |
| 544 } | 548 } |
| OLD | NEW |