// EXTERNAL INCLUDES
#include <Ecore_X.h>
#include <X11/Xutil.h>
+#include <X11/Xlib.h>
#include <dali/integration-api/debug.h>
-#include <render-surface.h>
// INTERNAL INCLUDES
#include <gl/egl-image-extensions.h>
#include <gl/egl-factory.h>
#include <adaptor-impl.h>
#include <bitmap-saver.h>
+#include <render-surface.h>
namespace Dali
{
};
}
-PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Dali::Adaptor& adaptor, Any pixmap )
+PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
{
- PixmapImage* image = new PixmapImage( width, height, depth, adaptor, pixmap );
+ PixmapImage* image = new PixmapImage( width, height, depth, pixmap );
DALI_ASSERT_DEBUG( image && "PixmapImage allocation failed." );
// 2nd phase construction
return image;
}
-PixmapImage::PixmapImage(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Dali::Adaptor& adaptor, Any pixmap)
-: mWidth(width),
- mHeight(height),
- mOwnPixmap(true),
- mPixmap(0),
- mDisplay(NULL),
- mPixelFormat(Pixel::RGB888),
- mColorDepth(depth),
- mAdaptor(Internal::Adaptor::Adaptor::GetImplementation(adaptor)),
- mEglImageKHR(NULL)
+PixmapImage::PixmapImage( unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, Any pixmap )
+: mWidth( width ),
+ mHeight( height ),
+ mOwnPixmap( true ),
+ mPixmap( 0 ),
+ mPixelFormat( Pixel::RGB888 ),
+ mColorDepth( depth ),
+ mEglImageKHR( NULL ),
+ mEglImageExtensions( NULL )
{
+ DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
+ EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
+ mEglImageExtensions = eglFactory.GetImageExtensions();
+ DALI_ASSERT_DEBUG( mEglImageExtensions );
+
// assign the pixmap
mPixmap = GetPixmapFromAny(pixmap);
}
void PixmapImage::Initialize()
{
- // Get render-surface being used by Dali
- Dali::RenderSurface& surface = mAdaptor.GetSurface();
-
- // get the X11 display pointer and store it
- // it is used by eglCreateImageKHR, and XFreePixmap
- // Any other display (x-connection) will fail in eglCreateImageKHR
- Any display = surface.GetDisplay();
-
- // the dali display pointer is needed
- mDisplay = AnyCast<Ecore_X_Display*>(display);
-
// if pixmap has been created outside of X11 Image we can return
if (mPixmap)
{
// set the pixel format
SetPixelFormat(depth);
- // Get the X-Renderable for which the pixmap is created on
- Any renderableSurface = surface.GetSurface();
-
- // if Dali is using a Pixmap or Window to render to it doesn't matter because they have the same
- // underlying type of unsigned long
- Ecore_X_Window daliWindow = AnyCast< Ecore_X_Window >(renderableSurface);
-
- mPixmap = ecore_x_pixmap_new(daliWindow, mWidth, mHeight, depth);
+ mPixmap = ecore_x_pixmap_new( 0, mWidth, mHeight, depth );
ecore_x_sync();
}
PixmapImage::~PixmapImage()
{
- // Lost the opportunity to call GlExtensionDestroy() if Adaptor is destroyed first
- if( Adaptor::IsAvailable() )
- {
- // GlExtensionDestroy() called from GLCleanup on the render thread. Checking this is done here.
- // (mEglImageKHR is now read/written from different threads although ref counted destruction
- // should mean this isnt concurrent)
- DALI_ASSERT_ALWAYS( NULL == mEglImageKHR && "NativeImage GL resources have not been properly cleaned up" );
- }
-
if (mOwnPixmap && mPixmap)
{
ecore_x_pixmap_free(mPixmap);
}
}
-Any PixmapImage::GetPixmap(Dali::PixmapImage::PixmapAPI api) const
-{
- if (api == Dali::PixmapImage::ECORE_X11)
- {
- // return ecore x11 type
- return Any(mPixmap);
- }
- else
- {
- // return x11 type after casting it
- Pixmap pixmap= static_cast<Pixmap>(mPixmap);
- return Any(pixmap);
- }
-}
-
-Any PixmapImage::GetDisplay() const
-{
- // return ecore x11 type
- return Any(mDisplay);
-}
-
bool PixmapImage::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
{
DALI_ASSERT_DEBUG(sizeof(unsigned) == 4);
width = mWidth;
height = mHeight;
- XImageJanitor xImageJanitor( XGetImage(static_cast<Display*>(mDisplay),
- mPixmap,
- 0, 0, // x,y of subregion to extract.
- width, height, // of suregion to extract.
- 0xFFFFFFFF,
- ZPixmap));
+ // Open a display connection
+ Display* displayConnection = XOpenDisplay( 0 );
+
+ XImageJanitor xImageJanitor( XGetImage( displayConnection,
+ mPixmap,
+ 0, 0, // x,y of subregion to extract.
+ width, height, // of suregion to extract.
+ 0xFFFFFFFF,
+ ZPixmap ) );
XImage* const pXImage = xImageJanitor.mXImage;
DALI_ASSERT_DEBUG(pXImage && "XImage (from pixmap) could not be retrieved from the server");
if(!pXImage)
width = 0;
height = 0;
}
+
+ // Close the display connection
+ XCloseDisplay( displayConnection );
+
return success;
}
GlExtensionDestroy();
}
- EglImageExtensions* eglImageExtensions = GetEglImageExtensions();
-
// casting from an unsigned int to a void *, which should then be cast back
// to an unsigned int in the driver.
EGLClientBuffer eglBuffer = reinterpret_cast< EGLClientBuffer > (mPixmap);
- mEglImageKHR = eglImageExtensions->CreateImageKHR( eglBuffer );
+ mEglImageKHR = mEglImageExtensions->CreateImageKHR( eglBuffer );
return mEglImageKHR != NULL;
}
void PixmapImage::GlExtensionDestroy()
{
- EglImageExtensions* eglImageExtensions = GetEglImageExtensions();
-
- eglImageExtensions->DestroyImageKHR(mEglImageKHR);
+ mEglImageExtensions->DestroyImageKHR(mEglImageKHR);
mEglImageKHR = NULL;
}
unsigned int PixmapImage::TargetTexture()
{
- EglImageExtensions* eglImageExtensions = GetEglImageExtensions();
-
- eglImageExtensions->TargetTextureKHR(mEglImageKHR);
+ mEglImageExtensions->TargetTextureKHR(mEglImageKHR);
return 0;
}
SetPixelFormat(ecore_x_pixmap_depth_get(mPixmap));
}
-EglImageExtensions* PixmapImage::GetEglImageExtensions() const
-{
- EglFactory& factory = mAdaptor.GetEGLFactory();
- EglImageExtensions* egl = factory.GetImageExtensions();
- DALI_ASSERT_DEBUG( egl && "EGL Image Extensions not initialized" );
- return egl;
-}
-
} // namespace Adaptor
} // namespace internal