1 /***************************************************************************
3 * Copyright 2010, 2011 BMW Car IT GmbH
4 * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
21 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
24 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
25 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 ****************************************************************************/
30 #ifndef _WAYLANDWINDOWSYSTEM_H_
31 #define _WAYLANDWINDOWSYSTEM_H_
32 #include "WindowSystems/BaseWindowSystem.h"
33 #include "GraphicSystems/BaseGraphicSystem.h"
36 #include <EGL/eglext.h>
37 #include <wayland-server.h>
38 #include "PlatformSurfaces/WaylandPlatformSurface.h"
40 #include "ScreenShotType.h"
45 typedef enum waylandWindowSystemStates
51 } WaylandWindowSystemStates;
55 struct native_surface;
57 class WaylandBaseWindowSystem: public BaseWindowSystem
60 WaylandBaseWindowSystem(const char* displayname, int width, int height, Scene* pScene);
61 virtual ~WaylandBaseWindowSystem();
62 bool init(BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* sys);
65 void signalRedrawEvent();
66 void wakeUpRendererThread();
67 void setSystemState(WaylandWindowSystemStates state); // TODO:don't check state
68 WaylandWindowSystemStates getSystemState();
69 struct wl_display* getNativeDisplayHandle();
70 virtual void allocatePlatformSurface(Surface *surface);
71 void doScreenShot(std::string fileName);
72 void doScreenShotOfLayer(std::string fileName, const uint id);
73 void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id);
76 struct wl_display* m_wlDisplay;
77 pthread_t renderThread;
78 pthread_mutex_t run_lock;
79 BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType>* graphicSystem;
80 virtual void CheckRedrawAllLayers();
81 virtual void RedrawAllLayers();
82 virtual bool initCompositor();
83 struct wl_shm* m_wlShm;
84 virtual bool createNativeContext() = 0;
85 virtual bool initGraphicSystem() = 0;
88 ScreenShotType m_takeScreenshot;
89 const char* m_displayname;
91 WaylandWindowSystemStates m_systemState;
92 uint m_manageConnectionId;
93 std::string m_screenShotFile;
94 uint m_screenShotSurfaceID;
95 uint m_screenShotLayerID;
101 struct wl_list m_listFrameCallback; // TODO:confirm:what's this
102 struct wl_event_source* m_idleSource; // TODO:confirm:what's this
103 int m_idleTime; // TODO:confirm:what's this
105 void createServerinfo(WaylandBaseWindowSystem* windowSystem);
106 void addIdleEventRepaint(); // TODO:confirm:what's this
107 struct native_surface* createNativeSurface();
108 void postReleaseBuffer(struct wl_buffer *buffer);
109 void attachBufferToNativeSurface(struct wl_buffer* buffer, struct wl_surface* surface); // ADIT TODO:reconfirm!!
110 void repaint(int msecs);
114 void shutdownCompositor();
115 Surface* getSurfaceFromNativeSurface(struct native_surface* nativeSurface);
116 void checkForNewSurface();
120 static void bindCompositor(struct wl_client* client, void* data, uint32_t version, uint32_t id);
121 static int signalEventOnTerm(int signal_number, void *data);
122 static void destroyListenerSurfaceBuffer(struct wl_listener* listener, struct wl_resource* resource, uint32_t time);
123 static int timerEventIdle(void *data);
124 static void idleEventRepaint(void *data);
127 static void serverinfoIFCreateConnection(struct wl_client *client, struct wl_resource *resource);
128 static void bindServerinfo(struct wl_client *client, void *data, uint32_t version, uint32_t id);
129 static uint32_t getTime(void);
130 static void destroySurfaceCallback(struct wl_resource* resource);
131 static void destroyFrameCallback(struct wl_resource *resource);
132 static void* eventLoopCallback(void* ptr);
134 // wl_surface interface
135 static void surfaceIFDestroy(struct wl_client *client, struct wl_resource *resource);
136 static void surfaceIFAttach(struct wl_client *client, struct wl_resource *resource, struct wl_resource *buffer_resource, int32_t x, int32_t y);
137 static void surfaceIFDamage(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height);
138 static void surfaceIFFrame(struct wl_client *client, struct wl_resource *resource, uint32_t callback);
140 // wl_compositor interface
141 static void compositorIFCreateSurface(struct wl_client *client, struct wl_resource* resource, uint32_t id);
144 static void shmIFBufferCreated(struct wl_buffer *buffer);
145 static void shmIFBufferDamaged(struct wl_buffer *buffer, int32_t x, int32_t y, int32_t width, int32_t height);
146 static void shmIFBufferDestroyed(struct wl_buffer *buffer);
148 struct wl_list m_connectionList;
151 inline void WaylandBaseWindowSystem::setSystemState (WaylandWindowSystemStates state)
153 m_systemState = state;
155 inline WaylandWindowSystemStates WaylandBaseWindowSystem::getSystemState ()
157 return m_systemState;
160 inline struct wl_display* WaylandBaseWindowSystem::getNativeDisplayHandle()
166 struct native_surface {
167 struct wl_surface surface;
168 WaylandBaseWindowSystem* windowSystem;
169 struct wl_buffer* buffer;
172 struct wl_list buffer_link; // TODO confirm:it's necessary or not
173 uint32_t visual; // TODO confirm:it's necessary or not
174 struct wl_listener buffer_destroy_listener; // TODO it's necessary or not
178 struct native_frame_callback {
179 struct wl_resource resource;
183 struct native_process;
184 typedef void (*cleanupFuncForNativeProcess)(struct native_process* process, int status);
186 struct native_process {
188 cleanupFuncForNativeProcess cleanup;
193 #endif /* _WAYLANDWINDOWSYSTEM_H_ */