Changeset 104931 in webkit


Ignore:
Timestamp:
Jan 13, 2012 6:39:48 AM (12 years ago)
Author:
jocelyn.turcotte@nokia.com
Message:

TextureMapper: Simplify transform manipulations.
https://bugs.webkit.org/show_bug.cgi?id=74719

Reviewed by Noam Rosenthal.

  • Make sure that the replica node has a complete transform and use it directly instead of keeping a copy in the source.
  • Apply the origin and position translation only once, on the target and descendants transforms.
  • Use to2dTransform() on !preserves3D layers instead of doing the flattening manually.
  • Remove mentions of perspective as this is handled by WebCore through the children transform.
  • Apply the inverse target transform on the replica only where it is needed in paintReflection since it uses the full transform in paintSelf.
  • Merge the base and local transforms.
  • platform/graphics/texmap/TextureMapperNode.cpp:

(WebCore::TextureMapperNode::setTransform):
(WebCore::TextureMapperNode::computeTransformsSelf):
(WebCore::TextureMapperNode::computeAllTransforms):
(WebCore::TextureMapperNode::paintSelf):
(WebCore::TextureMapperNode::paintReflection):

  • platform/graphics/texmap/TextureMapperNode.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104930 r104931  
     12012-01-12  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
     2
     3        TextureMapper: Simplify transform manipulations.
     4        https://bugs.webkit.org/show_bug.cgi?id=74719
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        - Make sure that the replica node has a complete transform and
     9          use it directly instead of keeping a copy in the source.
     10        - Apply the origin and position translation only once, on the
     11          target and descendants transforms.
     12        - Use to2dTransform() on !preserves3D layers instead of doing
     13          the flattening manually.
     14        - Remove mentions of perspective as this is handled by WebCore
     15          through the children transform.
     16        - Apply the inverse target transform on the replica only where it
     17          is needed in paintReflection since it uses the full transform in paintSelf.
     18        - Merge the base and local transforms.
     19
     20        * platform/graphics/texmap/TextureMapperNode.cpp:
     21        (WebCore::TextureMapperNode::setTransform):
     22        (WebCore::TextureMapperNode::computeTransformsSelf):
     23        (WebCore::TextureMapperNode::computeAllTransforms):
     24        (WebCore::TextureMapperNode::paintSelf):
     25        (WebCore::TextureMapperNode::paintReflection):
     26        * platform/graphics/texmap/TextureMapperNode.h:
     27
    1282012-01-12  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    229
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp

    r104930 r104931  
    4848void TextureMapperNode::setTransform(const TransformationMatrix& matrix)
    4949{
    50     if (m_transforms.base == matrix)
    51         return;
    52 
    5350    m_transforms.base = matrix;
    54 }
    55 
    56 void TextureMapperNode::computePerspectiveTransformIfNeeded()
    57 {
    58     if (m_children.isEmpty() || m_state.childrenTransform.isIdentity())
    59         return;
    60 
    61     const FloatPoint centerPoint = FloatPoint(m_size.width() / 2, m_size.height() / 2);
    62     m_transforms.perspective = TransformationMatrix()
    63             .translate(centerPoint.x(), centerPoint.y())
    64             .multiply(m_state.childrenTransform)
    65             .translate(-centerPoint.x(), -centerPoint.y());
    6651}
    6752
     
    8267}
    8368
    84 void TextureMapperNode::computeReplicaTransformIfNeeded()
    85 {
    86     if (!m_state.replicaLayer)
    87         return;
    88 
    89     m_transforms.replica =
    90         TransformationMatrix(m_transforms.target)
    91             .multiply(m_state.replicaLayer->m_transforms.local)
    92             .multiply(TransformationMatrix(m_transforms.target).inverse());
    93 }
    94 
    95 void TextureMapperNode::computeLocalTransformIfNeeded()
     69void TextureMapperNode::computeTransformsSelf()
    9670{
    9771    float originX = m_state.anchorPoint.x() * m_size.width();
    9872    float originY = m_state.anchorPoint.y() * m_size.height();
    99     m_transforms.local =
    100         TransformationMatrix()
    101         .translate3d(originX + m_state.pos.x(), originY + m_state.pos.y(), m_state.anchorPoint.z() )
    102         .multiply(m_transforms.base)
    103         .translate3d(-originX, -originY, -m_state.anchorPoint.z());
     73
     74    TransformationMatrix parentTransform;
     75    if (m_parent)
     76        parentTransform = m_parent->m_transforms.forDescendants;
     77    else if (m_effectTarget)
     78        parentTransform = m_effectTarget->m_transforms.target;
     79    m_transforms.target =
     80        TransformationMatrix(parentTransform)
     81            .translate3d(originX + m_state.pos.x(), originY + m_state.pos.y(), m_state.anchorPoint.z() )
     82            .multiply(m_transforms.base);
     83
     84    // The descendants transform will take it from here, if needed.
     85    m_transforms.forDescendants = m_transforms.target;
     86    m_transforms.target.translate3d(-originX, -originY, -m_state.anchorPoint.z());
     87
     88    if (m_children.isEmpty())
     89        return;
     90
     91    // In case a parent had preserves3D and this layer has not, flatten our children.
     92    if (!m_state.preserves3D)
     93        m_transforms.forDescendants = m_transforms.forDescendants.to2dTransform();
     94    m_transforms.forDescendants.multiply(m_state.childrenTransform);
     95    m_transforms.forDescendants.translate3d(-originX, -originY, -m_state.anchorPoint.z());
    10496}
    10597
     
    109101        return;
    110102
    111     computeLocalTransformIfNeeded();
    112     computeReplicaTransformIfNeeded();
    113     computePerspectiveTransformIfNeeded();
    114 
    115     TextureMapperNode* parent = m_parent ? m_parent : m_effectTarget;
    116     m_transforms.target = TransformationMatrix(parent ? parent->m_transforms.forDescendants : TransformationMatrix()).multiply(m_transforms.local);
     103    computeTransformsSelf();
    117104
    118105    m_state.visible = m_state.backfaceVisibility || m_transforms.target.inverse().m33() >= 0;
    119     if (!m_state.visible)
    120         return;
    121 
    122     // This transform is only applied if using a two-pass for the replica, because the transform needs to be adjusted to the size of the intermediate surface, insteaf of the size of the content layer.
    123     if (parent && parent->m_state.preserves3D)
     106
     107    if (m_parent && m_parent->m_state.preserves3D)
    124108        m_transforms.centerZ = m_transforms.target.mapPoint(FloatPoint3D(m_size.width() / 2, m_size.height() / 2, 0)).z();
    125109
    126     if (!m_children.size())
    127         return;
    128 
    129     m_transforms.forDescendants = m_transforms.target;
    130 
    131     if (!m_state.preserves3D) {
    132         m_transforms.forDescendants = TransformationMatrix(
    133                     m_transforms.forDescendants.m11(), m_transforms.forDescendants.m12(), 0, m_transforms.forDescendants.m14(),
    134                     m_transforms.forDescendants.m21(), m_transforms.forDescendants.m22(), 0, m_transforms.forDescendants.m24(),
    135                     0, 0, 1, 0,
    136                     m_transforms.forDescendants.m41(), m_transforms.forDescendants.m42(), 0, m_transforms.forDescendants.m44());
    137     }
    138 
    139     m_transforms.forDescendants.multiply(m_transforms.perspective);
     110    if (m_state.maskLayer)
     111        m_state.maskLayer->computeAllTransforms();
     112    if (m_state.replicaLayer)
     113        m_state.replicaLayer->computeAllTransforms();
    140114}
    141115
     
    402376            float replicaOpacity = 1.0;
    403377            if (m_state.replicaLayer) {
    404                 replicaMatrix = TransformationMatrix(m_transforms.target).scale(1.0 / tile.scale).multiply(m_state.replicaLayer->m_transforms.local);
     378                replicaMatrix = m_state.replicaLayer->m_transforms.target.scale(1.0 / tile.scale);
    405379                replicaOpacity = opacity * m_state.replicaLayer->m_opacity;
    406380            }
     
    419393        if (m_state.replicaLayer && !options.isSurface) {
    420394            options.textureMapper->drawTexture(*texture, targetRectForTileRect(targetRect, m_ownedTiles[i].rect),
    421                              TransformationMatrix(m_transforms.target).multiply(m_state.replicaLayer->m_transforms.local),
     395                             m_state.replicaLayer->m_transforms.target,
    422396                             opacity * m_state.replicaLayer->m_opacity,
    423397                             replicaMaskTexture ? replicaMaskTexture.get() : maskTexture.get());
     
    431405        if (m_state.replicaLayer && !options.isSurface)
    432406            m_currentContent.media->paintToTextureMapper(options.textureMapper, targetRect,
    433                                                          TransformationMatrix(m_transforms.target).multiply(m_state.replicaLayer->m_transforms.local),
     407                                                         m_state.replicaLayer->m_transforms.target,
    434408                                                         opacity * m_state.replicaLayer->m_opacity,
    435409                                                         replicaMaskTexture ? replicaMaskTexture.get() : maskTexture.get());
     
    486460    const bool useIntermediateBufferForMask = maskTexture && replicaMaskTexture;
    487461    const FloatRect viewportRect(0, 0, viewportSize.width(), viewportSize.height());
     462    // Reverse this layer's transform on the replica's transform and use it with the contents
     463    // intermediate surface, applied in the viewport coordinate system.
     464    TransformationMatrix replicaMatrix = m_state.replicaLayer->m_transforms.target;
     465    replicaMatrix.multiply(m_transforms.target.inverse());
    488466
    489467    // The mask has to be adjusted to target coordinates.
     
    517495        RefPtr<BitmapTexture> replicaSurface = options.textureMapper->acquireTextureFromPool(options.textureMapper->viewportSize());
    518496        options.textureMapper->bindSurface(replicaSurface.get());
    519         options.textureMapper->drawTexture(*surface.get(), viewportRect, m_transforms.replica, m_state.replicaLayer->m_opacity, replicaMaskTexture.get());
     497        options.textureMapper->drawTexture(*surface.get(), viewportRect, replicaMatrix, m_state.replicaLayer->m_opacity, replicaMaskTexture.get());
    520498        options.textureMapper->drawTexture(*surface.get(), viewportRect, TransformationMatrix(), 1, maskTexture.get());
    521499        options.textureMapper->releaseTextureToPool(surface.get());
     
    527505    // Draw the reflection.
    528506    if (!useIntermediateBufferForReplica)
    529         options.textureMapper->drawTexture(*surface.get(), viewportRect, m_transforms.replica, m_state.replicaLayer->m_opacity, replicaMaskTexture.get());
     507        options.textureMapper->drawTexture(*surface.get(), viewportRect, replicaMatrix, m_state.replicaLayer->m_opacity, replicaMaskTexture.get());
    530508
    531509    // Draw the original.
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h

    r104728 r104931  
    176176    TextureMapperNode* rootLayer();
    177177    void computeAllTransforms();
     178    void computeTransformsSelf();
    178179    void computeVisibleRect(const FloatRect& rootVisibleRect);
    179     void computePerspectiveTransformIfNeeded();
    180     void computeReplicaTransformIfNeeded();
    181180    void computeOverlapsIfNeeded();
    182     void computeLocalTransformIfNeeded();
    183181    void computeTiles();
    184182    void swapContentsBuffers();
     
    210208    struct TransformData {
    211209        TransformationMatrix target;
    212         TransformationMatrix replica;
    213210        TransformationMatrix forDescendants;
    214         TransformationMatrix local;
    215211        TransformationMatrix base;
    216         TransformationMatrix perspective;
    217212        float centerZ;
    218213        TransformData() { }
Note: See TracChangeset for help on using the changeset viewer.