| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #include "platform/graphics/GraphicsContext.h" | 27 #include "platform/graphics/GraphicsContext.h" |
| 28 | 28 |
| 29 #include "platform/RuntimeEnabledFeatures.h" |
| 29 #include "platform/graphics/BitmapImage.h" | 30 #include "platform/graphics/BitmapImage.h" |
| 30 #include "platform/graphics/ImageBuffer.h" | 31 #include "platform/graphics/ImageBuffer.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 #include "third_party/skia/include/core/SkCanvas.h" | 33 #include "third_party/skia/include/core/SkCanvas.h" |
| 33 #include "third_party/skia/include/core/SkPicture.h" | 34 #include "third_party/skia/include/core/SkPicture.h" |
| 34 #include "third_party/skia/include/core/SkShader.h" | 35 #include "third_party/skia/include/core/SkShader.h" |
| 35 #include "third_party/skia/include/effects/SkBlurDrawLooper.h" | 36 #include "third_party/skia/include/effects/SkBlurDrawLooper.h" |
| 36 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 37 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 37 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 38 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 38 | 39 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 context->drawPath(path.skPath(), paint); | 203 context->drawPath(path.skPath(), paint); |
| 203 | 204 |
| 204 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 205 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 #define DISPATCH1(c1, c2, op, param1) do { c1->op(param1); c2->op(param1); } whi
le (0); | 208 #define DISPATCH1(c1, c2, op, param1) do { c1->op(param1); c2->op(param1); } whi
le (0); |
| 208 #define DISPATCH2(c1, c2, op, param1, param2) do { c1->op(param1, param2); c2->o
p(param1, param2); } while (0); | 209 #define DISPATCH2(c1, c2, op, param1, param2) do { c1->op(param1, param2); c2->o
p(param1, param2); } while (0); |
| 209 | 210 |
| 210 TEST(GraphicsContextTest, RecordingTotalMatrix) | 211 TEST(GraphicsContextTest, RecordingTotalMatrix) |
| 211 { | 212 { |
| 213 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 214 // GraphicsContext::getCTM() won't do the right thing in Slimming Paint,
so just skip this test. |
| 215 return; |
| 216 } |
| 217 |
| 212 SkBitmap bitmap; | 218 SkBitmap bitmap; |
| 213 bitmap.allocN32Pixels(400, 400); | 219 bitmap.allocN32Pixels(400, 400); |
| 214 bitmap.eraseColor(0); | 220 bitmap.eraseColor(0); |
| 215 SkCanvas canvas(bitmap); | 221 SkCanvas canvas(bitmap); |
| 216 OwnPtr<GraphicsContext> context = GraphicsContext::deprecatedCreateWithCanva
s(&canvas); | 222 OwnPtr<GraphicsContext> context = GraphicsContext::deprecatedCreateWithCanva
s(&canvas); |
| 217 | 223 |
| 218 SkCanvas controlCanvas(400, 400); | 224 SkCanvas controlCanvas(400, 400); |
| 219 OwnPtr<GraphicsContext> controlContext = GraphicsContext::deprecatedCreateWi
thCanvas(&controlCanvas); | 225 OwnPtr<GraphicsContext> controlContext = GraphicsContext::deprecatedCreateWi
thCanvas(&controlCanvas); |
| 220 | 226 |
| 221 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); | 227 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 context->endRecording(); | 242 context->endRecording(); |
| 237 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); | 243 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); |
| 238 | 244 |
| 239 controlContext->restore(); | 245 controlContext->restore(); |
| 240 context->endRecording(); | 246 context->endRecording(); |
| 241 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); | 247 EXPECT_EQ(context->getCTM(), controlContext->getCTM()); |
| 242 } | 248 } |
| 243 | 249 |
| 244 TEST(GraphicsContextTest, RecordingCanvas) | 250 TEST(GraphicsContextTest, RecordingCanvas) |
| 245 { | 251 { |
| 252 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 253 // This test doesn't make any sense in slimming paint as you can't begin
recording within an existing recording, |
| 254 // so just bail out. |
| 255 return; |
| 256 } |
| 257 |
| 246 SkBitmap bitmap; | 258 SkBitmap bitmap; |
| 247 bitmap.allocN32Pixels(1, 1); | 259 bitmap.allocN32Pixels(1, 1); |
| 248 bitmap.eraseColor(0); | 260 bitmap.eraseColor(0); |
| 249 SkCanvas canvas(bitmap); | 261 SkCanvas canvas(bitmap); |
| 250 OwnPtr<GraphicsContext> context = GraphicsContext::deprecatedCreateWithCanva
s(&canvas); | 262 OwnPtr<GraphicsContext> context = GraphicsContext::deprecatedCreateWithCanva
s(&canvas); |
| 251 | 263 |
| 252 FloatRect rect(0, 0, 1, 1); | 264 FloatRect rect(0, 0, 1, 1); |
| 253 | 265 |
| 254 // Two beginRecordings in a row generate two canvases. | 266 // Two beginRecordings in a row generate two canvases. |
| 255 // Unfortunately the new one could be allocated in the same | 267 // Unfortunately the new one could be allocated in the same |
| 256 // spot as the old one so ref the first one to prolong its life. | 268 // spot as the old one so ref the first one to prolong its life. |
| 257 context->beginRecording(rect); | 269 context->beginRecording(rect); |
| 258 SkCanvas* canvas1 = context->canvas(); | 270 SkCanvas* canvas1 = context->canvas(); |
| 259 EXPECT_TRUE(canvas1); | 271 EXPECT_TRUE(canvas1); |
| 260 context->beginRecording(rect); | 272 context->beginRecording(rect); |
| 261 SkCanvas* canvas2 = context->canvas(); | 273 SkCanvas* canvas2 = context->canvas(); |
| 262 EXPECT_TRUE(canvas2); | 274 EXPECT_TRUE(canvas2); |
| 263 | 275 |
| 264 EXPECT_NE(canvas1, canvas2); | 276 EXPECT_NE(canvas1, canvas2); |
| 265 EXPECT_TRUE(canvas1->unique()); | 277 EXPECT_TRUE(canvas1->unique()); |
| 266 | 278 |
| 267 // endRecording finally makes the picture accessible | 279 // endRecording finally makes the picture accessible |
| 268 RefPtr<const SkPicture> picture = context->endRecording(); | 280 RefPtr<const SkPicture> picture = context->endRecording(); |
| 269 EXPECT_TRUE(picture); | 281 EXPECT_TRUE(picture); |
| 270 | 282 |
| 271 context->endRecording(); | 283 context->endRecording(); |
| 272 } | 284 } |
| 273 | 285 |
| 274 } // namespace | 286 } // namespace |
| OLD | NEW |