[GTK] [AC] Introduce AcceleratedCompositingContext to isolate different accelerated...
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 20:18:59 +0000 (20:18 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 20:18:59 +0000 (20:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75519

Reviewed by Alejandro G. Castro.

Add an AcceleratedCompositingContext which will isolate all the different accelerated compositing
implementations from one another. For right now this just includes the Clutter version.

* GNUmakefile.am: Add the new files to the source list.
* WebCoreSupport/AcceleratedCompositingContext.h: Added.
* WebCoreSupport/AcceleratedCompositingContextClutter.cpp: Added. Existing
clutter AC code has moved here.
* WebCoreSupport/ChromeClientGtk.cpp:
(WebKit::ChromeClient::attachRootGraphicsLayer): Use the new AccleratedCompositingContext now
instead of calling into the WebView.
(WebKit::ChromeClient::setNeedsOneShotDrawingSynchronization):Ditto.
(WebKit::ChromeClient::scheduleCompositingLayerSync): Ditto.
* webkit/webkitwebview.cpp:
(webkit_web_view_size_allocate): Call in the ACContext.
(webkit_web_view_init): Initialize the ACContext.
* webkit/webkitwebviewprivate.h: Add the ACContext as a private member.

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

Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/GNUmakefile.am
Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h [new file with mode: 0644]
Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextClutter.cpp [new file with mode: 0644]
Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp
Source/WebKit/gtk/webkit/webkitwebview.cpp
Source/WebKit/gtk/webkit/webkitwebviewprivate.h

index 61fcf55..fcd3ec6 100644 (file)
@@ -1,3 +1,27 @@
+2012-01-05  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] [AC] Introduce AcceleratedCompositingContext to isolate different accelerated compositing implementations
+        https://bugs.webkit.org/show_bug.cgi?id=75519
+
+        Reviewed by Alejandro G. Castro.
+
+        Add an AcceleratedCompositingContext which will isolate all the different accelerated compositing
+        implementations from one another. For right now this just includes the Clutter version.
+
+        * GNUmakefile.am: Add the new files to the source list.
+        * WebCoreSupport/AcceleratedCompositingContext.h: Added.
+        * WebCoreSupport/AcceleratedCompositingContextClutter.cpp: Added. Existing
+        clutter AC code has moved here.
+        * WebCoreSupport/ChromeClientGtk.cpp:
+        (WebKit::ChromeClient::attachRootGraphicsLayer): Use the new AccleratedCompositingContext now
+        instead of calling into the WebView.
+        (WebKit::ChromeClient::setNeedsOneShotDrawingSynchronization):Ditto.
+        (WebKit::ChromeClient::scheduleCompositingLayerSync): Ditto.
+        * webkit/webkitwebview.cpp:
+        (webkit_web_view_size_allocate): Call in the ACContext.
+        (webkit_web_view_init): Initialize the ACContext.
+        * webkit/webkitwebviewprivate.h: Add the ACContext as a private member.
+
 2012-01-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use gdk_screen_get_monitor_workarea() when available for screenAvailableRect()
index 786a27b..0a33486 100644 (file)
@@ -184,6 +184,8 @@ webkitgtk_sources += \
        Source/WebCore/bindings/gobject/WebKitDOMObject.h \
        Source/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.cpp \
        Source/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.h \
+       Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h \
+       Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextClutter.cpp \
        Source/WebKit/gtk/WebCoreSupport/AssertMatchingEnums.cpp \
        Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp \
        Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.h \
diff --git a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h
new file mode 100644 (file)
index 0000000..61c23b7
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 Igalia, S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef AcceleratedCompositingContext_h
+#define AcceleratedCompositingContext_h
+
+#include "GraphicsLayerClient.h"
+#include "IntRect.h"
+#include "IntSize.h"
+#include "Timer.h"
+#include "webkitwebview.h"
+#include <wtf/PassOwnPtr.h>
+
+#if USE(ACCELERATED_COMPOSITING)
+
+namespace WebCore {
+class GraphicsLayer;
+}
+
+namespace WebKit {
+
+class AcceleratedCompositingContext {
+    WTF_MAKE_NONCOPYABLE(AcceleratedCompositingContext);
+public:
+    static PassOwnPtr<AcceleratedCompositingContext> create(WebKitWebView* webView)
+    {
+        return adoptPtr(new AcceleratedCompositingContext(webView));
+    }
+
+    virtual ~AcceleratedCompositingContext();
+    void attachRootGraphicsLayer(WebCore::GraphicsLayer*);
+    void scheduleRootLayerRepaint(const WebCore::IntRect&);
+    void markForSync();
+    void syncLayersTimeout(WebCore::Timer<AcceleratedCompositingContext>*);
+    void resizeRootLayer(const WebCore::IntSize&);
+
+private:
+    WebKitWebView* m_webView;
+    OwnPtr<WebCore::GraphicsLayer> m_rootGraphicsLayer;
+    WebCore::Timer<AcceleratedCompositingContext> m_syncTimer;
+
+#if USE(CLUTTER)
+    GtkWidget* m_rootLayerEmbedder;
+#endif
+
+    AcceleratedCompositingContext(WebKitWebView*);
+};
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
+#endif // AcceleratedCompositingContext_h
diff --git a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextClutter.cpp b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextClutter.cpp
new file mode 100644 (file)
index 0000000..4657ec4
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2012 Igalia, S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "AcceleratedCompositingContext.h"
+
+#if USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
+
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsLayer.h"
+#include "webkitwebviewprivate.h"
+#include <clutter-gtk/clutter-gtk.h>
+#include <clutter/clutter.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+AcceleratedCompositingContext::AcceleratedCompositingContext(WebKitWebView* webView)
+    : m_webView(webView)
+    , m_rootGraphicsLayer(0)
+    , m_syncTimer(this, &AcceleratedCompositingContext::syncLayersTimeout)
+    , m_rootLayerEmbedder(0)
+{
+}
+
+AcceleratedCompositingContext::~AcceleratedCompositingContext()
+{
+}
+
+bool AcceleratedCompositingContext::renderLayersToWindow(cairo_t* widgetCr, const IntRect& clipRect)
+{
+    notImplemented();
+    return false;
+}
+
+void AcceleratedCompositingContext::attachRootGraphicsLayer(GraphicsLayer* graphicsLayer)
+{
+    if (!graphicsLayer) {
+        gtk_container_remove(GTK_CONTAINER(m_webView), m_rootLayerEmbedder);
+        m_rootLayerEmbedder = 0;
+        m_rootGraphicsLayer = 0;
+        return;
+    }
+
+    // Create an instance of GtkClutterEmbed to host actors as web layers.
+    if (!m_rootLayerEmbedder) {
+        m_rootLayerEmbedder = gtk_clutter_embed_new();
+        gtk_container_add(GTK_CONTAINER(m_webView), m_rootLayerEmbedder);
+        gtk_widget_show(m_rootLayerEmbedder);
+    }
+
+    // Add a root layer to the stage.
+    if (graphicsLayer) {
+        m_rootGraphicsLayer = graphicsLayer;
+        ClutterColor stageColor = { 0xFF, 0xFF, 0xFF, 0xFF };
+        ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(m_rootLayerEmbedder));
+        clutter_stage_set_color(CLUTTER_STAGE(stage), &stageColor);
+        clutter_container_add_actor(CLUTTER_CONTAINER(stage), m_rootGraphicsLayer->platformLayer());
+        clutter_actor_show_all(stage);
+    }
+}
+
+void AcceleratedCompositingContext::scheduleRootLayerRepaint(const IntRect& rect)
+{
+    if (!m_rootGraphicsLayer)
+        return;
+
+    if (rect.isEmpty()) {
+        m_rootGraphicsLayer->setNeedsDisplay();
+        return;
+    }
+
+    m_rootGraphicsLayer->setNeedsDisplayInRect(rect);
+}
+
+void AcceleratedCompositingContext::resizeRootLayer(const IntSize& size)
+{
+    if (!m_rootLayerEmbedder)
+        return;
+
+    GtkAllocation allocation;
+    allocation.x = 0;
+    allocation.y = 0;
+    allocation.width = size.width();
+    allocation.height = size.height();
+    gtk_widget_size_allocate(GTK_WIDGET(m_webView->priv->rootLayerEmbedder), &allocation);
+}
+
+void AcceleratedCompositingContext::markForSync()
+{
+    if (m_syncTimer.isActive())
+        return;
+    m_syncTimer.startOneShot(0);
+}
+
+void AcceleratedCompositingContext::syncLayersTimeout(Timer<AcceleratedCompositingContext>*)
+{
+    core(m_webView)->mainFrame()->view()->syncCompositingStateIncludingSubframes();
+}
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
index 6b20aa7..29a84a6 100644 (file)
@@ -927,20 +927,17 @@ void ChromeClient::exitFullScreenForElement(WebCore::Element* element)
 #if USE(ACCELERATED_COMPOSITING)
 void ChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* rootLayer)
 {
-    if (rootLayer)
-        webViewSetRootGraphicsLayer(m_webView, rootLayer);
-    else
-        webViewDetachRootGraphicsLayer(m_webView);
+    m_webView->priv->acceleratedCompositingContext->attachRootGraphicsLayer(rootLayer);
 }
 
 void ChromeClient::setNeedsOneShotDrawingSynchronization()
 {
-    webViewMarkForSync(m_webView, FALSE);
+    m_webView->priv->acceleratedCompositingContext->markForSync();
 }
 
 void ChromeClient::scheduleCompositingLayerSync()
 {
-    webViewMarkForSync(m_webView, TRUE);
+    m_webView->priv->acceleratedCompositingContext->markForSync();
 }
 
 ChromeClient::CompositingTriggerFlags ChromeClient::allowedCompositingTriggers() const
index 6fe8cdf..0868a4a 100644 (file)
@@ -7,7 +7,7 @@
  *  Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org>
  *  Copyright (C) 2008 Nuanti Ltd.
  *  Copyright (C) 2008, 2009, 2010 Collabora Ltd.
- *  Copyright (C) 2009, 2010 Igalia S.L.
+ *  Copyright (C) 2009, 2010, 2012 Igalia S.L.
  *  Copyright (C) 2009 Movial Creative Technologies Inc.
  *  Copyright (C) 2009 Bobby Powers
  *  Copyright (C) 2010 Joone Hur <joone@kldp.org>
@@ -872,12 +872,8 @@ static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allo
     chromeClient->widgetSizeChanged(oldSize, IntSize(allocation->width, allocation->height));
     chromeClient->adjustmentWatcher()->updateAdjustmentsFromScrollbars();
 
-#if USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
-    if (webView->priv->rootLayerEmbedder) {
-        allocation->x = 0;
-        allocation->y = 0;
-        gtk_widget_size_allocate(GTK_WIDGET(webView->priv->rootLayerEmbedder), allocation);
-    }
+#if USE(ACCELERATED_COMPOSITING)
+    WEBKIT_WEB_VIEW(widget)->priv->acceleratedCompositingContext->resizeRootLayer(IntSize(allocation->width, allocation->height));
 #endif
 }
 
@@ -3337,6 +3333,10 @@ static void webkit_web_view_init(WebKitWebView* webView)
     gtk_drag_dest_set_target_list(GTK_WIDGET(webView), PasteboardHelper::defaultPasteboardHelper()->targetList());
 
     priv->selfScrolling = false;
+
+#if USE(ACCELERATED_COMPOSITING)
+    priv->acceleratedCompositingContext = AcceleratedCompositingContext::create(webView);
+#endif
 }
 
 GtkWidget* webkit_web_view_new(void)
@@ -4909,68 +4909,6 @@ void webViewExitFullscreen(WebKitWebView* webView)
 #endif
 }
 
-#if USE(ACCELERATED_COMPOSITING)
-void webViewSetRootGraphicsLayer(WebKitWebView* webView, GraphicsLayer* graphicsLayer)
-{
-#if USE(CLUTTER)
-    WebKitWebViewPrivate* priv = webView->priv;
-
-    // Create an instance of GtkClutterEmbed to host actors as web layers.
-    if (!priv->rootLayerEmbedder) {
-        priv->rootLayerEmbedder = gtk_clutter_embed_new();
-        gtk_container_add(GTK_CONTAINER(webView), priv->rootLayerEmbedder);
-        gtk_widget_show(priv->rootLayerEmbedder);
-    }
-
-    // Add a root layer to the stage.
-    if (graphicsLayer) {
-        priv->rootGraphicsLayer = graphicsLayer;
-        // set white background
-        ClutterColor stageColor = { 0xFF, 0xFF, 0xFF, 0xFF };
-        ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->rootLayerEmbedder));
-        clutter_stage_set_color(CLUTTER_STAGE (stage), &stageColor);
-        clutter_container_add_actor(CLUTTER_CONTAINER(stage), priv->rootGraphicsLayer->platformLayer());
-        clutter_actor_show_all(stage);
-    }
-#else
-    notImplemented();
-#endif
-}
-
-void webViewDetachRootGraphicsLayer(WebKitWebView* webView)
-{
-#if USE(CLUTTER)
-    WebKitWebViewPrivate* priv = webView->priv;
-    // Detach the root layer from the hosting view.
-    gtk_container_remove(GTK_CONTAINER(webView), priv->rootLayerEmbedder);
-    priv->rootLayerEmbedder = 0;
-    priv->rootGraphicsLayer = 0;
-#else
-    notImplemented();
-#endif
-}
-
-#if USE(CLUTTER)
-static gboolean webViewSyncLayers(gpointer data)
-{
-    WebKitWebView* webView = WEBKIT_WEB_VIEW(data);
-    core(webView)->mainFrame()->view()->syncCompositingStateIncludingSubframes();
-
-    return FALSE;
-}
-#endif
-
-void webViewMarkForSync(WebKitWebView* webView, gboolean scheduleSync)
-{
-#if USE(CLUTTER)
-    g_timeout_add(0, webViewSyncLayers, webView);
-#else
-    notImplemented();
-#endif
-}
-
-#endif
-
 namespace WebKit {
 
 WebCore::Page* core(WebKitWebView* webView)
index f7671fc..8d2b7b0 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef webkitwebviewprivate_h
 #define webkitwebviewprivate_h
 
+#include "AcceleratedCompositingContext.h"
 #include "FullscreenVideoController.h"
 #include "GtkClickCounter.h"
 #include "GtkDragAndDropHelper.h"
 #include "WidgetBackingStore.h"
 #include <webkit/webkitwebview.h>
 
-#if USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
-#include <clutter-gtk/clutter-gtk.h>
-#include <clutter/clutter.h>
-#endif
-
 namespace WebKit {
 WebCore::Page* core(WebKitWebView*);
 WebKitWebView* kit(WebCore::Page*);
@@ -97,9 +93,9 @@ struct _WebKitWebViewPrivate {
     WebCore::GtkClickCounter clickCounter;
     WebCore::GtkDragAndDropHelper dragAndDropHelper;
     bool selfScrolling;
-#if USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
-    WebCore::GraphicsLayer* rootGraphicsLayer;
-    GtkWidget* rootLayerEmbedder;
+
+#if USE(ACCELERATED_COMPOSITING)
+    OwnPtr<WebKit::AcceleratedCompositingContext> acceleratedCompositingContext;
 #endif
 };
 
@@ -120,12 +116,6 @@ GtkMenu* webkit_web_view_get_context_menu(WebKitWebView*);
 
 void webViewEnterFullscreen(WebKitWebView* webView, WebCore::Node*);
 void webViewExitFullscreen(WebKitWebView* webView);
-
-#if USE(ACCELERATED_COMPOSITING)
-void webViewSetRootGraphicsLayer(WebKitWebView*, WebCore::GraphicsLayer*);
-void webViewDetachRootGraphicsLayer(WebKitWebView*);
-void webViewMarkForSync(WebKitWebView*, gboolean);
-#endif
 }
 
 #endif