From 78362f15020ea08bfce4a81076ef9ba05e57bd5b Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Wed, 3 Dec 2014 16:50:23 +0000 Subject: [PATCH] (PixmapImage) Removed dependency on Adaptor Change-Id: I314ff515b7c2e04aa1d0ebb222dd270f16c54a70 --- adaptors/common/indicator-impl.cpp | 2 +- .../public-api/adaptor-framework/pixmap-image.cpp | 24 ++--- .../public-api/adaptor-framework/pixmap-image.h | 36 +------ adaptors/wayland/pixmap-image-impl-wl.cpp | 62 +++-------- adaptors/wayland/pixmap-image-impl.h | 27 +---- adaptors/x11/pixmap-image-impl-x.cpp | 120 ++++++--------------- adaptors/x11/pixmap-image-impl.h | 26 +---- 7 files changed, 67 insertions(+), 230 deletions(-) diff --git a/adaptors/common/indicator-impl.cpp b/adaptors/common/indicator-impl.cpp index 9b8679b..3ab89fb 100644 --- a/adaptors/common/indicator-impl.cpp +++ b/adaptors/common/indicator-impl.cpp @@ -986,7 +986,7 @@ void Indicator::SetBackground() void Indicator::CreateNewPixmapImage() { DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d\n", mImageWidth, mImageHeight ); - Dali::PixmapImagePtr pixmapImage = Dali::PixmapImage::New(mPixmap, Dali::Adaptor::Get()); + Dali::PixmapImagePtr pixmapImage = Dali::PixmapImage::New( mPixmap ); if( pixmapImage ) { diff --git a/adaptors/public-api/adaptor-framework/pixmap-image.cpp b/adaptors/public-api/adaptor-framework/pixmap-image.cpp index 250f653..e4b16eb 100644 --- a/adaptors/public-api/adaptor-framework/pixmap-image.cpp +++ b/adaptors/public-api/adaptor-framework/pixmap-image.cpp @@ -27,30 +27,20 @@ namespace Dali { -PixmapImagePtr PixmapImage::New(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor) +PixmapImagePtr PixmapImage::New( unsigned int width, unsigned int height, ColorDepth depth ) { Any empty; - PixmapImagePtr image = new PixmapImage(width, height, depth, adaptor, empty); + PixmapImagePtr image = new PixmapImage( width, height, depth, empty ); return image; } -PixmapImagePtr PixmapImage::New(Any pixmap, Adaptor& adaptor) +PixmapImagePtr PixmapImage::New( Any pixmap ) { - PixmapImagePtr image = new PixmapImage(0, 0, COLOR_DEPTH_DEFAULT, adaptor, pixmap); + PixmapImagePtr image = new PixmapImage(0, 0, COLOR_DEPTH_DEFAULT, pixmap); return image; } -Any PixmapImage::GetPixmap(PixmapAPI api) -{ - return mImpl->GetPixmap(api); -} - -Any PixmapImage::GetDisplay() -{ - return mImpl->GetDisplay(); -} - -bool PixmapImage::GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const +bool PixmapImage::GetPixels( std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const { return mImpl->GetPixels( pixbuf, width, height, pixelFormat ); } @@ -95,9 +85,9 @@ Pixel::Format PixmapImage::GetPixelFormat() const return mImpl->GetPixelFormat(); } -PixmapImage::PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap) +PixmapImage::PixmapImage( unsigned int width, unsigned int height, ColorDepth depth, Any pixmap ) { - mImpl = Internal::Adaptor::PixmapImage::New( width, height, depth, adaptor, pixmap); + mImpl = Internal::Adaptor::PixmapImage::New( width, height, depth, pixmap ); } PixmapImage::~PixmapImage() diff --git a/adaptors/public-api/adaptor-framework/pixmap-image.h b/adaptors/public-api/adaptor-framework/pixmap-image.h index 0ef097e..05196bc 100644 --- a/adaptors/public-api/adaptor-framework/pixmap-image.h +++ b/adaptors/public-api/adaptor-framework/pixmap-image.h @@ -25,7 +25,6 @@ namespace Dali { -class Adaptor; namespace Internal DALI_INTERNAL { @@ -53,15 +52,6 @@ class DALI_IMPORT_API PixmapImage : public NativeImage public: /** - * @brief PixmapImage can use pixmaps created by X11 or ECORE X11. - */ - enum PixmapAPI - { - X11, ///< X types - ECORE_X11, ///< EFL e-core x11 types - }; - - /** * @brief When creating a pixmap the color depth has to be specified. */ enum ColorDepth @@ -80,36 +70,17 @@ public: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] depth color depth of the pixmap - * @param[in] adaptor reference to dali adaptor * @return A smart-pointer to a newly allocated image. */ - static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor ); + static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth ); /** * @brief Create a new PixmapImage from an existing pixmap. * * @param[in] pixmap must be a X11 pixmap or a Ecore_X_Pixmap - * @param[in] adaptor reference to dali adaptor * @return A smart-pointer to a newly allocated image. */ - static PixmapImagePtr New( Any pixmap, Adaptor& adaptor ); - - /** - * @brief Retrieve the internal pixmap - * - * @param api whether to return a pixmap that can be used with X11 or EFL - * @return pixmap any object containing a pixmap of the type specified PixmapAPI - */ - Any GetPixmap( PixmapAPI api ); - - /** - * @brief Retrieve the display used to create the pixmap. - * - * If the pixmap was created outside of Dali, then this display - * is the one Dali uses internally. - * @return Any object containing the display - */ - Any GetDisplay(); + static PixmapImagePtr New( Any pixmap ); /** * @brief Get a copy of the pixels used by PixmapImage. @@ -179,10 +150,9 @@ private: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] depth color depth of the pixmap - * @param[in] adaptor a reference to Dali adaptor * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty */ - DALI_INTERNAL PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap); + DALI_INTERNAL PixmapImage( unsigned int width, unsigned int height, ColorDepth depth, Any pixmap ); /** * @brief A reference counted object may only be deleted by calling Unreference(). diff --git a/adaptors/wayland/pixmap-image-impl-wl.cpp b/adaptors/wayland/pixmap-image-impl-wl.cpp index 870bddd..70a6423 100644 --- a/adaptors/wayland/pixmap-image-impl-wl.cpp +++ b/adaptors/wayland/pixmap-image-impl-wl.cpp @@ -19,8 +19,6 @@ #include "pixmap-image-impl.h" // EXTERNAL INCLUDES -#include -#include #include #include @@ -43,9 +41,9 @@ namespace Adaptor { using Dali::Integration::PixelBuffer; -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 @@ -57,15 +55,19 @@ PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::Pix 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), - 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 ), + 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 ); } void PixmapImage::Initialize() @@ -74,24 +76,6 @@ void PixmapImage::Initialize() 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" ); - } -} - -Any PixmapImage::GetPixmap(Dali::PixmapImage::PixmapAPI api) const -{ - return NULL; -} - -Any PixmapImage::GetDisplay() const -{ - return NULL; } bool PixmapImage::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const @@ -119,18 +103,14 @@ bool PixmapImage::GlExtensionCreate() 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; } @@ -196,14 +176,6 @@ void PixmapImage::GetPixmapDetails() { } -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 diff --git a/adaptors/wayland/pixmap-image-impl.h b/adaptors/wayland/pixmap-image-impl.h index 12f3498..86120ff 100644 --- a/adaptors/wayland/pixmap-image-impl.h +++ b/adaptors/wayland/pixmap-image-impl.h @@ -19,11 +19,9 @@ */ // EXTERNAL INCLUDES -#include -#include -#include // INTERNAL INCLUDES +#include namespace Dali { @@ -33,7 +31,6 @@ namespace Internal namespace Adaptor { -class Adaptor; class EglImageExtensions; /** @@ -49,26 +46,14 @@ public: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] depth color depth of the pixmap - * @param[in] adaptor reference to dali adaptor * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty * @return A smart-pointer to a newly allocated image. */ static PixmapImage* New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, - Dali::Adaptor& adaptor, Any pixmap); - /** - * @copydoc Dali::PixmapImage::GetPixmap() - */ - Any GetPixmap(Dali::PixmapImage::PixmapAPI api) const; - - /** - * @copydoc Dali::PixmapImage::GetDisplay() - */ - Any GetDisplay() const; - /** * @copydoc Dali::PixmapImage::GetPixels() */ @@ -130,13 +115,11 @@ private: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] colour depth of the pixmap - * @param[in] adaptor a reference to Dali adaptor * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty */ PixmapImage(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, - Dali::Adaptor &adaptor, Any pixmap); /** @@ -163,12 +146,6 @@ private: */ void GetPixmapDetails(); - /** - * Returns the egl image extensions class from the adaptor - * @return reference to egl image extensionsa - */ - EglImageExtensions* GetEglImageExtensions() const; - private: unsigned int mWidth; ///< pixmap width @@ -176,8 +153,8 @@ private: bool mOwnPixmap; ///< Whether we created pixmap or not Pixel::Format mPixelFormat; ///< pixmap pixel format Dali::PixmapImage::ColorDepth mColorDepth; ///< color depth of pixmap - Adaptor& mAdaptor; ///< adaptor void* mEglImageKHR; ///< From EGL extension + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions }; } // namespace Adaptor diff --git a/adaptors/x11/pixmap-image-impl-x.cpp b/adaptors/x11/pixmap-image-impl-x.cpp index c0cc671..c200b64 100644 --- a/adaptors/x11/pixmap-image-impl-x.cpp +++ b/adaptors/x11/pixmap-image-impl-x.cpp @@ -21,14 +21,15 @@ // EXTERNAL INCLUDES #include #include +#include #include -#include // INTERNAL INCLUDES #include #include #include #include +#include namespace Dali { @@ -71,9 +72,9 @@ namespace }; } -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 @@ -85,34 +86,27 @@ PixmapImage* PixmapImage::New(unsigned int width, unsigned int height, Dali::Pix 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(display); - // if pixmap has been created outside of X11 Image we can return if (mPixmap) { @@ -130,55 +124,18 @@ void PixmapImage::Initialize() // 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(mPixmap); - return Any(pixmap); - } -} - -Any PixmapImage::GetDisplay() const -{ - // return ecore x11 type - return Any(mDisplay); -} - bool PixmapImage::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const { DALI_ASSERT_DEBUG(sizeof(unsigned) == 4); @@ -186,12 +143,15 @@ bool PixmapImage::GetPixels(std::vector& pixbuf, unsigned& width, width = mWidth; height = mHeight; - XImageJanitor xImageJanitor( XGetImage(static_cast(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) @@ -283,6 +243,10 @@ bool PixmapImage::GetPixels(std::vector& pixbuf, unsigned& width, width = 0; height = 0; } + + // Close the display connection + XCloseDisplay( displayConnection ); + return success; } @@ -307,31 +271,25 @@ bool PixmapImage::GlExtensionCreate() 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; } @@ -431,14 +389,6 @@ void PixmapImage::GetPixmapDetails() 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 diff --git a/adaptors/x11/pixmap-image-impl.h b/adaptors/x11/pixmap-image-impl.h index 464081c..bd47110 100644 --- a/adaptors/x11/pixmap-image-impl.h +++ b/adaptors/x11/pixmap-image-impl.h @@ -20,9 +20,9 @@ // EXTERNAL INCLUDES #include -#include // INTERNAL INCLUDES +#include namespace Dali { @@ -32,7 +32,6 @@ namespace Internal namespace Adaptor { -class Adaptor; class EglImageExtensions; /** @@ -48,26 +47,14 @@ public: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] depth color depth of the pixmap - * @param[in] adaptor reference to dali adaptor * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty * @return A smart-pointer to a newly allocated image. */ static PixmapImage* New(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, - Dali::Adaptor& adaptor, Any pixmap); - /** - * @copydoc Dali::PixmapImage::GetPixmap() - */ - Any GetPixmap(Dali::PixmapImage::PixmapAPI api) const; - - /** - * @copydoc Dali::PixmapImage::GetDisplay() - */ - Any GetDisplay() const; - /** * @copydoc Dali::PixmapImage::GetPixels() */ @@ -129,13 +116,11 @@ private: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] colour depth of the pixmap - * @param[in] adaptor a reference to Dali adaptor * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty */ PixmapImage(unsigned int width, unsigned int height, Dali::PixmapImage::ColorDepth depth, - Dali::Adaptor &adaptor, Any pixmap); /** @@ -169,23 +154,16 @@ private: */ void GetPixmapDetails(); - /** - * Returns the egl image extensions class from the adaptor - * @return reference to egl image extensionsa - */ - EglImageExtensions* GetEglImageExtensions() const; - private: unsigned int mWidth; ///< pixmap width unsigned int mHeight; ///< pixmap heights bool mOwnPixmap; ///< Whether we created pixmap or not Ecore_X_Pixmap mPixmap; ///< From Xlib - Ecore_X_Display* mDisplay; ///< x-connection used to create pixmap (if it was not created outside of PixmapImage) Pixel::Format mPixelFormat; ///< pixmap pixel format Dali::PixmapImage::ColorDepth mColorDepth; ///< color depth of pixmap - Adaptor& mAdaptor; ///< adaptor void* mEglImageKHR; ///< From EGL extension + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions }; } // namespace Adaptor -- 2.7.4