The surface handling logic is seperated form the glRenderManager
authorDae Young Ryu <karzia@samsung.com>
Tue, 18 Feb 2014 09:10:14 +0000 (18:10 +0900)
committerDae Young Ryu <karzia@samsung.com>
Tue, 18 Feb 2014 09:10:14 +0000 (18:10 +0900)
Change-Id: I00419dd75c75cf2636f762dea9b605d0993ac4ba
Signed-off-by: Dae Young Ryu <karzia@samsung.com>
src/ui/animations/FUiAnim_DisplayManager.cpp
src/ui/animations/FUiAnim_GlContext.h
src/ui/animations/FUiAnim_GlLayer.cpp
src/ui/animations/FUiAnim_GlLayer.h
src/ui/animations/FUiAnim_GlRenderManager.cpp
src/ui/animations/FUiAnim_VisualElementSurfaceManager.cpp
src/ui/animations/FUiAnim_VisualElementSurfaceManager.h
src/ui/animations/platform/FUiAnim_Egl.cpp
src/ui/animations/platform/FUiAnim_Egl.h
src/ui/animations/platform/FUiAnim_GlContext.cpp

index e9e0eb2..c66d363 100644 (file)
@@ -80,7 +80,7 @@ _DisplayManager::_DisplayManager(void)
 {
 
        _VisualElementEnvironment::Initialize();
-       _VisualElementSurfaceManager::Initialize();
+
 
        __layers.Construct();
 
@@ -115,6 +115,7 @@ _DisplayManager::CreateInstance(void)
 
        _GlRenderManager::CreateInstance();
        //_GlRenderManager::GetInstance()->SyncRenderManager();
+
 #ifndef _WIN32
 #ifdef ECORE_X_NATIVE
        _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance());
index b648f8f..e0ee357 100644 (file)
@@ -34,6 +34,9 @@
 #ifdef _OSP_ARMEL_
 #define USE_EGL_IMAGE
 #endif
+#ifndef _OSP_EMUL_
+#define __SHARED_CONTEXT__
+#endif
 
 namespace Tizen { namespace Ui { namespace Animations
 {
@@ -51,7 +54,7 @@ struct TextureInfo;
 class _GlContext
 {
 public:
-       static _GlContext* CreateN(Handle nativeDisplay, Handle window);
+       static _GlContext* CreateN(Handle nativeDisplay, Handle window, _GlContext* pSharedContext);
 
 #ifndef VE_USE_GL_MULTI_CONTEXT
        static _GlContext* GetInstance(void)
@@ -102,6 +105,8 @@ public:
        ShaderProgram* GetTextureShaderAlphaMaskExtra1(const ShaderProgramIndex& index);
        ShaderProgram* GetTextureShaderAlphaMaskExtra2(const ShaderProgramIndex& index);
 
+       Handle GetNativeDisplay(void) const {return __nativeDisplay;}
+
 protected:
        _GlContext(Handle nativeDisplay, Handle window);
        virtual ~_GlContext(void);
@@ -160,6 +165,7 @@ private:
 #endif
 
        friend class _GlRenderManager;
+       friend class _VisualElementSurfaceManager;
 };
 
 }}} //namespace Tizen { namespace Ui { namespace Animations
index b1f008d..3e5935c 100644 (file)
@@ -34,6 +34,7 @@
 #include "FUiAnim_AnimationManager.h"
 #include "FUiAnim_DisplayManager.h"
 #include "FUiAnim_GlRenderManager.h"
+#include "FUiAnim_VisualElementSurfaceManager.h"
 #include "FUi_Math.h"
 
 using namespace Tizen;
@@ -70,7 +71,11 @@ _GlLayer::_GlLayer(void)
 
 _GlLayer::~_GlLayer(void)
 {
+#ifdef __SHARED_CONTEXT__
+       _VisualElementSurfaceManager::GetInstance()->FinalizeGLLayer(this);
+#endif
        _GlRenderManager::GetInstance()->FinalizeGLLayer(this);
+
 }
 
 
@@ -83,7 +88,13 @@ _GlLayer::OnConstructed(void)
 
                return E_INVALID_STATE; // CHECKME:
        }
+#ifdef __SHARED_CONTEXT__
+       if (!_VisualElementSurfaceManager::GetInstance()->InitializeGLLayer(this))
+       {
 
+               return E_INVALID_STATE; // CHECKME:
+       }
+#endif
        __reconfigureNeeded = true;
 
 //     SetShowState(true);
index f63613c..8561dca 100644 (file)
@@ -106,6 +106,7 @@ private:
 #endif
 
        friend class _GlRenderManager;
+       friend class _VisualElementSurfaceManager;
 };
 
 }}} //namespace Tizen { namespace Ui { namespace Animations
index 032c821..cdeddfe 100644 (file)
@@ -79,10 +79,22 @@ using namespace Tizen::Ui::Animations;
 //#define PRINT(...) fprintf(stderr, __VA_ARGS__)
 #define PRINT(...)
 
+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__)
+
 #ifdef VE_USE_GL_MULTI_CONTEXT
-#define        CHECK_GL_CONTEXT(pGlContext)    SysAssertf(pGlContext, "Invalid render manager status(no context)");
+#define        CHECK_GL_CONTEXT(pGlContext)    ASSERT(pGlContext, "Invalid render manager status(no context)");
 #else
-#define        CHECK_GL_CONTEXT()      SysAssertf(__pGlContext, "Invalid render manager status(no context)");
+#define        CHECK_GL_CONTEXT()      ASSERT(__pGlContext, "Invalid render manager status(no context)");
 #endif
 
 #define VERTEX_BUFFER_STRIDE           3
@@ -793,7 +805,7 @@ _GlRenderManager::_GlRenderManager(void)
        memset(&__threadInfo, 0x00, sizeof(pthread_t));
        if (pthread_create(&__threadInfo, NULL, _GlRenderManager::RenderProc, this) != 0)
        {
-               SysAssertf(false, "Creating render-thread failed");
+               ASSERT(false, "Creating render-thread failed");
        }
 
        __eyePosition[0] = 0.0f;
@@ -897,6 +909,11 @@ _GlRenderManager::CreateTexture(TextureInfo* pTextureInfo)
        _AutoMutex commandTransactionLock(__commandTransaction);
        _AutoMutex commandLock(__commandLock);
 
+       PRINT("ZZZZZZZZZZ-Texture[Type:%d],bounds(%d,%d,%d,%d) textureId(%x)\n",
+                 pTextureInfo->type,
+                 pTextureInfo->x, pTextureInfo->y, pTextureInfo->width, pTextureInfo->height,
+                 pTextureInfo->textureId);
+
        __commandId = COMMAND_CREATE_TEXTURE;
        __commandArg.__pCommandTextureInfo = pTextureInfo;
        __commandRequest.SendSignal();
@@ -1783,7 +1800,7 @@ _GlRenderManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer)
 #ifdef VE_USE_GL_MULTI_CONTEXT
 #ifdef ECORE_X_NATIVE
        _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance());
-       pGlLayer->__pContext = _GlContext::CreateN((Handle)pLooper->GetXDisplay(), (Handle)pGlLayer->GetNativeWindow());
+       pGlLayer->__pContext = _GlContext::CreateN((Handle)pLooper->GetXDisplay(), (Handle)pGlLayer->GetNativeWindow(), null);
 
        PRINT("[DEBUG]-003a _GlRenderManager::CommandHandlerInitializeGLLayer: Create surf...  \n" );
 #endif
@@ -1794,13 +1811,15 @@ _GlRenderManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer)
 #else
        CHECK_GL_CONTEXT();
 
-       SysAssertf(!pGlLayer->__surface, "");
+       ASSERT(!pGlLayer->__surface, "");
 
        PRINT("[DEBUG]-003 _GlRenderManager::CommandHandlerInitializeGLLayer: Create surf...  \n" );
 
        // TODO: jinstar
        //////////pGlLayer->__surface = __pGlContext->CreateWindowSurface( (Handle)pGlLayer->GetNativeWindow() );
+#ifndef __SHARED_CONTEXT__
        pGlLayer->__surface = __pGlContext->CreateWindowSurface( (Handle)pGlLayer->GetWindowHandle() );
+#endif
 
        PRINT(">> CommandHandlerInitializeGLLayer() surface %p \n", (void*)pGlLayer->__surface);
 #endif
@@ -1824,9 +1843,12 @@ _GlRenderManager::CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer)
 
        if (pGlLayer->__surface)
        {
+#ifndef __SHARED_CONTEXT__
                __pGlContext->DestroySurface((Handle)pGlLayer->__surface);
                pGlLayer->__surface = null;
+#endif //__SHARED_CONTEXT__
        }
+
 #endif
 
        return true;
@@ -2044,7 +2066,7 @@ _GlRenderManager::RenderProc(void* pData)
 
                        if (unlikely(pThis->__commandId == COMMAND_UNKNOWN))
                        {
-                               SysAssertf(!gotCommand, "No command sent, but got command !");
+                               ASSERT(!gotCommand, "No command sent, but got command !");
 
                                commandId = COMMAND_COMPOSITE;
                                commandArg = pThis->__commandArg;       // to avoid complier warning
index 8a4171e..da29c03 100644 (file)
 #include "FUiAnim_GlVisualElementSurfaceImpl.h"
 #include "FUiAnim_VisualElementSurfaceManager.h"
 
+#include "FUiAnim_GlContext.h"
+
 #ifdef VE_USE_GL_MULTI_CONTEXT
 #include "FUiAnim_GlContext.h"
 #endif
 
+//#define PRINT(...) fprintf(stderr, __VA_ARGS__)
+#define PRINT(...)
+
+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__)
+
 using namespace std;
 using namespace Tizen::Base;
 using namespace Tizen::Graphics;
@@ -55,12 +72,43 @@ _VisualElementSurfaceManager::Initialize(void)
        }
 }
 
+#ifdef __SHARED_CONTEXT__
+void
+_VisualElementSurfaceManager::Initialize(Handle nativeDisplay, Handle window,_GlContext& context)
+{
+       if (!__pInstance)
+       {
+               static _VisualElementSurfaceManager instance;
+               __pInstance = &instance;
+               __pInstance->__nativeDisplay  = nativeDisplay;
+               __pInstance->__window  = window;
+               __pInstance->InitializeManager(&context);
+
+       }
+}
+#endif
+
+
 _VisualElementSurfaceManager::_VisualElementSurfaceManager(void)
+#ifdef __SHARED_CONTEXT__
+       : __pGlContext(null)
+#endif
 {
+#ifdef __SHARED_CONTEXT__
+       memset(&__threadInfo, 0x00, sizeof(pthread_t));
+       if (pthread_create(&__threadInfo, NULL, _VisualElementSurfaceManager::ThreadProc, this) != 0)
+       {
+               ASSERT(false, "Creating surface-manager-thread failed");
+       }
+#endif
+
 }
 
 _VisualElementSurfaceManager::~_VisualElementSurfaceManager(void)
 {
+#ifdef __SHARED_CONTEXT__
+       delete __pGlContext;
+#endif
 }
 
 result
@@ -73,9 +121,13 @@ _VisualElementSurfaceManager::CreateSurface(_GlVisualElementSurfaceImpl* pGlSurf
                pTextureInfo->pPixels = (unsigned long*) new (std::nothrow) unsigned char[pTextureInfo->stride * pTextureInfo->height];
                SysTryReturnResult(NID_UI_ANIM, pTextureInfo->pPixels, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
        }
+#ifdef __SHARED_CONTEXT__
 
+       PRINT(">> _VisualElementSurfaceManager::CreateSurface() texture id %u \n", pTextureInfo->textureId);
+       CreateTexture(pTextureInfo);
+#else
        _GlRenderManager::GetInstance()->CreateTexture(pTextureInfo);
-
+#endif
        return E_SUCCESS;
 }
 
@@ -83,8 +135,13 @@ result
 _VisualElementSurfaceManager::DestroySurface(_GlVisualElementSurfaceImpl* pGlSurface)
 {
        TextureInfo* pTextureInfo = (TextureInfo*)pGlSurface->GetNativeHandle();
+#ifdef __SHARED_CONTEXT__
+       PRINT(">> _VisualElementSurfaceManager::DestroySurface() texture id %u \n", pTextureInfo->textureId);
 
+       DeleteTexture(pTextureInfo);
+#else
        _GlRenderManager::GetInstance()->DeleteTexture(pTextureInfo);
+#endif
 
        if (pTextureInfo->type == TEXTURE_NORMAL)
        {
@@ -95,5 +152,237 @@ _VisualElementSurfaceManager::DestroySurface(_GlVisualElementSurfaceImpl* pGlSur
        return E_SUCCESS;
 }
 
+
+#ifdef __SHARED_CONTEXT__
+void*
+_VisualElementSurfaceManager::ThreadProc(void* pData)
+{
+       PRINT(">> _GlRenderManager::RenderProc starts. \n");
+
+       _VisualElementSurfaceManager* pThis = reinterpret_cast< _VisualElementSurfaceManager* >(pData);
+
+
+       for (;;)
+       {
+               bool needReply = true;
+               SurfaceCommand commandId;
+               CommandArg commandArg;
+               bool gotCommand = true;
+
+               {
+                       _AutoMutex commandLock(pThis->__commandLock);
+
+                       while (pThis->__commandId == COMMAND_UNKNOWN && gotCommand)
+                       {
+                               gotCommand = pThis->__commandRequest.WaitForSignal(&pThis->__commandLock, -1);
+                       }
+
+                       commandId = pThis->__commandId;
+                       commandArg = pThis->__commandArg;
+
+
+//                     PRINT(">> command = %d, gotCommand = %d\n", pThis->__commandId, gotCommand);
+
+                       // clear command
+                       pThis->__commandId = COMMAND_UNKNOWN;
+               }
+
+               // ...........
+               switch (commandId)
+               {
+               case COMMAND_INITIALIZE_MANAGER:
+                       pThis->CommandHandlerInitializeManager(commandArg.__pCommandGlContext);
+                       break;
+               case COMMAND_INITIALIZE_GLLAYER:
+                       pThis->CommandHandlerInitializeGLLayer(commandArg.__pCommandGlLayer);
+                       break;
+
+               case COMMAND_FINALIZE_GLLAYER:
+                       pThis->CommandHandlerFinalizeGLLayer(commandArg.__pCommandGlLayer);
+                       break;
+
+               case COMMAND_CREATE_TEXTURE:
+                       pThis->CommandHandlerCreateTexture(commandArg.__pCommandTextureInfo);
+                       break;
+
+               case COMMAND_DELETE_TEXTURE:
+                       pThis->CommandHandlerDeleteTexture(commandArg.__pCommandTextureInfo);
+                       break;
+               default:
+                       PRINT("UNKNOWN COMMAND (%d)\n", commandId);
+                       needReply = false;
+                       break;
+               case COMMAND_EXIT:
+                       PRINT("COMMAND_EXIT\n");
+                       goto exit_renderer;
+               }
+
+               if (needReply)
+               {
+                       _AutoMutex commandLock(pThis->__commandLock);
+
+                       pThis->__commandResult = E_SUCCESS;
+                       pThis->__commandReply.SendSignal();
+               }
+       }
+exit_renderer:
+
+       delete pThis->__pGlContext;
+
+       {
+               _AutoMutex commandLock(pThis->__commandLock);
+
+               pThis->__commandResult = E_SUCCESS;
+               pThis->__commandReply.SendSignal();
+       }
+
+       return null;
+
+}
+bool
+_VisualElementSurfaceManager::InitializeManager(_GlContext* pContext)
+{
+       if (unlikely(IsSelfThread()))
+       {
+               return CommandHandlerInitializeManager(pContext);
+       }
+
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_INITIALIZE_MANAGER;
+       __commandArg.__pCommandGlContext = pContext;
+       __commandRequest.SendSignal();
+       __commandReply.WaitForSignal(&__commandLock);
+       return (__commandResult == E_SUCCESS);
+}
+
+bool
+_VisualElementSurfaceManager::InitializeGLLayer(_GlLayer* pGlLayer)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_INITIALIZE_GLLAYER;
+       __commandArg.__pCommandGlLayer = pGlLayer;
+       __commandRequest.SendSignal();
+
+       __commandReply.WaitForSignal(&__commandLock);
+       return (__commandResult == E_SUCCESS);
+}
+
+bool
+_VisualElementSurfaceManager::FinalizeGLLayer(_GlLayer* pGlLayer)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_FINALIZE_GLLAYER;
+       __commandArg.__pCommandGlLayer = pGlLayer;
+       __commandRequest.SendSignal();
+
+       __commandReply.WaitForSignal(&__commandLock);
+       return (__commandResult == E_SUCCESS);
+}
+
+bool
+_VisualElementSurfaceManager::CreateTexture(TextureInfo* pTextureInfo)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_CREATE_TEXTURE;
+       __commandArg.__pCommandTextureInfo = pTextureInfo;
+       __commandRequest.SendSignal();
+       __commandReply.WaitForSignal(&__commandLock);
+       return (__commandResult == E_SUCCESS);
+}
+
+bool
+_VisualElementSurfaceManager::DeleteTexture(TextureInfo* pTextureInfo)
+{
+       // WARNING: Surface can be deleted in render thread because of reference-counting
+       // FIXME: Need to add inline method or macro to determine of current thread is render thread
+       if (unlikely(IsSelfThread()))
+       {
+               return CommandHandlerDeleteTexture(pTextureInfo);
+       }
+
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_DELETE_TEXTURE;
+       __commandArg.__pCommandTextureInfo = pTextureInfo;
+       __commandRequest.SendSignal();
+       __commandReply.WaitForSignal(&__commandLock);
+       return (__commandResult == E_SUCCESS);
+}
+
+bool
+_VisualElementSurfaceManager::CommandHandlerInitializeManager(_GlContext* pContext)
+{
+       __pInstance->__pGlContext = _GlContext::CreateN(__nativeDisplay, __window, pContext);
+       return true;
+}
+
+bool
+_VisualElementSurfaceManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer)
+{
+
+       ASSERT(!pGlLayer->__surface, "");
+
+       PRINT("[DEBUG]-003 _VisualElementSurfaceManager::CommandHandlerInitializeGLLayer: Create surf...  \n" );
+
+       // TODO: jinstar
+       //////////pGlLayer->__surface = __pGlContext->CreateWindowSurface( (Handle)pGlLayer->GetNativeWindow() );
+       __pGlContext->MakeCurrent();
+
+       pGlLayer->__surface = __pGlContext->CreateWindowSurface( (Handle)pGlLayer->GetWindowHandle() );
+
+       PRINT(">> CommandHandlerInitializeGLLayer() surface %p \n", (void*)pGlLayer->__surface);
+
+
+       return true;
+}
+
+bool
+_VisualElementSurfaceManager::CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer)
+{
+
+       PRINT(">> CommandHandlerFinalizeGLLayer() surface %p \n", (void*)pGlLayer->__surface);
+       __pGlContext->MakeCurrent();
+
+       if (pGlLayer->__surface)
+       {
+               __pGlContext->DestroySurface((Handle)pGlLayer->__surface);
+               pGlLayer->__surface = null;
+       }
+       return true;
+}
+
+bool
+_VisualElementSurfaceManager::CommandHandlerCreateTexture(TextureInfo* pTextureInfo)
+{
+
+       PRINT(">> CommandHandlerCreateTexture() \n");
+       __pGlContext->MakeCurrent();
+
+       return __pGlContext->CreateTexture(pTextureInfo);
+
+}
+
+bool
+_VisualElementSurfaceManager::CommandHandlerDeleteTexture(TextureInfo* pTextureInfo)
+{
+
+       PRINT(">> CommandHandlerDeleteTexture() texture id %u \n", pTextureInfo->textureId);
+
+       __pGlContext->MakeCurrent();
+       __pGlContext->DeleteTexture(pTextureInfo);
+
+
+       return true;
+}
+#endif //__SHARED_CONTEXT__
 }}}            // Tizen::Ui::Animations
 
index 9c0abd4..14c3f1e 100644 (file)
 #ifndef _FUI_ANIM_INTERNAL_VISUAL_ELEMENT_SURFACE_MANAGER_H_
 #define _FUI_ANIM_INTERNAL_VISUAL_ELEMENT_SURFACE_MANAGER_H_
 
+
+
+
+
 #include <FBaseColArrayListT.h>
+#include "FUiAnim_GlContext.h"
+
+#ifdef __SHARED_CONTEXT__
+#include <pthread.h>
+#include "FUiAnim_Waiter.h"
+#endif
 
 namespace Tizen { namespace Base
 {
@@ -34,8 +44,9 @@ namespace Tizen { namespace Base
 
 namespace Tizen { namespace Ui { namespace Animations
 {
-
+class _GlContext;
 class _GlVisualElementSurfaceImpl;
+
 //struct TextureInfo;
 
 class _VisualElementSurfaceManager
@@ -44,7 +55,23 @@ public:
        virtual ~_VisualElementSurfaceManager(void);
 
 public:
+#ifdef __SHARED_CONTEXT__
+       enum SurfaceCommand
+       {
+               COMMAND_UNKNOWN,
+               COMMAND_INITIALIZE_MANAGER,
+               COMMAND_EXIT,
+               COMMAND_INITIALIZE_GLLAYER,
+               COMMAND_FINALIZE_GLLAYER,
+               COMMAND_CREATE_TEXTURE,
+               COMMAND_DELETE_TEXTURE
+       };
+#endif //__SHARED_CONTEXT__
+
        static void Initialize(void);
+#ifdef __SHARED_CONTEXT__
+       static void Initialize(Handle nativeDisplay, Handle window,_GlContext& context);
+#endif
 
        static _VisualElementSurfaceManager* GetInstance(void)
        {
@@ -54,6 +81,23 @@ public:
        result CreateSurface(_GlVisualElementSurfaceImpl* pGlSurface);
        result DestroySurface(_GlVisualElementSurfaceImpl* pGlSurface);
 
+#ifdef __SHARED_CONTEXT__
+       static void* ThreadProc(void* pData);
+       bool InitializeManager(_GlContext* pContext);
+       bool InitializeGLLayer(_GlLayer* pGlLayer);
+       bool FinalizeGLLayer(_GlLayer* pGlLayer);
+       bool CreateTexture(TextureInfo* pTextureInfo);
+       bool DeleteTexture(TextureInfo* pTextureInfo);
+private:
+       bool IsSelfThread(void){ return pthread_equal(__threadInfo, pthread_self()); }
+       bool CommandHandlerInitializeManager(_GlContext* pContext);
+       bool CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer);
+       bool CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer);
+
+       bool CommandHandlerCreateTexture(TextureInfo* pTextureInfo);
+       bool CommandHandlerDeleteTexture(TextureInfo* pTextureInfo);
+
+#endif
 private:
        _VisualElementSurfaceManager(void);
        _VisualElementSurfaceManager(const _VisualElementSurfaceManager& rhs);
@@ -77,6 +121,27 @@ private:
 
        AtlasListT __atlasList;
 #endif
+#ifdef __SHARED_CONTEXT__
+       typedef union
+       {
+               _GlLayer* __pCommandGlLayer;
+               TextureInfo* __pCommandTextureInfo;
+               _GlContext* __pCommandGlContext;
+       } CommandArg;
+       pthread_t __threadInfo;
+       _GlContext* __pGlContext;
+       SurfaceCommand __commandId;
+       CommandArg __commandArg;
+       result __commandResult;
+
+       _Mutex __commandTransaction;
+       _Mutex __commandLock;
+       _Waiter __commandRequest;
+       _Waiter __commandReply;
+
+       Handle __nativeDisplay;
+       Handle __window;
+#endif //__SHARED_CONTEXT__
 };             // _VisualElementSurfaceManager
 
 }}}            // Tizen::Ui::Animations
index 0542c44..0569047 100644 (file)
@@ -67,7 +67,7 @@ namespace Tizen { namespace Ui { namespace Animations {
 #define NATIVE_PIXMAP_PADDING_VALUE            2       // Redwood old target
 //#define NATIVE_PIXMAP_PADDING_VALUE          32      // Redwood 8974
 
-_Egl::_Egl(Handle nativeDisplay, Handle window)
+_Egl::_Egl(Handle nativeDisplay, Handle window, _Egl* pSharedContext)
        : _GlContext(nativeDisplay, window)
        ,  __display(EGL_NO_DISPLAY)
        , __context(EGL_NO_CONTEXT)
@@ -81,7 +81,7 @@ _Egl::_Egl(Handle nativeDisplay, Handle window)
        SysAssertf(nativeDisplay, "Invalid display");
 
        SysAssertf(GetDisplay(nativeDisplay), "Failed to get display.");
-       SysAssertf(CreateContext(), "Failed to create context.");
+       SysAssertf(CreateContext((pSharedContext)?pSharedContext->__context : EGL_NO_CONTEXT), "Failed to create context.");
 
        if (window)
        {
@@ -225,12 +225,12 @@ _Egl::GetDisplay(Handle nativeDisplay)
 }
 
 bool
-_Egl::CreateContext(void)
+_Egl::CreateContext(EGLContext sharedContext)
 {
        if (__context != EGL_NO_CONTEXT)
                return true;
 
-       EGLint eglContextList[] =
+       EGLint eglAttributeList[] =
        {
                EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL_NONE
@@ -243,7 +243,7 @@ _Egl::CreateContext(void)
                return false;
        }
        
-       __context = eglCreateContext(__display, __config, EGL_NO_CONTEXT, eglContextList);
+       __context = eglCreateContext(__display, __config, sharedContext/*EGL_NO_CONTEXT*/, eglAttributeList);
        if (__context == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS)
        {
                SysLog(NID_UI_ANIM, "eglCreateContext failed.");
@@ -446,12 +446,14 @@ _Egl::CreateDynamicTexture(unsigned int textureId, TextureInfo* pTextureInfo)
 
        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, EGL_NO_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, EGL_NO_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);
@@ -510,18 +512,25 @@ _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");
@@ -529,6 +538,7 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo)
        }
 
        pPixmapInfo->__drmFd = open(pDeviceName, O_RDWR);
+       PRINT("XXXXXXX-ERROR7\n");
        free(pDeviceName);
        if (pPixmapInfo->__drmFd < 0)
        {
@@ -536,6 +546,8 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo)
                goto CATCH_02;
        }
 
+       PRINT("XXXXXXX-ERROR8\n");
+
        drmGetMagic(pPixmapInfo->__drmFd, &magic);
        ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
        if (!ret)
@@ -544,6 +556,8 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo)
                goto CATCH_03;
        }
 
+       PRINT("XXXXXXX-ERROR9\n");
+
        pPixmapInfo->__pTbmBufMgr = (void*)tbm_bufmgr_init(pPixmapInfo->__drmFd);
        if (pPixmapInfo->__pTbmBufMgr == null)
        {
@@ -551,6 +565,8 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo)
                goto CATCH_03;
        }
 
+       PRINT("XXXXXXX-ERROR10\n");
+
        pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->__nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
        if (pDri2Buffer == null)
        {
@@ -558,6 +574,7 @@ _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)
@@ -566,6 +583,8 @@ _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)
        {
@@ -573,6 +592,8 @@ _Egl::CreateNativePixmap(TextureInfo *pTextureInfo)
                goto CATCH_05;
        }
 
+       PRINT("XXXXXXX-ERROR13\n");
+
        pTextureInfo->pPixels = (unsigned long*)tbmData.ptr;
        if (pTextureInfo->pPixels == null)
        {
index 6c5d3e4..d46f2d3 100644 (file)
@@ -45,7 +45,7 @@ class _Egl
                : public _GlContext
 {
 public:
-       _Egl(Handle nativeDisplay, Handle window);
+       _Egl(Handle nativeDisplay, Handle window, _Egl* pSharedContext);
        virtual ~_Egl(void);
 
        virtual bool MakeCurrent(Handle surface = 0);
@@ -83,7 +83,7 @@ private:
        };
 
        bool GetDisplay(Handle nativeDisplay);
-       bool CreateContext(void);
+       bool CreateContext(EGLContext sharedContext);
        EGLConfig GetConfig(bool useAlpha, bool useStencil, bool useDepth) const;
 
        virtual Handle CreateWindowSurface(Handle window);
index 7110c64..c789d0e 100644 (file)
@@ -60,14 +60,14 @@ _GlContext* _GlContext::__pInstance = null;
 #endif
 
 _GlContext*
-_GlContext::CreateN(Handle nativeDisplay, Handle window)
+_GlContext::CreateN(Handle nativeDisplay, Handle window, _GlContext* pSharedContext)
 {
        SysAssertf(nativeDisplay, "Invalid display");
 
        _GlContext* pGlContext = null;
 
 #ifndef BUILD_UI_CORE
-       pGlContext = new (std::nothrow) _Egl(nativeDisplay, window);
+       pGlContext = new (std::nothrow) _Egl(nativeDisplay, window, dynamic_cast<_Egl*>(pSharedContext));
 #elif _WIN32
        pGlContext = new (std::nothrow) _Wgl(nativeDisplay, window);
 #elif LINUX
@@ -75,7 +75,14 @@ _GlContext::CreateN(Handle nativeDisplay, Handle window)
 //#elif 
 //     pGlContext = new (std::nothrow) _Agl(nativeDisplay, window);
 #endif
-
+       if(_VisualElementSurfaceManager::GetInstance() == null)
+       {
+#ifdef __SHARED_CONTEXT__
+               _VisualElementSurfaceManager::Initialize(nativeDisplay,window, *pGlContext);
+#else
+               _VisualElementSurfaceManager::Initialize();
+#endif
+       }
        return pGlContext;
 }
 
@@ -109,6 +116,7 @@ _GlContext::_GlContext(Handle nativeDisplay, Handle window)
                __pTextureShaderAlphaMaskExtra2[i] = null;
        }
 
+
        PRINT(">> _GlContext:_GlContext() \n");
 }
 
@@ -123,7 +131,7 @@ _GlContext::CreateInstance(Handle nativeDisplay)
 {
        SysTryReturnResult(NID_UI_ANIM, !__pInstance, E_OBJ_ALREADY_EXIST, "The GL context already created.");
 
-       __pInstance = _GlContext::CreateN(nativeDisplay, null);
+       __pInstance = _GlContext::CreateN(nativeDisplay, null, null);
        if (!__pInstance)
        {
                return E_OUT_OF_MEMORY;