From 35e1cf6c55f996033482cb19c76fda9337f59ec4 Mon Sep 17 00:00:00 2001 From: Dae Young Ryu Date: Mon, 24 Feb 2014 17:11:32 +0900 Subject: [PATCH] add caching logic for pixmap Change-Id: Ie32af296728e4db068d488964f03782e35e8ab7b Signed-off-by: Dae Young Ryu --- src/ui/animations/FUiAnim_Debug.cpp | 4 +- src/ui/animations/FUiAnim_Debug.h | 3 +- src/ui/animations/FUiAnim_EflLayer.cpp | 2 +- src/ui/animations/FUiAnim_GeometryInfo.cpp | 2 +- src/ui/animations/FUiAnim_GlContext.h | 5 +- src/ui/animations/FUiAnim_GlNode.cpp | 4 +- src/ui/animations/FUiAnim_GlRenderManager.cpp | 43 +++-- .../FUiAnim_GlVisualElementSurfaceImpl.cpp | 4 + src/ui/animations/FUiAnim_VisualElementCanvas.cpp | 34 +++- src/ui/animations/FUiAnim_VisualElementImpl.cpp | 10 +- .../FUiAnim_VisualElementSurfaceManager.cpp | 77 +++++--- .../FUiAnim_VisualElementSurfaceManager.h | 7 +- .../animations/platform/FUiAnim_EcoreXLooper.cpp | 6 + src/ui/animations/platform/FUiAnim_Egl.cpp | 205 ++++++++++++++++----- src/ui/animations/platform/FUiAnim_Egl.h | 36 +++- src/ui/animations/platform/FUiAnim_GlContext.cpp | 35 ++-- src/ui/animations/platform/FUiAnim_X11.cpp | 4 +- src/ui/inc/FUiAnim_VisualElementCanvas.h | 2 + 18 files changed, 364 insertions(+), 119 deletions(-) diff --git a/src/ui/animations/FUiAnim_Debug.cpp b/src/ui/animations/FUiAnim_Debug.cpp index 16d421d..00e6fa4 100644 --- a/src/ui/animations/FUiAnim_Debug.cpp +++ b/src/ui/animations/FUiAnim_Debug.cpp @@ -79,12 +79,12 @@ using namespace Tizen::Media; namespace Tizen { namespace Ui { namespace Animations { -#ifdef _OSP_PERF_ + int _ElapsedTime::depth = 0; char _ElapsedTime::logs[500][256]; int _ElapsedTime::maxdepth = 0; int _ElapsedTime::count = 0; -#endif + #define DIGITATPOSITION(number, digit) static_cast< int >((number % static_cast< int >(powf(10.0f, (digit)))) / powf(10.0f, (digit - 1))) diff --git a/src/ui/animations/FUiAnim_Debug.h b/src/ui/animations/FUiAnim_Debug.h index 8d7fe63..69a0d9e 100644 --- a/src/ui/animations/FUiAnim_Debug.h +++ b/src/ui/animations/FUiAnim_Debug.h @@ -46,8 +46,8 @@ namespace Ui { namespace Animations { #ifdef VE_DEBUG_MODULE +class VisualElement; -#ifdef _OSP_PERF_ class _ElapsedTime { public: @@ -94,7 +94,6 @@ public: long long start_time; const char* tagName; }; // _ElapsedTime -#endif #define VeLog(UID, ...) \ SysLogInternal(UID, 0, 0, __VA_ARGS__); diff --git a/src/ui/animations/FUiAnim_EflLayer.cpp b/src/ui/animations/FUiAnim_EflLayer.cpp index 0b6912f..426e48c 100755 --- a/src/ui/animations/FUiAnim_EflLayer.cpp +++ b/src/ui/animations/FUiAnim_EflLayer.cpp @@ -45,7 +45,7 @@ using namespace Tizen::Graphics; using namespace Tizen::Ui; using namespace Tizen::Ui::Animations; -//#define PRINT(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) +//#define PRINT(...) fprintf(stderr, __VA_ARGS__) #define PRINT(...) diff --git a/src/ui/animations/FUiAnim_GeometryInfo.cpp b/src/ui/animations/FUiAnim_GeometryInfo.cpp index 2e0a42e..9efee09 100644 --- a/src/ui/animations/FUiAnim_GeometryInfo.cpp +++ b/src/ui/animations/FUiAnim_GeometryInfo.cpp @@ -33,7 +33,7 @@ #include -//#define PRINT(FMT__,...) fprint(stderr, __VA_ARGS__) +//#define PRINT(...) fprint(__VA_ARGS__) //#define PRINT(...) SysLog(NID_UI_ANIM, __VA_ARGS__) #define PRINT(...) diff --git a/src/ui/animations/FUiAnim_GlContext.h b/src/ui/animations/FUiAnim_GlContext.h index e0ee357..95390db 100644 --- a/src/ui/animations/FUiAnim_GlContext.h +++ b/src/ui/animations/FUiAnim_GlContext.h @@ -54,7 +54,8 @@ struct TextureInfo; class _GlContext { public: - static _GlContext* CreateN(Handle nativeDisplay, Handle window, _GlContext* pSharedContext); + static _GlContext* CreateN(Handle nativeDisplay, Handle window); + static _GlContext* CreateN(_GlContext& sharedContext); #ifndef VE_USE_GL_MULTI_CONTEXT static _GlContext* GetInstance(void) @@ -132,6 +133,7 @@ private: protected: Handle __nativeDisplay; //TODO remove + Handle __window; bool __supportBGRA8888; @@ -163,6 +165,7 @@ private: #ifndef VE_USE_GL_MULTI_CONTEXT static _GlContext* __pInstance; #endif + _GlContext* __pSharedContext; friend class _GlRenderManager; friend class _VisualElementSurfaceManager; diff --git a/src/ui/animations/FUiAnim_GlNode.cpp b/src/ui/animations/FUiAnim_GlNode.cpp index 8b57e39..14007e7 100644 --- a/src/ui/animations/FUiAnim_GlNode.cpp +++ b/src/ui/animations/FUiAnim_GlNode.cpp @@ -53,7 +53,7 @@ #include "FUiAnim_ShaderProgramImpl.h" //#define PRINT(...) fprintf(stderr, __VA_ARGS__) -#define PRINT +#define PRINT(...) using namespace Tizen; using namespace Tizen::Base; @@ -364,10 +364,12 @@ _GlNode::SyncStatus(VisualElementSurface* pSurface, _VisualElementImpl& element) } } + // Set texture info __texSize = pSurfaceImpl->GetPhysicalSize(); __textureId = ((TextureInfo*)pSurfaceImpl->GetNativeHandle())->textureId; + // Calc texture coordinates if (__useStencil) { diff --git a/src/ui/animations/FUiAnim_GlRenderManager.cpp b/src/ui/animations/FUiAnim_GlRenderManager.cpp index 15a3831..87ab58f 100644 --- a/src/ui/animations/FUiAnim_GlRenderManager.cpp +++ b/src/ui/animations/FUiAnim_GlRenderManager.cpp @@ -79,18 +79,16 @@ using namespace Tizen::Ui::Animations; //#define PRINT(...) fprintf(stderr, __VA_ARGS__) #define PRINT(...) -#if 0 -static bool __checkCondition(bool condition) -{ - bool bCond = condition; - if(bCond == false) - { - return bCond; - } - return bCond; -} -#endif +//static bool __checkCondition(bool condition) +//{ +// bool bCond = condition; +// if(bCond == false) +// { +// return bCond; +// } +// return bCond; +//} //#define ASSERT(__CONDITION__,...) {__checkCondition(__CONDITION__); SysAssertf(__CONDITION__,__VA_ARGS__);} #define ASSERT(...) SysAssertf(__VA_ARGS__) @@ -1262,7 +1260,8 @@ _GlRenderManager::FlushRenderQueue(void) glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_TEXTURE], 0); - if (__pRenderQueue[i].__isTexUpdated) + + if ( __pRenderQueue[i].__isTexUpdated) { __pGlContext->UpdateTexture(__pRenderQueue[i].__pSurfaceInfo); } @@ -1878,7 +1877,7 @@ _GlRenderManager::CommandHandlerCreateTexture(TextureInfo* pTextureInfo) CHECK_GL_CONTEXT(pGlContext); - PRINT(">> CommandHandlerCreateTexture() \n"); + PRINT(">> _GlRenderManager::CommandHandlerCreateTexture() \n"); pGlContext->MakeCurrent(); @@ -1886,7 +1885,7 @@ _GlRenderManager::CommandHandlerCreateTexture(TextureInfo* pTextureInfo) #else CHECK_GL_CONTEXT(); - PRINT(">> CommandHandlerCreateTexture() \n"); + PRINT(">> _GlRenderManager::CommandHandlerCreateTexture() \n"); return __pGlContext->CreateTexture(pTextureInfo); #endif @@ -1902,13 +1901,13 @@ _GlRenderManager::CommandHandlerDeleteTexture(TextureInfo* pTextureInfo) pGlContext->MakeCurrent(); - PRINT(">> CommandHandlerDeleteTexture() texture id %u \n", pTextureInfo->textureId); + PRINT(">> _GlRenderManager::CommandHandlerDeleteTexture() texture id %u \n", pTextureInfo->textureId); pGlContext->DeleteTexture(pTextureInfo); #else CHECK_GL_CONTEXT(); - PRINT(">> CommandHandlerDeleteTexture() texture id %u \n", pTextureInfo->textureId); + PRINT(">> _GlRenderManager::CommandHandlerDeleteTexture() texture id %u \n", pTextureInfo->textureId); __pGlContext->DeleteTexture(pTextureInfo); #endif @@ -2059,9 +2058,19 @@ _GlRenderManager::RenderProc(void* pData) #ifdef ECORE_X_NATIVE _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance()); _GlContext::CreateInstance(reinterpret_cast(pLooper->GetXDisplay()) ); + #endif pThis->__pGlContext = _GlContext::GetInstance(); #endif + if(_VisualElementSurfaceManager::GetInstance() == null) + { +#ifdef __SHARED_CONTEXT__ + _VisualElementSurfaceManager::CreateInstance(*pThis->__pGlContext); +#else + _VisualElementSurfaceManager::Initialize(); +#endif + } + pThis->__pAnimationManager = _AnimationManager::GetInstance(); @@ -2193,6 +2202,8 @@ exit_renderer: pThis->__pGlContext = null; #endif + _VisualElementSurfaceManager::ReleaseInstance(); + _GlesInterfaceTerminate(); { diff --git a/src/ui/animations/FUiAnim_GlVisualElementSurfaceImpl.cpp b/src/ui/animations/FUiAnim_GlVisualElementSurfaceImpl.cpp index 2edced7..edc5e2a 100644 --- a/src/ui/animations/FUiAnim_GlVisualElementSurfaceImpl.cpp +++ b/src/ui/animations/FUiAnim_GlVisualElementSurfaceImpl.cpp @@ -37,6 +37,9 @@ #include "FUiAnim_GlVisualElementSurfaceImpl.h" #include "FUiAnim_VisualElementSurfaceManager.h" +//#define PRINT(...) fprintf(stderr, __VA_ARGS__) +#define PRINT(...) + using namespace Tizen::Base; using namespace Tizen::Graphics; @@ -234,6 +237,7 @@ _GlVisualElementSurfaceImpl::_GlVisualElementSurfaceImpl(const Bitmap& bitmap, c __textureInfo.stride = 0; __textureInfo.bitsPerPixel = 0; + if (_VisualElementSurfaceManager::GetInstance()->CreateSurface(this) != E_SUCCESS) { SysAssertf(false, "Cannot initialize GL texture for surface"); diff --git a/src/ui/animations/FUiAnim_VisualElementCanvas.cpp b/src/ui/animations/FUiAnim_VisualElementCanvas.cpp index 5323cfe..c649c11 100644 --- a/src/ui/animations/FUiAnim_VisualElementCanvas.cpp +++ b/src/ui/animations/FUiAnim_VisualElementCanvas.cpp @@ -47,11 +47,20 @@ namespace Tizen { namespace Ui { namespace Animations //}; _VisualElementCanvas::_VisualElementCanvas(void) + : __pSurface(null) { } _VisualElementCanvas::~_VisualElementCanvas(void) { + if(__pSurface) + { + _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*__pSurface); + pSurfaceImpl->Invalidate(true); + + delete __pSurface; + __pSurface = null; + } } // TODO: @@ -62,12 +71,21 @@ _VisualElementCanvas::Construct(const VisualElementSurface& surface, const Tizen { ClearLastResult(); + if(__pSurface) + { + return E_OBJ_ALREADY_EXIST; + } + + __pSurface = new (std::nothrow) VisualElementSurface(surface); + SysTryReturnResult(NID_UI, __pSurface, E_OUT_OF_MEMORY, "Memory allocation failed."); + + Tizen::Graphics::_CanvasImpl* pCanvasImpl = Tizen::Graphics::_CanvasImpl::GetInstance(*this); SysTryReturnResult(NID_UI, pCanvasImpl, E_OUT_OF_MEMORY, "Memory allocation failed."); - SysTryReturnResult(NID_UI, _VisualElementSurfaceImpl::GetInstance(surface), E_SYSTEM, "A system error has been occurred. Invalid surface."); + SysTryReturnResult(NID_UI, _VisualElementSurfaceImpl::GetInstance(*__pSurface), E_SYSTEM, "A system error has been occurred. Invalid surface."); - Handle window = _VisualElementSurfaceImpl::GetInstance(surface)->GetNativeHandle(); + Handle window = _VisualElementSurfaceImpl::GetInstance(*__pSurface)->GetNativeHandle(); #ifdef ENABLE_VE_EFL Tizen::Graphics::_Canvas* pNativeCanvas = pCanvasImpl->_pNativeCanvas; @@ -85,12 +103,20 @@ _VisualElementCanvas::Construct(const VisualElementSurface& surface, const Tizen result _VisualElementCanvas::Construct(const VisualElementSurface& surface, const Tizen::Graphics::FloatRectangle& rectangle, bool useEfl) { + if(__pSurface) + { + return E_OBJ_ALREADY_EXIST; + } + + __pSurface = new (std::nothrow) VisualElementSurface(surface); + SysTryReturnResult(NID_UI, __pSurface, E_OUT_OF_MEMORY, "Memory allocation failed."); + Tizen::Graphics::_CanvasImpl* pCanvasImpl = Tizen::Graphics::_CanvasImpl::GetInstance(*this); SysTryReturnResult(NID_UI, pCanvasImpl, E_OUT_OF_MEMORY, "Memory allocation failed."); - SysTryReturnResult(NID_UI, _VisualElementSurfaceImpl::GetInstance(surface), E_SYSTEM, "A system error has been occurred. Invalid surface."); + SysTryReturnResult(NID_UI, _VisualElementSurfaceImpl::GetInstance(*__pSurface), E_SYSTEM, "A system error has been occurred. Invalid surface."); - Handle window = _VisualElementSurfaceImpl::GetInstance(surface)->GetNativeHandle(); + Handle window = _VisualElementSurfaceImpl::GetInstance(*__pSurface)->GetNativeHandle(); #ifdef ENABLE_VE_EFL Tizen::Graphics::_Canvas* pNativeCanvas = pCanvasImpl->_pNativeCanvas; diff --git a/src/ui/animations/FUiAnim_VisualElementImpl.cpp b/src/ui/animations/FUiAnim_VisualElementImpl.cpp index a8ca3b4..e9a4ae8 100644 --- a/src/ui/animations/FUiAnim_VisualElementImpl.cpp +++ b/src/ui/animations/FUiAnim_VisualElementImpl.cpp @@ -909,7 +909,8 @@ _VisualElementImpl::CreateImplicitAnimation( const String& property, const Varia { pPropertyAnimation->SetEndValue(newValue); } - pPropertyAnimation->SetStartValue(Variant()); + //pPropertyAnimation->SetStartValue(Variant()); //default is empty + } // if (isCustomProperty) @@ -4757,8 +4758,11 @@ _VisualElementImpl::GetCanvasN(const FloatRectangle& bounds) // pRenderTarget->SetFlushNeeded(); // pRenderTarget->GetSharedData().pNativeNode->SetFlushNeeded(); - _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pSurface); - pSurfaceImpl->Invalidate(true); + + +// _VisualElementSurfaceImpl* pSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pSurface); +// pSurfaceImpl->Invalidate(true); + // pRenderTarget->GetRootPublic()->SetNeedsSurfaceUpdate(true); diff --git a/src/ui/animations/FUiAnim_VisualElementSurfaceManager.cpp b/src/ui/animations/FUiAnim_VisualElementSurfaceManager.cpp index 29f1729..ece7790 100644 --- a/src/ui/animations/FUiAnim_VisualElementSurfaceManager.cpp +++ b/src/ui/animations/FUiAnim_VisualElementSurfaceManager.cpp @@ -37,21 +37,24 @@ #ifdef VE_USE_GL_MULTI_CONTEXT #include "FUiAnim_GlContext.h" #endif +#ifdef ECORE_X_NATIVE +#include "FUiAnim_EcoreXLooper.h" +#endif + //#define PRINT(...) fprintf(stderr, __VA_ARGS__) #define PRINT(...) -#if 0 -static bool __checkCondition(bool condition) -{ - bool bCond = condition; - if(bCond == false) - { - return bCond; - } - return bCond; -} -#endif + +//static bool __checkCondition(bool condition) +//{ +// bool bCond = condition; +// if(bCond == false) +// { +// return bCond; +// } +// return bCond; +//} //#define ASSERT(__CONDITION__,...) {__checkCondition(__CONDITION__); SysAssertf(__CONDITION__,__VA_ARGS__);} #define ASSERT(...) SysAssertf(__VA_ARGS__) @@ -66,31 +69,39 @@ namespace Tizen { namespace Ui { namespace Animations _VisualElementSurfaceManager* _VisualElementSurfaceManager::__pInstance = null; void -_VisualElementSurfaceManager::Initialize(void) +_VisualElementSurfaceManager::CreateInstance(void) { if (!__pInstance) { - static _VisualElementSurfaceManager instance; - __pInstance = &instance; + __pInstance = new _VisualElementSurfaceManager; } } #ifdef __SHARED_CONTEXT__ void -_VisualElementSurfaceManager::Initialize(Handle nativeDisplay, Handle window,_GlContext& context) +_VisualElementSurfaceManager::CreateInstance(_GlContext& context) { if (!__pInstance) { - static _VisualElementSurfaceManager instance; - __pInstance = &instance; - __pInstance->__nativeDisplay = nativeDisplay; - __pInstance->__window = window; + __pInstance = new _VisualElementSurfaceManager; +#ifdef ECORE_X_NATIVE + _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance()); + Handle display = reinterpret_cast(pLooper->GetXDisplay()); + __pInstance->__nativeDisplay = display; +#endif __pInstance->InitializeManager(&context); - } } #endif +void +_VisualElementSurfaceManager::ReleaseInstance(void) +{ + if (!__pInstance) + { + __pInstance = null; + } +} _VisualElementSurfaceManager::_VisualElementSurfaceManager(void) #ifdef __SHARED_CONTEXT__ @@ -110,7 +121,18 @@ _VisualElementSurfaceManager::_VisualElementSurfaceManager(void) _VisualElementSurfaceManager::~_VisualElementSurfaceManager(void) { #ifdef __SHARED_CONTEXT__ - delete __pGlContext; + + _AutoMutex commandTransactionLock(__commandTransaction); + _AutoMutex commandLock(__commandLock); + + __commandId = COMMAND_EXIT; + __commandRequest.SendSignal(); + + __commandReply.WaitForSignal(&__commandLock); + + pthread_join(__threadInfo, NULL); + + #endif } @@ -217,6 +239,7 @@ _VisualElementSurfaceManager::ThreadProc(void* pData) break; case COMMAND_EXIT: PRINT("COMMAND_EXIT\n"); + pThis->CommandHandlerFinalizeManager(); goto exit_renderer; } @@ -242,6 +265,7 @@ exit_renderer: return null; } + bool _VisualElementSurfaceManager::InitializeManager(_GlContext* pContext) { @@ -324,10 +348,19 @@ _VisualElementSurfaceManager::DeleteTexture(TextureInfo* pTextureInfo) bool _VisualElementSurfaceManager::CommandHandlerInitializeManager(_GlContext* pContext) { - __pInstance->__pGlContext = _GlContext::CreateN(__nativeDisplay, __window, pContext); + __pGlContext = _GlContext::CreateN(*pContext); + return true; +} + +bool +_VisualElementSurfaceManager::CommandHandlerFinalizeManager(void) +{ + delete __pGlContext; + __pGlContext = null; return true; } + bool _VisualElementSurfaceManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer) { diff --git a/src/ui/animations/FUiAnim_VisualElementSurfaceManager.h b/src/ui/animations/FUiAnim_VisualElementSurfaceManager.h index 14c3f1e..0e6e2a8 100644 --- a/src/ui/animations/FUiAnim_VisualElementSurfaceManager.h +++ b/src/ui/animations/FUiAnim_VisualElementSurfaceManager.h @@ -68,11 +68,13 @@ public: }; #endif //__SHARED_CONTEXT__ - static void Initialize(void); + static void CreateInstance(void); #ifdef __SHARED_CONTEXT__ - static void Initialize(Handle nativeDisplay, Handle window,_GlContext& context); + static void CreateInstance(_GlContext& context); #endif + static void ReleaseInstance(void); + static _VisualElementSurfaceManager* GetInstance(void) { return __pInstance; @@ -91,6 +93,7 @@ public: private: bool IsSelfThread(void){ return pthread_equal(__threadInfo, pthread_self()); } bool CommandHandlerInitializeManager(_GlContext* pContext); + bool CommandHandlerFinalizeManager(void); bool CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer); bool CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer); diff --git a/src/ui/animations/platform/FUiAnim_EcoreXLooper.cpp b/src/ui/animations/platform/FUiAnim_EcoreXLooper.cpp index 6d5ad8e..ea3ba80 100644 --- a/src/ui/animations/platform/FUiAnim_EcoreXLooper.cpp +++ b/src/ui/animations/platform/FUiAnim_EcoreXLooper.cpp @@ -66,6 +66,7 @@ OnWakeUp(void* pData, int type, void* pEvent) Eina_Bool OnIdleEntered(void* pData) { + PRINT("OnIdlerEnter() \n"); if(_DisplayManager::GetInstance()->HasUpdates()) { PRINT("RAWEVENT_DRAW() \n"); @@ -89,16 +90,21 @@ OnIdleEntered(void* pData) _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance()); _RawEvent rawEvent; bool event = true; + int loop = 0; do { + PRINT("OnIdlerEnter() - Loop(%d)\n", loop); pLooper->MonitorEvents(); event = pLooper->PeekRawEvent(rawEvent, true); if (event) { pLooper->DispatchRawEvent(rawEvent); } + loop++; } while (event == true); + PRINT("OnIdlerEnter() - Exit\n"); + return EINA_TRUE; } diff --git a/src/ui/animations/platform/FUiAnim_Egl.cpp b/src/ui/animations/platform/FUiAnim_Egl.cpp index 0569047..15c4f0a 100644 --- a/src/ui/animations/platform/FUiAnim_Egl.cpp +++ b/src/ui/animations/platform/FUiAnim_Egl.cpp @@ -22,16 +22,13 @@ * This file contains implementation _Egl class. */ -#include -#include - #include #include #include "FUiAnim_GlVisualElementSurfaceImpl.h" #include "FUiAnim_VisualElementSurfaceManager.h" #include "FUiAnim_Egl.h" - +#include "FUiAnim_Debug.h" #if !defined(VE_SIMULATOR) && !defined(BUILD_UI_CORE) #include @@ -66,6 +63,7 @@ namespace Tizen { namespace Ui { namespace Animations { // depends on target #define NATIVE_PIXMAP_PADDING_VALUE 2 // Redwood old target //#define NATIVE_PIXMAP_PADDING_VALUE 32 // Redwood 8974 +#define SCREEN_SIZE (720*1280) _Egl::_Egl(Handle nativeDisplay, Handle window, _Egl* pSharedContext) : _GlContext(nativeDisplay, window) @@ -77,6 +75,12 @@ _Egl::_Egl(Handle nativeDisplay, Handle window, _Egl* pSharedContext) , __dummySurface(EGL_NO_SURFACE) , __nativeDummyPixmap(0) #endif +#ifdef USE_EGL_IMAGE + , __funcEglCreateImageKHR(null) + , __funcGlEglImageTargetTexture2DOES(null) + , __funcEglDestroyImageKhr(null) + , __cachePixmapSize(0) +#endif { SysAssertf(nativeDisplay, "Invalid display"); @@ -105,14 +109,18 @@ _Egl::_Egl(Handle nativeDisplay, Handle window, _Egl* pSharedContext) CheckBGRASupport(); InitGL(); - +#ifdef USE_EGL_IMAGE __nativePixmaps.Construct(); - + __deletedPixmaps.Construct(500); +#endif PRINT(">> _Egl:_Egl() \n"); } _Egl::~_Egl(void) { +#ifdef USE_EGL_IMAGE + CleanCacheIfNeeded(true); +#endif TerminateGL(); #ifndef BUILD_UI_CORE @@ -392,16 +400,129 @@ _Egl::DeleteDynamicTexture(TextureInfo* pTextureInfo) _PixmapInfo* pPixmapInfo = null; __nativePixmaps.GetValue(pTextureInfo->textureId, pPixmapInfo); + __nativePixmaps.Remove(pTextureInfo->textureId); + + if (pPixmapInfo) + { + AddToCache(*pPixmapInfo); + } +#endif +} +#ifdef USE_EGL_IMAGE +bool +_Egl::AddToCache(_PixmapInfo& pixmapInfo) +{ + if(pixmapInfo.__width * pixmapInfo.__height > (SCREEN_SIZE/2)) + { + DeletePixmapTexture(&pixmapInfo); + return false; + } + + if(__deletedPixmaps.Add(&pixmapInfo) != E_SUCCESS) + { + DeletePixmapTexture(&pixmapInfo); + return false; + } + __cachePixmapSize += pixmapInfo.__width * pixmapInfo.__height; + // if too big it should be deleted directly. + return true; +} + +bool +_Egl::PickPixmapFromCache(unsigned int textureId, TextureInfo &textureInfo) +{ + _PixmapInfo* pPixmapInfo = null; + int count = __deletedPixmaps.GetCount(); + for (int i = count-1 ; i >= 0; i--) //search form end + { + if (__deletedPixmaps.GetAt(i, pPixmapInfo) == E_SUCCESS) + { + // WARNING: is condition right? + if ( pPixmapInfo != null + && pPixmapInfo->__width == textureInfo.width + && pPixmapInfo->__height == textureInfo.height + && pPixmapInfo->__bitsPerPixel == textureInfo.bitsPerPixel) + { + __deletedPixmaps.RemoveAt(i); + __nativePixmaps.Add(textureId, pPixmapInfo); + textureInfo.pPixels = pPixmapInfo->__pPixels; + textureInfo.stride = pPixmapInfo->__stride; + pPixmapInfo->__reuseCount++; + + __funcGlEglImageTargetTexture2DOES(GL_TEXTURE_2D, pPixmapInfo->__eglImage); + PRINT("_Egl::CreateDynamicTexture found pixmap in the cache(%d) , return \n",i); + return true; + } + + } + } + return false; +} + +void +_Egl::CleanCacheIfNeeded(bool fullClean) +{ + _PixmapInfo* pPixmapInfo = null; + int count = __deletedPixmaps.GetCount(); + if(fullClean ==true ) + { + for (int i = 0 ; i < count; i++) + { + if (__deletedPixmaps.GetAt(i, pPixmapInfo) == E_SUCCESS) + { + if(pPixmapInfo != null) + { + DeletePixmapTexture(pPixmapInfo); + } + + } + } + __deletedPixmaps.RemoveAll(); + } + else + { + if(__cachePixmapSize >= SCREEN_SIZE*4) + { + for (int i = count ; i >=0 ; i--) + { + if (__deletedPixmaps.GetAt(i, pPixmapInfo) == E_SUCCESS) + { + if(pPixmapInfo != null) + { + if(pPixmapInfo->__reuseCount > 10) + { + pPixmapInfo->__reuseCount -=2; + continue; + } + + DeletePixmapTexture(pPixmapInfo); + } + __deletedPixmaps.RemoveAt(i); + + } + } + } + } +} + +void +_Egl::DeletePixmapTexture(_PixmapInfo* pPixmapInfo) +{ if (pPixmapInfo) { //TODO: member variable - PFNEGLDESTROYIMAGEKHRPROC funcEglDestroyImageKhr = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - SysTryReturnVoidResult(NID_GRP, funcEglDestroyImageKhr != null, E_SYSTEM, "Destroy ImageKHR failed."); + + if (!__funcEglDestroyImageKhr ) + { + __funcEglDestroyImageKhr = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); + } + + SysTryReturnVoidResult(NID_GRP, __funcEglDestroyImageKhr != null, E_SYSTEM, "Destroy ImageKHR failed."); PRINT("_Egl::DeleteTexture: pPixmapInfo = %p, eglImage = %p\n", pPixmapInfo, pPixmapInfo->__eglImage); - funcEglDestroyImageKhr(__display, pPixmapInfo->__eglImage); + __funcEglDestroyImageKhr(__display, pPixmapInfo->__eglImage); #ifdef VE_USE_NATIVE_BUFFER native_buffer_destroy((native_buffer_t*)pPixmapInfo->__pNativeBuffer); @@ -421,42 +542,50 @@ _Egl::DeleteDynamicTexture(TextureInfo* pTextureInfo) XFreePixmap((Display*)__nativeDisplay, pPixmapInfo->__nativePixmap); #endif - - __nativePixmaps.Remove(pTextureInfo->textureId); - delete pPixmapInfo; } -#endif + } +#endif bool _Egl::CreateDynamicTexture(unsigned int textureId, TextureInfo* pTextureInfo) { #ifdef USE_EGL_IMAGE _PixmapInfo* pPixmapInfo; + if (!__funcEglCreateImageKHR) + { + __funcEglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); + } + if (!__funcGlEglImageTargetTexture2DOES) + { + __funcGlEglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + } - PFNEGLCREATEIMAGEKHRPROC funcEglCreateImageKHR = - (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); - PFNGLEGLIMAGETARGETTEXTURE2DOESPROC funcGlEglImageTargetTexture2DOES = - (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); - SysAssertf((funcEglCreateImageKHR != null && funcGlEglImageTargetTexture2DOES != null), "eglImageKHR is not supported.") - + SysAssertf((__funcEglCreateImageKHR != null && __funcGlEglImageTargetTexture2DOES != null), "eglImageKHR is not supported."); // SysTryReturn(NID_UI_ANIM, (funcEglCreateImageKHR != null && funcGlEglImageTargetTexture2dOes != null), // E_UNSUPPORTED_OPERATION, "eglCreateImageKHR"); + if(PickPixmapFromCache(textureId, *pTextureInfo) == true) + { + return true; + } + CleanCacheIfNeeded(); + pPixmapInfo = CreateNativePixmap(pTextureInfo); SysTryReturn(NID_UI_ANIM, pPixmapInfo, false, E_INVALID_STATE, "Creating native pixmap failed."); EGLContext context = EGL_NO_CONTEXT;//__context; + #ifdef VE_USE_NATIVE_BUFFER - pPixmapInfo->__eglImage = funcEglCreateImageKHR(__display, context, EGL_NATIVE_BUFFER_TIZEN, (EGLClientBuffer)pPixmapInfo->__pNativeBuffer, NULL); + pPixmapInfo->__eglImage = __funcEglCreateImageKHR(__display, context, EGL_NATIVE_BUFFER_TIZEN, (EGLClientBuffer)pPixmapInfo->__pNativeBuffer, NULL); #else - pPixmapInfo->__eglImage = funcEglCreateImageKHR(__display, context, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)pPixmapInfo->__nativePixmap, NULL); + pPixmapInfo->__eglImage = __funcEglCreateImageKHR(__display, context, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)pPixmapInfo->__nativePixmap, NULL); #endif SysTryReturn(NID_UI_ANIM, pPixmapInfo->__eglImage != (EGLImageKHR)0, false, E_INVALID_STATE, "Creating ImageKHR failed."); - funcGlEglImageTargetTexture2DOES(GL_TEXTURE_2D, pPixmapInfo->__eglImage); + __funcGlEglImageTargetTexture2DOES(GL_TEXTURE_2D, pPixmapInfo->__eglImage); // Set surface info #ifdef VE_USE_NATIVE_BUFFER @@ -464,6 +593,7 @@ _Egl::CreateDynamicTexture(unsigned int textureId, TextureInfo* pTextureInfo) #else pTextureInfo->stride = (pTextureInfo->width + NATIVE_PIXMAP_PADDING_VALUE - 1) / NATIVE_PIXMAP_PADDING_VALUE * NATIVE_PIXMAP_PADDING_VALUE * pTextureInfo->bitsPerPixel / 8; #endif + pPixmapInfo->__stride = pTextureInfo->stride; __nativePixmaps.Add(textureId, pPixmapInfo); @@ -473,16 +603,20 @@ _Egl::CreateDynamicTexture(unsigned int textureId, TextureInfo* pTextureInfo) return false; #endif } - +#ifdef USE_EGL_IMAGE _Egl::_PixmapInfo* _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) { -#ifdef USE_EGL_IMAGE + _PixmapInfo* pPixmapInfo = null; pPixmapInfo = new (std::nothrow) _PixmapInfo(); SysTryReturn(NID_UI_ANIM, pPixmapInfo, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pPixmapInfo->__width = pTextureInfo->width; + pPixmapInfo->__height = pTextureInfo->height; + pPixmapInfo->__bitsPerPixel = pTextureInfo->bitsPerPixel; + #ifdef VE_USE_NATIVE_BUFFER pPixmapInfo->__pProvider = (void*)native_buffer_provider_create(NATIVE_BUFFER_PROVIDER_CORE); @@ -512,25 +646,18 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) pNativeDisplay = (Display*)__nativeDisplay; nativeWindow = DefaultRootWindow(pNativeDisplay); - PRINT("XXXXXXX-ERROR1 size(%d,%d)\n", pTextureInfo->width, pTextureInfo->height); pPixmapInfo->__nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, pTextureInfo->width, pTextureInfo->height, pTextureInfo->bitsPerPixel); if (pPixmapInfo->__nativePixmap == (Pixmap)0) { PRINT("Error 1!\n"); goto CATCH_01; } - PRINT("XXXXXXX-ERROR2\n"); DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->__nativePixmap); - PRINT("XXXXXXX-ERROR3\n"); XSync(pNativeDisplay, False); - PRINT("XXXXXXX-ERROR4\n"); - ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName); - PRINT("XXXXXXX-ERROR5\n"); free(pDriverName); - PRINT("XXXXXXX-ERROR6\n"); if (!ret || pDeviceName == null) { PRINT("Error 2!\n"); @@ -538,7 +665,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) } pPixmapInfo->__drmFd = open(pDeviceName, O_RDWR); - PRINT("XXXXXXX-ERROR7\n"); free(pDeviceName); if (pPixmapInfo->__drmFd < 0) { @@ -546,8 +672,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_02; } - PRINT("XXXXXXX-ERROR8\n"); - drmGetMagic(pPixmapInfo->__drmFd, &magic); ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic); if (!ret) @@ -556,8 +680,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_03; } - PRINT("XXXXXXX-ERROR9\n"); - pPixmapInfo->__pTbmBufMgr = (void*)tbm_bufmgr_init(pPixmapInfo->__drmFd); if (pPixmapInfo->__pTbmBufMgr == null) { @@ -565,8 +687,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_03; } - PRINT("XXXXXXX-ERROR10\n"); - pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->__nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount); if (pDri2Buffer == null) { @@ -574,7 +694,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_04; } - PRINT("XXXXXXX-ERROR11\n"); pPixmapInfo->__pTbmBufferObject = (void*)tbm_bo_import((tbm_bufmgr)pPixmapInfo->__pTbmBufMgr, pDri2Buffer->name); free(pDri2Buffer); if (pPixmapInfo->__pTbmBufferObject == null) @@ -583,8 +702,6 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_04; } - PRINT("XXXXXXX-ERROR12\n"); - tbmData = tbm_bo_get_handle((tbm_bo)pPixmapInfo->__pTbmBufferObject, TBM_DEVICE_CPU); if (tbmData.ptr == null) { @@ -592,14 +709,13 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo) goto CATCH_05; } - PRINT("XXXXXXX-ERROR13\n"); - pTextureInfo->pPixels = (unsigned long*)tbmData.ptr; if (pTextureInfo->pPixels == null) { PRINT("Error 9!\n"); goto CATCH_05; } + pPixmapInfo->__pPixels = pTextureInfo->pPixels; PRINT("_Egl::CreateNativePixmap: pPixels = 0x%p\n", pTextureInfo->pPixels); @@ -628,10 +744,9 @@ CATCH_01: SysLog(NID_UI_ANIM, "CreateNativePixmap failed!!"); #endif -#endif return null; } - +#endif }}} // Tizen::Ui::Animations diff --git a/src/ui/animations/platform/FUiAnim_Egl.h b/src/ui/animations/platform/FUiAnim_Egl.h index d46f2d3..047bb20 100644 --- a/src/ui/animations/platform/FUiAnim_Egl.h +++ b/src/ui/animations/platform/FUiAnim_Egl.h @@ -27,6 +27,8 @@ #include #include +#include +#include #include #include @@ -38,7 +40,7 @@ namespace Tizen { namespace Ui { namespace Animations { //#define VE_USE_NATIVE_BUFFER - +#define USE_EGL_IMAGE struct TextureInfo; class _Egl @@ -52,6 +54,7 @@ public: virtual void SwapBuffers(void) const; private: +#ifdef USE_EGL_IMAGE class _PixmapInfo { public: @@ -65,6 +68,11 @@ private: , __pTbmBufferObject(null) , __drmFd(0) #endif + , __width(0) + , __height(0) + , __stride(0) + , __bitsPerPixel(0) + , __pPixels(null) , __eglImage(null) { } @@ -79,9 +87,15 @@ private: void* __pTbmBufferObject; // tbm_bo int __drmFd; #endif + int __width; + int __height; + int __stride; + int __bitsPerPixel; + long __reuseCount; + unsigned long* __pPixels; EGLImageKHR __eglImage; }; - +#endif bool GetDisplay(Handle nativeDisplay); bool CreateContext(EGLContext sharedContext); EGLConfig GetConfig(bool useAlpha, bool useStencil, bool useDepth) const; @@ -92,8 +106,16 @@ private: virtual bool CreateDynamicTexture(unsigned int textureId, TextureInfo* pTextureInfo); virtual void DeleteDynamicTexture(TextureInfo *pTextureInfo); +#ifdef USE_EGL_IMAGE _PixmapInfo* CreateNativePixmap(TextureInfo *pTextureInfo); - +#endif +private: +#ifdef USE_EGL_IMAGE + void DeletePixmapTexture(_PixmapInfo* pPixmapInfo); + bool AddToCache(_PixmapInfo& pixmapInfo); + bool PickPixmapFromCache(unsigned int textureId, TextureInfo &textureInfo); + void CleanCacheIfNeeded(bool fullClean = false); +#endif private: EGLDisplay __display; EGLContext __context; @@ -104,9 +126,15 @@ private: EGLSurface __dummySurface; Handle __nativeDummyPixmap; // for dummy #endif +#ifdef USE_EGL_IMAGE + PFNEGLCREATEIMAGEKHRPROC __funcEglCreateImageKHR; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC __funcGlEglImageTargetTexture2DOES ; + PFNEGLDESTROYIMAGEKHRPROC __funcEglDestroyImageKhr; Tizen::Base::Collection::HashMapT __nativePixmaps; - + Tizen::Base::Collection::ArrayListT<_PixmapInfo*> __deletedPixmaps; + unsigned long __cachePixmapSize; +#endif friend class _GlRenderManager; }; diff --git a/src/ui/animations/platform/FUiAnim_GlContext.cpp b/src/ui/animations/platform/FUiAnim_GlContext.cpp index c789d0e..5887499 100644 --- a/src/ui/animations/platform/FUiAnim_GlContext.cpp +++ b/src/ui/animations/platform/FUiAnim_GlContext.cpp @@ -60,14 +60,14 @@ _GlContext* _GlContext::__pInstance = null; #endif _GlContext* -_GlContext::CreateN(Handle nativeDisplay, Handle window, _GlContext* pSharedContext) +_GlContext::CreateN(Handle nativeDisplay, Handle window) { SysAssertf(nativeDisplay, "Invalid display"); _GlContext* pGlContext = null; #ifndef BUILD_UI_CORE - pGlContext = new (std::nothrow) _Egl(nativeDisplay, window, dynamic_cast<_Egl*>(pSharedContext)); + pGlContext = new (std::nothrow) _Egl(nativeDisplay, window,null); #elif _WIN32 pGlContext = new (std::nothrow) _Wgl(nativeDisplay, window); #elif LINUX @@ -75,19 +75,29 @@ _GlContext::CreateN(Handle nativeDisplay, Handle window, _GlContext* pSharedCont //#elif // pGlContext = new (std::nothrow) _Agl(nativeDisplay, window); #endif - if(_VisualElementSurfaceManager::GetInstance() == null) - { -#ifdef __SHARED_CONTEXT__ - _VisualElementSurfaceManager::Initialize(nativeDisplay,window, *pGlContext); -#else - _VisualElementSurfaceManager::Initialize(); + return pGlContext; +} + +_GlContext* +_GlContext::CreateN(_GlContext& sharedContext) +{ + _GlContext* pGlContext = null; + +#ifndef BUILD_UI_CORE + pGlContext = new (std::nothrow) _Egl(sharedContext.__nativeDisplay, sharedContext.__window, dynamic_cast<_Egl*>(&sharedContext)); +#elif _WIN32 + pGlContext = new (std::nothrow) _Wgl(sharedContext.__nativeDisplay, sharedContext.__window);// to do implementation +#elif LINUX + pGlContext = new (std::nothrow) _Xgl(sharedContext.__nativeDisplay, sharedContext.__window);// to do implementation +//#elif +// pGlContext = new (std::nothrow) _Agl(nativeDisplay, window); #endif - } return pGlContext; } _GlContext::_GlContext(Handle nativeDisplay, Handle window) : __nativeDisplay(nativeDisplay) + , __window(window) , __supportBGRA8888(false) , __useBlend(false) , __useStencil(false) @@ -131,7 +141,7 @@ _GlContext::CreateInstance(Handle nativeDisplay) { SysTryReturnResult(NID_UI_ANIM, !__pInstance, E_OBJ_ALREADY_EXIST, "The GL context already created."); - __pInstance = _GlContext::CreateN(nativeDisplay, null, null); + __pInstance = _GlContext::CreateN(nativeDisplay, null); if (!__pInstance) { return E_OUT_OF_MEMORY; @@ -488,17 +498,16 @@ _GlContext::CreateTexture(TextureInfo* pTextureInfo) void _GlContext::UpdateTexture(TextureInfo* pTextureInfo) { -#ifndef USE_EGL_IMAGE + // BindTexture(pTextureInfo->textureId); -// if (pTextureInfo->type == TEXTURE_EGL_NORMAL && pTextureInfo->updated) +// if (pTextureInfo->type == TEXTURE_NORMAL && pTextureInfo->updated) if (pTextureInfo->type == TEXTURE_NORMAL) { LoadTexture(pTextureInfo, false); pTextureInfo->updated = false; } -#endif } void diff --git a/src/ui/animations/platform/FUiAnim_X11.cpp b/src/ui/animations/platform/FUiAnim_X11.cpp index b554e3f..96fd716 100644 --- a/src/ui/animations/platform/FUiAnim_X11.cpp +++ b/src/ui/animations/platform/FUiAnim_X11.cpp @@ -15,8 +15,8 @@ using namespace Tizen::Base; using namespace Tizen::Graphics; using namespace Tizen::Ui; -#define PRINT(...) fprintf(stderr,__VA_ARGS__) -//#define PRINT printf +//#define PRINT(...) fprintf(stderr,__VA_ARGS__) +#define PRINT(...) namespace Tizen { namespace Ui { namespace Animations { diff --git a/src/ui/inc/FUiAnim_VisualElementCanvas.h b/src/ui/inc/FUiAnim_VisualElementCanvas.h index 21468ad..63246f8 100644 --- a/src/ui/inc/FUiAnim_VisualElementCanvas.h +++ b/src/ui/inc/FUiAnim_VisualElementCanvas.h @@ -50,6 +50,8 @@ public: private: _VisualElementCanvas(const _VisualElementCanvas& rhs); _VisualElementCanvas& operator =(const _VisualElementCanvas& rhs); +private: + VisualElementSurface* __pSurface; }; // _VisualElementCanvas -- 2.7.4