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> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return graphics_2d_interface_ && image_data_interface_ && | 52 return graphics_2d_interface_ && image_data_interface_ && |
53 CheckTestingInterface(); | 53 CheckTestingInterface(); |
54 } | 54 } |
55 | 55 |
56 void TestGraphics2D::RunTests(const std::string& filter) { | 56 void TestGraphics2D::RunTests(const std::string& filter) { |
57 RUN_TEST(InvalidResource, filter); | 57 RUN_TEST(InvalidResource, filter); |
58 RUN_TEST(InvalidSize, filter); | 58 RUN_TEST(InvalidSize, filter); |
59 RUN_TEST(Humongous, filter); | 59 RUN_TEST(Humongous, filter); |
60 RUN_TEST(InitToZero, filter); | 60 RUN_TEST(InitToZero, filter); |
61 RUN_TEST(Describe, filter); | 61 RUN_TEST(Describe, filter); |
| 62 RUN_TEST(Scale, filter); |
62 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); | 63 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); |
63 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); | 64 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); |
64 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); | 65 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); |
65 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter); | 66 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter); |
66 RUN_TEST_FORCEASYNC_AND_NOT(FlushOffscreenUpdate, filter); | 67 RUN_TEST_FORCEASYNC_AND_NOT(FlushOffscreenUpdate, filter); |
67 RUN_TEST(Dev, filter); | 68 RUN_TEST(Dev, filter); |
68 RUN_TEST(ReplaceContentsCaching, filter); | 69 RUN_TEST(ReplaceContentsCaching, filter); |
69 RUN_TEST(BindNull, filter); | 70 RUN_TEST(BindNull, filter); |
70 } | 71 } |
71 | 72 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, | 363 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, |
363 &is_always_opaque)) | 364 &is_always_opaque)) |
364 return "Describe failed"; | 365 return "Describe failed"; |
365 if (size.width != w || size.height != h || | 366 if (size.width != w || size.height != h || |
366 is_always_opaque != PP_FromBool(always_opaque)) | 367 is_always_opaque != PP_FromBool(always_opaque)) |
367 return "Mismatch of data."; | 368 return "Mismatch of data."; |
368 | 369 |
369 PASS(); | 370 PASS(); |
370 } | 371 } |
371 | 372 |
| 373 std::string TestGraphics2D::TestScale() { |
| 374 // Tests GetScale/SetScale |
| 375 const int w = 20, h = 16; |
| 376 const float scale = 1.0f/2.0f; |
| 377 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
| 378 if (dc.is_null()) |
| 379 return "Failure creating a boring device"; |
| 380 if (dc.GetScale() != 1.0f) |
| 381 return "GetScale returned unexpected value before SetScale"; |
| 382 if (!dc.SetScale(scale)) |
| 383 return "SetScale failed"; |
| 384 if (dc.GetScale() != scale) |
| 385 return "GetScale mismatch with prior SetScale"; |
| 386 // Try setting a few invalid scale factors. Ensure that we catch these errors |
| 387 // and don't change the actual scale |
| 388 if (dc.SetScale(-1.0f)) |
| 389 return "SetScale(-1f) did not fail"; |
| 390 if (dc.SetScale(0.0f)) |
| 391 return "SetScale(0.0f) did not fail"; |
| 392 if (dc.GetScale() != scale) |
| 393 return "SetScale with invalid parameter overwrote the scale"; |
| 394 |
| 395 // Verify that the context has the specified number of pixels, despite the |
| 396 // non-identity scale |
| 397 PP_Size size; |
| 398 size.width = -1; |
| 399 size.height = -1; |
| 400 PP_Bool is_always_opaque = PP_FALSE; |
| 401 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, |
| 402 &is_always_opaque)) |
| 403 return "Describe failed"; |
| 404 if (size.width != w || size.height != h || |
| 405 is_always_opaque != PP_FromBool(false)) |
| 406 return "Mismatch of data."; |
| 407 |
| 408 PASS(); |
| 409 } |
| 410 |
372 std::string TestGraphics2D::TestPaint() { | 411 std::string TestGraphics2D::TestPaint() { |
373 const int w = 15, h = 17; | 412 const int w = 15, h = 17; |
374 pp::Graphics2D dc(instance_, pp::Size(w, h), false); | 413 pp::Graphics2D dc(instance_, pp::Size(w, h), false); |
375 if (dc.is_null()) | 414 if (dc.is_null()) |
376 return "Failure creating a boring device"; | 415 return "Failure creating a boring device"; |
377 | 416 |
378 // Make sure the device background is 0. | 417 // Make sure the device background is 0. |
379 if (!IsDCUniformColor(dc, 0)) | 418 if (!IsDCUniformColor(dc, 0)) |
380 return "Bad initial color"; | 419 return "Bad initial color"; |
381 | 420 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 return "Failure creating device."; | 905 return "Failure creating device."; |
867 if (!instance_->BindGraphics(dc)) | 906 if (!instance_->BindGraphics(dc)) |
868 return "Failure to bind the boring device."; | 907 return "Failure to bind the boring device."; |
869 | 908 |
870 ASSERT_TRUE(instance_->BindGraphics(pp::Graphics2D())); | 909 ASSERT_TRUE(instance_->BindGraphics(pp::Graphics2D())); |
871 ASSERT_TRUE(instance_->BindGraphics(pp::Graphics3D())); | 910 ASSERT_TRUE(instance_->BindGraphics(pp::Graphics3D())); |
872 | 911 |
873 PASS(); | 912 PASS(); |
874 } | 913 } |
875 | 914 |
OLD | NEW |