2011-01-06 Chris Marrin <cmarrin@apple.com>
authorcmarrin@apple.com <cmarrin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 22:26:35 +0000 (22:26 +0000)
committercmarrin@apple.com <cmarrin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 22:26:35 +0000 (22:26 +0000)
        Reviewed by Simon Fraser.

        Share code between Mac (CA) and Windows (CACF) GraphicsLayer implementations
        https://bugs.webkit.org/show_bug.cgi?id=49388

        Changed PlatformCALayer API. Added PlatformCALayerClient abstract class which is
        used to communicate from PlatformCALayer to the owner. This replaces passing
        GraphicsLayerCA pointer when creating PlatformCALayer. It also includes the
        API that used to be in PlatformCALayerLayout. GraphicsLayerCA now implements
        the PlatformCALayerClient API.

        This change has little impact on the Mac side but makes the Windows
        interface simpler, especially when handling video layers on Windows.

        * WebCore.xcodeproj/project.pbxproj:
        * config.h:
        * platform/graphics/GraphicsLayer.h:
        (WebCore::GraphicsLayer::layerDidDisplay):
        (WebCore::GraphicsLayer::showDebugBorders):
        (WebCore::GraphicsLayer::showRepaintCounter):
        * platform/graphics/ca/GraphicsLayerCA.cpp:
        (WebCore::GraphicsLayerCA::platformCALayerAnimationStarted):
        (WebCore::GraphicsLayerCA::setContentsToImage):
        (WebCore::GraphicsLayerCA::setContentsToMedia):
        (WebCore::GraphicsLayerCA::layerDidDisplay):
        (WebCore::GraphicsLayerCA::updateSublayerList):
        * platform/graphics/ca/GraphicsLayerCA.h:
        (WebCore::GraphicsLayerCA::platformCALayerLayoutSublayersOfLayer):
        (WebCore::GraphicsLayerCA::platformCALayerRespondsToLayoutChanges):
        (WebCore::GraphicsLayerCA::platformCALayerContentsOrientation):
        (WebCore::GraphicsLayerCA::platformCALayerPaintContents):
        (WebCore::GraphicsLayerCA::platformCALayerShowDebugBorders):
        (WebCore::GraphicsLayerCA::platformCALayerShowRepaintCounter):
        (WebCore::GraphicsLayerCA::platformCALayerIncrementRepaintCount):
        (WebCore::GraphicsLayerCA::platformCALayerContentsOpaque):
        (WebCore::GraphicsLayerCA::platformCALayerDrawsContent):
        (WebCore::GraphicsLayerCA::platformCALayerLayerDidDisplay):
        (WebCore::GraphicsLayerCA::platformCALayer):
        * platform/graphics/ca/PlatformCALayer.h:
        (WebCore::PlatformCALayer::owner):
        (WebCore::PlatformCALayer::animationStarted):
        * platform/graphics/ca/PlatformCALayerClient.h: Added.
        (WebCore::PlatformCALayerClient::~PlatformCALayerClient):
        * platform/graphics/ca/mac/PlatformCALayerMac.mm:
        (PlatformCALayer::setOwner):
        (PlatformCALayer::create):
        (PlatformCALayer::PlatformCALayer):
        (PlatformCALayer::contents):
        (PlatformCALayer::setContents):
        * platform/graphics/mac/WebGLLayer.mm:
        (-[WebGLLayer display]):
        * platform/graphics/mac/WebLayer.h:
        * platform/graphics/mac/WebLayer.mm:
        (drawLayerContents):
        (setLayerNeedsDisplayInRect):
        (-[WebLayer setNeedsDisplay]):
        (-[WebLayer display]):
        * platform/graphics/mac/WebTiledLayer.mm:
        (-[WebTiledLayer setNeedsDisplay]):
        (-[WebTiledLayer display]):
        * rendering/RenderLayerBacking.cpp:
        (WebCore::RenderLayerBacking::showDebugBorders):
        (WebCore::RenderLayerBacking::showRepaintCounter):
        * rendering/RenderLayerCompositor.cpp:
        (WebCore::RenderLayerCompositor::ensureRootPlatformLayer):
        * rendering/RenderLayerCompositor.h:
        (WebCore::RenderLayerCompositor::compositorShowDebugBorders):
        (WebCore::RenderLayerCompositor::compositorShowRepaintCounter):
        (WebCore::RenderLayerCompositor::notifyAnimationStarted):
        (WebCore::RenderLayerCompositor::notifySyncRequired):
        (WebCore::RenderLayerCompositor::paintContents):
        (WebCore::RenderLayerCompositor::showDebugBorders):
        (WebCore::RenderLayerCompositor::showRepaintCounter):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@75199 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/config.h
WebCore/platform/graphics/GraphicsLayer.h
WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
WebCore/platform/graphics/ca/GraphicsLayerCA.h
WebCore/platform/graphics/ca/PlatformCALayer.h
WebCore/platform/graphics/ca/PlatformCALayerClient.h [new file with mode: 0644]
WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm
WebCore/platform/graphics/mac/WebGLLayer.mm
WebCore/platform/graphics/mac/WebLayer.h
WebCore/platform/graphics/mac/WebLayer.mm
WebCore/platform/graphics/mac/WebTiledLayer.mm
WebCore/rendering/RenderLayerBacking.cpp
WebCore/rendering/RenderLayerCompositor.cpp
WebCore/rendering/RenderLayerCompositor.h

index 01ebf58..9c5fd00 100644 (file)
@@ -1,3 +1,79 @@
+2011-01-06  Chris Marrin  <cmarrin@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        Share code between Mac (CA) and Windows (CACF) GraphicsLayer implementations
+        https://bugs.webkit.org/show_bug.cgi?id=49388
+
+        Changed PlatformCALayer API. Added PlatformCALayerClient abstract class which is
+        used to communicate from PlatformCALayer to the owner. This replaces passing
+        GraphicsLayerCA pointer when creating PlatformCALayer. It also includes the
+        API that used to be in PlatformCALayerLayout. GraphicsLayerCA now implements
+        the PlatformCALayerClient API.
+
+        This change has little impact on the Mac side but makes the Windows
+        interface simpler, especially when handling video layers on Windows.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * config.h:
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::layerDidDisplay):
+        (WebCore::GraphicsLayer::showDebugBorders):
+        (WebCore::GraphicsLayer::showRepaintCounter):
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::platformCALayerAnimationStarted):
+        (WebCore::GraphicsLayerCA::setContentsToImage):
+        (WebCore::GraphicsLayerCA::setContentsToMedia):
+        (WebCore::GraphicsLayerCA::layerDidDisplay):
+        (WebCore::GraphicsLayerCA::updateSublayerList):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        (WebCore::GraphicsLayerCA::platformCALayerLayoutSublayersOfLayer):
+        (WebCore::GraphicsLayerCA::platformCALayerRespondsToLayoutChanges):
+        (WebCore::GraphicsLayerCA::platformCALayerContentsOrientation):
+        (WebCore::GraphicsLayerCA::platformCALayerPaintContents):
+        (WebCore::GraphicsLayerCA::platformCALayerShowDebugBorders):
+        (WebCore::GraphicsLayerCA::platformCALayerShowRepaintCounter):
+        (WebCore::GraphicsLayerCA::platformCALayerIncrementRepaintCount):
+        (WebCore::GraphicsLayerCA::platformCALayerContentsOpaque):
+        (WebCore::GraphicsLayerCA::platformCALayerDrawsContent):
+        (WebCore::GraphicsLayerCA::platformCALayerLayerDidDisplay):
+        (WebCore::GraphicsLayerCA::platformCALayer):
+        * platform/graphics/ca/PlatformCALayer.h:
+        (WebCore::PlatformCALayer::owner):
+        (WebCore::PlatformCALayer::animationStarted):
+        * platform/graphics/ca/PlatformCALayerClient.h: Added.
+        (WebCore::PlatformCALayerClient::~PlatformCALayerClient):
+        * platform/graphics/ca/mac/PlatformCALayerMac.mm:
+        (PlatformCALayer::setOwner):
+        (PlatformCALayer::create):
+        (PlatformCALayer::PlatformCALayer):
+        (PlatformCALayer::contents):
+        (PlatformCALayer::setContents):
+        * platform/graphics/mac/WebGLLayer.mm:
+        (-[WebGLLayer display]):
+        * platform/graphics/mac/WebLayer.h:
+        * platform/graphics/mac/WebLayer.mm:
+        (drawLayerContents):
+        (setLayerNeedsDisplayInRect):
+        (-[WebLayer setNeedsDisplay]):
+        (-[WebLayer display]):
+        * platform/graphics/mac/WebTiledLayer.mm:
+        (-[WebTiledLayer setNeedsDisplay]):
+        (-[WebTiledLayer display]):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::showDebugBorders):
+        (WebCore::RenderLayerBacking::showRepaintCounter):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::ensureRootPlatformLayer):
+        * rendering/RenderLayerCompositor.h:
+        (WebCore::RenderLayerCompositor::compositorShowDebugBorders):
+        (WebCore::RenderLayerCompositor::compositorShowRepaintCounter):
+        (WebCore::RenderLayerCompositor::notifyAnimationStarted):
+        (WebCore::RenderLayerCompositor::notifySyncRequired):
+        (WebCore::RenderLayerCompositor::paintContents):
+        (WebCore::RenderLayerCompositor::showDebugBorders):
+        (WebCore::RenderLayerCompositor::showRepaintCounter):
+
 2011-01-06  Tony Gentilcore  <tonyg@chromium.org>
 
         Reviewed by Eric Seidel.
index 0c53e09..783e1d2 100644 (file)
                490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; };
                490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */; };
                492863991253B8FC00F792D6 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 492863981253B8FC00F792D6 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 493E5E0812D6420500020081 /* PlatformCALayerClient.h */; };
                49484FC1102CF23C00187DD3 /* CanvasGradient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */; };
                49484FC2102CF23C00187DD3 /* CanvasGradient.h in Headers */ = {isa = PBXBuildFile; fileRef = 49484FB4102CF23C00187DD3 /* CanvasGradient.h */; };
                49484FC4102CF23C00187DD3 /* CanvasPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB6102CF23C00187DD3 /* CanvasPattern.cpp */; };
                490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; };
                490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; };
                492863981253B8FC00F792D6 /* ResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadInfo.h; sourceTree = "<group>"; };
+               493E5E0812D6420500020081 /* PlatformCALayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCALayerClient.h; path = ca/PlatformCALayerClient.h; sourceTree = "<group>"; };
                49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CanvasGradient.cpp; path = canvas/CanvasGradient.cpp; sourceTree = "<group>"; };
                49484FB4102CF23C00187DD3 /* CanvasGradient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CanvasGradient.h; path = canvas/CanvasGradient.h; sourceTree = "<group>"; };
                49484FB5102CF23C00187DD3 /* CanvasGradient.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CanvasGradient.idl; path = canvas/CanvasGradient.idl; sourceTree = "<group>"; };
                                499B3ED5128CD31400E726C2 /* GraphicsLayerCA.h */,
                                499B3EDC128DB50100E726C2 /* PlatformCAAnimation.h */,
                                499B3EC3128CCC4700E726C2 /* PlatformCALayer.h */,
+                               493E5E0812D6420500020081 /* PlatformCALayerClient.h */,
                                494BC40C12AEDD9E00743BD2 /* TransformationMatrixCA.cpp */,
                        );
                        name = ca;
                                7EE6846D12D26E3800E79415 /* ResourceRequest.h in Headers */,
                                7EE6846F12D26E3800E79415 /* ResourceRequestCFNet.h in Headers */,
                                7EE6847012D26E3800E79415 /* ResourceResponse.h in Headers */,
+                               493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 404fa95..49eee8a 100644 (file)
@@ -220,6 +220,11 @@ typedef float CGFloat;
 #define WTF_USE_SAFARI_THEME 1
 #endif
 
+// CoreAnimation is available to IOS, Mac and Windows if using CG
+#if PLATFORM(MAC) || PLATFORM(IOS) || (PLATFORM(WIN) && PLATFORM(CG))
+#define WTF_PLATFORM_CA 1
+#endif
+
 #if PLATFORM(QT) && USE(V8) && defined(Q_WS_X11)
 /* protect ourselves from evil X11 defines */
 #include <bridge/npruntime_internal.h>
index 60638e7..fdc8811 100644 (file)
@@ -53,10 +53,7 @@ typedef CALayer PlatformLayer;
 typedef void* PlatformLayer;
 #endif
 #elif PLATFORM(WIN)
-namespace WebCore {
-class WKCACFLayer;
-typedef WKCACFLayer PlatformLayer;
-}
+typedef struct _CACFLayer PlatformLayer;
 #elif PLATFORM(QT)
 #if USE(TEXTURE_MAPPER)
 namespace WebCore {
@@ -314,7 +311,7 @@ public:
     // Callback from the underlying graphics system to draw layer contents.
     void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip);
     // Callback from the underlying graphics system when the layer has been displayed
-    virtual void didDisplay(PlatformLayer*) { }
+    virtual void layerDidDisplay(PlatformLayer*) { }
     
     // For hosting this GraphicsLayer in a native layer hierarchy.
     virtual PlatformLayer* platformLayer() const { return 0; }
@@ -330,8 +327,8 @@ public:
     virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
     CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
 
-    bool showDebugBorders() { return m_client ? m_client->showDebugBorders() : false; }
-    bool showRepaintCounter() { return m_client ? m_client->showRepaintCounter() : false; }
+    bool showDebugBorders() const { return m_client ? m_client->showDebugBorders() : false; }
+    bool showRepaintCounter() const { return m_client ? m_client->showRepaintCounter() : false; }
     
     void updateDebugIndicators();
     
index 06441d2..c3c58fd 100644 (file)
@@ -640,7 +640,7 @@ void GraphicsLayerCA::removeAnimation(const String& animationName)
     noteLayerPropertyChanged(AnimationChanged);
 }
 
-void GraphicsLayerCA::animationStarted(CFTimeInterval startTime)
+void GraphicsLayerCA::platformCALayerAnimationStarted(CFTimeInterval startTime)
 {
     if (m_client)
         m_client->notifyAnimationStarted(this, startTime);
@@ -660,6 +660,8 @@ void GraphicsLayerCA::setContentsToImage(Image* image)
         
         m_uncorrectedContentsImage = newImage;
         m_pendingContentsImage = newImage;
+
+#if !PLATFORM(WIN)
         CGColorSpaceRef colorSpace = CGImageGetColorSpace(m_pendingContentsImage.get());
 
         static CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB();
@@ -669,6 +671,7 @@ void GraphicsLayerCA::setContentsToImage(Image* image)
             static CGColorSpaceRef genericRGB = CGDisplayCopyColorSpace(kCGDirectMainDisplay);
             m_pendingContentsImage.adoptCF(CGImageCreateCopyWithColorSpace(m_pendingContentsImage.get(), genericRGB));
         }
+#endif
         m_contentsLayerPurpose = ContentsLayerForImage;
         if (!m_contentsLayer)
             noteSublayersChanged();
@@ -688,9 +691,15 @@ void GraphicsLayerCA::setContentsToMedia(PlatformLayer* mediaLayer)
     if (m_contentsLayer && mediaLayer == m_contentsLayer->platformLayer())
         return;
         
-    // Create the PlatformCALayer to wrap the incoming layer
-    m_contentsLayer = mediaLayer ? PlatformCALayer::create(mediaLayer, this) : 0;
-
+    // FIXME: The passed in layer might be a raw layer or an externally created 
+    // PlatformCALayer. To determine this we attempt to get the
+    // PlatformCALayer pointer. If this returns a null pointer we assume it's
+    // raw. This test might be invalid if the raw layer is, for instance, the
+    // PlatformCALayer is using a user data pointer in the raw layer, and
+    // the creator of the raw layer is using it for some other purpose.
+    // For now we don't support such a case.
+    PlatformCALayer* platformCALayer = PlatformCALayer::platformCALayer(mediaLayer);
+    m_contentsLayer = mediaLayer ? (platformCALayer ? platformCALayer : PlatformCALayer::create(mediaLayer, this)) : 0;
     m_contentsLayerPurpose = mediaLayer ? ContentsLayerForMedia : NoContentsLayer;
 
     noteSublayersChanged();
@@ -711,7 +720,7 @@ void GraphicsLayerCA::setContentsToCanvas(PlatformLayer* canvasLayer)
     noteLayerPropertyChanged(ContentsCanvasLayerChanged);
 }
     
-void GraphicsLayerCA::didDisplay(PlatformLayer* layer)
+void GraphicsLayerCA::layerDidDisplay(PlatformLayer* layer)
 {
     PlatformCALayer* currentLayer = PlatformCALayer::platformCALayer(layer);
     PlatformCALayer* sourceLayer;
@@ -903,7 +912,7 @@ void GraphicsLayerCA::updateSublayerList()
             newSublayers.append(childLayer);
         }
 
-        for (size_t i = 0; i < newSublayers.size(); ++i)
+        for (size_t i = 0; i < newSublayers.size(); --i)
             newSublayers[i]->removeFromSuperlayer();
     }
 
index 22921c1..13cbdd1 100644 (file)
@@ -31,6 +31,7 @@
 #include "GraphicsLayer.h"
 #include "Image.h"
 #include "PlatformCAAnimation.h"
+#include "PlatformCALayerClient.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/RetainPtr.h>
@@ -40,7 +41,7 @@ namespace WebCore {
 
 class PlatformCALayer;
 
-class GraphicsLayerCA : public GraphicsLayer {
+class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
 public:
     // The width and height of a single tile in a tiled layer. Should be large enough to
     // avoid lots of small tiles (and therefore lots of drawing callbacks), but small enough
@@ -49,12 +50,11 @@ public:
 
     GraphicsLayerCA(GraphicsLayerClient*);
     virtual ~GraphicsLayerCA();
-    
-    virtual void animationStarted(CFTimeInterval beginTime);
 
     virtual void setName(const String&);
 
     virtual PlatformLayer* platformLayer() const;
+    virtual PlatformCALayer* platformCALayer() const { return primaryLayer(); }
 
     virtual bool setChildren(const Vector<GraphicsLayer*>&);
     virtual void addChild(GraphicsLayer*);
@@ -112,7 +112,7 @@ public:
     virtual void setDebugBackgroundColor(const Color&);
     virtual void setDebugBorder(const Color&, float borderWidth);
 
-    virtual void didDisplay(PlatformLayer*);
+    virtual void layerDidDisplay(PlatformLayer*);
 
     void recursiveCommitChanges();
 
@@ -123,6 +123,21 @@ protected:
     virtual void setOpacityInternal(float);
 
 private:
+    // PlatformCALayerClient overrides
+    virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) { }
+    virtual bool platformCALayerRespondsToLayoutChanges() const { return false; }
+
+    virtual void platformCALayerAnimationStarted(CFTimeInterval beginTime);
+    virtual CompositingCoordinatesOrientation platformCALayerContentsOrientation() const { return contentsOrientation(); }
+    virtual void platformCALayerPaintContents(GraphicsContext& context, const IntRect& clip) { paintGraphicsLayerContents(context, clip); }
+    virtual bool platformCALayerShowDebugBorders() const { return showDebugBorders(); }
+    virtual bool platformCALayerShowRepaintCounter() const { return showRepaintCounter(); }
+    virtual int platformCALayerIncrementRepaintCount() { return incrementRepaintCount(); }
+
+    virtual bool platformCALayerContentsOpaque() const { return contentsOpaque(); }
+    virtual bool platformCALayerDrawsContent() const { return drawsContent(); }
+    virtual void platformCALayerLayerDidDisplay(PlatformLayer* layer) { return layerDidDisplay(layer); }
+
     void updateOpacityOnLayer();
 
     PlatformCALayer* primaryLayer() const { return m_structuralLayer.get() ? m_structuralLayer.get() : m_layer.get(); }
index 9cf0ccb..46f4bbf 100644 (file)
@@ -29,8 +29,8 @@
 #if USE(ACCELERATED_COMPOSITING)
 
 #include "GraphicsContext.h"
-#include "GraphicsLayerCA.h"
 #include "PlatformCAAnimation.h"
+#include "PlatformCALayerClient.h"
 #include "PlatformString.h"
 #include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
@@ -47,27 +47,17 @@ typedef Vector<RefPtr<PlatformCALayer> > PlatformCALayerList;
 
 class PlatformCALayer : public RefCounted<PlatformCALayer> {
 public:
-    // TiledLayer used in GraphicsLayer has constant settings:
-    //      cTiledLayerTileSize = 512
-    //      setTileSize:(cTiledLayerTileSize, cTiledLayerTileSize)
-    //      setLevelsOfDetail:1
-    //      setLevelsOfDetailBias:0
-    //      setContentsGravity:@"bottomLeft"
-    //
-    // TiledLayer also has drawing functions like WebLayer
-    //
-    // WebLayer is a CALayer with drawing functions specific to WebKit
-    //
-    // Layer and TransformLayer are used as is
-
-    enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeTransformLayer, LayerTypeWebTiledLayer, LayerTypeCustom };
+    // LayerTypeRootLayer is used on some platforms. It has no backing store, so setNeedsDisplay
+    // should not call CACFLayerSetNeedsDisplay, but rather just notify the renderer that it
+    // has changed and should be re-rendered.
+    enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeTransformLayer, LayerTypeWebTiledLayer, LayerTypeRootLayer, LayerTypeCustom };
     enum FilterType { Linear, Nearest, Trilinear };
 
-    static PassRefPtr<PlatformCALayer> create(LayerType, GraphicsLayerCA*);
+    static PassRefPtr<PlatformCALayer> create(LayerType, PlatformCALayerClient*);
     
     // This function passes the layer as a void* rather than a PlatformLayer because PlatformLayer
     // is defined differently for Obj C and C++. This allows callers from both languages.
-    static PassRefPtr<PlatformCALayer> create(void* platformLayer, GraphicsLayerCA*);
+    static PassRefPtr<PlatformCALayer> create(void* platformLayer, PlatformCALayerClient*);
 
     ~PlatformCALayer();
     
@@ -76,20 +66,29 @@ public:
     static PlatformCALayer* platformCALayer(void* platformLayer);
     
     PlatformLayer* platformLayer() const;
+
+    PlatformCALayer* rootLayer() const;
     
     static bool isValueFunctionSupported();
     
-    GraphicsLayerCA* owner() const { return m_owner; }
-    void setOwner(GraphicsLayerCA* owner);
+    PlatformCALayerClient* owner() const { return m_owner; }
+    void setOwner(PlatformCALayerClient*);
 
     void animationStarted(CFTimeInterval beginTime)
     {
         if (m_owner)
-            m_owner->animationStarted(beginTime);
+            m_owner->platformCALayerAnimationStarted(beginTime);
     }
 
+    // Layout support
+    void setNeedsLayout();
+
+
     void setNeedsDisplay(const FloatRect* dirtyRect = 0);
     
+    // This tells the layer tree to commit changes and perform a render, without do a setNeedsDisplay on any layer.
+    void setNeedsCommit();
+
     void setContentsChanged();
     
     LayerType layerType() const { return m_layerType; }
@@ -104,6 +103,7 @@ public:
     size_t sublayerCount() const;
 
     // This method removes the sublayers from the source and reparents them to the current layer.
+    // Any sublayers previously in the current layer are removed.
     void adoptSublayers(PlatformCALayer* source);
     
     void addAnimationForKey(const String& key, PlatformCAAnimation* animation);    
@@ -150,8 +150,8 @@ public:
     bool acceleratesDrawing() const;
     void setAcceleratesDrawing(bool);
 
-    void* contents() const;
-    void setContents(void*);
+    CFTypeRef contents() const;
+    void setContents(CFTypeRef);
 
     FloatRect contentsRect() const;
     void setContentsRect(const FloatRect&);
@@ -183,18 +183,25 @@ public:
     CFTimeInterval timeOffset() const;
     void setTimeOffset(CFTimeInterval);
 
+#if PLATFORM(WIN) && !defined(NDEBUG)
+    void printTree() const;
+#endif
+
 protected:
-    PlatformCALayer(LayerType, PlatformLayer*, GraphicsLayerCA*);
+    PlatformCALayer(LayerType, PlatformLayer*, PlatformCALayerClient*);
     
 private:
-    
-    GraphicsLayerCA* m_owner;
+    PlatformCALayerClient* m_owner;
     LayerType m_layerType;
     
 #if PLATFORM(MAC) || PLATFORM(WIN)
     RetainPtr<PlatformLayer> m_layer;
 #endif
 
+#if PLATFORM(WIN)
+    HashMap<String, RefPtr<PlatformCAAnimation> > m_animations;
+#endif
+
 #if PLATFORM(MAC)
 #ifdef __OBJC__
     RetainPtr<NSObject> m_delegate;
diff --git a/WebCore/platform/graphics/ca/PlatformCALayerClient.h b/WebCore/platform/graphics/ca/PlatformCALayerClient.h
new file mode 100644 (file)
index 0000000..ae1815c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef PlatformCALayerClient_h
+#define PlatformCALayerClient_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "GraphicsContext.h"
+#include "GraphicsLayer.h"
+#include "PlatformCAAnimation.h"
+#include "PlatformString.h"
+#include <wtf/HashMap.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class PlatformCALayer;
+
+class PlatformCALayerClient {
+public:
+    virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) = 0;
+    virtual bool platformCALayerRespondsToLayoutChanges() const = 0;
+
+    virtual void platformCALayerAnimationStarted(CFTimeInterval beginTime) = 0;
+    virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const = 0;
+    virtual void platformCALayerPaintContents(GraphicsContext&, const IntRect& inClip) = 0;
+    virtual bool platformCALayerShowDebugBorders() const = 0;
+    virtual bool platformCALayerShowRepaintCounter() const = 0;
+    virtual int platformCALayerIncrementRepaintCount() = 0;
+    
+    virtual bool platformCALayerContentsOpaque() const = 0;
+    virtual bool platformCALayerDrawsContent() const = 0;
+    virtual void platformCALayerLayerDidDisplay(PlatformLayer*) = 0;
+
+protected:
+    virtual ~PlatformCALayerClient() {}
+};
+
+}
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // PlatformCALayerClient_h
index 0aecf14..28460a7 100644 (file)
@@ -105,7 +105,7 @@ bool PlatformCALayer::isValueFunctionSupported()
     return sHaveValueFunction;
 }
 
-void PlatformCALayer::setOwner(GraphicsLayerCA* owner)
+void PlatformCALayer::setOwner(PlatformCALayerClient* owner)
 {
     m_owner = owner;
     
@@ -145,17 +145,17 @@ static NSString* toCAFilterType(PlatformCALayer::FilterType type)
 }
 #endif
 
-PassRefPtr<PlatformCALayer> PlatformCALayer::create(LayerType layerType, GraphicsLayerCA* owner)
+PassRefPtr<PlatformCALayer> PlatformCALayer::create(LayerType layerType, PlatformCALayerClient* owner)
 {
     return adoptRef(new PlatformCALayer(layerType, 0, owner));
 }
 
-PassRefPtr<PlatformCALayer> PlatformCALayer::create(void* platformLayer, GraphicsLayerCA* owner)
+PassRefPtr<PlatformCALayer> PlatformCALayer::create(void* platformLayer, PlatformCALayerClient* owner)
 {
     return adoptRef(new PlatformCALayer(LayerTypeCustom, static_cast<PlatformLayer*>(platformLayer), owner));
 }
 
-PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, GraphicsLayerCA* owner)
+PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, PlatformCALayerClient* owner)
     : m_owner(owner)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS
@@ -168,6 +168,7 @@ PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, Grap
         Class layerClass = Nil;
         switch(layerType) {
             case LayerTypeLayer:
+            case LayerTypeRootLayer:
                 layerClass = [CALayer class];
                 break;
             case LayerTypeWebLayer:
@@ -568,15 +569,15 @@ void PlatformCALayer::setAcceleratesDrawing(bool acceleratesDrawing)
 #endif
 }
 
-void* PlatformCALayer::contents() const
+CFTypeRef PlatformCALayer::contents() const
 {
     return [m_layer.get() contents];
 }
 
-void PlatformCALayer::setContents(void* value)
+void PlatformCALayer::setContents(CFTypeRef value)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-    [m_layer.get() setContents:static_cast<id>(value)];
+    [m_layer.get() setContents:static_cast<id>(const_cast<void*>(value))];
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
index 12c6f0d..c24181b 100644 (file)
@@ -144,7 +144,7 @@ static void freeData(void *, const void *data, size_t /* size */)
 {
     [super display];
     if (m_layerOwner)
-        m_layerOwner->didDisplay(self);
+        m_layerOwner->layerDidDisplay(self);
 }
 
 @end
index 62d69fc..30bf55b 100644 (file)
@@ -32,6 +32,7 @@
 
 namespace WebCore {
     class GraphicsLayer;
+    class PlatformCALayerClient;
 }
 
 #if defined(BUILDING_ON_LEOPARD)
@@ -47,8 +48,8 @@ namespace WebCore {
 @end
 
 // Functions allows us to share implementation across WebTiledLayer and WebLayer
-void drawLayerContents(CGContextRef, CALayer *, WebCore::GraphicsLayer*);
-void setLayerNeedsDisplayInRect(CALayer *, WebCore::GraphicsLayer*, CGRect);
+void drawLayerContents(CGContextRef, CALayer *, WebCore::PlatformCALayerClient*);
+void setLayerNeedsDisplayInRect(CALayer *, WebCore::PlatformCALayerClient*, CGRect);
 
 #endif // USE(ACCELERATED_COMPOSITING)
 
index 4154c10..06ea9be 100644 (file)
@@ -40,7 +40,7 @@ using namespace WebCore;
 
 @implementation WebLayer
 
-void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::GraphicsLayer* layerContents)
+void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::PlatformCALayerClient* layerContents)
 {
     if (!layerContents)
         return;
@@ -48,50 +48,38 @@ void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::GraphicsLa
     CGContextSaveGState(context);
 
     CGRect layerBounds = [layer bounds];
-    if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) {
+    if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) {
         CGContextScaleCTM(context, 1, -1);
         CGContextTranslateCTM(context, 0, -layerBounds.size.height);
     }
 
-    if (layerContents->client()) {
-        [NSGraphicsContext saveGraphicsState];
+    [NSGraphicsContext saveGraphicsState];
 
-        // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
-        // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
-        NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
-        [NSGraphicsContext setCurrentContext:layerContext];
+    // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
+    // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
+    NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
+    [NSGraphicsContext setCurrentContext:layerContext];
 
-        GraphicsContext graphicsContext(context);
+    GraphicsContext graphicsContext(context);
 
-        if (!layerContents->contentsOpaque()) {
-            // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
-            graphicsContext.setShouldSmoothFonts(false);
-        }
-        
-        // It's important to get the clip from the context, because it may be significantly
-        // smaller than the layer bounds (e.g. tiled layers)
-        CGRect clipBounds = CGContextGetClipBoundingBox(context);
-        IntRect clip(enclosingIntRect(clipBounds));
-        layerContents->paintGraphicsLayerContents(graphicsContext, clip);
-
-        [NSGraphicsContext restoreGraphicsState];
+    if (!layerContents->platformCALayerContentsOpaque()) {
+        // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
+        graphicsContext.setShouldSmoothFonts(false);
     }
-#ifndef NDEBUG
-    else {
-        ASSERT_NOT_REACHED();
+    
+    // It's important to get the clip from the context, because it may be significantly
+    // smaller than the layer bounds (e.g. tiled layers)
+    CGRect clipBounds = CGContextGetClipBoundingBox(context);
+    IntRect clip(enclosingIntRect(clipBounds));
+    layerContents->platformCALayerPaintContents(graphicsContext, clip);
 
-        // FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color,
-        // so CA never makes backing store for it (which is what -setNeedsDisplay will do above).
-        CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f);
-        CGContextFillRect(context, layerBounds);
-    }
-#endif
+    [NSGraphicsContext restoreGraphicsState];
 
-    if (layerContents->showRepaintCounter()) {
+    if (layerContents->platformCALayerShowRepaintCounter()) {
         bool isTiledLayer = [layer isKindOfClass:[CATiledLayer class]];
 
         char text[16]; // that's a lot of repaints
-        snprintf(text, sizeof(text), "%d", layerContents->incrementRepaintCount());
+        snprintf(text, sizeof(text), "%d", layerContents->platformCALayerIncrementRepaintCount());
 
         CGContextSaveGState(context);
         if (isTiledLayer)
@@ -117,26 +105,26 @@ void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::GraphicsLa
     CGContextRestoreGState(context);
 }
 
-void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::GraphicsLayer* layerContents, CGRect rect)
+void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::PlatformCALayerClient* layerContents, CGRect rect)
 {
-    if (layerContents && layerContents->client() && layerContents->drawsContent()) {
+    if (layerContents && layerContents->platformCALayerDrawsContent()) {
         struct objc_super layerSuper = { layer, class_getSuperclass(object_getClass(layer)) };
 #if defined(BUILDING_ON_LEOPARD)
         rect = CGRectApplyAffineTransform(rect, [layer contentsTransform]);
 #else
-        if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
+        if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
             rect.origin.y = [layer bounds].size.height - rect.origin.y - rect.size.height;
 #endif
         objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), rect);
 
 #ifndef NDEBUG
-        if (layerContents->showRepaintCounter()) {
+        if (layerContents->platformCALayerShowRepaintCounter()) {
             CGRect bounds = [layer bounds];
             CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 46, 25);
 #if defined(BUILDING_ON_LEOPARD)
             indicatorRect = CGRectApplyAffineTransform(indicatorRect, [layer contentsTransform]);
 #else
-            if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
+            if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
                 indicatorRect.origin.y = [layer bounds].size.height - indicatorRect.origin.y - indicatorRect.size.height;
 #endif
             objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), indicatorRect);
@@ -155,7 +143,7 @@ void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::GraphicsLayer* layerCon
 - (void)setNeedsDisplay
 {
     PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
-    if (layer && layer->owner() && layer->owner()->client() && layer->owner()->drawsContent())
+    if (layer && layer->owner() && layer->owner()->platformCALayerDrawsContent())
         [super setNeedsDisplay];
 }
 
@@ -171,7 +159,7 @@ void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::GraphicsLayer* layerCon
     [super display];
     PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
     if (layer && layer->owner())
-        layer->owner()->didDisplay(self);
+        layer->owner()->platformCALayerLayerDidDisplay(self);
 }
 
 - (void)drawInContext:(CGContextRef)context
index bf35431..e9fa5b7 100644 (file)
@@ -60,7 +60,7 @@ using namespace WebCore;
 - (void)setNeedsDisplay
 {
     PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
-    if (layer && layer->owner() && layer->owner()->client() && layer->owner()->drawsContent())
+    if (layer && layer->owner() && layer->owner()->platformCALayerDrawsContent())
         [super setNeedsDisplay];
 }
 
@@ -76,7 +76,7 @@ using namespace WebCore;
     [super display];
     PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
     if (layer && layer->owner())
-        layer->owner()->didDisplay(self);
+        layer->owner()->platformCALayerLayerDidDisplay(self);
 }
 
 - (void)drawInContext:(CGContextRef)context
index bac514d..1649372 100644 (file)
@@ -1101,12 +1101,12 @@ void RenderLayerBacking::paintContents(const GraphicsLayer*, GraphicsContext& co
 
 bool RenderLayerBacking::showDebugBorders() const
 {
-    return compositor() ? compositor()->showDebugBorders() : false;
+    return compositor() ? compositor()->compositorShowDebugBorders() : false;
 }
 
 bool RenderLayerBacking::showRepaintCounter() const
 {
-    return compositor() ? compositor()->showRepaintCounter() : false;
+    return compositor() ? compositor()->compositorShowRepaintCounter() : false;
 }
 
 bool RenderLayerBacking::startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes)
index fa25348..ce2224f 100644 (file)
@@ -1351,13 +1351,13 @@ void RenderLayerCompositor::ensureRootPlatformLayer()
         if (!m_clipLayer) {
             ASSERT(!m_scrollLayer);
             // Create a clipping layer if this is an iframe
-            m_clipLayer = GraphicsLayer::create(0);
+            m_clipLayer = GraphicsLayer::create(this);
 #ifndef NDEBUG
             m_clipLayer->setName("iframe Clipping");
 #endif
             m_clipLayer->setMasksToBounds(true);
             
-            m_scrollLayer = GraphicsLayer::create(0);
+            m_scrollLayer = GraphicsLayer::create(this);
 #ifndef NDEBUG
             m_scrollLayer->setName("iframe scrolling");
 #endif
index 06c0bcd..1409c06 100644 (file)
@@ -54,11 +54,11 @@ enum CompositingUpdateType {
 // 
 // There is one RenderLayerCompositor per RenderView.
 
-class RenderLayerCompositor {
+class RenderLayerCompositor : public GraphicsLayerClient {
 public:
     RenderLayerCompositor(RenderView*);
     ~RenderLayerCompositor();
-    
+
     // Return true if this RenderView is in "compositing mode" (i.e. has one or more
     // composited RenderLayers)
     bool inCompositingMode() const { return m_compositing; }
@@ -71,9 +71,6 @@ public:
 
     bool canRender3DTransforms() const;
 
-    bool showDebugBorders() const { return m_showDebugBorders; }
-    bool showRepaintCounter() const { return m_showRepaintCounter; }
-    
     // Copy the accelerated compositing related flags from Settings
     void cacheAcceleratedCompositingFlags();
 
@@ -172,7 +169,22 @@ public:
 
     String layerTreeAsText();
 
+    // These are named to avoid conflicts with the functions in GraphicsLayerClient
+    // These return the actual internal variables.
+    bool compositorShowDebugBorders() const { return m_showDebugBorders; }
+    bool compositorShowRepaintCounter() const { return m_showRepaintCounter; }
+
 private:
+    // GraphicsLayerClient Implementation
+    virtual void notifyAnimationStarted(const GraphicsLayer*, double) { }
+    virtual void notifySyncRequired(const GraphicsLayer*) { scheduleSync(); }
+    virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) { }
+
+    // These calls return false always. They are saying that the layers associated with this client
+    // (the clipLayer and scrollLayer) should never show debugging info.
+    virtual bool showDebugBorders() const { return false; }
+    virtual bool showRepaintCounter() const { return false; }
+    
     // Whether the given RL needs a compositing layer.
     bool needsToBeComposited(const RenderLayer*) const;
     // Whether the layer has an intrinsic need for compositing layer.