| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 scaledSrc.scale(1 / zoom); | 252 scaledSrc.scale(1 / zoom); |
| 253 | 253 |
| 254 // Compensate for the container size rounding by adjusting the source rect. | 254 // Compensate for the container size rounding by adjusting the source rect. |
| 255 FloatSize adjustedSrcSize = scaledSrc.size(); | 255 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 256 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | 256 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); |
| 257 scaledSrc.setSize(adjustedSrcSize); | 257 scaledSrc.setSize(adjustedSrcSize); |
| 258 | 258 |
| 259 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); | 259 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); |
| 260 } | 260 } |
| 261 | 261 |
| 262 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() | 262 sk_sp<SkImage> SVGImage::imageForCurrentFrame() |
| 263 { | 263 { |
| 264 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); | 264 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
containerSize, | 267 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
containerSize, |
| 268 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, | 268 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, |
| 269 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 269 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
| 270 const FloatSize& repeatSpacing, const KURL& url) | 270 const FloatSize& repeatSpacing, const KURL& url) |
| 271 { | 271 { |
| 272 // Tile adjusted for scaling/stretch. | 272 // Tile adjusted for scaling/stretch. |
| 273 FloatRect tile(srcRect); | 273 FloatRect tile(srcRect); |
| 274 tile.scale(tileScale.width(), tileScale.height()); | 274 tile.scale(tileScale.width(), tileScale.height()); |
| 275 | 275 |
| 276 // Expand the tile to account for repeat spacing. | 276 // Expand the tile to account for repeat spacing. |
| 277 FloatRect spacedTile(tile); | 277 FloatRect spacedTile(tile); |
| 278 spacedTile.expand(FloatSize(repeatSpacing)); | 278 spacedTile.expand(FloatSize(repeatSpacing)); |
| 279 | 279 |
| 280 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); | 280 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); |
| 281 { | 281 { |
| 282 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern
Picture, DisplayItem::Type::kSVGImage, spacedTile); | 282 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern
Picture, DisplayItem::Type::kSVGImage, spacedTile); |
| 283 // When generating an expanded tile, make sure we don't draw into the sp
acing area. | 283 // When generating an expanded tile, make sure we don't draw into the sp
acing area. |
| 284 if (tile != spacedTile) | 284 if (tile != spacedTile) |
| 285 patternPicture.context().clip(tile); | 285 patternPicture.context().clip(tile); |
| 286 SkPaint paint; | 286 SkPaint paint; |
| 287 drawForContainer(patternPicture.context().canvas(), paint, containerSize
, zoom, tile, srcRect, url); | 287 drawForContainer(patternPicture.context().canvas(), paint, containerSize
, zoom, tile, srcRect, url); |
| 288 } | 288 } |
| 289 RefPtr<SkPicture> tilePicture = patternPicture.endRecording(); | 289 sk_sp<SkPicture> tilePicture = patternPicture.endRecording(); |
| 290 | 290 |
| 291 SkMatrix patternTransform; | 291 SkMatrix patternTransform; |
| 292 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); | 292 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); |
| 293 | 293 |
| 294 SkPaint paint; | 294 SkPaint paint; |
| 295 paint.setShader(SkShader::MakePictureShader(toSkSp(tilePicture.release()), | 295 paint.setShader(SkShader::MakePictureShader(std::move(tilePicture), |
| 296 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor
m, nullptr)); | 296 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor
m, nullptr)); |
| 297 paint.setXfermodeMode(compositeOp); | 297 paint.setXfermodeMode(compositeOp); |
| 298 paint.setColorFilter(sk_ref_sp(context.colorFilter())); | 298 paint.setColorFilter(sk_ref_sp(context.colorFilter())); |
| 299 context.drawRect(dstRect, paint); | 299 context.drawRect(dstRect, paint); |
| 300 } | 300 } |
| 301 | 301 |
| 302 PassRefPtr<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url,
const FloatSize& containerSize) | 302 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const
FloatSize& containerSize) |
| 303 { | 303 { |
| 304 if (!m_page) | 304 if (!m_page) |
| 305 return nullptr; | 305 return nullptr; |
| 306 | 306 |
| 307 const FloatRect containerRect(FloatPoint(), containerSize); | 307 const FloatRect containerRect(FloatPoint(), containerSize); |
| 308 | 308 |
| 309 SkPictureRecorder recorder; | 309 SkPictureRecorder recorder; |
| 310 SkCanvas* canvas = recorder.beginRecording(containerRect); | 310 SkCanvas* canvas = recorder.beginRecording(containerRect); |
| 311 drawForContainer(canvas, SkPaint(), containerSize, 1, containerRect, contain
erRect, url); | 311 drawForContainer(canvas, SkPaint(), containerSize, 1, containerRect, contain
erRect, url); |
| 312 | 312 |
| 313 const IntSize imageSize = roundedIntSize(containerSize); | 313 const IntSize imageSize = roundedIntSize(containerSize); |
| 314 const SkMatrix residualScale = SkMatrix::MakeScale( | 314 const SkMatrix residualScale = SkMatrix::MakeScale( |
| 315 static_cast<float>(imageSize.width()) / containerSize.width(), | 315 static_cast<float>(imageSize.width()) / containerSize.width(), |
| 316 static_cast<float>(imageSize.height()) / containerSize.height()); | 316 static_cast<float>(imageSize.height()) / containerSize.height()); |
| 317 return fromSkSp(SkImage::MakeFromPicture(recorder.finishRecordingAsPicture()
, | 317 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
| 318 SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nu
llptr)); | 318 SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nu
llptr); |
| 319 } | 319 } |
| 320 | 320 |
| 321 static bool drawNeedsLayer(const SkPaint& paint) | 321 static bool drawNeedsLayer(const SkPaint& paint) |
| 322 { | 322 { |
| 323 if (SkColorGetA(paint.getColor()) < 255) | 323 if (SkColorGetA(paint.getColor()) < 255) |
| 324 return true; | 324 return true; |
| 325 | 325 |
| 326 SkXfermode::Mode xfermode; | 326 SkXfermode::Mode xfermode; |
| 327 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | 327 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { |
| 328 if (xfermode != SkXfermode::kSrcOver_Mode) | 328 if (xfermode != SkXfermode::kSrcOver_Mode) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect)))
; | 376 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect)))
; |
| 377 ASSERT(!view->needsLayout()); | 377 ASSERT(!view->needsLayout()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 { | 380 { |
| 381 SkAutoCanvasRestore ar(canvas, false); | 381 SkAutoCanvasRestore ar(canvas, false); |
| 382 if (drawNeedsLayer(paint)) { | 382 if (drawNeedsLayer(paint)) { |
| 383 SkRect layerRect = dstRect; | 383 SkRect layerRect = dstRect; |
| 384 canvas->saveLayer(&layerRect, &paint); | 384 canvas->saveLayer(&layerRect, &paint); |
| 385 } | 385 } |
| 386 RefPtr<const SkPicture> recording = imagePicture.endRecording(); | 386 sk_sp<const SkPicture> recording = imagePicture.endRecording(); |
| 387 canvas->drawPicture(recording.get()); | 387 canvas->drawPicture(recording.get()); |
| 388 } | 388 } |
| 389 | 389 |
| 390 if (getImageObserver()) | 390 if (getImageObserver()) |
| 391 getImageObserver()->didDraw(this); | 391 getImageObserver()->didDraw(this); |
| 392 | 392 |
| 393 // Start any (SMIL) animations if needed. This will restart or continue | 393 // Start any (SMIL) animations if needed. This will restart or continue |
| 394 // animations if preceded by calls to resetAnimation or stopAnimation | 394 // animations if preceded by calls to resetAnimation or stopAnimation |
| 395 // respectively. | 395 // respectively. |
| 396 startAnimation(); | 396 startAnimation(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 588 |
| 589 return m_page ? SizeAvailable : SizeUnavailable; | 589 return m_page ? SizeAvailable : SizeUnavailable; |
| 590 } | 590 } |
| 591 | 591 |
| 592 String SVGImage::filenameExtension() const | 592 String SVGImage::filenameExtension() const |
| 593 { | 593 { |
| 594 return "svg"; | 594 return "svg"; |
| 595 } | 595 } |
| 596 | 596 |
| 597 } // namespace blink | 597 } // namespace blink |
| OLD | NEW |