1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
20 #ifndef _X11WINDOWSYSTEM_H_
21 #define _X11WINDOWSYSTEM_H_
22 #include "WindowSystems/BaseWindowSystem.h"
23 #include "GraphicSystems/BaseGraphicSystem.h"
26 #include "PlatformSurfaces/XPlatformSurface.h"
27 #include <X11/Xutil.h>
28 #include <X11/extensions/Xfixes.h>
30 #include "ScreenShotType.h"
33 typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy);
35 typedef enum x11WindowSystemStates
41 } X11WindowSystemStates;
43 class X11WindowSystem : public BaseWindowSystem
46 X11WindowSystem(const char* displayname,
50 InputManager* pInputManager,
51 GetVisualInfoFunction func = X11WindowSystem::getDefaultVisual);
52 virtual ~X11WindowSystem();
53 bool init(BaseGraphicSystem<Display*, Window>* sys);
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);
69 ScreenShotType takeScreenshot;
70 std::string screenShotFile;
71 uint screenShotSurfaceID;
72 uint screenShotLayerID;
73 const char* displayname;
74 GetVisualInfoFunction getVisualFunc;
78 static int composite_opcode;
83 static int damage_opcode;
88 static const char CompositorWindowTitle[];
90 /* bool m_initialized; */
92 X11WindowSystemStates m_systemState;
93 const char* m_displayEnvironment;
98 XserverRegion x11DamageRegion;
99 pthread_t renderThread;
100 //void setDisplayMode();
103 // Window background;
104 Window CompositorWindow;
105 XVisualInfo* windowVis;
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);
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);
141 static int error(Display *dpy, XErrorEvent *ev);
142 void ManageXInputEvent(InputDevice type, InputEventState state, XEvent *pevent);
143 static bool m_xerror;
145 friend void * X11eventLoopCallback(void *);
148 inline void X11WindowSystem::setSystemState(X11WindowSystemStates state)
150 m_systemState = state;
153 inline X11WindowSystemStates X11WindowSystem::getSystemState()
155 return m_systemState;
158 inline Display* X11WindowSystem::getNativeDisplayHandle()
163 inline Window X11WindowSystem::getCompositorNativeWindowHandle()
165 return CompositorWindow;
168 #endif /* _X11WINDOWSYSTEM_H_ */