Paint directly into a GraphicsLayer when using accelerated compositing
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jan 2011 01:45:56 +0000 (01:45 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jan 2011 01:45:56 +0000 (01:45 +0000)
Before this patch, we were painting into our normal backing store
HBITMAP, wrapping it in a CGImage, and handing it off to Core
Animation. This had at least two disadvantages:
   1) The bitmap could be modified while Core Animation was using it.
   2) It introduced extra complexity.

When entering accelerated compositing mode, WebView now creates a
GraphicsLayer to draw into. This GraphicsLayer sits between the root
layer (owned by WKCACFLayerRenderer) and the RenderView's layer. When
WebView invalidates, it just calls setNeedsDisplayInRect on its
GraphicsLayer. When WebView paints, it just tells its
WKCACFLayerRenderer to paint, which will call back to WebView to draw
into the GraphicsLayer if it has a dirty region. This is very similar
to the current implementation of LayerBackedDrawingArea in WebKit2.

Fixes <http://webkit.org/b/52582> WebView should paint directly into a
GraphicsLayer when in accelerated compositing mode

Reviewed by Simon Fraser and Chris Marrin.

WebCore:

Remove special-cased support for providing content for the root layer

Clients will just have to provide content through the normal
GraphicsLayer channels now!

* platform/graphics/win/WKCACFLayerRenderer.cpp:
(WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer): Removed
initialization of m_backingStoreDirty, which has itself been removed.
(WebCore::WKCACFLayerRenderer::setNeedsDisplay): Moved code to schedule
a sync from here to syncCompositingStateSoon. We only need to call
renderSoon if we don't call syncCompositingStateSoon; the latter
function calls the former.
(WebCore::WKCACFLayerRenderer::paint): Removed code to handle
m_backingStoreDirty. We don't want to know anything about clients'
backing stores.
(WebCore::WKCACFLayerRenderer::syncCompositingStateSoon): Added. Code
came from setNeedsDisplay.

* platform/graphics/win/WKCACFLayerRenderer.h:
Removed setRootContents[AndDisplay], setBackingStoreDirty, and
m_backingStoreDirty. Made paint() public so that clients can force a
synchronous render (e.g., when handling WM_PAINT).

WebKit/win:

* WebCoreSupport/WebChromeClient.cpp:
(WebChromeClient::attachRootGraphicsLayer):
(WebChromeClient::scheduleCompositingLayerSync):
Updated for WebView changes.

* WebView.cpp:
(WebView::repaint): When using accelerated compositing, just invalidate
our backing layer. This matches the behavior of LayerBackedDrawingArea.
(WebView::deleteBackingStore): Removed accelerated compositing code.
The WKCACFLayerRenderer doesn't need to know about our backing store
anymore; we don't use it at all when in accelerated compositing mode.
(WebView::addToDirtyRegion): When using accelerated compositing, just
invalidate our backing layer.
(WebView::scrollBackingStore): Added an assertion that this isn't
called in accelerated compositing mode.
(WebView::sizeChanged): Update our backing layer's size, too, and
invalidate it.
(WebView::updateBackingStore): Added an assertion that this isn't
called in accelerated compositing mode.
(WebView::paint): If we're in accelerated compositing mode, sync our
compositing state. If we're *still* in accelerated compositing mode,
just tell our WKCACFLayerRenderer to paint and clear our dirty region.
(The later changes in this function are just un-indenting code that
used to be inside an if.)

(WebView::paintIntoBackingStore):
(WebView::paintIntoWindow):
Added assertions that these aren't called in accelerated compositing
mode.

(WebView::WebViewWndProc): Updated WM_XP_THEMECHANGED handling for
removal of setRootLayerNeedsDisplay.
(WebView::setRootChildLayer): Changed to take a GraphicsLayer. We now
set the layer as a child of our own backing layer.
(WebView::scheduleCompositingLayerSync): Just call through to
WKCACFLayerRenderer.
(WebView::setAcceleratedCompositing): Create our backing layer and set
it as the child of WKCACFLayerRenderer's root layer.
(WebView::notifyAnimationStarted): Added. We never expect this
GraphicsLayerClient override to be called, as we don't use animations
on our backing layer.
(WebView::notifySyncRequired): Added. Just schedule a sync.
(WebView::paintContents): Added. Just clip and paint!

(WebView::showDebugBorders):
(WebView::showRepaintCounter):
Added. These just call through to Settings.

(WebView::syncCompositingState): Changed to first update layout, then
sync state for our backing layer, then sync WebCore's state. This
matches LayerBackedDrawingArea.

* WebView.h: WebView now implements the GraphicsLayerClient interface.
Removed setRootLayerNeedsDisplay; it's been replaced by calling
setNeedsDisplay on our backing layer and calling
syncCompositingStateSoon on WKCACFLayerRenderer as needed. Removed
updateRootLayerContents; that function was used to pass our backing
store to Core Animation, which we no longer do. Added m_backingLayer.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h

index db5846d1a14b556670ad3fb758d584743da45d58..8e9d79aa6c87aa77e7e3a5a712d8bde793c282de 100644 (file)
@@ -1,3 +1,33 @@
+2011-01-17  Adam Roben  <aroben@apple.com>
+
+        Remove special-cased support for providing content for the root layer
+
+        Clients will just have to provide content through the normal
+        GraphicsLayer channels now!
+
+        Support for <http://webkit.org/b/52582> WebView should paint directly
+        into a GraphicsLayer when in accelerated compositing mode
+
+        Reviewed by Simon Fraser and Chris Marrin.
+
+        * platform/graphics/win/WKCACFLayerRenderer.cpp:
+        (WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer): Removed
+        initialization of m_backingStoreDirty, which has itself been removed.
+        (WebCore::WKCACFLayerRenderer::setNeedsDisplay): Moved code to schedule
+        a sync from here to syncCompositingStateSoon. We only need to call
+        renderSoon if we don't call syncCompositingStateSoon; the latter
+        function calls the former.
+        (WebCore::WKCACFLayerRenderer::paint): Removed code to handle
+        m_backingStoreDirty. We don't want to know anything about clients'
+        backing stores.
+        (WebCore::WKCACFLayerRenderer::syncCompositingStateSoon): Added. Code
+        came from setNeedsDisplay.
+
+        * platform/graphics/win/WKCACFLayerRenderer.h:
+        Removed setRootContents[AndDisplay], setBackingStoreDirty, and
+        m_backingStoreDirty. Made paint() public so that clients can force a
+        synchronous render (e.g., when handling WM_PAINT).
+
 2011-01-17  Adam Roben  <aroben@apple.com>
 
         Remove contexts from WKCACFContextFlusher before destroying them
index 4d77fbdeaacfee4e3f755c0b9e665f044ea934f3..d7e7e13574fe763467850f1e60b6ed519ed41590 100644 (file)
@@ -187,7 +187,6 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client)
     , m_context(wkCACFContextCreate())
     , m_hostWindow(0)
     , m_renderTimer(this, &WKCACFLayerRenderer::renderTimerFired)
-    , m_backingStoreDirty(false)
     , m_mustResetLostDeviceBeforeRendering(false)
     , m_syncLayerChanges(false)
 {
@@ -239,20 +238,6 @@ void WKCACFLayerRenderer::addPendingAnimatedLayer(PassRefPtr<PlatformCALayer> la
     m_pendingAnimatedLayers.add(layer);
 }
 
-void WKCACFLayerRenderer::setRootContents(CGImageRef image)
-{
-    ASSERT(m_rootLayer);
-    m_rootLayer->setContents(image);
-    renderSoon();
-}
-
-void WKCACFLayerRenderer::setRootContentsAndDisplay(CGImageRef image)
-{
-    ASSERT(m_rootLayer);
-    m_rootLayer->setContents(image);
-    paint();
-}
-
 void WKCACFLayerRenderer::setRootChildLayer(PlatformCALayer* layer)
 {
     m_rootLayer->removeAllSublayers();
@@ -269,12 +254,13 @@ void WKCACFLayerRenderer::layerTreeDidChange()
 
 void WKCACFLayerRenderer::setNeedsDisplay(bool sync)
 {
-    if (!m_syncLayerChanges && sync)
-        m_syncLayerChanges = true;
-
     ASSERT(m_rootLayer);
     m_rootLayer->setNeedsDisplay(0);
-    renderSoon();
+
+    if (sync)
+        syncCompositingStateSoon();
+    else
+        renderSoon();
 }
 
 bool WKCACFLayerRenderer::createRenderer()
@@ -423,15 +409,6 @@ void WKCACFLayerRenderer::paint()
         return;
     }
 
-    if (m_backingStoreDirty) {
-        // If the backing store is still dirty when we are about to draw the
-        // composited content, we need to force the window to paint into the
-        // backing store. The paint will only paint the dirty region that
-        // if being tracked in WebView.
-        UpdateWindow(m_hostWindow);
-        return;
-    }
-
     Vector<CGRect> dirtyRects;
     getDirtyRects(m_hostWindow, dirtyRects);
     render(dirtyRects);
@@ -546,6 +523,12 @@ void WKCACFLayerRenderer::renderSoon()
         m_renderTimer.startOneShot(0);
 }
 
+void WKCACFLayerRenderer::syncCompositingStateSoon()
+{
+    m_syncLayerChanges = true;
+    renderSoon();
+}
+
 CGRect WKCACFLayerRenderer::bounds() const
 {
     RECT clientRect;
index aff1f833b7b9b41cbf1d5fb0a3d1140ba99a10ee..2da6ac5aa8a4de0e72c153f18f90c59462a9560c 100644 (file)
@@ -70,17 +70,16 @@ public:
 
     static bool acceleratedCompositingAvailable();
 
-    void setRootContents(CGImageRef);
-    void setRootContentsAndDisplay(CGImageRef);
     void setRootChildLayer(PlatformCALayer*);
     void layerTreeDidChange();
     void setNeedsDisplay(bool sync = false);
     void setHostWindow(HWND window) { m_hostWindow = window; }
-    void setBackingStoreDirty(bool dirty) { m_backingStoreDirty = dirty; }
     bool createRenderer();
     void destroyRenderer();
+    void paint();
     void resize();
     void renderSoon();
+    void syncCompositingStateSoon();
 
 protected:
     PlatformCALayer* rootLayer() const;
@@ -102,7 +101,6 @@ private:
     bool resetDevice(ResetReason);
 
     void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
-    void paint();
 
     WKCACFLayerRendererClient* m_client;
     bool m_mightBeAbleToCreateDeviceLater;
@@ -112,7 +110,6 @@ private:
     WKCACFContext* m_context;
     HWND m_hostWindow;
     Timer<WKCACFLayerRenderer> m_renderTimer;
-    bool m_backingStoreDirty;
     bool m_mustResetLostDeviceBeforeRendering;
     bool m_syncLayerChanges;
     HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers;
index 1d90743d6754d172aa272c79fe119b46336a65c4..12f269c30cea096772de1a680a76c9156ed9ac21 100644 (file)
@@ -1,3 +1,86 @@
+2011-01-17  Adam Roben  <aroben@apple.com>
+
+        Paint directly into a GraphicsLayer when using accelerated compositing
+
+        Before this patch, we were painting into our normal backing store
+        HBITMAP, wrapping it in a CGImage, and handing it off to Core
+        Animation. This had at least two disadvantages:
+           1) The bitmap could be modified while Core Animation was using it.
+           2) It introduced extra complexity.
+
+        When entering accelerated compositing mode, WebView now creates a
+        GraphicsLayer to draw into. This GraphicsLayer sits between the root
+        layer (owned by WKCACFLayerRenderer) and the RenderView's layer. When
+        WebView invalidates, it just calls setNeedsDisplayInRect on its
+        GraphicsLayer. When WebView paints, it just tells its
+        WKCACFLayerRenderer to paint, which will call back to WebView to draw
+        into the GraphicsLayer if it has a dirty region. This is very similar
+        to the current implementation of LayerBackedDrawingArea in WebKit2.
+
+        Fixes <http://webkit.org/b/52582> WebView should paint directly into a
+        GraphicsLayer when in accelerated compositing mode
+
+        Reviewed by Simon Fraser and Chris Marrin.
+
+        * WebCoreSupport/WebChromeClient.cpp:
+        (WebChromeClient::attachRootGraphicsLayer):
+        (WebChromeClient::scheduleCompositingLayerSync):
+        Updated for WebView changes.
+
+        * WebView.cpp:
+        (WebView::repaint): When using accelerated compositing, just invalidate
+        our backing layer. This matches the behavior of LayerBackedDrawingArea.
+        (WebView::deleteBackingStore): Removed accelerated compositing code.
+        The WKCACFLayerRenderer doesn't need to know about our backing store
+        anymore; we don't use it at all when in accelerated compositing mode.
+        (WebView::addToDirtyRegion): When using accelerated compositing, just
+        invalidate our backing layer.
+        (WebView::scrollBackingStore): Added an assertion that this isn't
+        called in accelerated compositing mode.
+        (WebView::sizeChanged): Update our backing layer's size, too, and
+        invalidate it.
+        (WebView::updateBackingStore): Added an assertion that this isn't
+        called in accelerated compositing mode.
+        (WebView::paint): If we're in accelerated compositing mode, sync our
+        compositing state. If we're *still* in accelerated compositing mode,
+        just tell our WKCACFLayerRenderer to paint and clear our dirty region.
+        (The later changes in this function are just un-indenting code that
+        used to be inside an if.)
+
+        (WebView::paintIntoBackingStore):
+        (WebView::paintIntoWindow):
+        Added assertions that these aren't called in accelerated compositing
+        mode.
+
+        (WebView::WebViewWndProc): Updated WM_XP_THEMECHANGED handling for
+        removal of setRootLayerNeedsDisplay.
+        (WebView::setRootChildLayer): Changed to take a GraphicsLayer. We now
+        set the layer as a child of our own backing layer.
+        (WebView::scheduleCompositingLayerSync): Just call through to
+        WKCACFLayerRenderer.
+        (WebView::setAcceleratedCompositing): Create our backing layer and set
+        it as the child of WKCACFLayerRenderer's root layer.
+        (WebView::notifyAnimationStarted): Added. We never expect this
+        GraphicsLayerClient override to be called, as we don't use animations
+        on our backing layer.
+        (WebView::notifySyncRequired): Added. Just schedule a sync.
+        (WebView::paintContents): Added. Just clip and paint!
+
+        (WebView::showDebugBorders):
+        (WebView::showRepaintCounter):
+        Added. These just call through to Settings.
+
+        (WebView::syncCompositingState): Changed to first update layout, then
+        sync state for our backing layer, then sync WebCore's state. This
+        matches LayerBackedDrawingArea.
+
+        * WebView.h: WebView now implements the GraphicsLayerClient interface.
+        Removed setRootLayerNeedsDisplay; it's been replaced by calling
+        setNeedsDisplay on our backing layer and calling
+        syncCompositingStateSoon on WKCACFLayerRenderer as needed. Removed
+        updateRootLayerContents; that function was used to pass our backing
+        store to Core Animation, which we no longer do. Added m_backingLayer.
+
 2011-01-17  Tony Gentilcore  <tonyg@chromium.org>
 
         Reviewed by Alexey Proskuryakov.
index 3e73c626e3f8cc0754cf93f12ab9e4a82360a61f..6460b4ad02913a85dde69ff58a054ab6096634bb 100644 (file)
@@ -821,12 +821,12 @@ void WebChromeClient::setLastSetCursorToCurrentCursor()
 #if USE(ACCELERATED_COMPOSITING)
 void WebChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
 {
-    m_webView->setRootChildLayer(graphicsLayer ? PlatformCALayer::platformCALayer(graphicsLayer->platformLayer()) : 0);
+    m_webView->setRootChildLayer(graphicsLayer);
 }
 
 void WebChromeClient::scheduleCompositingLayerSync()
 {
-    m_webView->setRootLayerNeedsDisplay(true);
+    m_webView->scheduleCompositingLayerSync();
 }
 
 #endif
index 0aaf6c290ab60e32fffc8fd3faa659887533d636..f50d7c147b5619a9a482c95fcb3d843c4816d618 100644 (file)
@@ -722,8 +722,12 @@ HRESULT STDMETHODCALLTYPE WebView::close()
 void WebView::repaint(const WebCore::IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly)
 {
 #if USE(ACCELERATED_COMPOSITING)
-    if (isAcceleratedCompositing())
-        setRootLayerNeedsDisplay();
+    if (isAcceleratedCompositing()) {
+        // The contentChanged, immediate, and repaintContentOnly parameters are all based on a non-
+        // compositing painting/scrolling model.
+        addToDirtyRegion(windowRect);
+        return;
+    }
 #endif
 
     if (!repaintContentOnly) {
@@ -750,11 +754,6 @@ void WebView::deleteBackingStore()
     }
     m_backingStoreBitmap.clear();
     m_backingStoreDirtyRegion.clear();
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_layerRenderer)
-        m_layerRenderer->setBackingStoreDirty(false);
-#endif
-
     m_backingStoreSize.cx = m_backingStoreSize.cy = 0;
 }
 
@@ -785,6 +784,13 @@ void WebView::addToDirtyRegion(const IntRect& dirtyRect)
     // but it was being hit during our layout tests, and is being investigated in
     // http://webkit.org/b/29350.
 
+#if USE(ACCELERATED_COMPOSITING)
+    if (isAcceleratedCompositing()) {
+        m_backingLayer->setNeedsDisplayInRect(dirtyRect);
+        return;
+    }
+#endif
+
     HRGN newRegion = ::CreateRectRgn(dirtyRect.x(), dirtyRect.y(),
                                      dirtyRect.right(), dirtyRect.bottom());
     addToDirtyRegion(newRegion);
@@ -792,6 +798,10 @@ void WebView::addToDirtyRegion(const IntRect& dirtyRect)
 
 void WebView::addToDirtyRegion(HRGN newRegion)
 {
+#if USE(ACCELERATED_COMPOSITING)
+    ASSERT(!isAcceleratedCompositing());
+#endif
+
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
     if (m_backingStoreDirtyRegion) {
@@ -802,17 +812,16 @@ void WebView::addToDirtyRegion(HRGN newRegion)
     } else
         m_backingStoreDirtyRegion = RefCountedHRGN::create(newRegion);
 
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_layerRenderer)
-        m_layerRenderer->setBackingStoreDirty(true);
-#endif
-
     if (m_uiDelegatePrivate)
         m_uiDelegatePrivate->webViewDidInvalidate(this);
 }
 
 void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect)
 {
+#if USE(ACCELERATED_COMPOSITING)
+    ASSERT(!isAcceleratedCompositing());
+#endif
+
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
     // If there's no backing store we don't need to update it
@@ -866,6 +875,10 @@ void WebView::sizeChanged(const IntSize& newSize)
 #if USE(ACCELERATED_COMPOSITING)
     if (m_layerRenderer)
         m_layerRenderer->resize();
+    if (m_backingLayer) {
+        m_backingLayer->setSize(newSize);
+        m_backingLayer->setNeedsDisplay();
+    }
 #endif
 }
 
@@ -913,6 +926,10 @@ static void getUpdateRects(HRGN region, const IntRect& dirtyRect, Vector<IntRect
 
 void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStoreCompletelyDirty, WindowsToPaint windowsToPaint)
 {
+#if USE(ACCELERATED_COMPOSITING)
+    ASSERT(!isAcceleratedCompositing());
+#endif
+
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
     HDC windowDC = 0;
@@ -947,10 +964,6 @@ void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
             m_uiDelegatePrivate->webViewPainted(this);
 
         m_backingStoreDirtyRegion.clear();
-#if USE(ACCELERATED_COMPOSITING)
-        if (m_layerRenderer)
-            m_layerRenderer->setBackingStoreDirty(false);
-#endif
     }
 
     if (!dc) {
@@ -965,6 +978,19 @@ void WebView::paint(HDC dc, LPARAM options)
 {
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
+#if USE(ACCELERATED_COMPOSITING)
+    if (isAcceleratedCompositing()) {
+        syncCompositingState();
+        // Syncing might have taken us out of compositing mode.
+        if (isAcceleratedCompositing()) {
+            // FIXME: We need to paint into dc (if provided). <http://webkit.org/b/52578>
+            m_layerRenderer->paint();
+            ::ValidateRect(m_viewWindow, 0);
+            return;
+        }
+    }
+#endif
+
     Frame* coreFrame = core(m_mainFrame);
     if (!coreFrame)
         return;
@@ -1009,25 +1035,18 @@ void WebView::paint(HDC dc, LPARAM options)
     // Update our backing store if needed.
     updateBackingStore(frameView, bitmapDC, backingStoreCompletelyDirty, windowsToPaint);
 
-#if USE(ACCELERATED_COMPOSITING)
-    if (!isAcceleratedCompositing()) {
-#endif
-        // Now we blit the updated backing store
-        IntRect windowDirtyRect = rcPaint;
-        
-        // Apply the same heuristic for this update region too.
-        Vector<IntRect> blitRects;
-        if (region && regionType == COMPLEXREGION)
-            getUpdateRects(region.get(), windowDirtyRect, blitRects);
-        else
-            blitRects.append(windowDirtyRect);
+    // Now we blit the updated backing store
+    IntRect windowDirtyRect = rcPaint;
+    
+    // Apply the same heuristic for this update region too.
+    Vector<IntRect> blitRects;
+    if (region && regionType == COMPLEXREGION)
+        getUpdateRects(region.get(), windowDirtyRect, blitRects);
+    else
+        blitRects.append(windowDirtyRect);
 
-        for (unsigned i = 0; i < blitRects.size(); ++i)
-            paintIntoWindow(bitmapDC, hdc, blitRects[i]);
-#if USE(ACCELERATED_COMPOSITING)
-    } else
-        updateRootLayerContents();
-#endif
+    for (unsigned i = 0; i < blitRects.size(); ++i)
+        paintIntoWindow(bitmapDC, hdc, blitRects[i]);
 
     ::SelectObject(bitmapDC, oldBitmap);
     ::DeleteDC(bitmapDC);
@@ -1045,6 +1064,10 @@ void WebView::paint(HDC dc, LPARAM options)
 
 void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const IntRect& dirtyRect, WindowsToPaint windowsToPaint)
 {
+#if USE(ACCELERATED_COMPOSITING)
+    ASSERT(!isAcceleratedCompositing());
+#endif
+
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
     // FIXME: We want an assert here saying that the dirtyRect is inside the clienRect,
@@ -1084,6 +1107,10 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
 
 void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRect)
 {
+#if USE(ACCELERATED_COMPOSITING)
+    ASSERT(!isAcceleratedCompositing());
+#endif
+
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 #if FLASH_WINDOW_REDRAW
     OwnPtr<HBRUSH> greenBrush = CreateSolidBrush(RGB(0, 255, 0));
@@ -2201,7 +2228,7 @@ LRESULT CALLBACK WebView::WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam,
                 ::InvalidateRect(hWnd, &windowRect, false);
 #if USE(ACCELERATED_COMPOSITING)
                 if (webView->isAcceleratedCompositing())
-                    webView->setRootLayerNeedsDisplay();
+                    webView->m_backingLayer->setNeedsDisplay();
 #endif
            }
             break;
@@ -6231,11 +6258,19 @@ void WebView::downloadURL(const KURL& url)
 }
 
 #if USE(ACCELERATED_COMPOSITING)
-void WebView::setRootChildLayer(WebCore::PlatformCALayer* layer)
+void WebView::setRootChildLayer(GraphicsLayer* layer)
 {
     setAcceleratedCompositing(layer ? true : false);
-    if (m_layerRenderer)
-        m_layerRenderer->setRootChildLayer(layer);
+    if (!m_backingLayer)
+        return;
+    m_backingLayer->addChild(layer);
+}
+
+void WebView::scheduleCompositingLayerSync()
+{
+    if (!m_layerRenderer)
+        return;
+    m_layerRenderer->syncCompositingStateSoon();
 }
 
 void WebView::setAcceleratedCompositing(bool accelerated)
@@ -6252,55 +6287,32 @@ void WebView::setAcceleratedCompositing(bool accelerated)
             ASSERT(m_viewWindow);
             m_layerRenderer->setHostWindow(m_viewWindow);
             m_layerRenderer->createRenderer();
+
+            // FIXME: We could perhaps get better performance by never allowing this layer to
+            // become tiled (or choosing a higher-than-normal tiling threshold).
+            // <http://webkit.org/b/52603>
+            m_backingLayer = GraphicsLayer::create(this);
+            m_backingLayer->setDrawsContent(true);
+            m_backingLayer->setContentsOpaque(true);
+            RECT clientRect;
+            ::GetClientRect(m_viewWindow, &clientRect);
+            m_backingLayer->setSize(IntRect(clientRect).size());
+            m_backingLayer->setNeedsDisplay();
+
+            m_layerRenderer->setRootChildLayer(PlatformCALayer::platformCALayer(m_backingLayer->platformLayer()));
+
+            // We aren't going to be using our backing store while we're in accelerated compositing
+            // mode. But don't delete it immediately, in case we switch out of accelerated
+            // compositing mode soon (e.g., if we're only compositing for a :hover animation).
+            deleteBackingStoreSoon();
         }
     } else {
         m_layerRenderer = 0;
+        m_backingLayer = 0;
         m_isAcceleratedCompositing = false;
     }
 }
 
-void releaseBackingStoreCallback(void* info, const void* data, size_t size)
-{
-    // Release the backing store bitmap previously retained by updateRootLayerContents().
-    ASSERT(info);
-    if (info)
-        static_cast<RefCountedHBITMAP*>(info)->deref();
-}
-
-void WebView::updateRootLayerContents()
-{
-    if (!m_backingStoreBitmap || !m_layerRenderer)
-        return;
-
-    // Get the backing store into a CGImage
-    BITMAP bitmap;
-    GetObject(m_backingStoreBitmap->handle(), sizeof(bitmap), &bitmap);
-    size_t bmSize = bitmap.bmWidthBytes * bitmap.bmHeight;
-    RetainPtr<CGDataProviderRef> cgData(AdoptCF,
-        CGDataProviderCreateWithData(static_cast<void*>(m_backingStoreBitmap.get()),
-                                                        bitmap.bmBits, bmSize,
-                                                        releaseBackingStoreCallback));
-    RetainPtr<CGColorSpaceRef> space(AdoptCF, CGColorSpaceCreateDeviceRGB());
-    RetainPtr<CGImageRef> backingStoreImage(AdoptCF, CGImageCreate(bitmap.bmWidth, bitmap.bmHeight,
-                                     8, bitmap.bmBitsPixel, 
-                                     bitmap.bmWidthBytes, space.get(), 
-                                     kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
-                                     cgData.get(), 0, false, 
-                                     kCGRenderingIntentDefault));
-
-    // Retain the backing store bitmap so that it is not deleted by deleteBackingStore()
-    // while still in use within CA. When CA is done with the bitmap, it will
-    // call releaseBackingStoreCallback(), which will release the backing store bitmap.
-    m_backingStoreBitmap->ref();
-
-    // Hand the CGImage to CACF for compositing
-    if (m_nextDisplayIsSynchronous) {
-        m_layerRenderer->setRootContentsAndDisplay(backingStoreImage.get());
-        m_nextDisplayIsSynchronous = false;
-    } else
-        m_layerRenderer->setRootContents(backingStoreImage.get());
-}
-
 void WebView::layerRendererBecameVisible()
 {
     m_layerRenderer->createRenderer();
@@ -6458,6 +6470,39 @@ HRESULT WebView::nextDisplayIsSynchronous()
 }
 
 #if USE(ACCELERATED_COMPOSITING)
+void WebView::notifyAnimationStarted(const GraphicsLayer*, double)
+{
+    // We never set any animations on our backing layer.
+    ASSERT_NOT_REACHED();
+}
+
+void WebView::notifySyncRequired(const GraphicsLayer*)
+{
+    scheduleCompositingLayerSync();
+}
+
+void WebView::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& inClip)
+{
+    Frame* frame = core(m_mainFrame);
+    if (!frame)
+        return;
+
+    context.save();
+    context.clip(inClip);
+    frame->view()->paint(&context, inClip);
+    context.restore();
+}
+
+bool WebView::showDebugBorders() const
+{
+    return m_page->settings()->showDebugBorders();
+}
+
+bool WebView::showRepaintCounter() const
+{
+    return m_page->settings()->showRepaintCounter();
+}
+
 bool WebView::shouldRender() const
 {
     Frame* coreFrame = core(m_mainFrame);
@@ -6479,8 +6524,21 @@ void WebView::animationsStarted(CFTimeInterval t)
 void WebView::syncCompositingState()
 {
     Frame* coreFrame = core(m_mainFrame);
-    if (coreFrame && coreFrame->view())
-        coreFrame->view()->syncCompositingStateRecursive();
+    if (!coreFrame)
+        return;
+    FrameView* view = coreFrame->view();
+    if (!view)
+        return;
+    if (!m_backingLayer)
+        return;
+
+    view->updateLayoutAndStyleIfNeededRecursive();
+
+    // Updating layout might have taken us out of compositing mode.
+    if (m_backingLayer)
+        m_backingLayer->syncCompositingStateForThisLayerOnly();
+
+    view->syncCompositingStateRecursive();
 }
 
 #endif
index 192c05cbac28475ade60730dd3939b0165722b1b..3bd26f0bbdc62f909322e6ee516951343803985a 100644 (file)
@@ -70,6 +70,7 @@ class WebView
     , public IDropTarget
     , WebCore::WindowMessageListener
 #if USE(ACCELERATED_COMPOSITING)
+    , WebCore::GraphicsLayerClient
     , WebCore::WKCACFLayerRendererClient
 #endif
 {
@@ -904,12 +905,8 @@ public:
     void downloadURL(const WebCore::KURL&);
 
 #if USE(ACCELERATED_COMPOSITING)
-    void setRootLayerNeedsDisplay(bool sync = false)
-    {
-        if (m_layerRenderer)
-            m_layerRenderer->setNeedsDisplay(sync);
-    }
-    void setRootChildLayer(WebCore::PlatformCALayer*);
+    void scheduleCompositingLayerSync();
+    void setRootChildLayer(WebCore::GraphicsLayer*);
 #endif
 
     void enterFullscreenForNode(WebCore::Node*);
@@ -943,6 +940,13 @@ private:
     DWORD m_lastDropEffect;
 
 #if USE(ACCELERATED_COMPOSITING)
+    // GraphicsLayerClient
+    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
+    virtual void notifySyncRequired(const WebCore::GraphicsLayer*);
+    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& inClip);
+    virtual bool showDebugBorders() const;
+    virtual bool showRepaintCounter() const;
+
     // WKCACFLayerRendererClient
     virtual bool shouldRender() const;
     virtual void animationsStarted(CFTimeInterval);
@@ -1052,10 +1056,10 @@ protected:
 #if USE(ACCELERATED_COMPOSITING)
     bool isAcceleratedCompositing() const { return m_isAcceleratedCompositing; }
     void setAcceleratedCompositing(bool);
-    void updateRootLayerContents();
     void layerRendererBecameVisible();
 
     OwnPtr<WebCore::WKCACFLayerRenderer> m_layerRenderer;
+    OwnPtr<WebCore::GraphicsLayer> m_backingLayer;
     bool m_isAcceleratedCompositing;
 #endif