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 #include "Layermanager.h"
23 #include "LayerList.h"
25 #include "ICommunicator.h"
26 #include "IRenderer.h"
27 #include "ISceneProvider.h"
29 Layermanager::Layermanager()
31 m_pScene = new Scene();
32 m_pRendererList = new RendererList();
33 m_pCommunicatorList = new CommunicatorList();
34 m_pSceneProviderList = new SceneProviderList();
37 Layermanager::~Layermanager()
46 delete m_pRendererList;
49 if (m_pCommunicatorList)
51 delete m_pCommunicatorList;
55 uint Layermanager::getLayerTypeCapabilities(const LayerType layertype) const
57 uint capabilities = 0;
59 // get the first renderer for now TODO
60 // change to possibly load multiple renderers
62 IRenderer* renderer = *m_pRendererList->begin();
65 capabilities = renderer->getLayerTypeCapabilities(layertype);
71 uint Layermanager::getNumberOfHardwareLayers(const uint screenID) const
73 uint numberOfHardwareLayers = 0;
75 // get the first renderer for now TODO
76 // change to possibly load multiple renderers
77 IRenderer* renderer = *m_pRendererList->begin();
81 numberOfHardwareLayers = renderer->getNumberOfHardwareLayers(screenID);
84 return numberOfHardwareLayers;
87 uint* Layermanager::getScreenResolution(const uint screenID) const
89 uint* returnValue = 0;
91 // get the first renderer for now TODO
92 // change to possibly load multiple renderers
93 IRenderer* renderer = *m_pRendererList->begin();
97 returnValue = renderer->getScreenResolution(screenID);
103 uint* Layermanager::getScreenIDs(uint* length) const
105 uint* returnValue = 0;
107 // get the first renderer for now TODO
108 // change to possibly load multiple renderers
109 IRenderer* renderer = *m_pRendererList->begin();
112 returnValue = renderer->getScreenIDs(length);
118 // This function is used to propagate a signal to the window system
119 // via the renderer for a redraw because of a rendering property change
120 void Layermanager::signalRendererRedraw()
122 IRenderer* renderer = *m_pRendererList->begin();
124 renderer->signalWindowSystemRedraw();
126 void Layermanager::addRenderer(IRenderer* renderer)
130 m_pRendererList->push_back(renderer);
135 void Layermanager::removeRenderer(IRenderer* renderer)
139 m_pRendererList->remove(renderer);
143 void Layermanager::addSceneProvider(ISceneProvider* sceneProvider)
147 m_pSceneProviderList->push_back(sceneProvider);
152 void Layermanager::removeSceneProvider(ISceneProvider* sceneProvider)
156 m_pSceneProviderList->remove(sceneProvider);
160 void Layermanager::addCommunicator(ICommunicator* communicator)
164 m_pCommunicatorList->push_back(communicator);
168 void Layermanager::removeCommunicator(ICommunicator* communicator)
172 m_pCommunicatorList->remove(communicator);
176 void Layermanager::printDebugInformation() const
178 // print stuff about layerlist
179 LOG_INFO("LayerManager", "Layer: ID | X | Y | W | H |Al.| Z \n");
182 unsigned int* LayerIDs;
185 m_pScene->getLayerIDs(&length, &LayerIDs);
187 for (unsigned int i = 0; i < length; i++)
189 Layer* currentLayer = m_pScene->getLayer(LayerIDs[i]);
190 LOG_INFO("LayerManager", " " << std::setw(4) << currentLayer->getID() << "\n");
192 LOG_INFO("LayerManager", " Surface: ID |Al.| Z | SVP: X | Y | W | H DVP: X | Y | W | H \n");
194 // loop the surfaces of within each layer
195 SurfaceListConstIterator iter = currentLayer->getAllSurfaces().begin();
196 SurfaceListConstIterator iterEnd = currentLayer->getAllSurfaces().end();
198 for (; iter != iterEnd; ++iter)
200 LOG_INFO("LayerManager", " " << std::setw(4) << (*iter)->getID() << std::setw(4) << std::setprecision(3) << (*iter)->opacity << "\n");
205 bool Layermanager::executeCommand(ICommand* commandToBeExecuted)
207 ExecutionResult status = ExecutionFailed;
208 LOG_INFO("Layermanager", "executing command: " << commandToBeExecuted->getString());
209 m_pScene->lockScene();
210 status = commandToBeExecuted->execute(this);
211 m_pScene->unlockScene();
213 if (status == ExecutionFailedRedraw || status == ExecutionSuccessRedraw)
215 // either a command that has changed the output was executed, or
216 // commit command was executed which contained commands that requested redraw was executed.
217 signalRendererRedraw();
220 return (status == ExecutionSuccess || status == ExecutionSuccessRedraw);
223 bool Layermanager::enqueueCommand(ICommand* commandToBeExecuted)
225 LOG_INFO("Layermanager", "add command to queue: " << commandToBeExecuted->getString());
226 m_pScene->lockScene();
227 m_pScene->m_toBeCommittedList.push_back(commandToBeExecuted);
228 m_pScene->unlockScene();
232 bool Layermanager::execute(ICommand* commandToBeExecuted)
236 ExecutionType type = commandToBeExecuted->getExecutionType();
240 case ExecuteSynchronous:
241 status = executeCommand(commandToBeExecuted);
242 delete commandToBeExecuted;
245 case ExecuteAsynchronous:
246 status = enqueueCommand(commandToBeExecuted);
251 LOG_ERROR("Layermanager", "Command " << commandToBeExecuted->getString() << " was not processed");
258 bool Layermanager::startAllRenderers(const int width, const int height,
259 const char *displayName)
261 bool allStarted = false;
263 RendererListIterator iter = m_pRendererList->begin();
264 RendererListIterator iterEnd = m_pRendererList->end();
265 for (; iter != iterEnd; ++iter)
267 IRenderer* renderer = *iter;
270 allStarted = renderer->start(width, height, displayName);
272 if (renderer == NULL || allStarted == false)
279 LOG_ERROR("LayerManager","Could not start Compositing Controllers");
284 bool Layermanager::delegateScene()
286 bool allStarted = true;
288 SceneProviderListIterator iter = m_pSceneProviderList->begin();
289 SceneProviderListIterator iterEnd = m_pSceneProviderList->end();
291 for (; iter != iterEnd; ++iter)
293 ISceneProvider* sceneProvider = *iter;
296 allStarted &= sceneProvider->delegateScene();
305 LOG_WARNING("LayerManager","Could not start delegate Scenes, inital Scene is lost");
310 bool Layermanager::startAllCommunicators()
312 bool allStarted = true;
314 CommunicatorListIterator communicatorIter = m_pCommunicatorList->begin();
315 CommunicatorListIterator communicatorIterEnd = m_pCommunicatorList->end();
317 for (; communicatorIter != communicatorIterEnd; ++communicatorIter)
319 ICommunicator *communicator = *communicatorIter;
322 allStarted &= communicator->start();
331 LOG_ERROR("LayerManager","Could not start Communication Controllers");
336 bool Layermanager::startManagement(const int width, const int height,
337 const char* displayName)
339 bool renderersStarted = startAllRenderers(width, height, displayName);
340 bool communicatorsStarted = startAllCommunicators();
341 /* only call the initial layerscenery if all needed plugins are
342 * successfully started */
344 if (renderersStarted && communicatorsStarted)
348 return renderersStarted && communicatorsStarted;
351 void Layermanager::stopAllRenderers()
353 RendererListIterator iter = m_pRendererList->begin();
354 RendererListIterator iterEnd = m_pRendererList->end();
355 for (; iter != iterEnd; ++iter)
357 IRenderer *renderer = *iter;
365 void Layermanager::stopAllCommunicators()
367 CommunicatorListIterator iter = m_pCommunicatorList->begin();
368 CommunicatorListIterator iterEnd = m_pCommunicatorList->end();
369 for (; iter != iterEnd; ++iter)
371 ICommunicator *communicator = *iter;
374 communicator->stop();
379 bool Layermanager::stopManagement()
382 stopAllCommunicators();