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.
19 ****************************************************************************/
21 #include "WaylandGLESRenderer.h"
24 #include "ShaderProgramGLES.h"
25 #include "TextureBinders/WaylandGLESTexture.h"
26 #ifdef WITH_WAYLAND_FBDEV
27 #include "WindowSystems/WaylandFbdevWindowSystem.h"
28 #endif // WITH_WAYLAND_FBDEV
29 #ifdef WITH_WAYLAND_X11
30 #include "WindowSystems/WaylandX11WindowSystem.h"
31 #endif // WITH_WAYLAND_X11
32 #ifdef WITH_WAYLAND_DRM
33 #include "WindowSystems/WaylandDrmWindowSystem.h"
34 #include "GraphicSystems/DrmGLESGraphicSystem.h"
35 #endif // WITH_WAYLAND_DRM
37 WaylandGLESRenderer::WaylandGLESRenderer(Scene* pScene)
38 : BaseRenderer(pScene)
45 LOG_DEBUG("WaylandGLESRenderer", "Creating Renderer");
48 bool WaylandGLESRenderer::start(int width, int height, const char* displayname)
50 struct wl_display* nativeDisplayHandle = NULL;
51 EGLDisplay eglDisplayhandle = NULL;
55 // create Wayland windows, register as composite manager etc
56 m_pWindowSystem = NULL;
57 #ifdef WITH_WAYLAND_FBDEV
58 m_pWindowSystem = new WaylandFbdevWindowSystem(displayname, width, height, m_pScene);
60 #ifdef WITH_WAYLAND_X11
61 m_pWindowSystem = new WaylandX11WindowSystem(displayname, width, height, m_pScene);
63 #ifdef WITH_WAYLAND_DRM
64 m_pWindowSystem = new WaylandDrmWindowSystem(displayname, width, height, m_pScene);
66 if( m_pWindowSystem == NULL )
68 LOG_ERROR("WaylandGLESRenderer", "Window system is not specified. Consider to specify WITH_WAYLAND_X11 or WITH_WAYLAND_FBDEV");
69 goto fail; // TODO bad style
72 #ifdef WITH_WAYLAND_DRM
73 m_pGraphicSystem = new DrmGLESGraphicSystem(width,height, ShaderProgramGLES::createProgram);
75 m_pGraphicSystem = new GLESGraphicsystem(width,height, ShaderProgramGLES::createProgram);
78 if (!m_pWindowSystem->init((BaseGraphicSystem<void*, void*>*) m_pGraphicSystem))
80 goto fail; // TODO bad style
83 m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
85 // create graphic context from window, init egl etc
86 nativeDisplayHandle = m_pWindowSystem->getNativeDisplayHandle();
88 LOG_DEBUG("WaylandGLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
90 eglDisplayhandle = m_pGraphicSystem->getEGLDisplay();
92 m_binder = new WaylandGLESTexture(eglDisplayhandle, nativeDisplayHandle);
93 if (m_binder && nativeDisplayHandle && eglDisplayhandle)
95 m_pGraphicSystem->setTextureBinder(m_binder);
97 if (!m_pWindowSystem->start())
99 goto fail; // TODO bad style
104 goto fail; // TODO bad style
108 fail: // TODO bad style
110 LOG_ERROR("WaylandGLESRenderer", "Initialization failed !");
114 void WaylandGLESRenderer::stop()
116 m_pWindowSystem->stop();
123 void WaylandGLESRenderer::doScreenShot(std::string fileToSave)
125 m_pWindowSystem->doScreenShot(fileToSave);
128 void WaylandGLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
130 m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
133 void WaylandGLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
135 m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
138 uint WaylandGLESRenderer::getNumberOfHardwareLayers(uint screenID)
141 screen_id = screenID;
143 return 0; // TODO provide real value here
146 uint* WaylandGLESRenderer::getScreenResolution(uint screenID)
149 screen_id = screenID;
150 // TODO provide value of real screen here
151 uint * resolution = new uint[2];
152 resolution[0] = m_width;
153 resolution[1] = m_height;
157 uint* WaylandGLESRenderer::getScreenIDs(uint* length)
159 // TODO necessary to implement
160 uint* screenIDS = new uint[1];
166 void WaylandGLESRenderer::signalWindowSystemRedraw()
168 m_pWindowSystem->signalRedrawEvent();
171 void WaylandGLESRenderer::forceCompositionWindowSystem()
173 m_pWindowSystem->m_forceComposition = true;
176 Shader* WaylandGLESRenderer::createShader(const string* vertexName, const string* fragmentName)
178 Shader *result = NULL;
179 m_pWindowSystem->setSystemState(WAKEUP_STATE);
180 m_pWindowSystem->wakeUpRendererThread();
181 m_pGraphicSystem->activateGraphicContext();
182 result = Shader::createShader(*vertexName,*fragmentName);
183 m_pGraphicSystem->releaseGraphicContext();
184 m_pWindowSystem->setSystemState(IDLE_STATE);
188 extern "C" BaseRenderer* createWaylandGLESRenderer(Scene* pScene){
189 return new WaylandGLESRenderer(pScene);
192 extern "C" void destroyWaylandGLESRenderer(WaylandGLESRenderer* p)