Avoid round trip to display for every surface creation. 07/7907/3
authorKondapally Kalyan <kalyan.kondapally@intel.com>
Mon, 12 Aug 2013 05:43:13 +0000 (08:43 +0300)
committerJoone Hur <joone.hur@intel.com>
Wed, 14 Aug 2013 14:58:13 +0000 (07:58 -0700)
We currently do a round trip every time a surface is created.
This patch changes it so that instead of doing to for every surface,
we handle the synchronization once all the current tile updates are
done in WebProcess side.

Change-Id: I444d8bfa35e3bbf82bf11b78512eb03d1325b897

Source/WebCore/platform/graphics/surfaces/egl/EGLWaylandSurface.cpp
Source/WebCore/platform/graphics/surfaces/egl/EGLWaylandSurface.h
Source/WebCore/platform/graphics/surfaces/wayland/WaylandDisplay.cpp
Source/WebCore/platform/graphics/surfaces/wayland/WaylandDisplay.h
Source/WebCore/platform/graphics/surfaces/wayland/WaylandSurface.cpp
Source/WebCore/platform/graphics/surfaces/wayland/WaylandSurface.h
Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.cpp

index d749e72..59706ef 100644 (file)
@@ -39,7 +39,6 @@ namespace WebCore {
 EGLWindowSurface::EGLWindowSurface(const IntSize& size, GLPlatformSurface::SurfaceAttributes attributes)
     : EGLOffScreenSurface(attributes)
     , m_nativeWindow(0)
-    , m_bufferAttached(false)
 {
     if (!m_configSelector)
         return;
@@ -97,12 +96,6 @@ void EGLWindowSurface::swapBuffers()
         LOG_ERROR("Failed to SwapBuffers(%d).", eglGetError());
         m_surface->deleteFrameCallBack();
     }
-
-    if (!m_bufferAttached) {
-        // FIXME: Need a better way to handle this.
-        WaylandDisplay::instance()->syncDisplay();
-        m_bufferAttached = true;
-    }
 }
 
 void EGLWindowSurface::destroy()
index d4cce9e..d87e28c 100644 (file)
@@ -48,7 +48,6 @@ public:
 private:
     struct wl_egl_window* m_nativeWindow;
     OwnPtr<WaylandSurface> m_surface;
-    bool m_bufferAttached :1;
 };
 
 }
index 35f7cd8..1fd9fb8 100644 (file)
@@ -350,6 +350,7 @@ WaylandDisplay::WaylandDisplay()
     , m_registry(0)
     , m_wlCompositor(0)
     , m_queue(0)
+    , m_pendingEvents(false)
 {
 }
 
@@ -440,31 +441,19 @@ void WaylandDisplay::terminate()
     m_display = 0;
 }
 
-struct wl_display* WaylandDisplay::nativeDisplay()
+struct wl_display* WaylandDisplay::nativeDisplay() const
 {
-    wl_display* wlDisplay = 0;
-    if (m_instance)
-        wlDisplay = m_instance->m_display;
-
-    return wlDisplay;
+    return m_display;
 }
 
-struct wl_compositor* WaylandDisplay::compositor()
+struct wl_compositor* WaylandDisplay::compositor() const
 {
-    struct wl_compositor* wlCompositor = 0;
-    if (m_instance)
-        wlCompositor = m_instance->m_wlCompositor;
-
-    return wlCompositor;
+    return m_wlCompositor;
 }
 
-struct wl_registry* WaylandDisplay::registry()
+struct wl_registry* WaylandDisplay::registry() const
 {
-    struct wl_registry* wlRegistry = 0;
-    if (m_instance)
-        wlRegistry = m_instance->m_registry;
-
-    return wlRegistry;
+    return m_registry;
 }
 
 WaylandBuffer* WaylandDisplay::mapBuffer(WaylandSurfaceId sharedBufferId, WaylandBufferListener* listener, bool useLinearFilter)
@@ -536,12 +525,21 @@ void WaylandDisplay::syncCallback(void *data, struct wl_callback *callback, uint
     wl_callback_destroy(callback);
 }
 
+int WaylandDisplay::flush()
+{
+    if (!m_pendingEvents)
+        return 0;
+
+    return syncDisplay();
+}
+
 int WaylandDisplay::syncDisplay()
 {
     if (!m_queue)
         return -1;
 
     int done = 0, ret = 0;
+    m_pendingEvents = false;
     struct wl_callback* callback = wl_display_sync(m_display);
     wl_callback_add_listener(callback, &syncListener, &done);
     wl_proxy_set_queue((struct wl_proxy *) callback, m_queue);
index 35bdff2..8aa6ee4 100644 (file)
@@ -44,10 +44,12 @@ public:
     static WaylandDisplay* instance();
     static void disconnect();
     // client apis.
-    struct wl_display* nativeDisplay();
-    struct wl_compositor* compositor();
-    struct wl_registry* registry();
+    struct wl_display* nativeDisplay() const;
+    struct wl_compositor* compositor() const;
+    struct wl_registry* registry() const;
     int syncDisplay();
+    int flush();
+
     // Ownership is transferred.
     PassOwnPtr<WaylandSurface> createSurface();
 
@@ -71,6 +73,7 @@ private:
     void lock();
     void unlock();
     void handlePendingEvents();
+    void addPendingEvent() { m_pendingEvents = true; }
     void initialize(wl_display* = 0);
     static WaylandDisplay* openStaticConnection();
 
@@ -90,7 +93,9 @@ private:
     struct wl_registry* m_registry;
     struct wl_compositor* m_wlCompositor;
     struct wl_event_queue* m_queue;
+    bool m_pendingEvents :1;
     friend class WaylandBuffer;
+    friend class WaylandSurface;
 };
 
 }
index fba2707..45e5735 100644 (file)
@@ -52,6 +52,7 @@ WaylandSurface::WaylandSurface(struct wl_compositor* compositor)
     : m_surface(0)
     , m_frameCallBack(0)
     , m_queue(0)
+    , m_surfaceAttached(false)
     , m_id(0)
 {
     static WaylandSurfaceId bufferHandleId = 0;
@@ -64,7 +65,21 @@ WaylandSurface::WaylandSurface(struct wl_compositor* compositor)
 
     bufferHandleId++;
     m_id = bufferHandleId;
-    WaylandDisplay::instance()->syncDisplay();
+    WaylandDisplay::instance()->addPendingEvent();
+}
+
+WaylandSurface::~WaylandSurface()
+{
+    m_id = 0;
+    deleteFrameCallBack();
+
+    if (m_surface) {
+        wl_surface_destroy(m_surface);
+        m_surface = 0;
+    }
+
+    if (WaylandDisplay::instance())
+        WaylandDisplay::instance()->addPendingEvent();
 }
 
 void WaylandSurface::addFrameCallBack()
@@ -75,6 +90,7 @@ void WaylandSurface::addFrameCallBack()
     if (!m_queue) {
         m_queue = wl_display_create_queue(WaylandDisplay::instance()->nativeDisplay());
         wl_proxy_set_queue((struct wl_proxy *)WaylandDisplay::instance()->registry(), m_queue);
+        ensureSurfaceMapped();
     }
 
     m_frameCallBack = wl_surface_frame(m_surface);
@@ -120,14 +136,11 @@ void WaylandSurface::destroyFrameCallBack()
     m_frameCallBack = 0;
 }
 
-WaylandSurface::~WaylandSurface()
+void WaylandSurface::ensureSurfaceMapped()
 {
-    m_id = 0;
-    deleteFrameCallBack();
-
-    if (m_surface) {
-        wl_surface_destroy(m_surface);
-        m_surface = 0;
+    if (!m_surfaceAttached) {
+        WaylandDisplay::instance()->addPendingEvent();
+        m_surfaceAttached = true;
     }
 }
 
index 1bcad24..22bebdd 100644 (file)
@@ -48,16 +48,17 @@ public:
     // m_surface->addFrameCallBack();
     // Swap buffers.
     void addFrameCallBack();
-    // Ensure that deleteFrameCallBack is called before
-    // destroying any EGL resources associated with the
-    // surface.
-    // Example usage:
+    // Ensure deleteFrameCallBack(in case a framecallback is requested)
+    // is called before destroying any EGL resources associated with the
+    // surface. Example usage:
     // deleteFrameCallBack();
     // destroy egl window etc
     // m_surface = nullptr; i.e destroy WaylandSurface.
     void deleteFrameCallBack();
     // see addFrameCallBack.
     int ensureFrameCallBackDone();
+    // Synchronizes initial Attach call.
+    void ensureSurfaceMapped();
 
     // callback
     static void surfaceFrameCallback(void*, struct wl_callback*, uint32_t);
@@ -68,6 +69,7 @@ private:
     struct wl_surface* m_surface;
     struct wl_callback* m_frameCallBack;
     struct wl_event_queue* m_queue;
+    bool m_surfaceAttached :1;
     WaylandSurfaceId m_id;
     friend class WaylandDisplay;
 };
index 32b016e..c242a17 100755 (executable)
@@ -33,6 +33,9 @@
 #include "TextureMapperPlatformLayer.h"
 #include "TiledBackingStoreRemoteTile.h"
 #include "SharedPlatformSurfaceTizen.h"
+#if PLATFORM(WAYLAND)
+#include "WaylandDisplay.h"
+#endif
 #include "WebPage.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/HashMap.h>
@@ -760,6 +763,10 @@ void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const In
 
 void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects)
 {
+#if PLATFORM(WAYLAND)
+    if (WaylandDisplay::instance())
+        WaylandDisplay::instance()->flush();
+#endif
 }
 
 bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const