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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "platform/EventDispatchForbiddenScope.h" | 47 #include "platform/EventDispatchForbiddenScope.h" |
48 #include "platform/LengthFunctions.h" | 48 #include "platform/LengthFunctions.h" |
49 #include "platform/ScriptForbiddenScope.h" | 49 #include "platform/ScriptForbiddenScope.h" |
50 #include "platform/geometry/IntRect.h" | 50 #include "platform/geometry/IntRect.h" |
51 #include "platform/graphics/GraphicsContext.h" | 51 #include "platform/graphics/GraphicsContext.h" |
52 #include "platform/graphics/ImageBuffer.h" | 52 #include "platform/graphics/ImageBuffer.h" |
53 #include "platform/graphics/ImageObserver.h" | 53 #include "platform/graphics/ImageObserver.h" |
54 #include "platform/graphics/paint/ClipRecorder.h" | 54 #include "platform/graphics/paint/ClipRecorder.h" |
55 #include "platform/graphics/paint/CullRect.h" | 55 #include "platform/graphics/paint/CullRect.h" |
56 #include "platform/graphics/paint/DrawingRecorder.h" | 56 #include "platform/graphics/paint/DrawingRecorder.h" |
| 57 #include "platform/graphics/paint/PaintRecord.h" |
57 #include "platform/graphics/paint/SkPictureBuilder.h" | 58 #include "platform/graphics/paint/SkPictureBuilder.h" |
58 #include "platform/instrumentation/tracing/TraceEvent.h" | 59 #include "platform/instrumentation/tracing/TraceEvent.h" |
59 #include "third_party/skia/include/core/SkPicture.h" | |
60 #include "wtf/PassRefPtr.h" | 60 #include "wtf/PassRefPtr.h" |
61 | 61 |
62 namespace blink { | 62 namespace blink { |
63 | 63 |
64 SVGImage::SVGImage(ImageObserver* observer) | 64 SVGImage::SVGImage(ImageObserver* observer) |
65 : Image(observer), | 65 : Image(observer), |
66 m_paintController(PaintController::create()), | 66 m_paintController(PaintController::create()), |
67 m_hasPendingTimelineRewind(false) {} | 67 m_hasPendingTimelineRewind(false) {} |
68 | 68 |
69 SVGImage::~SVGImage() { | 69 SVGImage::~SVGImage() { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return FloatSize(solutionWidth, defaultObjectSize.height()); | 220 return FloatSize(solutionWidth, defaultObjectSize.height()); |
221 | 221 |
222 float solutionHeight = resolveHeightForRatio( | 222 float solutionHeight = resolveHeightForRatio( |
223 defaultObjectSize.width(), intrinsicSizingInfo.aspectRatio); | 223 defaultObjectSize.width(), intrinsicSizingInfo.aspectRatio); |
224 return FloatSize(defaultObjectSize.width(), solutionHeight); | 224 return FloatSize(defaultObjectSize.width(), solutionHeight); |
225 } | 225 } |
226 | 226 |
227 return defaultObjectSize; | 227 return defaultObjectSize; |
228 } | 228 } |
229 | 229 |
230 void SVGImage::drawForContainer(SkCanvas* canvas, | 230 void SVGImage::drawForContainer(PaintCanvas* canvas, |
231 const SkPaint& paint, | 231 const PaintFlags& paint, |
232 const FloatSize containerSize, | 232 const FloatSize containerSize, |
233 float zoom, | 233 float zoom, |
234 const FloatRect& dstRect, | 234 const FloatRect& dstRect, |
235 const FloatRect& srcRect, | 235 const FloatRect& srcRect, |
236 const KURL& url) { | 236 const KURL& url) { |
237 if (!m_page) | 237 if (!m_page) |
238 return; | 238 return; |
239 | 239 |
240 // Temporarily disable the image observer to prevent changeInRect() calls due | 240 // Temporarily disable the image observer to prevent changeInRect() calls due |
241 // re-laying out the image. | 241 // re-laying out the image. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 299 } |
300 | 300 |
301 { | 301 { |
302 DrawingRecorder patternPictureRecorder( | 302 DrawingRecorder patternPictureRecorder( |
303 patternPicture.context(), patternPicture, DisplayItem::Type::kSVGImage, | 303 patternPicture.context(), patternPicture, DisplayItem::Type::kSVGImage, |
304 spacedTile); | 304 spacedTile); |
305 // When generating an expanded tile, make sure we don't draw into the | 305 // When generating an expanded tile, make sure we don't draw into the |
306 // spacing area. | 306 // spacing area. |
307 if (tile != spacedTile) | 307 if (tile != spacedTile) |
308 patternPicture.context().clip(tile); | 308 patternPicture.context().clip(tile); |
309 SkPaint paint; | 309 PaintFlags paint; |
310 drawForContainer(patternPicture.context().canvas(), paint, containerSize, | 310 drawForContainer(patternPicture.context().canvas(), paint, containerSize, |
311 zoom, tile, srcRect, url); | 311 zoom, tile, srcRect, url); |
312 } | 312 } |
313 sk_sp<SkPicture> tilePicture = patternPicture.endRecording(); | 313 sk_sp<PaintRecord> tilePicture = patternPicture.endRecording(); |
314 | 314 |
315 SkMatrix patternTransform; | 315 SkMatrix patternTransform; |
316 patternTransform.setTranslate(phase.x() + spacedTile.x(), | 316 patternTransform.setTranslate(phase.x() + spacedTile.x(), |
317 phase.y() + spacedTile.y()); | 317 phase.y() + spacedTile.y()); |
318 | 318 |
319 SkPaint paint; | 319 PaintFlags paint; |
320 paint.setShader(SkShader::MakePictureShader( | 320 paint.setShader(MakePaintShaderPicture( |
321 std::move(tilePicture), SkShader::kRepeat_TileMode, | 321 tilePicture, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, |
322 SkShader::kRepeat_TileMode, &patternTransform, nullptr)); | 322 &patternTransform, nullptr)); |
323 paint.setBlendMode(compositeOp); | 323 paint.setBlendMode(compositeOp); |
324 paint.setColorFilter(sk_ref_sp(context.getColorFilter())); | 324 paint.setColorFilter(sk_ref_sp(context.getColorFilter())); |
325 context.drawRect(dstRect, paint); | 325 context.drawRect(dstRect, paint); |
326 } | 326 } |
327 | 327 |
328 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer( | 328 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer( |
329 const KURL& url, | 329 const KURL& url, |
330 const IntSize& containerSize) { | 330 const IntSize& containerSize) { |
331 if (!m_page) | 331 if (!m_page) |
332 return nullptr; | 332 return nullptr; |
333 | 333 |
334 const FloatRect containerRect((FloatPoint()), FloatSize(containerSize)); | 334 const FloatRect containerRect((FloatPoint()), FloatSize(containerSize)); |
335 | 335 |
336 SkPictureRecorder recorder; | 336 PaintRecorder recorder; |
337 SkCanvas* canvas = recorder.beginRecording(containerRect); | 337 PaintCanvas* canvas = recorder.beginRecording(containerRect); |
338 drawForContainer(canvas, SkPaint(), containerRect.size(), 1, containerRect, | 338 drawForContainer(canvas, PaintFlags(), containerRect.size(), 1, containerRect, |
339 containerRect, url); | 339 containerRect, url); |
340 | 340 |
341 return SkImage::MakeFromPicture( | 341 return SkImage::MakeFromPicture( |
342 recorder.finishRecordingAsPicture(), | 342 ToSkPicture(recorder.finishRecordingAsPicture()), |
343 SkISize::Make(containerSize.width(), containerSize.height()), nullptr, | 343 SkISize::Make(containerSize.width(), containerSize.height()), nullptr, |
344 nullptr); | 344 nullptr); |
345 } | 345 } |
346 | 346 |
347 static bool drawNeedsLayer(const SkPaint& paint) { | 347 static bool drawNeedsLayer(const PaintFlags& paint) { |
348 if (SkColorGetA(paint.getColor()) < 255) | 348 if (SkColorGetA(paint.getColor()) < 255) |
349 return true; | 349 return true; |
350 return !paint.isSrcOver(); | 350 return !paint.isSrcOver(); |
351 } | 351 } |
352 | 352 |
353 void SVGImage::draw(SkCanvas* canvas, | 353 void SVGImage::draw(PaintCanvas* canvas, |
354 const SkPaint& paint, | 354 const PaintFlags& paint, |
355 const FloatRect& dstRect, | 355 const FloatRect& dstRect, |
356 const FloatRect& srcRect, | 356 const FloatRect& srcRect, |
357 RespectImageOrientationEnum shouldRespectImageOrientation, | 357 RespectImageOrientationEnum shouldRespectImageOrientation, |
358 ImageClampingMode clampMode, | 358 ImageClampingMode clampMode, |
359 const ColorBehavior& colorBehavior) { | 359 const ColorBehavior& colorBehavior) { |
360 // TODO(ccameron): This function should not ignore |colorBehavior|. | 360 // TODO(ccameron): This function should not ignore |colorBehavior|. |
361 // https://crbug.com/667431 | 361 // https://crbug.com/667431 |
362 if (!m_page) | 362 if (!m_page) |
363 return; | 363 return; |
364 | 364 |
365 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, | 365 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, |
366 clampMode, KURL()); | 366 clampMode, KURL()); |
367 } | 367 } |
368 | 368 |
369 void SVGImage::drawInternal(SkCanvas* canvas, | 369 void SVGImage::drawInternal(PaintCanvas* canvas, |
370 const SkPaint& paint, | 370 const PaintFlags& paint, |
371 const FloatRect& dstRect, | 371 const FloatRect& dstRect, |
372 const FloatRect& srcRect, | 372 const FloatRect& srcRect, |
373 RespectImageOrientationEnum, | 373 RespectImageOrientationEnum, |
374 ImageClampingMode, | 374 ImageClampingMode, |
375 const KURL& url) { | 375 const KURL& url) { |
376 DCHECK(m_page); | 376 DCHECK(m_page); |
377 FrameView* view = toLocalFrame(m_page->mainFrame())->view(); | 377 FrameView* view = toLocalFrame(m_page->mainFrame())->view(); |
378 view->resize(containerSize()); | 378 view->resize(containerSize()); |
379 | 379 |
380 // Always call processUrlFragment, even if the url is empty, because | 380 // Always call processUrlFragment, even if the url is empty, because |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 transform.scale(scale.width(), scale.height()); | 417 transform.scale(scale.width(), scale.height()); |
418 TransformRecorder transformRecorder(imagePicture.context(), imagePicture, | 418 TransformRecorder transformRecorder(imagePicture.context(), imagePicture, |
419 transform); | 419 transform); |
420 | 420 |
421 view->updateAllLifecyclePhasesExceptPaint(); | 421 view->updateAllLifecyclePhasesExceptPaint(); |
422 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect))); | 422 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect))); |
423 ASSERT(!view->needsLayout()); | 423 ASSERT(!view->needsLayout()); |
424 } | 424 } |
425 | 425 |
426 { | 426 { |
427 SkAutoCanvasRestore ar(canvas, false); | 427 PaintCanvasAutoRestore ar(canvas, false); |
428 if (drawNeedsLayer(paint)) { | 428 if (drawNeedsLayer(paint)) { |
429 SkRect layerRect = dstRect; | 429 SkRect layerRect = dstRect; |
430 canvas->saveLayer(&layerRect, &paint); | 430 canvas->saveLayer(&layerRect, &paint); |
431 } | 431 } |
432 sk_sp<const SkPicture> recording = imagePicture.endRecording(); | 432 sk_sp<PaintRecord> recording = imagePicture.endRecording(); |
433 canvas->drawPicture(recording.get()); | 433 canvas->drawPicture(recording.get()); |
434 } | 434 } |
435 | 435 |
436 // Start any (SMIL) animations if needed. This will restart or continue | 436 // Start any (SMIL) animations if needed. This will restart or continue |
437 // animations if preceded by calls to resetAnimation or stopAnimation | 437 // animations if preceded by calls to resetAnimation or stopAnimation |
438 // respectively. | 438 // respectively. |
439 startAnimation(); | 439 startAnimation(); |
440 } | 440 } |
441 | 441 |
442 LayoutReplaced* SVGImage::embeddedReplacedContent() const { | 442 LayoutReplaced* SVGImage::embeddedReplacedContent() const { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 648 } |
649 | 649 |
650 return m_page ? SizeAvailable : SizeUnavailable; | 650 return m_page ? SizeAvailable : SizeUnavailable; |
651 } | 651 } |
652 | 652 |
653 String SVGImage::filenameExtension() const { | 653 String SVGImage::filenameExtension() const { |
654 return "svg"; | 654 return "svg"; |
655 } | 655 } |
656 | 656 |
657 } // namespace blink | 657 } // namespace blink |
OLD | NEW |