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);
54 bool start(int maxIterationDurationInMS);
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 int getIterationCounter();
70 ScreenShotType takeScreenshot;
71 std::string screenShotFile;
72 uint screenShotSurfaceID;
73 uint screenShotLayerID;
74 const char* displayname;
75 GetVisualInfoFunction getVisualFunc;
79 static int composite_opcode;
84 static int damage_opcode;
89 static const char CompositorWindowTitle[];
91 /* bool m_initialized; */
93 X11WindowSystemStates m_systemState;
94 const char* m_displayEnvironment;
95 int m_iterationCounter;
96 int m_maxIterationDurationInMS;
101 XserverRegion x11DamageRegion;
102 pthread_t renderThread;
103 //void setDisplayMode();
106 // Window background;
107 Window CompositorWindow;
108 XVisualInfo* windowVis;
110 pthread_mutex_t run_lock;
111 pthread_mutex_t init_lock;
112 pthread_cond_t init_condition;
113 pthread_cond_t run_condition;
114 BaseGraphicSystem<Display*, Window>* graphicSystem;
115 virtual bool initXServer();
116 virtual bool RedrawAllLayers(bool clear, bool swap);
117 virtual void renderHWLayer(Layer* layer);
118 virtual void calculateFps();
119 virtual void calculateSurfaceFps(Surface *currentSurface, float time);
124 bool OpenDisplayConnection();
125 bool checkForCompositeExtension();
126 bool checkForDamageExtension();
127 void createSurfaceForWindow(Window w);
128 void configureSurfaceWindow(Window w);
129 Surface* getSurfaceForWindow(Window w);
130 void checkForNewSurfaceNativeContent();
131 void destroy_surface(Window w);
132 void updateSurface(Surface* s, Window w, XPlatformSurface* x11surf);
133 void MapWindow(Window w);
134 void UnMapWindow(Window w);
135 void NewWindow(Surface* s, Window w);
136 void DestroyWindow(Window w);
137 bool isWindowValid(Window w);
138 bool CreatePixmapsForAllWindows();
139 bool CreateCompositorWindow();
140 void UnredirectSpecialWIndows(Window w);
144 static int error(Display *dpy, XErrorEvent *ev);
145 void ManageXInputEvent(InputDevice type, InputEventState state, XEvent *pevent);
146 static bool m_xerror;
148 friend void * X11eventLoopCallback(void *);
151 inline void X11WindowSystem::setSystemState(X11WindowSystemStates state)
153 m_systemState = state;
156 inline X11WindowSystemStates X11WindowSystem::getSystemState()
158 return m_systemState;
161 inline Display* X11WindowSystem::getNativeDisplayHandle()
166 inline Window X11WindowSystem::getCompositorNativeWindowHandle()
168 return CompositorWindow;
171 #endif /* _X11WINDOWSYSTEM_H_ */