Changeset 215952 in webkit
- Timestamp:
- Apr 28, 2017 3:37:56 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r215951 r215952 1 2017-04-28 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 Unify how BitmapImage handles the availability of a decoded for large and animated images 4 https://bugs.webkit.org/show_bug.cgi?id=171410 5 6 Reviewed by Simon Fraser. 7 8 Rename some functions which are related to animation frame availability. 9 Make BitmapImage call ImageObserver::imageFrameAvailable() whenever a 10 frame is available regardless it is for an animated or for a large image. 11 12 * html/HTMLMediaElement.cpp: 13 (WebCore::HTMLMediaElement::isVisibleInViewport): 14 * html/MediaElementSession.cpp: 15 (WebCore::MediaElementSession::autoplayPermitted): 16 (WebCore::isMainContentForPurposesOfAutoplay): 17 * loader/cache/CachedImage.cpp: 18 (WebCore::CachedImage::CachedImageObserver::imageFrameAvailable): 19 (WebCore::CachedImage::imageFrameAvailable): 20 (WebCore::CachedImage::usesImageContainerSize): Deleted. 21 (WebCore::CachedImage::imageHasRelativeWidth): Deleted. 22 (WebCore::CachedImage::imageHasRelativeHeight): Deleted. 23 (WebCore::CachedImage::CachedImageObserver::animationAdvanced): Deleted. 24 (WebCore::CachedImage::animationAdvanced): Deleted. 25 * loader/cache/CachedImage.h: 26 * loader/cache/CachedImageClient.h: 27 (WebCore::CachedImageClient::imageFrameAvailable): 28 (WebCore::CachedImageClient::newImageAnimationFrameAvailable): Deleted. 29 * platform/graphics/BitmapImage.cpp: 30 (WebCore::BitmapImage::internalAdvanceAnimation): 31 (WebCore::BitmapImage::imageFrameAvailableAtIndex): 32 (WebCore::BitmapImage::newFrameNativeImageAvailableAtIndex): Deleted. 33 * platform/graphics/BitmapImage.h: 34 * platform/graphics/Image.h: 35 (WebCore::Image::imageFrameAvailableAtIndex): 36 (WebCore::Image::newFrameNativeImageAvailableAtIndex): Deleted. 37 * platform/graphics/ImageFrameCache.cpp: 38 (WebCore::ImageFrameCache::cacheAsyncFrameNativeImageAtIndex): 39 * platform/graphics/ImageObserver.h: 40 * platform/graphics/ImageTypes.h: 41 * rendering/RenderElement.cpp: 42 (WebCore::RenderElement::RenderElement): 43 (WebCore::RenderElement::shouldRepaintInVisibleRect): 44 (WebCore::RenderElement::imageFrameAvailable): 45 (WebCore::RenderElement::repaintForPausedImageAnimationsIfNeeded): 46 (WebCore::shouldRepaintForImageAnimation): Deleted. 47 (WebCore::RenderElement::newImageAnimationFrameAvailable): Deleted. 48 * rendering/RenderElement.h: 49 * rendering/RenderView.cpp: 50 (WebCore::RenderView::updateVisibleViewportRect): 51 * svg/graphics/SVGImageClients.h: 52 1 53 2017-04-28 Jeremy Jones <jeremyj@apple.com> 2 54 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r215948 r215952 7418 7418 { 7419 7419 auto renderer = this->renderer(); 7420 return renderer && renderer->visibleInViewportState() == RenderElement::VisibleInViewport;7420 return renderer && renderer->visibleInViewportState() == VisibleInViewportState::Yes; 7421 7421 } 7422 7422 -
trunk/Source/WebCore/html/MediaElementSession.cpp
r215617 r215952 210 210 if (renderer->view().frameView().isOffscreen()) 211 211 return false; 212 if (renderer->visibleInViewportState() != RenderElement::VisibleInViewport)212 if (renderer->visibleInViewportState() != VisibleInViewportState::Yes) 213 213 return false; 214 214 return true; … … 663 663 if (renderer->style().visibility() != VISIBLE) 664 664 return false; 665 if (renderer->visibleInViewportState() != RenderElement::VisibleInViewport&& !element.isPlaying())665 if (renderer->visibleInViewportState() != VisibleInViewportState::Yes && !element.isPlaying()) 666 666 return false; 667 667 -
trunk/Source/WebCore/loader/cache/CachedImage.cpp
r215900 r215952 240 240 } 241 241 242 bool CachedImage::usesImageContainerSize() const243 {244 if (m_image)245 return m_image->usesContainerSize();246 247 return false;248 }249 250 bool CachedImage::imageHasRelativeWidth() const251 {252 if (m_image)253 return m_image->hasRelativeWidth();254 255 return false;256 }257 258 bool CachedImage::imageHasRelativeHeight() const259 {260 if (m_image)261 return m_image->hasRelativeHeight();262 263 return false;264 }265 266 242 LayoutSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType) 267 243 { … … 367 343 } 368 344 369 void CachedImage::CachedImageObserver:: animationAdvanced(const Image* image)345 void CachedImage::CachedImageObserver::imageFrameAvailable(const Image* image, ImageAnimatingState animatingState, const IntRect* changeRect) 370 346 { 371 347 for (auto cachedImage : m_cachedImages) 372 cachedImage-> animationAdvanced(image);348 cachedImage->imageFrameAvailable(image, animatingState, changeRect); 373 349 } 374 350 … … 522 498 } 523 499 524 void CachedImage:: animationAdvanced(const Image* image)500 void CachedImage::imageFrameAvailable(const Image* image, ImageAnimatingState animatingState, const IntRect* changeRect) 525 501 { 526 502 if (!image || image != m_image) 527 503 return; 528 504 529 bool shouldPauseAnimation = true;530 531 505 CachedResourceClientWalker<CachedImageClient> clientWalker(m_clients); 506 VisibleInViewportState visibleState = VisibleInViewportState::No; 507 532 508 while (CachedImageClient* client = clientWalker.next()) { 533 bool canPause = false; 534 client->newImageAnimationFrameAvailable(*this, canPause); 535 if (!canPause) 536 shouldPauseAnimation = false; 537 } 538 539 if (shouldPauseAnimation) 509 if (client->imageFrameAvailable(*this, animatingState, changeRect) == VisibleInViewportState::Yes) 510 visibleState = VisibleInViewportState::Yes; 511 } 512 513 if (visibleState == VisibleInViewportState::No && animatingState == ImageAnimatingState::Yes) 540 514 m_image->stopAnimation(); 541 515 } -
trunk/Source/WebCore/loader/cache/CachedImage.h
r215900 r215952 65 65 66 66 void setContainerSizeForRenderer(const CachedImageClient*, const LayoutSize&, float); 67 bool usesImageContainerSize() const ;68 bool imageHasRelativeWidth() const ;69 bool imageHasRelativeHeight() const ;67 bool usesImageContainerSize() const { return m_image && m_image->usesContainerSize(); } 68 bool imageHasRelativeWidth() const { return m_image && m_image->hasRelativeWidth(); } 69 bool imageHasRelativeHeight() const { return m_image && m_image->hasRelativeHeight(); } 70 70 71 71 void addDataBuffer(SharedBuffer&) override; … … 132 132 void didDraw(const Image*) final; 133 133 134 void animationAdvanced(const Image*) final;134 void imageFrameAvailable(const Image*, ImageAnimatingState, const IntRect* changeRect = nullptr) final; 135 135 void changedInRect(const Image*, const IntRect*) final; 136 136 … … 140 140 void decodedSizeChanged(const Image*, long long delta); 141 141 void didDraw(const Image*); 142 void animationAdvanced(const Image*);142 void imageFrameAvailable(const Image*, ImageAnimatingState, const IntRect* changeRect = nullptr); 143 143 void changedInRect(const Image*, const IntRect*); 144 144 -
trunk/Source/WebCore/loader/cache/CachedImageClient.h
r215700 r215952 24 24 25 25 #include "CachedResourceClient.h" 26 #include "ImageTypes.h" 26 27 27 28 namespace WebCore { … … 29 30 class CachedImage; 30 31 class IntRect; 32 33 enum class VisibleInViewportState { Unknown, Yes, No }; 31 34 32 35 class CachedImageClient : public CachedResourceClient { … … 41 44 42 45 // Called when GIF animation progresses. 43 virtual void newImageAnimationFrameAvailable(CachedImage& image, bool& canPause) { imageChanged(&image); canPause = true; }46 virtual VisibleInViewportState imageFrameAvailable(CachedImage& image, ImageAnimatingState, const IntRect* changeRect) { imageChanged(&image, changeRect); return VisibleInViewportState::No; } 44 47 45 48 virtual void didRemoveCachedImageClient(CachedImage&) { } -
trunk/Source/WebCore/platform/graphics/BitmapImage.cpp
r215900 r215952 412 412 413 413 if (imageObserver()) 414 imageObserver()-> animationAdvanced(this);414 imageObserver()->imageFrameAvailable(this, ImageAnimatingState::Yes); 415 415 416 416 LOG(Images, "BitmapImage::%s - %p - url: %s [m_currentFrame = %ld]", __FUNCTION__, this, sourceURL().string().utf8().data(), m_currentFrame); … … 443 443 } 444 444 445 void BitmapImage:: newFrameNativeImageAvailableAtIndex(size_t index)445 void BitmapImage::imageFrameAvailableAtIndex(size_t index) 446 446 { 447 447 UNUSED_PARAM(index); … … 458 458 } else { 459 459 ASSERT(index == m_currentFrame && !m_currentFrame); 460 imageObserver()-> changedInRect(this, nullptr);460 imageObserver()->imageFrameAvailable(this, ImageAnimatingState::No); 461 461 462 462 if (m_source.isAsyncDecodingQueueIdle()) -
trunk/Source/WebCore/platform/graphics/BitmapImage.h
r215900 r215952 175 175 void stopAnimation() override; 176 176 void resetAnimation() override; 177 void newFrameNativeImageAvailableAtIndex(size_t) override;177 void imageFrameAvailableAtIndex(size_t) override; 178 178 179 179 // Handle platform-specific data -
trunk/Source/WebCore/platform/graphics/Image.h
r215710 r215952 134 134 virtual void stopAnimation() {} 135 135 virtual void resetAnimation() {} 136 virtual void newFrameNativeImageAvailableAtIndex(size_t) { }136 virtual void imageFrameAvailableAtIndex(size_t) { } 137 137 virtual bool isAnimating() const { return false; } 138 138 -
trunk/Source/WebCore/platform/graphics/ImageFrameCache.cpp
r215710 r215952 256 256 // Notify the image with the readiness of the new frame NativeImage. 257 257 if (m_image) 258 m_image-> newFrameNativeImageAvailableAtIndex(index);258 m_image->imageFrameAvailableAtIndex(index); 259 259 } 260 260 -
trunk/Source/WebCore/platform/graphics/ImageObserver.h
r215900 r215952 27 27 #define ImageObserver_h 28 28 29 #include "ImageTypes.h" 30 29 31 namespace WebCore { 30 32 … … 44 46 virtual void didDraw(const Image*) = 0; 45 47 46 virtual void animationAdvanced(const Image*) = 0;48 virtual void imageFrameAvailable(const Image*, ImageAnimatingState, const IntRect* changeRect = nullptr) = 0; 47 49 virtual void changedInRect(const Image*, const IntRect* changeRect = nullptr) = 0; 48 50 }; -
trunk/Source/WebCore/platform/graphics/ImageTypes.h
r215211 r215952 64 64 Ignored 65 65 }; 66 66 67 enum class ImageAnimatingState { Yes, No }; 68 67 69 enum class EncodedDataStatus { 68 70 Error, -
trunk/Source/WebCore/rendering/RenderElement.cpp
r215700 r215952 116 116 , m_renderBlockFlowLineLayoutPath(RenderBlockFlow::UndeterminedPath) 117 117 , m_isRegisteredForVisibleInViewportCallback(false) 118 , m_visibleInViewportState( VisibilityUnknown)118 , m_visibleInViewportState(static_cast<unsigned>(VisibleInViewportState::Unknown)) 119 119 , m_firstChild(nullptr) 120 120 , m_lastChild(nullptr) … … 1434 1434 } 1435 1435 1436 static bool shouldRepaintForImageAnimation(const RenderElement& renderer, const IntRect& visibleRect) 1437 { 1438 const Document& document = renderer.document(); 1439 if (document.activeDOMObjectsAreSuspended()) 1436 bool RenderElement::shouldRepaintInVisibleRect(const IntRect& visibleRect) const 1437 { 1438 if (document().activeDOMObjectsAreSuspended()) 1440 1439 return false; 1441 if ( renderer.style().visibility() != VISIBLE)1440 if (style().visibility() != VISIBLE) 1442 1441 return false; 1443 if ( renderer.view().frameView().isOffscreen())1442 if (view().frameView().isOffscreen()) 1444 1443 return false; 1445 1444 … … 1448 1447 // be propagated to the root. At this point, we unfortunately don't have access to the image anymore so we 1449 1448 // can no longer check if it is a background image. 1450 bool backgroundIsPaintedByRoot = renderer.isDocumentElementRenderer();1451 if ( renderer.isBody()) {1452 auto& rootRenderer = * renderer.parent(); // If <body> has a renderer then <html> does too.1449 bool backgroundIsPaintedByRoot = isDocumentElementRenderer(); 1450 if (isBody()) { 1451 auto& rootRenderer = *parent(); // If <body> has a renderer then <html> does too. 1453 1452 ASSERT(rootRenderer.isDocumentElementRenderer()); 1454 1453 ASSERT(is<HTMLHtmlElement>(rootRenderer.element())); … … 1457 1456 1458 1457 } 1459 LayoutRect backgroundPaintingRect = backgroundIsPaintedByRoot ? renderer.view().backgroundRect() : renderer.absoluteClippedOverflowRect(); 1458 1459 LayoutRect backgroundPaintingRect = backgroundIsPaintedByRoot ? view().backgroundRect() : absoluteClippedOverflowRect(); 1460 1460 if (!visibleRect.intersects(enclosingIntRect(backgroundPaintingRect))) 1461 1461 return false; … … 1484 1484 void RenderElement::setVisibleInViewportState(VisibleInViewportState state) 1485 1485 { 1486 if (state == m_visibleInViewportState)1487 return; 1488 m_visibleInViewportState = stat e;1486 if (state == visibleInViewportState()) 1487 return; 1488 m_visibleInViewportState = static_cast<unsigned>(state); 1489 1489 visibleInViewportStateChanged(); 1490 1490 } … … 1495 1495 } 1496 1496 1497 void RenderElement::newImageAnimationFrameAvailable(CachedImage& image, bool& canPause)1497 VisibleInViewportState RenderElement::imageFrameAvailable(CachedImage& image, ImageAnimatingState animatingState, const IntRect* changeRect) 1498 1498 { 1499 1499 auto& frameView = view().frameView(); 1500 1500 auto visibleRect = frameView.windowToContents(frameView.windowClipRect()); 1501 if (!shouldRepaintForImageAnimation(*this, visibleRect)) { 1501 bool shouldRepaint = shouldRepaintInVisibleRect(visibleRect); 1502 1503 if (!shouldRepaint && animatingState == ImageAnimatingState::Yes) 1502 1504 view().addRendererWithPausedImageAnimations(*this, image); 1503 canPause = true; 1504 return; 1505 } 1506 imageChanged(&image); 1505 1506 // Static images should repaint even if they are outside the viewport rectangle 1507 // because they should be inside the TileCoverageRect. 1508 if (shouldRepaint || animatingState == ImageAnimatingState::No) 1509 imageChanged(&image, changeRect); 1510 1511 return shouldRepaint ? VisibleInViewportState::Yes : VisibleInViewportState::No; 1507 1512 } 1508 1513 … … 1516 1521 { 1517 1522 ASSERT(m_hasPausedImageAnimations); 1518 if (!shouldRepaint ForImageAnimation(*this,visibleRect))1523 if (!shouldRepaintInVisibleRect(visibleRect)) 1519 1524 return false; 1520 1525 -
trunk/Source/WebCore/rendering/RenderElement.h
r215700 r215952 139 139 bool borderImageIsLoadedAndCanBeRendered() const; 140 140 bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const; 141 bool shouldRepaintInVisibleRect(const IntRect& visibleRect) const; 141 142 142 143 // Returns true if this renderer requires a new stacking context. … … 188 189 void unregisterForVisibleInViewportCallback(); 189 190 190 enum VisibleInViewportState {191 VisibilityUnknown,192 VisibleInViewport,193 NotVisibleInViewport,194 };195 191 VisibleInViewportState visibleInViewportState() const { return static_cast<VisibleInViewportState>(m_visibleInViewportState); } 196 192 void setVisibleInViewportState(VisibleInViewportState); … … 319 315 void invalidateCachedFirstLineStyle(); 320 316 321 void newImageAnimationFrameAvailable(CachedImage&, bool& canPause) final;317 VisibleInViewportState imageFrameAvailable(CachedImage&, ImageAnimatingState, const IntRect* changeRect) final; 322 318 void didRemoveCachedImageClient(CachedImage&) final; 323 319 -
trunk/Source/WebCore/rendering/RenderView.cpp
r215160 r215952 1391 1391 1392 1392 for (auto* renderer : m_visibleInViewportRenderers) { 1393 auto state = visibleRect.intersects(enclosingIntRect(renderer->absoluteClippedOverflowRect())) ? RenderElement::VisibleInViewport : RenderElement::NotVisibleInViewport;1393 auto state = visibleRect.intersects(enclosingIntRect(renderer->absoluteClippedOverflowRect())) ? VisibleInViewportState::Yes : VisibleInViewportState::No; 1394 1394 renderer->setVisibleInViewportState(state); 1395 1395 } -
trunk/Source/WebCore/svg/graphics/SVGImageClients.h
r214503 r215952 53 53 void invalidateContentsAndRootView(const IntRect& r) final 54 54 { 55 // If m_image->m_page is null, we're being destr ucted, don't fire changedInRect() in that case.55 // If m_image->m_page is null, we're being destroyed. 56 56 if (!m_image || !m_image->m_page) 57 57 return; … … 61 61 return; 62 62 63 if (m_image->isAnimating()) 64 imageObserver->animationAdvanced(m_image); 65 else 66 imageObserver->changedInRect(m_image, &r); 63 imageObserver->imageFrameAvailable(m_image, m_image->isAnimating() ? ImageAnimatingState::Yes : ImageAnimatingState::No, &r); 67 64 } 68 65
Note: See TracChangeset
for help on using the changeset viewer.