X11WindowSystem: Introducing new SystemStates
authorMichael Schuldt <michael.schuldt@bmw-carit.de>
Fri, 23 Dec 2011 09:41:47 +0000 (10:41 +0100)
committerMichael Schuldt <michael.schuldt@bmw-carit.de>
Fri, 23 Dec 2011 09:41:47 +0000 (10:41 +0100)
- redrawEvent removed, new SystemState REDRAW_STATE introduced
- some class methods to inline declaration.
- introducing wakeUpRendererThread

LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp

index 1f17b9f..96941b6 100644 (file)
 
 typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy);
 
+typedef enum x11WindowSystemStates
+{
+    REDRAW_STATE = 0,
+    WAKEUP_STATE = 1,
+    IDLE_STATE = 2,
+    UNKOWN_STATE    
+} X11WindowSystemStates;
+
 class X11WindowSystem: public BaseWindowSystem
 {
 public:
@@ -41,23 +49,16 @@ public:
     bool start();
     void stop();
     static XVisualInfo * getDefaultVisual(Display *dpy);
-       void signalRedrawEvent();
-
-    Display* getNativeDisplayHandle()
-    {
-        return x11Display;
-    }
-
-    Window getCompositorNativeWindowHandle()
-    {
-        return CompositorWindow;
-    }
-
+    void signalRedrawEvent();
+    void wakeUpRendererThread();
+    void setSystemState (X11WindowSystemStates state);
+    X11WindowSystemStates getSystemState ();
+    Display* getNativeDisplayHandle();
+    Window getCompositorNativeWindowHandle();
     virtual void allocatePlatformSurface(Surface *surface);
     void doScreenShot(std::string fileName);
     void doScreenShotOfLayer(std::string fileName, const uint id);
     void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id);
-
 private:
     ScreenShotType takeScreenshot;
     std::string screenShotFile;
@@ -71,13 +72,14 @@ private:
     static int composite_opcode;
     int composite_event, composite_error;
     int composite_major, composite_minor;
-       static int damage_opcode;
-       int damage_event, damage_error;
-       int damage_major, damage_minor;
+    static int damage_opcode;
+    int damage_event, damage_error;
+    int damage_major, damage_minor;
     static const char CompositorWindowTitle[];
     bool m_running;
     bool m_initialized;
     bool m_success;
+    X11WindowSystemStates m_systemState;
 
 protected:
     Display* x11Display;
@@ -119,13 +121,32 @@ private:
     void printDebug();
     void* EventLoop();
     static int error(Display *dpy, XErrorEvent *ev);
-    bool redrawEvent;
+
     static bool m_xerror;
     #ifdef WITH_INPUT_EVENTS
     void ManageXInputEvent(XEvent *pevent);
     #endif
-
+    
     friend void * X11eventLoopCallback(void *);
 };
 
+inline void X11WindowSystem::setSystemState (X11WindowSystemStates state)
+{
+        m_systemState = state;
+};
+inline X11WindowSystemStates X11WindowSystem::getSystemState () 
+{
+    return m_systemState;
+};
+
+inline Display* X11WindowSystem::getNativeDisplayHandle()
+{
+    return x11Display;
+}
+
+inline Window X11WindowSystem::getCompositorNativeWindowHandle()
+{
+    return CompositorWindow;
+}
+
 #endif /* _X11WINDOWSYSTEM_H_ */
index f77ee2b..5e49839 100644 (file)
@@ -50,7 +50,7 @@ X11WindowSystem::X11WindowSystem(const char* displayname, int width, int height,
 , m_success(false)
 , windowWidth(width)
 , windowHeight(height)
-, redrawEvent(false)
+, m_systemState(IDLE_STATE)
 {
     LOG_DEBUG("X11WindowSystem", "creating X11WindowSystem");
 
@@ -558,12 +558,11 @@ void X11WindowSystem::Redraw()
 
     CheckRedrawAllLayers();
     if (m_damaged)
-    {
+    {   
         graphicSystem->clearBackground();
         RedrawAllLayers();
-        m_pScene->unlockScene();
+        m_pScene->unlockScene();       
         graphicSystem->swapBuffers();
-
         if (debugMode)
         {
             printDebug();
@@ -823,9 +822,10 @@ init_complete:
 #ifndef WITH_XTHREADS
         }
 #endif //WITH_XTHREADS
-        if (this->redrawEvent)
+        if (this->m_systemState == REDRAW_STATE)
         {
-            this->redrawEvent = false;
+            LOG_DEBUG("X11WindowSystem", "Enter Redraw State");
+            this->m_systemState = IDLE_STATE;
 
             // check if we are supposed to take screenshot
             if (this->takeScreenshot!=ScreenShotNone)
@@ -838,6 +838,10 @@ init_complete:
                 checkRedraw = true;
             }
 
+        } 
+        else if (this->m_systemState == WAKEUP_STATE)         
+        {
+            LOG_DEBUG("X11WindowSystem", "Enter Wake Up State");
         }
 
         if (checkRedraw)
@@ -894,11 +898,8 @@ void X11WindowSystem::ManageXInputEvent(XEvent *pevent)
 #ifdef WITH_XTHREADS
 static Display* displaySignal = NULL;
 #endif //WITH_XTHREADS
-void X11WindowSystem::signalRedrawEvent()
+void X11WindowSystem::wakeUpRendererThread() 
 {
-    // set flag that redraw is needed
-    redrawEvent = true;
-    m_damaged = true;
 #ifdef WITH_XTHREADS
     // send dummy expose event, to wake up blocking x11 event loop (XNextEvent)
     LOG_DEBUG("X11WindowSystem", "Sending dummy event to wake up renderer thread");
@@ -915,6 +916,14 @@ void X11WindowSystem::signalRedrawEvent()
 #endif //WITH_XTHREADS
 }
 
+void X11WindowSystem::signalRedrawEvent()
+{
+    // set flag that redraw is needed
+    this->m_systemState = REDRAW_STATE;
+    m_damaged = true;
+    this->wakeUpRendererThread();
+}
+
 void X11WindowSystem::cleanup(){
     LOG_DEBUG("X11WindowSystem", "Cleanup");
     if (None != CompositorWindow)