Stability Fixes, adapted to new Interfaces, Rendering concept rewritten
authorMichael Schuldt <Michael.Schuldt@bmw-carit.de>
Mon, 4 Apr 2011 10:20:54 +0000 (12:20 +0200)
committerMichael Schuldt <Michael.Schuldt@bmw-carit.de>
Mon, 4 Apr 2011 10:20:54 +0000 (12:20 +0200)
45 files changed:
LayerManagerPlugins/Renderers/Base/include/BaseRenderer.h
LayerManagerPlugins/Renderers/Base/include/RenderUtil.h
LayerManagerPlugins/Renderers/Base/src/BaseRenderer.cpp
LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/BaseGraphicSystem.h
LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLESGraphicSystem.h
LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLXGraphicsystem.h
LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/BeaglePlatformSurface.h
LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/EglXPlatformSurface.h
LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/GLXPlatformSurface.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/TextureBinders/X11Copy.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLX.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11EglImage.h
LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11TextureFromPixmap.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/NullWindowSystem.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLXGraphicSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11Copy.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11EglImage.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11TextureFromPixmap.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/NullWindowSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/BeagleRenderer.h
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/ShaderProgramBeagle.h
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/makefile
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_frag.glslf
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_vert.glslv
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/BeagleRenderer.cpp
LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/ShaderProgramBeagle.cpp
LayerManagerPlugins/Renderers/Platform/GLXRenderer/include/X11GLXRenderer.h
LayerManagerPlugins/Renderers/Platform/GLXRenderer/src/X11GLXRenderer.cpp
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_frag.glslf
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslf
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_layer.glslv
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_vert.glslv
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/ShaderProgramGLES.cpp
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp

index 32bd087..5509158 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,14 +30,13 @@ public:
        BaseRenderer(LayerList* layerlist);
        virtual ~BaseRenderer();
 
-       bool start(int, int, const char*);
-       void stop();
+       bool start(int, int, const char*)=0;
+       void stop()=0;
        void setdebug(bool onoff){debugMode = onoff;};
        virtual void doScreenShot(std::string fileToSave)=0;
        uint getLayerTypeCapabilities(LayerType layerType);
 
 protected:
-       BaseWindowSystem* m_windowSystem;
        LayerList* m_layerlist;
 
 private:
index c9e4f18..3aedb03 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index cab6fbf..2afe978 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,12 +35,12 @@ uint BaseRenderer::getLayerTypeCapabilities(LayerType layerType){
        {
                case Software_2D:
                {
-                       result = LayerPosition & LayerScalable & LayerOrientable;
+                       result = LayerPosition | LayerScalable | LayerOrientable | LayerComposedByAlpha;
                }
                break;
                case Software_2_5D:
                {
-                       result = LayerPosition & LayerScalable & LayerOrientable & Layer3D;
+                       result = LayerPosition | LayerScalable | LayerOrientable | LayerComposedByAlpha;
                }
                break;
                default :
@@ -51,10 +51,3 @@ uint BaseRenderer::getLayerTypeCapabilities(LayerType layerType){
        return result;
 }
 
-bool BaseRenderer::start(int displayWidth, int displayHeight, const char* DisplayName){
-       bool windowSystemStatus = m_windowSystem->start(displayWidth,displayHeight,DisplayName);
-       return windowSystemStatus;
-}
-void BaseRenderer::stop(){
-               m_windowSystem->stop();
-}
index d98b9ed..81d5b72 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 #define _BASEGRAPHICSYSTEM_H_
 
 #include "TextureBinders/ITextureBinder.h"
+#include "WindowSystems/BaseWindowSystem.h"
 #include "PlatformSurface.h"
 #include "Surface.h"
 #include "Layer.h"
 
+template <class DisplayType, class WindowType>
 class BaseGraphicSystem {
 public:
+       virtual bool init(DisplayType display, WindowType window)=0;
        virtual ~BaseGraphicSystem(){};
-       virtual bool init(void* display, void* WindowID,int WindowHeight, int WindowWidth)=0;
-       virtual void drawSurface(Layer*,Surface*)=0;
+       virtual void setBaseWindowSystem(BaseWindowSystem* windowSystem){m_baseWindowSystem = windowSystem;};
+       virtual void beginLayer(Layer* layer) = 0;
+       virtual void renderLayer() = 0;
+       virtual void endLayer() = 0;
+
        virtual void clearBackground()=0;
        virtual void swapBuffers()=0;
-       virtual void doScreenShot(std::string fileToSave)=0;
+       virtual void saveScreenShotOfFramebuffer(std::string fileToSave)=0;
+       void setTextureBinder(ITextureBinder* binder){m_binder=binder;};
        ITextureBinder* m_binder;
-
+       virtual void renderSurface(Surface*)=0;
+protected:
+       BaseWindowSystem* m_baseWindowSystem;
 };
 
 #endif /* _BASEGRAPHICSYSTEM_H_ */
index 87d32d6..13001fd 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 #include "Shader.h"
 /* uncomment if layer drawing needed */
 /* #define DRAW_LAYER_DEBUG */
-class GLESGraphicsystem : public BaseGraphicSystem {
+class GLESGraphicsystem : public BaseGraphicSystem<EGLNativeDisplayType, EGLNativeWindowType> {
 public:
-       GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder);
 
-       bool init(void* display, void* WindowID,int WindowHeight, int WindowWidth);
+       GLESGraphicsystem(int windowHeight, int windowWidth, PfnShaderProgramCreator shaderProgram);
+
+       bool init(EGLNativeDisplayType display, EGLNativeWindowType window);
+
        void clearBackground();
+
        void swapBuffers();
-       void drawSurface(Layer* currentLayer, Surface* surface);
+
+       void beginLayer(Layer* layer);
+       void renderLayer();
+       void endLayer();
+
        bool initOpenGLES(EGLint displayWidth, EGLint displayHeight);
        void resize(EGLint displayWidth, EGLint displayHeight);
        void doScreenShot(std::string fileToSave);
 
+       void saveScreenShotOfFramebuffer(std::string fileToSave);
+
+       EGLDisplay getEGLDisplay(){return m_eglDisplay;};
+
+       int                                                             m_windowWidth;
+       int                                                             m_windowHeight;
+       EGLNativeDisplayType                            m_nativeDisplay;
+       EGLNativeWindowType                             m_nativeWindow;
        PfnShaderProgramCreator                         m_shaderCreatorFunc;
        EGLConfig                                                       m_eglConfig;
        EGLContext                                                      m_eglContext;
@@ -49,13 +64,14 @@ public:
        EGLint                                                          m_displayHeight;
        EGLBoolean                                                      m_blendingStatus;
        Shader*                                                         m_defaultShader;
+       Layer*                                                          m_currentLayer;
+       void renderSurface(Surface* surface);
 #ifdef DRAW_LAYER_DEBUG
        Shader*                                                         m_layerShader;
 #endif
+protected:
 private:
        void saveScreenShot();
-       std::string screenShotFile;
-       bool takescreenshot;
 };
 
 #endif /* _GLESGRAPHICSYSTEM_H_ */
index 10d606a..1c6d732 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 #include "PlatformSurfaces/GLXPlatformSurface.h"
 #include "Log.h"
 
-class GLXGraphicsystem : public BaseGraphicSystem {
+class GLXGraphicsystem : public BaseGraphicSystem<Display*, Window> {
 public:
-       GLXGraphicsystem();
+       GLXGraphicsystem( int WindowHeight, int WindowWidth);
        virtual ~GLXGraphicsystem();
        static XVisualInfo* ChooseWindowVisual(Display *dpy);
-       bool init(void* display, void* WindowID,int WindowHeight, int WindowWidth);
+       bool init(Display* x11Display, Window x11Window);
+
+       void beginLayer(Layer* layer);
+       void renderLayer();
+       void endLayer();
+
        void clearBackground();
        void swapBuffers();
-       void drawSurface(Layer* currentLayer, Surface* currentSurface);
-       void doScreenShot(std::string fileToSave);
+       void saveScreenShotOfFramebuffer(std::string fileToSave);
+       static GLXFBConfig ChoosePixmapFBConfig(Display *display);
+       void renderSurface(Surface* currentSurface);
 
 private:
-       void saveScreenShot();
-       std::string screenShotFile;
-       bool takescreenshot;
-       static GLXFBConfig ChoosePixmapFBConfig(Display *display);
        int windowWidth;
        int windowHeight;
        Display* x11disp;
-       Window window;
+       Window  window;
+       Layer*  m_currentLayer;
 };
 
 #endif /* _GLXGRAPHICSYSTEM_H_ */
index c79592a..afb126b 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 72c6963..e821490 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 7874323..95a22fe 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index a2b7a0c..d15d960 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index ce8222e..71493e7 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,7 @@
 
 class BeagleEglImage : public ITextureBinder {
 public:
-       BeagleEglImage(){
+       BeagleEglImage(EGLDisplay eglDisplay) : m_eglDisplay(eglDisplay){
                LOG_INFO("BeagleEglImage", "Query EGL Extensions ...");
                CMEM_init();
                m_pfGLEglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
@@ -45,7 +45,6 @@ public:
                        LOG_ERROR("BeagleEglImage", "Query EGL Extensions failed");
                }
 
-               m_eglDisplay = eglGetDisplay(0);
        }
        void bindSurfaceTexture(Surface*s){
                //              LOG_INFO("BeagleEglImage", "bindSurfaceTexture");
index f46222e..c2b305e 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 6a66dd5..1c5da92 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index de7c1e4..7ca79ab 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 
 class X11CopyGLES : public X11Copy {
 public:
-       X11CopyGLES(Display* display) : X11Copy(display){};
+       X11CopyGLES(EGLDisplay eglDisplay, Display* display) : X11Copy(display){
+               // pseudo require EGL to have been initialised
+               // we dont really need the handle
+       };
        void bindSurfaceTexture(Surface* surface);
        void createClientBuffer(Surface*s);
 
index b8498b1..f3fadd2 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index e6898e6..0704388 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@
 
 class X11EglImage : public ITextureBinder {
 public:
-       X11EglImage(Display* x11display);
+       X11EglImage(EGLDisplay eglDisplay, Display* x11display);
        void bindSurfaceTexture(Surface*s);
        void unbindSurfaceTexture(Surface*s);
        void createClientBuffer(Surface* surface);
index d9ab1d2..83a59d0 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 8389fba..1bcd500 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 #ifndef _BASEWINDOWSYSTEM_H_
 #define _BASEWINDOWSYSTEM_H_
 
-#include "GraphicSystems/BaseGraphicSystem.h"
 #include "LayerList.h"
 
 class BaseWindowSystem {
 public:
-       BaseWindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem) : graphicSystem(graphicSystem), layerlist(layerlist){};
+       BaseWindowSystem(LayerList* layerlist) : layerlist(layerlist){};
        virtual ~BaseWindowSystem(){};
-       virtual bool start(int, int, const char*)=0;
+       virtual bool start()=0;
        virtual void stop()=0;
+       virtual void allocatePlatformSurface(Surface *surface) = 0;
+       virtual void doScreenShot(std::string fileName)=0;
+       virtual void doScreenShotOfLayer(std::string fileName, const uint id)=0;
+       virtual void doScreenShotOfSurface(std::string fileName, const uint id)=0;
 
 protected:
-       BaseGraphicSystem* graphicSystem;
        LayerList* layerlist;
 };
 
index 51cd78a..a2bd496 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@
 
 class NullWindowSystem : public BaseWindowSystem {
 public:
-       NullWindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem) : BaseWindowSystem(layerlist, graphicSystem){
+       NullWindowSystem(LayerList* layerlist,int width, int height) : BaseWindowSystem(layerlist), windowWidth(width), windowHeight(height),resolutionWidth(width),resolutionHeight(height){
                LOG_DEBUG("NullWindowSystem", "creating BeagleWindowSystem");
        };
        bool start(int, int, const char*);
@@ -45,8 +45,8 @@ private:
        void Redraw();
        void printDebug(int posx,int posy);
        static bool debugMode;
-       static int resolutionWidth;
-       static int resolutionHeight;
+       int resolutionWidth;
+       int resolutionHeight;
 };
 
 #endif /* _NULLWINDOWSYSTEM_H_ */
index c721e0e..312198c 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 
 #ifndef _X11WINDOWSYSTEM_H_
 #define _X11WINDOWSYSTEM_H_
-
 #include "WindowSystems/BaseWindowSystem.h"
+#include "GraphicSystems/BaseGraphicSystem.h"
 #include "X11/Xlib.h"
 #include "Surface.h"
 #include "PlatformSurfaces/XPlatformSurface.h"
 #include <X11/Xutil.h>
 #include "Log.h"
+#include "ScreenShotType.h"
 
 typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy);
 
 class X11WindowSystem : public BaseWindowSystem {
 public:
-       X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem,GetVisualInfoFunction func=X11WindowSystem::getDefaultVisual );
+       X11WindowSystem(const char* displayname, int width, int height, LayerList* layerlist, GetVisualInfoFunction func=X11WindowSystem::getDefaultVisual );
        virtual ~X11WindowSystem();
-       bool start(int, int, const char*);
+       bool init(BaseGraphicSystem<Display*,Window>* sys);
+       bool start();
        void stop();
        static XVisualInfo *
        getDefaultVisual(Display *dpy);
+       Display* getNativeDisplayHandle(){return x11Display;};
+       Window getCompositorNativeWindowHandle(){return CompositorWindow;};
+       virtual void allocatePlatformSurface(Surface *surface);
+       void doScreenShot(std::string fileName);
+       void doScreenShotOfLayer(std::string fileName, const uint id);
+       void doScreenShotOfSurface(std::string fileName, const uint id);
 
 private:
+       ScreenShotType takeScreenshot;
+       std::string screenShotFile;
+       uint screenShotID;
+       void RedrawAllLayers();
        static void* EventLoop(void * ptr);
        static int error (Display *dpy, XErrorEvent *ev);
+       const char* displayname;
        GetVisualInfoFunction getVisualFunc;
+       BaseGraphicSystem<Display*,Window>* graphicSystem;
 
 protected:
        Display* x11Display;
@@ -53,14 +67,13 @@ protected:
        //      Window background;
        Window CompositorWindow;
        XVisualInfo* windowVis;
-       static bool m_success;
-       static bool m_initialized;
+       pthread_mutex_t run_lock;
 
 private:
        void cleanup();
        void Redraw();
-       void OpenDisplayConnection();
-       void checkForCompositeExtension();
+       bool OpenDisplayConnection();
+       bool checkForCompositeExtension();
        void createSurfaceForWindow(Window w);
        void configureSurfaceWindow(Window w);
        Surface* getSurfaceForWindow(Window w);
@@ -83,6 +96,8 @@ private:
        int composite_major, composite_minor;
        static const char CompositorWindowTitle[];
        bool m_running;
+       bool m_initialized;
+       bool m_success;
 };
 
 #endif /* _X11WINDOWSYSTEM_H_ */
index 6419b40..fdf7079 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
  *
- * Copyright 2010 BMW Car IT GmbH
+ * Copyright 2010,2011 BMW Car IT GmbH
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -83,24 +83,26 @@ static const float vertices[8*12] = {
 
 };
 
-GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram), takescreenshot(false){
+GLESGraphicsystem::GLESGraphicsystem(int windowWidth, int windowHeight, PfnShaderProgramCreator shaderProgram) : m_shaderCreatorFunc(shaderProgram),
+                                                               m_windowHeight(windowHeight),
+                                                               m_windowWidth(windowWidth){
   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);
+bool GLESGraphicsystem::init(EGLNativeDisplayType display, EGLNativeWindowType NativeWindow){
+       m_nativeDisplay = display;
+       m_nativeWindow = NativeWindow;
 
   EGLint iMajorVersion, iMinorVersion;
-  LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display");
-  m_eglDisplay = eglGetDisplay(display);
+  LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display with native display " << m_nativeDisplay);
+  m_eglDisplay = eglGetDisplay(m_nativeDisplay);
 
   LOG_DEBUG("GLESGraphicsystem", "Initialising EGL");
   if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion))
+  {
+       LOG_ERROR("GLESGraphicsystem", "Initialising EGL failed");
     return false;
+  }
 
   LOG_DEBUG("GLESGraphicsystem", "Binding GLES API");
   eglBindAPI(EGL_OPENGL_ES_API);
@@ -122,15 +124,21 @@ bool GLESGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeigh
   EGLint id =0;
   eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id);
 
+  EGLint windowsAttr[]={EGL_RENDER_BUFFER,EGL_BACK_BUFFER,
+                                                 EGL_NONE};
+
   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");
+  m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_nativeWindow, windowsAttr);
+  if (!m_eglSurface)
+  {
+    EGLenum status = eglGetError();
+    LOG_ERROR("GLESGraphicsystem", "Window Surface creation failed with EGL Error Code: "<< status);
+    return false;
   }
+  LOG_DEBUG("GLESGraphicsystem", "Window Surface creation successfull");
+
   EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
   m_eglContext = eglCreateContext(m_eglDisplay,
       m_eglConfig,
@@ -150,7 +158,7 @@ bool GLESGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeigh
   LOG_INFO("GLESGraphicsystem", "made current");
 
 
-  if (!initOpenGLES(WindowWidth,WindowHeight) )
+  if (!initOpenGLES(m_windowWidth,m_windowHeight) )
     {
       return false;
     }
@@ -164,21 +172,47 @@ void GLESGraphicsystem::clearBackground()
 void GLESGraphicsystem::swapBuffers()
 {
   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)
+void GLESGraphicsystem::beginLayer(Layer* currentLayer)
+{
+       //LOG_DEBUG("GLESGraphicsystem", "Beginning to draw layer: " << currentLayer->getID());
+       m_currentLayer = currentLayer;
+       // TODO layer destination / source
+}
+
+void GLESGraphicsystem::renderLayer()
 {
+       if ((m_currentLayer)->visibility && (m_currentLayer)->opacity > 0.0)
+       {
+               std::list<Surface*> surfaces = m_currentLayer->surfaces;
+               for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++)
+               {
+                       //LOG_DEBUG("GLESGraphicsystem", "Testing if going to render surface: " << (*currentS)->getID());
+                       if ((*currentS)->visibility && (*currentS)->opacity>0.0f)
+                       {
+                               Surface* currentSurface = (Surface*)*currentS;
+                               m_baseWindowSystem->allocatePlatformSurface(currentSurface);
+                               renderSurface(currentSurface);
+                       }
+               }
+       }
+}
+
+void GLESGraphicsystem::endLayer()
+{
+       //LOG_DEBUG("GLESGraphicsystem", "Done with rendering layer: " << m_currentLayer->getID());
+       m_currentLayer = NULL;
+}
+
+void GLESGraphicsystem::renderSurface(Surface* surface)
+{
+//     LOG_DEBUG("GLESGraphicsystem", "renderSurface " << surface->getID());
   GLint index = 0;
   IlmMatrix layerMatrix;
   IlmMatrixIdentity(layerMatrix);
-  Rectangle layerdest = (currentLayer)->getDestinationRegion();
-  Rectangle layersrc = (currentLayer)->getSourceRegion();
+  Rectangle layerdest = (m_currentLayer)->getDestinationRegion();
+  Rectangle layersrc = (m_currentLayer)->getSourceRegion();
 
   float scalex = (float)layerdest.width / (float) m_displayWidth;
   float scaley = (float)layerdest.height / (float) m_displayHeight;
@@ -186,7 +220,7 @@ void GLESGraphicsystem::drawSurface(Layer* currentLayer,Surface* surface)
 #ifdef DRAW_LAYER_DEBUG
   ShaderProgram::CommonUniforms layeruniforms;
 #endif
-  Shader* layerShader = currentLayer->getShader();
+  Shader* layerShader = m_currentLayer->getShader();
   if (!layerShader)
     {
       // use default shader if no custom shader is assigned to this layer
@@ -213,13 +247,13 @@ void GLESGraphicsystem::drawSurface(Layer* currentLayer,Surface* surface)
   float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight;
 
   glBindBuffer(GL_ARRAY_BUFFER,m_vbo);
-  IlmMatrixRotateZ(layerMatrix,currentLayer->getOrientation()*90.0f);
+  IlmMatrixRotateZ(layerMatrix,m_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.opacity = (surface)->getOpacity() * m_currentLayer->getOpacity();
   uniforms.texRange[0] = sourceViewportWidthPercent;
   uniforms.texRange[1] = sourceViewportHeightpercent;
   uniforms.texOffset[0] = sourceViewportXPercent;
@@ -273,7 +307,7 @@ bool GLESGraphicsystem::initOpenGLES(EGLint displayWidth,EGLint displayHeight)
   ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc);
   m_defaultShader = Shader::createShader("default", "default");
 #ifdef DRAW_LAYER_DEBUG
-  m_layerShader = Shader::createShader("renderer_layer.glslv", "renderer_layer.glslf");
+  m_layerShader = Shader::createShader("/usr/lib/layermanager/renderer/renderer_layer.glslv", "/usr/lib/layermanager/renderer/renderer_layer.glslf");
 #endif
   if (
       !m_defaultShader
@@ -300,7 +334,7 @@ bool GLESGraphicsystem::initOpenGLES(EGLint displayWidth,EGLint displayHeight)
       glEnable (GL_BLEND);
       glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
       m_blendingStatus = true;
-      glClearColor(1.0, 1.0, 1.0, 1.0);
+      glClearColor(0.0, 0.0, 0.0, 1.0);
       resize(displayWidth,displayHeight);
     }
   return result;
@@ -312,11 +346,11 @@ void GLESGraphicsystem::resize(EGLint displayWidth,EGLint displayHeight)
   glViewport(0, 0, m_displayWidth, m_displayHeight);
 }
 
-void GLESGraphicsystem::saveScreenShot(){
+void GLESGraphicsystem::saveScreenShotOfFramebuffer(std::string fileToSave)
        {
                // clear error if any
                int error = glGetError();
-               LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << screenShotFile);
+               LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << fileToSave);
 
                GLint viewport[4];
                glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height
@@ -343,12 +377,7 @@ void GLESGraphicsystem::saveScreenShot(){
                        }
                }
 
-               writeBitmap(screenShotFile,rgbbuffer,WINDOW_WIDTH,WINDOW_HEIGHT);
+               writeBitmap(fileToSave,rgbbuffer,WINDOW_WIDTH,WINDOW_HEIGHT);
                free(buffer);
-       }
 }
 
-void GLESGraphicsystem::doScreenShot(std::string fileToSave){
-        screenShotFile = fileToSave;
-        takescreenshot=true;
-}
index 439cb61..729e2f5 100644 (file)
@@ -1,21 +1,21 @@
 /***************************************************************************
-*
-* 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,2011 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/GLXGraphicsystem.h"
 #include <string.h>
 
 #include "Bitmap.h"
 
-GLXGraphicsystem::GLXGraphicsystem() : takescreenshot(false) {
+GLXGraphicsystem::GLXGraphicsystem( int WindowWidth,int WindowHeight)
+{
        LOG_DEBUG("GLXGraphicsystem", "creating GLXGraphicsystem");
+       this->windowHeight = WindowHeight;
+       this->windowWidth = WindowWidth;
 }
 
-GLXGraphicsystem::~GLXGraphicsystem(){
+GLXGraphicsystem::~GLXGraphicsystem()
+{
        if (NULL!=m_binder)
                delete m_binder;
 }
 
 XVisualInfo* GLXGraphicsystem::ChooseWindowVisual(Display *dpy)
-       {
-               int screen = DefaultScreen(dpy);
-               XVisualInfo *visinfo;
-               int attribs[] = {
-                               GLX_RGBA,
-                               GLX_ALPHA_SIZE,8,
-                               GLX_RED_SIZE, 1,
-                               GLX_GREEN_SIZE, 1,
-                               GLX_BLUE_SIZE, 1,
-                               GLX_DEPTH_SIZE,8,
-                               GLX_BUFFER_SIZE,32,
-                               GLX_DOUBLEBUFFER,
-                               None
-               };
-
-               visinfo = glXChooseVisual(dpy, screen, attribs);
-               if (!visinfo) {
-                       LOG_ERROR("GLXGraphicsystem", "Unable to find RGB, double-buffered visual");
-                       exit(1);
-               }
-               return visinfo;
+{
+       int screen = DefaultScreen(dpy);
+       XVisualInfo *visinfo;
+       int attribs[] = {
+                       GLX_RGBA,
+                       GLX_ALPHA_SIZE,8,
+                       GLX_RED_SIZE, 1,
+                       GLX_GREEN_SIZE, 1,
+                       GLX_BLUE_SIZE, 1,
+                       GLX_DEPTH_SIZE,8,
+                       GLX_BUFFER_SIZE,32,
+                       GLX_DOUBLEBUFFER,
+                       None
        };
 
+       visinfo = glXChooseVisual(dpy, screen, attribs);
+       if (!visinfo) {
+               LOG_ERROR("GLXGraphicsystem", "Unable to find RGB, double-buffered visual");
+               exit(1);
+       }
+       return visinfo;
+}
+
 GLXFBConfig GLXGraphicsystem::ChoosePixmapFBConfig(Display *display)
 {
        LOG_DEBUG("GLXGraphicsystem", "Choose pixmap GL configuration");
@@ -104,12 +108,12 @@ GLXFBConfig GLXGraphicsystem::ChoosePixmapFBConfig(Display *display)
        return fbconfigs[i];
 }
 
-bool GLXGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeight, int WindowWidth){
+bool GLXGraphicsystem::init(Display* x11Display, Window x11Window)
+{
        LOG_DEBUG("GLXGraphicsystem", "init");
-       x11disp = *(Display**)displayPtr;
-       window = *(uint*)WIndowIDPtr;
-       this->windowHeight = WindowHeight;
-       this->windowWidth = WindowWidth;
+       x11disp = x11Display;
+       window = x11Window;
+
        if (!x11disp)
                LOG_ERROR("GLXGraphicsystem", "given display is null");
 
@@ -127,47 +131,81 @@ bool GLXGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeight
        glXMakeCurrent(x11disp, window, ctx);
        glEnable (GL_BLEND);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glClearColor(0.0, 1.0, 0.0, 1.0);
+       glClearColor(0.0, 0.0, 0.0, 1.0);
        glEnable(GL_TEXTURE_2D);
 
-       // decide on a binder to use
+       ITextureBinder * binder;
        const char *ext;
        ext = glXQueryExtensionsString(x11disp, 0);
-       if (!strstr(ext, "GLX_EXT_texture_from_pixmap")) {
-               LOG_ERROR("GLXGraphicsystem", "GLX_EXT_texture_from_pixmap not supported");
-               m_binder = new X11CopyGLX(x11disp);
-       }else{
-               GLXFBConfig pixmapConfig = ChoosePixmapFBConfig(x11disp);
-               m_binder = new X11TextureFromPixmap(x11disp,pixmapConfig);
+       if (!strstr(ext, "GLX_EXT_texture_from_pixmap"))
+       {
+               LOG_WARNING("GLXGraphicsystem", "GLX_EXT_texture_from_pixmap not supported! Fallback to copy!");
+               binder = new X11CopyGLX(x11disp);
        }
+       else
+       {
+               GLXFBConfig pixmapConfig = GLXGraphicsystem::ChoosePixmapFBConfig(x11disp);
+               binder = new X11TextureFromPixmap(x11disp,pixmapConfig);
+       }
+
+       setTextureBinder(binder);
 
-       LOG_DEBUG("GLXGraphicsystem", "Initialised opengl");
-       return true;
+       LOG_DEBUG("GLXGraphicsystem", "Initialised");
 }
 
 
-void GLXGraphicsystem::clearBackground(){
+void GLXGraphicsystem::clearBackground()
+{
        glClear(GL_COLOR_BUFFER_BIT);
 }
 
-void GLXGraphicsystem::swapBuffers(){
+void GLXGraphicsystem::swapBuffers()
+{
        glXSwapBuffers(x11disp, window);
-       // 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 GLXGraphicsystem::beginLayer(Layer* currentLayer)
+{
+       m_currentLayer = currentLayer;
+       // TODO layer destination / source
+}
+
+void GLXGraphicsystem::renderLayer()
+{
+       if ((m_currentLayer)->visibility && (m_currentLayer)->opacity > 0.0)
+       {
+               std::list<Surface*> surfaces = m_currentLayer->surfaces;
+               for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++)
+               {
+                       if ((*currentS)->visibility && (*currentS)->opacity>0.0f)
+                       {
+                               Surface* currentSurface = (Surface*)*currentS;
+                               m_baseWindowSystem->allocatePlatformSurface(currentSurface);
+                               renderSurface(currentSurface);
+                       }
+               }
        }
 }
 
- void GLXGraphicsystem::drawSurface(Layer* currentLayer, Surface* currentSurface){
+void GLXGraphicsystem::endLayer()
+{
+       m_currentLayer = NULL;
+}
+
+void GLXGraphicsystem::renderSurface(Surface* currentSurface)
+{
        m_binder->bindSurfaceTexture(currentSurface);
        glPushMatrix();
-       //   glRotated(-90*currentSurface->getOrientation(),0,0,1.0);
-       glColor4f(1.0f,1.0f,1.0f,currentSurface->opacity*(currentLayer)->opacity);
+       glColor4f(1.0f,1.0f,1.0f,currentSurface->opacity*(m_currentLayer)->opacity);
        glBegin(GL_QUADS);
        const Rectangle& src = currentSurface->getSourceRegion();
        const Rectangle& dest = currentSurface->getDestinationRegion();
+
+//     LOG_DEBUG("GLXGraphicsystem","rendersurface: src" << src.x << " " << src.y << " " << src.width << " " << src.height );
+//     LOG_DEBUG("GLXGraphicsystem","rendersurface: dest" << dest.x << " " << dest.y << " " << dest.width << " " << dest.height );
+//     LOG_DEBUG("GLXGraphicsystem","orig: " << currentSurface->OriginalSourceWidth << " " << currentSurface->OriginalSourceHeight  );
+//     LOG_DEBUG("GLXGraphicsystem","window" << windowWidth << " " << windowHeight  );
+
        //bottom left
        glTexCoord2d((float)src.x/currentSurface->OriginalSourceWidth, (float)(src.y+src.height)/currentSurface->OriginalSourceHeight);
        glVertex2d((float)dest.x/windowWidth*2-1,  1-(float)(dest.y+dest.height)/windowHeight*2);
@@ -184,32 +222,28 @@ void GLXGraphicsystem::swapBuffers(){
        glTexCoord2f((float)src.x/currentSurface->OriginalSourceWidth, (float)src.y/currentSurface->OriginalSourceHeight);
        glVertex2d((float)dest.x/windowWidth*2-1 ,  1-(float)dest.y/windowHeight*2);
        glEnd();
-       //glXReleaseTexImageEXT_func(dpy, nativeSurface->glxPixmap, GLX_FRONT_LEFT_EXT);
+
        m_binder->unbindSurfaceTexture(currentSurface);
        glPopMatrix();
 }
 
- void GLXGraphicsystem::saveScreenShot(){
-       {
-               LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << screenShotFile);
-
-               GLint viewport[4];
-               glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height
-
-               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 * 3 * sizeof(unsigned char));
-               glReadPixels(0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_BGR,GL_UNSIGNED_BYTE, buffer);
+void GLXGraphicsystem::saveScreenShotOfFramebuffer(std::string fileToSave)
+{
+       {
+               LOG_DEBUG("GLXGraphicsystem","taking screenshot and saving it to:" << fileToSave);
 
-               writeBitmap(screenShotFile,buffer,WINDOW_WIDTH,WINDOW_HEIGHT);
-               free(buffer);
-       }
+               GLint viewport[4];
+               glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height
 
- }
+               int WINDOW_WIDTH= viewport[2];
+               int WINDOW_HEIGHT= viewport[3];
+               LOG_DEBUG("GLXGraphicsystem","Screenshot: " << WINDOW_WIDTH << " * " << WINDOW_HEIGHT);
+               char *buffer = (char *)malloc(WINDOW_WIDTH * WINDOW_HEIGHT * 3 * sizeof(unsigned char));
+               glReadPixels(0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_BGR,GL_UNSIGNED_BYTE, buffer);
 
- void GLXGraphicsystem::doScreenShot(std::string fileToSave){
-        screenShotFile = fileToSave;
-        takescreenshot=true;
- }
+               writeBitmap(fileToSave,buffer,WINDOW_WIDTH,WINDOW_HEIGHT);
+               free(buffer);
+               LOG_DEBUG("GLXGraphicsystem","done taking screenshot");
+       }
+}
 
index 8f453ed..5a55eb7 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index a4481f9..655f611 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 4c3890f..6b2dd17 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 void X11CopyGLX::bindSurfaceTexture(Surface* surface){
        XPlatformSurface* nativeSurface = (XPlatformSurface*)surface->platform;
        Pixmap p = 0;
-       p= XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
+       GLenum targetType = GL_BGRA;
+       GLenum sourceType = GL_RGBA;
+
+       p = XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
        if (p==0)
+       {
                LOG_ERROR("X11CopyGLX", "didnt create pixmap!");
+               return;
+       }
        nativeSurface->pixmap = p;
        XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap);
-       glBindTexture(GL_TEXTURE_2D, nativeSurface->texture);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 320,240, 0, GL_RGBA, GL_UNSIGNED_BYTE, xim->data);
-        XDestroyImage(xim);
+       if ( xim != NULL )
+       {
+               glBindTexture(GL_TEXTURE_2D, nativeSurface->texture);
+               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+               if ( xim->depth == 24 )
+               {
+                       targetType = GL_BGR;
+                       sourceType = GL_RGB;
+               }
+               glTexImage2D(GL_TEXTURE_2D, 0, sourceType, surface->OriginalSourceWidth, surface->OriginalSourceHeight, 0, targetType, GL_UNSIGNED_BYTE, xim->data);
+               XDestroyImage(xim);
+       }
 }
 
 void X11CopyGLX::createClientBuffer(Surface*s){
index 58d8d7e..bb304f0 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,8 +25,9 @@
 #include "PlatformSurfaces/EglXPlatformSurface.h"
 #include "Log.h"
 
-       X11EglImage::X11EglImage(Display* x11display) : m_x11display(x11display){
-               LOG_INFO("X11EglImage", "Query EGL Extensions ...");
+       X11EglImage::X11EglImage(EGLDisplay eglDisplay, Display* x11display) : m_eglDisplay(eglDisplay), m_x11display(x11display){
+               // pseudo require EGL to have been initialised
+               // we dont really need the EGL handle as such
 
                m_pfGLEglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
                        eglGetProcAddress("glEGLImageTargetTexture2DOES");
                        LOG_ERROR("X11EglImage", "Query EGL Extensions failed");
                }
 
-               m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_x11display);
        }
        void X11EglImage::bindSurfaceTexture(Surface*s){
                EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)s->platform;
-               glBindTexture(GL_TEXTURE_2D, nativeSurface->texture);
-               if (nativeSurface->eglImage != NULL){
-                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
-                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
-                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-                       m_pfGLEglImageTargetTexture2DOES(GL_TEXTURE_2D, nativeSurface->eglImage);
+               if (NULL!=nativeSurface){
+                       glBindTexture(GL_TEXTURE_2D, nativeSurface->texture);
+                       if (nativeSurface->eglImage != NULL){
+                               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
+                               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
+                               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+                               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+                               m_pfGLEglImageTargetTexture2DOES(GL_TEXTURE_2D, nativeSurface->eglImage);
+                       }
                }
        }
 
        }
 
        void X11EglImage::createClientBuffer(Surface* surface){
-               LOG_DEBUG("X11EglImage", "creating client buffer");
+               LOG_DEBUG("X11EglImage", "creating client buffer with native display: " << m_x11display << " for native handle: " << surface->nativeHandle);
                EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)surface->platform;
-               Pixmap windowPixmap = 0;
-               windowPixmap= XCompositeNameWindowPixmap (m_x11display, surface->nativeHandle);
-               if (windowPixmap==0)
-                       LOG_ERROR("X11EglImage", "didnt create pixmap!");
+               if (NULL!=nativeSurface){
+                       Pixmap windowPixmap = 0;
+                       windowPixmap= XCompositeNameWindowPixmap (m_x11display, surface->nativeHandle);
+                       if (windowPixmap==0)
+                               LOG_ERROR("X11EglImage", "didnt create pixmap!");
 
-               EGLImageKHR eglImage = 0;
-               LOG_DEBUG("X11EglImage", "creating EGL Image from client buffer");
-               if (nativeSurface->eglImage != NULL)
-               {
-                       m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage);
-                       glDeleteTextures(1,&nativeSurface->texture);
-               }
-               eglImage = m_pfEglCreateImageKHR(m_eglDisplay,
-                                                                        EGL_NO_CONTEXT,
-                                                                        EGL_NATIVE_PIXMAP_KHR,
-                                                                        (EGLClientBuffer)windowPixmap,
-                                                                        NULL);
-               if (eglImage == 0)
-               {
-                       LOG_DEBUG("X11EglImage", "could not allocate EGL Image for window");
-               } else {
-                       nativeSurface->eglImage = eglImage;
-                       glGenTextures(1,&nativeSurface->texture);
+                       EGLImageKHR eglImage = 0;
+                       LOG_DEBUG("X11EglImage", "creating EGL Image from client buffer");
+                       if (nativeSurface->eglImage != NULL)
+                       {
+                               m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage);
+                               glDeleteTextures(1,&nativeSurface->texture);
+                       }
+                       eglImage = m_pfEglCreateImageKHR(m_eglDisplay,
+                                                                                EGL_NO_CONTEXT,
+                                                                                EGL_NATIVE_PIXMAP_KHR,
+                                                                                (EGLClientBuffer)windowPixmap,
+                                                                                NULL);
+                       if (eglImage == 0)
+                       {
+                               LOG_DEBUG("X11EglImage", "could not allocate EGL Image for window");
+                       } else {
+                               nativeSurface->eglImage = eglImage;
+                               glGenTextures(1,&nativeSurface->texture);
+                       }
                }
        }
 
                if (nativeSurface != NULL && nativeSurface->eglImage != NULL )
                {
                      m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage);
-                     glDeleteTextures(1,&nativeSurface->texture);
+                         glDeleteTextures(1,&nativeSurface->texture);
                }
-               glDeleteTextures(1,&nativeSurface->texture);
        }
index c988e6b..62bc8bb 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,32 +40,37 @@ const int X11TextureFromPixmap::pixmapAttribs[] = {
 
        void X11TextureFromPixmap::bindSurfaceTexture(Surface*s){
                GLXPlatformSurface* nativeSurface = (GLXPlatformSurface*)s->platform;
-               glXBindTexImageEXT_func(dpy, nativeSurface->glxPixmap, GLX_FRONT_LEFT_EXT, NULL);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+               if (NULL!=nativeSurface){
+                       glXBindTexImageEXT_func(dpy, nativeSurface->glxPixmap, GLX_FRONT_LEFT_EXT, NULL);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+               }
        }
        void X11TextureFromPixmap::unbindSurfaceTexture(Surface*s){
                GLXPlatformSurface* nativeSurface = (GLXPlatformSurface*)s->platform;
-               glXReleaseTexImageEXT_func(dpy, nativeSurface->glxPixmap, GLX_FRONT_LEFT_EXT);
+               if (NULL!=nativeSurface)
+                       glXReleaseTexImageEXT_func(dpy, nativeSurface->glxPixmap, GLX_FRONT_LEFT_EXT);
        }
 
        void X11TextureFromPixmap::createClientBuffer(Surface* surface){
                LOG_DEBUG("X11TextureFromPixmap", "creating clientBuffer for window: " << surface->nativeHandle);
                GLXPlatformSurface* platformSurface = (GLXPlatformSurface*)surface->platform;
-               Pixmap p = 0;
-               LOG_DEBUG("X11TextureFromPixmap", "get X Pixmap");
-               p= XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
-               if (p==0)
-                       LOG_ERROR("X11TextureFromPixmap", "didnt create pixmap!");
-               XSync(dpy, 0);
+               if (NULL!=platformSurface){
+                       Pixmap p = 0;
+                       LOG_DEBUG("X11TextureFromPixmap", "get X Pixmap");
+                       p= XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
+                       if (p==0)
+                               LOG_ERROR("X11TextureFromPixmap", "didnt create pixmap!");
+                       XSync(dpy, 0);
 
-               GLXPixmap pm = 0;
-               LOG_DEBUG("X11TextureFromPixmap", "creating glx pixmap from xpixmap");
-               pm = glXCreatePixmap(dpy, pixmapConfig, p, pixmapAttribs);
-               if (pm ==0)
-                       LOG_DEBUG("X11TextureFromPixmap", "could not allocate glxpixmap for window");
-               platformSurface->glxPixmap = pm;
-               platformSurface->pixmap = p;
+                       GLXPixmap pm = 0;
+                       LOG_DEBUG("X11TextureFromPixmap", "creating glx pixmap from xpixmap");
+                       pm = glXCreatePixmap(dpy, pixmapConfig, p, pixmapAttribs);
+                       if (pm ==0)
+                               LOG_DEBUG("X11TextureFromPixmap", "could not allocate glxpixmap for window");
+                       platformSurface->glxPixmap = pm;
+                       platformSurface->pixmap = p;
+               }
        }
 
        PlatformSurface* X11TextureFromPixmap::createPlatformSurface(Surface* s){
@@ -76,7 +81,7 @@ const int X11TextureFromPixmap::pixmapAttribs[] = {
                LOG_ERROR("X11TextureFromPixmap", "destroying clientBuffer");
                GLXPlatformSurface* platformSurface = (GLXPlatformSurface*)surface->platform;
                LOG_DEBUG("X11TextureFromPixmap", "removing GLX Pixmap");
-               if (platformSurface->glxPixmap){
+               if (NULL!=platformSurface){
                        //glXReleaseTexImageEXT_func(dpy, x11surf->glxPixmap, GLX_FRONT_LEFT_EXT);
                        glXDestroyPixmap(dpy,platformSurface->glxPixmap);
                        platformSurface->glxPixmap = 0;
@@ -84,7 +89,7 @@ const int X11TextureFromPixmap::pixmapAttribs[] = {
                XSync(dpy, 0);
 
                LOG_DEBUG("X11TextureFromPixmap", "removing X Pixmap");
-               if (platformSurface->pixmap){
+               if (NULL!=platformSurface){
                        XFreePixmap(dpy,platformSurface->pixmap);
                        platformSurface->pixmap = 0;
                }
index 7365e50..f159c86 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 #include <iomanip>
 
 
-int NullWindowSystem::windowWidth= 1280;
-
-
-int NullWindowSystem::windowHeight= 480;
-
-
-int NullWindowSystem::resolutionWidth= 1280;
-
-
-int NullWindowSystem::resolutionHeight= 480;
-
-
 bool NullWindowSystem::m_initialized= false;
 
 
index 1bc24ca..9c2e89a 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 
 int            X11WindowSystem::composite_opcode;
 const char X11WindowSystem::CompositorWindowTitle[] = "LayerManager";
-bool X11WindowSystem::m_success = false;
-bool X11WindowSystem::m_initialized = false;
 
-X11WindowSystem::X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem,GetVisualInfoFunction func) : BaseWindowSystem(layerlist, graphicSystem), getVisualFunc(func), windowWidth(1280), windowHeight(480),resolutionWidth(1280),resolutionHeight(480),debugMode(false){
+X11WindowSystem::X11WindowSystem(const char* displayname, int width, int height, LayerList* layerlist,GetVisualInfoFunction func) : BaseWindowSystem(layerlist), displayname(displayname), getVisualFunc(func), windowWidth(width), windowHeight(height),resolutionWidth(width),resolutionHeight(height),debugMode(false), m_initialized(false), m_success(false), takeScreenshot(ScreenShotNone){
                LOG_DEBUG("X11WindowSystem", "creating X11WindowSystem");
 
+               // init and take mutex, so windowsystem only does init phase until mutex is released again
+               pthread_mutex_init(&run_lock, NULL);
+               pthread_mutex_lock(&run_lock);
        };
 
 X11WindowSystem::~X11WindowSystem(){
-       delete graphicSystem;
 }
 
 XVisualInfo* X11WindowSystem::getDefaultVisual(Display *dpy)
@@ -55,24 +55,29 @@ XVisualInfo* X11WindowSystem::getDefaultVisual(Display *dpy)
                return windowVis;
        };
 
-void X11WindowSystem::OpenDisplayConnection(){
-       x11Display = XOpenDisplay(NULL);
+bool X11WindowSystem::OpenDisplayConnection(){
+       x11Display = XOpenDisplay(":0");
        if (!x11Display)
        {
                LOG_ERROR("X11WindowSystem", "Couldn't open default display!");
+               return false;
        }
+       LOG_DEBUG("X11WindowSystem", "Display connection: " << x11Display);
+       return true;
 }
 
-void X11WindowSystem::checkForCompositeExtension(){
+bool X11WindowSystem::checkForCompositeExtension(){
        if (!XQueryExtension (x11Display, COMPOSITE_NAME, &composite_opcode,
                                &composite_event, &composite_error))
        {
                LOG_ERROR("X11WindowSystem", "No composite extension");
+               return false;
        }
        XCompositeQueryVersion (x11Display, &composite_major, &composite_minor);
        LOG_DEBUG("X11WindowSystem", "Found composite extension: composite opcode: " << composite_opcode);
        LOG_DEBUG("X11WindowSystem", "composite_major: " << composite_major);
        LOG_DEBUG("X11WindowSystem", "composite_minor: " << composite_minor);
+       return true;
 }
 
 void X11WindowSystem::printDebug(int posx,int posy){
@@ -120,8 +125,8 @@ bool X11WindowSystem::isWindowValid(Window w){
 Surface* X11WindowSystem::getSurfaceForWindow(Window w){
        LOG_DEBUG("X11WindowSystem", "finding surface for window " << w);
        // go though all surfaces
-       const std::map<int,Surface*> surfaces = layerlist->getAllSurfaces();
-       for(std::map<int, Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
+       const std::map<unsigned int,Surface*> surfaces = layerlist->getAllSurfaces();
+       for(std::map<unsigned int, Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
                Surface* currentSurface = (*currentS).second;
                LOG_DEBUG("X11WindowSystem", "CurrentSurface surface for window " << currentSurface->getID());
                 LOG_DEBUG("X11WindowSystem", "CurrentSurface nativeHandle " << currentSurface->nativeHandle);
@@ -141,7 +146,6 @@ void X11WindowSystem::configureSurfaceWindow(Window w){
                LOG_DEBUG("X11WindowSystem", "Updating window " << w);
                UnMapWindow(w);
                MapWindow(w);
-               LOG_INFO("X11WindowSystem","after map 1");
                XWindowAttributes att;
                status = XGetWindowAttributes (x11Display, w, &att);
                int winWidth = att.width;
@@ -385,6 +389,13 @@ bool X11WindowSystem::CreateCompositorWindow()
                                0, windowVis->depth, InputOutput,
                                windowVis->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr);
 
+       //      Screen* s = ScreenOfDisplay( x11Display, 0 );
+       //      CompositorWindow = XCreateSimpleWindow( x11Display,
+       //                                                               RootWindowOfScreen(s),
+       //                                                               0, 0, windowWidth, windowHeight, 0,
+       //                                                               BlackPixelOfScreen(s),
+       //                                                               WhitePixelOfScreen(s) );
+       //
        if (!CompositorWindow)
        {
                LOG_ERROR("X11WindowSystem", "Could not create window");
@@ -406,6 +417,7 @@ bool X11WindowSystem::CreateCompositorWindow()
        XSetStandardProperties(x11Display, CompositorWindow, CompositorWindowTitle, CompositorWindowTitle,
                        None, (char **)NULL, 0, &sizehints);
        XMapRaised(x11Display, CompositorWindow);
+       XFlush(x11Display);
        return result;
 }
 
@@ -427,41 +439,65 @@ void CalculateFPS() {
                prevTime = TimeCounter; } }
 
 void
-X11WindowSystem::Redraw()
+X11WindowSystem::RedrawAllLayers()
 {
-       // 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++)
          {
                Layer* currentLayer = (Layer*)*current;
-               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++)
-                         {
-                                /*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");*/
-                                               // 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");*/
-                                  }
-                         }
-                 }
+               graphicSystem->beginLayer(currentLayer);
+               graphicSystem->renderLayer();
+               graphicSystem->endLayer();
          }
+}
+
+void
+X11WindowSystem::Redraw()
+{
+       // draw all the layers
+       graphicSystem->clearBackground();
+       /*LOG_INFO("X11WindowSystem","Locking List");*/
+       layerlist->lockList();
+
+       // check if we are supposed to take screenshot
+       if (takeScreenshot!=ScreenShotNone){
+               if (takeScreenshot==ScreenshotOfDisplay){
+               LOG_DEBUG("X11WindowSystem", "Taking screenshot");
+                       RedrawAllLayers();
+               }else if(takeScreenshot==ScreenshotOfLayer){
+                       LOG_DEBUG("X11WindowSystem", "Taking screenshot of layer");
+                       Layer* currentLayer = layerlist->getLayer(screenShotID);
+                       if (currentLayer!=NULL){
+                               graphicSystem->beginLayer(currentLayer);
+                               graphicSystem->renderLayer();
+                               graphicSystem->endLayer();
+                       }
+               }else if(takeScreenshot==ScreenshotOfSurface){
+                       LOG_DEBUG("X11WindowSystem", "Taking screenshot of surface");
+                       Surface* currentSurface = layerlist->getSurface(screenShotID);
+                       if (NULL!=currentSurface){
+                               Layer* l = layerlist->createLayer(GraphicalObject::INVALID_ID);
+                               l->setOpacity(1.0);
+                               l->setDestinationRegion(currentSurface->getDestinationRegion());
+                               l->setSourceRegion(currentSurface->getSourceRegion());
+                               graphicSystem->beginLayer(l);
+                               graphicSystem->renderSurface(currentSurface);
+                               graphicSystem->endLayer();
+                               layerlist->removeLayer(l);
+                               // layer is deleted in removeLayer.
+                       }else{
+                               LOG_ERROR("X11WindowSystem", "Could not take screenshot of non existing surface");
+                       }
+               }
+
+               graphicSystem->saveScreenShotOfFramebuffer(screenShotFile);
+//             graphicSystem->swapBuffers();
+               takeScreenshot = ScreenShotNone;
+               LOG_DEBUG("X11WindowSystem", "Done taking screenshot");
+       }
+
+       RedrawAllLayers();
+
        if (debugMode)
        {
                printDebug(200,windowHeight-40);
@@ -472,7 +508,7 @@ X11WindowSystem::Redraw()
        sprintf(floatStringBuffer, "FPS: %f", FPS);
        if ((Frame % 1000 ) == 0)
        {
-               LOG_INFO("X11WindowSystem",floatStringBuffer);
+               LOG_DEBUG("X11WindowSystem",floatStringBuffer);
        }
        layerlist->unlockList();
        /*LOG_INFO("X11WindowSystem","UnLocking List");*/
@@ -488,7 +524,7 @@ X11WindowSystem::error (Display *dpy, XErrorEvent *ev)
        if (ev->request_code == composite_opcode &&
                        ev->minor_code == X_CompositeRedirectWindow)
        {
-               LOG_ERROR("X11WindowSystem", "Another composite manager is already running!");
+               LOG_ERROR("X11WindowSystem", "Maybe another composite manager is already running");
        }
 
        if (name == NULL)
@@ -502,46 +538,6 @@ X11WindowSystem::error (Display *dpy, XErrorEvent *ev)
        return 0;
 }
 
-//void X11WindowSystem::setDisplayMode(){
-//     XF86VidModeModeInfo **modes;
-//     int modeNum;
-//     int bestMode = -1;
-//     LOG_DEBUG("X11WindowSystem", "trying for fullscreen mode " << resolutionWidth << "  " << resolutionHeight);
-//     XF86VidModeGetAllModeLines(x11Display, 0, &modeNum, &modes);
-//     LOG_DEBUG("X11WindowSystem", "found " << modeNum << " modes");
-//     /* look for mode with requested resolution */
-//     for (int i = 0; i < modeNum; i++)
-//             if ((modes[i]->hdisplay == resolutionWidth) && (modes[i]->vdisplay == resolutionHeight))
-//                     bestMode = i;
-//     if (bestMode==-1){
-//             int bestHeight = 0;
-//             for (int i = 0; i < modeNum; i++)
-//                     if (modes[i]->hdisplay == resolutionWidth && modes[i]->vdisplay >= bestHeight){
-//                             bestMode = i;
-//                             bestHeight = modes[i]->vdisplay;
-//                     }
-//     }
-//     if (bestMode>=0){
-//             LOG_DEBUG("X11WindowSystem", "changing mode to "<< modes[bestMode]->hdisplay << "  " << modes[bestMode]->vdisplay );
-//             XF86VidModeSwitchToMode(x11Display, 0, modes[bestMode]);
-//             XF86VidModeSetViewPort(x11Display, 0, 0, 0);
-//
-//     }else{
-//             LOG_ERROR("X11WindowSystem", "could not find appropriate mode!");
-//             // take last mode, its probably the highest resolution
-//             resolutionWidth = modes[modeNum-1]->hdisplay;
-//             resolutionHeight = modes[modeNum-1]->vdisplay;
-//             windowWidth = resolutionWidth;
-//             if (windowHeight>resolutionHeight)
-//                     windowHeight = resolutionHeight;
-//             XF86VidModeSwitchToMode(x11Display, 0, modes[modeNum-1]);
-//             XF86VidModeSetViewPort(x11Display, 0, 0, 0);
-//     }
-//     LOG_DEBUG("X11WindowSystem", "Set the mode");
-//     LOG_DEBUG("X11WindowSystem", "mode: " << resolutionWidth << "x" << resolutionHeight);
-//     LOG_DEBUG("X11WindowSystem", "renderwindow: " << windowWidth << "x" << windowHeight);
-//}
-
 bool X11WindowSystem::initXServer()
 {
        LOG_DEBUG("X11WindowSystem", "Initialising XServer connection");
@@ -556,72 +552,53 @@ bool X11WindowSystem::initXServer()
 
        LOG_DEBUG("X11WindowSystem", "Compositor Window ID: " << CompositorWindow);
 
-       //      LOG_DEBUG("X11WindowSystem", "Allocate Pixmaps for all the offscreen windows");
        CreatePixmapsForAllWindows();
-       //      LOG_DEBUG("X11WindowSystem", "Allocated Pixmaps");
-
        //unredirect our window
 #ifdef FULLSCREEN
        XCompositeUnredirectWindow(x11Display,background,CompositeRedirectManual);
 #endif
        XCompositeUnredirectWindow(x11Display,CompositorWindow,CompositeRedirectManual);
 
-       //unredirect special windows if present
-       /*XGrabServer (x11Display);
-       unsigned int numberOfWindows = 0;
-       Window *children = getListOfAllTopLevelWindows(x11Display,&numberOfWindows);
-       LOG_DEBUG("X11WindowSystem", "unredirecting special windows");
-       for (unsigned int i=0;i<numberOfWindows;i++){
-               Window w = (Window) children[i];
-               char* name;
-               int status = XFetchName(x11Display, w, &name);
-               if (status >= Success)
-               {
-                       char GuiTitle[]  = "Layermanager Remote GUI\0";
-                       char DFEETTITLE[] = "D-Feet D-Bus debugger\0";
-                       if (name != NULL && (strcmp(name,GuiTitle)==0 || strcmp(name,DFEETTITLE)==0 ) ){
-                               LOG_DEBUG("X11WindowSystem", "Found gui window: repositioning it");
-                               XCompositeUnredirectWindow(x11Display,w,CompositeRedirectManual);
-                               XCompositeUnredirectSubwindows(x11Display,w,CompositeRedirectAutomatic);
-                               XMoveWindow(x11Display, w, 50,  500);
-                               XMapRaised(x11Display, w);
-                       }
-               }
-               XFree(name);
-       }
-       XFree(children);
-       XUngrabServer (x11Display);
-       XSync(x11Display, 0);
-*/
        LOG_DEBUG("X11WindowSystem", "Initialised XServer connection");
        return result;
 }
 
 void* X11WindowSystem::EventLoop(void * ptr)
 {
+       // INITALIZATION
        LOG_DEBUG("X11WindowSystem", "Enter thread");
-       X11WindowSystem *windowsys = (X11WindowSystem *) ptr;
 
+       bool status = true;
+
+       X11WindowSystem *windowsys = (X11WindowSystem *) ptr;
+       XSetErrorHandler(error);
        // init own stuff
-       m_success = false;
+       LOG_DEBUG("X11WindowSystem", "open display connection");
+       status &= windowsys->OpenDisplayConnection();
+
+       LOG_DEBUG("X11WindowSystem", "check for composite extension");
+       status &= windowsys->checkForCompositeExtension();
+
+       LOG_DEBUG("X11WindowSystem", "init xserver");
+       status &= windowsys->initXServer();
 
-       windowsys->OpenDisplayConnection();
-       windowsys->checkForCompositeExtension();
-       windowsys->initXServer();
+       status &= windowsys->graphicSystem->init(windowsys->x11Display,windowsys->CompositorWindow);
 
-       // then init graphiclib
-       m_success = windowsys->graphicSystem->init(&windowsys->x11Display,&windowsys->CompositorWindow,windowsys->windowHeight,windowsys->windowWidth);
-       m_initialized = true;
+       windowsys->m_success = status;
+       windowsys->m_initialized = true;
 
+       // Done with init, wait for lock to actually run (ie start/stop method called)
+       pthread_mutex_lock(&windowsys->run_lock);
+
+       LOG_DEBUG("X11WindowSystem", "Starting Event loop");
        Layer* defaultLayer;
 
        // run the main event loop while rendering
-       windowsys->m_running = m_success;
        gettimeofday(&tv0, NULL);
        FramesPerFPS = 30;
        if (windowsys->debugMode)
        {
-               defaultLayer = windowsys->layerlist->createLayer(-1);
+               defaultLayer = windowsys->layerlist->createLayer(0);
                defaultLayer->setOpacity(1.0);
                defaultLayer->setDestinationRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
                defaultLayer->setSourceRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
@@ -639,7 +616,7 @@ void* X11WindowSystem::EventLoop(void * ptr)
                                if (windowsys->debugMode)
                                {
                                        LOG_DEBUG("X11WindowSystem", "CreateNotify Event");
-                                       Surface* s = windowsys->layerlist->createSurface(-1);
+                                       Surface* s = windowsys->layerlist->createSurface(0);
                                        s->setOpacity(1.0);
                                        windowsys->NewWindow(s, event.xcreatewindow.window);
                                        defaultLayer->addSurface(s);
@@ -696,33 +673,68 @@ void X11WindowSystem::cleanup(){
        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");
+bool X11WindowSystem::init(BaseGraphicSystem<Display*,Window>* base){
        X11WindowSystem *renderer = this;
-       resolutionWidth = displayWidth;
-       resolutionHeight = displayHeight;
+       graphicSystem = base;
        int status = pthread_create( &renderThread, NULL, X11WindowSystem::EventLoop, (void*) renderer);
        if (0 != status )
        {
                return false;
        }
+
        while ( m_initialized == false )
        {
-               usleep(50000);
+               usleep(10000);
                LOG_INFO("X11WindowSystem","Waiting start complete " << m_initialized);
        }
        LOG_INFO("X11WindowSystem","Start complete " << m_initialized << " success " << m_success);
        return m_success;
 }
 
+bool X11WindowSystem::start(){
+       LOG_INFO("X11WindowSystem", "Starting / Creating thread");
+       // let thread actually run
+       this->m_running = true;
+       pthread_mutex_unlock(&run_lock);
+       return true;
+}
+
 void X11WindowSystem::stop(){
        LOG_INFO("X11WindowSystem","Stopping..");
        this->m_running = false;
+       // needed if start was never called, we wake up thread, so it can immediatly finish
+       pthread_mutex_unlock(&run_lock);
        pthread_join(renderThread,NULL);
 }
 
+void X11WindowSystem::allocatePlatformSurface(Surface* surface)
+{
+       XPlatformSurface* nativeSurface = (XPlatformSurface*)surface->platform;
+       if (NULL == nativeSurface)
+       {
+               /*LOG_INFO("X11WindowSystem","creating native surface for new window");*/
+               // this surface does not have a native platform surface attached yet!
+               NewWindow(surface,surface->nativeHandle);
+               MapWindow(surface->nativeHandle);
+       }
+}
+
+void X11WindowSystem::doScreenShot(std::string fileName){
+       takeScreenshot = ScreenshotOfDisplay;
+       screenShotFile = fileName;
+}
+
+void X11WindowSystem::doScreenShotOfLayer(std::string fileName, const uint id){
+       takeScreenshot = ScreenshotOfLayer;
+       screenShotFile = fileName;
+       screenShotID = id;
+}
+
+void X11WindowSystem::doScreenShotOfSurface(std::string fileName, const uint id){
+       takeScreenshot = ScreenshotOfSurface;
+       screenShotFile = fileName;
+       screenShotID = id;
+}
index 85d65f5..9b73959 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 5841289..0efb003 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 58163fb..2a75430 100644 (file)
@@ -1,6 +1,6 @@
 ############################################################################
 # 
-# Copyright 2010 BMW Car IT GmbH  
+# Copyright 2010, 2011 BMW Car IT GmbH
 # 
 # 
 # Licensed under the Apache License, Version 2.0 (the "License"); 
index fa75b92..6e009bb 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 2b6475c..4dc0b12 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 6e0508e..ffb7c7f 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 655eb19..4f02424 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 0550f2c..46848c4 100644 (file)
 
 #include "LayerList.h"
 #include "BaseRenderer.h"
-#include "GraphicSystems/BaseGraphicSystem.h"
+#include "GraphicSystems/GLXGraphicsystem.h"
+#include "WindowSystems/X11WindowSystem.h"
 
 class X11GLXRenderer : public BaseRenderer {
 public:
        X11GLXRenderer(LayerList* layerlist);
        virtual ~X11GLXRenderer();
        void doScreenShot(std::string fileToSave);
+       void doScreenShotOfLayer(std::string fileToSave, uint id);
+       void doScreenShotOfSurface(std::string fileToSave, uint id);
+       uint getNumberOfHardwareLayers(uint screenID);
+       uint* getScreenResolution(uint screenID);
+       uint* getScreenIDs(uint* length);
+       bool start(int, int, const char*);
+       void stop();
 private:
-       BaseGraphicSystem* graphicSys;
+       X11WindowSystem*  m_windowSystem;
+       GLXGraphicsystem* m_graphicSystem;
+       uint m_width;
+       uint m_height;
 };
 
 #endif /* X11GLXRENDERER_H_ */
index 72bfc65..e0f5645 100644 (file)
 #include "GraphicSystems/GLXGraphicsystem.h"
 #include "WindowSystems/X11WindowSystem.h"
 #include "Log.h"
+#include <string.h>
 
-X11GLXRenderer::X11GLXRenderer(LayerList* layerlist) : BaseRenderer(layerlist), graphicSys(NULL){
-       LOG_DEBUG("X11GLXRenderer", "creating X11GLXRenderer");
-       graphicSys = new GLXGraphicsystem();
-       m_windowSystem = new X11WindowSystem(layerlist, graphicSys, GLXGraphicsystem::ChooseWindowVisual);
+X11GLXRenderer::X11GLXRenderer(LayerList* layerlist) : BaseRenderer(layerlist){
 };
 
+bool X11GLXRenderer::start(int width, int height, const char* displayname){
+       LOG_DEBUG("X11GLXRenderer", "creating X11GLXRenderer");
+       m_width = width;
+       m_height = height;
+
+       // create X11 windows, register as composite manager etc
+       m_windowSystem  = new X11WindowSystem(displayname, width, height, m_layerlist, GLXGraphicsystem::ChooseWindowVisual);
+       m_graphicSystem = new GLXGraphicsystem(width, height);
+       m_graphicSystem->setBaseWindowSystem(m_windowSystem);
+
+       LOG_DEBUG("X11GLXRenderer", "init windowsystem");
+       m_windowSystem->init(m_graphicSystem );
+
+       Display* x11Display = m_windowSystem->getNativeDisplayHandle();
+       if (NULL==x11Display)
+               LOG_ERROR("GLXGraphicsystem", "Display from windowsystem is null");
+
+       m_windowSystem->start();
+}
+
+void X11GLXRenderer::stop(){
+       m_windowSystem->stop();
+}
+
 X11GLXRenderer::~X11GLXRenderer() {
        delete m_windowSystem;
 };
 
 void X11GLXRenderer::doScreenShot(std::string fileToSave){
-       graphicSys->doScreenShot(fileToSave);
+       m_windowSystem->doScreenShot(fileToSave);
+}
+
+void X11GLXRenderer::doScreenShotOfLayer(std::string fileToSave,uint id){
+       m_windowSystem->doScreenShotOfLayer(fileToSave,id);
+}
+
+void X11GLXRenderer::doScreenShotOfSurface(std::string fileToSave, uint id){
+       m_windowSystem->doScreenShotOfSurface(fileToSave,id);
+}
+
+uint X11GLXRenderer::getNumberOfHardwareLayers(uint screenID){
+       return 0;
+       // TODO
+}
+
+uint* X11GLXRenderer::getScreenResolution(uint screenID){
+       uint * resolution = new uint[2];
+       resolution[0] = m_width;
+       resolution[1] = m_height;
+       return resolution;
+}
+
+uint* X11GLXRenderer::getScreenIDs(uint* length){
+       Display* x11Display = m_windowSystem->getNativeDisplayHandle();
+       if (!x11Display)
+               return NULL;
+       // Screens in X11 can be addresses/accessed by just the number - we must only know how many there are
+       uint numberOfScreens = ScreenCount(x11Display);
+       uint* screenIDS = new uint[numberOfScreens];
+       for (int i = 0;i<numberOfScreens;i++){
+               screenIDS[i] = i;
+       }
+       *length = numberOfScreens;
+       return screenIDS;
 }
 
-extern "C" IRenderer* createX11Renderer(LayerList* layerlist) {
+extern "C" IRenderer* createX11GLXRenderer(LayerList* layerlist) {
        return new X11GLXRenderer(layerlist);
 }
 
-extern "C" void destroyX11Renderer(X11GLXRenderer* p) {
+extern "C" void destroyX11GLXRenderer(X11GLXRenderer* p) {
        delete p;
 }
index e819dea..f47bfc4 100644 (file)
 #include "BaseRenderer.h"
 #include "LayerList.h"
 #include "GraphicSystems/GLESGraphicSystem.h"
+#include "WindowSystems/X11WindowSystem.h"
 
 class X11GLESRenderer : public BaseRenderer
 {
 public:
        X11GLESRenderer(LayerList* layerlist);
+       bool start(int, int, const char*);
+       void stop();
        void doScreenShot(std::string fileToSave);
+       void doScreenShotOfLayer(std::string fileToSave, uint id);
+       void doScreenShotOfSurface(std::string fileToSave, uint id);
+       uint getNumberOfHardwareLayers(uint screenID);
+       uint* getScreenResolution(uint screenID);
+       uint* getScreenIDs(uint* length);
+
 private:
-       BaseGraphicSystem* graphicSystem;
+       X11WindowSystem* m_windowSystem;
+       GLESGraphicsystem* m_graphicSystem;
+       uint m_width;
+       uint m_height;
 };
 
 #endif /* _X11GLESRENDERER_H_*/
index 67d73f1..57f2eff 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 3a85ba7..d958392 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index d6cee2e..603242e 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index 7b2d540..b6fae4f 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
 *
-* Copyright 2010 BMW Car IT GmbH
+* Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
index af33cfa..c189691 100644 (file)
@@ -30,7 +30,10 @@ ShaderProgram* ShaderProgramGLES::createProgram(const std::string& vertName, con
        if (vertName=="default" && fragName=="default")
        {
                // load default shader from binary data
-               progHandle = RenderUtilLoadShaderSources("renderer_vert.glslv", "renderer_frag.glslf", GL_TRUE);
+               progHandle = RenderUtilLoadShaderSources("/usr/lib/layermanager/renderer/renderer_vert.glslv", "/usr/lib/layermanager/renderer/renderer_frag.glslf", GL_TRUE);
+               if (progHandle==0){
+                       progHandle = RenderUtilLoadShaderSources("/usr/local/lib/layermanager/renderer/renderer_vert.glslv", "/usr/local/lib/layermanager/renderer/renderer_frag.glslf", GL_TRUE);
+               }
        }
        else
        {
index 9da7afa..f0bfb1f 100644 (file)
 
 #include "X11GLESRenderer.h"
 #include "ShaderProgramGLES.h"
-#include "WindowSystems/X11WindowSystem.h"
 #include "X11/Xlib.h"
 #include "TextureBinders/X11CopyGLES.h"
 #include "TextureBinders/X11EglImage.h"
 
-X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist), graphicSystem(NULL)
+X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist)
 {
        LOG_DEBUG("X11GLESRenderer", "Creating Renderer");
 
-       // if no binder has been set yet
-       Display* display = XOpenDisplay(0);
-       EGLDisplay m_eglDisplay = eglGetDisplay(display);
-       ITextureBinder* binder=NULL;
-       const char* query = eglQueryString(m_eglDisplay, EGL_EXTENSIONS);
-       LOG_DEBUG("X11GLESRenderer", "EGL_EXTENSIONS: " << query);
+};
+
+bool X11GLESRenderer::start(int width, int height, const char* displayname){
+       m_width = width;
+       m_height = height;
+       // create X11 windows, register as composite manager etc
+       m_windowSystem = new X11WindowSystem(displayname, width, height, m_layerlist);
+       m_graphicSystem = new GLESGraphicsystem(width,height, ShaderProgramGLES::createProgram);
+
+       m_windowSystem->init(m_graphicSystem);
+       m_graphicSystem->setBaseWindowSystem(m_windowSystem);
+
+       // create graphic context from window, init egl etc
+       Display* nativeDisplayHandle = m_windowSystem->getNativeDisplayHandle();
+
+       LOG_DEBUG("X11GLESRenderer", "Got nativedisplay handle: " << nativeDisplayHandle << " from windowsystem");
+
+       EGLDisplay eglDisplayhandle = m_graphicSystem->getEGLDisplay();
+
        #ifdef EGL_NATIVE_PIXMAP_KHR
-                       binder = new X11EglImage((Display*)display);
+                       ITextureBinder* binder = new X11EglImage(eglDisplayhandle, nativeDisplayHandle);
        #else
-                       binder = new X11CopyGLES((Display*)display);
+                       ITextureBinder* binder = new X11CopyGLES(eglDisplayhandle, nativeDisplayHandle);
        #endif
+       m_graphicSystem->setTextureBinder(binder);
 
-       graphicSystem = new GLESGraphicsystem( ShaderProgramGLES::createProgram, binder);
-       m_windowSystem = new X11WindowSystem(layerlist, graphicSystem);
-};
+       m_windowSystem->start();
+}
+
+void X11GLESRenderer::stop(){
+       m_windowSystem->stop();
+}
 
 void X11GLESRenderer::doScreenShot(std::string fileToSave){
-       graphicSystem->doScreenShot(fileToSave);
+       m_windowSystem->doScreenShot(fileToSave);
+}
+
+void X11GLESRenderer::doScreenShotOfLayer(std::string fileToSave,uint id){
+       m_windowSystem->doScreenShotOfLayer(fileToSave,id);
+}
+
+void X11GLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id){
+       m_windowSystem->doScreenShotOfSurface(fileToSave,id);
+}
+
+uint X11GLESRenderer::getNumberOfHardwareLayers(uint screenID){
+       return 0;
+       // TODO
+}
+
+uint* X11GLESRenderer::getScreenResolution(uint screenID){
+       uint * resolution = new uint[2];
+       resolution[0] = m_width;
+       resolution[1] = m_height;
+       return resolution;
+}
+
+uint* X11GLESRenderer::getScreenIDs(uint* length){
+       Display* x11Display = m_windowSystem->getNativeDisplayHandle();
+       if (!x11Display)
+               return NULL;
+       // Screens in X11 can be addresses/accessed by just the number - we must only know how many there are
+       uint numberOfScreens = ScreenCount(x11Display);
+       uint* screenIDS = new uint[numberOfScreens];
+       for (int i = 0;i<numberOfScreens;i++){
+               screenIDS[i] = i;
+       }
+       *length = numberOfScreens;
+       return screenIDS;
 }
 
 extern "C" BaseRenderer* createX11GLESRenderer(LayerList* layerlist){