Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1570)

Side by Side Diff: Source/web/tests/TransparencyWinTest.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: mac+win build fix Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/platform/graphics/win/TransparencyWin.h" 32 #include "core/platform/graphics/win/TransparencyWin.h"
33 #include "platform/graphics/GraphicsContext.h" 33 #include "platform/graphics/GraphicsContext.h"
34 #include "platform/graphics/ImageBuffer.h" 34 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/transforms/AffineTransform.h" 35 #include "platform/transforms/AffineTransform.h"
36 #include "skia/ext/platform_canvas.h"
37 36
38 #include <windows.h> 37 #include <windows.h>
39 #include <gtest/gtest.h> 38 #include <gtest/gtest.h>
40 39
41 namespace WebCore { 40 namespace WebCore {
42 41
43 static FloatRect RECTToFloatRect(const RECT* rect) 42 static FloatRect RECTToFloatRect(const RECT* rect)
44 { 43 {
45 return FloatRect(static_cast<float>(rect->left), 44 return FloatRect(static_cast<float>(rect->left),
46 static_cast<float>(rect->top), 45 static_cast<float>(rect->top),
47 static_cast<float>(rect->right - rect->left), 46 static_cast<float>(rect->right - rect->left),
48 static_cast<float>(rect->bottom - rect->top)); 47 static_cast<float>(rect->bottom - rect->top));
49 } 48 }
50 49
51 static void drawNativeRect(GraphicsContext* context,
52 int x, int y, int w, int h)
53 {
54 SkCanvas* canvas = context->canvas();
55 HDC dc = skia::BeginPlatformPaint(canvas);
56
57 RECT innerRc;
58 innerRc.left = x;
59 innerRc.top = y;
60 innerRc.right = x + w;
61 innerRc.bottom = y + h;
62 FillRect(dc, &innerRc,
63 reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));
64
65 skia::EndPlatformPaint(canvas);
66 }
67
68 static Color getPixelAt(GraphicsContext* context, int x, int y) 50 static Color getPixelAt(GraphicsContext* context, int x, int y)
69 { 51 {
70 const SkBitmap& bitmap = context->layerBitmap(); 52 const SkBitmap& bitmap = context->layerBitmap();
71 return Color(*reinterpret_cast<const RGBA32*>(bitmap.getAddr32(x, y))); 53 return Color(*reinterpret_cast<const RGBA32*>(bitmap.getAddr32(x, y)));
72 } 54 }
73 55
74 // Resets the top layer's alpha channel to 0 for each pixel. This simulates 56 // Resets the top layer's alpha channel to 0 for each pixel. This simulates
75 // Windows messing it up. 57 // Windows messing it up.
76 static void clearTopLayerAlphaChannel(GraphicsContext* context) 58 static void clearTopLayerAlphaChannel(GraphicsContext* context)
77 { 59 {
(...skipping 16 matching lines...) Expand all
94 { 76 {
95 std::ios_base::fmtflags oldFlags = out.flags(std::ios_base::hex | 77 std::ios_base::fmtflags oldFlags = out.flags(std::ios_base::hex |
96 std::ios_base::showbase); 78 std::ios_base::showbase);
97 out << c.rgb(); 79 out << c.rgb();
98 out.flags(oldFlags); 80 out.flags(oldFlags);
99 return out; 81 return out;
100 } 82 }
101 83
102 TEST(TransparencyWin, NoLayer) 84 TEST(TransparencyWin, NoLayer)
103 { 85 {
104 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(17, 16), 1)); 86 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(17, 16)));
105 87
106 // KeepTransform 88 // KeepTransform
107 { 89 {
108 TransparencyWin helper; 90 TransparencyWin helper;
109 helper.init(src->context(), 91 helper.init(src->context(),
110 TransparencyWin::NoLayer, 92 TransparencyWin::NoLayer,
111 TransparencyWin::KeepTransform, 93 TransparencyWin::KeepTransform,
112 IntRect(1, 1, 14, 12)); 94 IntRect(1, 1, 14, 12));
113 95
114 EXPECT_TRUE(src->context() == helper.context()); 96 EXPECT_TRUE(src->context() == helper.context());
(...skipping 18 matching lines...) Expand all
133 // It should be post-transformed. 115 // It should be post-transformed.
134 EXPECT_TRUE(src->context() == helper.context()); 116 EXPECT_TRUE(src->context() == helper.context());
135 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); 117 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize);
136 EXPECT_TRUE(IntRect(4, 1, 12, 3) == helper.drawRect()); 118 EXPECT_TRUE(IntRect(4, 1, 12, 3) == helper.drawRect());
137 } 119 }
138 src->context()->restore(); 120 src->context()->restore();
139 } 121 }
140 122
141 TEST(TransparencyWin, WhiteLayer) 123 TEST(TransparencyWin, WhiteLayer)
142 { 124 {
143 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 125 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
144 126
145 // KeepTransform 127 // KeepTransform
146 { 128 {
147 TransparencyWin helper; 129 TransparencyWin helper;
148 helper.init(src->context(), 130 helper.init(src->context(),
149 TransparencyWin::WhiteLayer, 131 TransparencyWin::WhiteLayer,
150 TransparencyWin::KeepTransform, 132 TransparencyWin::KeepTransform,
151 IntRect(1, 1, 14, 12)); 133 IntRect(1, 1, 14, 12));
152 helper.composite(); 134 helper.composite();
153 135
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // It should be post-transformed. 167 // It should be post-transformed.
186 EXPECT_TRUE(src->context() != helper.context()); 168 EXPECT_TRUE(src->context() != helper.context());
187 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); 169 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize);
188 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); 170 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect());
189 } 171 }
190 src->context()->restore(); 172 src->context()->restore();
191 } 173 }
192 174
193 TEST(TransparencyWin, TextComposite) 175 TEST(TransparencyWin, TextComposite)
194 { 176 {
195 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 177 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
196 178
197 // KeepTransform is the only valid transform mode for TextComposite. 179 // KeepTransform is the only valid transform mode for TextComposite.
198 { 180 {
199 TransparencyWin helper; 181 TransparencyWin helper;
200 helper.init(src->context(), 182 helper.init(src->context(),
201 TransparencyWin::TextComposite, 183 TransparencyWin::TextComposite,
202 TransparencyWin::KeepTransform, 184 TransparencyWin::KeepTransform,
203 IntRect(1, 1, 14, 12)); 185 IntRect(1, 1, 14, 12));
204 helper.composite(); 186 helper.composite();
205 187
206 EXPECT_TRUE(src->context() != helper.context()); 188 EXPECT_TRUE(src->context() != helper.context());
207 EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); 189 EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize);
208 EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); 190 EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect());
209 } 191 }
210 } 192 }
211 193
212 TEST(TransparencyWin, OpaqueCompositeLayer) 194 TEST(TransparencyWin, OpaqueCompositeLayer)
213 { 195 {
214 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 196 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
215 197
216 // KeepTransform 198 // KeepTransform
217 { 199 {
218 TransparencyWin helper; 200 TransparencyWin helper;
219 helper.init(src->context(), 201 helper.init(src->context(),
220 TransparencyWin::OpaqueCompositeLayer, 202 TransparencyWin::OpaqueCompositeLayer,
221 TransparencyWin::KeepTransform, 203 TransparencyWin::KeepTransform,
222 IntRect(1, 1, 14, 12)); 204 IntRect(1, 1, 14, 12));
223 helper.composite(); 205 helper.composite();
224 206
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 253
272 // The coordinate system should be based in the upper left of our box. 254 // The coordinate system should be based in the upper left of our box.
273 // It should be post-transformed. 255 // It should be post-transformed.
274 EXPECT_TRUE(src->context() != helper.context()); 256 EXPECT_TRUE(src->context() != helper.context());
275 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); 257 EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize);
276 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); 258 EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect());
277 } 259 }
278 src->context()->restore(); 260 src->context()->restore();
279 } 261 }
280 262
281 TEST(TransparencyWin, WhiteLayerPixelTest)
282 {
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));
285
286 {
287 TransparencyWin helper;
288 helper.init(src->context(),
289 TransparencyWin::WhiteLayer,
290 TransparencyWin::KeepTransform,
291 IntRect(1, 1, 14, 14));
292
293 // Coordinates should be in the original space, not the layer.
294 drawNativeRect(helper.context(), 3, 3, 1, 1);
295 clearTopLayerAlphaChannel(helper.context());
296 helper.composite();
297 }
298
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.
301 EXPECT_EQ(Color(Color::transparent), getPixelAt(src->context(), 0, 0));
302 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2));
303 EXPECT_EQ(Color(Color::black), getPixelAt(src->context(), 3, 3));
304 EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 4, 4));
305 }
306
307 TEST(TransparencyWin, OpaqueCompositeLayerPixel) 263 TEST(TransparencyWin, OpaqueCompositeLayerPixel)
308 { 264 {
309 Color red(0xFFFF0000), darkRed(0xFFBF0000); 265 Color red(0xFFFF0000), darkRed(0xFFBF0000);
310 Color green(0xFF00FF00); 266 Color green(0xFF00FF00);
311 267
312 // Make a red bottom layer, followed by a half green next layer @ 50%. 268 // Make a red bottom layer, followed by a half green next layer @ 50%.
313 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 269 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
314 270
315 FloatRect fullRect(0, 0, 16, 16); 271 FloatRect fullRect(0, 0, 16, 16);
316 src->context()->fillRect(fullRect, red); 272 src->context()->fillRect(fullRect, red);
317 src->context()->beginTransparencyLayer(0.5); 273 src->context()->beginTransparencyLayer(0.5);
318 FloatRect rightHalf(8, 0, 8, 16); 274 FloatRect rightHalf(8, 0, 8, 16);
319 src->context()->fillRect(rightHalf, green); 275 src->context()->fillRect(rightHalf, green);
320 276
321 // Make a transparency layer inset by one pixel, and fill it inset by 277 // Make a transparency layer inset by one pixel, and fill it inset by
322 // another pixel with 50% black. 278 // another pixel with 50% black.
323 { 279 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // 50% green on top of red = FF808000 (rounded to what Skia will produce). 312 // 50% green on top of red = FF808000 (rounded to what Skia will produce).
357 Color greenRed(0xFF807F00); 313 Color greenRed(0xFF807F00);
358 EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14)); 314 EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14));
359 EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15)); 315 EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15));
360 } 316 }
361 317
362 // Tests that translations are properly handled when using KeepTransform. 318 // Tests that translations are properly handled when using KeepTransform.
363 TEST(TransparencyWin, TranslateOpaqueCompositeLayer) 319 TEST(TransparencyWin, TranslateOpaqueCompositeLayer)
364 { 320 {
365 // Fill with white. 321 // Fill with white.
366 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 322 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
367 Color white(0xFFFFFFFF); 323 Color white(0xFFFFFFFF);
368 FloatRect fullRect(0, 0, 16, 16); 324 FloatRect fullRect(0, 0, 16, 16);
369 src->context()->fillRect(fullRect, white); 325 src->context()->fillRect(fullRect, white);
370 326
371 // Scroll down by 8 (coordinate system goes up). 327 // Scroll down by 8 (coordinate system goes up).
372 src->context()->save(); 328 src->context()->save();
373 src->context()->translate(0, -8); 329 src->context()->translate(0, -8);
374 330
375 Color red(0xFFFF0000); 331 Color red(0xFFFF0000);
376 Color green(0xFF00FF00); 332 Color green(0xFF00FF00);
(...skipping 15 matching lines...) Expand all
392 348
393 src->context()->restore(); 349 src->context()->restore();
394 350
395 // Check the pixel we wrote. 351 // Check the pixel we wrote.
396 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); 352 EXPECT_EQ(green, getPixelAt(src->context(), 15, 7));
397 } 353 }
398 354
399 static void testClippedLayerKeepTransform(TransparencyWin::LayerMode layerMode) 355 static void testClippedLayerKeepTransform(TransparencyWin::LayerMode layerMode)
400 { 356 {
401 // Fill with white. 357 // Fill with white.
402 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 358 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
403 Color white(0xFFFFFFFF); 359 Color white(0xFFFFFFFF);
404 FloatRect fullRect(0, 0, 16, 16); 360 FloatRect fullRect(0, 0, 16, 16);
405 src->context()->fillRect(fullRect, white); 361 src->context()->fillRect(fullRect, white);
406 362
407 IntRect clipRect(IntPoint(11, 5), IntSize(1, 1)); 363 IntRect clipRect(IntPoint(11, 5), IntSize(1, 1));
408 src->context()->clip(clipRect); 364 src->context()->clip(clipRect);
409 365
410 // Scroll down by 6 (coordinate system goes up). 366 // Scroll down by 6 (coordinate system goes up).
411 src->context()->save(); 367 src->context()->save();
412 src->context()->translate(0, -6); 368 src->context()->translate(0, -6);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 409
454 TEST(TransparencyWin, ClippedKeepTransformWhiteLayer) 410 TEST(TransparencyWin, ClippedKeepTransformWhiteLayer)
455 { 411 {
456 testClippedLayerKeepTransform(TransparencyWin::WhiteLayer); 412 testClippedLayerKeepTransform(TransparencyWin::WhiteLayer);
457 } 413 }
458 414
459 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This 415 // Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This
460 // tests that the propert transform is applied to the copied layer. 416 // tests that the propert transform is applied to the copied layer.
461 TEST(TransparencyWin, RotateOpaqueCompositeLayer) 417 TEST(TransparencyWin, RotateOpaqueCompositeLayer)
462 { 418 {
463 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 419 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
464 420
465 // The background is white. 421 // The background is white.
466 Color white(0xFFFFFFFF); 422 Color white(0xFFFFFFFF);
467 FloatRect fullRect(0, 0, 16, 16); 423 FloatRect fullRect(0, 0, 16, 16);
468 src->context()->fillRect(fullRect, white); 424 src->context()->fillRect(fullRect, white);
469 425
470 // Rotate the image by 90 degrees. This matrix is the same as 426 // Rotate the image by 90 degrees. This matrix is the same as
471 // cw90.rotate(90); but avoids rounding errors. Rounding errors can cause 427 // cw90.rotate(90); but avoids rounding errors. Rounding errors can cause
472 // Skia to think that !rectStaysRect() and it will fall through to path 428 // Skia to think that !rectStaysRect() and it will fall through to path
473 // drawing mode, which in turn gives us antialiasing. We want no 429 // drawing mode, which in turn gives us antialiasing. We want no
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 EXPECT_EQ(redwhite, getPixelAt(src->context(), 9, 1)); 488 EXPECT_EQ(redwhite, getPixelAt(src->context(), 9, 1));
533 EXPECT_EQ(redwhite, getPixelAt(src->context(), 14, 1)); 489 EXPECT_EQ(redwhite, getPixelAt(src->context(), 14, 1));
534 EXPECT_EQ(white, getPixelAt(src->context(), 15, 1)); 490 EXPECT_EQ(white, getPixelAt(src->context(), 15, 1));
535 491
536 // Complete the 50% transparent layer. 492 // Complete the 50% transparent layer.
537 src->context()->restore(); 493 src->context()->restore();
538 } 494 }
539 495
540 TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer) 496 TEST(TransparencyWin, DISABLED_TranslateScaleOpaqueCompositeLayer)
541 { 497 {
542 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 498 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
543 499
544 // The background is white on top with red on bottom. 500 // The background is white on top with red on bottom.
545 Color white(0xFFFFFFFF); 501 Color white(0xFFFFFFFF);
546 FloatRect topRect(0, 0, 16, 8); 502 FloatRect topRect(0, 0, 16, 8);
547 src->context()->fillRect(topRect, white); 503 src->context()->fillRect(topRect, white);
548 Color red(0xFFFF0000); 504 Color red(0xFFFF0000);
549 FloatRect bottomRect(0, 8, 16, 8); 505 FloatRect bottomRect(0, 8, 16, 8);
550 src->context()->fillRect(bottomRect, red); 506 src->context()->fillRect(bottomRect, red);
551 507
552 src->context()->save(); 508 src->context()->save();
(...skipping 27 matching lines...) Expand all
580 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000)); 536 helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000));
581 clearTopLayerAlphaChannel(helper.context()); 537 clearTopLayerAlphaChannel(helper.context());
582 helper.composite(); 538 helper.composite();
583 } 539 }
584 } 540 }
585 541
586 // Tests scale mode with no additional copy. 542 // Tests scale mode with no additional copy.
587 TEST(TransparencyWin, Scale) 543 TEST(TransparencyWin, Scale)
588 { 544 {
589 // Create an opaque white buffer. 545 // Create an opaque white buffer.
590 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 546 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
591 FloatRect fullBuffer(0, 0, 16, 16); 547 FloatRect fullBuffer(0, 0, 16, 16);
592 src->context()->fillRect(fullBuffer, Color::white); 548 src->context()->fillRect(fullBuffer, Color::white);
593 549
594 // Scale by 2x. 550 // Scale by 2x.
595 src->context()->save(); 551 src->context()->save();
596 AffineTransform scale; 552 AffineTransform scale;
597 scale.scale(2.0); 553 scale.scale(2.0);
598 src->context()->concatCTM(scale); 554 src->context()->concatCTM(scale);
599 555
600 // Start drawing a rectangle from 1->4. This should get scaled to 2->8. 556 // Start drawing a rectangle from 1->4. This should get scaled to 2->8.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); 589 // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2));
634 } 590 }
635 591
636 // Tests scale mode with an additional copy for transparency. This will happen 592 // 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 593 // 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 594 // transparency layer, draw the text field, then draw the text into it, then
639 // composite this down with an opacity. 595 // composite this down with an opacity.
640 TEST(TransparencyWin, ScaleTransparency) 596 TEST(TransparencyWin, ScaleTransparency)
641 { 597 {
642 // Create an opaque white buffer. 598 // Create an opaque white buffer.
643 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 599 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
644 FloatRect fullBuffer(0, 0, 16, 16); 600 FloatRect fullBuffer(0, 0, 16, 16);
645 src->context()->fillRect(fullBuffer, Color::white); 601 src->context()->fillRect(fullBuffer, Color::white);
646 602
647 // Make another layer (which duplicates how WebKit will make this). We fill 603 // 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. 604 // the top half with red, and have the layer be 50% opaque.
649 src->context()->beginTransparencyLayer(0.5); 605 src->context()->beginTransparencyLayer(0.5);
650 FloatRect topHalf(0, 0, 16, 8); 606 FloatRect topHalf(0, 0, 16, 8);
651 src->context()->fillRect(topHalf, Color(0xFFFF0000)); 607 src->context()->fillRect(topHalf, Color(0xFFFF0000));
652 608
653 // Scale by 2x. 609 // Scale by 2x.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); 647 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8));
692 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); 648 EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13));
693 649
694 Color white(0xFFFFFFFF); // Background in the lower-right. 650 Color white(0xFFFFFFFF); // Background in the lower-right.
695 EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); 651 EXPECT_EQ(white, getPixelAt(src->context(), 14, 14));
696 EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); 652 EXPECT_EQ(white, getPixelAt(src->context(), 15, 15));
697 } 653 }
698 654
699 TEST(TransparencyWin, Text) 655 TEST(TransparencyWin, Text)
700 { 656 {
701 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); 657 OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16)));
702 658
703 // Our text should end up 50% transparent blue-green. 659 // Our text should end up 50% transparent blue-green.
704 Color fullResult(0x80008080); 660 Color fullResult(0x80008080);
705 661
706 { 662 {
707 TransparencyWin helper; 663 TransparencyWin helper;
708 helper.init(src->context(), 664 helper.init(src->context(),
709 TransparencyWin::TextComposite, 665 TransparencyWin::TextComposite,
710 TransparencyWin::KeepTransform, 666 TransparencyWin::KeepTransform,
711 IntRect(0, 0, 16, 16)); 667 IntRect(0, 0, 16, 16));
(...skipping 28 matching lines...) Expand all
740 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); 696 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0));
741 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); 697 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0));
742 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); 698 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0));
743 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); 699 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0));
744 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); 700 EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0));
745 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); 701 EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0));
746 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); 702 EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0));
747 } 703 }
748 704
749 } // namespace WebCore 705 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698