TextureBinders: Correct usage for getNativeContent()
authorRahul Singhal <rasinghal@nvidia.com>
Mon, 19 Mar 2012 09:28:38 +0000 (14:58 +0530)
committerMichael Schuldt <michael.schuldt@bmw.de>
Fri, 23 Mar 2012 09:28:57 +0000 (10:28 +0100)
getNativeContent() returns -1 and not 0 to indicate a failure.

LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp
LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLX.cpp

index 3457670..5e4441a 100644 (file)
 #include "GLES2/gl2.h"
 
 bool X11CopyGLES::bindSurfaceTexture(Surface* surface)
-{   
+{
     XPlatformSurface* nativeSurface = NULL;
     Pixmap pixmap = 0;
     GLenum targetType = GL_RGBA;
     GLenum sourceType = GL_RGBA;
-       unsigned char* swapedData = NULL;
-       bool swaprgb = false;
+    unsigned char* swapedData = NULL;
+    bool swaprgb = false;
     bool includeAlpha = false;
-    if (surface != NULL ) 
+    if (surface != NULL )
     {
         nativeSurface = (XPlatformSurface*)surface->platform;
-    } 
-    if( nativeSurface != NULL && surface->getNativeContent() != 0 && nativeSurface->isReadyForRendering())
+    }
+    if( nativeSurface != NULL && surface->getNativeContent() != -1 && nativeSurface->isReadyForRendering())
     {
-           pixmap = XCompositeNameWindowPixmap (dpy, surface->getNativeContent());
-           if (!pixmap)
-           {
-                   LOG_ERROR("X11CopyGLES", "didnt create pixmap!");
-                   return false;
-           }
-           nativeSurface->pixmap = pixmap;
-           XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap);
-           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 ( surface->getPixelFormat() == PIXELFORMAT_RGB888)
-                   {
-                           targetType = GL_RGB;
-                           sourceType = GL_RGB;
-                           swaprgb = true;                
-                           swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*3];
-                   } 
+        pixmap = XCompositeNameWindowPixmap (dpy, surface->getNativeContent());
+        if (!pixmap)
+        {
+            LOG_ERROR("X11CopyGLES", "didnt create pixmap!");
+            return false;
+        }
+        nativeSurface->pixmap = pixmap;
+        XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap);
+        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 ( surface->getPixelFormat() == PIXELFORMAT_RGB888)
+            {
+                targetType = GL_RGB;
+                sourceType = GL_RGB;
+                swaprgb = true;
+                swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*3];
+            }
             else if ( surface->getPixelFormat() == PIXELFORMAT_RGBA8888)
             {
-                if (xim->depth == 24) 
+                if (xim->depth == 24)
                 {
-                               includeAlpha = true;
+                    includeAlpha = true;
                 }
                 swapedData = new unsigned char[surface->OriginalSourceWidth*surface->OriginalSourceHeight*4];
-                   } 
-            else 
+            }
+            else
             {
                 LOG_ERROR("X11CopyGLES","Pixelformat currently not supported : " << surface->getPixelFormat());
-                   XDestroyImage(xim);
+                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;
+            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;
+        } 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,bool includeAlpha) 
+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)
-       {       
-               count = width*height;
-               for (uint j=0;j<count; j++) {
-                       dest[j*4]=src[j*4+2];
-                       dest[j*4+1]=src[j*4+1];
-                       dest[j*4+2]=src[j*4];
+    unsigned int count = 0;
+    if (swaprgb == false)
+    {
+        count = width*height;
+        for (uint j=0;j<count; j++) {
+            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];
-            if (includeAlpha) 
-            {    
-                       dest[j*4+3]=255;
-            } 
-               }
-       } else {
-               count = width*height;        
-               for (uint j=0;j<count; j++)
-               {
-                       dest[j*3]=src[j*3+2];
-                       dest[j*3+1]=src[j*3+1];
-                       dest[j*3+2]=src[j*3];
-               }
-       }
+            if (includeAlpha)
+            {
+                dest[j*4+3]=255;
+            }
+        }
+    } else {
+        count = width*height;
+        for (uint j=0;j<count; j++)
+        {
+            dest[j*3]=src[j*3+2];
+            dest[j*3+1]=src[j*3+1];
+            dest[j*3+2]=src[j*3];
+        }
+    }
 }
 
 void X11CopyGLES::createClientBuffer(Surface* surface)
index 9272996..720e378 100644 (file)
@@ -30,11 +30,11 @@ bool X11CopyGLX::bindSurfaceTexture(Surface* surface)
     Pixmap pixmap = 0;
     GLenum targetType = GL_BGRA;
     GLenum sourceType = GL_RGBA;
-    if (surface != NULL ) 
+    if (surface != NULL )
     {
         nativeSurface = (XPlatformSurface*)surface->platform;
-    } 
-    if( nativeSurface != NULL && surface->getNativeContent() != 0 && nativeSurface->isReadyForRendering())
+    }
+    if( nativeSurface != NULL && surface->getNativeContent() != -1 && nativeSurface->isReadyForRendering())
     {
         pixmap = XCompositeNameWindowPixmap (dpy, surface->getNativeContent());
         if (!pixmap)
@@ -55,22 +55,22 @@ bool X11CopyGLX::bindSurfaceTexture(Surface* surface)
                 targetType = GL_BGR;
                 sourceType = GL_RGB;
             } 
-            else if ( surface->getPixelFormat() == PIXELFORMAT_RGBA8888 ) 
+            else if ( surface->getPixelFormat() == PIXELFORMAT_RGBA8888 )
             {
                 targetType = GL_BGRA;
                 sourceType = GL_RGBA;
-                if (xim->depth == 24) 
+                if (xim->depth == 24)
                 {
                     /* Set alpha value */
                     int count = surface->OriginalSourceWidth*surface->OriginalSourceHeight;
-                    for (int j=0;j<count; j++) 
+                    for (int j=0;j<count; j++)
                     {
                         xim->data[j*4+3]=255;
-                    } 
+                    }
                 }
             } else {
                 LOG_ERROR("X11CopyGLX","Pixelformat currently not supported : " << surface->getPixelFormat());
-                   XDestroyImage(xim);
+                XDestroyImage(xim);
                 return false;
             }
             glTexImage2D(GL_TEXTURE_2D, 0, sourceType, surface->OriginalSourceWidth, surface->OriginalSourceHeight, 0, targetType, GL_UNSIGNED_BYTE, xim->data);