| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 scaledSrc.scale(1 / zoom); | 242 scaledSrc.scale(1 / zoom); |
| 243 | 243 |
| 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 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() | 252 sk_sp<SkImage> SVGImage::imageForCurrentFrame() |
| 253 { | 253 { |
| 254 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); | 254 return imageForCurrentFrameForContainer(KURL(), FloatSize(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()); |
| 265 | 265 |
| 266 // Expand the tile to account for repeat spacing. | 266 // Expand the tile to account for repeat spacing. |
| 267 FloatRect spacedTile(tile); | 267 FloatRect spacedTile(tile); |
| 268 spacedTile.expand(FloatSize(repeatSpacing)); | 268 spacedTile.expand(FloatSize(repeatSpacing)); |
| 269 | 269 |
| 270 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); | 270 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); |
| 271 { | 271 { |
| 272 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern
Picture, DisplayItem::Type::kSVGImage, spacedTile); | 272 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern
Picture, DisplayItem::Type::kSVGImage, spacedTile); |
| 273 // When generating an expanded tile, make sure we don't draw into the sp
acing area. | 273 // When generating an expanded tile, make sure we don't draw into the sp
acing area. |
| 274 if (tile != spacedTile) | 274 if (tile != spacedTile) |
| 275 patternPicture.context().clip(tile); | 275 patternPicture.context().clip(tile); |
| 276 SkPaint paint; | 276 SkPaint paint; |
| 277 drawForContainer(patternPicture.context().canvas(), paint, containerSize
, zoom, tile, srcRect, url); | 277 drawForContainer(patternPicture.context().canvas(), paint, containerSize
, zoom, tile, srcRect, url); |
| 278 } | 278 } |
| 279 RefPtr<SkPicture> tilePicture = patternPicture.endRecording(); | 279 sk_sp<SkPicture> tilePicture = patternPicture.endRecording(); |
| 280 | 280 |
| 281 SkMatrix patternTransform; | 281 SkMatrix patternTransform; |
| 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(toSkSp(tilePicture.release()), | 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 PassRefPtr<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url,
const FloatSize& containerSize) | 292 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const
FloatSize& 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(), 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(), containerSize, 1, containerRect, contain
erRect, url); |
| 302 | 302 |
| 303 const IntSize imageSize = roundedIntSize(containerSize); | 303 const IntSize imageSize = roundedIntSize(containerSize); |
| 304 const SkMatrix residualScale = SkMatrix::MakeScale( | 304 const SkMatrix residualScale = SkMatrix::MakeScale( |
| 305 static_cast<float>(imageSize.width()) / containerSize.width(), | 305 static_cast<float>(imageSize.width()) / containerSize.width(), |
| 306 static_cast<float>(imageSize.height()) / containerSize.height()); | 306 static_cast<float>(imageSize.height()) / containerSize.height()); |
| 307 return fromSkSp(SkImage::MakeFromPicture(recorder.finishRecordingAsPicture()
, | 307 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
| 308 SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nu
llptr)); | 308 SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nu
llptr); |
| 309 } | 309 } |
| 310 | 310 |
| 311 static bool drawNeedsLayer(const SkPaint& paint) | 311 static bool drawNeedsLayer(const SkPaint& paint) |
| 312 { | 312 { |
| 313 if (SkColorGetA(paint.getColor()) < 255) | 313 if (SkColorGetA(paint.getColor()) < 255) |
| 314 return true; | 314 return true; |
| 315 | 315 |
| 316 SkXfermode::Mode xfermode; | 316 SkXfermode::Mode xfermode; |
| 317 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | 317 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { |
| 318 if (xfermode != SkXfermode::kSrcOver_Mode) | 318 if (xfermode != SkXfermode::kSrcOver_Mode) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect)))
; | 366 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect)))
; |
| 367 ASSERT(!view->needsLayout()); | 367 ASSERT(!view->needsLayout()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 { | 370 { |
| 371 SkAutoCanvasRestore ar(canvas, false); | 371 SkAutoCanvasRestore ar(canvas, false); |
| 372 if (drawNeedsLayer(paint)) { | 372 if (drawNeedsLayer(paint)) { |
| 373 SkRect layerRect = dstRect; | 373 SkRect layerRect = dstRect; |
| 374 canvas->saveLayer(&layerRect, &paint); | 374 canvas->saveLayer(&layerRect, &paint); |
| 375 } | 375 } |
| 376 RefPtr<const SkPicture> recording = imagePicture.endRecording(); | 376 sk_sp<const SkPicture> recording = imagePicture.endRecording(); |
| 377 canvas->drawPicture(recording.get()); | 377 canvas->drawPicture(recording.get()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 if (getImageObserver()) | 380 if (getImageObserver()) |
| 381 getImageObserver()->didDraw(this); | 381 getImageObserver()->didDraw(this); |
| 382 | 382 |
| 383 // Start any (SMIL) animations if needed. This will restart or continue | 383 // Start any (SMIL) animations if needed. This will restart or continue |
| 384 // animations if preceded by calls to resetAnimation or stopAnimation | 384 // animations if preceded by calls to resetAnimation or stopAnimation |
| 385 // respectively. | 385 // respectively. |
| 386 startAnimation(); | 386 startAnimation(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 return m_page ? SizeAvailable : SizeUnavailable; | 579 return m_page ? SizeAvailable : SizeUnavailable; |
| 580 } | 580 } |
| 581 | 581 |
| 582 String SVGImage::filenameExtension() const | 582 String SVGImage::filenameExtension() const |
| 583 { | 583 { |
| 584 return "svg"; | 584 return "svg"; |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace blink | 587 } // namespace blink |
| OLD | NEW |