[GTK] Avoid the redirected window resize when the view is realized in AC mode
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jul 2016 07:04:59 +0000 (07:04 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jul 2016 07:04:59 +0000 (07:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159463

Reviewed by Michael Catanzaro.

We are always creating the redirected window at 1x1 and then resizing it if we are in AC mode. When the view is
realized and AC mode is already enabled, which happens for example when AC mode is forced, or when the threaded
compositor is enabled, we could just pass the initial size to the redirected window constructor to create the
XWindow at the right size.

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseResizeRedirectedWindow): We no longer need to pass the device scale factor, since the
RedirectedXCompositeWindow already knows it.
(webkitWebViewBaseRealize): Pass the WebPageProxy and an initial size to the RedirectedXCompositeWindow
constructor instead of the parent GdkWindow. If AC mode is disabled, the initial size will be empty. With the
WebPageProxy the redirected window has access to the device scale factor and view widget to get the parent
GdkWindow.
(deviceScaleFactorChanged): Resize the redirected window when device scale factor changes.
* UIProcess/gtk/RedirectedXCompositeWindow.cpp:
(WebKit::RedirectedXCompositeWindow::create):
(WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow):
(WebKit::RedirectedXCompositeWindow::resize):
(WebKit::RedirectedXCompositeWindow::surface):
(WebKit::RedirectedXCompositeWindow::~RedirectedXCompositeWindow):
* UIProcess/gtk/RedirectedXCompositeWindow.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp
Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h

index 500bb8a..24b3a88 100644 (file)
@@ -1,5 +1,33 @@
 2016-07-20  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Avoid the redirected window resize when the view is realized in AC mode
+        https://bugs.webkit.org/show_bug.cgi?id=159463
+
+        Reviewed by Michael Catanzaro.
+
+        We are always creating the redirected window at 1x1 and then resizing it if we are in AC mode. When the view is
+        realized and AC mode is already enabled, which happens for example when AC mode is forced, or when the threaded
+        compositor is enabled, we could just pass the initial size to the redirected window constructor to create the
+        XWindow at the right size.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseResizeRedirectedWindow): We no longer need to pass the device scale factor, since the
+        RedirectedXCompositeWindow already knows it.
+        (webkitWebViewBaseRealize): Pass the WebPageProxy and an initial size to the RedirectedXCompositeWindow
+        constructor instead of the parent GdkWindow. If AC mode is disabled, the initial size will be empty. With the
+        WebPageProxy the redirected window has access to the device scale factor and view widget to get the parent
+        GdkWindow.
+        (deviceScaleFactorChanged): Resize the redirected window when device scale factor changes.
+        * UIProcess/gtk/RedirectedXCompositeWindow.cpp:
+        (WebKit::RedirectedXCompositeWindow::create):
+        (WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow):
+        (WebKit::RedirectedXCompositeWindow::resize):
+        (WebKit::RedirectedXCompositeWindow::surface):
+        (WebKit::RedirectedXCompositeWindow::~RedirectedXCompositeWindow):
+        * UIProcess/gtk/RedirectedXCompositeWindow.h:
+
+2016-07-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK][Threaded Compositor] Web Process crash when the page is closed before the web view is realized
         https://bugs.webkit.org/show_bug.cgi?id=159918
 
index 0e85491..c8c7547 100644 (file)
@@ -359,8 +359,8 @@ static void webkitWebViewBaseResizeRedirectedWindow(WebKitWebViewBase* webView)
 {
     WebKitWebViewBasePrivate* priv = webView->priv;
     DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea());
-    ASSERT(drawingArea);
-    priv->redirectedWindow->setDeviceScaleFactor(priv->pageProxy->deviceScaleFactor());
+    if (!drawingArea)
+        return;
     priv->redirectedWindow->resize(drawingArea->size());
 }
 #endif
@@ -373,19 +373,19 @@ static void webkitWebViewBaseRealize(GtkWidget* widget)
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
     if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) {
         ASSERT(!priv->redirectedWindow);
+        DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea());
         priv->redirectedWindow = RedirectedXCompositeWindow::create(
-            gtk_widget_get_parent_window(widget),
+            *priv->pageProxy,
+            drawingArea && drawingArea->isInAcceleratedCompositingMode() ? drawingArea->size() : IntSize(),
             [webView] {
                 DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(webView->priv->pageProxy->drawingArea());
                 if (drawingArea && drawingArea->isInAcceleratedCompositingMode())
                     gtk_widget_queue_draw(GTK_WIDGET(webView));
             });
-        if (priv->redirectedWindow) {
-            if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(priv->pageProxy->drawingArea())) {
-                drawingArea->setNativeSurfaceHandleForCompositing(priv->redirectedWindow->windowID());
-                if (drawingArea->isInAcceleratedCompositingMode())
-                    webkitWebViewBaseResizeRedirectedWindow(webView);
-            }
+        if (priv->redirectedWindow && drawingArea) {
+            drawingArea->setNativeSurfaceHandleForCompositing(priv->redirectedWindow->windowID());
+            if (drawingArea->isInAcceleratedCompositingMode())
+                webkitWebViewBaseResizeRedirectedWindow(webView);
         }
     }
 #endif
@@ -1265,7 +1265,7 @@ static void deviceScaleFactorChanged(WebKitWebViewBase* webkitWebViewBase)
 {
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
     if (webkitWebViewBase->priv->redirectedWindow)
-        webkitWebViewBase->priv->redirectedWindow->setDeviceScaleFactor(webkitWebViewBase->priv->pageProxy->deviceScaleFactor());
+        webkitWebViewBaseResizeRedirectedWindow(webkitWebViewBase);
 #endif
     webkitWebViewBase->priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase)));
 }
index ad07133..8da5f05 100644 (file)
@@ -29,6 +29,7 @@
 
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
 
+#include "WebPageProxy.h"
 #include <WebCore/CairoUtilities.h>
 #include <WebCore/PlatformDisplayX11.h>
 #include <X11/Xlib.h>
@@ -130,21 +131,26 @@ static bool supportsXDamageAndXComposite(GdkWindow* window)
     return true;
 }
 
-std::unique_ptr<RedirectedXCompositeWindow> RedirectedXCompositeWindow::create(GdkWindow* parentWindow, std::function<void()> damageNotify)
+std::unique_ptr<RedirectedXCompositeWindow> RedirectedXCompositeWindow::create(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify)
 {
+    GdkWindow* parentWindow = gtk_widget_get_parent_window(webPage.viewWidget());
     ASSERT(GDK_IS_WINDOW(parentWindow));
-    return supportsXDamageAndXComposite(parentWindow) ? std::unique_ptr<RedirectedXCompositeWindow>(new RedirectedXCompositeWindow(parentWindow, damageNotify)) : nullptr;
+    if (!supportsXDamageAndXComposite(parentWindow))
+        return nullptr;
+    return std::unique_ptr<RedirectedXCompositeWindow>(new RedirectedXCompositeWindow(webPage, initialSize, WTFMove(damageNotify)));
 }
 
-RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
-    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
-    , m_needsNewPixmapAfterResize(false)
-    , m_deviceScale(1)
+RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify)
+    : m_webPage(webPage)
+    , m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gtk_widget_get_parent_window(webPage.viewWidget()))))
+    , m_size(initialSize)
 {
+    m_size.scale(m_webPage.deviceScaleFactor());
+
     ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
     Screen* screen = DefaultScreenOfDisplay(m_display);
 
-    GdkVisual* visual = gdk_window_get_visual(parentWindow);
+    GdkVisual* visual = gdk_window_get_visual(gtk_widget_get_parent_window(webPage.viewWidget()));
     XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));
 
     // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
@@ -214,8 +220,7 @@ RedirectedXCompositeWindow::~RedirectedXCompositeWindow()
 void RedirectedXCompositeWindow::resize(const IntSize& size)
 {
     IntSize scaledSize(size);
-    scaledSize.scale(m_deviceScale);
-
+    scaledSize.scale(m_webPage.deviceScaleFactor());
     if (scaledSize == m_size)
         return;
 
@@ -261,7 +266,7 @@ cairo_surface_t* RedirectedXCompositeWindow::surface()
     }
 
     RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height()));
-    cairoSurfaceSetDeviceScale(newSurface.get(), m_deviceScale, m_deviceScale);
+    cairoSurfaceSetDeviceScale(newSurface.get(), m_webPage.deviceScaleFactor(), m_webPage.deviceScaleFactor());
 
     RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get()));
     cairo_set_source_rgb(cr.get(), 1, 1, 1);
index bfc2a14..cbeedd6 100644 (file)
@@ -40,29 +40,31 @@ typedef unsigned long Window;
 
 namespace WebKit {
 
+class WebPageProxy;
+
 class RedirectedXCompositeWindow {
+    WTF_MAKE_NONCOPYABLE(RedirectedXCompositeWindow); WTF_MAKE_FAST_ALLOCATED;
 public:
-    static std::unique_ptr<RedirectedXCompositeWindow> create(GdkWindow*, std::function<void()> damageNotify);
+    static std::unique_ptr<RedirectedXCompositeWindow> create(WebPageProxy&, const WebCore::IntSize&, std::function<void ()>&& damageNotify);
     ~RedirectedXCompositeWindow();
 
     Window windowID() const { return m_window.get(); }
     void resize(const WebCore::IntSize&);
-    void setDeviceScaleFactor(float scale) { m_deviceScale = scale; }
     cairo_surface_t* surface();
 
 private:
-    RedirectedXCompositeWindow(GdkWindow*, std::function<void()> damageNotify);
+    RedirectedXCompositeWindow(WebPageProxy&, const WebCore::IntSize&, std::function<void ()>&& damageNotify);
     void cleanupPixmapAndPixmapSurface();
 
-    Display* m_display;
+    WebPageProxy& m_webPage;
+    Display* m_display { nullptr };
     WebCore::IntSize m_size;
     WebCore::XUniqueWindow m_window;
     WebCore::XUniqueWindow m_parentWindow;
     WebCore::XUniquePixmap m_pixmap;
     WebCore::XUniqueDamage m_damage;
     RefPtr<cairo_surface_t> m_surface;
-    bool m_needsNewPixmapAfterResize;
-    float m_deviceScale;
+    bool m_needsNewPixmapAfterResize { false };
 };
 
 } // namespace WebKit