X11WindowSystem: Introducing skip of DamageEvents for resized surfaces
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Graphic / include / WindowSystems / X11WindowSystem.h
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19
20 #ifndef _X11WINDOWSYSTEM_H_
21 #define _X11WINDOWSYSTEM_H_
22 #include "WindowSystems/BaseWindowSystem.h"
23 #include "GraphicSystems/BaseGraphicSystem.h"
24 #include "X11/Xlib.h"
25 #include "Surface.h"
26 #include "PlatformSurfaces/XPlatformSurface.h"
27 #include <X11/Xutil.h>
28 #include <X11/extensions/Xfixes.h>
29 #include "Log.h"
30 #include "ScreenShotType.h"
31
32
33 typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy);
34
35 typedef enum x11WindowSystemStates
36 {
37     REDRAW_STATE = 0,
38     WAKEUP_STATE = 1,
39     IDLE_STATE = 2,
40     UNKOWN_STATE
41 } X11WindowSystemStates;
42
43 class X11WindowSystem : public BaseWindowSystem
44 {
45 public:
46     X11WindowSystem(const char* displayname,
47                     int width,
48                     int height,
49                     Scene* pScene,
50                     InputManager* pInputManager,
51                     GetVisualInfoFunction func = X11WindowSystem::getDefaultVisual);
52     virtual ~X11WindowSystem();
53     bool init(BaseGraphicSystem<Display*, Window>* sys);
54     bool start();
55     void stop();
56     static XVisualInfo * getDefaultVisual(Display *dpy);
57     void signalRedrawEvent();
58     void wakeUpRendererThread();
59     void setSystemState(X11WindowSystemStates state);
60     X11WindowSystemStates getSystemState();
61     Display* getNativeDisplayHandle();
62     Window getCompositorNativeWindowHandle();
63     virtual void allocatePlatformSurface(Surface *surface);
64     virtual void deallocatePlatformSurface(Surface *surface);
65     void doScreenShot(std::string fileName);
66     void doScreenShotOfLayer(std::string fileName, const uint id);
67     void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id);
68 private:
69     ScreenShotType takeScreenshot;
70     std::string screenShotFile;
71     uint screenShotSurfaceID;
72     uint screenShotLayerID;
73     const char* displayname;
74     GetVisualInfoFunction getVisualFunc;
75     bool debugMode;
76     int resolutionWidth;
77     int resolutionHeight;
78     static int composite_opcode;
79     int composite_event;
80     int composite_error;
81     int composite_major;
82     int composite_minor;
83     static int damage_opcode;
84     int damage_event;
85     int damage_error;
86     int damage_major;
87     int damage_minor;
88     static const char CompositorWindowTitle[];
89     bool m_running;
90 /*    bool m_initialized; */
91     bool m_success;
92     X11WindowSystemStates m_systemState;
93     const char* m_displayEnvironment;
94
95 protected:
96     Display* x11Display;
97
98     XserverRegion x11DamageRegion;
99     pthread_t renderThread;
100     //void setDisplayMode();
101     int windowWidth;
102     int windowHeight;
103     //    Window background;
104     Window CompositorWindow;
105     XVisualInfo* windowVis;
106     float m_fpsinterval;
107     pthread_mutex_t run_lock;
108     pthread_mutex_t init_lock;
109     pthread_cond_t init_condition;
110     pthread_cond_t run_condition;
111     BaseGraphicSystem<Display*, Window>* graphicSystem;
112     virtual bool initXServer();
113     virtual void RedrawAllLayers(bool clear, bool swap);
114     virtual void renderHWLayer(Layer* layer);
115     virtual void calculateFps();
116     virtual void calculateSurfaceFps(Surface *currentSurface, float time);
117 private:
118     void cleanup();
119     void Screenshot();
120     void Redraw();
121     bool OpenDisplayConnection();
122     bool checkForCompositeExtension();
123     bool checkForDamageExtension();
124     void createSurfaceForWindow(Window w);
125     void configureSurfaceWindow(Window w);
126     Surface* getSurfaceForWindow(Window w);
127     void checkForNewSurfaceNativeContent();
128     void destroy_surface(Window w);
129     void updateSurface(Surface* s, Window w, XPlatformSurface* x11surf);
130     void MapWindow(Window w);
131     void UnMapWindow(Window w);
132     void NewWindow(Surface* s, Window w);
133     void DestroyWindow(Window w);
134     bool isWindowValid(Window w);
135     bool CreatePixmapsForAllWindows();
136     bool CreateCompositorWindow();
137     void UnredirectSpecialWIndows(Window w);
138
139     void printDebug();
140     void* EventLoop();
141     static int error(Display *dpy, XErrorEvent *ev);
142     void ManageXInputEvent(InputDevice type, InputEventState state, XEvent *pevent);
143     static bool m_xerror;
144
145     friend void * X11eventLoopCallback(void *);
146 };
147
148 inline void X11WindowSystem::setSystemState(X11WindowSystemStates state)
149 {
150     m_systemState = state;
151 }
152
153 inline X11WindowSystemStates X11WindowSystem::getSystemState()
154 {
155     return m_systemState;
156 }
157
158 inline Display* X11WindowSystem::getNativeDisplayHandle()
159 {
160     return x11Display;
161 }
162
163 inline Window X11WindowSystem::getCompositorNativeWindowHandle()
164 {
165     return CompositorWindow;
166 }
167
168 #endif /* _X11WINDOWSYSTEM_H_ */