diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp index 99aaf0ca83f1..54a87e082cad 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp @@ -1356,11 +1356,6 @@ void TextureMapper::setDepthRange(double zNear, double zFar) updateProjectionMatrix(); } -std::pair TextureMapper::depthRange() const -{ - return { data().zNear, data().zFar }; -} - void TextureMapper::updateProjectionMatrix() { bool flipY; diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.h b/Source/WebCore/platform/graphics/texmap/TextureMapper.h index d6f19150fd93..f8e2d24e7f1c 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapper.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.h @@ -82,7 +82,6 @@ class TextureMapper { IntRect clipBounds(); IntSize maxTextureSize() const; void setDepthRange(double zNear, double zFar); - std::pair depthRange() const; void setMaskMode(bool m) { m_isMaskMode = m; } void setWrapMode(WrapMode m) { m_wrapMode = m; } void setPatternTransform(const TransformationMatrix& p) { m_patternTransform = p; } diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp index 39c184daa8ae..fa52dbaadb83 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp @@ -61,89 +61,6 @@ struct TextureMapperLayer::ComputeTransformData { } }; -class TextureMapperFlattenedLayer final { - WTF_MAKE_FAST_ALLOCATED; -public: - explicit TextureMapperFlattenedLayer(const IntRect& rect, double zNear, double zFar) - : m_rect(rect) - , m_zNear(zNear) - , m_zFar(zFar) - { } - - IntRect layerRect() const { return m_rect; } - - bool needsUpdate() const { return m_needsUpdate; } - - void update(TextureMapperPaintOptions& options, const std::function& paintFunction) - { - if (!m_needsUpdate) - return; - - auto [prevZNear, prevZFar] = options.textureMapper.depthRange(); - options.textureMapper.setDepthRange(m_zNear, m_zFar); - - m_textures.clear(); - - auto maxTextureSize = options.textureMapper.maxTextureSize(); - forEachTile(maxTextureSize, [&](const IntRect& tileRect) { - RefPtr surface = options.textureMapper.acquireTextureFromPool(tileRect.size(), { BitmapTexture::Flags::SupportsAlpha }); - { - SetForScope scopedSurface(options.surface, surface); - SetForScope scopedOffset(options.offset, -toIntSize(tileRect.location())); - SetForScope scopedOpacity(options.opacity, 1); - - options.textureMapper.bindSurface(options.surface.get()); - - paintFunction(options); - - // If paintFunction applies filters to flattened surface then surface object might have - // changed to new intermediate filter surface and it needs to be stored for painting. - ASSERT(options.surface); - surface = options.surface; - } - m_textures.append(WTFMove(surface)); - }); - - options.textureMapper.bindSurface(options.surface.get()); - options.textureMapper.setDepthRange(prevZNear, prevZFar); - - m_needsUpdate = false; - } - - void paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, TransformationMatrix& modelViewMatrix, float opacity) - { - auto maxTextureSize = textureMapper.maxTextureSize(); - auto allEdgesExposed = m_rect.width() <= maxTextureSize.width() && m_rect.height() <= maxTextureSize.height() - ? TextureMapper::AllEdgesExposed::Yes - : TextureMapper::AllEdgesExposed::No; - TransformationMatrix adjustedTransform = modelViewMatrix * TransformationMatrix::rectToRect(m_rect, targetRect); - - size_t textureIndex = 0; - forEachTile(maxTextureSize, [&](const IntRect& tileRect) { - ASSERT(textureIndex < m_textures.size()); - textureMapper.drawTexture(*m_textures[textureIndex++], tileRect, adjustedTransform, opacity, allEdgesExposed); - }); - } - -private: - void forEachTile(const IntSize& maxTextureSize, const std::function& tileAction) - { - for (int x = m_rect.x(); x < m_rect.maxX(); x += maxTextureSize.width()) { - for (int y = m_rect.y(); y < m_rect.maxY(); y += maxTextureSize.height()) { - IntRect tileRect({ x, y }, maxTextureSize); - tileRect.intersect(m_rect); - tileAction(tileRect); - } - } - } - - IntRect m_rect; - double m_zNear; - double m_zFar; - Vector> m_textures; - bool m_needsUpdate { true }; -}; - TextureMapperLayer::TextureMapperLayer(Damage::ShouldPropagate propagateDamage) : m_propagateDamage(propagateDamage) { @@ -157,89 +74,6 @@ TextureMapperLayer::~TextureMapperLayer() removeFromParent(); } -void TextureMapperLayer::processDescendantLayersFlatteningRequirements() -{ - // Traverse all children in depth first, post-order - for (auto* child : m_children) { - child->processDescendantLayersFlatteningRequirements(); - - if (child->flattensAsLeafOf3DSceneOr3DPerspective()) - child->processFlatteningRequirements(); - } -} - -void TextureMapperLayer::processFlatteningRequirements() -{ - m_flattenedLayer = nullptr; - - // Reset transformations as this layer is root 2D - SetForScope scopedLocalTransform(m_layerTransforms.localTransform, TransformationMatrix::identity); - m_layerTransforms.combined = { }; - m_layerTransforms.combinedForChildren = { }; -#if USE(COORDINATED_GRAPHICS) - SetForScope scopedFutureLocalTransform(m_layerTransforms.futureLocalTransform, TransformationMatrix::identity); - m_layerTransforms.futureLocalTransform = { }; - m_layerTransforms.futureCombined = { }; - m_layerTransforms.futureCombinedForChildren = { }; -#endif - ComputeTransformData data; - if (m_state.maskLayer) - m_state.maskLayer->computeTransformsRecursive(data); - if (m_state.replicaLayer) - m_state.replicaLayer->computeTransformsRecursive(data); - if (m_state.backdropLayer) - m_state.backdropLayer->computeTransformsRecursive(data); - for (auto* child : m_children) - child->computeTransformsRecursive(data); - - Region layerRegion; - computeFlattenedRegion(layerRegion, true); - - if (layerRegion.isEmpty()) - return; - - m_flattenedLayer = makeUnique(layerRegion.bounds(), data.zNear, data.zFar); -} - -void TextureMapperLayer::computeFlattenedRegion(Region& region, bool layerIsFlatteningRoot) -{ - auto rect = isFlattened() ? m_flattenedLayer->layerRect() : layerRect(); - - bool shouldExpand = m_currentFilters.hasOutsets() && !m_state.masksToBounds && !m_state.maskLayer; - if (shouldExpand && !layerIsFlatteningRoot) { - auto outsets = m_currentFilters.outsets(); - rect.move(-outsets.left(), -outsets.top()); - rect.expand(outsets.left() + outsets.right(), outsets.top() + outsets.bottom()); - } - - region.unite(enclosingIntRect(m_layerTransforms.combined.mapRect(rect))); - - if (!m_state.masksToBounds && !m_state.maskLayer) { - if (m_state.replicaLayer) - region.unite(enclosingIntRect(m_state.replicaLayer->m_layerTransforms.combined.mapRect(m_state.replicaLayer->layerRect()))); - - for (auto* child : m_children) - child->computeFlattenedRegion(region, false); - } - - if (shouldExpand && layerIsFlatteningRoot) { - auto bounds = region.bounds(); - auto outsets = m_currentFilters.outsets(); - bounds.move(-outsets.left(), -outsets.top()); - bounds.expand(outsets.left() + outsets.right(), outsets.top() + outsets.bottom()); - region = bounds; - } -} - -void TextureMapperLayer::destroyFlattenedDescendantLayers() -{ - if (m_flattenedLayer) - m_flattenedLayer = nullptr; - - for (auto* child : m_children) - child->destroyFlattenedDescendantLayers(); -} - void TextureMapperLayer::computeTransformsRecursive(ComputeTransformData& data) { if (m_state.size.isEmpty() && m_state.masksToBounds) @@ -268,7 +102,7 @@ void TextureMapperLayer::computeTransformsRecursive(ComputeTransformData& data) m_layerTransforms.combined.translate(-m_state.pos.x(), -m_state.pos.y()); if (!m_state.preserves3D) - m_layerTransforms.combinedForChildren.flatten(); + m_layerTransforms.combinedForChildren = m_layerTransforms.combinedForChildren.to2dTransform(); m_layerTransforms.combinedForChildren.multiply(m_state.childrenTransform); m_layerTransforms.combinedForChildren.translate3d(-originX, -originY, -m_state.anchorPoint.z()); @@ -289,7 +123,7 @@ void TextureMapperLayer::computeTransformsRecursive(ComputeTransformData& data) m_layerTransforms.futureCombined.translate3d(-originX, -originY, -m_state.anchorPoint.z()); if (!m_state.preserves3D) - m_layerTransforms.futureCombinedForChildren.flatten(); + m_layerTransforms.futureCombinedForChildren = m_layerTransforms.futureCombinedForChildren.to2dTransform(); m_layerTransforms.futureCombinedForChildren.multiply(m_state.childrenTransform); m_layerTransforms.futureCombinedForChildren.translate3d(-originX, -originY, -m_state.anchorPoint.z()); #endif @@ -311,28 +145,23 @@ void TextureMapperLayer::computeTransformsRecursive(ComputeTransformData& data) return z / w; }; - auto rect = isFlattened() ? m_flattenedLayer->layerRect() : layerRect(); - - data.updateDepthRange(calculateZ(rect.x(), rect.y())); - data.updateDepthRange(calculateZ(rect.x() + rect.width(), rect.y())); - data.updateDepthRange(calculateZ(rect.x(), rect.y() + rect.height())); - data.updateDepthRange(calculateZ(rect.x() + rect.width(), rect.y() + rect.height())); + data.updateDepthRange(calculateZ(0, 0)); + data.updateDepthRange(calculateZ(m_state.size.width(), 0)); + data.updateDepthRange(calculateZ(0, m_state.size.height())); + data.updateDepthRange(calculateZ(m_state.size.width(), m_state.size.height())); if (m_parent && m_parent->m_state.preserves3D) - m_centerZ = calculateZ(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2); + m_centerZ = calculateZ(m_state.size.width() / 2, m_state.size.height() / 2); + if (m_state.maskLayer) + m_state.maskLayer->computeTransformsRecursive(data); + if (m_state.replicaLayer) + m_state.replicaLayer->computeTransformsRecursive(data); if (m_state.backdropLayer) m_state.backdropLayer->computeTransformsRecursive(data); - - if (!isFlattened()) { - if (m_state.maskLayer) - m_state.maskLayer->computeTransformsRecursive(data); - if (m_state.replicaLayer) - m_state.replicaLayer->computeTransformsRecursive(data); - for (auto* child : m_children) { - ASSERT(child->m_parent == this); - child->computeTransformsRecursive(data); - } + for (auto* child : m_children) { + ASSERT(child->m_parent == this); + child->computeTransformsRecursive(data); } // Reorder children if needed on the way back up. @@ -347,8 +176,6 @@ void TextureMapperLayer::computeTransformsRecursive(ComputeTransformData& data) void TextureMapperLayer::paint(TextureMapper& textureMapper) { - processDescendantLayersFlatteningRequirements(); - ComputeTransformData data; computeTransformsRecursive(data); textureMapper.setDepthRange(data.zNear, data.zFar); @@ -356,8 +183,6 @@ void TextureMapperLayer::paint(TextureMapper& textureMapper) TextureMapperPaintOptions options(textureMapper); options.surface = textureMapper.currentSurface(); paintRecursive(options); - - destroyFlattenedDescendantLayers(); } void TextureMapperLayer::paintSelf(TextureMapperPaintOptions& options) @@ -374,11 +199,6 @@ void TextureMapperLayer::paintSelf(TextureMapperPaintOptions& options) transform.multiply(options.transform); transform.multiply(m_layerTransforms.combined); - if (isFlattened() && !m_flattenedLayer->needsUpdate()) { - m_flattenedLayer->paintToTextureMapper(options.textureMapper, m_flattenedLayer->layerRect(), transform, options.opacity); - return; - } - TextureMapperSolidColorLayer solidColorLayer; TextureMapperBackingStore* backingStore = m_backingStore; if (m_state.backgroundColor.isValid()) { @@ -488,24 +308,20 @@ void TextureMapperLayer::sortByZOrder(Vector& array) }); } -void TextureMapperLayer::paintBackdrop(TextureMapperPaintOptions& options) -{ - TransformationMatrix clipTransform; - clipTransform.translate(options.offset.width(), options.offset.height()); - clipTransform.multiply(options.transform); - clipTransform.multiply(m_layerTransforms.combined); - options.textureMapper.beginClip(clipTransform, m_state.backdropFiltersRect); - m_state.backdropLayer->paintRecursive(options); - options.textureMapper.endClip(); -} - void TextureMapperLayer::paintSelfAndChildren(TextureMapperPaintOptions& options) { if (m_state.backdropLayer && m_state.backdropLayer == options.backdropLayer) return; - if (m_state.backdropLayer && !options.backdropLayer) - paintBackdrop(options); + if (m_state.backdropLayer && !options.backdropLayer) { + TransformationMatrix clipTransform; + clipTransform.translate(options.offset.width(), options.offset.height()); + clipTransform.multiply(options.transform); + clipTransform.multiply(m_layerTransforms.combined); + options.textureMapper.beginClip(clipTransform, m_state.backdropFiltersRect); + m_state.backdropLayer->paintRecursive(options); + options.textureMapper.endClip(); + } paintSelf(options); @@ -534,10 +350,8 @@ void TextureMapperLayer::paintSelfAndChildren(TextureMapperPaintOptions& options } } - if (!isFlattened() || m_flattenedLayer->needsUpdate()) { - for (auto* child : m_children) - child->paintRecursive(options); - } + for (auto* child : m_children) + child->paintRecursive(options); if (shouldClip) options.textureMapper.endClip(); @@ -551,16 +365,6 @@ bool TextureMapperLayer::shouldBlend() const return m_currentOpacity < 1; } -bool TextureMapperLayer::flattensAsLeafOf3DSceneOr3DPerspective() const -{ - bool isLeafOf3DScene = !m_state.preserves3D && (m_parent && m_parent->preserves3D()); - bool hasPerspective = m_layerTransforms.localTransform.hasPerspective() && m_layerTransforms.localTransform.m34() != -1.f; - if ((isLeafOf3DScene || hasPerspective) && !m_children.isEmpty() && !m_layerTransforms.localTransform.isAffine()) - return true; - - return false; -} - bool TextureMapperLayer::isVisible() const { if (m_state.size.isEmpty() && (m_state.masksToBounds || m_state.maskLayer || m_children.isEmpty())) @@ -782,9 +586,7 @@ void TextureMapperLayer::computeOverlapRegions(ComputeOverlapRegionData& data, c return; FloatRect localBoundingRect; - if (isFlattened() && !m_isBackdrop) - localBoundingRect = m_flattenedLayer->layerRect(); - else if (m_backingStore || m_state.masksToBounds || m_state.maskLayer || hasFilters()) + if (m_backingStore || m_state.masksToBounds || m_state.maskLayer || hasFilters()) localBoundingRect = layerRect(); else if (m_contentsLayer || m_state.solidColor.isVisible()) localBoundingRect = m_state.contentsRect; @@ -816,7 +618,7 @@ void TextureMapperLayer::computeOverlapRegions(ComputeOverlapRegionData& data, c computeOverlapRegions(data, newReplicaTransform, false); } - if (!m_state.masksToBounds && data.mode != ComputeOverlapRegionMode::Mask && !isFlattened()) { + if (!m_state.masksToBounds && data.mode != ComputeOverlapRegionMode::Mask) { for (auto* child : m_children) child->computeOverlapRegions(data, accumulatedReplicaTransform); } @@ -927,7 +729,6 @@ void TextureMapperLayer::paintIntoSurface(TextureMapperPaintOptions& options) SetForScope scopedTransform(options.transform, TransformationMatrix()); SetForScope scopedReplicaLayer(options.replicaLayer, nullptr); SetForScope scopedBackdropLayer(options.backdropLayer, this); - rootLayer().paintSelfAndChildren(options); } else paintSelfAndChildren(options); @@ -1011,40 +812,14 @@ void TextureMapperLayer::paintRecursive(TextureMapperPaintOptions& options) SetForScope scopedOpacity(options.opacity, options.opacity * m_currentOpacity); - if (preserves3D()) + if (m_state.preserves3D) paintWith3DRenderingContext(options); - else if (isFlattened()) - paintFlattened(options); else if (shouldBlend()) paintUsingOverlapRegions(options); else paintSelfChildrenReplicaFilterAndMask(options); } -void TextureMapperLayer::paintFlattened(TextureMapperPaintOptions& options) -{ - // If painting a backdrop for a flattened layer, processing should stop here. - // Only the elements up to the flattened layer need to be painted into the backdrop buffer. - if (m_state.backdropLayer && m_state.backdropLayer == options.backdropLayer) - return; - - if (m_state.backdropLayer && !options.backdropLayer) - paintBackdrop(options); - - if (m_flattenedLayer->needsUpdate()) { - SetForScope scopedOffset(options.offset, IntSize()); - SetForScope scopedTransform(options.transform, TransformationMatrix()); - SetForScope scopedCombinedTransform(m_layerTransforms.combined, TransformationMatrix()); - SetForScope scopedBackdropLayer(m_state.backdropLayer, nullptr); - - m_flattenedLayer->update(options, [&](TextureMapperPaintOptions& options) { - paintIntoSurface(options); - }); - } - - paintSelf(options); -} - void TextureMapperLayer::paintWith3DRenderingContext(TextureMapperPaintOptions& options) { if (options.preserves3D) { diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h index 1ccf770033aa..70f21b27fb8f 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h @@ -41,7 +41,6 @@ template<> struct IsDeprecatedWeakRefSmartPointerExceptionrootLayer(); - if (m_parent) { - if (m_parent->flattensAsLeafOf3DSceneOr3DPerspective()) - return *m_parent; + if (m_parent) return m_parent->rootLayer(); - } return const_cast(*this); } - void processDescendantLayersFlatteningRequirements(); - void processFlatteningRequirements(); - void computeFlattenedRegion(Region&, bool); - void destroyFlattenedDescendantLayers(); - struct ComputeTransformData; void computeTransformsRecursive(ComputeTransformData&); @@ -176,7 +167,6 @@ class WEBCORE_EXPORT TextureMapperLayer : public CanMakeWeakPtr m_effectTarget; TextureMapperBackingStore* m_backingStore { nullptr }; TextureMapperPlatformLayer* m_contentsLayer { nullptr }; - std::unique_ptr m_flattenedLayer; float m_currentOpacity { 1.0 }; FilterOperations m_currentFilters; float m_centerZ { 0 };