Remove uses of CACFContextRef and CARender* from WebCore
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Oct 2010 06:36:00 +0000 (06:36 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Oct 2010 06:36:00 +0000 (06:36 +0000)
These types are now wrapped in a WKCACFContext type exported by
WebKitSystemInterface.

Fixes <http://webkit.org/b/43244>.

Reviewed by Sam Weinig.

WebCore:

* platform/graphics/win/WKCACFContextFlusher.cpp:
(WebCore::WKCACFContextFlusher::addContext):
(WebCore::WKCACFContextFlusher::removeContext):
(WebCore::WKCACFContextFlusher::flushAllContexts):
* platform/graphics/win/WKCACFContextFlusher.h:
Changed to use WKCACFContext. We don't retain/release the context when
putting it into/taking it out of the set. WKCACFContext is not a
ref-counted type, so we can't retain/release it, but the
retain/release was also unnecessary as WKCACFLayerRenderer calls
removeContext before the context is destroyed.

* platform/graphics/win/WKCACFLayer.cpp:
(WebCore::WKCACFLayer::becomeRootLayerForContext):
* platform/graphics/win/WKCACFLayer.h:
Changed to use WKCACFContext.

* platform/graphics/win/WKCACFLayerRenderer.cpp:
(WebCore::WKCACFLayerRenderer::didFlushContext):
(WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer):
(WebCore::WKCACFLayerRenderer::~WKCACFLayerRenderer):
(WebCore::WKCACFLayerRenderer::layerTreeDidChange):
(WebCore::WKCACFLayerRenderer::createRenderer):
(WebCore::WKCACFLayerRenderer::destroyRenderer):
(WebCore::WKCACFLayerRenderer::render): Also replaced uses of
CGSRegion with WebKitSystemInterface functions/types.
(WebCore::WKCACFLayerRenderer::resetDevice):
* platform/graphics/win/WKCACFLayerRenderer.h:
Replaced our CACFContextRef, CARenderContext, and CARenderOGLContext
with a single WKCACFContext, which wraps all three. We hold a bare
pointer to it and destroy it in our destructor.

WebKitLibraries:

Add WKCACFContext and related functions

* win/lib/WebKitSystemInterface.lib:
* win/lib/WebKitSystemInterface_debug.lib:

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

WebCore/ChangeLog
WebCore/platform/graphics/win/WKCACFContextFlusher.cpp
WebCore/platform/graphics/win/WKCACFContextFlusher.h
WebCore/platform/graphics/win/WKCACFLayer.cpp
WebCore/platform/graphics/win/WKCACFLayer.h
WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp
WebCore/platform/graphics/win/WKCACFLayerRenderer.h
WebKitLibraries/ChangeLog
WebKitLibraries/win/lib/WebKitSystemInterface.lib
WebKitLibraries/win/lib/WebKitSystemInterface_debug.lib

index 195d7d9..d1f1cf8 100644 (file)
@@ -1,3 +1,45 @@
+2010-10-19  Adam Roben  <aroben@apple.com>
+
+        Remove uses of CACFContextRef and CARender* from WebCore
+
+        These types are now wrapped in a WKCACFContext type exported by
+        WebKitSystemInterface.
+
+        Fixes <http://webkit.org/b/43244>.
+
+        Reviewed by Sam Weinig.
+
+        * platform/graphics/win/WKCACFContextFlusher.cpp:
+        (WebCore::WKCACFContextFlusher::addContext):
+        (WebCore::WKCACFContextFlusher::removeContext):
+        (WebCore::WKCACFContextFlusher::flushAllContexts):
+        * platform/graphics/win/WKCACFContextFlusher.h:
+        Changed to use WKCACFContext. We don't retain/release the context when
+        putting it into/taking it out of the set. WKCACFContext is not a
+        ref-counted type, so we can't retain/release it, but the
+        retain/release was also unnecessary as WKCACFLayerRenderer calls
+        removeContext before the context is destroyed.
+
+        * platform/graphics/win/WKCACFLayer.cpp:
+        (WebCore::WKCACFLayer::becomeRootLayerForContext):
+        * platform/graphics/win/WKCACFLayer.h:
+        Changed to use WKCACFContext.
+
+        * platform/graphics/win/WKCACFLayerRenderer.cpp:
+        (WebCore::WKCACFLayerRenderer::didFlushContext):
+        (WebCore::WKCACFLayerRenderer::WKCACFLayerRenderer):
+        (WebCore::WKCACFLayerRenderer::~WKCACFLayerRenderer):
+        (WebCore::WKCACFLayerRenderer::layerTreeDidChange):
+        (WebCore::WKCACFLayerRenderer::createRenderer):
+        (WebCore::WKCACFLayerRenderer::destroyRenderer):
+        (WebCore::WKCACFLayerRenderer::render): Also replaced uses of
+        CGSRegion with WebKitSystemInterface functions/types.
+        (WebCore::WKCACFLayerRenderer::resetDevice):
+        * platform/graphics/win/WKCACFLayerRenderer.h:
+        Replaced our CACFContextRef, CARenderContext, and CARenderOGLContext
+        with a single WKCACFContext, which wraps all three. We hold a bare
+        pointer to it and destroy it in our destructor.
+
 2010-10-19  Yongjun Zhang  <yongjun_zhang@apple.com>
 
         Reviewed by Dan Bernstein.
index 1685a30..d75c854 100644 (file)
@@ -29,8 +29,8 @@
 
 #include "WKCACFContextFlusher.h"
 
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/StdLibExtras.h>
-#include <QuartzCore/CACFContext.h>
 
 namespace WebCore {
 
@@ -48,24 +48,18 @@ WKCACFContextFlusher::~WKCACFContextFlusher()
 {
 }
 
-void WKCACFContextFlusher::addContext(CACFContextRef context)
+void WKCACFContextFlusher::addContext(WKCACFContext* context)
 {
     ASSERT(context);
 
-    if (m_contexts.add(context).second)
-        CFRetain(context);
+    m_contexts.add(context);
 }
 
-void WKCACFContextFlusher::removeContext(CACFContextRef context)
+void WKCACFContextFlusher::removeContext(WKCACFContext* context)
 {
     ASSERT(context);
 
-    ContextSet::iterator found = m_contexts.find(context);
-    if (found == m_contexts.end())
-        return;
-
-    CFRelease(*found);
-    m_contexts.remove(found);
+    m_contexts.remove(context);
 }
 
 void WKCACFContextFlusher::flushAllContexts()
@@ -76,11 +70,8 @@ void WKCACFContextFlusher::flushAllContexts()
     contextsToFlush.swap(m_contexts);
 
     ContextSet::const_iterator end = contextsToFlush.end();
-    for (ContextSet::const_iterator it = contextsToFlush.begin(); it != end; ++it) {
-        CACFContextRef context = *it;
-        CACFContextFlush(context);
-        CFRelease(context);
-    }
+    for (ContextSet::const_iterator it = contextsToFlush.begin(); it != end; ++it)
+        wkCACFContextFlush(*it);
 }
 
 }
index 9ce76aa..17ec41d 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <wtf/HashSet.h>
 
-typedef struct _CACFContext* CACFContextRef;
+struct WKCACFContext;
 
 namespace WebCore {
 
@@ -40,8 +40,8 @@ class WKCACFContextFlusher : public Noncopyable {
 public:
     static WKCACFContextFlusher& shared();
 
-    void addContext(CACFContextRef);
-    void removeContext(CACFContextRef);
+    void addContext(WKCACFContext*);
+    void removeContext(WKCACFContext*);
 
     void flushAllContexts();
 
@@ -49,7 +49,7 @@ private:
     WKCACFContextFlusher();
     ~WKCACFContextFlusher();
 
-    typedef HashSet<CACFContextRef> ContextSet;
+    typedef HashSet<WKCACFContext*> ContextSet;
     ContextSet m_contexts;
 };
 
index bf47925..a8714e3 100644 (file)
 #include "WKCACFLayer.h"
 
 #include "WKCACFLayerRenderer.h"
-#include <wtf/text/CString.h>
-
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <stdio.h>
-#include <QuartzCore/CACFContext.h>
-#include <QuartzCore/CARender.h>
-
-#ifndef NDEBUG
 #include <wtf/CurrentTime.h>
-#endif
+#include <wtf/text/CString.h>
 
 namespace WebCore {
 
@@ -190,9 +185,9 @@ WKCACFLayer::~WKCACFLayer()
     CACFLayerSetDisplayCallback(layer(), 0);
 }
 
-void WKCACFLayer::becomeRootLayerForContext(CACFContextRef context)
+void WKCACFLayer::becomeRootLayerForContext(WKCACFContext* context)
 {
-    CACFContextSetLayer(context, layer());
+    wkCACFContextSetLayer(context, layer());
     setNeedsCommit();
 }
 
index 7243508..4c6639a 100644 (file)
@@ -41,6 +41,8 @@
 #include "PlatformString.h"
 #include "TransformationMatrix.h"
 
+struct WKCACFContext;
+
 namespace WebCore {
 
 class WKCACFLayer;
@@ -83,7 +85,7 @@ public:
     }
 
     // Makes this layer the root when the passed context is rendered
-    void becomeRootLayerForContext(CACFContextRef);
+    void becomeRootLayerForContext(WKCACFContext*);
 
     static RetainPtr<CFTypeRef> cfValue(float value) { return RetainPtr<CFTypeRef>(AdoptCF, CFNumberCreate(0, kCFNumberFloat32Type, &value)); }
     static RetainPtr<CFTypeRef> cfValue(const TransformationMatrix& value)
index 8082217..73cb794 100644 (file)
@@ -36,9 +36,7 @@
 #include "WKCACFContextFlusher.h"
 #include "WKCACFLayer.h"
 #include "WebCoreInstanceHandle.h"
-#include <CoreGraphics/CGSRegion.h>
-#include <QuartzCore/CACFContext.h>
-#include <QuartzCore/CARenderOGL.h>
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/HashMap.h>
 #include <wtf/OwnArrayPtr.h>
 #include <wtf/OwnPtr.h>
@@ -108,7 +106,7 @@ private:
     WKCACFLayerRenderer* m_renderer;
 };
 
-typedef HashMap<CACFContextRef, WKCACFLayerRenderer*> ContextToWindowMap;
+typedef HashMap<WKCACFContext*, WKCACFLayerRenderer*> ContextToWindowMap;
 
 static ContextToWindowMap& windowsForContexts()
 {
@@ -206,7 +204,7 @@ bool WKCACFLayerRenderer::acceleratedCompositingAvailable()
     return available;
 }
 
-void WKCACFLayerRenderer::didFlushContext(CACFContextRef context)
+void WKCACFLayerRenderer::didFlushContext(WKCACFContext* context)
 {
     WKCACFLayerRenderer* window = windowsForContexts().get(context);
     if (!window)
@@ -226,15 +224,13 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client)
     : m_client(client)
     , m_mightBeAbleToCreateDeviceLater(true)
     , m_rootLayer(WKCACFRootLayer::create(this))
-    , m_context(AdoptCF, CACFContextCreate(0))
-    , m_renderContext(static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get())))
-    , m_renderer(0)
+    , m_context(wkCACFContextCreate())
     , m_hostWindow(0)
     , m_renderTimer(this, &WKCACFLayerRenderer::renderTimerFired)
     , m_backingStoreDirty(false)
     , m_mustResetLostDeviceBeforeRendering(false)
 {
-    windowsForContexts().set(m_context.get(), this);
+    windowsForContexts().set(m_context, this);
 
     // Under the root layer, we have a clipping layer to clip the content,
     // that contains a scroll layer that we use for scrolling the content.
@@ -256,7 +252,7 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client)
 #endif
 
     if (m_context)
-        m_rootLayer->becomeRootLayerForContext(m_context.get());
+        m_rootLayer->becomeRootLayerForContext(m_context);
 
 #ifndef NDEBUG
     char* printTreeFlag = getenv("CA_PRINT_TREE");
@@ -267,6 +263,7 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client)
 WKCACFLayerRenderer::~WKCACFLayerRenderer()
 {
     destroyRenderer();
+    wkCACFContextDestroy(m_context);
 }
 
 WKCACFLayer* WKCACFLayerRenderer::rootLayer() const
@@ -298,7 +295,7 @@ void WKCACFLayerRenderer::setRootChildLayer(WKCACFLayer* layer)
    
 void WKCACFLayerRenderer::layerTreeDidChange()
 {
-    WKCACFContextFlusher::shared().addContext(m_context.get());
+    WKCACFContextFlusher::shared().addContext(m_context);
     renderSoon();
 }
 
@@ -373,7 +370,7 @@ bool WKCACFLayerRenderer::createRenderer()
 
     initD3DGeometry();
 
-    m_renderer = CARenderOGLNew(&kCARenderDX9Callbacks, m_d3dDevice.get(), 0);
+    wkCACFContextInitializeD3DDevice(m_context, m_d3dDevice.get());
 
     if (IsWindow(m_hostWindow))
         m_rootLayer->setBounds(bounds());
@@ -384,14 +381,10 @@ bool WKCACFLayerRenderer::createRenderer()
 void WKCACFLayerRenderer::destroyRenderer()
 {
     if (m_context) {
-        CACFContextSetLayer(m_context.get(), 0);
-        windowsForContexts().remove(m_context.get());
-        WKCACFContextFlusher::shared().removeContext(m_context.get());
+        windowsForContexts().remove(m_context);
+        WKCACFContextFlusher::shared().removeContext(m_context);
     }
 
-    if (m_renderer)
-        CARenderOGLDestroy(m_renderer);
-    m_renderer = 0;
     m_d3dDevice = 0;
     if (s_d3d)
         s_d3d->Release();
@@ -476,7 +469,7 @@ void WKCACFLayerRenderer::paint()
     render(dirtyRects);
 }
 
-void WKCACFLayerRenderer::render(const Vector<CGRect>& dirtyRects)
+void WKCACFLayerRenderer::render(const Vector<CGRect>& windowDirtyRects)
 {
     ASSERT(m_d3dDevice);
 
@@ -499,31 +492,21 @@ void WKCACFLayerRenderer::render(const Vector<CGRect>& dirtyRects)
     CFTimeInterval t = CACurrentMediaTime();
 
     // Give the renderer some space to use. This needs to be valid until the
-    // CARenderUpdateFinish() call below.
+    // wkCACFContextFinishUpdate() call below.
     char space[4096];
-    CARenderUpdate* u = CARenderUpdateBegin(space, sizeof(space), t, 0, 0, &bounds);
-    if (!u)
+    if (!wkCACFContextBeginUpdate(m_context, space, sizeof(space), t, bounds, windowDirtyRects.data(), windowDirtyRects.size()))
         return;
 
-    CARenderContextLock(m_renderContext);
-    CARenderUpdateAddContext(u, m_renderContext);
-    CARenderContextUnlock(m_renderContext);
-
-    for (size_t i = 0; i < dirtyRects.size(); ++i)
-        CARenderUpdateAddRect(u, &dirtyRects[i]);
-
     HRESULT err = S_OK;
     do {
-        CGSRegionObj rgn = CARenderUpdateCopyRegion(u);
+        // FIXME: don't need to clear dirty region if layer tree is opaque.
 
-        if (!rgn)
+        WKCACFUpdateRectEnumerator* e = wkCACFContextCopyUpdateRectEnumerator(m_context);
+        if (!e)
             break;
 
-        // FIXME: don't need to clear dirty region if layer tree is opaque.
-
         Vector<D3DRECT, 64> rects;
-        CGSRegionEnumeratorObj e = CGSRegionEnumerator(rgn);
-        for (const CGRect* r = CGSNextRect(e); r; r = CGSNextRect(e)) {
+        for (const CGRect* r = wkCACFUpdateRectEnumeratorNextRect(e); r; r = wkCACFUpdateRectEnumeratorNextRect(e)) {
             D3DRECT rect;
             rect.x1 = r->origin.x;
             rect.x2 = rect.x1 + r->size.width;
@@ -532,8 +515,7 @@ void WKCACFLayerRenderer::render(const Vector<CGRect>& dirtyRects)
 
             rects.append(rect);
         }
-        CGSReleaseRegionEnumerator(e);
-        CGSReleaseRegion(rgn);
+        wkCACFUpdateRectEnumeratorRelease(e);
 
         if (rects.isEmpty())
             break;
@@ -541,13 +523,13 @@ void WKCACFLayerRenderer::render(const Vector<CGRect>& dirtyRects)
         m_d3dDevice->Clear(rects.size(), rects.data(), D3DCLEAR_TARGET, 0, 1.0f, 0);
 
         m_d3dDevice->BeginScene();
-        CARenderOGLRender(m_renderer, u);
+        wkCACFContextRenderUpdate(m_context);
         m_d3dDevice->EndScene();
 
         err = m_d3dDevice->Present(0, 0, 0, 0);
 
         if (err == D3DERR_DEVICELOST) {
-            CARenderUpdateAddRect(u, &bounds);
+            wkCACFContextAddUpdateRect(m_context, bounds);
             if (!resetDevice(LostDevice)) {
                 // We can't reset the device right now. Try again soon.
                 renderSoon();
@@ -556,7 +538,7 @@ void WKCACFLayerRenderer::render(const Vector<CGRect>& dirtyRects)
         }
     } while (err == D3DERR_DEVICELOST);
 
-    CARenderUpdateFinish(u);
+    wkCACFContextFinishUpdate(m_context);
 
 #ifndef NDEBUG
     if (m_printTree)
@@ -598,7 +580,7 @@ void WKCACFLayerRenderer::initD3DGeometry()
 bool WKCACFLayerRenderer::resetDevice(ResetReason reason)
 {
     ASSERT(m_d3dDevice);
-    ASSERT(m_renderContext);
+    ASSERT(m_context);
 
     HRESULT hr = m_d3dDevice->TestCooperativeLevel();
 
@@ -617,10 +599,10 @@ bool WKCACFLayerRenderer::resetDevice(ResetReason reason)
 
     // We can reset the device.
 
-    // We have to purge the CARenderOGLContext whenever we reset the IDirect3DDevice9 in order to
+    // We have to release the context's D3D resrouces whenever we reset the IDirect3DDevice9 in order to
     // destroy any D3DPOOL_DEFAULT resources that Core Animation has allocated (e.g., textures used
     // for mask layers). See <http://msdn.microsoft.com/en-us/library/bb174425(v=VS.85).aspx>.
-    CARenderOGLPurge(m_renderer);
+    wkCACFContextReleaseD3DResources(m_context);
 
     D3DPRESENT_PARAMETERS parameters = initialPresentationParameters();
     hr = m_d3dDevice->Reset(&parameters);
index 1d73b99..763fffa 100644 (file)
@@ -41,9 +41,7 @@
 #include <CoreGraphics/CGGeometry.h>
 
 interface IDirect3DDevice9;
-typedef struct _CACFContext* CACFContextRef;
-typedef struct _CARenderContext CARenderContext;
-typedef struct _CARenderOGLContext CARenderOGLContext;
+struct WKCACFContext;
 
 namespace WebCore {
 
@@ -64,7 +62,7 @@ public:
     ~WKCACFLayerRenderer();
 
     static bool acceleratedCompositingAvailable();
-    static void didFlushContext(CACFContextRef);
+    static void didFlushContext(WKCACFContext*);
 
     void setRootContents(CGImageRef);
     void setRootContentsAndDisplay(CGImageRef);
@@ -104,9 +102,7 @@ private:
     COMPtr<IDirect3DDevice9> m_d3dDevice;
     RefPtr<WKCACFRootLayer> m_rootLayer;
     RefPtr<WKCACFLayer> m_rootChildLayer;
-    RetainPtr<CACFContextRef> m_context;
-    CARenderContext* m_renderContext;
-    CARenderOGLContext* m_renderer;
+    WKCACFContext* m_context;
     HWND m_hostWindow;
     Timer<WKCACFLayerRenderer> m_renderTimer;
     bool m_backingStoreDirty;
index f99f6bd..7241445 100644 (file)
@@ -1,3 +1,14 @@
+2010-10-19  Adam Roben  <aroben@apple.com>
+
+        Add WKCACFContext and related functions
+
+        Fixes <http://webkit.org/b/43244>.
+
+        Reviewed by Sam Weinig.
+
+        * win/lib/WebKitSystemInterface.lib:
+        * win/lib/WebKitSystemInterface_debug.lib:
+
 2010-10-14  Ada Chan  <adachan@apple.com>
 
         Rubber-stamped by Adam Roben.
index a52d9c2..c23ae49 100644 (file)
Binary files a/WebKitLibraries/win/lib/WebKitSystemInterface.lib and b/WebKitLibraries/win/lib/WebKitSystemInterface.lib differ
index 2b0dea5..ddcbeee 100644 (file)
Binary files a/WebKitLibraries/win/lib/WebKitSystemInterface_debug.lib and b/WebKitLibraries/win/lib/WebKitSystemInterface_debug.lib differ