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

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

Powered by Google App Engine
This is Rietveld 408576698