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

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

Issue 2000483003: Rework timeline/frame scheduling logic for SVGImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittest Created 4 years, 6 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 29 matching lines...) Expand all
40 #include "core/paint/FloatClipRecorder.h" 40 #include "core/paint/FloatClipRecorder.h"
41 #include "core/paint/TransformRecorder.h" 41 #include "core/paint/TransformRecorder.h"
42 #include "core/svg/SVGDocumentExtensions.h" 42 #include "core/svg/SVGDocumentExtensions.h"
43 #include "core/svg/SVGFEImageElement.h" 43 #include "core/svg/SVGFEImageElement.h"
44 #include "core/svg/SVGImageElement.h" 44 #include "core/svg/SVGImageElement.h"
45 #include "core/svg/SVGSVGElement.h" 45 #include "core/svg/SVGSVGElement.h"
46 #include "core/svg/animation/SMILTimeContainer.h" 46 #include "core/svg/animation/SMILTimeContainer.h"
47 #include "core/svg/graphics/SVGImageChromeClient.h" 47 #include "core/svg/graphics/SVGImageChromeClient.h"
48 #include "platform/EventDispatchForbiddenScope.h" 48 #include "platform/EventDispatchForbiddenScope.h"
49 #include "platform/LengthFunctions.h" 49 #include "platform/LengthFunctions.h"
50 #include "platform/ScriptForbiddenScope.h"
50 #include "platform/TraceEvent.h" 51 #include "platform/TraceEvent.h"
51 #include "platform/geometry/IntRect.h" 52 #include "platform/geometry/IntRect.h"
52 #include "platform/graphics/GraphicsContext.h" 53 #include "platform/graphics/GraphicsContext.h"
53 #include "platform/graphics/ImageBuffer.h" 54 #include "platform/graphics/ImageBuffer.h"
54 #include "platform/graphics/ImageObserver.h" 55 #include "platform/graphics/ImageObserver.h"
55 #include "platform/graphics/paint/ClipRecorder.h" 56 #include "platform/graphics/paint/ClipRecorder.h"
56 #include "platform/graphics/paint/CullRect.h" 57 #include "platform/graphics/paint/CullRect.h"
57 #include "platform/graphics/paint/DrawingRecorder.h" 58 #include "platform/graphics/paint/DrawingRecorder.h"
58 #include "platform/graphics/paint/SkPictureBuilder.h" 59 #include "platform/graphics/paint/SkPictureBuilder.h"
59 #include "third_party/skia/include/core/SkPicture.h" 60 #include "third_party/skia/include/core/SkPicture.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 { 331 {
331 if (!m_page) 332 if (!m_page)
332 return; 333 return;
333 334
334 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, clampMode, KURL()); 335 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, clampMode, KURL());
335 } 336 }
336 337
337 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR ect& dstRect, const FloatRect& srcRect, 338 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR ect& dstRect, const FloatRect& srcRect,
338 RespectImageOrientationEnum, ImageClampingMode, const KURL& url) 339 RespectImageOrientationEnum, ImageClampingMode, const KURL& url)
339 { 340 {
340 FrameView* view = frameView(); 341 DCHECK(m_page);
342 FrameView* view = toLocalFrame(m_page->mainFrame())->view();
341 view->resize(containerSize()); 343 view->resize(containerSize());
342 344
343 // Always call processUrlFragment, even if the url is empty, because 345 // Always call processUrlFragment, even if the url is empty, because
344 // there may have been a previous url/fragment that needs to be reset. 346 // there may have been a previous url/fragment that needs to be reset.
345 view->processUrlFragment(url); 347 view->processUrlFragment(url);
346 348
347 SkPictureBuilder imagePicture(dstRect); 349 SkPictureBuilder imagePicture(dstRect);
348 { 350 {
349 ClipRecorder clipRecorder(imagePicture.context(), imagePicture, DisplayI tem::ClipNodeImage, LayoutRect(enclosingIntRect(dstRect))); 351 ClipRecorder clipRecorder(imagePicture.context(), imagePicture, DisplayI tem::ClipNodeImage, LayoutRect(enclosingIntRect(dstRect)));
350 352
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 384 }
383 385
384 LayoutReplaced* SVGImage::embeddedReplacedContent() const 386 LayoutReplaced* SVGImage::embeddedReplacedContent() const
385 { 387 {
386 SVGSVGElement* rootElement = svgRootElement(m_page.get()); 388 SVGSVGElement* rootElement = svgRootElement(m_page.get());
387 if (!rootElement) 389 if (!rootElement)
388 return nullptr; 390 return nullptr;
389 return toLayoutSVGRoot(rootElement->layoutObject()); 391 return toLayoutSVGRoot(rootElement->layoutObject());
390 } 392 }
391 393
392 FrameView* SVGImage::frameView() const
393 {
394 if (!m_page)
395 return nullptr;
396
397 return toLocalFrame(m_page->mainFrame())->view();
398 }
399
400 // FIXME: support CatchUpAnimation = CatchUp. 394 // FIXME: support CatchUpAnimation = CatchUp.
401 void SVGImage::startAnimation(CatchUpAnimation) 395 void SVGImage::startAnimation(CatchUpAnimation)
402 { 396 {
403 SVGSVGElement* rootElement = svgRootElement(m_page.get()); 397 SVGSVGElement* rootElement = svgRootElement(m_page.get());
404 if (!rootElement || !rootElement->animationsPaused()) 398 if (!rootElement)
405 return; 399 return;
406 rootElement->unpauseAnimations(); 400 m_chromeClient->resumeAnimation();
401 if (rootElement->animationsPaused())
402 rootElement->unpauseAnimations();
403 }
404
405 void SVGImage::stopAnimation()
406 {
407 SVGSVGElement* rootElement = svgRootElement(m_page.get());
408 if (!rootElement)
409 return;
410 m_chromeClient->suspendAnimation();
411 rootElement->pauseAnimations();
407 } 412 }
408 413
409 void SVGImage::resetAnimation() 414 void SVGImage::resetAnimation()
410 { 415 {
411 SVGSVGElement* rootElement = svgRootElement(m_page.get()); 416 SVGSVGElement* rootElement = svgRootElement(m_page.get());
412 if (!rootElement) 417 if (!rootElement)
413 return; 418 return;
419 m_chromeClient->suspendAnimation();
414 rootElement->pauseAnimations(); 420 rootElement->pauseAnimations();
415 rootElement->setCurrentTime(0); 421 rootElement->setCurrentTime(0);
416 } 422 }
417 423
418 bool SVGImage::hasAnimations() const 424 bool SVGImage::hasAnimations() const
419 { 425 {
420 SVGSVGElement* rootElement = svgRootElement(m_page.get()); 426 SVGSVGElement* rootElement = svgRootElement(m_page.get());
421 if (!rootElement) 427 if (!rootElement)
422 return false; 428 return false;
423 return rootElement->timeContainer()->hasAnimations() || toLocalFrame(m_page- >mainFrame())->document()->timeline().hasPendingUpdates(); 429 return rootElement->timeContainer()->hasAnimations()
430 || toLocalFrame(m_page->mainFrame())->document()->timeline().hasPendingU pdates();
431 }
432
433 void SVGImage::serviceAnimations(double monotonicAnimationStartTime)
434 {
435 // If none of our observers (sic!) are visible, or for some other reason
436 // does not want us to keep running animations, stop them until further
437 // notice (next paint.)
438 if (getImageObserver()->shouldPauseAnimation(this)) {
439 stopAnimation();
440 return;
441 }
442
443 // serviceScriptedAnimations runs requestAnimationFrame callbacks, but SVG
444 // images can't have any so we assert there's no script.
445 ScriptForbiddenScope forbidScript;
446
447 // The calls below may trigger GCs, so set up the required persistent
448 // reference on the ImageResource which owns this SVGImage. By transitivity,
449 // that will keep the associated SVGImageChromeClient object alive.
450 Persistent<ImageObserver> protect(getImageObserver());
451 m_page->animator().serviceScriptedAnimations(monotonicAnimationStartTime);
452 m_page->animator().updateAllLifecyclePhases(*toLocalFrame(m_page->mainFrame( )));
424 } 453 }
425 454
426 void SVGImage::advanceAnimationForTesting() 455 void SVGImage::advanceAnimationForTesting()
427 { 456 {
428 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) { 457 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) {
429 rootElement->timeContainer()->advanceFrameForTesting(); 458 rootElement->timeContainer()->advanceFrameForTesting();
430 459
431 // The following triggers animation updates which can issue a new draw 460 // The following triggers animation updates which can issue a new draw
432 // but will not permanently change the animation timeline. 461 // but will not permanently change the animation timeline.
433 // TODO(pdr): Actually advance the document timeline so CSS animations 462 // TODO(pdr): Actually advance the document timeline so CSS animations
434 // can be properly tested. 463 // can be properly tested.
435 rootElement->document().page()->animator().serviceScriptedAnimations(roo tElement->getCurrentTime()); 464 m_page->animator().serviceScriptedAnimations(rootElement->getCurrentTime ());
436 getImageObserver()->animationAdvanced(this); 465 getImageObserver()->animationAdvanced(this);
437 } 466 }
438 } 467 }
439 468
469 SVGImageChromeClient& SVGImage::chromeClientForTesting()
470 {
471 return *m_chromeClient;
472 }
473
440 void SVGImage::updateUseCounters(Document& document) const 474 void SVGImage::updateUseCounters(Document& document) const
441 { 475 {
442 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) { 476 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) {
443 if (rootElement->timeContainer()->hasAnimations()) 477 if (rootElement->timeContainer()->hasAnimations())
444 Deprecation::countDeprecation(document, UseCounter::SVGSMILAnimation InImageRegardlessOfCache); 478 Deprecation::countDeprecation(document, UseCounter::SVGSMILAnimation InImageRegardlessOfCache);
445 } 479 }
446 } 480 }
447 481
448 bool SVGImage::dataChanged(bool allDataReceived) 482 bool SVGImage::dataChanged(bool allDataReceived)
449 { 483 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 561
528 return m_page; 562 return m_page;
529 } 563 }
530 564
531 String SVGImage::filenameExtension() const 565 String SVGImage::filenameExtension() const
532 { 566 {
533 return "svg"; 567 return "svg";
534 } 568 }
535 569
536 } // namespace blink 570 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698