Initial support for Wayland 1.3.
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Graphic / include / WindowSystems / WaylandBaseWindowSystem.h
index 2a03252..8e89d59 100644 (file)
  *
  ****************************************************************************/
 
-#ifndef _WAYLANDWINDOWSYSTEM_H_
-#define _WAYLANDWINDOWSYSTEM_H_
+#ifndef _WAYLANDBASEWINDOWSYSTEM_H_
+#define _WAYLANDBASEWINDOWSYSTEM_H_
 #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"
 #include "config.h"
+#include "InputManager.h"
+#include "WindowSystems/WaylandInputEvent.h"
+#include "Rectangle.h"
 
 extern "C" {
 // TODO:to abstract
@@ -50,37 +52,63 @@ typedef enum waylandWindowSystemStates
     UNKOWN_STATE
 } WaylandWindowSystemStates;
 
+typedef struct _wlevent
+{
+    int        x;
+    int y;
+    int32_t    button;
+    enum wl_pointer_button_state buttonState;
+    long       keyCode;
+    enum wl_keyboard_key_state   keyState;
+    uint32_t   serial;
+    uint32_t   axis;
+    wl_fixed_t axisValue;
+    int        touchId;
+    int        touchType;
+} WLEvent;
 } // extern "C"
 
 struct native_surface;
 
-class WaylandBaseWindowSystem: public BaseWindowSystem
+class WaylandBaseWindowSystem : public BaseWindowSystem
 {
 public:
-    WaylandBaseWindowSystem(const char* displayname, int width, int height, Scene* pScene);
-    ~WaylandBaseWindowSystem();
-    bool init(BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* sys);
-    bool start();
+    WaylandBaseWindowSystem(const char* displayname, int width, int height, Scene* pScene, InputManager* pInputManager);
+    virtual ~WaylandBaseWindowSystem();
+    bool init(BaseGraphicSystem<void*, void*>* sys);
+    bool start(int maxIterationDurationInMS);
     void stop();
     void signalRedrawEvent();
     void wakeUpRendererThread();
-    void setSystemState(WaylandWindowSystemStates state);      // TODO:don't check state
+    void setSystemState(WaylandWindowSystemStates state);   // TODO:don't check state
     WaylandWindowSystemStates getSystemState();
     struct wl_display* getNativeDisplayHandle();
     virtual void allocatePlatformSurface(Surface *surface);
-    void doScreenShot(std::string fileName);
+    virtual void deallocatePlatformSurface(Surface *surface);
+    void doScreenShot(std::string fileName, const uint screen_id);
     void doScreenShotOfLayer(std::string fileName, const uint id);
     void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id);
+    int getWindowWidth() const;
+    int getWindowHeight() const;
+    virtual void finishFrame();
+    virtual void scheduleRepaint(void *data);
 
 protected:
     struct wl_display* m_wlDisplay;
+    struct wl_display* m_wlDisplayClient;
+    struct wl_registry* m_wlRegistryClient;
+    struct wl_compositor* m_wlCompositorClient;
+    struct wl_surface* m_wlSurfaceClient;
     pthread_t renderThread;
     pthread_mutex_t run_lock;
-    BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* graphicSystem;
-    virtual void CheckRedrawAllLayers();
-    virtual void RedrawAllLayers();
+    BaseGraphicSystem<void*, void*>* graphicSystem;
+    virtual void RedrawAllLayers(bool clear, bool swap);
+    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;
 
@@ -91,37 +119,50 @@ protected:
     WaylandWindowSystemStates m_systemState;
     uint m_manageConnectionId;
     std::string m_screenShotFile;
+    uint m_screenShotScreenID;
     uint m_screenShotSurfaceID;
     uint m_screenShotLayerID;
     bool m_debugMode;
     bool m_error;
     int m_width;
     int m_height;
+    bool m_bRepaintNeeded;
+    bool m_bRepaintScheduled;
+    bool m_bUseFrameTimer;
+    struct wl_event_source* m_finishFrameTimer;
+
+    struct wl_list m_listFrameCallback;
+    struct wl_list m_nativeSurfaceList;
 
-    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
+    int m_maxIterationDurationInMS;
 
     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!!
+    virtual void attachBufferToNativeSurface(struct wl_buffer* buffer, struct wl_surface* surface);
     void repaint(int msecs);
     void cleanup();
     void Screenshot();
     void Redraw();
     void shutdownCompositor();
     Surface* getSurfaceFromNativeSurface(struct native_surface* nativeSurface);
-    void checkForNewSurface();
+    struct native_surface* getNativeSurfaceFromSurface(Surface* surface);
+    virtual void checkForNewSurfaceNativeContent();
+    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 destroyListenerSurfaceBuffer(struct wl_listener* listener, void *data);
+    static void destroyListenerSurfacePendingBuffer(struct wl_listener* listener, void *data);
     static void idleEventRepaint(void *data);
+    bool createWaylandClient();
+    void releaseWaylandClient();
+
+    WaylandInputEvent* m_inputEvent;
+    virtual bool createInputEvent();
 
 public:
     static void serverinfoIFCreateConnection(struct wl_client *client, struct wl_resource *resource);
@@ -130,64 +171,119 @@ public:
     static void destroySurfaceCallback(struct wl_resource* resource);
     static void destroyFrameCallback(struct wl_resource *resource);
     static void* eventLoopCallback(void* ptr);
+    static void registryHandleGlobalClient(void* data,
+                                            struct wl_registry* registry,
+                                            uint32_t name,
+                                            const char* interface,
+                                            uint32_t version);
+    static void surfaceListenerFrame(void* data, struct wl_callback* callback, uint32_t time);
+    static int finishFrameHandler(void *data);
 
     // wl_surface interface
-    static void surfaceIFDestroy(struct wl_client *client, struct wl_resource *resource);
-    static void surfaceIFAttach(struct wl_client *client, struct wl_resource *resource, struct wl_resource *buffer_resource, int32_t x, int32_t y);
-    static void surfaceIFDamage(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
-    static void surfaceIFFrame(struct wl_client *client, struct wl_resource *resource, uint32_t callback);
+    static void surfaceIFDestroy(struct wl_client *client,
+                                struct wl_resource *resource);
+    static void surfaceIFAttach(struct wl_client *client,
+                                struct wl_resource *resource,
+                                struct wl_resource *buffer_resource,
+                                int32_t x,
+                                int32_t y);
+    static void surfaceIFDamage(struct wl_client *client,
+                                struct wl_resource *resource,
+                                int32_t x,
+                                int32_t y,
+                                int32_t width,
+                                int32_t height);
+    static void surfaceIFFrame(struct wl_client *client,
+                                struct wl_resource *resource,
+                                uint32_t callback);
+    static void surfaceIFCommit(struct wl_client *client,
+                                struct wl_resource *resource);
 
     // wl_compositor interface
     static void compositorIFCreateSurface(struct wl_client *client, struct wl_resource* resource, uint32_t id);
 
-    // wl_shm interface
-    static void shmIFBufferCreated(struct wl_buffer *buffer);
-    static void shmIFBufferDamaged(struct wl_buffer *buffer, int32_t x, int32_t y, int32_t width, int32_t height);
-    static void shmIFBufferDestroyed(struct wl_buffer *buffer);
-
     struct wl_list m_connectionList;
+
+    // Input event
+    void manageWLInputEvent(const InputDevice type, const InputEventState state, const WLEvent *wlEvent);
 };
 
-inline void WaylandBaseWindowSystem::setSystemState (WaylandWindowSystemStates state)
+inline void WaylandBaseWindowSystem::setSystemState(WaylandWindowSystemStates state)
 {
     m_systemState = state;
-};
-inline WaylandWindowSystemStates WaylandBaseWindowSystem::getSystemState ()
+}
+
+inline WaylandWindowSystemStates WaylandBaseWindowSystem::getSystemState()
 {
     return m_systemState;
-};
+}
 
 inline struct wl_display* WaylandBaseWindowSystem::getNativeDisplayHandle()
 {
     return m_wlDisplay;
 }
 
+inline bool WaylandBaseWindowSystem::createInputEvent()
+{
+    return false;
+}
+
+inline int WaylandBaseWindowSystem::getWindowWidth() const
+{
+    return m_width;
+}
+
+inline int WaylandBaseWindowSystem::getWindowHeight() const
+{
+    return m_height;
+}
+
 extern "C" {
-    struct native_surface {
-        struct wl_surface surface;
-        WaylandBaseWindowSystem* windowSystem;
-        struct wl_buffer* buffer;
-        int connectionId;
-
-        struct wl_list buffer_link; // TODO confirm:it's necessary or not
-        uint32_t visual; // TODO confirm:it's necessary or not
-        struct wl_listener buffer_destroy_listener; // TODO it's necessary or not
-        struct wl_list link;
-    };
-
-    struct native_frame_callback {
-        struct wl_resource resource;
-        struct wl_list link;
-    };
-
-    struct native_process;
-    typedef void (*cleanupFuncForNativeProcess)(struct native_process* process, int status);
-
-    struct native_process {
-        pid_t pid;
-        cleanupFuncForNativeProcess cleanup;
-        struct wl_list link;
-    };
+struct native_surface
+{
+    struct wl_surface* surface;
+    WaylandBaseWindowSystem* windowSystem;
+    struct wl_buffer* buffer;
+    int connectionId;
+
+    uint32_t visual; // TODO confirm:it's necessary or not
+    struct wl_listener buffer_destroy_listener;
+    struct wl_list link;
+
+    /* All the pending state, that wl_surface.commit will apply. */
+    struct
+    {
+        /* wl_surface.attach */
+        int remove_contents;
+        struct wl_buffer *buffer;
+        struct wl_listener buffer_destroy_listener;
+        int32_t sx;
+        int32_t sy;
+
+        /* wl_surface.damage */
+        Rectangle damage;
+        bool damaged;
+
+        /* wl_surface.frame */
+        struct wl_list frame_callback_list;
+    } pending;
+};
+
+struct native_frame_callback
+{
+    struct wl_resource* resource;
+    struct wl_list link;
+};
+
+struct native_process;
+typedef void (*cleanupFuncForNativeProcess)(struct native_process* process, int status);
+
+struct native_process
+{
+    pid_t pid;
+    cleanupFuncForNativeProcess cleanup;
+    struct wl_list link;
+};
 }
 
-#endif /* _WAYLANDWINDOWSYSTEM_H_ */
+#endif /* _WAYLANDBASEWINDOWSYSTEM_H_ */