WindowSystem: Forced composition should also redraw HW layers
[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 "config.h"
23 #include "Shader.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
36
37 WaylandGLESRenderer::WaylandGLESRenderer(Scene* pScene)
38 : BaseRenderer(pScene)
39 , m_pWindowSystem(0)
40 , m_pGraphicSystem(0)
41 , m_width(0)
42 , m_height(0)
43 , m_binder(0)
44 {
45     LOG_DEBUG("WaylandGLESRenderer", "Creating Renderer");
46 }
47
48 bool WaylandGLESRenderer::start(int width, int height, const char* displayname)
49 {
50     struct wl_display* nativeDisplayHandle = NULL;
51     EGLDisplay eglDisplayhandle = NULL;
52     m_binder = NULL;
53     m_width = width;
54     m_height = height;
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);
59 #endif
60 #ifdef WITH_WAYLAND_X11
61     m_pWindowSystem = new WaylandX11WindowSystem(displayname, width, height, m_pScene);
62 #endif
63 #ifdef WITH_WAYLAND_DRM
64     m_pWindowSystem = new WaylandDrmWindowSystem(displayname, width, height, m_pScene);
65 #endif
66     if( m_pWindowSystem == NULL )
67     {
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
70     }
71
72 #ifdef WITH_WAYLAND_DRM
73     m_pGraphicSystem = new DrmGLESGraphicSystem(width,height, ShaderProgramGLES::createProgram);
74 #else
75     m_pGraphicSystem = new GLESGraphicsystem(width,height, ShaderProgramGLES::createProgram);
76 #endif
77
78     if (!m_pWindowSystem->init((BaseGraphicSystem<void*, void*>*) m_pGraphicSystem))
79     {
80         goto fail; // TODO bad style
81     }
82
83     m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
84
85     // create graphic context from window, init egl etc
86     nativeDisplayHandle = m_pWindowSystem->getNativeDisplayHandle();
87
88     LOG_DEBUG("WaylandGLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
89
90     eglDisplayhandle = m_pGraphicSystem->getEGLDisplay();
91
92     m_binder = new WaylandGLESTexture(eglDisplayhandle, nativeDisplayHandle);
93     if (m_binder && nativeDisplayHandle && eglDisplayhandle)
94     {
95         m_pGraphicSystem->setTextureBinder(m_binder);
96
97         if (!m_pWindowSystem->start())
98         {
99             goto fail; // TODO bad style
100         }
101     }
102     else
103     {
104         goto fail; // TODO bad style
105     }
106     return true;
107
108     fail: // TODO bad style
109
110     LOG_ERROR("WaylandGLESRenderer", "Initialization failed !");
111     return false;
112 }
113
114 void WaylandGLESRenderer::stop()
115 {
116     m_pWindowSystem->stop();
117     if(m_binder)
118     {
119         delete m_binder;
120     }
121 }
122
123 void WaylandGLESRenderer::doScreenShot(std::string fileToSave)
124 {
125     m_pWindowSystem->doScreenShot(fileToSave);
126 }
127
128 void WaylandGLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
129 {
130     m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
131 }
132
133 void WaylandGLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
134 {
135     m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
136 }
137
138 uint WaylandGLESRenderer::getNumberOfHardwareLayers(uint screenID)
139 {
140     uint screen_id;
141     screen_id = screenID;
142
143     return 0; // TODO provide real value here
144 }
145
146 uint* WaylandGLESRenderer::getScreenResolution(uint screenID)
147 {
148     uint screen_id;
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;
154     return resolution;
155 }
156
157 uint* WaylandGLESRenderer::getScreenIDs(uint* length)
158 {
159     // TODO necessary to implement
160     uint* screenIDS = new uint[1];
161     screenIDS[0] = 0;
162     *length = 1;
163     return screenIDS;
164 }
165
166 void WaylandGLESRenderer::signalWindowSystemRedraw()
167 {
168     m_pWindowSystem->signalRedrawEvent();
169 }
170
171 void WaylandGLESRenderer::forceCompositionWindowSystem()
172 {
173     m_pWindowSystem->m_forceComposition = true;
174 }
175
176 Shader* WaylandGLESRenderer::createShader(const string* vertexName, const string* fragmentName)  
177 {
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);
185     return result;
186 }
187
188 extern "C" BaseRenderer* createWaylandGLESRenderer(Scene* pScene){
189     return new WaylandGLESRenderer(pScene);
190 }
191
192 extern "C" void destroyWaylandGLESRenderer(WaylandGLESRenderer* p)
193 {
194     delete p;
195 }