#include <dali/integration-api/debug.h>
#include <dali/integration-api/gl-defines.h>
#include <cstring>
+#include <tbm_surface_internal.h>
// INTERNAL INCLUDES
#include <gl/egl-image-extensions.h>
#include <gl/egl-factory.h>
#include <adaptor-impl.h>
#include <render-surface.h>
+#include <trigger-event-factory.h>
+
// Allow this to be encoded and saved:
-#include <platform-abstractions/tizen/resource-loader/resource-loader.h>
#include <bitmap-saver.h>
namespace Dali
mColorDepth( depth ),
mEglImageKHR( NULL ),
mEglImageExtensions( NULL ),
- mSetSource( false )
+ mSetSource( false ),
+ mNotification( NULL )
{
DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() );
EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory();
if( mTbmSurface != NULL )
{
+ tbm_surface_internal_ref( mTbmSurface );
mBlendingRequired = CheckBlending( tbm_surface_get_format( mTbmSurface ) );
mWidth = tbm_surface_get_width( mTbmSurface );
mHeight = tbm_surface_get_height( mTbmSurface );
NativeImageSource::~NativeImageSource()
{
- if( mOwnTbmSurface && mTbmSurface != NULL )
+ if( mOwnTbmSurface )
{
- if( tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
+ if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
{
DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" );
}
}
+ else
+ {
+ if( mTbmSurface != NULL )
+ {
+ tbm_surface_internal_unref( mTbmSurface );
+
+ if (mNotification != NULL) {
+ TriggerEventInterface* triggerEvent = static_cast<TriggerEventInterface* >(mNotification);
+ triggerEvent->Trigger();
+ }
+ }
+ }
}
Any NativeImageSource::GetNativeImageSource() const
return Any( mTbmSurface );
}
+
+void NativeImageSource::SetDestructorNotification(void* notification)
+{
+ mNotification = notification;
+}
+
bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const
{
if( mTbmSurface != NULL )
{
cOffset = c*3;
offset = cOffset + r*stride;
- *(bufptr) = ptr[offset+2];
+ *(bufptr+cOffset) = ptr[offset+2];
*(bufptr+cOffset+1) = ptr[offset+1];
*(bufptr+cOffset+2) = ptr[offset];
}
{
cOffset = c*4;
offset = cOffset + r*stride;
- *(bufptr) = ptr[offset+3];
+ *(bufptr+cOffset) = ptr[offset+3];
*(bufptr+cOffset+1) = ptr[offset+2];
*(bufptr+cOffset+2) = ptr[offset+1];
*(bufptr+cOffset+3) = ptr[offset];
}
default:
{
- DALI_LOG_WARNING( "Tbm surface has unsupported pixel format.\n" );
-
- pixbuf.resize( 0 );
- width = 0;
- height = 0;
+ DALI_ASSERT_ALWAYS( 0 && "Tbm surface has unsupported pixel format.\n" );
return false;
}
void NativeImageSource::SetSource( Any source )
{
- if( mOwnTbmSurface && mTbmSurface != NULL )
+ if( mOwnTbmSurface )
{
- if( tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
+ if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE )
{
DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" );
}
mTbmSurface = NULL;
mOwnTbmSurface = false;
}
+ else
+ {
+ if( mTbmSurface != NULL )
+ {
+ tbm_surface_internal_unref( mTbmSurface );
+ mTbmSurface = NULL;
+ }
+ }
mTbmSurface = GetSurfaceFromAny( source );
- mSetSource = true;
if( mTbmSurface != NULL )
{
+ mSetSource = true;
+ tbm_surface_internal_ref( mTbmSurface );
mBlendingRequired = CheckBlending( tbm_surface_get_format( mTbmSurface ) );
mWidth = tbm_surface_get_width( mTbmSurface );
mHeight = tbm_surface_get_height( mTbmSurface );
{
// 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 > (mTbmSurface);
+ EGLClientBuffer eglBuffer = reinterpret_cast< EGLClientBuffer >(mTbmSurface);
if( !eglBuffer )
{
return false;
void NativeImageSource::PrepareTexture()
{
- if( mSetSource && GlExtensionCreate() )
+ if( mSetSource )
{
- TargetTexture();
+ void* eglImage = mEglImageKHR;
+
+ if( GlExtensionCreate() )
+ {
+ TargetTexture();
+ }
+
+ mEglImageExtensions->DestroyImageKHR( eglImage );
+
mSetSource = false;
}
}