| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // Compensate for the container size rounding by adjusting the source rect. | 244 // Compensate for the container size rounding by adjusting the source rect. |
| 245 FloatSize adjustedSrcSize = scaledSrc.size(); | 245 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 246 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | 246 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); |
| 247 scaledSrc.setSize(adjustedSrcSize); | 247 scaledSrc.setSize(adjustedSrcSize); |
| 248 | 248 |
| 249 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); | 249 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); |
| 250 } | 250 } |
| 251 | 251 |
| 252 sk_sp<SkImage> SVGImage::imageForCurrentFrame() | 252 sk_sp<SkImage> SVGImage::imageForCurrentFrame() |
| 253 { | 253 { |
| 254 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); | 254 return imageForCurrentFrameForContainer(KURL(), size()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
containerSize, | 257 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
containerSize, |
| 258 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, | 258 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, |
| 259 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 259 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
| 260 const FloatSize& repeatSpacing, const KURL& url) | 260 const FloatSize& repeatSpacing, const KURL& url) |
| 261 { | 261 { |
| 262 // Tile adjusted for scaling/stretch. | 262 // Tile adjusted for scaling/stretch. |
| 263 FloatRect tile(srcRect); | 263 FloatRect tile(srcRect); |
| 264 tile.scale(tileScale.width(), tileScale.height()); | 264 tile.scale(tileScale.width(), tileScale.height()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 282 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); | 282 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); |
| 283 | 283 |
| 284 SkPaint paint; | 284 SkPaint paint; |
| 285 paint.setShader(SkShader::MakePictureShader(std::move(tilePicture), | 285 paint.setShader(SkShader::MakePictureShader(std::move(tilePicture), |
| 286 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor
m, nullptr)); | 286 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor
m, nullptr)); |
| 287 paint.setXfermodeMode(compositeOp); | 287 paint.setXfermodeMode(compositeOp); |
| 288 paint.setColorFilter(sk_ref_sp(context.colorFilter())); | 288 paint.setColorFilter(sk_ref_sp(context.colorFilter())); |
| 289 context.drawRect(dstRect, paint); | 289 context.drawRect(dstRect, paint); |
| 290 } | 290 } |
| 291 | 291 |
| 292 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const
FloatSize& containerSize) | 292 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const
IntSize& containerSize) |
| 293 { | 293 { |
| 294 if (!m_page) | 294 if (!m_page) |
| 295 return nullptr; | 295 return nullptr; |
| 296 | 296 |
| 297 const FloatRect containerRect(FloatPoint(), containerSize); | 297 const FloatRect containerRect((FloatPoint()), FloatSize(containerSize)); |
| 298 | 298 |
| 299 SkPictureRecorder recorder; | 299 SkPictureRecorder recorder; |
| 300 SkCanvas* canvas = recorder.beginRecording(containerRect); | 300 SkCanvas* canvas = recorder.beginRecording(containerRect); |
| 301 drawForContainer(canvas, SkPaint(), containerSize, 1, containerRect, contain
erRect, url); | 301 drawForContainer(canvas, SkPaint(), containerRect.size(), 1, containerRect,
containerRect, url); |
| 302 | 302 |
| 303 const IntSize imageSize = roundedIntSize(containerSize); | |
| 304 const SkMatrix residualScale = SkMatrix::MakeScale( | |
| 305 static_cast<float>(imageSize.width()) / containerSize.width(), | |
| 306 static_cast<float>(imageSize.height()) / containerSize.height()); | |
| 307 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 303 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
| 308 SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nu
llptr); | 304 SkISize::Make(containerSize.width(), containerSize.height()), nullptr, n
ullptr); |
| 309 } | 305 } |
| 310 | 306 |
| 311 static bool drawNeedsLayer(const SkPaint& paint) | 307 static bool drawNeedsLayer(const SkPaint& paint) |
| 312 { | 308 { |
| 313 if (SkColorGetA(paint.getColor()) < 255) | 309 if (SkColorGetA(paint.getColor()) < 255) |
| 314 return true; | 310 return true; |
| 315 | 311 |
| 316 SkXfermode::Mode xfermode; | 312 SkXfermode::Mode xfermode; |
| 317 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | 313 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { |
| 318 if (xfermode != SkXfermode::kSrcOver_Mode) | 314 if (xfermode != SkXfermode::kSrcOver_Mode) |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 574 |
| 579 return m_page ? SizeAvailable : SizeUnavailable; | 575 return m_page ? SizeAvailable : SizeUnavailable; |
| 580 } | 576 } |
| 581 | 577 |
| 582 String SVGImage::filenameExtension() const | 578 String SVGImage::filenameExtension() const |
| 583 { | 579 { |
| 584 return "svg"; | 580 return "svg"; |
| 585 } | 581 } |
| 586 | 582 |
| 587 } // namespace blink | 583 } // namespace blink |
| OLD | NEW |