Wayland: fixed build of Wayland Renderers caused by Health Monitoring API change
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Platform / WaylandGLESRenderer / src / WaylandGLESRenderer.cpp
1 /***************************************************************************
2 *
3 * Copyright 2010, 2011 BMW Car IT GmbH
4 * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5 *
6 *
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
10 *
11 *        http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 ****************************************************************************/
20
21 #include "WaylandGLESRenderer.h"
22 #include "Configuration.h"
23 #include "Shader.h"
24 #include "ShaderProgramGLES.h"
25 #include "TextureBinders/WaylandGLESTexture.h"
26
27 WaylandGLESRenderer::WaylandGLESRenderer(ICommandExecutor& executor, Configuration& config)
28 : BaseRenderer(executor, config)
29 , m_pWindowSystem(0)
30 , m_pGraphicSystem(0)
31 , m_width(0)
32 , m_height(0)
33 , m_binder(0)
34 {
35     LOG_DEBUG("WaylandGLESRenderer", "Creating Renderer");
36 }
37
38 bool WaylandGLESRenderer::start(int width, int height, const char* displayname, int maxIterationDurationInMS)
39 {
40     struct wl_display* nativeDisplayHandle = NULL;
41     EGLDisplay eglDisplayhandle = NULL;
42     m_binder = NULL;
43     m_width = width;
44     m_height = height;
45
46     // add default screen
47     LmScreenList& screenList = m_pScene->getScreenList();
48     LmScreen* lmScreen = new LmScreen();
49     screenList.push_back(lmScreen);
50
51     // create Wayland windows, register as composite manager etc
52     m_pWindowSystem = getWindowSystem(displayname);
53     if (m_pWindowSystem == NULL)
54     {
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
57     }
58
59     m_pGraphicSystem = getGraphicSystem(ShaderProgramGLES::createProgram);
60
61     if (!m_pWindowSystem->init((BaseGraphicSystem<void*, void*>*) m_pGraphicSystem))
62     {
63         goto fail; // TODO bad style
64     }
65
66     m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
67
68     // create graphic context from window, init egl etc
69     nativeDisplayHandle = m_pWindowSystem->getNativeDisplayHandle();
70
71     LOG_DEBUG("WaylandGLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
72
73     eglDisplayhandle = m_pGraphicSystem->getEGLDisplay();
74
75     m_binder = new WaylandGLESTexture(eglDisplayhandle, nativeDisplayHandle);
76     if (m_binder && nativeDisplayHandle && eglDisplayhandle)
77     {
78         m_pGraphicSystem->setTextureBinder(m_binder);
79
80         if (!m_pWindowSystem->start(maxIterationDurationInMS))
81         {
82             goto fail; // TODO bad style
83         }
84     }
85     else
86     {
87         goto fail; // TODO bad style
88     }
89     return true;
90
91 fail: // TODO bad style
92
93     LOG_ERROR("WaylandGLESRenderer", "Initialization failed !");
94     return false;
95 }
96
97 void WaylandGLESRenderer::stop()
98 {
99     m_pWindowSystem->stop();
100     if (m_binder)
101     {
102         delete m_binder;
103     }
104 }
105
106 void WaylandGLESRenderer::doScreenShot(std::string fileToSave)
107 {
108     m_pWindowSystem->doScreenShot(fileToSave);
109 }
110
111 void WaylandGLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
112 {
113     m_pWindowSystem->doScreenShotOfLayer(fileToSave, id);
114 }
115
116 void WaylandGLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
117 {
118     m_pWindowSystem->doScreenShotOfSurface(fileToSave, id, layer_id);
119 }
120
121 uint WaylandGLESRenderer::getNumberOfHardwareLayers(uint screenID)
122 {
123     (void)screenID;
124
125     return 0; // TODO provide real value here
126 }
127
128 uint* WaylandGLESRenderer::getScreenResolution(uint screenID)
129 {
130     (void)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;
135     return resolution;
136 }
137
138 uint* WaylandGLESRenderer::getScreenIDs(uint* length)
139 {
140     // TODO necessary to implement
141     uint* screenIDS = new uint[1];
142     screenIDS[0] = 0;
143     *length = 1;
144     return screenIDS;
145 }
146
147 void WaylandGLESRenderer::signalWindowSystemRedraw()
148 {
149     m_pWindowSystem->signalRedrawEvent();
150 }
151
152 void WaylandGLESRenderer::forceCompositionWindowSystem()
153 {
154     m_pWindowSystem->m_forceComposition = true;
155 }
156
157 bool WaylandGLESRenderer::setOptimizationMode(OptimizationType id, OptimizationModeType mode)
158 {
159     return m_pGraphicSystem->setOptimizationMode(id, mode);
160 }
161
162 bool WaylandGLESRenderer::getOptimizationMode(OptimizationType id, OptimizationModeType *mode)
163 {
164     return m_pGraphicSystem->getOptimizationMode(id, mode);
165 }
166
167 Shader* WaylandGLESRenderer::createShader(const string* vertexName, const string* fragmentName)
168 {
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);
176     return result;
177 }
178
179 int WaylandGLESRenderer::getIterationCounter()
180 {
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.
189
190     // TODO: remove this placeholder, which just returns an
191     // incremented interation counter to make health monitoring happy.
192     static int iteration = 0;
193     return ++iteration;
194 }