Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2009 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 
     28 #if USE(ACCELERATED_COMPOSITING)
     29 
     30 #include "GraphicsLayerCACF.h"
     31 
     32 #include "CString.h"
     33 #include "FloatConversion.h"
     34 #include "FloatRect.h"
     35 #include "Image.h"
     36 #include "PlatformString.h"
     37 #include "SystemTime.h"
     38 #include "WKCACFLayer.h"
     39 #include <QuartzCoreInterface/QuartzCoreInterface.h>
     40 #include <wtf/CurrentTime.h>
     41 #include <wtf/StringExtras.h>
     42 
     43 using namespace std;
     44 
     45 namespace WebCore {
     46 
     47 static inline void copyTransform(CATransform3D& toT3D, const TransformationMatrix& t)
     48 {
     49     toT3D.m11 = narrowPrecisionToFloat(t.m11());
     50     toT3D.m12 = narrowPrecisionToFloat(t.m12());
     51     toT3D.m13 = narrowPrecisionToFloat(t.m13());
     52     toT3D.m14 = narrowPrecisionToFloat(t.m14());
     53     toT3D.m21 = narrowPrecisionToFloat(t.m21());
     54     toT3D.m22 = narrowPrecisionToFloat(t.m22());
     55     toT3D.m23 = narrowPrecisionToFloat(t.m23());
     56     toT3D.m24 = narrowPrecisionToFloat(t.m24());
     57     toT3D.m31 = narrowPrecisionToFloat(t.m31());
     58     toT3D.m32 = narrowPrecisionToFloat(t.m32());
     59     toT3D.m33 = narrowPrecisionToFloat(t.m33());
     60     toT3D.m34 = narrowPrecisionToFloat(t.m34());
     61     toT3D.m41 = narrowPrecisionToFloat(t.m41());
     62     toT3D.m42 = narrowPrecisionToFloat(t.m42());
     63     toT3D.m43 = narrowPrecisionToFloat(t.m43());
     64     toT3D.m44 = narrowPrecisionToFloat(t.m44());
     65 }
     66 
     67 TransformationMatrix CAToTransform3D(const CATransform3D& fromT3D)
     68 {
     69     return TransformationMatrix(
     70         fromT3D.m11,
     71         fromT3D.m12,
     72         fromT3D.m13,
     73         fromT3D.m14,
     74         fromT3D.m21,
     75         fromT3D.m22,
     76         fromT3D.m23,
     77         fromT3D.m24,
     78         fromT3D.m31,
     79         fromT3D.m32,
     80         fromT3D.m33,
     81         fromT3D.m34,
     82         fromT3D.m41,
     83         fromT3D.m42,
     84         fromT3D.m43,
     85         fromT3D.m44);
     86 }
     87 
     88 static void setLayerBorderColor(WKCACFLayer* layer, const Color& color)
     89 {
     90     CGColorRef borderColor = createCGColor(color);
     91     layer->setBorderColor(borderColor);
     92     CGColorRelease(borderColor);
     93 }
     94 
     95 static void clearBorderColor(WKCACFLayer* layer)
     96 {
     97     layer->setBorderColor(0);
     98 }
     99 
    100 static void setLayerBackgroundColor(WKCACFLayer* layer, const Color& color)
    101 {
    102     CGColorRef bgColor = createCGColor(color);
    103     layer->setBackgroundColor(bgColor);
    104     CGColorRelease(bgColor);
    105 }
    106 
    107 static void clearLayerBackgroundColor(WKCACFLayer* layer)
    108 {
    109     layer->setBackgroundColor(0);
    110 }
    111 
    112 GraphicsLayer::CompositingCoordinatesOrientation GraphicsLayer::compositingCoordinatesOrientation()
    113 {
    114     return CompositingCoordinatesBottomUp;
    115 }
    116 
    117 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
    118 {
    119     return new GraphicsLayerCACF(client);
    120 }
    121 
    122 GraphicsLayerCACF::GraphicsLayerCACF(GraphicsLayerClient* client)
    123     : GraphicsLayer(client)
    124     , m_contentsLayerPurpose(NoContentsLayer)
    125     , m_contentsLayerHasBackgroundColor(false)
    126 {
    127     m_layer = WKCACFLayer::create(WKCACFLayer::Layer, this);
    128 
    129     updateDebugIndicators();
    130 }
    131 
    132 GraphicsLayerCACF::~GraphicsLayerCACF()
    133 {
    134     // clean up the WK layer
    135     if (m_layer)
    136         m_layer->removeFromSuperlayer();
    137 
    138     if (m_contentsLayer)
    139         m_contentsLayer->removeFromSuperlayer();
    140 
    141     if (m_transformLayer)
    142         m_transformLayer->removeFromSuperlayer();
    143 }
    144 
    145 void GraphicsLayerCACF::setName(const String& inName)
    146 {
    147     String name = String::format("CALayer(%p) GraphicsLayer(%p) ", m_layer.get(), this) + inName;
    148     GraphicsLayer::setName(name);
    149 
    150     m_layer->setName(inName);
    151 }
    152 
    153 NativeLayer GraphicsLayerCACF::nativeLayer() const
    154 {
    155     return m_layer.get();
    156 }
    157 
    158 bool GraphicsLayerCACF::setChildren(const Vector<GraphicsLayer*>& children)
    159 {
    160     bool childrenChanged = GraphicsLayer::setChildren(children);
    161     // FIXME: GraphicsLayer::setChildren calls addChild() for each sublayer, which
    162     // will end up calling updateSublayerList() N times.
    163     if (childrenChanged)
    164         updateSublayerList();
    165 
    166     return childrenChanged;
    167 }
    168 
    169 void GraphicsLayerCACF::addChild(GraphicsLayer* childLayer)
    170 {
    171     GraphicsLayer::addChild(childLayer);
    172     updateSublayerList();
    173 }
    174 
    175 void GraphicsLayerCACF::addChildAtIndex(GraphicsLayer* childLayer, int index)
    176 {
    177     GraphicsLayer::addChildAtIndex(childLayer, index);
    178     updateSublayerList();
    179 }
    180 
    181 void GraphicsLayerCACF::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
    182 {
    183     GraphicsLayer::addChildBelow(childLayer, sibling);
    184     updateSublayerList();
    185 }
    186 
    187 void GraphicsLayerCACF::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer *sibling)
    188 {
    189     GraphicsLayer::addChildAbove(childLayer, sibling);
    190     updateSublayerList();
    191 }
    192 
    193 bool GraphicsLayerCACF::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
    194 {
    195     if (GraphicsLayer::replaceChild(oldChild, newChild)) {
    196         updateSublayerList();
    197         return true;
    198     }
    199     return false;
    200 }
    201 
    202 void GraphicsLayerCACF::removeFromParent()
    203 {
    204     GraphicsLayer::removeFromParent();
    205     layerForSuperlayer()->removeFromSuperlayer();
    206 }
    207 
    208 void GraphicsLayerCACF::setPosition(const FloatPoint& point)
    209 {
    210     GraphicsLayer::setPosition(point);
    211     updateLayerPosition();
    212 }
    213 
    214 void GraphicsLayerCACF::setAnchorPoint(const FloatPoint3D& point)
    215 {
    216     if (point == m_anchorPoint)
    217         return;
    218 
    219     GraphicsLayer::setAnchorPoint(point);
    220     updateAnchorPoint();
    221 }
    222 
    223 void GraphicsLayerCACF::setSize(const FloatSize& size)
    224 {
    225     if (size == m_size)
    226         return;
    227 
    228     GraphicsLayer::setSize(size);
    229     updateLayerSize();
    230 }
    231 
    232 void GraphicsLayerCACF::setTransform(const TransformationMatrix& t)
    233 {
    234     if (t == m_transform)
    235         return;
    236 
    237     GraphicsLayer::setTransform(t);
    238     updateTransform();
    239 }
    240 
    241 void GraphicsLayerCACF::setChildrenTransform(const TransformationMatrix& t)
    242 {
    243     if (t == m_childrenTransform)
    244         return;
    245 
    246     GraphicsLayer::setChildrenTransform(t);
    247     updateChildrenTransform();
    248 }
    249 
    250 void GraphicsLayerCACF::setPreserves3D(bool preserves3D)
    251 {
    252     if (preserves3D == m_preserves3D)
    253         return;
    254 
    255     GraphicsLayer::setPreserves3D(preserves3D);
    256     updateLayerPreserves3D();
    257 }
    258 
    259 void GraphicsLayerCACF::setMasksToBounds(bool masksToBounds)
    260 {
    261     if (masksToBounds == m_masksToBounds)
    262         return;
    263 
    264     GraphicsLayer::setMasksToBounds(masksToBounds);
    265     updateMasksToBounds();
    266 }
    267 
    268 void GraphicsLayerCACF::setDrawsContent(bool drawsContent)
    269 {
    270     if (drawsContent == m_drawsContent)
    271         return;
    272 
    273     GraphicsLayer::setDrawsContent(drawsContent);
    274     updateLayerDrawsContent();
    275 }
    276 
    277 void GraphicsLayerCACF::setBackgroundColor(const Color& color)
    278 {
    279     if (m_backgroundColorSet && m_backgroundColor == color)
    280         return;
    281 
    282     GraphicsLayer::setBackgroundColor(color);
    283 
    284     m_contentsLayerHasBackgroundColor = true;
    285     updateLayerBackgroundColor();
    286 }
    287 
    288 void GraphicsLayerCACF::clearBackgroundColor()
    289 {
    290     if (!m_backgroundColorSet)
    291         return;
    292 
    293     GraphicsLayer::clearBackgroundColor();
    294     clearLayerBackgroundColor(m_contentsLayer.get());
    295 }
    296 
    297 void GraphicsLayerCACF::setContentsOpaque(bool opaque)
    298 {
    299     if (m_contentsOpaque == opaque)
    300         return;
    301 
    302     GraphicsLayer::setContentsOpaque(opaque);
    303     updateContentsOpaque();
    304 }
    305 
    306 void GraphicsLayerCACF::setBackfaceVisibility(bool visible)
    307 {
    308     if (m_backfaceVisibility == visible)
    309         return;
    310 
    311     GraphicsLayer::setBackfaceVisibility(visible);
    312     updateBackfaceVisibility();
    313 }
    314 
    315 void GraphicsLayerCACF::setOpacity(float opacity)
    316 {
    317     float clampedOpacity = max(min(opacity, 1.0f), 0.0f);
    318 
    319     if (m_opacity == clampedOpacity)
    320         return;
    321 
    322     GraphicsLayer::setOpacity(clampedOpacity);
    323     primaryLayer()->setOpacity(opacity);
    324 }
    325 
    326 void GraphicsLayerCACF::setNeedsDisplay()
    327 {
    328     if (drawsContent())
    329         m_layer->setNeedsDisplay();
    330 }
    331 
    332 void GraphicsLayerCACF::setNeedsDisplayInRect(const FloatRect& rect)
    333 {
    334     if (drawsContent())
    335         m_layer->setNeedsDisplay(rect);
    336 }
    337 
    338 void GraphicsLayerCACF::setContentsRect(const IntRect& rect)
    339 {
    340     if (rect == m_contentsRect)
    341         return;
    342 
    343     GraphicsLayer::setContentsRect(rect);
    344     updateContentsRect();
    345 }
    346 
    347 void GraphicsLayerCACF::setContentsToImage(Image* image)
    348 {
    349     bool childrenChanged = false;
    350 
    351     if (image) {
    352         m_pendingContentsImage = image->nativeImageForCurrentFrame();
    353         m_contentsLayerPurpose = ContentsLayerForImage;
    354         if (!m_contentsLayer)
    355             childrenChanged = true;
    356     } else {
    357         m_pendingContentsImage = 0;
    358         m_contentsLayerPurpose = NoContentsLayer;
    359         if (m_contentsLayer)
    360             childrenChanged = true;
    361     }
    362 
    363     updateContentsImage();
    364 
    365     // This has to happen after updateContentsImage
    366     if (childrenChanged)
    367         updateSublayerList();
    368 }
    369 
    370 void GraphicsLayerCACF::setContentsToMedia(PlatformLayer* mediaLayer)
    371 {
    372     if (mediaLayer == m_contentsLayer)
    373         return;
    374 
    375     m_contentsLayer = mediaLayer;
    376     m_contentsLayerPurpose = mediaLayer ? ContentsLayerForMedia : NoContentsLayer;
    377 
    378     updateContentsMedia();
    379 
    380     // This has to happen after updateContentsMedia
    381     updateSublayerList();
    382 }
    383 
    384 void GraphicsLayerCACF::setGeometryOrientation(CompositingCoordinatesOrientation orientation)
    385 {
    386     if (orientation == m_geometryOrientation)
    387         return;
    388 
    389     GraphicsLayer::setGeometryOrientation(orientation);
    390     updateGeometryOrientation();
    391 }
    392 
    393 PlatformLayer* GraphicsLayerCACF::hostLayerForSublayers() const
    394 {
    395     return m_transformLayer ? m_transformLayer.get() : m_layer.get();
    396 }
    397 
    398 PlatformLayer* GraphicsLayerCACF::layerForSuperlayer() const
    399 {
    400     return m_transformLayer ? m_transformLayer.get() : m_layer.get();
    401 }
    402 
    403 PlatformLayer* GraphicsLayerCACF::platformLayer() const
    404 {
    405     return primaryLayer();
    406 }
    407 
    408 void GraphicsLayerCACF::setDebugBackgroundColor(const Color& color)
    409 {
    410     if (color.isValid())
    411         setLayerBackgroundColor(m_layer.get(), color);
    412     else
    413         clearLayerBackgroundColor(m_layer.get());
    414 }
    415 
    416 void GraphicsLayerCACF::setDebugBorder(const Color& color, float borderWidth)
    417 {
    418     if (color.isValid()) {
    419         setLayerBorderColor(m_layer.get(), color);
    420         m_layer->setBorderWidth(borderWidth);
    421     } else {
    422         clearBorderColor(m_layer.get());
    423         m_layer->setBorderWidth(0);
    424     }
    425 }
    426 
    427 GraphicsLayer::CompositingCoordinatesOrientation GraphicsLayerCACF::defaultContentsOrientation() const
    428 {
    429     return CompositingCoordinatesTopDown;
    430 }
    431 
    432 void GraphicsLayerCACF::updateSublayerList()
    433 {
    434     Vector<RefPtr<WKCACFLayer> > newSublayers;
    435 
    436     if (m_transformLayer) {
    437         // Add the primary layer first. Even if we have negative z-order children, the primary layer always comes behind.
    438         newSublayers.append(m_layer.get());
    439     } else if (m_contentsLayer) {
    440         // FIXME: add the contents layer in the correct order with negative z-order children.
    441         // This does not cause visible rendering issues because currently contents layers are only used
    442         // for replaced elements that don't have children.
    443         newSublayers.append(m_contentsLayer.get());
    444     }
    445 
    446     const Vector<GraphicsLayer*>& childLayers = children();
    447     size_t numChildren = childLayers.size();
    448     for (size_t i = 0; i < numChildren; ++i) {
    449         GraphicsLayerCACF* curChild = static_cast<GraphicsLayerCACF*>(childLayers[i]);
    450 
    451         WKCACFLayer* childLayer = curChild->layerForSuperlayer();
    452         newSublayers.append(childLayer);
    453     }
    454 
    455     for (int i = 0; i < newSublayers.size(); ++i)
    456         newSublayers[i]->removeFromSuperlayer();
    457 
    458     if (m_transformLayer) {
    459         m_transformLayer->setSublayers(newSublayers);
    460 
    461         if (m_contentsLayer) {
    462             // If we have a transform layer, then the contents layer is parented in the
    463             // primary layer (which is itself a child of the transform layer).
    464             m_layer->removeAllSublayers();
    465             m_layer->addSublayer(m_contentsLayer);
    466         }
    467     } else
    468         m_layer->setSublayers(newSublayers);
    469 }
    470 
    471 void GraphicsLayerCACF::updateLayerPosition()
    472 {
    473     // Position is offset on the layer by the layer anchor point.
    474     CGPoint posPoint = CGPointMake(m_position.x() + m_anchorPoint.x() * m_size.width(),
    475                                    m_position.y() + m_anchorPoint.y() * m_size.height());
    476 
    477     primaryLayer()->setPosition(posPoint);
    478 }
    479 
    480 void GraphicsLayerCACF::updateLayerSize()
    481 {
    482     CGRect rect = CGRectMake(0, 0, m_size.width(), m_size.height());
    483     if (m_transformLayer) {
    484         m_transformLayer->setBounds(rect);
    485         // The anchor of the contents layer is always at 0.5, 0.5, so the position is center-relative.
    486         CGPoint centerPoint = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f);
    487         m_layer->setPosition(centerPoint);
    488     }
    489 
    490     m_layer->setBounds(rect);
    491 
    492     // Note that we don't resize m_contentsLayer. It's up the caller to do that.
    493 
    494     // if we've changed the bounds, we need to recalculate the position
    495     // of the layer, taking anchor point into account.
    496     updateLayerPosition();
    497 }
    498 
    499 void GraphicsLayerCACF::updateAnchorPoint()
    500 {
    501     primaryLayer()->setAnchorPoint(FloatPoint(m_anchorPoint.x(), m_anchorPoint.y()));
    502     primaryLayer()->setAnchorPointZ(m_anchorPoint.z());
    503     updateLayerPosition();
    504 }
    505 
    506 void GraphicsLayerCACF::updateTransform()
    507 {
    508     CATransform3D transform;
    509     copyTransform(transform, m_transform);
    510     primaryLayer()->setTransform(transform);
    511 }
    512 
    513 void GraphicsLayerCACF::updateChildrenTransform()
    514 {
    515     CATransform3D transform;
    516     copyTransform(transform, m_childrenTransform);
    517     primaryLayer()->setSublayerTransform(transform);
    518 }
    519 
    520 void GraphicsLayerCACF::updateMasksToBounds()
    521 {
    522     m_layer->setMasksToBounds(m_masksToBounds);
    523     updateDebugIndicators();
    524 }
    525 
    526 void GraphicsLayerCACF::updateContentsOpaque()
    527 {
    528     m_layer->setOpaque(m_contentsOpaque);
    529 }
    530 
    531 void GraphicsLayerCACF::updateBackfaceVisibility()
    532 {
    533     m_layer->setDoubleSided(m_backfaceVisibility);
    534 }
    535 
    536 void GraphicsLayerCACF::updateLayerPreserves3D()
    537 {
    538     if (m_preserves3D && !m_transformLayer) {
    539         // Create the transform layer.
    540         m_transformLayer = WKCACFLayer::create(WKCACFLayer::TransformLayer, this);
    541 
    542 #ifndef NDEBUG
    543         m_transformLayer->setName(String().format("Transform Layer CATransformLayer(%p) GraphicsLayer(%p)", m_transformLayer.get(), this));
    544 #endif
    545         // Copy the position from this layer.
    546         updateLayerPosition();
    547         updateLayerSize();
    548         updateAnchorPoint();
    549         updateTransform();
    550         updateChildrenTransform();
    551 
    552         CGPoint point = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f);
    553         m_layer->setPosition(point);
    554 
    555         m_layer->setAnchorPoint(CGPointMake(0.5f, 0.5f));
    556         m_layer->setTransform(wkqcCATransform3DIdentity());
    557 
    558         // Set the old layer to opacity of 1. Further down we will set the opacity on the transform layer.
    559         m_layer->setOpacity(1);
    560 
    561         // Move this layer to be a child of the transform layer.
    562         if (m_layer->superlayer())
    563             m_layer->superlayer()->replaceSublayer(m_layer.get(), m_transformLayer.get());
    564         m_transformLayer->addSublayer(m_layer.get());
    565 
    566         updateSublayerList();
    567     } else if (!m_preserves3D && m_transformLayer) {
    568         // Relace the transformLayer in the parent with this layer.
    569         m_layer->removeFromSuperlayer();
    570         m_transformLayer->superlayer()->replaceSublayer(m_transformLayer.get(), m_layer.get());
    571 
    572         // Release the transform layer.
    573         m_transformLayer = 0;
    574 
    575         updateLayerPosition();
    576         updateLayerSize();
    577         updateAnchorPoint();
    578         updateTransform();
    579         updateChildrenTransform();
    580 
    581         updateSublayerList();
    582     }
    583 
    584     updateOpacityOnLayer();
    585 }
    586 
    587 void GraphicsLayerCACF::updateLayerDrawsContent()
    588 {
    589     if (m_drawsContent)
    590         m_layer->setNeedsDisplay();
    591     else
    592         m_layer->setContents(nil);
    593 
    594     updateDebugIndicators();
    595 }
    596 
    597 void GraphicsLayerCACF::updateLayerBackgroundColor()
    598 {
    599     if (!m_contentsLayer)
    600         return;
    601 
    602     // We never create the contents layer just for background color yet.
    603     if (m_backgroundColorSet)
    604         setLayerBackgroundColor(m_contentsLayer.get(), m_backgroundColor);
    605     else
    606         clearLayerBackgroundColor(m_contentsLayer.get());
    607 }
    608 
    609 void GraphicsLayerCACF::updateContentsImage()
    610 {
    611     if (m_pendingContentsImage) {
    612         if (!m_contentsLayer.get()) {
    613             RefPtr<WKCACFLayer> imageLayer = WKCACFLayer::create(WKCACFLayer::Layer, this);
    614 #ifndef NDEBUG
    615             imageLayer->setName("Image Layer");
    616 #endif
    617             setupContentsLayer(imageLayer.get());
    618             m_contentsLayer = imageLayer;
    619             // m_contentsLayer will be parented by updateSublayerList
    620         }
    621 
    622         // FIXME: maybe only do trilinear if the image is being scaled down,
    623         // but then what if the layer size changes?
    624         m_contentsLayer->setMinificationFilter(WKCACFLayer::Trilinear);
    625         m_contentsLayer->setContents(m_pendingContentsImage.get());
    626         m_pendingContentsImage = 0;
    627 
    628         updateContentsRect();
    629     } else {
    630         // No image.
    631         // m_contentsLayer will be removed via updateSublayerList.
    632         m_contentsLayer = 0;
    633     }
    634 }
    635 
    636 void GraphicsLayerCACF::updateContentsMedia()
    637 {
    638     // Media layer was set as m_contentsLayer, and will get parented in updateSublayerList().
    639     if (m_contentsLayer) {
    640         setupContentsLayer(m_contentsLayer.get());
    641         updateContentsRect();
    642     }
    643 }
    644 
    645 void GraphicsLayerCACF::updateContentsRect()
    646 {
    647     if (!m_contentsLayer)
    648         return;
    649 
    650     CGPoint point = CGPointMake(m_contentsRect.x(),
    651                                 m_contentsRect.y());
    652     CGRect rect = CGRectMake(0.0f,
    653                              0.0f,
    654                              m_contentsRect.width(),
    655                              m_contentsRect.height());
    656 
    657     m_contentsLayer->setPosition(point);
    658     m_contentsLayer->setBounds(rect);
    659 }
    660 
    661 void GraphicsLayerCACF::updateGeometryOrientation()
    662 {
    663     switch (geometryOrientation()) {
    664         case CompositingCoordinatesTopDown:
    665             m_layer->setGeometryFlipped(false);
    666             break;
    667 
    668         case CompositingCoordinatesBottomUp:
    669             m_layer->setGeometryFlipped(true);
    670             break;
    671     }
    672     // Geometry orientation is mapped onto children transform in older QuartzCores,
    673     // so is handled via setGeometryOrientation().
    674 }
    675 
    676 void GraphicsLayerCACF::setupContentsLayer(WKCACFLayer* contentsLayer)
    677 {
    678     if (contentsLayer == m_contentsLayer)
    679         return;
    680 
    681     if (m_contentsLayer) {
    682         m_contentsLayer->removeFromSuperlayer();
    683         m_contentsLayer = 0;
    684     }
    685 
    686     if (contentsLayer) {
    687         m_contentsLayer = contentsLayer;
    688 
    689         if (defaultContentsOrientation() == CompositingCoordinatesBottomUp) {
    690             CATransform3D flipper = {
    691                 1.0f, 0.0f, 0.0f, 0.0f,
    692                 0.0f, -1.0f, 0.0f, 0.0f,
    693                 0.0f, 0.0f, 1.0f, 0.0f,
    694                 0.0f, 0.0f, 0.0f, 1.0f};
    695             m_contentsLayer->setTransform(flipper);
    696             m_contentsLayer->setAnchorPoint(CGPointMake(0.0f, 1.0f));
    697         } else
    698             m_contentsLayer->setAnchorPoint(CGPointMake(0.0f, 0.0f));
    699 
    700         // Insert the content layer first. Video elements require this, because they have
    701         // shadow content that must display in front of the video.
    702         m_layer->insertSublayer(m_contentsLayer.get(), 0);
    703 
    704         updateContentsRect();
    705 
    706         if (showDebugBorders()) {
    707             setLayerBorderColor(m_contentsLayer.get(), Color(0, 0, 128, 180));
    708             m_contentsLayer->setBorderWidth(1.0f);
    709         }
    710     }
    711     updateDebugIndicators();
    712 }
    713 
    714 // This function simply mimics the operation of GraphicsLayerCA
    715 void GraphicsLayerCACF::updateOpacityOnLayer()
    716 {
    717     primaryLayer()->setOpacity(m_opacity);
    718 }
    719 
    720 } // namespace WebCore
    721 
    722 #endif // USE(ACCELERATED_COMPOSITING)
    723