diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp | 225 |
1 files changed, 99 insertions, 126 deletions
diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp index 7e7babbcd..d39cffcbb 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp @@ -21,35 +21,25 @@ #include "TextureMapperLayer.h" #include "FloatQuad.h" +#include "GraphicsLayerTextureMapper.h" #include "Region.h" #include <wtf/MathExtras.h> -#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) - namespace WebCore { class TextureMapperPaintOptions { public: - RefPtr<BitmapTexture> surface; - float opacity; + TextureMapperPaintOptions(TextureMapper& textureMapper) + : textureMapper(textureMapper) + { } + + TextureMapper& textureMapper; TransformationMatrix transform; + RefPtr<BitmapTexture> surface; + float opacity { 1 }; IntSize offset; - TextureMapper* textureMapper; - TextureMapperPaintOptions() - : opacity(1) - , textureMapper(0) - { } }; -const TextureMapperLayer* TextureMapperLayer::rootLayer() const -{ - if (m_effectTarget) - return m_effectTarget->rootLayer(); - if (m_parent) - return m_parent->rootLayer(); - return this; -} - void TextureMapperLayer::computeTransformsRecursive() { if (m_state.size.isEmpty() && m_state.masksToBounds) @@ -72,9 +62,9 @@ void TextureMapperLayer::computeTransformsRecursive() m_state.maskLayer->computeTransformsRecursive(); if (m_state.replicaLayer) m_state.replicaLayer->computeTransformsRecursive(); - for (size_t i = 0; i < m_children.size(); ++i) { - RELEASE_ASSERT(m_children[i]->m_parent == this); - m_children[i]->computeTransformsRecursive(); + for (auto* child : m_children) { + ASSERT(child->m_parent == this); + child->computeTransformsRecursive(); } // Reorder children if needed on the way back up. @@ -86,19 +76,19 @@ void TextureMapperLayer::paint() { computeTransformsRecursive(); - TextureMapperPaintOptions options; - options.textureMapper = m_textureMapper; - options.textureMapper->bindSurface(0); + ASSERT(m_textureMapper); + TextureMapperPaintOptions options(*m_textureMapper); + options.textureMapper.bindSurface(0); + paintRecursive(options); } static Color blendWithOpacity(const Color& color, float opacity) { - RGBA32 rgba = color.rgb(); - // See Color::getRGBA() to know how to extract alpha from color. - float alpha = alphaChannel(rgba) / 255.; - float effectiveAlpha = alpha * opacity; - return Color(colorWithOverrideAlpha(rgba, effectiveAlpha)); + if (color.isOpaque() && opacity == 1.) + return color; + + return color.colorWithAlphaMultipliedBy(opacity); } void TextureMapperLayer::computePatternTransformIfNeeded() @@ -108,8 +98,8 @@ void TextureMapperLayer::computePatternTransformIfNeeded() m_patternTransformDirty = false; m_patternTransform = - TransformationMatrix::rectToRect(FloatRect(FloatPoint::zero(), m_state.contentsTileSize), m_state.contentsRect) - .multiply(TransformationMatrix().translate(m_state.contentsTilePhase.x() / m_state.contentsRect.width(), m_state.contentsTilePhase.y() / m_state.contentsRect.height())); + TransformationMatrix::rectToRect(FloatRect(FloatPoint::zero(), m_state.contentsTileSize), FloatRect(FloatPoint::zero(), m_state.contentsRect.size())) + .multiply(TransformationMatrix().translate(m_state.contentsTilePhase.width() / m_state.contentsRect.width(), m_state.contentsTilePhase.height() / m_state.contentsRect.height())); } void TextureMapperLayer::paintSelf(const TextureMapperPaintOptions& options) @@ -123,15 +113,15 @@ void TextureMapperLayer::paintSelf(const TextureMapperPaintOptions& options) transform.multiply(options.transform); transform.multiply(m_currentTransform.combined()); - if (m_state.solidColor.isValid() && !m_state.contentsRect.isEmpty() && m_state.solidColor.alpha()) { - options.textureMapper->drawSolidColor(m_state.contentsRect, transform, blendWithOpacity(m_state.solidColor, options.opacity)); + if (m_state.solidColor.isValid() && !m_state.contentsRect.isEmpty() && m_state.solidColor.isVisible()) { + options.textureMapper.drawSolidColor(m_state.contentsRect, transform, blendWithOpacity(m_state.solidColor, options.opacity)); if (m_state.showDebugBorders) - options.textureMapper->drawBorder(m_state.debugBorderColor, m_state.debugBorderWidth, layerRect(), transform); + options.textureMapper.drawBorder(m_state.debugBorderColor, m_state.debugBorderWidth, layerRect(), transform); return; } - options.textureMapper->setWrapMode(TextureMapper::StretchWrap); - options.textureMapper->setPatternTransform(TransformationMatrix()); + options.textureMapper.setWrapMode(TextureMapper::StretchWrap); + options.textureMapper.setPatternTransform(TransformationMatrix()); if (m_backingStore) { FloatRect targetRect = layerRect(); @@ -149,8 +139,8 @@ void TextureMapperLayer::paintSelf(const TextureMapperPaintOptions& options) if (!m_state.contentsTileSize.isEmpty()) { computePatternTransformIfNeeded(); - options.textureMapper->setWrapMode(TextureMapper::RepeatWrap); - options.textureMapper->setPatternTransform(m_patternTransform); + options.textureMapper.setWrapMode(TextureMapper::RepeatWrap); + options.textureMapper.setPatternTransform(m_patternTransform); } ASSERT(!layerRect().isEmpty()); @@ -159,16 +149,12 @@ void TextureMapperLayer::paintSelf(const TextureMapperPaintOptions& options) m_contentsLayer->drawBorder(options.textureMapper, m_state.debugBorderColor, m_state.debugBorderWidth, m_state.contentsRect, transform); } -int TextureMapperLayer::compareGraphicsLayersZValue(const void* a, const void* b) -{ - TextureMapperLayer* const* layerA = static_cast<TextureMapperLayer* const*>(a); - TextureMapperLayer* const* layerB = static_cast<TextureMapperLayer* const*>(b); - return int(((*layerA)->m_centerZ - (*layerB)->m_centerZ) * 1000); -} - void TextureMapperLayer::sortByZOrder(Vector<TextureMapperLayer* >& array) { - qsort(array.data(), array.size(), sizeof(TextureMapperLayer*), compareGraphicsLayersZValue); + std::sort(array.begin(), array.end(), + [](TextureMapperLayer* a, TextureMapperLayer* b) { + return a->m_centerZ < b->m_centerZ; + }); } void TextureMapperLayer::paintSelfAndChildren(const TextureMapperPaintOptions& options) @@ -184,14 +170,14 @@ void TextureMapperLayer::paintSelfAndChildren(const TextureMapperPaintOptions& o clipTransform.translate(options.offset.width(), options.offset.height()); clipTransform.multiply(options.transform); clipTransform.multiply(m_currentTransform.combined()); - options.textureMapper->beginClip(clipTransform, layerRect()); + options.textureMapper.beginClip(clipTransform, layerRect()); } - for (size_t i = 0; i < m_children.size(); ++i) - m_children[i]->paintRecursive(options); + for (auto* child : m_children) + child->paintRecursive(options); if (shouldClip) - options.textureMapper->endClip(); + options.textureMapper.endClip(); } bool TextureMapperLayer::shouldBlend() const @@ -224,7 +210,7 @@ void TextureMapperLayer::paintSelfAndChildrenWithReplica(const TextureMapperPain TextureMapperPaintOptions replicaOptions(options); replicaOptions.transform .multiply(m_state.replicaLayer->m_currentTransform.combined()) - .multiply(m_currentTransform.combined().inverse()); + .multiply(m_currentTransform.combined().inverse().value_or(TransformationMatrix())); paintSelfAndChildren(replicaOptions); } @@ -243,17 +229,15 @@ void TextureMapperLayer::setAnimatedOpacity(float opacity) TransformationMatrix TextureMapperLayer::replicaTransform() { - return TransformationMatrix(m_state.replicaLayer->m_currentTransform.combined()).multiply(m_currentTransform.combined().inverse()); + return TransformationMatrix(m_state.replicaLayer->m_currentTransform.combined()).multiply(m_currentTransform.combined().inverse().value_or(TransformationMatrix())); } -#if ENABLE(CSS_FILTERS) void TextureMapperLayer::setAnimatedFilters(const FilterOperations& filters) { m_currentFilters = filters; } -#endif -static void resolveOverlaps(Region newRegion, Region& overlapRegion, Region& nonOverlapRegion) +static void resolveOverlaps(Region& newRegion, Region& overlapRegion, Region& nonOverlapRegion) { Region newOverlapRegion(newRegion); newOverlapRegion.intersect(nonOverlapRegion); @@ -271,10 +255,9 @@ void TextureMapperLayer::computeOverlapRegions(Region& overlapRegion, Region& no FloatRect boundingRect; if (m_backingStore || m_state.masksToBounds || m_state.maskLayer || hasFilters()) boundingRect = layerRect(); - else if (m_contentsLayer || m_state.solidColor.alpha()) + else if (m_contentsLayer || m_state.solidColor.isVisible()) boundingRect = m_state.contentsRect; -#if ENABLE(CSS_FILTERS) if (m_currentFilters.hasOutsets()) { FilterOutsets outsets = m_currentFilters.outsets(); IntRect unfilteredTargetRect(boundingRect); @@ -282,7 +265,6 @@ void TextureMapperLayer::computeOverlapRegions(Region& overlapRegion, Region& no boundingRect.expand(outsets.left() + outsets.right(), outsets.top() + outsets.bottom()); boundingRect.unite(unfilteredTargetRect); } -#endif TransformationMatrix replicaMatrix; if (m_state.replicaLayer) { @@ -304,10 +286,8 @@ void TextureMapperLayer::computeOverlapRegions(Region& overlapRegion, Region& no Region newNonOverlapRegion(enclosingIntRect(boundingRect)); if (!m_state.masksToBounds) { - for (size_t i = 0; i < m_children.size(); ++i) { - TextureMapperLayer* child = m_children[i]; + for (auto* child : m_children) child->computeOverlapRegions(newOverlapRegion, newNonOverlapRegion, ResolveSelfOverlapIfNeeded); - } } if (m_state.replicaLayer) { @@ -345,14 +325,13 @@ void TextureMapperLayer::paintUsingOverlapRegions(const TextureMapperPaintOption nonOverlapRegion.translate(options.offset); Vector<IntRect> rects = nonOverlapRegion.rects(); - for (size_t i = 0; i < rects.size(); ++i) { - IntRect rect = rects[i]; - if (!rect.intersects(options.textureMapper->clipBounds())) + for (auto& rect : rects) { + if (!rect.intersects(options.textureMapper.clipBounds())) continue; - options.textureMapper->beginClip(TransformationMatrix(), rects[i]); + options.textureMapper.beginClip(TransformationMatrix(), rect); paintSelfAndChildrenWithReplica(options); - options.textureMapper->endClip(); + options.textureMapper.endClip(); } rects = overlapRegion.rects(); @@ -362,11 +341,10 @@ void TextureMapperLayer::paintUsingOverlapRegions(const TextureMapperPaintOption rects.append(overlapRegion.bounds()); } - IntSize maxTextureSize = options.textureMapper->maxTextureSize(); - IntRect adjustedClipBounds(options.textureMapper->clipBounds()); + IntSize maxTextureSize = options.textureMapper.maxTextureSize(); + IntRect adjustedClipBounds(options.textureMapper.clipBounds()); adjustedClipBounds.move(-options.offset); - for (size_t i = 0; i < rects.size(); ++i) { - IntRect rect = rects[i]; + for (auto& rect : rects) { for (int x = rect.x(); x < rect.maxX(); x += maxTextureSize.width()) { for (int y = rect.y(); y < rect.maxY(); y += maxTextureSize.height()) { IntRect tileRect(IntPoint(x, y), maxTextureSize); @@ -382,34 +360,32 @@ void TextureMapperLayer::paintUsingOverlapRegions(const TextureMapperPaintOption void TextureMapperLayer::applyMask(const TextureMapperPaintOptions& options) { - options.textureMapper->setMaskMode(true); + options.textureMapper.setMaskMode(true); paintSelf(options); - options.textureMapper->setMaskMode(false); + options.textureMapper.setMaskMode(false); } PassRefPtr<BitmapTexture> TextureMapperLayer::paintIntoSurface(const TextureMapperPaintOptions& options, const IntSize& size) { - RefPtr<BitmapTexture> surface = options.textureMapper->acquireTextureFromPool(size); + RefPtr<BitmapTexture> surface = options.textureMapper.acquireTextureFromPool(size, BitmapTexture::SupportsAlpha | BitmapTexture::FBOAttachment); TextureMapperPaintOptions paintOptions(options); paintOptions.surface = surface; - options.textureMapper->bindSurface(surface.get()); + options.textureMapper.bindSurface(surface.get()); paintSelfAndChildren(paintOptions); if (m_state.maskLayer) m_state.maskLayer->applyMask(options); -#if ENABLE(CSS_FILTERS) surface = surface->applyFilters(options.textureMapper, m_currentFilters); -#endif - options.textureMapper->bindSurface(surface.get()); - return surface; + options.textureMapper.bindSurface(surface.get()); + return surface.release(); } static void commitSurface(const TextureMapperPaintOptions& options, PassRefPtr<BitmapTexture> surface, const IntRect& rect, float opacity) { - options.textureMapper->bindSurface(options.surface.get()); + options.textureMapper.bindSurface(options.surface.get()); TransformationMatrix targetTransform; targetTransform.translate(options.offset.width(), options.offset.height()); targetTransform.multiply(options.transform); - options.textureMapper->drawTexture(*surface.get(), rect, targetTransform, opacity); + options.textureMapper.drawTexture(*surface.get(), rect, targetTransform, opacity); } void TextureMapperLayer::paintWithIntermediateSurface(const TextureMapperPaintOptions& options, const IntRect& rect) @@ -430,13 +406,13 @@ void TextureMapperLayer::paintWithIntermediateSurface(const TextureMapperPaintOp if (replicaSurface && options.opacity == 1) { commitSurface(options, replicaSurface, rect, 1); - replicaSurface.clear(); + replicaSurface = nullptr; } mainSurface = paintIntoSurface(paintOptions, rect.size()); if (replicaSurface) { - options.textureMapper->bindSurface(replicaSurface.get()); - options.textureMapper->drawTexture(*mainSurface.get(), FloatRect(FloatPoint::zero(), rect.size())); + options.textureMapper.bindSurface(replicaSurface.get()); + options.textureMapper.drawTexture(*mainSurface.get(), FloatRect(FloatPoint::zero(), rect.size())); mainSurface = replicaSurface; } @@ -461,23 +437,33 @@ void TextureMapperLayer::paintRecursive(const TextureMapperPaintOptions& options TextureMapperLayer::~TextureMapperLayer() { - for (int i = m_children.size() - 1; i >= 0; --i) - m_children[i]->m_parent = 0; + for (auto* child : m_children) + child->m_parent = nullptr; - if (m_parent) - m_parent->m_children.remove(m_parent->m_children.find(this)); + removeFromParent(); + + if (m_effectTarget) { + if (m_effectTarget->m_state.maskLayer == this) + m_effectTarget->m_state.maskLayer = nullptr; + if (m_effectTarget->m_state.replicaLayer == this) + m_effectTarget->m_state.replicaLayer = nullptr; + } } -TextureMapper* TextureMapperLayer::textureMapper() const +#if !USE(COORDINATED_GRAPHICS) +void TextureMapperLayer::setChildren(const Vector<GraphicsLayer*>& newChildren) { - return rootLayer()->m_textureMapper; + removeAllChildren(); + for (auto* child : newChildren) + addChild(&downcast<GraphicsLayerTextureMapper>(child)->layer()); } +#endif void TextureMapperLayer::setChildren(const Vector<TextureMapperLayer*>& newChildren) { removeAllChildren(); - for (size_t i = 0; i < newChildren.size(); ++i) - addChild(newChildren[i]); + for (auto* child : newChildren) + addChild(child); } void TextureMapperLayer::addChild(TextureMapperLayer* childLayer) @@ -494,25 +480,19 @@ void TextureMapperLayer::addChild(TextureMapperLayer* childLayer) void TextureMapperLayer::removeFromParent() { if (m_parent) { - unsigned i; - for (i = 0; i < m_parent->m_children.size(); i++) { - if (this == m_parent->m_children[i]) { - m_parent->m_children.remove(i); - break; - } - } - - m_parent = 0; + size_t index = m_parent->m_children.find(this); + ASSERT(index != notFound); + m_parent->m_children.remove(index); } + + m_parent = nullptr; } void TextureMapperLayer::removeAllChildren() { - while (m_children.size()) { - TextureMapperLayer* curLayer = m_children[0]; - ASSERT(curLayer->m_parent); - curLayer->removeFromParent(); - } + auto oldChildren = WTFMove(m_children); + for (auto* child : oldChildren) + child->m_parent = nullptr; } void TextureMapperLayer::setMaskLayer(TextureMapperLayer* maskLayer) @@ -565,7 +545,7 @@ void TextureMapperLayer::setChildrenTransform(const TransformationMatrix& childr m_currentTransform.setChildrenTransform(childrenTransform); } -void TextureMapperLayer::setContentsRect(const IntRect& contentsRect) +void TextureMapperLayer::setContentsRect(const FloatRect& contentsRect) { if (contentsRect == m_state.contentsRect) return; @@ -573,7 +553,7 @@ void TextureMapperLayer::setContentsRect(const IntRect& contentsRect) m_patternTransformDirty = true; } -void TextureMapperLayer::setContentsTileSize(const IntSize& size) +void TextureMapperLayer::setContentsTileSize(const FloatSize& size) { if (size == m_state.contentsTileSize) return; @@ -581,7 +561,7 @@ void TextureMapperLayer::setContentsTileSize(const IntSize& size) m_patternTransformDirty = true; } -void TextureMapperLayer::setContentsTilePhase(const IntPoint& phase) +void TextureMapperLayer::setContentsTilePhase(const FloatSize& phase) { if (phase == m_state.contentsTilePhase) return; @@ -624,12 +604,10 @@ void TextureMapperLayer::setSolidColor(const Color& color) m_state.solidColor = color; } -#if ENABLE(CSS_FILTERS) void TextureMapperLayer::setFilters(const FilterOperations& filters) { m_state.filters = filters; } -#endif void TextureMapperLayer::setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth, bool showRepaintCounter) { @@ -649,7 +627,7 @@ void TextureMapperLayer::setContentsLayer(TextureMapperPlatformLayer* platformLa m_contentsLayer = platformLayer; } -void TextureMapperLayer::setAnimations(const GraphicsLayerAnimations& animations) +void TextureMapperLayer::setAnimations(const TextureMapperAnimations& animations) { m_animations = animations; } @@ -669,33 +647,29 @@ bool TextureMapperLayer::descendantsOrSelfHaveRunningAnimations() const if (m_animations.hasRunningAnimations()) return true; - for (size_t i = 0; i < m_children.size(); ++i) { - if (m_children[i]->descendantsOrSelfHaveRunningAnimations()) - return true; - } - - return false; + return std::any_of(m_children.begin(), m_children.end(), + [](TextureMapperLayer* child) { + return child->descendantsOrSelfHaveRunningAnimations(); + }); } void TextureMapperLayer::applyAnimationsRecursively() { syncAnimations(); - for (size_t i = 0; i < m_children.size(); ++i) - m_children[i]->applyAnimationsRecursively(); + for (auto* child : m_children) + child->applyAnimationsRecursively(); } void TextureMapperLayer::syncAnimations() { - m_animations.apply(this); - if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform)) + m_animations.apply(*this); + if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyTransform)) m_currentTransform.setLocalTransform(m_state.transform); if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity)) m_currentOpacity = m_state.opacity; -#if ENABLE(CSS_FILTERS) - if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitFilter)) + if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyFilter)) m_currentFilters = m_state.filters; -#endif } bool TextureMapperLayer::isAncestorFixedToViewport() const @@ -756,7 +730,7 @@ TextureMapperLayer* TextureMapperLayer::findScrollableContentsLayerAt(const Floa FloatSize TextureMapperLayer::mapScrollOffset(const FloatSize& offset) { double zeroX, zeroY, offsetX, offsetY; - TransformationMatrix transform = m_currentTransform.combined().inverse(); + TransformationMatrix transform = m_currentTransform.combined().inverse().value_or(TransformationMatrix()); transform.map(0, 0, zeroX, zeroY); transform.map(offset.width(), offset.height(), offsetX, offsetY); return FloatSize(offsetX - zeroX, offsetY - zeroY); @@ -795,4 +769,3 @@ void TextureMapperLayer::didCommitScrollOffset(const IntSize& offset) } } -#endif |