| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 { | 94 { |
| 95 std::ios_base::fmtflags oldFlags = out.flags(std::ios_base::hex | | 95 std::ios_base::fmtflags oldFlags = out.flags(std::ios_base::hex | |
| 96 std::ios_base::showbase); | 96 std::ios_base::showbase); |
| 97 out << c.rgb(); | 97 out << c.rgb(); |
| 98 out.flags(oldFlags); | 98 out.flags(oldFlags); |
| 99 return out; | 99 return out; |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST(TransparencyWin, NoLayer) | 102 TEST(TransparencyWin, NoLayer) |
| 103 { | 103 { |
| 104 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(17, 16), 1, ColorSpaceDe
viceRGB)); | 104 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(17, 16), 1)); |
| 105 | 105 |
| 106 // KeepTransform | 106 // KeepTransform |
| 107 { | 107 { |
| 108 TransparencyWin helper; | 108 TransparencyWin helper; |
| 109 helper.init(src->context(), | 109 helper.init(src->context(), |
| 110 TransparencyWin::NoLayer, | 110 TransparencyWin::NoLayer, |
| 111 TransparencyWin::KeepTransform, | 111 TransparencyWin::KeepTransform, |
| 112 IntRect(1, 1, 14, 12)); | 112 IntRect(1, 1, 14, 12)); |
| 113 | 113 |
| 114 EXPECT_TRUE(src->context() == helper.context()); | 114 EXPECT_TRUE(src->context() == helper.context()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 133 // It should be post-transformed. | 133 // It should be post-transformed. |
| 134 EXPECT_TRUE(src->context() == helper.context()); | 134 EXPECT_TRUE(src->context() == helper.context()); |
| 135 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); | 135 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); |
| 136 EXPECT_TRUE(IntRect(4, 1, 12, 3) == helper.drawRect()); | 136 EXPECT_TRUE(IntRect(4, 1, 12, 3) == helper.drawRect()); |
| 137 } | 137 } |
| 138 src->context()->restore(); | 138 src->context()->restore(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST(TransparencyWin, WhiteLayer) | 141 TEST(TransparencyWin, WhiteLayer) |
| 142 { | 142 { |
| 143 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 143 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 144 | 144 |
| 145 // KeepTransform | 145 // KeepTransform |
| 146 { | 146 { |
| 147 TransparencyWin helper; | 147 TransparencyWin helper; |
| 148 helper.init(src->context(), | 148 helper.init(src->context(), |
| 149 TransparencyWin::WhiteLayer, | 149 TransparencyWin::WhiteLayer, |
| 150 TransparencyWin::KeepTransform, | 150 TransparencyWin::KeepTransform, |
| 151 IntRect(1, 1, 14, 12)); | 151 IntRect(1, 1, 14, 12)); |
| 152 helper.composite(); | 152 helper.composite(); |
| 153 | 153 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // It should be post-transformed. | 185 // It should be post-transformed. |
| 186 EXPECT_TRUE(src->context() != helper.context()); | 186 EXPECT_TRUE(src->context() != helper.context()); |
| 187 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); | 187 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); |
| 188 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); | 188 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); |
| 189 } | 189 } |
| 190 src->context()->restore(); | 190 src->context()->restore(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST(TransparencyWin, TextComposite) | 193 TEST(TransparencyWin, TextComposite) |
| 194 { | 194 { |
| 195 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 195 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 196 | 196 |
| 197 // KeepTransform is the only valid transform mode for TextComposite. | 197 // KeepTransform is the only valid transform mode for TextComposite. |
| 198 { | 198 { |
| 199 TransparencyWin helper; | 199 TransparencyWin helper; |
| 200 helper.init(src->context(), | 200 helper.init(src->context(), |
| 201 TransparencyWin::TextComposite, | 201 TransparencyWin::TextComposite, |
| 202 TransparencyWin::KeepTransform, | 202 TransparencyWin::KeepTransform, |
| 203 IntRect(1, 1, 14, 12)); | 203 IntRect(1, 1, 14, 12)); |
| 204 helper.composite(); | 204 helper.composite(); |
| 205 | 205 |
| 206 EXPECT_TRUE(src->context() != helper.context()); | 206 EXPECT_TRUE(src->context() != helper.context()); |
| 207 EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); | 207 EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); |
| 208 EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); | 208 EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST(TransparencyWin, OpaqueCompositeLayer) | 212 TEST(TransparencyWin, OpaqueCompositeLayer) |
| 213 { | 213 { |
| 214 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 214 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 215 | 215 |
| 216 // KeepTransform | 216 // KeepTransform |
| 217 { | 217 { |
| 218 TransparencyWin helper; | 218 TransparencyWin helper; |
| 219 helper.init(src->context(), | 219 helper.init(src->context(), |
| 220 TransparencyWin::OpaqueCompositeLayer, | 220 TransparencyWin::OpaqueCompositeLayer, |
| 221 TransparencyWin::KeepTransform, | 221 TransparencyWin::KeepTransform, |
| 222 IntRect(1, 1, 14, 12)); | 222 IntRect(1, 1, 14, 12)); |
| 223 helper.composite(); | 223 helper.composite(); |
| 224 | 224 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 EXPECT_TRUE(src->context() != helper.context()); | 274 EXPECT_TRUE(src->context() != helper.context()); |
| 275 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); | 275 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); |
| 276 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); | 276 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); |
| 277 } | 277 } |
| 278 src->context()->restore(); | 278 src->context()->restore(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST(TransparencyWin, WhiteLayerPixelTest) | 281 TEST(TransparencyWin, WhiteLayerPixelTest) |
| 282 { | 282 { |
| 283 // Make a total transparent buffer, and draw the white layer inset by 1 px. | 283 // Make a total transparent buffer, and draw the white layer inset by 1 px. |
| 284 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 284 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 285 | 285 |
| 286 { | 286 { |
| 287 TransparencyWin helper; | 287 TransparencyWin helper; |
| 288 helper.init(src->context(), | 288 helper.init(src->context(), |
| 289 TransparencyWin::WhiteLayer, | 289 TransparencyWin::WhiteLayer, |
| 290 TransparencyWin::KeepTransform, | 290 TransparencyWin::KeepTransform, |
| 291 IntRect(1, 1, 14, 14)); | 291 IntRect(1, 1, 14, 14)); |
| 292 | 292 |
| 293 // Coordinates should be in the original space, not the layer. | 293 // Coordinates should be in the original space, not the layer. |
| 294 drawNativeRect(helper.context(), 3, 3, 1, 1); | 294 drawNativeRect(helper.context(), 3, 3, 1, 1); |
| 295 clearTopLayerAlphaChannel(helper.context()); | 295 clearTopLayerAlphaChannel(helper.context()); |
| 296 helper.composite(); | 296 helper.composite(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // The final image should be transparent around the edges for 1 px, white | 299 // The final image should be transparent around the edges for 1 px, white |
| 300 // in the middle, with (3,3) (what we drew above) being opaque black. | 300 // in the middle, with (3,3) (what we drew above) being opaque black. |
| 301 EXPECT_EQ(Color(Color::transparent), getPixelAt(src->context(), 0, 0)); | 301 EXPECT_EQ(Color(Color::transparent), getPixelAt(src->context(), 0, 0)); |
| 302 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); | 302 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); |
| 303 EXPECT_EQ(Color(Color::black), getPixelAt(src->context(), 3, 3)); | 303 EXPECT_EQ(Color(Color::black), getPixelAt(src->context(), 3, 3)); |
| 304 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 4, 4)); | 304 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 4, 4)); |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST(TransparencyWin, OpaqueCompositeLayerPixel) | 307 TEST(TransparencyWin, OpaqueCompositeLayerPixel) |
| 308 { | 308 { |
| 309 Color red(0xFFFF0000), darkRed(0xFFBF0000); | 309 Color red(0xFFFF0000), darkRed(0xFFBF0000); |
| 310 Color green(0xFF00FF00); | 310 Color green(0xFF00FF00); |
| 311 | 311 |
| 312 // Make a red bottom layer, followed by a half green next layer @ 50%. | 312 // Make a red bottom layer, followed by a half green next layer @ 50%. |
| 313 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 313 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 314 | 314 |
| 315 FloatRect fullRect(0, 0, 16, 16); | 315 FloatRect fullRect(0, 0, 16, 16); |
| 316 src->context()->fillRect(fullRect, red, ColorSpaceDeviceRGB); | 316 src->context()->fillRect(fullRect, red); |
| 317 src->context()->beginTransparencyLayer(0.5); | 317 src->context()->beginTransparencyLayer(0.5); |
| 318 FloatRect rightHalf(8, 0, 8, 16); | 318 FloatRect rightHalf(8, 0, 8, 16); |
| 319 src->context()->fillRect(rightHalf, green, ColorSpaceDeviceRGB); | 319 src->context()->fillRect(rightHalf, green); |
| 320 | 320 |
| 321 // Make a transparency layer inset by one pixel, and fill it inset by | 321 // Make a transparency layer inset by one pixel, and fill it inset by |
| 322 // another pixel with 50% black. | 322 // another pixel with 50% black. |
| 323 { | 323 { |
| 324 TransparencyWin helper; | 324 TransparencyWin helper; |
| 325 helper.init(src->context(), | 325 helper.init(src->context(), |
| 326 TransparencyWin::OpaqueCompositeLayer, | 326 TransparencyWin::OpaqueCompositeLayer, |
| 327 TransparencyWin::KeepTransform, | 327 TransparencyWin::KeepTransform, |
| 328 IntRect(1, 1, 14, 14)); | 328 IntRect(1, 1, 14, 14)); |
| 329 | 329 |
| 330 FloatRect inner(2, 2, 12, 12); | 330 FloatRect inner(2, 2, 12, 12); |
| 331 helper.context()->fillRect(inner, Color(0x7f000000), ColorSpaceDeviceRGB
); | 331 helper.context()->fillRect(inner, Color(0x7f000000)); |
| 332 // These coordinates are relative to the layer, whish is inset by 1x1 | 332 // These coordinates are relative to the layer, whish is inset by 1x1 |
| 333 // pixels from the top left. So we're actually clearing (2, 2) and | 333 // pixels from the top left. So we're actually clearing (2, 2) and |
| 334 // (13,13), which are the extreme corners of the black area (and which | 334 // (13,13), which are the extreme corners of the black area (and which |
| 335 // we check below). | 335 // we check below). |
| 336 clearTopLayerAlphaPixel(helper.context(), 1, 1); | 336 clearTopLayerAlphaPixel(helper.context(), 1, 1); |
| 337 clearTopLayerAlphaPixel(helper.context(), 12, 12); | 337 clearTopLayerAlphaPixel(helper.context(), 12, 12); |
| 338 helper.composite(); | 338 helper.composite(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // Finish the compositing. | 341 // Finish the compositing. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 356 // 50% green on top of red = FF808000 (rounded to what Skia will produce). | 356 // 50% green on top of red = FF808000 (rounded to what Skia will produce). |
| 357 Color greenRed(0xFF807F00); | 357 Color greenRed(0xFF807F00); |
| 358 EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14)); | 358 EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14)); |
| 359 EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15)); | 359 EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Tests that translations are properly handled when using KeepTransform. | 362 // Tests that translations are properly handled when using KeepTransform. |
| 363 TEST(TransparencyWin, TranslateOpaqueCompositeLayer) | 363 TEST(TransparencyWin, TranslateOpaqueCompositeLayer) |
| 364 { | 364 { |
| 365 // Fill with white. | 365 // Fill with white. |
| 366 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 366 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 367 Color white(0xFFFFFFFF); | 367 Color white(0xFFFFFFFF); |
| 368 FloatRect fullRect(0, 0, 16, 16); | 368 FloatRect fullRect(0, 0, 16, 16); |
| 369 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); | 369 src->context()->fillRect(fullRect, white); |
| 370 | 370 |
| 371 // Scroll down by 8 (coordinate system goes up). | 371 // Scroll down by 8 (coordinate system goes up). |
| 372 src->context()->save(); | 372 src->context()->save(); |
| 373 src->context()->translate(0, -8); | 373 src->context()->translate(0, -8); |
| 374 | 374 |
| 375 Color red(0xFFFF0000); | 375 Color red(0xFFFF0000); |
| 376 Color green(0xFF00FF00); | 376 Color green(0xFF00FF00); |
| 377 { | 377 { |
| 378 // Make the transparency layer after translation will be @ (0, -8) with | 378 // Make the transparency layer after translation will be @ (0, -8) with |
| 379 // size 16x16. | 379 // size 16x16. |
| 380 TransparencyWin helper; | 380 TransparencyWin helper; |
| 381 helper.init(src->context(), | 381 helper.init(src->context(), |
| 382 TransparencyWin::OpaqueCompositeLayer, | 382 TransparencyWin::OpaqueCompositeLayer, |
| 383 TransparencyWin::KeepTransform, | 383 TransparencyWin::KeepTransform, |
| 384 IntRect(0, 0, 16, 16)); | 384 IntRect(0, 0, 16, 16)); |
| 385 | 385 |
| 386 // Draw a red pixel at (15, 15). This should be the at (15, 7) after | 386 // Draw a red pixel at (15, 15). This should be the at (15, 7) after |
| 387 // the transform. | 387 // the transform. |
| 388 FloatRect bottomRight(15, 15, 1, 1); | 388 FloatRect bottomRight(15, 15, 1, 1); |
| 389 helper.context()->fillRect(bottomRight, green, ColorSpaceDeviceRGB); | 389 helper.context()->fillRect(bottomRight, green); |
| 390 helper.composite(); | 390 helper.composite(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 src->context()->restore(); | 393 src->context()->restore(); |
| 394 | 394 |
| 395 // Check the pixel we wrote. | 395 // Check the pixel we wrote. |
| 396 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); | 396 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); |
| 397 } | 397 } |
| 398 | 398 |
| 399 static void testClippedLayerKeepTransform(TransparencyWin::LayerMode layerMode) | 399 static void testClippedLayerKeepTransform(TransparencyWin::LayerMode layerMode) |
| 400 { | 400 { |
| 401 // Fill with white. | 401 // Fill with white. |
| 402 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 402 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 403 Color white(0xFFFFFFFF); | 403 Color white(0xFFFFFFFF); |
| 404 FloatRect fullRect(0, 0, 16, 16); | 404 FloatRect fullRect(0, 0, 16, 16); |
| 405 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); | 405 src->context()->fillRect(fullRect, white); |
| 406 | 406 |
| 407 IntRect clipRect(IntPoint(11, 5), IntSize(1, 1)); | 407 IntRect clipRect(IntPoint(11, 5), IntSize(1, 1)); |
| 408 src->context()->clip(clipRect); | 408 src->context()->clip(clipRect); |
| 409 | 409 |
| 410 // Scroll down by 6 (coordinate system goes up). | 410 // Scroll down by 6 (coordinate system goes up). |
| 411 src->context()->save(); | 411 src->context()->save(); |
| 412 src->context()->translate(0, -6); | 412 src->context()->translate(0, -6); |
| 413 | 413 |
| 414 Color red(0xFFFF0000); | 414 Color red(0xFFFF0000); |
| 415 Color green(0xFF00FF00); | 415 Color green(0xFF00FF00); |
| 416 { | 416 { |
| 417 // The transparency layer after translation will be @ (0, -6) with | 417 // The transparency layer after translation will be @ (0, -6) with |
| 418 // a size that would be too large to handle unclipped. | 418 // a size that would be too large to handle unclipped. |
| 419 TransparencyWin helper; | 419 TransparencyWin helper; |
| 420 helper.init(src->context(), | 420 helper.init(src->context(), |
| 421 layerMode, | 421 layerMode, |
| 422 TransparencyWin::KeepTransform, | 422 TransparencyWin::KeepTransform, |
| 423 IntRect(0, 0, INT_MAX, INT_MAX)); | 423 IntRect(0, 0, INT_MAX, INT_MAX)); |
| 424 | 424 |
| 425 // Draw a green pixel at (11, 11). This should be within the clip rect | 425 // Draw a green pixel at (11, 11). This should be within the clip rect |
| 426 // and at (11, 5) after the transform. | 426 // and at (11, 5) after the transform. |
| 427 FloatRect greenRect(11, 11, 1, 1); | 427 FloatRect greenRect(11, 11, 1, 1); |
| 428 helper.context()->fillRect(greenRect, green, ColorSpaceDeviceRGB); | 428 helper.context()->fillRect(greenRect, green); |
| 429 | 429 |
| 430 // Draw a red pixel at (9, 9). This should be outside the clip rect | 430 // Draw a red pixel at (9, 9). This should be outside the clip rect |
| 431 // and not drawn. | 431 // and not drawn. |
| 432 FloatRect redRect(9, 9, 1, 1); | 432 FloatRect redRect(9, 9, 1, 1); |
| 433 helper.context()->fillRect(redRect, red, ColorSpaceDeviceRGB); | 433 helper.context()->fillRect(redRect, red); |
| 434 helper.composite(); | 434 helper.composite(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 src->context()->restore(); | 437 src->context()->restore(); |
| 438 | 438 |
| 439 // Verify green pixel got drawn in clip rect and red pixel got clipped. | 439 // Verify green pixel got drawn in clip rect and red pixel got clipped. |
| 440 EXPECT_EQ(green, getPixelAt(src->context(), 11, 5)); | 440 EXPECT_EQ(green, getPixelAt(src->context(), 11, 5)); |
| 441 EXPECT_EQ(white, getPixelAt(src->context(), 9, 3)); | 441 EXPECT_EQ(white, getPixelAt(src->context(), 9, 3)); |
| 442 } | 442 } |
| 443 | 443 |
| 444 TEST(TransparencyWin, ClippedKeepTransformNoLayer) | 444 TEST(TransparencyWin, ClippedKeepTransformNoLayer) |
| 445 { | 445 { |
| 446 testClippedLayerKeepTransform(TransparencyWin::NoLayer); | 446 testClippedLayerKeepTransform(TransparencyWin::NoLayer); |
| 447 } | 447 } |
| 448 | 448 |
| 449 TEST(TransparencyWin, ClippedKeepTransformOpaqueCompositeLayer) | 449 TEST(TransparencyWin, ClippedKeepTransformOpaqueCompositeLayer) |
| 450 { | 450 { |
| 451 testClippedLayerKeepTransform(TransparencyWin::OpaqueCompositeLayer); | 451 testClippedLayerKeepTransform(TransparencyWin::OpaqueCompositeLayer); |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST(TransparencyWin, ClippedKeepTransformWhiteLayer) | 454 TEST(TransparencyWin, ClippedKeepTransformWhiteLayer) |
| 455 { | 455 { |
| 456 testClippedLayerKeepTransform(TransparencyWin::WhiteLayer); | 456 testClippedLayerKeepTransform(TransparencyWin::WhiteLayer); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This | 459 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This |
| 460 // tests that the propert transform is applied to the copied layer. | 460 // tests that the propert transform is applied to the copied layer. |
| 461 TEST(TransparencyWin, RotateOpaqueCompositeLayer) | 461 TEST(TransparencyWin, RotateOpaqueCompositeLayer) |
| 462 { | 462 { |
| 463 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 463 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 464 | 464 |
| 465 // The background is white. | 465 // The background is white. |
| 466 Color white(0xFFFFFFFF); | 466 Color white(0xFFFFFFFF); |
| 467 FloatRect fullRect(0, 0, 16, 16); | 467 FloatRect fullRect(0, 0, 16, 16); |
| 468 src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); | 468 src->context()->fillRect(fullRect, white); |
| 469 | 469 |
| 470 // Rotate the image by 90 degrees. This matrix is the same as | 470 // Rotate the image by 90 degrees. This matrix is the same as |
| 471 // cw90.rotate(90); but avoids rounding errors. Rounding errors can cause | 471 // cw90.rotate(90); but avoids rounding errors. Rounding errors can cause |
| 472 // Skia to think that !rectStaysRect() and it will fall through to path | 472 // Skia to think that !rectStaysRect() and it will fall through to path |
| 473 // drawing mode, which in turn gives us antialiasing. We want no | 473 // drawing mode, which in turn gives us antialiasing. We want no |
| 474 // antialiasing or other rounding problems since we're testing exact pixel | 474 // antialiasing or other rounding problems since we're testing exact pixel |
| 475 // values. | 475 // values. |
| 476 src->context()->save(); | 476 src->context()->save(); |
| 477 AffineTransform cw90(0, 1, -1, 0, 0, 0); | 477 AffineTransform cw90(0, 1, -1, 0, 0, 0); |
| 478 src->context()->concatCTM(cw90); | 478 src->context()->concatCTM(cw90); |
| 479 | 479 |
| 480 // Make a transparency layer consisting of a horizontal line of 50% black. | 480 // Make a transparency layer consisting of a horizontal line of 50% black. |
| 481 // Since the rotation is applied, this will actually be a vertical line | 481 // Since the rotation is applied, this will actually be a vertical line |
| 482 // down the middle of the image. | 482 // down the middle of the image. |
| 483 src->context()->beginTransparencyLayer(0.5); | 483 src->context()->beginTransparencyLayer(0.5); |
| 484 FloatRect blackRect(0, -9, 16, 2); | 484 FloatRect blackRect(0, -9, 16, 2); |
| 485 Color black(0xFF000000); | 485 Color black(0xFF000000); |
| 486 src->context()->fillRect(blackRect, black, ColorSpaceDeviceRGB); | 486 src->context()->fillRect(blackRect, black); |
| 487 | 487 |
| 488 // Now draw 50% red square. | 488 // Now draw 50% red square. |
| 489 { | 489 { |
| 490 // Create a transparency helper inset one pixel in the buffer. The | 490 // Create a transparency helper inset one pixel in the buffer. The |
| 491 // coordinates are before transforming into this space, and maps to | 491 // coordinates are before transforming into this space, and maps to |
| 492 // IntRect(1, 1, 14, 14). | 492 // IntRect(1, 1, 14, 14). |
| 493 TransparencyWin helper; | 493 TransparencyWin helper; |
| 494 helper.init(src->context(), | 494 helper.init(src->context(), |
| 495 TransparencyWin::OpaqueCompositeLayer, | 495 TransparencyWin::OpaqueCompositeLayer, |
| 496 TransparencyWin::Untransform, | 496 TransparencyWin::Untransform, |
| 497 IntRect(1, -15, 14, 14)); | 497 IntRect(1, -15, 14, 14)); |
| 498 | 498 |
| 499 // Fill with red. | 499 // Fill with red. |
| 500 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000), ColorSp
aceDeviceRGB); | 500 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000)); |
| 501 clearTopLayerAlphaChannel(helper.context()); | 501 clearTopLayerAlphaChannel(helper.context()); |
| 502 helper.composite(); | 502 helper.composite(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 // Finish the compositing. | 505 // Finish the compositing. |
| 506 src->context()->endTransparencyLayer(); | 506 src->context()->endTransparencyLayer(); |
| 507 | 507 |
| 508 // Top corner should be the original background. | 508 // Top corner should be the original background. |
| 509 EXPECT_EQ(white, getPixelAt(src->context(), 0, 0)); | 509 EXPECT_EQ(white, getPixelAt(src->context(), 0, 0)); |
| 510 | 510 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 532 EXPECT_EQ(redwhite, getPixelAt(src->context(), 9, 1)); | 532 EXPECT_EQ(redwhite, getPixelAt(src->context(), 9, 1)); |
| 533 EXPECT_EQ(redwhite, getPixelAt(src->context(), 14, 1)); | 533 EXPECT_EQ(redwhite, getPixelAt(src->context(), 14, 1)); |
| 534 EXPECT_EQ(white, getPixelAt(src->context(), 15, 1)); | 534 EXPECT_EQ(white, getPixelAt(src->context(), 15, 1)); |
| 535 | 535 |
| 536 // Complete the 50% transparent layer. | 536 // Complete the 50% transparent layer. |
| 537 src->context()->restore(); | 537 src->context()->restore(); |
| 538 } | 538 } |
| 539 | 539 |
| 540 TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer) | 540 TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer) |
| 541 { | 541 { |
| 542 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 542 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 543 | 543 |
| 544 // The background is white on top with red on bottom. | 544 // The background is white on top with red on bottom. |
| 545 Color white(0xFFFFFFFF); | 545 Color white(0xFFFFFFFF); |
| 546 FloatRect topRect(0, 0, 16, 8); | 546 FloatRect topRect(0, 0, 16, 8); |
| 547 src->context()->fillRect(topRect, white, ColorSpaceDeviceRGB); | 547 src->context()->fillRect(topRect, white); |
| 548 Color red(0xFFFF0000); | 548 Color red(0xFFFF0000); |
| 549 FloatRect bottomRect(0, 8, 16, 8); | 549 FloatRect bottomRect(0, 8, 16, 8); |
| 550 src->context()->fillRect(bottomRect, red, ColorSpaceDeviceRGB); | 550 src->context()->fillRect(bottomRect, red); |
| 551 | 551 |
| 552 src->context()->save(); | 552 src->context()->save(); |
| 553 | 553 |
| 554 // Translate left by one pixel. | 554 // Translate left by one pixel. |
| 555 AffineTransform left; | 555 AffineTransform left; |
| 556 left.translate(-1, 0); | 556 left.translate(-1, 0); |
| 557 | 557 |
| 558 // Scale by 2x. | 558 // Scale by 2x. |
| 559 AffineTransform scale; | 559 AffineTransform scale; |
| 560 scale.scale(2.0); | 560 scale.scale(2.0); |
| 561 src->context()->concatCTM(scale); | 561 src->context()->concatCTM(scale); |
| 562 | 562 |
| 563 // Then translate up by one pixel (which will actually be 2 due to scaling). | 563 // Then translate up by one pixel (which will actually be 2 due to scaling). |
| 564 AffineTransform up; | 564 AffineTransform up; |
| 565 up.translate(0, -1); | 565 up.translate(0, -1); |
| 566 src->context()->concatCTM(up); | 566 src->context()->concatCTM(up); |
| 567 | 567 |
| 568 // Now draw 50% red square. | 568 // Now draw 50% red square. |
| 569 { | 569 { |
| 570 // Create a transparency helper inset one pixel in the buffer. The | 570 // Create a transparency helper inset one pixel in the buffer. The |
| 571 // coordinates are before transforming into this space, and maps to | 571 // coordinates are before transforming into this space, and maps to |
| 572 // IntRect(1, 1, 14, 14). | 572 // IntRect(1, 1, 14, 14). |
| 573 TransparencyWin helper; | 573 TransparencyWin helper; |
| 574 helper.init(src->context(), | 574 helper.init(src->context(), |
| 575 TransparencyWin::OpaqueCompositeLayer, | 575 TransparencyWin::OpaqueCompositeLayer, |
| 576 TransparencyWin::KeepTransform, | 576 TransparencyWin::KeepTransform, |
| 577 IntRect(1, -15, 14, 14)); | 577 IntRect(1, -15, 14, 14)); |
| 578 | 578 |
| 579 // Fill with red. | 579 // Fill with red. |
| 580 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000), ColorSp
aceDeviceRGB); | 580 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000)); |
| 581 clearTopLayerAlphaChannel(helper.context()); | 581 clearTopLayerAlphaChannel(helper.context()); |
| 582 helper.composite(); | 582 helper.composite(); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 | 585 |
| 586 // Tests scale mode with no additional copy. | 586 // Tests scale mode with no additional copy. |
| 587 TEST(TransparencyWin, Scale) | 587 TEST(TransparencyWin, Scale) |
| 588 { | 588 { |
| 589 // Create an opaque white buffer. | 589 // Create an opaque white buffer. |
| 590 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 590 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 591 FloatRect fullBuffer(0, 0, 16, 16); | 591 FloatRect fullBuffer(0, 0, 16, 16); |
| 592 src->context()->fillRect(fullBuffer, Color::white, ColorSpaceDeviceRGB); | 592 src->context()->fillRect(fullBuffer, Color::white); |
| 593 | 593 |
| 594 // Scale by 2x. | 594 // Scale by 2x. |
| 595 src->context()->save(); | 595 src->context()->save(); |
| 596 AffineTransform scale; | 596 AffineTransform scale; |
| 597 scale.scale(2.0); | 597 scale.scale(2.0); |
| 598 src->context()->concatCTM(scale); | 598 src->context()->concatCTM(scale); |
| 599 | 599 |
| 600 // Start drawing a rectangle from 1->4. This should get scaled to 2->8. | 600 // Start drawing a rectangle from 1->4. This should get scaled to 2->8. |
| 601 { | 601 { |
| 602 TransparencyWin helper; | 602 TransparencyWin helper; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 633 // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); | 633 // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); |
| 634 } | 634 } |
| 635 | 635 |
| 636 // Tests scale mode with an additional copy for transparency. This will happen | 636 // Tests scale mode with an additional copy for transparency. This will happen |
| 637 // if we have a scaled textbox, for example. WebKit will create a new | 637 // if we have a scaled textbox, for example. WebKit will create a new |
| 638 // transparency layer, draw the text field, then draw the text into it, then | 638 // transparency layer, draw the text field, then draw the text into it, then |
| 639 // composite this down with an opacity. | 639 // composite this down with an opacity. |
| 640 TEST(TransparencyWin, ScaleTransparency) | 640 TEST(TransparencyWin, ScaleTransparency) |
| 641 { | 641 { |
| 642 // Create an opaque white buffer. | 642 // Create an opaque white buffer. |
| 643 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 643 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 644 FloatRect fullBuffer(0, 0, 16, 16); | 644 FloatRect fullBuffer(0, 0, 16, 16); |
| 645 src->context()->fillRect(fullBuffer, Color::white, ColorSpaceDeviceRGB); | 645 src->context()->fillRect(fullBuffer, Color::white); |
| 646 | 646 |
| 647 // Make another layer (which duplicates how WebKit will make this). We fill | 647 // Make another layer (which duplicates how WebKit will make this). We fill |
| 648 // the top half with red, and have the layer be 50% opaque. | 648 // the top half with red, and have the layer be 50% opaque. |
| 649 src->context()->beginTransparencyLayer(0.5); | 649 src->context()->beginTransparencyLayer(0.5); |
| 650 FloatRect topHalf(0, 0, 16, 8); | 650 FloatRect topHalf(0, 0, 16, 8); |
| 651 src->context()->fillRect(topHalf, Color(0xFFFF0000), ColorSpaceDeviceRGB); | 651 src->context()->fillRect(topHalf, Color(0xFFFF0000)); |
| 652 | 652 |
| 653 // Scale by 2x. | 653 // Scale by 2x. |
| 654 src->context()->save(); | 654 src->context()->save(); |
| 655 AffineTransform scale; | 655 AffineTransform scale; |
| 656 scale.scale(2.0); | 656 scale.scale(2.0); |
| 657 src->context()->concatCTM(scale); | 657 src->context()->concatCTM(scale); |
| 658 | 658 |
| 659 // Make a layer inset two pixels (because of scaling, this is 2->14). And | 659 // Make a layer inset two pixels (because of scaling, this is 2->14). And |
| 660 // will it with 50% black. | 660 // will it with 50% black. |
| 661 { | 661 { |
| 662 TransparencyWin helper; | 662 TransparencyWin helper; |
| 663 helper.init(src->context(), | 663 helper.init(src->context(), |
| 664 TransparencyWin::OpaqueCompositeLayer, | 664 TransparencyWin::OpaqueCompositeLayer, |
| 665 TransparencyWin::ScaleTransform, | 665 TransparencyWin::ScaleTransform, |
| 666 IntRect(1, 1, 6, 6)); | 666 IntRect(1, 1, 6, 6)); |
| 667 | 667 |
| 668 helper.context()->fillRect(helper.drawRect(), Color(0x7f000000), ColorSp
aceDeviceRGB); | 668 helper.context()->fillRect(helper.drawRect(), Color(0x7f000000)); |
| 669 clearTopLayerAlphaChannel(helper.context()); | 669 clearTopLayerAlphaChannel(helper.context()); |
| 670 helper.composite(); | 670 helper.composite(); |
| 671 } | 671 } |
| 672 | 672 |
| 673 // Finish the layer. | 673 // Finish the layer. |
| 674 src->context()->restore(); | 674 src->context()->restore(); |
| 675 src->context()->endTransparencyLayer(); | 675 src->context()->endTransparencyLayer(); |
| 676 | 676 |
| 677 Color redBackground(0xFFFF8080); // 50% red composited on white. | 677 Color redBackground(0xFFFF8080); // 50% red composited on white. |
| 678 EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); | 678 EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 691 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); | 691 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); |
| 692 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); | 692 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); |
| 693 | 693 |
| 694 Color white(0xFFFFFFFF); // Background in the lower-right. | 694 Color white(0xFFFFFFFF); // Background in the lower-right. |
| 695 EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); | 695 EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); |
| 696 EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); | 696 EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); |
| 697 } | 697 } |
| 698 | 698 |
| 699 TEST(TransparencyWin, Text) | 699 TEST(TransparencyWin, Text) |
| 700 { | 700 { |
| 701 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1, ColorSpaceDe
viceRGB)); | 701 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); |
| 702 | 702 |
| 703 // Our text should end up 50% transparent blue-green. | 703 // Our text should end up 50% transparent blue-green. |
| 704 Color fullResult(0x80008080); | 704 Color fullResult(0x80008080); |
| 705 | 705 |
| 706 { | 706 { |
| 707 TransparencyWin helper; | 707 TransparencyWin helper; |
| 708 helper.init(src->context(), | 708 helper.init(src->context(), |
| 709 TransparencyWin::TextComposite, | 709 TransparencyWin::TextComposite, |
| 710 TransparencyWin::KeepTransform, | 710 TransparencyWin::KeepTransform, |
| 711 IntRect(0, 0, 16, 16)); | 711 IntRect(0, 0, 16, 16)); |
| 712 helper.setTextCompositeColor(fullResult); | 712 helper.setTextCompositeColor(fullResult); |
| 713 | 713 |
| 714 // Write several different squares to simulate ClearType. These should | 714 // Write several different squares to simulate ClearType. These should |
| 715 // all reduce to 2/3 coverage. | 715 // all reduce to 2/3 coverage. |
| 716 FloatRect pixel(0, 0, 1, 1); | 716 FloatRect pixel(0, 0, 1, 1); |
| 717 helper.context()->fillRect(pixel, 0xFFFF0000, ColorSpaceDeviceRGB); | 717 helper.context()->fillRect(pixel, 0xFFFF0000); |
| 718 pixel.move(1.0f, 0.0f); | 718 pixel.move(1.0f, 0.0f); |
| 719 helper.context()->fillRect(pixel, 0xFF00FF00, ColorSpaceDeviceRGB); | 719 helper.context()->fillRect(pixel, 0xFF00FF00); |
| 720 pixel.move(1.0f, 0.0f); | 720 pixel.move(1.0f, 0.0f); |
| 721 helper.context()->fillRect(pixel, 0xFF0000FF, ColorSpaceDeviceRGB); | 721 helper.context()->fillRect(pixel, 0xFF0000FF); |
| 722 pixel.move(1.0f, 0.0f); | 722 pixel.move(1.0f, 0.0f); |
| 723 helper.context()->fillRect(pixel, 0xFF008080, ColorSpaceDeviceRGB); | 723 helper.context()->fillRect(pixel, 0xFF008080); |
| 724 pixel.move(1.0f, 0.0f); | 724 pixel.move(1.0f, 0.0f); |
| 725 helper.context()->fillRect(pixel, 0xFF800080, ColorSpaceDeviceRGB); | 725 helper.context()->fillRect(pixel, 0xFF800080); |
| 726 pixel.move(1.0f, 0.0f); | 726 pixel.move(1.0f, 0.0f); |
| 727 helper.context()->fillRect(pixel, 0xFF808000, ColorSpaceDeviceRGB); | 727 helper.context()->fillRect(pixel, 0xFF808000); |
| 728 | 728 |
| 729 // Try one with 100% coverage (opaque black). | 729 // Try one with 100% coverage (opaque black). |
| 730 pixel.move(1.0f, 0.0f); | 730 pixel.move(1.0f, 0.0f); |
| 731 helper.context()->fillRect(pixel, 0xFF000000, ColorSpaceDeviceRGB); | 731 helper.context()->fillRect(pixel, 0xFF000000); |
| 732 | 732 |
| 733 // Now mess with the alpha channel. | 733 // Now mess with the alpha channel. |
| 734 clearTopLayerAlphaChannel(helper.context()); | 734 clearTopLayerAlphaChannel(helper.context()); |
| 735 helper.composite(); | 735 helper.composite(); |
| 736 } | 736 } |
| 737 | 737 |
| 738 Color oneThirdResult(0x55005555); // = fullResult * 2 / 3 | 738 Color oneThirdResult(0x55005555); // = fullResult * 2 / 3 |
| 739 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 0, 0)); | 739 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 0, 0)); |
| 740 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); | 740 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); |
| 741 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); | 741 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); |
| 742 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); | 742 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); |
| 743 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); | 743 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); |
| 744 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); | 744 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); |
| 745 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); | 745 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); |
| 746 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); | 746 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); |
| 747 } | 747 } |
| 748 | 748 |
| 749 } // namespace WebCore | 749 } // namespace WebCore |
| OLD | NEW |