Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #include "core/platform/graphics/GraphicsContext.h" | 27 #include "core/platform/graphics/GraphicsContext.h" |
| 28 | 28 |
| 29 #include "SkCanvas.h" | 29 #include "SkCanvas.h" |
| 30 #include "core/platform/graphics/BitmapImage.h" | 30 #include "core/platform/graphics/BitmapImage.h" |
| 31 #include "core/platform/graphics/ImageBuffer.h" | 31 #include "core/platform/graphics/ImageBuffer.h" |
| 32 #include "core/platform/graphics/skia/NativeImageSkia.h" | 32 #include "core/platform/graphics/skia/NativeImageSkia.h" |
| 33 #include "platform/graphics/DisplayList.h" | 33 #include "platform/graphics/DisplayList.h" |
| 34 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | |
| 34 #include "third_party/skia/include/core/SkBitmapDevice.h" | 35 #include "third_party/skia/include/core/SkBitmapDevice.h" |
| 35 #include <gtest/gtest.h> | 36 #include <gtest/gtest.h> |
| 36 | 37 |
| 37 using namespace WebCore; | 38 using namespace WebCore; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 #define EXPECT_EQ_RECT(a, b) \ | 42 #define EXPECT_EQ_RECT(a, b) \ |
| 42 EXPECT_EQ(a.x(), b.x()); \ | 43 EXPECT_EQ(a.x(), b.x()); \ |
| 43 EXPECT_EQ(a.y(), b.y()); \ | 44 EXPECT_EQ(a.y(), b.y()); \ |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 // out a transparency layer below that is filled with the mask color. In the end this should | 238 // out a transparency layer below that is filled with the mask color. In the end this should |
| 238 // not be marked opaque. | 239 // not be marked opaque. |
| 239 | 240 |
| 240 context.setCompositeOperation(CompositeSourceOver); | 241 context.setCompositeOperation(CompositeSourceOver); |
| 241 context.beginTransparencyLayer(1); | 242 context.beginTransparencyLayer(1); |
| 242 context.fillRect(FloatRect(10, 10, 10, 10), opaque, CompositeSourceOver); | 243 context.fillRect(FloatRect(10, 10, 10, 10), opaque, CompositeSourceOver); |
| 243 | 244 |
| 244 context.setCompositeOperation(CompositeDestinationIn); | 245 context.setCompositeOperation(CompositeDestinationIn); |
| 245 context.beginTransparencyLayer(1); | 246 context.beginTransparencyLayer(1); |
| 246 | 247 |
| 247 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100)); | 248 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(IntSize(100, 100))); |
| 248 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha); | 249 ImageBuffer alphaImage(surface.release()); |
|
Stephen White
2013/12/04 21:18:40
Ooooh, ImageBuffer on the stack. *mindblown*
| |
| 250 alphaImage.context()->fillRect(IntRect(0, 0, 100, 100), alpha); | |
| 249 | 251 |
| 250 context.setCompositeOperation(CompositeSourceOver); | 252 context.setCompositeOperation(CompositeSourceOver); |
| 251 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10)); | 253 context.drawImageBuffer(&alphaImage, FloatRect(10, 10, 10, 10)); |
| 252 | 254 |
| 253 context.endLayer(); | 255 context.endLayer(); |
| 254 context.endLayer(); | 256 context.endLayer(); |
| 255 | 257 |
| 256 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); | 258 EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); |
| 257 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); | 259 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); |
| 258 } | 260 } |
| 259 | 261 |
| 260 TEST(GraphicsContextTest, trackImageMaskWithOpaqueRect) | 262 TEST(GraphicsContextTest, trackImageMaskWithOpaqueRect) |
| 261 { | 263 { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 275 // out a transparency layer below that is filled with the mask color. In the end this should | 277 // out a transparency layer below that is filled with the mask color. In the end this should |
| 276 // not be marked opaque. | 278 // not be marked opaque. |
| 277 | 279 |
| 278 context.setCompositeOperation(CompositeSourceOver); | 280 context.setCompositeOperation(CompositeSourceOver); |
| 279 context.beginTransparencyLayer(1); | 281 context.beginTransparencyLayer(1); |
| 280 context.fillRect(FloatRect(10, 10, 10, 10), opaque, CompositeSourceOver); | 282 context.fillRect(FloatRect(10, 10, 10, 10), opaque, CompositeSourceOver); |
| 281 | 283 |
| 282 context.setCompositeOperation(CompositeDestinationIn); | 284 context.setCompositeOperation(CompositeDestinationIn); |
| 283 context.beginTransparencyLayer(1); | 285 context.beginTransparencyLayer(1); |
| 284 | 286 |
| 285 OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100)); | 287 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(IntSize(100, 100))); |
| 286 alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha); | 288 ImageBuffer alphaImage(surface.release()); |
| 289 alphaImage.context()->fillRect(IntRect(0, 0, 100, 100), alpha); | |
| 287 | 290 |
| 288 context.setCompositeOperation(CompositeSourceOver); | 291 context.setCompositeOperation(CompositeSourceOver); |
| 289 context.drawImageBuffer(alphaImage.get(), FloatRect(10, 10, 10, 10)); | 292 context.drawImageBuffer(&alphaImage, FloatRect(10, 10, 10, 10)); |
| 290 | 293 |
| 291 // We can't have an opaque mask actually, but we can pretend here like it wo uld look if we did. | 294 // We can't have an opaque mask actually, but we can pretend here like it wo uld look if we did. |
| 292 context.fillRect(FloatRect(12, 12, 3, 3), opaque, CompositeSourceOver); | 295 context.fillRect(FloatRect(12, 12, 3, 3), opaque, CompositeSourceOver); |
| 293 | 296 |
| 294 context.endLayer(); | 297 context.endLayer(); |
| 295 context.endLayer(); | 298 context.endLayer(); |
| 296 | 299 |
| 297 EXPECT_EQ_RECT(IntRect(12, 12, 3, 3), context.opaqueRegion().asRect()); | 300 EXPECT_EQ_RECT(IntRect(12, 12, 3, 3), context.opaqueRegion().asRect()); |
| 298 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); | 301 EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); |
| 299 } | 302 } |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 controlContext.restore(); | 1117 controlContext.restore(); |
| 1115 context.endRecording(); | 1118 context.endRecording(); |
| 1116 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1119 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1117 | 1120 |
| 1118 controlContext.restore(); | 1121 controlContext.restore(); |
| 1119 context.endRecording(); | 1122 context.endRecording(); |
| 1120 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1123 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1121 } | 1124 } |
| 1122 | 1125 |
| 1123 } // namespace | 1126 } // namespace |
| OLD | NEW |