1 /***************************************************************************
3 * Copyright 2010 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 #include "X11GLESRenderer.h"
21 #include "Configuration.h"
23 #include "ShaderProgramGLES.h"
25 #include "TextureBinders/X11CopyGLES.h"
26 #include "TextureBinders/X11EglImage.h"
30 X11GLESRenderer::X11GLESRenderer(ICommandExecutor& executor, Configuration& config)
31 : BaseRenderer(executor, config)
38 LOG_DEBUG("X11GLESRenderer", "Creating Renderer");
41 bool X11GLESRenderer::start(int width, int height, const char* displayname, int maxIterationDurationInMS)
43 Display* nativeDisplayHandle = NULL;
44 EGLDisplay eglDisplayhandle = NULL;
50 LmScreenList& screenList = m_pScene->getScreenList();
51 LmScreen* lmScreen = new LmScreen();
52 screenList.push_back(lmScreen);
54 // create X11 windows, register as composite manager etc
55 m_pWindowSystem = new X11WindowSystem(displayname, width, height, m_pScene, m_pInputManager);
56 m_pGraphicSystem = new GLESGraphicsystem(width, height, ShaderProgramGLES::createProgram);
58 if (!m_pWindowSystem->init(m_pGraphicSystem))
60 goto fail; // TODO bad style
63 m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
65 // create graphic context from window, init egl etc
66 nativeDisplayHandle = m_pWindowSystem->getNativeDisplayHandle();
68 LOG_DEBUG("X11GLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
70 eglDisplayhandle = m_pGraphicSystem->getEGLDisplay();
72 #ifdef WITH_FORCE_COPY
73 m_binder = new X11CopyGLES(eglDisplayhandle, nativeDisplayHandle);
74 #else // WITH_FORCE_COPY
75 #ifdef EGL_NATIVE_PIXMAP_KHR
76 m_binder = new X11EglImage(eglDisplayhandle, nativeDisplayHandle);
77 #else // EGL_NATIVE_PIXMAP_KHR
78 m_binder = new X11CopyGLES(eglDisplayhandle, nativeDisplayHandle);
79 #endif // EGL_NATIVE_PIXMAP_KHR
80 #endif // WITH_FORCE_COPY
81 if (m_binder && nativeDisplayHandle && eglDisplayhandle)
83 m_pGraphicSystem->setTextureBinder(m_binder);
85 if (!m_pWindowSystem->start(maxIterationDurationInMS))
87 goto fail; // TODO bad style
92 goto fail; // TODO bad style
96 fail: // TODO bad style
98 LOG_ERROR("X11GLESRenderer", "Initialization failed !");
102 void X11GLESRenderer::stop()
104 m_pWindowSystem->stop();
105 delete m_pGraphicSystem;
106 delete m_pWindowSystem;
113 void X11GLESRenderer::doScreenShot(std::string fileToSave, uint screen_id)
115 m_pWindowSystem->doScreenShot(fileToSave, screen_id);
118 void X11GLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
120 m_pWindowSystem->doScreenShotOfLayer(fileToSave, id);
123 void X11GLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
125 m_pWindowSystem->doScreenShotOfSurface(fileToSave, id, layer_id);
128 uint X11GLESRenderer::getNumberOfHardwareLayers(uint screenID)
132 return 0; // TODO provide real value here
135 uint* X11GLESRenderer::getScreenResolution(uint screenID)
139 // TODO provide value of real screen here
140 uint * resolution = new uint[2];
141 resolution[0] = m_width;
142 resolution[1] = m_height;
146 uint* X11GLESRenderer::getScreenIDs(uint* length)
148 Display* x11Display = m_pWindowSystem->getNativeDisplayHandle();
153 // Screens in X11 can be addresses/accessed by just the number - we must only know how many there are
154 uint numberOfScreens = ScreenCount(x11Display);
155 uint* screenIDS = new uint[numberOfScreens];
156 for (uint i = 0; i < numberOfScreens; ++i)
160 *length = numberOfScreens;
164 void X11GLESRenderer::signalWindowSystemRedraw()
166 m_pWindowSystem->signalRedrawEvent();
169 void X11GLESRenderer::forceCompositionWindowSystem()
171 m_pWindowSystem->m_forceComposition = true;
174 bool X11GLESRenderer::setOptimizationMode(OptimizationType id, OptimizationModeType mode)
176 return m_pGraphicSystem->setOptimizationMode(id, mode);
179 bool X11GLESRenderer::getOptimizationMode(OptimizationType id, OptimizationModeType *mode)
181 return m_pGraphicSystem->getOptimizationMode(id, mode);
184 t_ilm_const_string X11GLESRenderer::pluginGetName() const
186 return "X11GLESRenderer";
189 Shader* X11GLESRenderer::createShader(const string* vertexName, const string* fragmentName)
191 Shader *result = NULL;
192 m_pWindowSystem->setSystemState(WAKEUP_STATE);
193 m_pWindowSystem->wakeUpRendererThread();
194 m_pScene->unlockScene();
195 while (m_pWindowSystem->getSystemState() != IDLE_STATE);
196 m_pGraphicSystem->activateGraphicContext();
197 result = Shader::createShader(*vertexName, *fragmentName);
198 m_pGraphicSystem->releaseGraphicContext();
199 m_pWindowSystem->setSystemState(WAKEUP_STATE);
200 m_pScene->lockScene();
204 int X11GLESRenderer::getIterationCounter()
206 return m_pWindowSystem->getIterationCounter();
209 DECLARE_LAYERMANAGEMENT_PLUGIN(X11GLESRenderer)