Several Bugfixes to improve the stability
authorMichael Schuldt <Michael.Schuldt@bmw-carit.de>
Wed, 24 Nov 2010 10:47:26 +0000 (11:47 +0100)
committerMichael Schuldt <Michael.Schuldt@bmw-carit.de>
Wed, 24 Nov 2010 10:47:26 +0000 (11:47 +0100)
15 files changed:
LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLESGraphicSystem.h
LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/XPlatformSurface.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/BeagleEglImage.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/ITextureBinder.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11EglImage.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/makefile
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslf [new file with mode: 0644]
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslv [new file with mode: 0644]
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_vert.glslv
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp

index 67d290d..87d32d6 100644 (file)
@@ -25,7 +25,8 @@
 #include "EGL/egl.h"
 #include "Log.h"
 #include "Shader.h"
-
+/* uncomment if layer drawing needed */
+/* #define DRAW_LAYER_DEBUG */
 class GLESGraphicsystem : public BaseGraphicSystem {
 public:
        GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder);
@@ -36,6 +37,7 @@ public:
        void drawSurface(Layer* currentLayer, Surface* surface);
        bool initOpenGLES(EGLint displayWidth, EGLint displayHeight);
        void resize(EGLint displayWidth, EGLint displayHeight);
+       void doScreenShot(std::string fileToSave);
 
        PfnShaderProgramCreator                         m_shaderCreatorFunc;
        EGLConfig                                                       m_eglConfig;
@@ -46,7 +48,14 @@ public:
        EGLint                                                          m_displayWidth;
        EGLint                                                          m_displayHeight;
        EGLBoolean                                                      m_blendingStatus;
-       Shader*                                                         defaultShader;
+       Shader*                                                         m_defaultShader;
+#ifdef DRAW_LAYER_DEBUG
+       Shader*                                                         m_layerShader;
+#endif
+private:
+       void saveScreenShot();
+       std::string screenShotFile;
+       bool takescreenshot;
 };
 
 #endif /* _GLESGRAPHICSYSTEM_H_ */
index a6f0d27..a2b7a0c 100644 (file)
 
 class XPlatformSurface : public PlatformSurface {
 public:
-       XPlatformSurface (Surface* surface) : PlatformSurface(surface), isMapped(false), pixmap(0){};
+       XPlatformSurface (Surface* surface) : PlatformSurface(surface), isMapped(false), pixmap(0), texture(0){};
        ~XPlatformSurface(){};
 
-       Pixmap pixmap;
        bool isMapped;
+       Pixmap pixmap;
        uint texture;
 };
 
index 6131d6e..ce8222e 100644 (file)
@@ -71,7 +71,7 @@ public:
        }
 
        void createClientBuffer(Surface* surface){
-               LOG_INFO("BeagleEglImage", "createClientBuffer");
+               LOG_DEBUG("BeagleEglImage", "createClientBuffer");
                BeaglePlatformSurface* nativeSurface = (BeaglePlatformSurface*)surface->platform;
                NATIVE_PIXMAP_STRUCT* pNativePixmap = (NATIVE_PIXMAP_STRUCT*)malloc(sizeof(NATIVE_PIXMAP_STRUCT));
                pNativePixmap->ePixelFormat = 2;
@@ -108,6 +108,14 @@ public:
        }
 
        void destroyClientBuffer(Surface* surface){
+               LOG_DEBUG("BeagleEglImage", "destroyClientBuffer");
+               BeaglePlatformSurface* nativeSurface = (BeaglePlatformSurface*)surface->platform;
+               if (NULL!=nativeSurface && 0!=nativeSurface->eglImage){
+                       EGLBoolean status = m_pfEglDestroyImageKHR(m_eglDisplay,nativeSurface->eglImage);
+                       if (!status)
+                               LOG_ERROR("BeagleEglImage", "could not delete EGLImage");
+                       nativeSurface->eglImage = 0;
+               }
        }
 private:
        PFNEGLCREATEIMAGEKHRPROC                m_pfEglCreateImageKHR;
index d74de5b..f46222e 100644 (file)
@@ -24,6 +24,7 @@
 
 class ITextureBinder {
 public:
+       virtual ~ITextureBinder(){};
        virtual void bindSurfaceTexture(Surface*s)=0;
        virtual void unbindSurfaceTexture(Surface*s)=0;
        virtual void createClientBuffer(Surface*s)=0;
index f44344e..8389fba 100644 (file)
@@ -26,6 +26,7 @@
 class BaseWindowSystem {
 public:
        BaseWindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem) : graphicSystem(graphicSystem), layerlist(layerlist){};
+       virtual ~BaseWindowSystem(){};
        virtual bool start(int, int, const char*)=0;
        virtual void stop()=0;
 
index a3e52e0..c721e0e 100644 (file)
@@ -32,11 +32,12 @@ typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy);
 class X11WindowSystem : public BaseWindowSystem {
 public:
        X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem,GetVisualInfoFunction func=X11WindowSystem::getDefaultVisual );
+       virtual ~X11WindowSystem();
        bool start(int, int, const char*);
-       void stop(){};
-
+       void stop();
        static XVisualInfo *
        getDefaultVisual(Display *dpy);
+
 private:
        static void* EventLoop(void * ptr);
        static int error (Display *dpy, XErrorEvent *ev);
@@ -45,6 +46,7 @@ private:
 protected:
        Display* x11Display;
        bool initXServer();
+       pthread_t renderThread;
        //void setDisplayMode();
        int windowWidth;
        int windowHeight;
@@ -55,6 +57,7 @@ protected:
        static bool m_initialized;
 
 private:
+       void cleanup();
        void Redraw();
        void OpenDisplayConnection();
        void checkForCompositeExtension();
@@ -79,6 +82,7 @@ private:
        int composite_event, composite_error;
        int composite_major, composite_minor;
        static const char CompositorWindowTitle[];
+       bool m_running;
 };
 
 #endif /* _X11WINDOWSYSTEM_H_ */
index 594c84d..6419b40 100644 (file)
 /***************************************************************************
-*
-* Copyright 2010 BMW Car IT GmbH
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-             http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-****************************************************************************/
+ *
+ * Copyright 2010 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
 
 #include "GraphicSystems/GLESGraphicSystem.h"
-
+#include "IlmMatrix.h"
 #include "string.h"
 #include "EGL/egl.h"
 #include "GLES2/gl2.h"
+#include "Bitmap.h"
 
 static const float vertices[8*12] = {
-        0.0, 0.0,
-        1.0, 0.0,
-        1.0, 1.0,
-        1.0, 1.0,
-        0.0, 1.0,
-        0.0, 0.0,
-
-        0.0, 0.0,
-        1.0, 0.0,
-        1.0, 1.0,
-        1.0, 1.0,
-        0.0, 1.0,
-        0.0, 0.0,
-
-        0.0, 0.0,
-        1.0, 0.0,
-        1.0, 1.0,
-        1.0, 1.0,
-        0.0, 1.0,
-        0.0, 0.0,
-
-        1.0, 0.0,
-        1.0, 1.0,
-        0.0, 1.0,
-        0.0, 1.0,
-        0.0, 0.0,
-        1.0, 0.0,
-
-        0.0, 0.0,
-               1.0, 0.0,
-               1.0, 1.0,
-               1.0, 1.0,
-               0.0, 1.0,
-               0.0, 0.0,
-
-               1.0, 1.0,
-               0.0, 1.0,
-               0.0, 0.0,
-               0.0, 0.0,
-               1.0, 0.0,
-               1.0, 1.0,
-
-               0.0, 0.0,
-               1.0, 0.0,
-               1.0, 1.0,
-               1.0, 1.0,
-               0.0, 1.0,
-               0.0, 0.0,
-
-               0.0, 1.0,
-               0.0, 0.0,
-               1.0, 0.0,
-               1.0, 0.0,
-               1.0, 1.0,
-               0.0, 1.0
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+
+    1.0, 0.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+    1.0, 0.0,
+
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    1.0, 1.0,
+    0.0, 1.0,
+    0.0, 0.0,
+
+    0.0, 1.0,
+    0.0, 0.0,
+    1.0, 0.0,
+    1.0, 0.0,
+    1.0, 1.0,
+    0.0, 1.0
 
 };
 
-GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram){
-       LOG_DEBUG("GLESGraphicsystem", "creating GLESGraphicsystem");
-       m_binder = binder;
+GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram), takescreenshot(false){
+  LOG_DEBUG("GLESGraphicsystem", "creating GLESGraphicsystem");
+  m_binder = binder;
 };
 
 bool GLESGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeight, int WindowWidth){
-       EGLNativeDisplayType display = *(EGLNativeDisplayType*)displayPtr;
-       LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeDisplay:" << display);
-       EGLNativeWindowType WIndowID = *(EGLNativeWindowType*)WIndowIDPtr;
-       LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeWindow:" << WIndowID);
-
-       EGLint iMajorVersion, iMinorVersion;
-       LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display");
-       m_eglDisplay = eglGetDisplay(display);
-
-       LOG_DEBUG("GLESGraphicsystem", "Initialising EGL");
-       if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion))
-               return false;
-
-       LOG_DEBUG("GLESGraphicsystem", "Binding GLES API");
-       eglBindAPI(EGL_OPENGL_ES_API);
-
-       EGLint pi32ConfigAttribs[]={
-                       EGL_SURFACE_TYPE,EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
-                       EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
-                       EGL_ALPHA_SIZE,8,
-                       EGL_NONE
-       };
-
-       LOG_DEBUG("GLESGraphicsystem", "EGLChooseConfig");
-       int iConfigs;
-       if (!eglChooseConfig(m_eglDisplay, pi32ConfigAttribs, &m_eglConfig, 1, &iConfigs) || (iConfigs != 1))
-       {
-               LOG_DEBUG("GLESGraphicsystem", "Error: eglChooseConfig() failed.");
-               return false;
-       }
-       EGLint id =0;
-       eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id);
-
-       LOG_DEBUG("GLESGraphicsystem", "Config chosen:" << id);
-       LOG_DEBUG("GLESGraphicsystem", "Create Window surface");
-
-       m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, WIndowID, NULL);
-       if (!m_eglSurface){
-               LOG_DEBUG("GLESGraphicsystem", "create unsucessfull");
-       }else{
-               LOG_DEBUG("GLESGraphicsystem", "create successfull");
-       }
-       EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-       m_eglContext = eglCreateContext(m_eglDisplay,
-                                        m_eglConfig,
-                                        NULL,
-                                        contextAttrs);
-    if (!m_eglContext)
+  EGLNativeDisplayType display = *(EGLNativeDisplayType*)displayPtr;
+  LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeDisplay:" << display);
+  EGLNativeWindowType WIndowID = *(EGLNativeWindowType*)WIndowIDPtr;
+  LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeWindow:" << WIndowID);
+
+  EGLint iMajorVersion, iMinorVersion;
+  LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display");
+  m_eglDisplay = eglGetDisplay(display);
+
+  LOG_DEBUG("GLESGraphicsystem", "Initialising EGL");
+  if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion))
+    return false;
+
+  LOG_DEBUG("GLESGraphicsystem", "Binding GLES API");
+  eglBindAPI(EGL_OPENGL_ES_API);
+
+  EGLint pi32ConfigAttribs[]={
+      EGL_SURFACE_TYPE,EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
+      EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
+      EGL_ALPHA_SIZE,8,
+      EGL_NONE
+  };
+
+  LOG_DEBUG("GLESGraphicsystem", "EGLChooseConfig");
+  int iConfigs;
+  if (!eglChooseConfig(m_eglDisplay, pi32ConfigAttribs, &m_eglConfig, 1, &iConfigs) || (iConfigs != 1))
+    {
+      LOG_DEBUG("GLESGraphicsystem", "Error: eglChooseConfig() failed.");
+      return false;
+    }
+  EGLint id =0;
+  eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id);
+
+  LOG_DEBUG("GLESGraphicsystem", "Config chosen:" << id);
+  LOG_DEBUG("GLESGraphicsystem", "Create Window surface");
+
+  m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, WIndowID, NULL);
+  if (!m_eglSurface){
+    LOG_DEBUG("GLESGraphicsystem", "create unsucessfull");
+  }else{
+    LOG_DEBUG("GLESGraphicsystem", "create successfull");
+  }
+  EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+  m_eglContext = eglCreateContext(m_eglDisplay,
+      m_eglConfig,
+      NULL,
+      contextAttrs);
+  if (!m_eglContext)
     {
-        LOG_ERROR("GLESGraphicsystem","EGL couldn't create context\n");
-        return false;
+      LOG_ERROR("GLESGraphicsystem","EGL couldn't create context\n");
+      return false;
     }
-    LOG_INFO("GLESGraphicsystem", "EGL make current ...");
-    // Make the context and surface current for rendering
-    EGLBoolean eglStatus = false;
-    eglStatus = eglMakeCurrent(m_eglDisplay,
-                               m_eglSurface, m_eglSurface,
-                               m_eglContext);
-    LOG_INFO("GLESGraphicsystem", "made current");
+  LOG_INFO("GLESGraphicsystem", "EGL make current ...");
+  // Make the context and surface current for rendering
+  EGLBoolean eglStatus = false;
+  eglStatus = eglMakeCurrent(m_eglDisplay,
+      m_eglSurface, m_eglSurface,
+      m_eglContext);
+  LOG_INFO("GLESGraphicsystem", "made current");
 
 
-       if (!initOpenGLES(WindowWidth,WindowHeight) )
-       {
-                               return false;
-       }
-       return true;
+  if (!initOpenGLES(WindowWidth,WindowHeight) )
+    {
+      return false;
+    }
+  return true;
 }
 
 void GLESGraphicsystem::clearBackground()
 {
-       glClear(GL_COLOR_BUFFER_BIT);
+  glClear(GL_COLOR_BUFFER_BIT);
 }
 void GLESGraphicsystem::swapBuffers()
 {
-       eglSwapBuffers(m_eglDisplay,m_eglSurface);
+  eglSwapBuffers(m_eglDisplay,m_eglSurface);
+  // check if we are ordered to take screenshot at next possible moment
+       // taking right after swap ensures that we obtain full image
+       if (takescreenshot){
+               takescreenshot = false;
+               saveScreenShot();
+       }
 }
 
 void GLESGraphicsystem::drawSurface(Layer* currentLayer,Surface* surface)
 {
-       ShaderProgram::CommonUniforms uniforms;
-       Shader* layerShader = currentLayer->getShader();
-       if (!layerShader)
-       {
-               // use default shader if no custom shader is assigned to this layer
-               layerShader = defaultShader;
-       }
-       Shader* shader = (surface)->getShader();
-       if (!shader)
-       {
-               // use layer shader if no custom shader is assigned to this surface
-               shader = layerShader;
-       }
-       Rectangle dest = (surface)->getDestinationRegion();
-       Rectangle src = (surface)->getSourceRegion();
-       float surfaceXOfScreen =        (float) dest.x / m_displayWidth;
-       float surfaceYOfScreen =        (float) dest.y / m_displayHeight;
-       float surfaceWidthOfScreen = (float) dest.width / m_displayWidth;
-       float surfaceHeightOfScreen =  (float) dest.height / m_displayHeight;
-
-       float sourceViewportWidthPercent = (float)src.width/(surface)->OriginalSourceWidth;
-       float sourceViewportHeightpercent = (float)src.height/(surface)->OriginalSourceHeight;
-       float sourceViewportXPercent = (float)src.x/(surface)->OriginalSourceWidth;
-       float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight;
-
-       //      LOG_INFO("GLESGraphicsystem", "Binding Buffer");
-       glBindBuffer(GL_ARRAY_BUFFER,m_vbo);
-
-       //      LOG_INFO("GLESGraphicsystem", "Binding Buffer done");
-       shader->use();
-
-       //      LOG_INFO("GLESGraphicsystem", "Update Uniforms");
-       // update all common uniforms
-       uniforms.x = surfaceXOfScreen;
-       uniforms.y = surfaceYOfScreen;
-       uniforms.width = surfaceWidthOfScreen;
-       uniforms.height = surfaceHeightOfScreen;
-       uniforms.opacity = (surface)->getOpacity() * currentLayer->getOpacity();
-       uniforms.texRange[0] = sourceViewportWidthPercent;
-       uniforms.texRange[1] = sourceViewportHeightpercent;
-       uniforms.texOffset[0] = sourceViewportXPercent;
-       uniforms.texOffset[1] = -sourceViewportYPercent;
-       uniforms.texUnit = 0;
-
-       //      LOG_INFO("GLESGraphicsystem", "Load Common Uniforms");
-       shader->loadCommonUniforms(uniforms);
-
-       //      LOG_INFO("GLESGraphicsystem", "Load Custom Uniforms");
-       // update all custom defined uniforms
-       shader->loadUniforms();
-       /* Bind texture and set section */
-       glActiveTexture(GL_TEXTURE0);
-       m_binder->bindSurfaceTexture(surface);
-
-       // rotated positions are saved sequentially in vbo
-       // offset in multiples of 12 decide rotation
-       int orientation = (surface)->getOrientation() + (currentLayer)->getOrientation();
-       orientation %= 4;
-       int index = orientation * 12;
-//     LOG_INFO("GLESGraphicsystem", "Drawing surface");
-       // Draw two triangles
-       glDrawArrays(GL_TRIANGLES, 0, 6);
-       // get the next surface
-       glBindBuffer(GL_ARRAY_BUFFER,NULL);
-//     LOG_INFO("GLESGraphicsystem", "Drawing surface done");
-//     LOG_INFO("GLESGraphicsystem", "Drawing surface done now checking for error");
-       GLenum status = glGetError();
+  GLint index = 0;
+  IlmMatrix layerMatrix;
+  IlmMatrixIdentity(layerMatrix);
+  Rectangle layerdest = (currentLayer)->getDestinationRegion();
+  Rectangle layersrc = (currentLayer)->getSourceRegion();
+
+  float scalex = (float)layerdest.width / (float) m_displayWidth;
+  float scaley = (float)layerdest.height / (float) m_displayHeight;
+  ShaderProgram::CommonUniforms uniforms;
+#ifdef DRAW_LAYER_DEBUG
+  ShaderProgram::CommonUniforms layeruniforms;
+#endif
+  Shader* layerShader = currentLayer->getShader();
+  if (!layerShader)
+    {
+      // use default shader if no custom shader is assigned to this layer
+      layerShader = m_defaultShader;
+    }
+  Shader* shader = (surface)->getShader();
+  if (!shader)
+    {
+      // use layer shader if no custom shader is assigned to this surface
+      shader = layerShader;
+    }
+  Rectangle dest = (surface)->getDestinationRegion();
+  Rectangle src = (surface)->getSourceRegion();
+
+
+  float surfaceXOfScreen =      (float) dest.x / (float) layerdest.width + (float) layerdest.x / m_displayWidth ;
+  float surfaceYOfScreen =     (float) dest.y / (float) layerdest.height + (float) layerdest.y / m_displayHeight ;
+  float surfaceWidthOfScreen = ((float) dest.width / m_displayWidth ) * scalex;
+  float surfaceHeightOfScreen = ((float) dest.height / m_displayHeight ) * scaley;
+
+  float sourceViewportWidthPercent = (float)src.width/(surface)->OriginalSourceWidth;
+  float sourceViewportHeightpercent = (float)src.height/(surface)->OriginalSourceHeight;
+  float sourceViewportXPercent = (float)src.x/(surface)->OriginalSourceWidth;
+  float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight;
+
+  glBindBuffer(GL_ARRAY_BUFFER,m_vbo);
+  IlmMatrixRotateZ(layerMatrix,currentLayer->getOrientation()*90.0f);
+  /* update all common uniforms */
+  uniforms.x = surfaceXOfScreen;
+  uniforms.y = surfaceYOfScreen;
+  uniforms.width = surfaceWidthOfScreen;
+  uniforms.height = surfaceHeightOfScreen;
+  uniforms.opacity = (surface)->getOpacity() * currentLayer->getOpacity();
+  uniforms.texRange[0] = sourceViewportWidthPercent;
+  uniforms.texRange[1] = sourceViewportHeightpercent;
+  uniforms.texOffset[0] = sourceViewportXPercent;
+  uniforms.texOffset[1] = -sourceViewportYPercent;
+  uniforms.texUnit = 0;
+  uniforms.matrix = &layerMatrix.f[0];
+
+#ifdef DRAW_LAYER_DEBUG
+  layeruniforms.x = (float) layerdest.x / m_displayWidth;
+  layeruniforms.y = (float) layerdest.y / m_displayHeight;
+  layeruniforms.width = (float)layerdest.width / m_displayWidth;
+  layeruniforms.height = (float)layerdest.height / m_displayHeight;
+  layeruniforms.opacity = currentLayer->getOpacity();
+  layeruniforms.matrix = &layerMatrix.f[0];
+  m_layerShader->use();
+  m_layerShader->loadCommonUniforms(layeruniforms);
+  m_layerShader->loadUniforms();
+
+  glDrawArrays(GL_TRIANGLES, 0, 6);
+#endif
+  shader->use();
+
+  /* load common uniforms */
+  shader->loadCommonUniforms(uniforms);
+
+
+  /* update all custom defined uniforms */
+  shader->loadUniforms();
+  /* Bind texture and set section */
+  glActiveTexture(GL_TEXTURE0);
+  m_binder->bindSurfaceTexture(surface);
+
+  /* rotated positions are saved sequentially in vbo
+           offset in multiples of 12 decide rotation */
+  /* Draw two triangles */
+  int orientation = (surface)->getOrientation();
+  orientation %= 4;
+  index = orientation * 12;
+
+  glDrawArrays(GL_TRIANGLES, index, 6);
+
+  glBindBuffer(GL_ARRAY_BUFFER,NULL);
+
+  GLenum status = glGetError();
 }
 
 bool GLESGraphicsystem::initOpenGLES(EGLint displayWidth,EGLint displayHeight)
 {
-       LOG_DEBUG("GLESGraphicsystem", "initEGL");
-       bool result = true;
-    ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc);
-    defaultShader = Shader::createShader("default", "default");
-    if (!defaultShader)
+  LOG_DEBUG("GLESGraphicsystem", "initEGL");
+  bool result = true;
+  ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc);
+  m_defaultShader = Shader::createShader("default", "default");
+#ifdef DRAW_LAYER_DEBUG
+  m_layerShader = Shader::createShader("renderer_layer.glslv", "renderer_layer.glslf");
+#endif
+  if (
+      !m_defaultShader
+#ifdef DRAW_LAYER_DEBUG
+     || !m_layerShader
+#endif
+  )
     {
-        LOG_ERROR("GLESGraphicsystem", "Failed to create and link default shader program");
-        delete defaultShader;
-        result = false;
+      LOG_ERROR("GLESGraphicsystem", "Failed to create and link default shader program");
+      delete m_defaultShader;
+      result = false;
     }
-    else
-       {
-        LOG_INFO("GLESGraphicsystem", "Default Shader successfully applied");
-       glGenBuffers(1,&m_vbo);
-       glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
-       glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
-        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
-        glEnableVertexAttribArray(0);
-        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) *12));
-        glEnableVertexAttribArray(1);
-
-               glEnable (GL_BLEND);
-               glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               m_blendingStatus = true;
-               glClearColor(1.0, 0.0, 0.0, 1.0);
-               resize(displayWidth,displayHeight);
-       }
-       return result;
+  else
+    {
+      LOG_INFO("GLESGraphicsystem", "Default Shader successfully applied");
+      glGenBuffers(1,&m_vbo);
+      glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+      glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+      glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
+      glEnableVertexAttribArray(0);
+      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) *12));
+      glEnableVertexAttribArray(1);
+
+      glEnable (GL_BLEND);
+      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+      m_blendingStatus = true;
+      glClearColor(1.0, 1.0, 1.0, 1.0);
+      resize(displayWidth,displayHeight);
+    }
+  return result;
 }
 void GLESGraphicsystem::resize(EGLint displayWidth,EGLint displayHeight)
 {
-       m_displayWidth = displayWidth;
-       m_displayHeight = displayHeight;
-    glViewport(0, 0, m_displayWidth, m_displayHeight);
+  m_displayWidth = displayWidth;
+  m_displayHeight = displayHeight;
+  glViewport(0, 0, m_displayWidth, m_displayHeight);
+}
+
+void GLESGraphicsystem::saveScreenShot(){
+       {
+               // clear error if any
+               int error = glGetError();
+               LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << screenShotFile);
+
+               GLint viewport[4];
+               glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height
+               error = glGetError();
+               if (error != GL_NO_ERROR)
+                       LOG_DEBUG("BaseGraphicSystem","error getting dimensions");
+               int WINDOW_WIDTH= viewport[2];
+               int WINDOW_HEIGHT= viewport[3];
+               LOG_DEBUG("BaseGraphicSystem","Screenshot: " << WINDOW_WIDTH << " * " << WINDOW_HEIGHT);
+               char *buffer = (char *)malloc(WINDOW_WIDTH * WINDOW_HEIGHT * 4 * sizeof(char));
+               glReadPixels(0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_RGBA,GL_UNSIGNED_BYTE, buffer);
+               error = glGetError();
+               if (error != GL_NO_ERROR)
+                       LOG_DEBUG("BaseGraphicSystem","error reading pixels for screenshot: " << error);
+               // convert to RGB for bitmap
+               int pixelcount = WINDOW_WIDTH * WINDOW_HEIGHT;
+               char *rgbbuffer = (char *)malloc(pixelcount*3 * sizeof(char));
+               for (int row=0;row<WINDOW_HEIGHT;row++ ){
+                       for (int col=0;col<WINDOW_WIDTH;col++){
+                               int offset = row*WINDOW_WIDTH+col;
+                               rgbbuffer[offset*3]   = buffer[offset*4+2];
+                               rgbbuffer[offset*3+1] = buffer[offset*4+1];
+                               rgbbuffer[offset*3+2] = buffer[offset*4];
+                       }
+               }
+
+               writeBitmap(screenShotFile,rgbbuffer,WINDOW_WIDTH,WINDOW_HEIGHT);
+               free(buffer);
+       }
+}
+
+void GLESGraphicsystem::doScreenShot(std::string fileToSave){
+        screenShotFile = fileToSave;
+        takescreenshot=true;
 }
index 35c12e0..58d8d7e 100644 (file)
 
        void X11EglImage::destroyClientBuffer(Surface* surface){
                EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)surface->platform;
-               if (nativeSurface->eglImage != NULL )
+               if (nativeSurface != NULL && nativeSurface->eglImage != NULL )
                {
-                       m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage);
+                     m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage);
+                     glDeleteTextures(1,&nativeSurface->texture);
                }
                glDeleteTextures(1,&nativeSurface->texture);
        }
index 4301ec8..6356a6d 100644 (file)
@@ -40,6 +40,10 @@ X11WindowSystem::X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphi
 
        };
 
+X11WindowSystem::~X11WindowSystem(){
+       delete graphicSystem;
+}
+
 XVisualInfo* X11WindowSystem::getDefaultVisual(Display *dpy)
        {
                XVisualInfo* windowVis = new XVisualInfo();
@@ -120,14 +124,12 @@ Surface* X11WindowSystem::getSurfaceForWindow(Window w){
        const std::map<int,Surface*> surfaces = layerlist->getAllSurfaces();
        for(std::map<int, Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
                Surface* currentSurface = (*currentS).second;
-               XPlatformSurface* x11surf = NULL;
-               if (NULL != currentSurface->platform){
-                       x11surf = (XPlatformSurface*)currentSurface->platform;
-                       if (currentSurface->nativeHandle == w){
-                               LOG_DEBUG("X11WindowSystem", "surface " << currentSurface->getID() << " corresponds to window" << w);
-                               return currentSurface;
-                       }
-               }
+               LOG_DEBUG("X11WindowSystem", "CurrentSurface surface for window " << currentSurface->getID());
+                LOG_DEBUG("X11WindowSystem", "CurrentSurface nativeHandle " << currentSurface->nativeHandle);
+                if (currentSurface->nativeHandle == w){
+                        LOG_DEBUG("X11WindowSystem", "surface " << currentSurface->getID() << " corresponds to window" << w);
+                        return currentSurface;
+                }
        }
        LOG_DEBUG("X11WindowSystem", "could not find surface for window " << w);
        return NULL;
@@ -221,7 +223,7 @@ void X11WindowSystem::MapWindow(Window window){
                        LOG_DEBUG("X11WindowSystem", "Done mapping");
                }
        }
-       LOG_INFO("EglXCompositeRenderer","mapping end");
+       LOG_INFO("X11WindowSystem","mapping end");
 }
 
 void X11WindowSystem::UnMapWindow(Window window){
@@ -310,7 +312,8 @@ XLowerWindow(x11Display,window);
 }
 
 void X11WindowSystem::DestroyWindow(Window window){
-       if (isWindowValid(window)){
+       if (isWindowValid(window))
+         {
                LOG_DEBUG("X11WindowSystem", "Destroying Surface for window " << window);
                Surface* surface = getSurfaceForWindow(window);
                if (surface==NULL){
@@ -319,9 +322,11 @@ void X11WindowSystem::DestroyWindow(Window window){
                }
                graphicSystem->m_binder->destroyClientBuffer(surface);
                UnMapWindow(window);
-               layerlist->removeSurface(surface);
-               LOG_DEBUG("X11WindowSystem", "Removed Surface " << surface->getID());
-       }
+                LOG_DEBUG("X11WindowSystem", "Removed Surface " << surface->getID());
+               layerlist->lockList();
+                layerlist->removeSurface(surface);
+                layerlist->unlockList();
+         }
 }
 
 bool
@@ -350,9 +355,6 @@ X11WindowSystem::CreatePixmapsForAllWindows()
        return result;
 }
 
-
-
-
 bool X11WindowSystem::CreateCompositorWindow()
 {
        LOG_DEBUG("X11WindowSystem", "Get root window");
@@ -384,7 +386,6 @@ bool X11WindowSystem::CreateCompositorWindow()
                                0, windowVis->depth, InputOutput,
                                windowVis->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr);
 
-
        if (!CompositorWindow)
        {
                LOG_ERROR("X11WindowSystem", "Could not create window");
@@ -431,31 +432,37 @@ X11WindowSystem::Redraw()
 {
        // draw all the layers
        graphicSystem->clearBackground();
+       /*LOG_INFO("X11WindowSystem","Locking List");*/
+       layerlist->lockList();
        std::list<Layer*> layers = layerlist->getCurrentRenderOrder();
-       for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++){
+       for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++)
+         {
                Layer* currentLayer = (Layer*)*current;
-               if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f){
-                       //   glRotated(-90*currentLayer->getOrientation(),0,0,1.0);
-                       // draw all the surfaces of the layer
+               if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f)
+                 {
+                        /*LOG_INFO("X11WindowSystem","Draw Layer " << currentLayer->getID());*/
                        std::list<Surface*> surfaces = currentLayer->surfaces;
-                       for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
-                               if ((*currentS)->visibility && (*currentS)->opacity>0.0f){
+                       for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++)
+                         {
+                                /*LOG_INFO("X11WindowSystem","Surface to draw " << (*currentS)->getID());*/
+                                if ((*currentS)->visibility && (*currentS)->opacity>0.0f)
+                                  {
                                        Surface* currentSurface = (Surface*)*currentS;
                                        XPlatformSurface* nativeSurface = (XPlatformSurface*)currentSurface->platform;
                                        if (NULL==nativeSurface)
                                        {
-                                               LOG_INFO("X11WindowSystem","creating native surface for new window");
+                                               /*LOG_INFO("X11WindowSystem","creating native surface for new window");*/
                                                // this surface does not have a native platform surface attached yet!
                                                NewWindow(currentSurface,currentSurface->nativeHandle);
                                                MapWindow(currentSurface->nativeHandle);
                                        }
+                                       /*LOG_INFO("X11WindowSystem","Drawing Layer begin");*/
                                        graphicSystem->drawSurface(currentLayer,currentSurface);
-
-                               }
-                       }
-               }
-       }
-
+                                       /*LOG_INFO("X11WindowSystem","Drawing Layer end");*/
+                                  }
+                         }
+                 }
+         }
        if (debugMode)
        {
                printDebug(200,windowHeight-40);
@@ -468,7 +475,9 @@ X11WindowSystem::Redraw()
        {
                LOG_INFO("X11WindowSystem",floatStringBuffer);
        }
-       graphicSystem->swapBuffers();
+       layerlist->unlockList();
+       /*LOG_INFO("X11WindowSystem","UnLocking List");*/
+       graphicSystem->swapBuffers();
 }
 
 int
@@ -579,6 +588,7 @@ bool X11WindowSystem::initXServer()
                                XMapRaised(x11Display, w);
                        }
                }
+               XFree(name);
        }
        XFree(children);
        XUngrabServer (x11Display);
@@ -607,19 +617,19 @@ void* X11WindowSystem::EventLoop(void * ptr)
        Layer* defaultLayer;
 
        // run the main event loop while rendering
-       bool running = windowsys->m_success;
+       windowsys->m_running = m_success;
        gettimeofday(&tv0, NULL);
        FramesPerFPS = 30;
        if (windowsys->debugMode)
        {
-               defaultLayer = windowsys->layerlist->createLayer();
+               defaultLayer = windowsys->layerlist->createLayer(-1);
                defaultLayer->setOpacity(1.0);
                defaultLayer->setDestinationRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
                defaultLayer->setSourceRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
                windowsys->layerlist->getCurrentRenderOrder().push_back(defaultLayer);
        }
        LOG_DEBUG("X11WindowSystem", "Enter render loop");
-       while (running)
+       while (windowsys->m_running)
        {
                if ( XPending(windowsys->x11Display) > 0) {
                        XEvent event;
@@ -630,7 +640,7 @@ void* X11WindowSystem::EventLoop(void * ptr)
                                if (windowsys->debugMode)
                                {
                                        LOG_DEBUG("X11WindowSystem", "CreateNotify Event");
-                                       Surface* s = windowsys->layerlist->createSurface();
+                                       Surface* s = windowsys->layerlist->createSurface(-1);
                                        s->setOpacity(1.0);
                                        windowsys->NewWindow(s, event.xcreatewindow.window);
                                        defaultLayer->addSurface(s);
@@ -676,14 +686,24 @@ void* X11WindowSystem::EventLoop(void * ptr)
                }
                windowsys->Redraw();
        }
+       windowsys->cleanup();
        LOG_INFO("X11WindowSystem", "Renderer thread finished");
        return NULL;
 }
 
+void X11WindowSystem::cleanup(){
+       LOG_INFO("X11WindowSystem", "Cleanup");
+       Window root = RootWindow(x11Display, 0);
+       XCompositeUnredirectSubwindows(x11Display,root,CompositeRedirectManual);
+       XDestroyWindow(x11Display,CompositorWindow);
+       XCloseDisplay(x11Display);
+       m_initialized = false;
+       m_running = false;
+}
+
 
 bool X11WindowSystem::start(int displayWidth, int displayHeight, const char* DisplayName){
        LOG_INFO("X11WindowSystem", "Starting / Creating thread");
-       pthread_t renderThread;
        X11WindowSystem *renderer = this;
        resolutionWidth = displayWidth;
        resolutionHeight = displayHeight;
@@ -700,3 +720,10 @@ bool X11WindowSystem::start(int displayWidth, int displayHeight, const char* Dis
        LOG_INFO("X11WindowSystem","Start complete " << m_initialized << " success " << m_success);
        return m_success;
 }
+
+void X11WindowSystem::stop(){
+       LOG_INFO("X11WindowSystem","Stopping..");
+       this->m_running = false;
+       pthread_join(renderThread,NULL);
+}
+
index 5902f61..58163fb 100644 (file)
@@ -71,6 +71,8 @@ $(TARGET): $(SHADERS) $(OBJS)
 install:
        mkdir -p $(PREFIX)/usr/lib/layermanager/renderer
        install -m 755 $(TARGET) $(PREFIX)/usr/lib/layermanager/renderer
+       install -m 755 renderer_frag.glslf $(PREFIX)/usr/lib/layermanager/renderer
+       install -m 755 renderer_vert.glslv $(PREFIX)/usr/lib/layermanager/renderer
 
 clean:
        rm -f $(OBJS) $(TARGET)
index 44e86c3..e819dea 100644 (file)
 
 #include "BaseRenderer.h"
 #include "LayerList.h"
+#include "GraphicSystems/GLESGraphicSystem.h"
 
 class X11GLESRenderer : public BaseRenderer
 {
 public:
        X11GLESRenderer(LayerList* layerlist);
-
+       void doScreenShot(std::string fileToSave);
+private:
+       BaseGraphicSystem* graphicSystem;
 };
 
 #endif /* _X11GLESRENDERER_H_*/
diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslf b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslf
new file mode 100644 (file)
index 0000000..3a85ba7
--- /dev/null
@@ -0,0 +1,27 @@
+/***************************************************************************
+*
+* Copyright 2010 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*       http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+// alpha value of the surfaces 
+uniform float uAlphaVal;
+
+void main()
+{      
+       // correct Texture Coords;
+    mediump vec4 color = vec4(0.0,1.0,0.0,uAlphaVal);
+    gl_FragColor = color;
+}
diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslv b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslv
new file mode 100644 (file)
index 0000000..d6cee2e
--- /dev/null
@@ -0,0 +1,45 @@
+/***************************************************************************
+*
+* Copyright 2010 BMW Car IT GmbH
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*       http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+
+// Vertex position. Will be in range 0 to 1
+attribute highp vec2 aPosition;
+attribute highp vec2 aTexCoords;
+
+uniform mediump mat4 uMatrix;
+// normalized window position
+// (0, 0 is upper left,  1, 1 is lower right)
+uniform mediump float uX;
+uniform mediump float uY;
+
+// normalized window size
+// 1.0 will cover the entire viewport
+uniform mediump float uWidth;
+uniform mediump float uHeight;
+
+void main()
+{
+       // Get the size correct. Multiply by 2 because -1 to +1 is mapped to 
+       // the viewport
+       highp vec4 position;
+       position.xy = 2.0 * aPosition.xy * vec2( uWidth, uHeight);                      // rechte seite des fensters: volle breite sonst 0
+       position.xy += vec2(uX * 2.0 - 1.0, 1.0 - ((uY + uHeight)* 2.0));               // linke seite des fensters                 
+       position.zw = vec2(0.0, 1.0);
+                
+       gl_Position     = uMatrix*position;      
+}
index c4b8be6..7b2d540 100644 (file)
@@ -21,6 +21,7 @@
 attribute highp vec2 aPosition;
 attribute highp vec2 aTexCoords;
 
+uniform mediump mat4 uMatrix;
 // normalized window position
 // (0, 0 is upper left,  1, 1 is lower right)
 uniform mediump float uX;
@@ -43,8 +44,11 @@ void main()
 {
        // Get the size correct. Multiply by 2 because -1 to +1 is mapped to 
        // the viewport
-       gl_Position.xy = 2.0 * aPosition.xy * vec2( uWidth, uHeight);                   // rechte seite des fensters: volle breite sonst 0
-       gl_Position.xy += vec2(uX * 2.0 - 1.0, 1.0 - ((uY + uHeight)* 2.0));            // linke seite des fensters                 
-       gl_Position.zw = vec2(0.0, 1.0);
+       highp vec4 position;
+       position.xy = 2.0 * aPosition.xy * vec2( uWidth, uHeight);                      // rechte seite des fensters: volle breite sonst 0
+       position.xy += vec2(uX * 2.0 - 1.0, 1.0 - ((uY + uHeight)* 2.0));               // linke seite des fensters                 
+       position.zw = vec2(0.0, 1.0);
+       
+       gl_Position = uMatrix*position;
        vTexout = vec2(uTexOffset.x + uTexRange.x * aTexCoords.x,1.0-(uTexOffset.y + aTexCoords.y*uTexRange.y+(1.0-uTexRange.y)));
 }
index efc3ba1..9da7afa 100644 (file)
 
 #include "X11GLESRenderer.h"
 #include "ShaderProgramGLES.h"
-#include "GraphicSystems/GLESGraphicSystem.h"
 #include "WindowSystems/X11WindowSystem.h"
 #include "X11/Xlib.h"
 #include "TextureBinders/X11CopyGLES.h"
 #include "TextureBinders/X11EglImage.h"
 
-X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist)
+X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist), graphicSystem(NULL)
 {
        LOG_DEBUG("X11GLESRenderer", "Creating Renderer");
 
@@ -41,10 +40,14 @@ X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist)
                        binder = new X11CopyGLES((Display*)display);
        #endif
 
-       BaseGraphicSystem* graphicSystem = new GLESGraphicsystem( ShaderProgramGLES::createProgram, binder);
+       graphicSystem = new GLESGraphicsystem( ShaderProgramGLES::createProgram, binder);
        m_windowSystem = new X11WindowSystem(layerlist, graphicSystem);
 };
 
+void X11GLESRenderer::doScreenShot(std::string fileToSave){
+       graphicSystem->doScreenShot(fileToSave);
+}
+
 extern "C" BaseRenderer* createX11GLESRenderer(LayerList* layerlist){
     return new X11GLESRenderer(layerlist);
 }