summaryrefslogtreecommitdiff
path: root/LayerManagerPlugins
diff options
context:
space:
mode:
authorMichael Schuldt <michael.schuldt@bmw-carit.de>2011-06-30 12:55:39 +0200
committerMichael Schuldt <michael.schuldt@bmw-carit.de>2011-06-30 14:11:06 +0200
commit7fbf57604efe92e9450cbcdc5f9b686f713bd760 (patch)
treeacb0d175a07735f7bd4b5e4e7e9404dd3d8df142 /LayerManagerPlugins
parent22018606ad5573571ac2d5929f225eaac25860b7 (diff)
parentd11cfb71dc0da60eedfa35df926e0b5b6f4128fc (diff)
downloadlayer_management-7fbf57604efe92e9450cbcdc5f9b686f713bd760.tar.gz
Merging patches from NVIDIA an CARIT
Diffstat (limited to 'LayerManagerPlugins')
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h2
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h1
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp7
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp45
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp44
-rw-r--r--LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp86
6 files changed, 116 insertions, 69 deletions
diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h
index f0016f0..816a015 100644
--- a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h
+++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h
@@ -35,7 +35,7 @@ public:
// pseudo require EGL to have been initialised
// we dont really need the handle
};
- void swapPixmap(unsigned char* src,unsigned char* dest,unsigned int width,unsigned int height,bool swaprgb);
+ void swapPixmap(unsigned char* src,unsigned char* dest,unsigned int width,unsigned int height,bool swaprgb,bool includeAlpha);
bool bindSurfaceTexture(Surface* surface);
void createClientBuffer(Surface* surface);
void destroyClientBuffer(Surface* surface);
diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
index 2f06889..c46767a 100644
--- a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
+++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
@@ -115,6 +115,7 @@ private:
static void* EventLoop(void * ptr);
static int error(Display *dpy, XErrorEvent *ev);
bool redrawEvent;
+ static bool m_xerror;
};
#endif /* _X11WINDOWSYSTEM_H_ */
diff --git a/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp
index e983f03..d25135f 100644
--- a/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp
+++ b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp
@@ -200,7 +200,8 @@ void GLESGraphicsystem::renderLayer()
if ((*currentS)->visibility && (*currentS)->opacity>0.0f)
{
Surface* currentSurface = (Surface*)*currentS;
- renderSurface(currentSurface);
+ m_baseWindowSystem->allocatePlatformSurface(currentSurface);
+ renderSurface(currentSurface);
}
}
}
@@ -329,8 +330,10 @@ void GLESGraphicsystem::renderSurface(Surface* surface)
glActiveTexture(GL_TEXTURE0);
if (false == m_binder->bindSurfaceTexture(surface))
{
- /* skip render surface if not bind successfully */
+// LOG_DEBUG("GLESGraphicsystem", "renderSurface not successfully bind " << surface->getID());
return;
+ } else {
+// LOG_DEBUG("GLESGraphicsystem", "renderSurface " << surface->getID());
}
/* rotated positions are saved sequentially in vbo
diff --git a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp
index 0454896..7d86e5c 100644
--- a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp
+++ b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp
@@ -32,11 +32,12 @@ bool X11CopyGLES::bindSurfaceTexture(Surface* surface)
GLenum sourceType = GL_RGBA;
unsigned char* swapedData = NULL;
bool swaprgb = false;
+ bool includeAlpha = false;
if (surface != NULL )
{
nativeSurface = (XPlatformSurface*)surface->platform;
}
- else if( nativeSurface != NULL && surface->nativeHandle != 0 )
+ if( nativeSurface != NULL && surface->nativeHandle != 0 )
{
pixmap = XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
if (!pixmap)
@@ -51,25 +52,40 @@ bool X11CopyGLES::bindSurfaceTexture(Surface* surface)
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 )
+ if ( surface->getPixelFormat() == PIXELFORMAT_RGB888)
{
targetType = GL_RGB;
sourceType = GL_RGB;
- swaprgb = true;
+ swaprgb = true;
swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*3];
- } else {
- swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*4];
- }
- swapPixmap((unsigned char*)xim->data, swapedData, surface->OriginalSourceWidth, surface->OriginalSourceHeight,swaprgb);
+ }
+ else if ( surface->getPixelFormat() == PIXELFORMAT_RGBA8888)
+ {
+ if (xim->depth == 24)
+ {
+ includeAlpha = true;
+ }
+ swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*4];
+ }
+ else
+ {
+ LOG_ERROR("X11CopyGLES","Pixelformat currently not supported : " << surface->getPixelFormat());
+ XDestroyImage(xim);
+ return false;
+ }
+ swapPixmap((unsigned char*)xim->data, swapedData, surface->OriginalSourceWidth, surface->OriginalSourceHeight,swaprgb,includeAlpha);
glTexImage2D(GL_TEXTURE_2D, 0, sourceType, surface->OriginalSourceWidth, surface->OriginalSourceHeight, 0, targetType, GL_UNSIGNED_BYTE, swapedData);
XDestroyImage(xim);
delete[] swapedData;
return true;
- }
- }
+ } else {
+ LOG_ERROR("X11CopyGLES", "X image data empty");
+ return false;
+ }
+ }
return false;
}
-void X11CopyGLES::swapPixmap(unsigned char* src,unsigned char* dest, unsigned int width,unsigned int height,bool swaprgb)
+void X11CopyGLES::swapPixmap(unsigned char* src,unsigned char* dest, unsigned int width,unsigned int height,bool swaprgb,bool includeAlpha)
{
unsigned int count = 0;
if (swaprgb == false)
@@ -79,10 +95,14 @@ void X11CopyGLES::swapPixmap(unsigned char* src,unsigned char* dest, unsigned in
dest[j*4]=src[j*4+2];
dest[j*4+1]=src[j*4+1];
dest[j*4+2]=src[j*4];
- dest[j*4+3]=src[j*4+3];
+ dest[j*4+3]=src[j*4+3];
+ if (includeAlpha)
+ {
+ dest[j*4+3]=255;
+ }
}
} else {
- count = width*height;
+ count = width*height;
for (int j=0;j<count; j++)
{
dest[j*3]=src[j*3+2];
@@ -105,5 +125,6 @@ void X11CopyGLES::destroyClientBuffer(Surface* surface)
{
glDeleteTextures(1,&nativeSurface->texture);
XFreePixmap(dpy, nativeSurface->pixmap);
+ nativeSurface->pixmap = NULL;
}
}
diff --git a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp
index 7e4b5f2..e785f64 100644
--- a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp
+++ b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp
@@ -30,29 +30,35 @@ bool X11CopyGLX::bindSurfaceTexture(Surface* surface)
Pixmap pixmap = 0;
GLenum targetType = GL_BGRA;
GLenum sourceType = GL_RGBA;
-
- pixmap = XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
- if (!pixmap)
+ if (surface != NULL )
{
- LOG_ERROR("X11CopyGLX", "didnt create pixmap!");
- return false;
- }
-
- nativeSurface->pixmap = pixmap;
- XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap);
- if (xim)
+ nativeSurface = (XPlatformSurface*)surface->platform;
+ }
+ if( nativeSurface != NULL && surface->nativeHandle != 0 )
{
- 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)
+ pixmap = XCompositeNameWindowPixmap (dpy, surface->nativeHandle);
+ if (!pixmap)
+ {
+ LOG_ERROR("X11CopyGLX", "didnt create pixmap!");
+ return false;
+ }
+
+ nativeSurface->pixmap = pixmap;
+ XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap);
+ if (xim)
{
- targetType = GL_BGR;
- sourceType = GL_RGB;
+ 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);
+ return true;
}
- glTexImage2D(GL_TEXTURE_2D, 0, sourceType, surface->OriginalSourceWidth, surface->OriginalSourceHeight, 0, targetType, GL_UNSIGNED_BYTE, xim->data);
- XDestroyImage(xim);
- return true;
}
return false;
}
diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
index 025d0f6..b474d16 100644
--- a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
+++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
@@ -22,6 +22,9 @@
#include "Layer.h"
#include <time.h>
#include <sys/time.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
#include <stdio.h>
@@ -30,9 +33,10 @@
#include <unistd.h>
#include <iomanip>
-int X11WindowSystem::composite_opcode;
+int X11WindowSystem::composite_opcode;
int X11WindowSystem::damage_opcode;
const char X11WindowSystem::CompositorWindowTitle[] = "LayerManager";
+bool X11WindowSystem::m_xerror = false;
X11WindowSystem::X11WindowSystem(const char* displayname, int width, int height, Scene* pScene,GetVisualInfoFunction func)
: BaseWindowSystem(pScene)
@@ -185,12 +189,14 @@ Surface* X11WindowSystem::getSurfaceForWindow(Window w)
void X11WindowSystem::checkForNewSurface()
{
+ m_pScene->lockScene();
const std::map<unsigned int,Surface*> surfaces = m_pScene->getAllSurfaces();
for(std::map<unsigned int, Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++)
{
Surface* currentSurface = (*currentS).second;
allocatePlatformSurface(currentSurface);
}
+ m_pScene->unlockScene();
}
void X11WindowSystem::configureSurfaceWindow(Window window)
@@ -234,6 +240,9 @@ void X11WindowSystem::MapWindow(Window window)
{
XWindowAttributes att;
XGetWindowAttributes (x11Display, window, &att);
+/* LOG_DEBUG("X11WindowSystem", "XCompositeRedirectWindow()");
+ XCompositeRedirectWindow(x11Display, window, CompositeRedirectManual);
+ XSync(x11Display, 0);*/
if (att.map_state == IsViewable && att.override_redirect==0)
{
LOG_DEBUG("X11WindowSystem", "Mapping window " << window);
@@ -323,10 +332,10 @@ void X11WindowSystem::UnMapWindow(Window window)
LOG_DEBUG("X11WindowSystem", "XFreePixmap() returned " << result);
}
- LOG_DEBUG("X11WindowSystem", "XCompositeUnredirectWindow()");
+/* LOG_DEBUG("X11WindowSystem", "XCompositeUnredirectWindow()");
XCompositeUnredirectWindow(x11Display, window, CompositeRedirectManual);
- XSync(x11Display, 0);
+ XSync(x11Display, 0);*/
}
LOG_DEBUG("X11WindowSystem", "Unmap finished");
}
@@ -416,23 +425,8 @@ bool X11WindowSystem::CreatePixmapsForAllWindows()
bool result = true;
LOG_DEBUG("X11WindowSystem", "redirecting all windows");
Window root = RootWindow(x11Display, 0);
-// XGrabServer (x11Display);
-// unsigned int numberOfWindows = 0;
-// Window *children = getListOfAllTopLevelWindows(x11Display,&numberOfWindows);
-
-// LOG_DEBUG("X11WindowSystem", "Found " << numberOfWindows << " windows");
XCompositeRedirectSubwindows(x11Display,root,CompositeRedirectManual);
-
-/* for (unsigned int i=0;i< (numberOfWindows-1);i++)
- {
- Window w = (Window) children[i];
- NewWindow(w);
- MapWindow(w);
- } */
-// XFree(children);
-// XUngrabServer (x11Display);
-// XSync(x11Display, 0);
-
+ XSync(x11Display,0);
return result;
}
@@ -440,7 +434,7 @@ bool X11WindowSystem::CreateCompositorWindow()
{
LOG_DEBUG("X11WindowSystem", "Get root window");
bool result = true;
- Window root = XDefaultRootWindow(x11Display);
+ Window root = RootWindow(x11Display,0);
LOG_DEBUG("X11WindowSystem", "Get default screen");
// draw a black background the full size of the resolution
@@ -458,9 +452,15 @@ bool X11WindowSystem::CreateCompositorWindow()
attr.border_pixel = 0;
windowVis = getVisualFunc(x11Display);
attr.colormap = XCreateColormap(x11Display, root, windowVis->visual, AllocNone);
-
attr.override_redirect = True;
+ Window compManager = XGetSelectionOwner(x11Display,XInternAtom(x11Display,"_NET_WM_CM_S0",0));
+ if ( 0 != compManager )
+ {
+ LOG_ERROR("X11WindowSystem", "Could not create compositor window, annother compisite manager is already running");
+ return false;
+ }
+
// Window overlaywindow = XCompositeGetOverlayWindow(x11Display,root);
CompositorWindow = XCreateWindow(x11Display, root, 0, 0, windowWidth, windowHeight,
@@ -528,8 +528,6 @@ void CalculateFPS()
void
X11WindowSystem::RedrawAllLayers()
{
- m_damaged = false;
-
std::list<Layer*> layers = m_pScene->getCurrentRenderOrder();
for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++)
{
@@ -549,6 +547,8 @@ X11WindowSystem::RedrawAllLayers()
graphicSystem->endLayer();
}
}
+ /* Reset the damage flag, all is up to date */
+ m_damaged = false;
}
void X11WindowSystem::Redraw()
@@ -622,7 +622,7 @@ X11WindowSystem::error (Display *dpy, XErrorEvent *ev)
const char* name = NULL;
static char buffer[256];
- if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectWindow)
+ if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows)
{
LOG_ERROR("X11WindowSystem", "Maybe another composite manager is already running");
}
@@ -635,6 +635,7 @@ X11WindowSystem::error (Display *dpy, XErrorEvent *ev)
}
name = (strlen (name) > 0) ? name : "unknown";
LOG_ERROR("X11WindowSystem", "X Error: " << (int)ev->error_code << " " << name << " request : " << (int)ev->request_code << " minor: " << (int)ev->minor_code << " serial: " << (int)ev->serial);
+ m_xerror = true;
return 0;
}
@@ -652,14 +653,19 @@ bool X11WindowSystem::initXServer()
LOG_DEBUG("X11WindowSystem", "Compositor Window ID: " << CompositorWindow);
- CreatePixmapsForAllWindows();
- //unredirect our window
+ if ( CreatePixmapsForAllWindows() )
+ {
+ //unredirect our window
#ifdef FULLSCREEN
- XCompositeUnredirectWindow(x11Display, background, CompositeRedirectManual);
+ XCompositeUnredirectWindow(x11Display, background, CompositeRedirectManual);
#endif
- XCompositeUnredirectWindow(x11Display, CompositorWindow, CompositeRedirectManual);
+ XCompositeUnredirectWindow(x11Display, CompositorWindow, CompositeRedirectManual);
+ LOG_DEBUG("X11WindowSystem", "Initialised XServer connection complete");
+ } else {
+ LOG_ERROR("X11WindowSystem", "Initialised XServer connection failed");
+ result = false;
+ }
- LOG_DEBUG("X11WindowSystem", "Initialised XServer connection");
return result;
}
@@ -712,7 +718,7 @@ void* X11WindowSystem::EventLoop(void * ptr)
// clear screen to avoid garbage on startup
windowsys->graphicSystem->clearBackground();
windowsys->graphicSystem->swapBuffers();
-
+ XFlush(windowsys->x11Display);
while (windowsys->m_running)
{
#ifndef USE_XTHREADS
@@ -763,7 +769,7 @@ void* X11WindowSystem::EventLoop(void * ptr)
case UnmapNotify:
LOG_DEBUG("X11WindowSystem", "Unmap Event");
windowsys->UnMapWindow(event.xunmap.window);
- checkRedraw = true;
+ checkRedraw = true;
break;
case ReparentNotify:
LOG_DEBUG("X11WindowSystem", "Reparent Event");
@@ -804,7 +810,7 @@ void* X11WindowSystem::EventLoop(void * ptr)
}
else
{
- windowsys->checkForNewSurface();
+ windowsys->checkForNewSurface();
checkRedraw = true;
}
@@ -834,6 +840,7 @@ void X11WindowSystem::signalRedrawEvent()
{
// set flag that redraw is needed
redrawEvent = true;
+ m_damaged = true;
#ifdef USE_XTHREADS
// send dummy expose event, to wake up blocking x11 event loop (XNextEvent)
LOG_DEBUG("X11WindowSystem", "Sending dummy event to wake up renderer thread");
@@ -889,11 +896,19 @@ bool X11WindowSystem::init(BaseGraphicSystem<Display*,Window>* base)
bool X11WindowSystem::start()
{
+ bool result = true;
LOG_INFO("X11WindowSystem", "Starting / Creating thread");
// let thread actually run
- this->m_running = true;
- pthread_mutex_unlock(&run_lock);
- return true;
+ if ( m_xerror == false )
+ {
+ this->m_running = true;
+ pthread_mutex_unlock(&run_lock);
+ } else {
+ this->m_running = false;
+ pthread_mutex_unlock(&run_lock);
+ result = false;
+ }
+ return result;
}
void X11WindowSystem::stop()
@@ -936,3 +951,4 @@ void X11WindowSystem::doScreenShotOfSurface(std::string fileName, const uint id)
screenShotFile = fileName;
screenShotID = id;
}
+