| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> | 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> |
| 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // Compensate for the container size rounding by adjusting the source rect. | 211 // Compensate for the container size rounding by adjusting the source rect. |
| 212 FloatSize adjustedSrcSize = scaledSrc.size(); | 212 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | 213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); |
| 214 scaledSrc.setSize(adjustedSrcSize); | 214 scaledSrc.setSize(adjustedSrcSize); |
| 215 | 215 |
| 216 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); | 216 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); |
| 217 } | 217 } |
| 218 | 218 |
| 219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() | 219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() |
| 220 { | 220 { |
| 221 if (!m_page) | 221 return imageForCurrentFrameForContainer(KURL()); |
| 222 return nullptr; | |
| 223 | |
| 224 SkPictureRecorder recorder; | |
| 225 SkCanvas* canvas = recorder.beginRecording(width(), height()); | |
| 226 drawForContainer(canvas, SkPaint(), FloatSize(size()), 1, rect(), rect(), KU
RL()); | |
| 227 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | |
| 228 | |
| 229 return adoptRef( | |
| 230 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()),
nullptr, nullptr)); | |
| 231 } | 222 } |
| 232 | 223 |
| 233 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, | 224 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, |
| 234 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, | 225 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, |
| 235 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 226 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
| 236 const FloatSize& repeatSpacing, const KURL& url) | 227 const FloatSize& repeatSpacing, const KURL& url) |
| 237 { | 228 { |
| 238 // Tile adjusted for scaling/stretch. | 229 // Tile adjusted for scaling/stretch. |
| 239 FloatRect tile(srcRect); | 230 FloatRect tile(srcRect); |
| 240 tile.scale(tileScale.width(), tileScale.height()); | 231 tile.scale(tileScale.width(), tileScale.height()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 260 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, | 251 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, |
| 261 &patternTransform, nullptr)); | 252 &patternTransform, nullptr)); |
| 262 | 253 |
| 263 SkPaint paint; | 254 SkPaint paint; |
| 264 paint.setShader(patternShader.get()); | 255 paint.setShader(patternShader.get()); |
| 265 paint.setXfermodeMode(compositeOp); | 256 paint.setXfermodeMode(compositeOp); |
| 266 paint.setColorFilter(context->colorFilter()); | 257 paint.setColorFilter(context->colorFilter()); |
| 267 context->drawRect(dstRect, paint); | 258 context->drawRect(dstRect, paint); |
| 268 } | 259 } |
| 269 | 260 |
| 261 PassRefPtr<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url) |
| 262 { |
| 263 if (!m_page) |
| 264 return nullptr; |
| 265 |
| 266 SkPictureRecorder recorder; |
| 267 SkCanvas* canvas = recorder.beginRecording(width(), height()); |
| 268 drawForContainer(canvas, SkPaint(), FloatSize(size()), 1, rect(), rect(), ur
l); |
| 269 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); |
| 270 |
| 271 return adoptRef( |
| 272 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()),
nullptr, nullptr)); |
| 273 } |
| 274 |
| 270 static bool drawNeedsLayer(const SkPaint& paint) | 275 static bool drawNeedsLayer(const SkPaint& paint) |
| 271 { | 276 { |
| 272 if (SkColorGetA(paint.getColor()) < 255) | 277 if (SkColorGetA(paint.getColor()) < 255) |
| 273 return true; | 278 return true; |
| 274 | 279 |
| 275 SkXfermode::Mode xfermode; | 280 SkXfermode::Mode xfermode; |
| 276 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | 281 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { |
| 277 if (xfermode != SkXfermode::kSrcOver_Mode) | 282 if (xfermode != SkXfermode::kSrcOver_Mode) |
| 278 return true; | 283 return true; |
| 279 } | 284 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 512 |
| 508 return m_page; | 513 return m_page; |
| 509 } | 514 } |
| 510 | 515 |
| 511 String SVGImage::filenameExtension() const | 516 String SVGImage::filenameExtension() const |
| 512 { | 517 { |
| 513 return "svg"; | 518 return "svg"; |
| 514 } | 519 } |
| 515 | 520 |
| 516 } | 521 } |
| OLD | NEW |