2010-07-01 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jul 2010 22:23:37 +0000 (22:23 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jul 2010 22:23:37 +0000 (22:23 +0000)
        Reviewed by Anders Carlsson.

        Get accelerated compositing working with webkit2
        https://bugs.webkit.org/show_bug.cgi?id=41084

        Add a new kind of DrawingArea, which is a LayerBackedDrawingArea, which will be used
        when the page goes into accelerated compositing mode. It is not wired up yet.

        * Shared/CoreIPCSupport/DrawingAreaProxyMessageKinds.h: New 'attach' and 'detach' messages
        related to accelerated compositing.

        * UIProcess/API/mac/WKView.mm:
        (-[WKView _startAcceleratedCompositing:]):
        (-[WKView _stopAcceleratedCompositing]):
        * UIProcess/API/mac/WKViewInternal.h:
        Add a subview of the WKView which has layer-backing enabled, and put the drawing area's
        layer inside of that.

        * UIProcess/ChunkedUpdateDrawingAreaProxy.h:
        (WebKit::ChunkedUpdateDrawingAreaProxy::attachCompositingContext):
        (WebKit::ChunkedUpdateDrawingAreaProxy::detachCompositingContext): These methods will never be called
        on the ChunkedUpdateDrawingArea. Stub them out.

        * UIProcess/DrawingAreaProxy.h:
        Add attachCompositingContext() and detachCompositingContext() methods, and a new drawing area
        type to the enum.

        * UIProcess/LayerBackedDrawingAreaProxy.cpp: Added.
        * UIProcess/LayerBackedDrawingAreaProxy.h: Added.
        * UIProcess/mac/LayerBackedDrawingAreaProxyMac.mm: Added.

        * WebKit2.xcodeproj/project.pbxproj: Add LayerBackedDrawingArea files.

        * WebProcess/WebPage/ChunkedUpdateDrawingArea.h: Add virtual methods stubs.

        * WebProcess/WebPage/DrawingArea.cpp:
        (WebKit::DrawingArea::create): Create a LayerBackedDrawingArea if asked.
        * WebProcess/WebPage/DrawingArea.h: New LayerBackedDrawingAreaType type, and new virtual
        methods related to accelerated compositing.

        * WebProcess/WebPage/LayerBackedDrawingArea.cpp: Added.
        * WebProcess/WebPage/LayerBackedDrawingArea.h: Added.
        * WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm: Added.

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

16 files changed:
WebKit2/ChangeLog
WebKit2/Shared/CoreIPCSupport/DrawingAreaProxyMessageKinds.h
WebKit2/UIProcess/API/mac/WKView.mm
WebKit2/UIProcess/API/mac/WKViewInternal.h
WebKit2/UIProcess/ChunkedUpdateDrawingAreaProxy.h
WebKit2/UIProcess/DrawingAreaProxy.h
WebKit2/UIProcess/LayerBackedDrawingAreaProxy.cpp [new file with mode: 0644]
WebKit2/UIProcess/LayerBackedDrawingAreaProxy.h [new file with mode: 0644]
WebKit2/UIProcess/mac/LayerBackedDrawingAreaProxyMac.mm [new file with mode: 0644]
WebKit2/WebKit2.xcodeproj/project.pbxproj
WebKit2/WebProcess/WebPage/ChunkedUpdateDrawingArea.h
WebKit2/WebProcess/WebPage/DrawingArea.cpp
WebKit2/WebProcess/WebPage/DrawingArea.h
WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.cpp [new file with mode: 0644]
WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.h [new file with mode: 0644]
WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm [new file with mode: 0644]

index fd71a6a..b543258 100644 (file)
@@ -1,3 +1,49 @@
+2010-07-01  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        Get accelerated compositing working with webkit2
+        https://bugs.webkit.org/show_bug.cgi?id=41084
+        
+        Add a new kind of DrawingArea, which is a LayerBackedDrawingArea, which will be used
+        when the page goes into accelerated compositing mode. It is not wired up yet.
+
+        * Shared/CoreIPCSupport/DrawingAreaProxyMessageKinds.h: New 'attach' and 'detach' messages
+        related to accelerated compositing.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _startAcceleratedCompositing:]):
+        (-[WKView _stopAcceleratedCompositing]):
+        * UIProcess/API/mac/WKViewInternal.h:
+        Add a subview of the WKView which has layer-backing enabled, and put the drawing area's
+        layer inside of that.
+        
+        * UIProcess/ChunkedUpdateDrawingAreaProxy.h:
+        (WebKit::ChunkedUpdateDrawingAreaProxy::attachCompositingContext):
+        (WebKit::ChunkedUpdateDrawingAreaProxy::detachCompositingContext): These methods will never be called
+        on the ChunkedUpdateDrawingArea. Stub them out.
+
+        * UIProcess/DrawingAreaProxy.h:
+        Add attachCompositingContext() and detachCompositingContext() methods, and a new drawing area
+        type to the enum.
+
+        * UIProcess/LayerBackedDrawingAreaProxy.cpp: Added.
+        * UIProcess/LayerBackedDrawingAreaProxy.h: Added.
+        * UIProcess/mac/LayerBackedDrawingAreaProxyMac.mm: Added.
+
+        * WebKit2.xcodeproj/project.pbxproj: Add LayerBackedDrawingArea files.
+
+        * WebProcess/WebPage/ChunkedUpdateDrawingArea.h: Add virtual methods stubs.
+
+        * WebProcess/WebPage/DrawingArea.cpp:
+        (WebKit::DrawingArea::create): Create a LayerBackedDrawingArea if asked.
+        * WebProcess/WebPage/DrawingArea.h: New LayerBackedDrawingAreaType type, and new virtual
+        methods related to accelerated compositing.
+
+        * WebProcess/WebPage/LayerBackedDrawingArea.cpp: Added.
+        * WebProcess/WebPage/LayerBackedDrawingArea.h: Added.
+        * WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm: Added.
+
 2010-07-01  Kenneth Rohde Christiansen  <kenneth.christiansen@openbossa.org>
 
        Rubberstamped by Sam Weinig.
index 942a280..eb17043 100644 (file)
@@ -34,7 +34,11 @@ namespace DrawingAreaProxyMessage {
 
 enum Kind {
     Update,
-    DidSetSize
+    DidSetSize,
+#if USE(ACCELERATED_COMPOSITING)
+    AttachCompositingContext,
+    DetachCompositingContext,
+#endif
 };
 
 }
index 614b808..60ab248 100644 (file)
@@ -30,6 +30,7 @@
 
 // Implementation
 #import "ChunkedUpdateDrawingAreaProxy.h"
+#import "LayerBackedDrawingAreaProxy.h"
 #import "PageClientImpl.h"
 #import "RunLoop.h"
 #import "WebContext.h"
@@ -54,6 +55,10 @@ using namespace WebCore;
     NSToolTipTag _lastToolTipTag;
     id _trackingRectOwner;
     void* _trackingRectUserData;
+
+#if USE(ACCELERATED_COMPOSITING)
+    NSView* _layerHostingView;
+#endif
 }
 @end
 
@@ -427,4 +432,64 @@ static bool isViewVisible(NSView *view)
     }
 }
 
+#if USE(ACCELERATED_COMPOSITING)
+- (void)_startAcceleratedCompositing:(CALayer*)rootLayer
+{
+    if (!_data->_layerHostingView) {
+        NSView* hostingView = [[NSView alloc] initWithFrame:[self bounds]];
+#if !defined(BUILDING_ON_LEOPARD)
+        [hostingView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
+#endif
+        
+        [self addSubview:hostingView];
+        [hostingView release];
+        // hostingView is owned by being a subview of self
+        _data->_layerHostingView = hostingView;
+    }
+
+    // Make a container layer, which will get sized/positioned by AppKit and CA.
+    CALayer* viewLayer = [CALayer layer];
+
+#if defined(BUILDING_ON_LEOPARD)
+    // Turn off default animations.
+    NSNull *nullValue = [NSNull null];
+    NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:
+                             nullValue, @"anchorPoint",
+                             nullValue, @"bounds",
+                             nullValue, @"contents",
+                             nullValue, @"contentsRect",
+                             nullValue, @"opacity",
+                             nullValue, @"position",
+                             nullValue, @"sublayerTransform",
+                             nullValue, @"sublayers",
+                             nullValue, @"transform",
+                             nil];
+    [viewLayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
+#endif
+
+#if !defined(BUILDING_ON_LEOPARD)
+    // If we aren't in the window yet, we'll use the screen's scale factor now, and reset the scale 
+    // via -viewDidMoveToWindow.
+    CGFloat scaleFactor = [self window] ? [[self window] userSpaceScaleFactor] : [[NSScreen mainScreen] userSpaceScaleFactor];
+    [viewLayer setTransform:CATransform3DMakeScale(scaleFactor, scaleFactor, 1)];
+#endif
+
+    [_data->_layerHostingView setLayer:viewLayer];
+    [_data->_layerHostingView setWantsLayer:YES];
+    
+    // Parent our root layer in the container layer
+    [viewLayer addSublayer:rootLayer];
+}
+
+- (void)_stopAcceleratedCompositing
+{
+    if (_data->_layerHostingView) {
+        [_data->_layerHostingView setLayer:nil];
+        [_data->_layerHostingView setWantsLayer:NO];
+        [_data->_layerHostingView removeFromSuperview];
+        _data->_layerHostingView = nil;
+    }
+}
+#endif // USE(ACCELERATED_COMPOSITING)
+
 @end
index 39c4cc2..c72872d 100644 (file)
@@ -30,4 +30,9 @@
 - (void)_processDidRevive;
 - (void)_takeFocus:(BOOL)direction;
 - (void)_toolTipChangedFrom:(NSString *)oldToolTip to:(NSString *)newToolTip;
+
+#if USE(ACCELERATED_COMPOSITING)
+- (void)_startAcceleratedCompositing:(CALayer*)rootLayer;
+- (void)_stopAcceleratedCompositing;
+#endif
 @end
index 64ac3c2..537a16a 100644 (file)
@@ -77,6 +77,11 @@ private:
     void didSetSize(UpdateChunk*);
     void update(UpdateChunk*);
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual void attachCompositingContext(uint32_t) { }
+    virtual void detachCompositingContext() { }
+#endif
+
     bool m_isWaitingForDidSetFrameNotification;
     bool m_isVisible;
 
index f475a67..62b1ba0 100644 (file)
@@ -50,7 +50,10 @@ typedef HDC PlatformDrawingContext;
 class DrawingAreaProxy {
 public:
     enum Type {
-        ChunkedUpdateDrawingAreaType
+        ChunkedUpdateDrawingAreaType,
+#if USE(ACCELERATED_COMPOSITING)
+        LayerBackedDrawingAreaType,
+#endif
     };
 
     virtual ~DrawingAreaProxy();
@@ -68,6 +71,11 @@ public:
         encoder.encode(static_cast<uint32_t>(m_type));
     }
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual void attachCompositingContext(uint32_t contextID) = 0;
+    virtual void detachCompositingContext() = 0;
+#endif
+
 protected:
     DrawingAreaProxy(Type);
 
diff --git a/WebKit2/UIProcess/LayerBackedDrawingAreaProxy.cpp b/WebKit2/UIProcess/LayerBackedDrawingAreaProxy.cpp
new file mode 100644 (file)
index 0000000..fb87f39
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "LayerBackedDrawingAreaProxy.h"
+
+#include "DrawingAreaMessageKinds.h"
+#include "DrawingAreaProxyMessageKinds.h"
+#include "MessageID.h"
+#include "WebPageProxy.h"
+#include "WebProcessProxy.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+LayerBackedDrawingAreaProxy::LayerBackedDrawingAreaProxy(PlatformWebView* webView)
+    : DrawingAreaProxy(LayerBackedDrawingAreaType)
+    , m_isWaitingForDidSetFrameNotification(false)
+    , m_isVisible(true)
+    , m_webView(webView)
+{
+}
+
+LayerBackedDrawingAreaProxy::~LayerBackedDrawingAreaProxy()
+{
+}
+
+void LayerBackedDrawingAreaProxy::paint(const IntRect& rect, PlatformDrawingContext context)
+{
+}
+
+void LayerBackedDrawingAreaProxy::setSize(const IntSize& viewSize)
+{
+    WebPageProxy* page = this->page();
+    if (!page->isValid())
+        return;
+
+    if (viewSize.isEmpty())
+        return;
+
+    m_viewSize = viewSize;
+    m_lastSetViewSize = viewSize;
+
+    platformSetSize();
+
+    if (m_isWaitingForDidSetFrameNotification)
+        return;
+    m_isWaitingForDidSetFrameNotification = true;
+
+    page->process()->responsivenessTimer()->start();
+    page->process()->connection()->send(DrawingAreaMessage::SetSize, page->pageID(), CoreIPC::In(viewSize));
+}
+
+#if !PLATFORM(MAC)
+void LayerBackedDrawingAreaProxy::platformSetSize()
+{
+}
+#endif
+
+void LayerBackedDrawingAreaProxy::setPageIsVisible(bool isVisible)
+{
+    WebPageProxy* page = this->page();
+
+    if (isVisible == m_isVisible)
+        return;
+    
+    m_isVisible = isVisible;
+    if (!page->isValid())
+        return;
+
+    if (!m_isVisible) {
+        // Tell the web process that it doesn't need to paint anything for now.
+        page->process()->connection()->send(DrawingAreaMessage::SuspendPainting, page->pageID(), CoreIPC::In());
+        return;
+    }
+    
+    // The page is now visible.
+    page->process()->connection()->send(DrawingAreaMessage::ResumePainting, page->pageID(), CoreIPC::In());
+    
+    // FIXME: We should request a full repaint here if needed.
+}
+    
+void LayerBackedDrawingAreaProxy::didSetSize()
+{
+    m_isWaitingForDidSetFrameNotification = false;
+}
+
+void LayerBackedDrawingAreaProxy::update()
+{
+    WebPageProxy* page = this->page();
+    page->process()->connection()->send(DrawingAreaMessage::DidUpdate, page->pageID(), CoreIPC::In());
+}
+
+void LayerBackedDrawingAreaProxy::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments)
+{
+    switch (messageID.get<DrawingAreaProxyMessage::Kind>()) {
+        case DrawingAreaProxyMessage::Update: {
+            update();
+            break;
+        }
+        case DrawingAreaProxyMessage::DidSetSize: {
+            didSetSize();
+            break;
+        }
+#if USE(ACCELERATED_COMPOSITING)
+        case DrawingAreaProxyMessage::AttachCompositingContext: {
+            uint32_t contextID;
+            if (!arguments.decode(CoreIPC::Out(contextID)))
+                return;
+            attachCompositingContext(contextID);
+            break;
+        }
+        case DrawingAreaProxyMessage::DetachCompositingContext: {
+            detachCompositingContext();
+            break;
+        }
+#endif
+        default:
+            ASSERT_NOT_REACHED();
+    }
+}
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebKit2/UIProcess/LayerBackedDrawingAreaProxy.h b/WebKit2/UIProcess/LayerBackedDrawingAreaProxy.h
new file mode 100644 (file)
index 0000000..c5fe67a
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 LayerBackedDrawingAreaProxy_h
+#define LayerBackedDrawingAreaProxy_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "DrawingAreaProxy.h"
+#include <WebCore/IntSize.h>
+
+#if PLATFORM(MAC)
+#include <wtf/RetainPtr.h>
+#ifdef __OBJC__
+@class CALayer;
+@class WKView;
+#else
+class CALayer;
+class WKView;
+#endif
+#endif
+
+namespace WebKit {
+
+class WebPageProxy;
+
+#if PLATFORM(MAC)
+typedef WKView PlatformWebView;
+#elif PLATFORM(WIN)
+class WebView;
+typedef WebView PlatformWebView;
+#endif
+
+class LayerBackedDrawingAreaProxy : public DrawingAreaProxy {
+public:
+    LayerBackedDrawingAreaProxy(PlatformWebView*);
+    virtual ~LayerBackedDrawingAreaProxy();
+
+    // The DrawingAreaProxy should never be decoded itself. Instead, the DrawingArea should be decoded.
+    virtual void encode(CoreIPC::ArgumentEncoder& encoder) const
+    {
+        DrawingAreaProxy::encode(encoder);
+    }
+
+private:
+    WebPageProxy* page();
+
+    // DrawingAreaProxy
+    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&);
+    virtual void paint(const WebCore::IntRect&, PlatformDrawingContext);
+    virtual void setSize(const WebCore::IntSize&);
+    virtual void setPageIsVisible(bool isVisible);
+
+    virtual void attachCompositingContext(uint32_t contextID);
+    virtual void detachCompositingContext();
+    
+    void didSetSize();
+    void update();
+    
+    void platformSetSize();
+
+    bool m_isWaitingForDidSetFrameNotification;
+    bool m_isVisible;
+
+    WebCore::IntSize m_viewSize; // Size of the BackingStore as well.
+    WebCore::IntSize m_lastSetViewSize;
+
+#if PLATFORM(MAC)
+    RetainPtr<CALayer> m_compositingRootLayer;
+#endif
+
+    PlatformWebView* m_webView;
+};
+    
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // LayerBackedDrawingAreaProxy_h
diff --git a/WebKit2/UIProcess/mac/LayerBackedDrawingAreaProxyMac.mm b/WebKit2/UIProcess/mac/LayerBackedDrawingAreaProxyMac.mm
new file mode 100644 (file)
index 0000000..2fa42d8
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#include "LayerBackedDrawingAreaProxy.h"
+
+#include <QuartzCore/QuartzCore.h>
+
+#include "DrawingAreaMessageKinds.h"
+#include "DrawingAreaProxyMessageKinds.h"
+#include "UpdateChunk.h"
+#include "WKAPICast.h"
+#include "WKView.h"
+#include "WKViewInternal.h"
+#include "WebKitSystemInterface.h"
+#include "WebPageProxy.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebPageProxy* LayerBackedDrawingAreaProxy::page()
+{
+    return toWK([m_webView pageRef]);
+}
+
+void LayerBackedDrawingAreaProxy::platformSetSize()
+{
+    [m_compositingRootLayer.get() setBounds:CGRectMake(0, 0, m_viewSize.width(), m_viewSize.height())];
+}
+
+void LayerBackedDrawingAreaProxy::attachCompositingContext(uint32_t contextID)
+{
+    m_compositingRootLayer = WKMakeRenderLayer(contextID);
+
+    // Turn off default animations.
+    NSNull *nullValue = [NSNull null];
+    NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:
+                             nullValue, @"anchorPoint",
+                             nullValue, @"bounds",
+                             nullValue, @"contents",
+                             nullValue, @"contentsRect",
+                             nullValue, @"opacity",
+                             nullValue, @"position",
+                             nullValue, @"sublayerTransform",
+                             nullValue, @"sublayers",
+                             nullValue, @"transform",
+                             nil];
+    [m_compositingRootLayer.get() setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
+    
+    [m_compositingRootLayer.get() setAnchorPoint:CGPointZero];
+    [m_compositingRootLayer.get() setBounds:CGRectMake(0, 0, m_viewSize.width(), m_viewSize.height())];
+    
+    // This is required to anchor the layer at the top, to avoid jiggle during window resize.
+    [m_compositingRootLayer.get() setGeometryFlipped:YES];
+
+    [m_webView _startAcceleratedCompositing:m_compositingRootLayer.get()];
+}
+
+void LayerBackedDrawingAreaProxy::detachCompositingContext()
+{
+    [m_webView _stopAcceleratedCompositing];
+    m_compositingRootLayer = 0;
+}
+
+} // namespace WebKit
index 3df428e..d023904 100644 (file)
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+               0F5265B311DD37680006D33C /* LayerBackedDrawingArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F5265B111DD37680006D33C /* LayerBackedDrawingArea.cpp */; };
+               0F5265B411DD37680006D33C /* LayerBackedDrawingArea.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5265B211DD37680006D33C /* LayerBackedDrawingArea.h */; };
+               0F5265B611DD37700006D33C /* LayerBackedDrawingAreaMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F5265B511DD37700006D33C /* LayerBackedDrawingAreaMac.mm */; };
+               0F5265B911DD377F0006D33C /* LayerBackedDrawingAreaProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F5265B711DD377F0006D33C /* LayerBackedDrawingAreaProxy.cpp */; };
+               0F5265BA11DD377F0006D33C /* LayerBackedDrawingAreaProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5265B811DD377F0006D33C /* LayerBackedDrawingAreaProxy.h */; };
+               0F5265BC11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F5265BB11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm */; };
                1A10475A110A5AD500A43ECD /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AA1C7DE100E846E0078DEBC /* JavaScriptCore.framework */; };
                1A1C4EC810D06099005E67E7 /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AA1C79A100E7FC50078DEBC /* WebCore.framework */; };
                1A30066E1110F4F70031937C /* ResponsivenessTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A30066C1110F4F70031937C /* ResponsivenessTimer.h */; };
 /* Begin PBXFileReference section */
                0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
                089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+               0F5265B111DD37680006D33C /* LayerBackedDrawingArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayerBackedDrawingArea.cpp; sourceTree = "<group>"; };
+               0F5265B211DD37680006D33C /* LayerBackedDrawingArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayerBackedDrawingArea.h; sourceTree = "<group>"; };
+               0F5265B511DD37700006D33C /* LayerBackedDrawingAreaMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LayerBackedDrawingAreaMac.mm; sourceTree = "<group>"; };
+               0F5265B711DD377F0006D33C /* LayerBackedDrawingAreaProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayerBackedDrawingAreaProxy.cpp; sourceTree = "<group>"; };
+               0F5265B811DD377F0006D33C /* LayerBackedDrawingAreaProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayerBackedDrawingAreaProxy.h; sourceTree = "<group>"; };
+               0F5265BB11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LayerBackedDrawingAreaProxyMac.mm; sourceTree = "<group>"; };
                1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
                1A30066C1110F4F70031937C /* ResponsivenessTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResponsivenessTimer.h; sourceTree = "<group>"; };
                1A30EAC5115D7DA30053E937 /* ConnectionMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConnectionMac.cpp; sourceTree = "<group>"; };
                                BC8452A61162C80900CAB9B5 /* DrawingArea.h */,
                                BC5F7BB21182376C0052C02C /* ChunkedUpdateDrawingArea.cpp */,
                                BC5F7BB31182376C0052C02C /* ChunkedUpdateDrawingArea.h */,
+                               0F5265B111DD37680006D33C /* LayerBackedDrawingArea.cpp */,
+                               0F5265B211DD37680006D33C /* LayerBackedDrawingArea.h */,
                                BC111ADC112F5B9300337BAB /* WebFrame.cpp */,
                                BC032D8910F437A00058C15A /* WebFrame.h */,
                                BC963D6A113DD19200574BE2 /* WebPage.cpp */,
                                BC2652141182608100243E12 /* ChunkedUpdateDrawingAreaProxy.cpp */,
                                BC2652151182608100243E12 /* ChunkedUpdateDrawingAreaProxy.h */,
                                BC17753E118BABF0007D9E9A /* GenericCallback.h */,
+                               0F5265B711DD377F0006D33C /* LayerBackedDrawingAreaProxy.cpp */,
+                               0F5265B811DD377F0006D33C /* LayerBackedDrawingAreaProxy.h */,
                                BC6EDAA5111271C600E7678B /* PageClient.h */,
                                BC597074116591D000551FCA /* ProcessModel.h */,
                                BC111B08112F5E3C00337BAB /* ResponsivenessTimer.cpp */,
                        isa = PBXGroup;
                        children = (
                                BC5F7BB8118237990052C02C /* ChunkedUpdateDrawingAreaMac.cpp */,
+                               0F5265B511DD37700006D33C /* LayerBackedDrawingAreaMac.mm */,
                                BC963D6D113DD1A500574BE2 /* WebPageMac.mm */,
                        );
                        path = mac;
                        isa = PBXGroup;
                        children = (
                                BC2651F511825EF800243E12 /* ChunkedUpdateDrawingAreaProxyMac.mm */,
+                               0F5265BB11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                BCD25F1711D6BDE100169B0E /* WKBundleFrame.h in Headers */,
                                BC64680311DBBA73006455B0 /* WKArray.h in Headers */,
                                BC64697011DBE603006455B0 /* ImmutableArray.h in Headers */,
+                               0F5265B411DD37680006D33C /* LayerBackedDrawingArea.h in Headers */,
+                               0F5265BA11DD377F0006D33C /* LayerBackedDrawingAreaProxy.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                BCD25F1811D6BDE100169B0E /* WKBundleFrame.cpp in Sources */,
                                BC64680B11DBBD69006455B0 /* WKArray.cpp in Sources */,
                                BC64696F11DBE603006455B0 /* ImmutableArray.cpp in Sources */,
+                               0F5265B311DD37680006D33C /* LayerBackedDrawingArea.cpp in Sources */,
+                               0F5265B611DD37700006D33C /* LayerBackedDrawingAreaMac.mm in Sources */,
+                               0F5265B911DD377F0006D33C /* LayerBackedDrawingAreaProxy.cpp in Sources */,
+                               0F5265BC11DD37860006D33C /* LayerBackedDrawingAreaProxyMac.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index bc00f01..13ae3fa 100644 (file)
@@ -46,6 +46,13 @@ public:
     virtual void setNeedsDisplay(const WebCore::IntRect&);
     virtual void display();
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual void attachCompositingContext(WebCore::GraphicsLayer*) { }
+    virtual void detachCompositingContext() { }
+    virtual void scheduleCompositingLayerSync() { }
+    virtual void syncCompositingLayers() { }
+#endif
+
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&);
 
 private:
index 4eb04dc..16a6914 100644 (file)
@@ -27,6 +27,9 @@
 
 // Subclasses
 #include "ChunkedUpdateDrawingArea.h"
+#if USE(ACCELERATED_COMPOSITING)
+#include "LayerBackedDrawingArea.h"
+#endif
 
 namespace WebKit {
 
@@ -37,6 +40,11 @@ DrawingArea* DrawingArea::create(Type type, WebPage* webPage)
         case ChunkedUpdateDrawingAreaType:
             drawingArea = new ChunkedUpdateDrawingArea(webPage);
             break;
+#if USE(ACCELERATED_COMPOSITING)
+        case LayerBackedDrawingAreaType:
+            drawingArea = new LayerBackedDrawingArea(webPage);
+            break;
+#endif
     }
 
     return drawingArea;
index 2dea320..9494249 100644 (file)
@@ -31,6 +31,9 @@
 namespace WebCore {
     class IntRect;
     class IntSize;
+#if USE(ACCELERATED_COMPOSITING)
+    class GraphicsLayer;
+#endif
 }
 
 namespace CoreIPC {
@@ -46,7 +49,10 @@ class WebPage;
 class DrawingArea {
 public:
     enum Type {
-        ChunkedUpdateDrawingAreaType
+        ChunkedUpdateDrawingAreaType,
+#if USE(ACCELERATED_COMPOSITING)
+        LayerBackedDrawingAreaType,
+#endif
     };
 
     // FIXME: It might make sense to move this create function into a factory style class. 
@@ -61,6 +67,13 @@ public:
     virtual void setNeedsDisplay(const WebCore::IntRect&) = 0;
     virtual void display() = 0;
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual void attachCompositingContext(WebCore::GraphicsLayer*) = 0;
+    virtual void detachCompositingContext() = 0;
+    virtual void scheduleCompositingLayerSync() = 0;
+    virtual void syncCompositingLayers() = 0;
+#endif
+
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&) = 0;
 
     // The DrawingArea should never be encoded itself. Instead, the DrawingAreaProxy should be encoded.
diff --git a/WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.cpp b/WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.cpp
new file mode 100644 (file)
index 0000000..dc8da7c
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "LayerBackedDrawingArea.h"
+
+#include "DrawingAreaMessageKinds.h"
+#include "DrawingAreaProxyMessageKinds.h"
+#include "MessageID.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebPage.h"
+#include "WebProcess.h"
+#include <WebCore/GraphicsLayer.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+LayerBackedDrawingArea::LayerBackedDrawingArea(WebPage* webPage)
+    : DrawingArea(LayerBackedDrawingAreaType, webPage)
+    , m_syncTimer(WebProcess::shared().runLoop(), this, &LayerBackedDrawingArea::syncCompositingLayers)
+#if PLATFORM(MAC)
+    , m_remoteLayerRef(0)
+#endif
+    , m_attached(false)
+    , m_shouldPaint(true)
+{
+    m_backingLayer = GraphicsLayer::create(this);
+    m_backingLayer->setDrawsContent(true);
+#ifndef NDEBUG
+    m_backingLayer->setName("DrawingArea backing layer");
+#endif
+    m_backingLayer->syncCompositingStateForThisLayerOnly();
+    
+    platformInit();
+}
+
+LayerBackedDrawingArea::~LayerBackedDrawingArea()
+{
+    platformClear();
+}
+
+void LayerBackedDrawingArea::invalidateWindow(const IntRect& rect, bool immediate)
+{
+
+}
+
+void LayerBackedDrawingArea::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
+{
+    setNeedsDisplay(rect);
+}
+
+void LayerBackedDrawingArea::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
+{
+    setNeedsDisplay(rect);
+}
+
+void LayerBackedDrawingArea::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
+{
+    // FIXME: Do something much smarter.
+    setNeedsDisplay(rectToScroll);
+}
+
+void LayerBackedDrawingArea::setNeedsDisplay(const IntRect& rect)
+{
+    if (!m_remoteLayerRef)
+        attachCompositingContext(0);
+
+    m_backingLayer->setNeedsDisplayInRect(rect);
+    m_backingLayer->syncCompositingStateForThisLayerOnly();
+
+#if PLATFORM(MAC)
+    scheduleUpdateLayoutRunLoopObserver();
+#endif
+}
+
+void LayerBackedDrawingArea::display()
+{
+    // Layout if necessary.
+    m_webPage->layoutIfNeeded();
+}
+
+void LayerBackedDrawingArea::scheduleDisplay()
+{
+}
+
+void LayerBackedDrawingArea::setSize(const IntSize& viewSize)
+{
+    ASSERT(m_shouldPaint);
+    ASSERT_ARG(viewSize, !viewSize.isEmpty());
+
+    m_backingLayer->setSize(viewSize);
+    m_backingLayer->syncCompositingStateForThisLayerOnly();
+    
+    m_webPage->setSize(viewSize);
+
+    // Layout if necessary.
+    m_webPage->layoutIfNeeded();
+
+    WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(0));
+}
+
+void LayerBackedDrawingArea::suspendPainting()
+{
+    ASSERT(m_shouldPaint);
+    
+    m_shouldPaint = false;
+}
+
+void LayerBackedDrawingArea::resumePainting()
+{
+    ASSERT(!m_shouldPaint);
+    
+    m_shouldPaint = true;
+    
+    // Display if needed.
+    display();
+}
+
+void LayerBackedDrawingArea::didUpdate()
+{
+
+    // Display if needed.
+    display();
+}
+
+void LayerBackedDrawingArea::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments)
+{
+    switch (messageID.get<DrawingAreaMessage::Kind>()) {
+        case DrawingAreaMessage::SetSize: {
+            IntSize size;
+            if (!arguments.decode(CoreIPC::Out(size)))
+                return;
+
+            setSize(size);
+            break;
+        }
+        
+        case DrawingAreaMessage::SuspendPainting:
+            suspendPainting();
+            break;
+
+        case DrawingAreaMessage::ResumePainting:
+            resumePainting();
+            break;
+
+        case DrawingAreaMessage::DidUpdate:
+            didUpdate();
+            break;
+
+        default:
+            ASSERT_NOT_REACHED();
+            break;
+    }
+}
+
+// GraphicsLayerClient methods
+void LayerBackedDrawingArea::paintContents(const GraphicsLayer*, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& inClip)
+{
+    m_webPage->drawRect(graphicsContext, inClip);
+}
+
+bool LayerBackedDrawingArea::showDebugBorders() const
+{
+    // FIXME: get from settings;
+    return false;
+}
+
+bool LayerBackedDrawingArea::showRepaintCounter() const
+{
+    // FIXME: get from settings;
+    return false;
+}
+
+#if !PLATFORM(MAC)
+void LayerBackedDrawingArea::attachCompositingContext(GraphicsLayer*)
+{
+}
+
+void LayerBackedDrawingArea::detachCompositingContext()
+{
+}
+
+void LayerBackedDrawingArea::scheduleCompositingLayerSync()
+{
+}
+
+void LayerBackedDrawingArea::syncCompositingLayers()
+{
+}
+
+void LayerBackedDrawingArea::platformInit()
+{
+}
+
+void LayerBackedDrawingArea::platformClear()
+{
+}
+#endif
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.h b/WebKit2/WebProcess/WebPage/LayerBackedDrawingArea.h
new file mode 100644 (file)
index 0000000..abaa333
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 LayerBackedDrawingArea_h
+#define LayerBackedDrawingArea_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "DrawingArea.h"
+#include "RunLoop.h"
+#include <WebCore/IntPoint.h>
+#include <WebCore/GraphicsLayerClient.h>
+
+#if PLATFORM(MAC)
+#include <wtf/RetainPtr.h>
+#ifdef __OBJC__
+@class CALayer;
+#else
+class CALayer;
+#endif
+typedef struct __WKCARemoteLayerClientRef *WKCARemoteLayerClientRef;
+#endif
+
+namespace WebCore {
+    class GraphicsContext;
+    class GraphicsLayer;
+    class IntRect;
+}
+
+namespace WebKit {
+
+class LayerBackedDrawingArea : public DrawingArea, private WebCore::GraphicsLayerClient {
+public:
+    LayerBackedDrawingArea(WebPage*);
+    virtual ~LayerBackedDrawingArea();
+
+    virtual void invalidateWindow(const WebCore::IntRect& rect, bool immediate);
+    virtual void invalidateContentsAndWindow(const WebCore::IntRect& rect, bool immediate);
+    virtual void invalidateContentsForSlowScroll(const WebCore::IntRect& rect, bool immediate);
+    virtual void scroll(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& rectToScroll, const WebCore::IntRect& clipRect);
+    virtual void setNeedsDisplay(const WebCore::IntRect&);
+    virtual void display();
+
+    virtual void attachCompositingContext(WebCore::GraphicsLayer*);
+    virtual void detachCompositingContext();
+    virtual void scheduleCompositingLayerSync();
+    virtual void syncCompositingLayers();
+
+    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&);
+
+private:
+
+    // GraphicsLayerClient
+    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double /*time*/) { }
+    virtual void notifySyncRequired(const WebCore::GraphicsLayer*) { }
+public:
+    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& inClip);
+private:
+    virtual bool showDebugBorders() const;
+    virtual bool showRepaintCounter() const;
+
+    void scheduleDisplay();
+    
+    // CoreIPC message handlers.
+    void setSize(const WebCore::IntSize& viewSize);
+    void suspendPainting();
+    void resumePainting();
+    void didUpdate();
+    
+    void platformInit();
+    void platformClear();
+
+#if PLATFORM(MAC)
+    void setUpUpdateLayoutRunLoopObserver();
+    void scheduleUpdateLayoutRunLoopObserver();
+    void removeUpdateLayoutRunLoopObserver();
+
+    static void updateLayoutRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void*);
+    void updateLayoutRunLoopObserverFired();
+#endif
+
+    RunLoop::Timer<LayerBackedDrawingArea> m_syncTimer;
+
+    OwnPtr<WebCore::GraphicsLayer> m_backingLayer;
+#if PLATFORM(MAC)
+    RetainPtr<WKCARemoteLayerClientRef> m_remoteLayerRef;
+    RetainPtr<CFRunLoopObserverRef> m_updateLayoutRunLoopObserver;
+#endif
+
+    bool m_attached;
+    bool m_shouldPaint;
+};
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // LayerBackedDrawingArea_h
diff --git a/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm b/WebKit2/WebProcess/WebPage/mac/LayerBackedDrawingAreaMac.mm
new file mode 100644 (file)
index 0000000..cc653e4
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "LayerBackedDrawingArea.h"
+
+#include "DrawingAreaProxyMessageKinds.h"
+#include "WebKitSystemInterface.h"
+#include "WebPage.h"
+#include "WebProcess.h"
+#include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GraphicsLayer.h>
+#include <WebCore/Page.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void LayerBackedDrawingArea::platformInit()
+{
+    setUpUpdateLayoutRunLoopObserver();
+}
+
+void LayerBackedDrawingArea::platformClear()
+{
+    if (m_updateLayoutRunLoopObserver) {
+        CFRunLoopObserverInvalidate(m_updateLayoutRunLoopObserver.get());
+        m_updateLayoutRunLoopObserver = 0;
+    }
+
+    WKCARemoteLayerClientInvalidate(m_remoteLayerRef.get());
+    m_remoteLayerRef = 0;
+}
+
+void LayerBackedDrawingArea::attachCompositingContext(GraphicsLayer* layer)
+{
+    m_backingLayer->removeAllChildren();
+    if (layer) {
+        m_backingLayer->addChild(layer);
+    }
+
+    m_backingLayer->syncCompositingState();     // FIXME: hack
+    
+    m_backingLayer->setDebugBorder(Color(0, 0, 255, 0.6), 4);
+    
+    if (m_attached)
+        return;
+        
+    m_attached = true;
+
+    mach_port_t serverPort = 0; // FIXME: will use WebProcess::shared().compositingRenderServerPort();
+    m_remoteLayerRef = WKCARemoteLayerClientMakeWithServerPort(serverPort);
+    WKCARemoteLayerClientSetLayer(m_remoteLayerRef.get(), m_backingLayer->platformLayer());
+    
+    uint32_t contextID = WKCARemoteLayerClientGetClientId(m_remoteLayerRef.get());
+    WebProcess::shared().connection()->send(DrawingAreaProxyMessage::AttachCompositingContext, m_webPage->pageID(), CoreIPC::In(contextID));
+}
+
+void LayerBackedDrawingArea::detachCompositingContext()
+{
+    m_backingLayer->removeAllChildren();
+    m_backingLayer->syncCompositingState();     // FIXME: hack
+}
+
+void LayerBackedDrawingArea::scheduleCompositingLayerSync()
+{
+//    if (m_syncTimer.isActive())
+//        return;
+//
+//    m_syncTimer.startOneShot(0);
+
+    scheduleUpdateLayoutRunLoopObserver();
+}
+
+void LayerBackedDrawingArea::syncCompositingLayers()
+{
+    bool didSync = m_webPage->corePage()->mainFrame()->view()->syncCompositingStateRecursive();
+    if (!didSync) {
+    
+    }
+}
+
+void LayerBackedDrawingArea::setUpUpdateLayoutRunLoopObserver()
+{
+    if (m_updateLayoutRunLoopObserver)
+        return;
+
+    // Run before Core Animations commit observer, which has order 2000000.
+    const CFIndex runLoopOrder = 2000000 - 1;
+    CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
+    m_updateLayoutRunLoopObserver.adoptCF(CFRunLoopObserverCreate(0,
+        kCFRunLoopBeforeWaiting | kCFRunLoopExit, true /* repeats */,
+        runLoopOrder, updateLayoutRunLoopObserverCallback, &context));
+}
+
+void LayerBackedDrawingArea::scheduleUpdateLayoutRunLoopObserver()
+{
+    CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
+    if (CFRunLoopContainsObserver(currentRunLoop, m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes))
+        return;
+
+    CFRunLoopAddObserver(currentRunLoop, m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes);
+}
+
+void LayerBackedDrawingArea::removeUpdateLayoutRunLoopObserver()
+{
+    // FIXME: cache the run loop ref?
+    CFRunLoopRemoveObserver(CFRunLoopGetCurrent(), m_updateLayoutRunLoopObserver.get(), kCFRunLoopCommonModes);
+}
+
+void LayerBackedDrawingArea::updateLayoutRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* info)
+{
+    LayerBackedDrawingArea* drawingArea = reinterpret_cast<LayerBackedDrawingArea*>(info);
+    drawingArea->updateLayoutRunLoopObserverFired();
+}
+
+void LayerBackedDrawingArea::updateLayoutRunLoopObserverFired()
+{
+    m_webPage->layoutIfNeeded();
+    syncCompositingLayers();
+}
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)