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"
22 #include "Configuration.h"
24 #include "ShaderProgramGLES.h"
25 #include "TextureBinders/WaylandGLESTexture.h"
27 WaylandGLESRenderer::WaylandGLESRenderer(ICommandExecutor& executor, Configuration& config)
28 : BaseRenderer(executor, config)
35 LOG_DEBUG("WaylandGLESRenderer", "Creating Renderer");
38 bool WaylandGLESRenderer::start(int width, int height, const char* displayname, int maxIterationDurationInMS)
40 struct wl_display* nativeDisplayHandle = NULL;
41 EGLDisplay eglDisplayhandle = NULL;
47 LmScreenList& screenList = m_pScene->getScreenList();
48 LmScreen* lmScreen = new LmScreen();
49 screenList.push_back(lmScreen);
51 // create Wayland windows, register as composite manager etc
52 m_pWindowSystem = getWindowSystem(displayname);
53 if (m_pWindowSystem == NULL)
55 LOG_ERROR("WaylandGLESRenderer", "Window system is not specified. Consider to specify WITH_WAYLAND_X11 or WITH_WAYLAND_FBDEV");
56 goto fail; // TODO bad style
59 m_pGraphicSystem = getGraphicSystem(ShaderProgramGLES::createProgram);
61 if (!m_pWindowSystem->init((BaseGraphicSystem<void*, void*>*) m_pGraphicSystem))
63 goto fail; // TODO bad style
66 m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
68 // create graphic context from window, init egl etc
69 nativeDisplayHandle = m_pWindowSystem->getNativeDisplayHandle();
71 LOG_DEBUG("WaylandGLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
73 eglDisplayhandle = m_pGraphicSystem->getEGLDisplay();
75 m_binder = new WaylandGLESTexture(eglDisplayhandle, nativeDisplayHandle);
76 if (m_binder && nativeDisplayHandle && eglDisplayhandle)
78 m_pGraphicSystem->setTextureBinder(m_binder);
80 if (!m_pWindowSystem->start(maxIterationDurationInMS))
82 goto fail; // TODO bad style
87 goto fail; // TODO bad style
91 fail: // TODO bad style
93 LOG_ERROR("WaylandGLESRenderer", "Initialization failed !");
97 void WaylandGLESRenderer::stop()
99 m_pWindowSystem->stop();
106 void WaylandGLESRenderer::doScreenShot(std::string fileToSave)
108 m_pWindowSystem->doScreenShot(fileToSave);
111 void WaylandGLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
113 m_pWindowSystem->doScreenShotOfLayer(fileToSave, id);
116 void WaylandGLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
118 m_pWindowSystem->doScreenShotOfSurface(fileToSave, id, layer_id);
121 uint WaylandGLESRenderer::getNumberOfHardwareLayers(uint screenID)
125 return 0; // TODO provide real value here
128 uint* WaylandGLESRenderer::getScreenResolution(uint screenID)
131 // TODO provide value of real screen here
132 uint * resolution = new uint[2];
133 resolution[0] = m_width;
134 resolution[1] = m_height;
138 uint* WaylandGLESRenderer::getScreenIDs(uint* length)
140 // TODO necessary to implement
141 uint* screenIDS = new uint[1];
147 void WaylandGLESRenderer::signalWindowSystemRedraw()
149 m_pWindowSystem->signalRedrawEvent();
152 void WaylandGLESRenderer::forceCompositionWindowSystem()
154 m_pWindowSystem->m_forceComposition = true;
157 bool WaylandGLESRenderer::setOptimizationMode(OptimizationType id, OptimizationModeType mode)
159 return m_pGraphicSystem->setOptimizationMode(id, mode);
162 bool WaylandGLESRenderer::getOptimizationMode(OptimizationType id, OptimizationModeType *mode)
164 return m_pGraphicSystem->getOptimizationMode(id, mode);
167 Shader* WaylandGLESRenderer::createShader(const string* vertexName, const string* fragmentName)
169 Shader *result = NULL;
170 m_pWindowSystem->setSystemState(WAKEUP_STATE);
171 m_pWindowSystem->wakeUpRendererThread();
172 m_pGraphicSystem->activateGraphicContext();
173 result = Shader::createShader(*vertexName, *fragmentName);
174 m_pGraphicSystem->releaseGraphicContext();
175 m_pWindowSystem->setSystemState(IDLE_STATE);
179 int WaylandGLESRenderer::getIterationCounter()
181 // TODO: add real thread iteration counter here
182 // The renderer plugin thread must wake up at least once in
183 // each health monitoring interval. This interval is passed
184 // to the plugin as argument in its start() method.
185 // Each time the plugin thread gets active, it must
186 // increment the internal iteration counter.
187 // This way the health monitor can detect, if the plugin
188 // thread is running, dead or blocked.
190 // TODO: remove this placeholder, which just returns an
191 // incremented interation counter to make health monitoring happy.
192 static int iteration = 0;