Changeset 196803 in webkit
- Timestamp:
- Feb 18, 2016 11:27:28 PM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r196802 r196803 1 2016-02-18 Gwang Yoon Hwang <yoon@igalia.com> 2 3 [GTK] Limit the number of tiles according to the visible area 4 https://bugs.webkit.org/show_bug.cgi?id=126122 5 6 Reviewed by Carlos Garcia Campos. 7 8 TextureMapperTiledBackingStore creates tiles for whole layer bounds, which 9 means it creates the huge amount of textures if there is an excessively big 10 layer. Not only it wastes the memory and the CPU time, it even can crash GPU 11 drivers. 12 13 This patch modifies TextureMapperTiledBackingStore to take into account the 14 visible area with a coverage multiplier when creating tiles. 15 16 * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp: 17 (WebCore::GraphicsLayerTextureMapper::GraphicsLayerTextureMapper): 18 Set a flag to recalculate the visible area of the layer when there are 19 geometric changes. 20 (WebCore::GraphicsLayerTextureMapper::setContentsToImage): 21 (WebCore::GraphicsLayerTextureMapper::flushCompositingStateForThisLayerOnly): 22 (WebCore::GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers): 23 (WebCore::GraphicsLayerTextureMapper::updateBackingStoreIfNeeded): 24 (WebCore::GraphicsLayerTextureMapper::markVisibleRectAsDirty): 25 (WebCore::GraphicsLayerTextureMapper::selfOrAncestorHasActiveTransformAnimation): 26 (WebCore::GraphicsLayerTextureMapper::computeTransformedVisibleRect): 27 Compute the inverse transform matrix to map a global visible are to 28 the local visible area. 29 (WebCore::clampToContentsRectIfRectIsInfinite): 30 (WebCore::GraphicsLayerTextureMapper::transformedVisibleRect): 31 * platform/graphics/texmap/TextureMapperTiledBackingStore.cpp: 32 (WebCore::TextureMapperTiledBackingStore::paintToTextureMapper): 33 In HiDPI, the directly composited image is uploaded to the unscaled 34 texture to reduce memory usages. So we should apply device scale 35 factor to render it correctly. 36 (WebCore::TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded): 37 Create tiles which covered by visible rect with a coverage multiplier. 38 1 39 2016-02-18 Brent Fulgham <bfulgham@apple.com> 2 40 -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
r194445 r196803 49 49 , m_animationStartTime(0) 50 50 , m_isScrollable(false) 51 , m_isNonCompositingLayer(false) 52 , m_isVisibleRectDirty(true) 51 53 { 52 54 } … … 168 170 GraphicsLayer::setPosition(value); 169 171 notifyChange(PositionChange); 172 markVisibleRectAsDirty(); 170 173 } 171 174 … … 176 179 GraphicsLayer::setAnchorPoint(value); 177 180 notifyChange(AnchorPointChange); 181 markVisibleRectAsDirty(); 178 182 } 179 183 … … 187 191 maskLayer()->setSize(value); 188 192 notifyChange(SizeChange); 193 markVisibleRectAsDirty(); 189 194 } 190 195 … … 196 201 GraphicsLayer::setTransform(value); 197 202 notifyChange(TransformChange); 203 markVisibleRectAsDirty(); 198 204 } 199 205 … … 204 210 GraphicsLayer::setChildrenTransform(value); 205 211 notifyChange(ChildrenTransformChange); 212 markVisibleRectAsDirty(); 206 213 } 207 214 … … 212 219 GraphicsLayer::setPreserves3D(value); 213 220 notifyChange(Preserves3DChange); 221 markVisibleRectAsDirty(); 214 222 } 215 223 … … 220 228 GraphicsLayer::setMasksToBounds(value); 221 229 notifyChange(MasksToBoundsChange); 230 markVisibleRectAsDirty(); 222 231 } 223 232 … … 302 311 m_compositedImage->setContentsToImage(image); 303 312 m_compositedImage->updateContentsScale(pageScaleFactor() * deviceScaleFactor()); 313 m_compositedImage->updateContentsSize(image->size()); 304 314 } else { 305 315 m_compositedNativeImagePtr = nullptr; … … 370 380 commitLayerChanges(); 371 381 m_layer.syncAnimations(); 382 if (!m_isNonCompositingLayer) 383 computeTransformedVisibleRect(); 372 384 } 373 385 … … 513 525 } 514 526 515 void GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers( )527 void GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers(const FloatRect& visibleContentRect) 516 528 { 517 529 if (!m_layer.textureMapper()) 518 530 return; 519 531 520 updateBackingStoreIfNeeded( );532 updateBackingStoreIfNeeded(visibleContentRect); 521 533 522 534 if (maskLayer()) 523 downcast<GraphicsLayerTextureMapper>(*maskLayer()).updateBackingStoreIfNeeded( );535 downcast<GraphicsLayerTextureMapper>(*maskLayer()).updateBackingStoreIfNeeded(visibleContentRect); 524 536 if (replicaLayer()) 525 downcast<GraphicsLayerTextureMapper>(*replicaLayer()).updateBackingStoreIfNeeded( );537 downcast<GraphicsLayerTextureMapper>(*replicaLayer()).updateBackingStoreIfNeeded(visibleContentRect); 526 538 for (auto* child : children()) 527 downcast<GraphicsLayerTextureMapper>(*child).updateBackingStoreIncludingSubLayers( );528 } 529 530 void GraphicsLayerTextureMapper::updateBackingStoreIfNeeded( )539 downcast<GraphicsLayerTextureMapper>(*child).updateBackingStoreIncludingSubLayers(visibleContentRect); 540 } 541 542 void GraphicsLayerTextureMapper::updateBackingStoreIfNeeded(const FloatRect& visibleContentRect) 531 543 { 532 544 TextureMapper* textureMapper = m_layer.textureMapper(); … … 548 560 TextureMapperTiledBackingStore* backingStore = static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get()); 549 561 backingStore->updateContentsScale(pageScaleFactor() * deviceScaleFactor()); 562 backingStore->updateContentsSize(m_size); 550 563 551 564 dirtyRect.scale(pageScaleFactor() * deviceScaleFactor()); 552 backingStore->updateContents(*textureMapper, this, m_size, dirtyRect, BitmapTexture::UpdateCanModifyOriginalImageData);565 backingStore->updateContents(*textureMapper, this, transformedVisibleRect(visibleContentRect), dirtyRect, BitmapTexture::UpdateCanModifyOriginalImageData); 553 566 554 567 m_needsDisplay = false; … … 627 640 } 628 641 642 void GraphicsLayerTextureMapper::markVisibleRectAsDirty() 643 { 644 m_isVisibleRectDirty = true; 645 646 if (maskLayer()) 647 downcast<GraphicsLayerTextureMapper>(*maskLayer()).markVisibleRectAsDirty(); 648 if (replicaLayer()) 649 downcast<GraphicsLayerTextureMapper>(*replicaLayer()).markVisibleRectAsDirty(); 650 for (auto* child : children()) 651 downcast<GraphicsLayerTextureMapper>(*child).markVisibleRectAsDirty(); 652 } 653 654 bool GraphicsLayerTextureMapper::selfOrAncestorHasActiveTransformAnimation() const 655 { 656 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyTransform)) 657 return true; 658 659 if (!parent()) 660 return false; 661 662 return downcast<GraphicsLayerTextureMapper>(*parent()).selfOrAncestorHasActiveTransformAnimation(); 663 } 664 665 void GraphicsLayerTextureMapper::computeTransformedVisibleRect() 666 { 667 if (!m_isVisibleRectDirty && !selfOrAncestorHasActiveTransformAnimation()) 668 return; 669 670 m_isVisibleRectDirty = false; 671 TransformationMatrix currentTransform = transform(); 672 if (selfOrAncestorHasActiveTransformAnimation()) 673 client().getCurrentTransform(this, currentTransform); 674 m_layerTransform.setLocalTransform(currentTransform); 675 676 m_layerTransform.setAnchorPoint(m_anchorPoint); 677 m_layerTransform.setPosition(m_position); 678 m_layerTransform.setSize(m_size); 679 680 m_layerTransform.setFlattening(!preserves3D()); 681 m_layerTransform.setChildrenTransform(childrenTransform()); 682 m_layerTransform.combineTransforms(parent() ? downcast<GraphicsLayerTextureMapper>(*parent()).m_layerTransform.combinedForChildren() : TransformationMatrix()); 683 684 m_cachedInverseTransform = m_layerTransform.combined().inverse().valueOr(TransformationMatrix()); 685 } 686 687 static void clampToContentsRectIfRectIsInfinite(FloatRect& rect, const FloatSize& contentsSize) 688 { 689 if (rect.width() >= LayoutUnit::nearlyMax() || rect.width() <= LayoutUnit::nearlyMin()) { 690 rect.setX(0); 691 rect.setWidth(contentsSize.width()); 692 } 693 694 if (rect.height() >= LayoutUnit::nearlyMax() || rect.height() <= LayoutUnit::nearlyMin()) { 695 rect.setY(0); 696 rect.setHeight(contentsSize.height()); 697 } 698 } 699 700 FloatRect GraphicsLayerTextureMapper::transformedVisibleRect(const FloatRect& visibleContentRect) 701 { 702 if (m_isNonCompositingLayer) 703 return FloatRect(FloatPoint::zero(), m_size); 704 705 // Non-invertible layers are not visible. 706 if (!m_layerTransform.combined().isInvertible()) 707 return IntRect(); 708 709 // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates). 710 // The resulting quad might be squewed and the visible rect is the bounding box of this quad, 711 // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier). 712 ASSERT(m_cachedInverseTransform == m_layerTransform.combined().inverse().valueOr(TransformationMatrix())); 713 FloatRect rect = m_cachedInverseTransform.clampedBoundsOfProjectedQuad(FloatQuad(visibleContentRect)); 714 clampToContentsRectIfRectIsInfinite(rect, size()); 715 return rect; 716 } 717 629 718 } 630 719 #endif -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
r193630 r196803 87 87 virtual void flushCompositingStateForThisLayerOnly(bool) override; 88 88 89 void updateBackingStoreIncludingSubLayers( );89 void updateBackingStoreIncludingSubLayers(const FloatRect&); 90 90 91 91 TextureMapperLayer& layer() { return m_layer; } … … 103 103 104 104 void setAnimations(const TextureMapperAnimations&); 105 void setAsNonCompositingLayer() { m_isNonCompositingLayer = true; } 105 106 106 107 private: … … 114 115 void commitLayerChanges(); 115 116 void updateDebugBorderAndRepaintCount(); 116 void updateBackingStoreIfNeeded( );117 void updateBackingStoreIfNeeded(const FloatRect&); 117 118 void prepareBackingStoreIfNeeded(); 118 119 bool shouldHaveBackingStore() const; 120 121 bool selfOrAncestorHasActiveTransformAnimation() const; 122 void computeTransformedVisibleRect(); 123 void markVisibleRectAsDirty(); 124 FloatRect transformedVisibleRect(const FloatRect&); 119 125 120 126 // This set of flags help us defer which properties of the layer have been … … 183 189 IntSize m_committedScrollOffset; 184 190 bool m_isScrollable; 191 192 bool m_isNonCompositingLayer; 193 bool m_isVisibleRectDirty; 194 GraphicsLayerTransform m_layerTransform; 195 TransformationMatrix m_cachedInverseTransform; 185 196 }; 186 197 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp
r194103 r196803 36 36 return; 37 37 38 updateContents(textureMapper, m_image.get(), m_image-> size(), enclosingIntRect(m_image->rect()), BitmapTexture::UpdateCannotModifyOriginalImageData);38 updateContents(textureMapper, m_image.get(), m_image->rect(), enclosingIntRect(m_image->rect()), BitmapTexture::UpdateCannotModifyOriginalImageData); 39 39 40 40 if (m_image->imageObserver()) … … 45 45 TransformationMatrix TextureMapperTiledBackingStore::adjustedTransformForRect(const FloatRect& targetRect) 46 46 { 47 return TransformationMatrix::rectToRect(rect(), targetRect); 47 FloatRect scaledContentsRect(FloatPoint::zero(), m_contentsSize); 48 scaledContentsRect.scale(m_contentsScale); 49 return TransformationMatrix::rectToRect(scaledContentsRect, targetRect); 48 50 } 49 51 50 52 void TextureMapperTiledBackingStore::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& transform, float opacity) 51 53 { 54 FloatRect scaledTargetRect(targetRect); 55 if (m_image) 56 scaledTargetRect.scale(m_contentsScale); 57 52 58 updateContentsFromImageIfNeeded(textureMapper); 53 TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect); 54 for (auto& tile : m_tiles) 55 tile.paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(rect(), tile.rect())); 59 TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(scaledTargetRect); 60 FloatRect scaledContentsRect(FloatPoint::zero(), m_contentsSize); 61 scaledContentsRect.scale(m_contentsScale); 62 for (auto& tile : m_tiles) 63 tile.paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(scaledContentsRect, tile.rect())); 56 64 } 57 65 … … 79 87 } 80 88 81 void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSize& size, const IntSize& tileSize, bool hasAlpha) 82 { 83 if (size == m_size && !m_isScaleDirty) 84 return; 85 86 m_size = size; 89 void TextureMapperTiledBackingStore::updateContentsSize(const FloatSize& size) 90 { 91 if (m_contentsSize == size) 92 return; 93 94 m_isSizeDirty = true; 95 m_contentsSize = size; 96 } 97 98 void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatRect& visibleRect, const IntSize& tileSize, bool hasAlpha) 99 { 100 if (visibleRect == m_visibleRect && !m_isScaleDirty && !m_isSizeDirty) 101 return; 102 103 m_visibleRect = visibleRect; 87 104 m_isScaleDirty = false; 88 89 FloatSize scaledSize(m_size); 90 if (!m_image) 91 scaledSize.scale(m_contentsScale); 105 m_isSizeDirty = false; 106 107 FloatRect scaledContentsRect(FloatRect(FloatPoint::zero(), m_contentsSize)); 108 FloatRect scaledVisibleRect(m_visibleRect); 109 110 static const float coverRectMultiplier = 1.2; 111 FloatPoint delta(scaledVisibleRect.center()); 112 delta.scale(1 - coverRectMultiplier, 1 - coverRectMultiplier); 113 114 scaledVisibleRect.scale(coverRectMultiplier); 115 scaledVisibleRect.moveBy(delta); 116 if (!m_image) { 117 scaledContentsRect.scale(m_contentsScale); 118 scaledVisibleRect.scale(m_contentsScale); 119 } 92 120 93 121 Vector<FloatRect> tileRectsToAdd; … … 97 125 // This method recycles tiles. We check which tiles we need to add, which to remove, and use as many 98 126 // removable tiles as replacement for new tiles when possible. 99 for (float y = 0; y < scaled Size.height(); y += tileSize.height()) {100 for (float x = 0; x < scaled Size.width(); x += tileSize.width()) {127 for (float y = 0; y < scaledContentsRect.height(); y += tileSize.height()) { 128 for (float x = 0; x < scaledContentsRect.width(); x += tileSize.width()) { 101 129 FloatRect tileRect(x, y, tileSize.width(), tileSize.height()); 102 tileRect.intersect(rect()); 103 tileRectsToAdd.append(tileRect); 130 tileRect.intersect(scaledContentsRect); 131 if (tileRect.intersects(scaledVisibleRect)) 132 tileRectsToAdd.append(tileRect); 104 133 } 105 134 } … … 151 180 } 152 181 153 void TextureMapperTiledBackingStore::updateContents(TextureMapper& textureMapper, Image* image, const Float Size& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag)154 { 155 createOrDestroyTilesIfNeeded( totalSize, textureMapper.maxTextureSize(), !image->currentFrameKnownToBeOpaque());182 void TextureMapperTiledBackingStore::updateContents(TextureMapper& textureMapper, Image* image, const FloatRect& visibleRect, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag) 183 { 184 createOrDestroyTilesIfNeeded(visibleRect, textureMapper.maxTextureSize(), !image->currentFrameKnownToBeOpaque()); 156 185 for (auto& tile : m_tiles) 157 186 tile.updateContents(textureMapper, image, dirtyRect, updateContentsFlag); 158 187 } 159 188 160 void TextureMapperTiledBackingStore::updateContents(TextureMapper& textureMapper, GraphicsLayer* sourceLayer, const Float Size& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag)161 { 162 createOrDestroyTilesIfNeeded( totalSize, textureMapper.maxTextureSize(), true);189 void TextureMapperTiledBackingStore::updateContents(TextureMapper& textureMapper, GraphicsLayer* sourceLayer, const FloatRect& visibleRect, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag) 190 { 191 createOrDestroyTilesIfNeeded(visibleRect, textureMapper.maxTextureSize(), true); 163 192 for (auto& tile : m_tiles) 164 193 tile.updateContents(textureMapper, sourceLayer, dirtyRect, updateContentsFlag, m_contentsScale); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.h
r194103 r196803 44 44 45 45 void updateContentsScale(float); 46 void updateContents(TextureMapper&, Image*, const FloatSize&, const IntRect&, BitmapTexture::UpdateContentsFlag); 47 void updateContents(TextureMapper&, GraphicsLayer*, const FloatSize&, const IntRect&, BitmapTexture::UpdateContentsFlag); 46 void updateContentsSize(const FloatSize&); 47 48 void updateContents(TextureMapper&, Image*, const FloatRect& visibleRect, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag); 49 void updateContents(TextureMapper&, GraphicsLayer*, const FloatRect& visibleRect, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag); 48 50 49 51 void setContentsToImage(Image* image) { m_image = image; } … … 52 54 TextureMapperTiledBackingStore() { } 53 55 54 void createOrDestroyTilesIfNeeded(const Float Size& backingStoreSize, const IntSize& tileSize, bool hasAlpha);56 void createOrDestroyTilesIfNeeded(const FloatRect& visibleRect, const IntSize& tileSize, bool hasAlpha); 55 57 void updateContentsFromImageIfNeeded(TextureMapper&); 56 58 TransformationMatrix adjustedTransformForRect(const FloatRect&); 57 inline FloatRect rect() const58 {59 FloatRect rect(FloatPoint::zero(), m_size);60 rect.scale(m_contentsScale);61 return rect;62 }63 59 64 60 Vector<TextureMapperTile> m_tiles; 65 FloatSize m_size; 61 FloatSize m_contentsSize; 62 FloatRect m_visibleRect; 63 FloatRect m_scaledvisibleRect; 66 64 RefPtr<Image> m_image; 67 65 float m_contentsScale { 1 }; 68 66 bool m_isScaleDirty { false }; 67 bool m_isSizeDirty { false }; 69 68 }; 70 69 -
trunk/Source/WebKit2/ChangeLog
r196786 r196803 1 2016-02-18 Gwang Yoon Hwang <yoon@igalia.com> 2 3 [GTK] Limit the number of tiles according to the visible area 4 https://bugs.webkit.org/show_bug.cgi?id=126122 5 6 Reviewed by Carlos Garcia Campos. 7 8 * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp: 9 (WebKit::LayerTreeHostGtk::initialize): Because we creates 10 nonCompositingLayer with a size of current view, we should not apply 11 the currently visible rect when creating / deleting tiles. 12 (WebKit::LayerTreeHostGtk::flushPendingLayerChanges): Passes the current 13 visible rect to the GraphicsLayers. 14 1 15 2016-02-18 Brady Eidson <beidson@apple.com> 2 16 -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp
r194496 r196803 173 173 // The non-composited contents are a child of the root layer. 174 174 m_nonCompositedContentLayer = GraphicsLayer::create(graphicsLayerFactory(), *this); 175 downcast<GraphicsLayerTextureMapper>(*m_nonCompositedContentLayer).setAsNonCompositingLayer(); 175 176 m_nonCompositedContentLayer->setDrawsContent(true); 176 177 m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground()); … … 323 324 m_viewOverlayRootLayer->flushCompositingState(FloatRect(FloatPoint(), m_rootLayer->size()), viewportIsStable); 324 325 325 downcast<GraphicsLayerTextureMapper>(*m_rootLayer).updateBackingStoreIncludingSubLayers(); 326 FloatRect visibleRect(m_webPage->mainFrame()->view()->scrollPosition(), m_webPage->size()); 327 downcast<GraphicsLayerTextureMapper>(*m_rootLayer).updateBackingStoreIncludingSubLayers(visibleRect); 326 328 return true; 327 329 }
Note: See TracChangeset
for help on using the changeset viewer.