Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp

Issue 2791043002: Draw recorded content directly into the containing PaintCanvas, when possible. (Closed)
Patch Set: none Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 PaintRecordBuilder builder(intBounds, nullptr, nullptr, 431 PaintRecordBuilder builder(intBounds, nullptr, nullptr,
432 m_paintController.get()); 432 m_paintController.get());
433 433
434 view->updateAllLifecyclePhasesExceptPaint(); 434 view->updateAllLifecyclePhasesExceptPaint();
435 view->paint(builder.context(), CullRect(intBounds)); 435 view->paint(builder.context(), CullRect(intBounds));
436 DCHECK(!view->needsLayout()); 436 DCHECK(!view->needsLayout());
437 437
438 return builder.endRecording(); 438 return builder.endRecording();
439 } 439 }
440 440
441 void SVGImage::paintCurrentFrame(const FloatRect& bounds,
wkorman 2017/04/01 00:32:40 This looks identical to SVGImage::paintRecordForCu
chrishtr 2017/04/01 04:05:47 Good idea, done.
442 const KURL& url,
443 PaintCanvas& canvas) {
444 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
445 DCHECK(m_page);
446 FrameView* view = toLocalFrame(m_page->mainFrame())->view();
447 view->resize(containerSize());
448
449 // Always call processUrlFragment, even if the url is empty, because
450 // there may have been a previous url/fragment that needs to be reset.
451 view->processUrlFragment(url);
452
453 // If the image was reset, we need to rewind the timeline back to 0. This
454 // needs to be done before painting, or else we wouldn't get the correct
455 // reset semantics (we'd paint the "last" frame rather than the one at
456 // time=0.) The reason we do this here and not in resetAnimation() is to
457 // avoid setting timers from the latter.
458 flushPendingTimelineRewind();
459
460 IntRect intBounds(enclosingIntRect(bounds));
461 PaintRecordBuilder builder(intBounds, nullptr, nullptr,
462 m_paintController.get());
463
464 view->updateAllLifecyclePhasesExceptPaint();
465 view->paint(builder.context(), CullRect(intBounds));
466 DCHECK(!view->needsLayout());
467
468 builder.endRecording(canvas);
469 }
470
441 void SVGImage::drawInternal(PaintCanvas* canvas, 471 void SVGImage::drawInternal(PaintCanvas* canvas,
442 const PaintFlags& flags, 472 const PaintFlags& flags,
443 const FloatRect& dstRect, 473 const FloatRect& dstRect,
444 const FloatRect& srcRect, 474 const FloatRect& srcRect,
445 RespectImageOrientationEnum, 475 RespectImageOrientationEnum,
446 ImageClampingMode, 476 ImageClampingMode,
447 const KURL& url) { 477 const KURL& url) {
448 { 478 {
449 PaintCanvasAutoRestore ar(canvas, false); 479 PaintCanvasAutoRestore ar(canvas, false);
450 if (drawNeedsLayer(flags)) { 480 if (drawNeedsLayer(flags)) {
451 SkRect layerRect = dstRect; 481 SkRect layerRect = dstRect;
452 canvas->saveLayer(&layerRect, &flags); 482 canvas->saveLayer(&layerRect, &flags);
453 } 483 }
454 // We can only draw the entire frame, clipped to the rect we want. So 484 // We can only draw the entire frame, clipped to the rect we want. So
455 // compute where the top left of the image would be if we were drawing 485 // compute where the top left of the image would be if we were drawing
456 // without clipping, and translate accordingly. 486 // without clipping, and translate accordingly.
457 FloatSize scale(dstRect.width() / srcRect.width(), 487 FloatSize scale(dstRect.width() / srcRect.width(),
458 dstRect.height() / srcRect.height()); 488 dstRect.height() / srcRect.height());
459 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), 489 FloatSize topLeftOffset(srcRect.location().x() * scale.width(),
460 srcRect.location().y() * scale.height()); 490 srcRect.location().y() * scale.height());
461 FloatPoint destOffset = dstRect.location() - topLeftOffset; 491 FloatPoint destOffset = dstRect.location() - topLeftOffset;
462 AffineTransform transform = 492 AffineTransform transform =
463 AffineTransform::translation(destOffset.x(), destOffset.y()); 493 AffineTransform::translation(destOffset.x(), destOffset.y());
464 transform.scale(scale.width(), scale.height()); 494 transform.scale(scale.width(), scale.height());
465 495
466 canvas->save(); 496 canvas->save();
467 canvas->clipRect(enclosingIntRect(dstRect)); 497 canvas->clipRect(enclosingIntRect(dstRect));
468 canvas->concat(affineTransformToSkMatrix(transform)); 498 canvas->concat(affineTransformToSkMatrix(transform));
469 canvas->PlaybackPaintRecord(paintRecordForCurrentFrame(srcRect, url)); 499 paintCurrentFrame(srcRect, url, *canvas);
470 canvas->restore(); 500 canvas->restore();
471 } 501 }
472 502
473 // Start any (SMIL) animations if needed. This will restart or continue 503 // Start any (SMIL) animations if needed. This will restart or continue
474 // animations if preceded by calls to resetAnimation or stopAnimation 504 // animations if preceded by calls to resetAnimation or stopAnimation
475 // respectively. 505 // respectively.
476 startAnimation(); 506 startAnimation();
477 } 507 }
478 508
479 LayoutReplaced* SVGImage::embeddedReplacedContent() const { 509 LayoutReplaced* SVGImage::embeddedReplacedContent() const {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 715 }
686 716
687 return m_page ? SizeAvailable : SizeUnavailable; 717 return m_page ? SizeAvailable : SizeUnavailable;
688 } 718 }
689 719
690 String SVGImage::filenameExtension() const { 720 String SVGImage::filenameExtension() const {
691 return "svg"; 721 return "svg";
692 } 722 }
693 723
694 } // namespace blink 724 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698