LayerManagerPlugins: refinement of Wayland Plugins.
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Tue, 26 Jun 2012 09:53:15 +0000 (18:53 +0900)
committerMichael Schuldt <michael.schuldt@bmw.de>
Tue, 26 Jun 2012 14:04:34 +0000 (16:04 +0200)
- WindowSystems:

  - WaylandBaseWindowSystem:
    -support calculateSurfaceFps and calculateFps
    -change debug of information from INFO to DEBUG
    -improve deallocation method of wayland surface resources
    -add macro:WL_OMIT_CLEAR_GB to disable calling clearbackground
    -add macro:WL_LOG_DETAIL_TIMER to get detail performance value of wayland plutin
    -remove unnecesary codes
    -remove modifying m_damaged in Redraw()

  - WaylandDrmWindowSystem:
  - WaylandFbdevWindowsystem:
  - WaylandX11WindowSystem:
    -remove dependency on EGL. Because no all composition method are dependent on EGL.

- WaylandGLESRenderer:
  - remove dependency on EGL from init method.

LayerManagerPlugins/Renderers/Graphic/CMakeLists.txt
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandBaseWindowSystem.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandX11WindowSystem.h
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandDrmWindowSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandFbdevWindowSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandX11WindowSystem.cpp
LayerManagerPlugins/Renderers/Platform/WaylandGLESRenderer/src/WaylandGLESRenderer.cpp

index eb804e7..b6fc83d 100644 (file)
@@ -261,6 +261,7 @@ if (WITH_WAYLAND)
         set(LIBS
                 ${LIBS}
                 ${X11_X11_LIB}
+                ${WAYLAND_EGL_LIBRARIES}
         )
         
         set(SOURCES
@@ -282,11 +283,16 @@ if (WITH_WAYLAND)
 
         set(GRAPHIC_LIB_NAME LayerManagerGraphicWaylandGLESv2)
 
+        set(LIBS
+                ${LIBS}
+                ${WAYLAND_EGL_LIBRARIES}
+        )
+
         file(GLOB SOURCES 
             ../Base/src/BaseRenderer.cpp
             src/GraphicSystems/GLESGraphicSystem.cpp
             src/WindowSystems/WaylandBaseWindowSystem.cpp
-            src/WindowSystems/WaylandX11WindowSystem.cpp
+            src/WindowSystems/WaylandFbdevWindowSystem.cpp
             src/WindowSystems/WaylandServerinfoProtocol.cpp  
             src/TextureBinders/WaylandCopyGLES.cpp
             src/TextureBinders/WaylandEglImage.cpp
@@ -355,7 +361,7 @@ if (WITH_WAYLAND)
     install(FILES
                 include/TextureBinders/ITextureBinder.h
                 include/TextureBinders/WaylandCopyGLES.h
-                include/TextureBinders/WaylandNullTexture.h
+                include/TextureBinders/WaylandEglImage.h
             DESTINATION
                 include/layermanager/graphic/TextureBinders
     )
index acae3a1..b97a044 100644 (file)
@@ -32,9 +32,8 @@
 #include "WindowSystems/BaseWindowSystem.h"
 #include "GraphicSystems/BaseGraphicSystem.h"
 #include "Surface.h"
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
 #include <wayland-server.h>
+#include <wayland-client.h>
 #include "PlatformSurfaces/WaylandPlatformSurface.h"
 #include "Log.h"
 #include "ScreenShotType.h"
@@ -59,7 +58,7 @@ class WaylandBaseWindowSystem: public BaseWindowSystem
 public:
     WaylandBaseWindowSystem(const char* displayname, int width, int height, Scene* pScene);
     virtual ~WaylandBaseWindowSystem();
-    bool init(BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* sys);
+    bool init(BaseGraphicSystem<void*, void*>* sys);
     bool start();
     void stop();
     void signalRedrawEvent();
@@ -74,14 +73,21 @@ public:
 
 protected:
     struct wl_display* m_wlDisplay;
+    struct wl_display* m_wlDisplayClient;
+    struct wl_compositor* m_wlCompositorClient;
+    struct wl_global_listener* m_wlCompositorGlobalListener;
+    struct wl_surface* m_wlSurfaceClient;
     pthread_t renderThread;
     pthread_mutex_t run_lock;
-    BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* graphicSystem;
+    BaseGraphicSystem<void*, void*>* graphicSystem;
     virtual void CheckRedrawAllLayers();
     virtual void RedrawAllLayers();
     virtual void renderHWLayer(Layer* layer);
     virtual bool initCompositor();
     struct wl_shm* m_wlShm;
+    struct wl_global* m_serverInfoGlobal;
+    void* m_serverInfo;
+    struct wl_global* m_wlCompositorGlobal;
     virtual bool createNativeContext() = 0;
     virtual bool initGraphicSystem() = 0;
 
@@ -99,12 +105,9 @@ protected:
     int m_width;
     int m_height;
 
-    struct wl_list m_listFrameCallback;        // TODO:confirm:what's this
-    struct wl_event_source* m_idleSource; // TODO:confirm:what's this
-    int m_idleTime; // TODO:confirm:what's this
+    struct wl_list m_listFrameCallback;
 
     void createServerinfo(WaylandBaseWindowSystem* windowSystem);
-    void addIdleEventRepaint();        // TODO:confirm:what's this
     struct native_surface* createNativeSurface();
     void postReleaseBuffer(struct wl_buffer *buffer);
     void attachBufferToNativeSurface(struct wl_buffer* buffer, struct wl_surface* surface); // ADIT TODO:reconfirm!!
@@ -115,14 +118,17 @@ protected:
     void shutdownCompositor();
     Surface* getSurfaceFromNativeSurface(struct native_surface* nativeSurface);
     void checkForNewSurface();
+    void calculateFps();
+    void calculateSurfaceFps(Surface *currentSurface, float time) ;
     void printDebug();
     void* eventLoop();
 
     static void bindCompositor(struct wl_client* client, void* data, uint32_t version, uint32_t id);
     static int signalEventOnTerm(int signal_number, void *data);
     static void destroyListenerSurfaceBuffer(struct wl_listener* listener, struct wl_resource* resource, uint32_t time);
-    static int timerEventIdle(void *data);
     static void idleEventRepaint(void *data);
+    bool createWaylandClient();
+    void releaseWaylandClient();
 
 public:
     static void serverinfoIFCreateConnection(struct wl_client *client, struct wl_resource *resource);
@@ -131,6 +137,8 @@ public:
     static void destroySurfaceCallback(struct wl_resource* resource);
     static void destroyFrameCallback(struct wl_resource *resource);
     static void* eventLoopCallback(void* ptr);
+    static void bindDisplayClient(struct wl_display* display, uint32_t id, const char* interface, uint32_t version, void* data);
+    static void surfaceListenerFrame(void* data, struct wl_callback* callback, uint32_t time);
 
     // wl_surface interface
     static void surfaceIFDestroy(struct wl_client *client, struct wl_resource *resource);
index 464ccb3..60e34d0 100644 (file)
 #ifndef _WAYLANDX11WINDOWSYSTEM_H_
 #define _WAYLANDX11WINDOWSYSTEM_H_
 #include "WindowSystems/WaylandBaseWindowSystem.h"
+#include "X11/Xlib.h"
+#include <X11/Xutil.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
 
 class WaylandX11WindowSystem: public WaylandBaseWindowSystem
 {
index 18aaada..e048954 100644 (file)
@@ -81,7 +81,7 @@ extern "C" {
 
     void WaylandBaseWindowSystem::bindServerinfo(struct wl_client *client, void *data, uint32_t version, uint32_t id)
     {
-        LOG_INFO("WaylandBaseWindowSystem", "bindServerinfo client:" << client << ", data:" << data << ", version:" << version << ", id:" << id);
+        LOG_DEBUG("WaylandBaseWindowSystem", "bindServerinfo client:" << client << ", data:" << data << ", version:" << version << ", id:" << id);
         wl_client_add_object(client, &serverinfo_interface, &g_serverinfoImplementation, id, data);
     }
 
@@ -101,17 +101,31 @@ extern "C" {
         serverInfo->base.data = NULL;
         serverInfo->windowSystem = windowSystem;
 
-        wl_display_add_global(windowSystem->m_wlDisplay, &serverinfo_interface, serverInfo, WaylandBaseWindowSystem::bindServerinfo);
+        m_serverInfoGlobal = wl_display_add_global(windowSystem->m_wlDisplay, &serverinfo_interface, serverInfo, WaylandBaseWindowSystem::bindServerinfo);
+        if (NULL == m_serverInfoGlobal)
+        {
+            LOG_ERROR("WaylandBaseWindowSystem", "failed wl_display_add_global");
+            free(serverInfo);
+            return;
+        }
+
+        m_serverInfo = (void*)serverInfo;
     };
 }
 
 WaylandBaseWindowSystem::WaylandBaseWindowSystem(const char* displayname, int width, int height, Scene* pScene)
 : BaseWindowSystem(pScene)
 , m_wlDisplay(NULL)
+, m_wlDisplayClient(NULL)
+, m_wlCompositorClient(NULL)
+, m_wlSurfaceClient(NULL)
 , renderThread(0)
 , run_lock()
 , graphicSystem(NULL)
 , m_wlShm(NULL)
+, m_serverInfoGlobal(NULL)
+, m_serverInfo(NULL)
+, m_wlCompositorGlobal(NULL)
 , m_initialized(false)
 , m_takeScreenshot(ScreenShotNone)
 , m_displayname(displayname)
@@ -221,30 +235,61 @@ void WaylandBaseWindowSystem::checkForNewSurface()
     m_pScene->unlockScene();
 }
 
-static float timeSinceLastCalc = 0.0;
-static float FPS = 0.0;
-static struct timeval tv;
 static struct timeval tv0;
-static int Frame = 0;
+static struct timeval tv0_forRender;
+
+
+void WaylandBaseWindowSystem::calculateSurfaceFps(Surface *currentSurface, float time )
+{
+        char floatStringBuffer[256];
+        float surfaceUpdateFps = ((float)(currentSurface->updateCounter)) / time ;
+        float surfaceDrawFps = ((float)(currentSurface->drawCounter)) / time ;
+        sprintf(floatStringBuffer, "0x%08x update fps: %3.2f", currentSurface->getID(),surfaceUpdateFps);
+        currentSurface->updateCounter = 0;
+        LOG_INFO("WaylandBaseWindowSystem", "Surface " << floatStringBuffer);
+        sprintf(floatStringBuffer, "0x%08x draw fps: %3.2f", currentSurface->getID(),surfaceDrawFps);
+        currentSurface->drawCounter = 0;
+        LOG_INFO("WaylandBaseWindowSystem", "Surface " << floatStringBuffer);
+}
 
-void CalculateFPS()
+void WaylandBaseWindowSystem::calculateFps()
 {
+    struct timeval tv;
+    float FPS = 0.0;
+    int Frame = 0;
+    float timeSinceLastCalc = 0.0;
+
     // we have rendered a frame
     Frame ++;
-
+    std::list<Layer*> layers = m_pScene->getCurrentRenderOrder();
     // every 3 seconds, calculate & print fps
     gettimeofday(&tv, NULL);
     timeSinceLastCalc = (float)(tv.tv_sec-tv0.tv_sec) + 0.000001*((float)(tv.tv_usec-tv0.tv_usec));
 
-    if (timeSinceLastCalc > 3.0f)
-    {
+    // calculate every rendering because of event driven
+    // if (timeSinceLastCalc > 10.0f)
+    // {
+        //LOG_INFO("WaylandBaseWindowSystem", "tv.tv_sec:" << tv.tv_sec << ", tv.tv_usec:" << tv.tv_usec);
+        //LOG_INFO("WaylandBaseWindowSystem", "timeSinceLastCalc " << timeSinceLastCalc);
         FPS = ((float)(Frame)) / timeSinceLastCalc;
         char floatStringBuffer[256];
-        sprintf(floatStringBuffer, "FPS: %f", FPS);
+        sprintf(floatStringBuffer, "Overall fps: %f", FPS);
+
+        timeSinceLastCalc = (float)(tv.tv_sec-tv0_forRender.tv_sec) + 0.000001*((float)(tv.tv_usec-tv0_forRender.tv_usec));
+        for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++)
+        {
+            SurfaceList surfaceList = (*current)->getAllSurfaces();
+            SurfaceListIterator surfaceIter = surfaceList.begin();
+            SurfaceListIterator surfaceIterEnd = surfaceList.end();
+            for(; surfaceIter != surfaceIterEnd ; ++surfaceIter)
+            {
+                calculateSurfaceFps((*surfaceIter),timeSinceLastCalc);
+            }
+        }
         LOG_INFO("WaylandBaseWindowSystem", floatStringBuffer);
         tv0 = tv;
         Frame = 0;
-    }
+    // }
 }
 
 void WaylandBaseWindowSystem::CheckRedrawAllLayers()
@@ -264,14 +309,17 @@ void WaylandBaseWindowSystem::CheckRedrawAllLayers()
 void WaylandBaseWindowSystem::RedrawAllLayers()
 {
     std::list<Layer*> layers = m_pScene->getCurrentRenderOrder();
+       bool bRedraw = m_damaged || (m_systemState == REDRAW_STATE);
 
     // m_damaged represents that SW composition is required
     // At this point if a layer has damaged = true then it must be a HW layer that needs update.
     // A SW layer which needs update will make m_damaged = true
-    if (m_damaged)
+    if (bRedraw)
     {
         graphicSystem->activateGraphicContext();
+#ifndef WL_OMIT_CLEAR_GB
         graphicSystem->clearBackground();
+#endif /* WL_OMIT_CLEAR_GB */
     }
     for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++)
     {
@@ -283,16 +331,27 @@ void WaylandBaseWindowSystem::RedrawAllLayers()
                 (*current)->damaged = false;
             }
         }
-        else if (m_damaged)
+        else if (bRedraw)
         {
             graphicSystem->beginLayer(*current);
             graphicSystem->renderSWLayer();
             graphicSystem->endLayer();
         }
     }
-    if (m_damaged)
+    if (bRedraw)
     {
+#ifdef WL_LOG_DETAIL_TIMER
+        struct timeval tv_s;
+        struct timeval tv_e;
+        float timeSinceLastCalc = 0.0;
+        gettimeofday(&tv_s, NULL);
         graphicSystem->swapBuffers();
+        gettimeofday(&tv_e, NULL);
+        timeSinceLastCalc = (float)(tv_e.tv_sec-tv_s.tv_sec) + 0.000001*((float)(tv_e.tv_usec-tv_s.tv_usec));
+        LOG_INFO("WaylandBaseWindowSystem", "swapBuffers" << timeSinceLastCalc);
+#else
+        graphicSystem->swapBuffers();
+#endif
         graphicSystem->releaseGraphicContext();
     }
 }
@@ -304,6 +363,8 @@ void WaylandBaseWindowSystem::renderHWLayer(Layer *layer)
 
 void WaylandBaseWindowSystem::Redraw()
 {
+    gettimeofday(&tv0_forRender, NULL);
+
     // draw all the layers
     //graphicSystem->clearBackground();
     /*LOG_INFO("WaylandBaseWindowSystem","Locking List");*/
@@ -314,19 +375,20 @@ void WaylandBaseWindowSystem::Redraw()
 
     m_pScene->unlockScene();
 
-    if (m_damaged)
+    if (m_damaged || (m_systemState == REDRAW_STATE))
     {
         // TODO: This block won't be executed for HW only changes
         // Is that acceptable?
-        if (debugMode)
+        if (m_debugMode)
         {
             printDebug();
         }
 
-        CalculateFPS();
+        calculateFps();
 
         /* Reset the damage flag, all is up to date */
         m_damaged = false;
+        m_systemState = IDLE_STATE;
     }
 }
 
@@ -371,7 +433,7 @@ void WaylandBaseWindowSystem::Screenshot()
 
 void WaylandBaseWindowSystem::destroyListenerSurfaceBuffer(struct wl_listener* listener, struct wl_resource* resource, uint32_t time)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "destroyListenerSurfaceBuffer listener:" << listener << ", resource:" << resource << ", time:" << time);
+    LOG_DEBUG("WaylandBaseWindowSystem", "destroyListenerSurfaceBuffer listener:" << listener << ", resource:" << resource << ", time:" << time);
     struct native_surface *es = container_of(listener, struct native_surface, buffer_destroy_listener);
 
     es->buffer = NULL;
@@ -405,22 +467,32 @@ struct native_surface* WaylandBaseWindowSystem::createNativeSurface()
 
 uint32_t WaylandBaseWindowSystem::getTime(void)
 {
+#ifdef WL_OMIT_GETTIME
+    return 0xF0F0F0F0;
+#else /* WL_OMIT_GETTIME */
     struct timeval tv;
 
     gettimeofday(&tv, NULL);
 
     return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+#endif /* WL_OMIT_GETTIME */
 }
 
 void WaylandBaseWindowSystem::destroySurfaceCallback(struct wl_resource* resource)
 {
     struct native_surface* nativeSurface = container_of(resource, struct native_surface, surface.resource);
-#if 0 /* ADIT TODO */
-    Surface* surface = getSurfaceFromNativeSurface(struct native_surface* nativeSurface);
+    WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)nativeSurface->windowSystem);
+    Surface* ilmSurface = windowSystem->getSurfaceFromNativeSurface(nativeSurface);
 
-    WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)surface->windowSystem);
-    windowSystem->graphicSystem->getTextureBinder()->destroyClientBuffer(nativeSurface);
-#endif /* ADIT TODO */
+    if (NULL != ilmSurface)
+    {
+        if (NULL != ilmSurface->platform)
+        {
+            delete ilmSurface->platform;
+            ilmSurface->platform = NULL;
+        }
+        windowSystem->graphicSystem->getTextureBinder()->destroyClientBuffer(ilmSurface);
+    }
 
     wl_list_remove(&nativeSurface->link);
     wl_list_remove(&nativeSurface->buffer_link);
@@ -435,7 +507,7 @@ void WaylandBaseWindowSystem::destroySurfaceCallback(struct wl_resource* resourc
 
 extern "C" void WaylandBaseWindowSystem::surfaceIFDestroy(struct wl_client *client, struct wl_resource *resource)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "surfaceIFDestroy client:" << client << ", resource:" << resource);
+    LOG_DEBUG("WaylandBaseWindowSystem", "surfaceIFDestroy client:" << client << ", resource:" << resource);
     wl_resource_destroy(resource, getTime());
 }
 
@@ -468,19 +540,20 @@ void WaylandBaseWindowSystem::attachBufferToNativeSurface(struct wl_buffer* buff
     }
     struct wl_list* surfaces_attached_to;
 
+    ilmSurface->updateCounter++;
+    ilmSurface->removeNativeContent();
+    ilmSurface->setNativeContent((long int)buffer);
+    WaylandPlatformSurface* nativePlatformSurface = (WaylandPlatformSurface*)ilmSurface->platform;
+    if (0 != nativePlatformSurface)
+    {
+        windowSystem->graphicSystem->getTextureBinder()->createClientBuffer(ilmSurface);
+        LOG_DEBUG("WaylandBaseWindowSystem","nativePlatformSurface->enable");
+        nativePlatformSurface->enableRendering();
+    }
+
     if (wl_buffer_is_shm(buffer))
     {
         LOG_DEBUG("WaylandBaseWindowSystem", "shm buffer" << buffer);
-        ilmSurface->removeNativeContent();
-        ilmSurface->setNativeContent((long int)buffer);
-
-        WaylandPlatformSurface* nativePlatformSurface = (WaylandPlatformSurface*)ilmSurface->platform;
-        if (0 != nativePlatformSurface)
-        {
-            windowSystem->graphicSystem->getTextureBinder()->createClientBuffer(ilmSurface);
-            LOG_DEBUG("WaylandBaseWindowSystem","nativePlatformSurface->enable");
-            nativePlatformSurface->enableRendering();
-        }
 
         // TODO:only ARGB32.
         //switch (wl_shm_buffer_get_format(buffer)) {
@@ -503,17 +576,6 @@ void WaylandBaseWindowSystem::attachBufferToNativeSurface(struct wl_buffer* buff
     else {
         LOG_DEBUG("WaylandBaseWindowSystem", "wl buffer");
 
-        ilmSurface->removeNativeContent();
-        ilmSurface->setNativeContent((long int)buffer);
-
-        WaylandPlatformSurface* nativePlatformSurface = (WaylandPlatformSurface*)ilmSurface->platform;
-        if (0 != nativePlatformSurface)
-        {
-            windowSystem->graphicSystem->getTextureBinder()->createClientBuffer(ilmSurface);
-            LOG_DEBUG("WaylandBaseWindowSystem","nativePlatformSurface->enable");
-            nativePlatformSurface->enableRendering();
-        }
-
         // TODO: we need to get the visual from the wl_buffer */
         // es->visual = WLSC_PREMUL_ARGB_VISUAL;
         // es->pitch = es->width;
@@ -525,7 +587,7 @@ extern "C" void WaylandBaseWindowSystem::surfaceIFAttach(struct wl_client* clien
               struct wl_resource* resource,
               struct wl_resource* buffer_resource, int32_t x, int32_t y)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "surfaceIFAttach client:" << client << ", resource:" << resource << ", buffer_resource:" << buffer_resource << ", x:" << x << ", y:" << y);
+    LOG_DEBUG("WaylandBaseWindowSystem", "surfaceIFAttach client:" << client << ", resource:" << resource << ", buffer_resource:" << buffer_resource << ", x:" << x << ", y:" << y);
     LOG_DEBUG("WaylandBaseWindowSystem", "surfaceIFAttach IN");
     struct native_surface* nativeSurface = (struct native_surface*)resource->data;
     WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)nativeSurface->windowSystem);
@@ -550,7 +612,7 @@ extern "C" void WaylandBaseWindowSystem::surfaceIFDamage(struct wl_client *clien
               struct wl_resource *resource,
               int32_t x, int32_t y, int32_t width, int32_t height)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "surfaceIFDamage client:" << client << ", resource:" << resource << ", x:" << x << ", y:" << y << ", width:" << width << ", height:" << height);
+    LOG_DEBUG("WaylandBaseWindowSystem", "surfaceIFDamage client:" << client << ", resource:" << resource << ", x:" << x << ", y:" << y << ", width:" << width << ", height:" << height);
     LOG_DEBUG("WaylandBaseWindowSystem", "surfaceIFDamage IN");
     struct native_surface* nativeSurface = (struct native_surface*)resource->data;
     WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)nativeSurface->windowSystem);
@@ -644,6 +706,7 @@ extern "C" void WaylandBaseWindowSystem::compositorIFCreateSurface
         break;
     }
 
+    windowSystem->checkForNewSurface();
     wl_client_add_resource(client, &surface->surface.resource);
     LOG_DEBUG("WaylandBaseWindowSystem", "compositorIFCreateSurface OUT");
 }
@@ -672,20 +735,7 @@ extern "C" void WaylandBaseWindowSystem::shmIFBufferCreated(struct wl_buffer *bu
 
 extern "C" void WaylandBaseWindowSystem::shmIFBufferDamaged(struct wl_buffer* buffer, int32_t x, int32_t y, int32_t width, int32_t height)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "shmIFBufferDamaged buffer:" << buffer << ", x:" << x << ", y:" << y << ", width:" << width << ", height:" << height);
-    LOG_DEBUG("WaylandBaseWindowSystem", "shmIFBufferDamaged IN");
-    struct wl_list* surfaces_attached_to = (struct wl_list*)buffer->user_data;
-    struct native_surface* nativeSurface;
-
-    wl_list_for_each(nativeSurface, surfaces_attached_to, buffer_link) {
-#if 0 /* ADIT TODO */
-        glBindTexture(GL_TEXTURE_2D, es->texture);
-        glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, tex_width, buffer->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, wl_shm_buffer_get_data(buffer));
-        /* Hmm, should use glTexSubImage2D() here but GLES2 doesn't
-         * support any unpack attributes except GL_UNPACK_ALIGNMENT. */
-#endif /* ADIT TODO */
-    }
-    LOG_DEBUG("WaylandBaseWindowSystem", "shmIFBufferDamaged OUT");
+    LOG_DEBUG("WaylandBaseWindowSystem", "shmIFBufferDamaged buffer:" << buffer << ", x:" << x << ", y:" << y << ", width:" << width << ", height:" << height);
 }
 
 extern "C" void WaylandBaseWindowSystem::shmIFBufferDestroyed(struct wl_buffer *buffer)
@@ -723,7 +773,7 @@ extern "C" void* WaylandBaseWindowSystem::eventLoopCallback(void *ptr)
 
 void WaylandBaseWindowSystem::bindCompositor(struct wl_client* client, void* data, uint32_t version, uint32_t id)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "bindCompositor client:" << client << ", data:" << data << ", version:" << version << ", id:" << id);
+    LOG_DEBUG("WaylandBaseWindowSystem", "bindCompositor client:" << client << ", data:" << data << ", version:" << version << ", id:" << id);
     wl_client_add_object(client, &wl_compositor_interface, &g_compositorInterface, id, data);
 }
 
@@ -735,8 +785,6 @@ void WaylandBaseWindowSystem::repaint(int msecs)
 
     Redraw();
 
-    wl_event_source_timer_update(m_idleSource, 10);
-
     wl_list_for_each_safe(cb, cnext, &m_listFrameCallback, link)
     {
         wl_resource_post_event(&cb->resource, WL_CALLBACK_DONE, msecs);
@@ -753,36 +801,12 @@ void WaylandBaseWindowSystem::idleEventRepaint(void *data)
     LOG_DEBUG("WaylandBaseWindowSystem", "idleEventRepaint OUT");
 }
 
-int WaylandBaseWindowSystem::timerEventIdle(void *data)
-{
-    WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)data);
-
-    LOG_DEBUG("WaylandBaseWindowSystem", "timerEventIdle IN");
-    windowSystem->Redraw();
-    LOG_DEBUG("WaylandBaseWindowSystem", "timerEventIdle OUT");
-
-    return 1;
-}
-
-void WaylandBaseWindowSystem::addIdleEventRepaint()
-{
-    LOG_DEBUG("WaylandBaseWindowSystem", "addIdleEventRepaint IN");
-
-    struct wl_event_loop* loop;
-    loop = wl_display_get_event_loop(m_wlDisplay);
-    wl_event_loop_add_idle(loop, idleEventRepaint, this);
-
-    LOG_DEBUG("WaylandBaseWindowSystem", "addIdleEventRepaint OUT");
-}
-
-
 bool WaylandBaseWindowSystem::initCompositor()
 {
     LOG_DEBUG("WaylandBaseWindowSystem", "initCompositor START");
-    long int status = 0;
 
-    status = (long int)wl_display_add_global(m_wlDisplay, &wl_compositor_interface, this, bindCompositor);
-    if (0 == status)
+    m_wlCompositorGlobal = wl_display_add_global(m_wlDisplay, &wl_compositor_interface, this, bindCompositor);
+    if (NULL == m_wlCompositorGlobal)
     {
         LOG_ERROR("WaylandBaseWindowSystem", "wl_display_add_global:failed to set wl_compositor_interface");
         return false;
@@ -790,33 +814,55 @@ bool WaylandBaseWindowSystem::initCompositor()
     LOG_DEBUG("WaylandBaseWindowSystem", "wl_display_add_global:SUCCESS");
 
     m_wlShm = wl_shm_init(m_wlDisplay, &g_shmCallbacks);
+    if (NULL == m_wlShm)
+    {
+        LOG_ERROR("WaylandBaseWindowSystem", "failed to init wl_shm");
+        return false;
+    }
 
     wl_list_init(&m_listFrameCallback);
 
     wl_list_init(&m_connectionList);
     createServerinfo(this);
 
-    struct wl_event_loop *loop;
-    loop = wl_display_get_event_loop(m_wlDisplay);
-    m_idleSource = wl_event_loop_add_timer(loop, timerEventIdle, this);
-    wl_event_source_timer_update(m_idleSource, m_idleTime * 1000);
-
-    addIdleEventRepaint();
-
     LOG_DEBUG("WaylandBaseWindowSystem", "initCompositor END");
     return true;
 }
 
 void WaylandBaseWindowSystem::shutdownCompositor()
 {
+    if (NULL != m_serverInfoGlobal)
+    {
+        wl_display_remove_global(m_wlDisplay, m_serverInfoGlobal);
+        m_serverInfoGlobal = NULL;
+    }
+    if (NULL != m_serverInfo)
+    {
+        free(m_serverInfo);
+        m_serverInfo = NULL;
+    }
+    if (NULL != m_wlShm)
+    {
+        wl_shm_finish(m_wlShm);
+        m_wlShm = NULL;
+    }
+    if (NULL != m_wlCompositorGlobal)
+    {
+        wl_display_remove_global(m_wlDisplay, m_wlCompositorGlobal);
+        m_wlCompositorGlobal = NULL;
+    }
+}
+
+void WaylandBaseWindowSystem::wakeUpRendererThread()
+{
 }
 
 int WaylandBaseWindowSystem::signalEventOnTerm(int signal_number, void *data)
 {
-    struct wl_display* display = (struct wl_display*)data;
+    WaylandBaseWindowSystem* windowSystem = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*)data);
 
-    LOG_ERROR("WaylandBaseWindowSystem", "caught signal " << signal_number);
-    wl_display_terminate(display);
+    LOG_INFO("WaylandBaseWindowSystem", "caught signal " << signal_number);
+    windowSystem->cleanup();
 
     return 1;
 }
@@ -826,7 +872,6 @@ void* WaylandBaseWindowSystem::eventLoop()
     // INITALIZATION
     LOG_DEBUG("WaylandBaseWindowSystem", "Enter thread");
 
-    int option_idle_time = 3000;
     bool status = true;
     struct wl_event_loop *loop;
 
@@ -842,15 +887,13 @@ void* WaylandBaseWindowSystem::eventLoop()
         LOG_DEBUG("WaylandBaseWindowSystem", "create wayland display");
 
         loop = wl_display_get_event_loop(m_wlDisplay);
-        wl_event_loop_add_signal(loop, SIGTERM, signalEventOnTerm, m_wlDisplay);
-        wl_event_loop_add_signal(loop, SIGINT, signalEventOnTerm, m_wlDisplay);
-        wl_event_loop_add_signal(loop, SIGQUIT, signalEventOnTerm, m_wlDisplay);
-        wl_event_loop_add_signal(loop, SIGKILL, signalEventOnTerm, m_wlDisplay);
+        wl_event_loop_add_signal(loop, SIGTERM, signalEventOnTerm, this);
+        wl_event_loop_add_signal(loop, SIGINT, signalEventOnTerm, this);
+        wl_event_loop_add_signal(loop, SIGQUIT, signalEventOnTerm, this);
+        wl_event_loop_add_signal(loop, SIGKILL, signalEventOnTerm, this);
 
         LOG_DEBUG("WaylandBaseWindowSystem", "wl_event_loop_add_signal");
 
-        this->m_idleTime = option_idle_time;
-
         status = this->initCompositor();
         if (false == status)
         {
@@ -910,38 +953,124 @@ void* WaylandBaseWindowSystem::eventLoop()
     return NULL;
 }
 
-void WaylandBaseWindowSystem::wakeUpRendererThread()
+extern "C" void WaylandBaseWindowSystem::surfaceListenerFrame(void* data, struct wl_callback* callback, uint32_t time)
 {
+    data = data; // TODO:to avoid warning
+    time = time; // TODO:to avoid warining
+    if (callback)
+    {
+        wl_callback_destroy(callback);
+    }
 }
 
+extern "C" const struct wl_callback_listener g_frameListener = {
+    WaylandBaseWindowSystem::surfaceListenerFrame
+};
+
 void WaylandBaseWindowSystem::signalRedrawEvent()
 {
     LOG_DEBUG("WaylandBaseWindowSystem", "signalRedrawEvent");
     // set flag that redraw is needed
     this->m_systemState = REDRAW_STATE;
-    this->wakeUpRendererThread();
+
+    struct wl_callback* callback = wl_surface_frame(m_wlSurfaceClient);
+    wl_callback_add_listener(callback, &g_frameListener, NULL);
+    wl_display_flush(m_wlDisplayClient);
 }
 
 void WaylandBaseWindowSystem::cleanup()
 {
     LOG_DEBUG("WaylandBaseWindowSystem", "Cleanup");
 
-#if 1 /* ADIT TODO */
     shutdownCompositor();
-#endif /* ADIT TODO */
 
-#if 0 /* ADIT */
     if (NULL != m_wlDisplay)
     {
-        wl_display_destroy(m_wlDisplay);
+        wl_display_terminate(m_wlDisplay);
         m_wlDisplay = NULL;
     }
-#endif /* ADIT */
 }
 
-bool WaylandBaseWindowSystem::init(BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* base)
+extern "C" void WaylandBaseWindowSystem::bindDisplayClient(struct wl_display* display, uint32_t id, const char* interface, uint32_t version, void* data)
 {
-    LOG_INFO("WaylandBaseWindowSystem", "init base:" << base);
+    LOG_DEBUG("WaylandBaseWindowSystem", "version " << version);
+    WaylandBaseWindowSystem* windowsys = static_cast<WaylandBaseWindowSystem*>( (WaylandBaseWindowSystem*) data);
+    int ans_strcmp = 0;
+
+    do
+    {
+        ans_strcmp = strcmp(interface, "wl_compositor");
+        if (0 == ans_strcmp)
+        {
+            windowsys->m_wlCompositorClient = (wl_compositor*)wl_display_bind(display, id, &wl_compositor_interface);
+            break;
+        }
+    } while(0);
+}
+
+bool WaylandBaseWindowSystem::createWaylandClient()
+{
+    do
+    {
+        while (NULL == m_wlDisplayClient)
+        {
+            usleep(10000);
+            LOG_DEBUG("WaylandBaseWindowSystem", "Waiting start wayland server");
+
+            m_wlDisplayClient = wl_display_connect(NULL);
+        }
+
+        LOG_DEBUG("WaylandBaseWindowSystem", "connect display");
+
+        m_wlCompositorGlobalListener = wl_display_add_global_listener(m_wlDisplayClient, WaylandBaseWindowSystem::bindDisplayClient, this);
+        if (NULL == m_wlCompositorGlobalListener)
+        {
+            LOG_ERROR("WaylandBaseWindowSystem", "Waiting start wayland server");
+            break;
+        }
+        wl_display_iterate(m_wlDisplayClient, WL_DISPLAY_READABLE);
+        wl_display_roundtrip(m_wlDisplayClient);
+
+        m_wlSurfaceClient = wl_compositor_create_surface(m_wlCompositorClient);
+        if (NULL == m_wlSurfaceClient)
+        {
+            LOG_ERROR("WaylandBaseWindowSystem", "failed to create client surface");
+            break;
+        }
+        LOG_DEBUG("WaylandBaseWindowSystem", "create client surface");
+
+        return true;
+    } while(0);
+
+    releaseWaylandClient();
+
+    return false;
+}
+
+void WaylandBaseWindowSystem::releaseWaylandClient()
+{
+    if (NULL != m_wlSurfaceClient)
+    {
+        wl_surface_destroy(m_wlSurfaceClient);
+        m_wlSurfaceClient = NULL;
+    }
+    if (NULL != m_wlCompositorClient)
+    {
+        wl_compositor_destroy(m_wlCompositorClient);
+        m_wlCompositorClient = NULL;
+    }
+    if (NULL != m_wlDisplayClient)
+    {
+#if 0 // will add wayland version more than 0.85.0
+        wl_display_disconnect(m_wlDisplayClient);
+#endif
+        m_wlDisplayClient = NULL;
+    }
+}
+
+bool WaylandBaseWindowSystem::init(BaseGraphicSystem<void*, void*>* base)
+{
+    LOG_DEBUG("WaylandBaseWindowSystem", "init base:" << base);
     graphicSystem = base;
     int status = pthread_create(&renderThread, NULL, eventLoopCallback, (void*)this);
     if (0 != status)
@@ -970,6 +1099,13 @@ bool WaylandBaseWindowSystem::start()
         pthread_mutex_unlock(&run_lock);
         result = false;
     }
+
+    result = createWaylandClient();
+    if (false == result)
+    {
+        LOG_DEBUG("WaylandBaseWindowSystem", "Failed to create wayland client");
+    }
+
     return result;
 }
 
@@ -978,10 +1114,9 @@ void WaylandBaseWindowSystem::stop()
     LOG_INFO("WaylandBaseWindowSystem","Stopping..");
     // needed if start was never called, we wake up thread, so it can immediatly finish
     // this->signalRedrawEvent();
-    if (NULL != m_wlDisplay)
-    {
-        wl_display_terminate(m_wlDisplay);
-    }
+
+    releaseWaylandClient();
+
     pthread_mutex_unlock(&run_lock);
     pthread_join(renderThread, NULL);
 }
index 7c24cb2..0e612de 100644 (file)
@@ -58,7 +58,7 @@ WaylandDrmWindowSystem::~WaylandDrmWindowSystem()
 bool WaylandDrmWindowSystem::initGraphicSystem()
 {
        graphicSystem->setBaseWindowSystem(this);
-    return graphicSystem->init((EGLNativeDisplayType)m_gbm, (EGLNativeWindowType)NULL);
+    return graphicSystem->init((void*)m_gbm, (void*)NULL);
 }
 
 bool WaylandDrmWindowSystem::createNativeContext()
index 4c85b41..f3ee75f 100644 (file)
@@ -54,7 +54,7 @@ WaylandFbdevWindowSystem::WaylandFbdevWindowSystem(const char* displayname, int
 
 bool WaylandFbdevWindowSystem::initGraphicSystem()
 {
-    return graphicSystem->init((EGLNativeDisplayType)m_fdFB, (EGLNativeWindowType)NULL);
+    return graphicSystem->init((void*)m_fdFB, (void*)NULL);
 }
 
 bool WaylandFbdevWindowSystem::createNativeContext()
index 0cdd4e9..5c4fe92 100644 (file)
@@ -63,7 +63,7 @@ bool WaylandX11WindowSystem::initGraphicSystem()
     LOG_DEBUG("WaylandX11WindowSystem", "initGraphicSystem IN");
 
     //. create egl context
-    status = graphicSystem->init((EGLNativeDisplayType)m_x11Display, (EGLNativeWindowType)m_x11Window);
+    status = graphicSystem->init((void*)m_x11Display, (void*)m_x11Window);
     if (false == status)
     {
         LOG_ERROR("WaylandX11WindowSystem", "failed to init graphicSystem");
index 13470ba..12f304e 100644 (file)
@@ -76,7 +76,7 @@ bool WaylandGLESRenderer::start(int width, int height, const char* displayname)
     m_pGraphicSystem = new GLESGraphicsystem(width,height, ShaderProgramGLES::createProgram);
 #endif
 
-    if (!m_pWindowSystem->init((BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>*) m_pGraphicSystem))
+    if (!m_pWindowSystem->init((BaseGraphicSystem<void*, void*>*) m_pGraphicSystem))
     {
         goto fail; // TODO bad style
     }