OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 helper.context()->fillRect(bottomRight, green, ColorSpaceDeviceRGB); | 388 helper.context()->fillRect(bottomRight, green, ColorSpaceDeviceRGB); |
389 helper.composite(); | 389 helper.composite(); |
390 } | 390 } |
391 | 391 |
392 src->context()->restore(); | 392 src->context()->restore(); |
393 | 393 |
394 // Check the pixel we wrote. | 394 // Check the pixel we wrote. |
395 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); | 395 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); |
396 } | 396 } |
397 | 397 |
| 398 static void testClippedLayerKeepTransform(TransparencyWin::LayerMode layerMode) |
| 399 { |
| 400 // Fill with white. |
| 401 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); |
| 402 Color white(0xFFFFFFFF); |
| 403 FloatRect fullRect(0, 0, 16, 16); |
| 404 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); |
| 405 |
| 406 IntRect clipRect(IntPoint(11, 5), IntSize(1, 1)); |
| 407 src->context()->clip(clipRect); |
| 408 |
| 409 // Scroll down by 6 (coordinate system goes up). |
| 410 src->context()->save(); |
| 411 src->context()->translate(0, -6); |
| 412 |
| 413 Color red(0xFFFF0000); |
| 414 Color green(0xFF00FF00); |
| 415 { |
| 416 // The transparency layer after translation will be @ (0, -6) with |
| 417 // a size that would be too large to handle unclipped. |
| 418 TransparencyWin helper; |
| 419 helper.init(src->context(), |
| 420 layerMode, |
| 421 TransparencyWin::KeepTransform, |
| 422 IntRect(0, 0, INT_MAX, INT_MAX)); |
| 423 |
| 424 // Draw a green pixel at (11, 11). This should be within the clip rect |
| 425 // and at (11, 5) after the transform. |
| 426 FloatRect greenRect(11, 11, 1, 1); |
| 427 helper.context()->fillRect(greenRect, green, ColorSpaceDeviceRGB); |
| 428 |
| 429 // Draw a red pixel at (9, 9). This should be outside the clip rect |
| 430 // and not drawn. |
| 431 FloatRect redRect(9, 9, 1, 1); |
| 432 helper.context()->fillRect(redRect, red, ColorSpaceDeviceRGB); |
| 433 helper.composite(); |
| 434 } |
| 435 |
| 436 src->context()->restore(); |
| 437 |
| 438 // Verify green pixel got drawn in clip rect and red pixel got clipped. |
| 439 EXPECT_EQ(green, getPixelAt(src->context(), 11, 5)); |
| 440 EXPECT_EQ(white, getPixelAt(src->context(), 9, 3)); |
| 441 } |
| 442 |
| 443 TEST(TransparencyWin, ClippedKeepTransformNoLayer) |
| 444 { |
| 445 testClippedLayerKeepTransform(TransparencyWin::NoLayer); |
| 446 } |
| 447 |
| 448 TEST(TransparencyWin, ClippedKeepTransformOpaqueCompositeLayer) |
| 449 { |
| 450 testClippedLayerKeepTransform(TransparencyWin::OpaqueCompositeLayer); |
| 451 } |
| 452 |
| 453 TEST(TransparencyWin, ClippedKeepTransformWhiteLayer) |
| 454 { |
| 455 testClippedLayerKeepTransform(TransparencyWin::WhiteLayer); |
| 456 } |
| 457 |
398 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This | 458 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This |
399 // tests that the propert transform is applied to the copied layer. | 459 // tests that the propert transform is applied to the copied layer. |
400 TEST(TransparencyWin, RotateOpaqueCompositeLayer) | 460 TEST(TransparencyWin, RotateOpaqueCompositeLayer) |
401 { | 461 { |
402 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 462 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); |
403 | 463 |
404 // The background is white. | 464 // The background is white. |
405 Color white(0xFFFFFFFF); | 465 Color white(0xFFFFFFFF); |
406 FloatRect fullRect(0, 0, 16, 16); | 466 FloatRect fullRect(0, 0, 16, 16); |
407 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); | 467 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); | 739 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); |
680 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); | 740 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); |
681 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); | 741 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); |
682 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); | 742 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); |
683 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); | 743 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); |
684 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); | 744 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); |
685 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); | 745 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); |
686 } | 746 } |
687 | 747 |
688 } // namespace WebCore | 748 } // namespace WebCore |
OLD | NEW |