2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the implementation file for egl.
28 #if defined(_OSP_EMUL_)
29 #define FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER
31 #define FGRAPHICS_INTERNAL_USE_DRM
34 #define FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING
35 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
39 #include <Ecore_Evas.h>
41 #include <Evas_Engine_GL_X11.h>
43 #include <FBaseSysLog.h>
44 #include <FGrpBitmap.h>
45 #include <FUiControl.h>
46 #include <FUiCtrlForm.h>
47 #include <FUiCtrlFrame.h>
48 #include <FUiWindow.h>
50 #include <FUi_EcoreEvasMgr.h>
51 #include <FUi_EcoreEvas.h>
53 #include <FGrp_BitmapTool.h>
54 #include <FGrp_BitmapImpl.h>
55 #include <FUi_ControlImpl.h>
56 #include <FUi_Control.h>
57 #include <FUi_WindowImpl.h>
58 #include <FUiAnim_VisualElementSurfaceImpl.h>
59 #include <FUiAnim_VisualElementImpl.h>
67 #include <elm_config.h>
69 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
73 #include <libdrm/drm_slp_bufmgr.h>
76 typedef int _SglIndex;
79 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList);
80 EGLSurface _SglGetCurrentSurface(EGLint readDraw);
81 EGLNativePixmapType _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pixmap);
82 EGLNativePixmapType _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo);
84 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
85 void _GlesInterfaceTerminate_1();
86 void _GlesInterfaceTerminate_2();
89 using namespace Tizen::Ui::Controls;
91 #define FGRAPHICS_INTERNAL_USE_FBO
92 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
94 #include <GLES2/gl2.h>
95 bool _GlesFboInitialize_1(int& fboWidth, int& fboHeight, GLuint& frameBufferObject, GLuint& depthRenderBuffer, GLuint& stencilRenderBuffer
96 , GLuint colorSize, GLuint depthSize, GLuint stencilSize, GLuint& textureId);
97 bool _GlesFboBinding_1(const GLuint frameBufferObject);
98 void _GlesFboSwapBuffers_1(const Frame* pFrame, int fboWidth, int fboHeight, const GLuint frameBufferObject, const GLuint textureId);
99 void _GlesFboTerminate_1(GLuint& frameBufferObject, GLuint& depthRenderBuffer, GLuint& stencilRenderBuffer, GLuint& textureId);
101 bool _GlesFboInitialize_2(const int fboWidth, const int fboHeight, GLuint& frameBufferObject, GLuint& depthRenderBuffer, GLuint& stencilRenderBuffer
102 , GLuint colorSize, GLuint depthSize, GLuint stencilSize, GLuint& textureId, GLuint &program);
103 bool _GlesFboBinding_2(const GLuint frameBufferObject);
104 void _GlesFboSwapBuffers_2(const Frame* pFrame, const GLuint frameBufferObject, const GLuint textureId, const GLuint program);
105 void _GlesFboTerminate_2(GLuint& frameBufferObject, GLuint& depthRenderBuffer, GLuint& stencilRenderBuffer
106 , GLuint& textureId, GLuint& program);
113 using namespace Tizen::Ui::Animations;
114 using namespace Tizen::Ui;
115 using namespace Tizen::Base;
117 namespace Tizen { namespace Graphics
126 #define FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT
127 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
128 void _PostRenderCallback(Ecore_Evas* ee);
129 void _SaveCurrentContext(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
130 void _UnregisterRenderCallback(Evas_Object* pObject);
133 #if !defined(_OSP_EMUL_)
134 #define FGRAPHICS_INTERNAL_USE_EVAS_NATIVE_SURFACE
136 bool isEvasNativeSetEnabled = false;
138 void _OnBoundsChanged(void* pData);
140 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
141 void _OnBoundsChangedFbo(void* pData);
142 EGLContext _fboContext = EGL_NO_CONTEXT;
145 const int INVALID_SGL_INDEX = 0;
146 const int MAX_SGL_INDEX = 100;
152 : sglIndex(INVALID_SGL_INDEX)
153 , display(EGL_NO_DISPLAY)
154 , surface(EGL_NO_SURFACE)
155 , context(EGL_NO_CONTEXT)
156 , config((EGLConfig)0)
159 , nativePixmap((EGLNativePixmapType)0)
160 , pVisualElementImpl(null)
162 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
167 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
168 , frameBufferObject(0)
169 , depthRenderBuffer(0)
170 , stencilRenderBuffer(0)
174 , isStencilEnabled(false)
179 , isFboAvailable(true)
186 virtual ~_SglInfo(void)
188 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
189 if (this->pEcoreImage != null)
191 ecore_x_image_free(this->pEcoreImage);
194 if (pBitmap != null && pObject != null)
197 int objectHeight = 0;
198 int objectBitsPerPixel = 0;
199 Evas_Colorspace colorSpace = EVAS_COLORSPACE_ARGB8888;
201 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
202 if (isEvasNativeSetEnabled)
204 _UnregisterRenderCallback(pObject);
207 evas_object_image_size_get(pObject, &objectWidth, &objectHeight);
208 colorSpace = evas_object_image_colorspace_get(pObject);
209 if (colorSpace == EVAS_COLORSPACE_ARGB8888)
211 objectBitsPerPixel = 32;
213 else if (colorSpace == EVAS_COLORSPACE_RGB565_A5P)
215 objectBitsPerPixel = 24;
217 else if (colorSpace == EVAS_COLORSPACE_GRY8)
219 objectBitsPerPixel = 8;
223 SysLog(NID_GRP, "Incompatible color space for Evas Object.");
224 objectBitsPerPixel = 0;
227 int size = objectWidth * objectHeight * objectBitsPerPixel;
231 void* pPtr = new (std::nothrow) int[size];
234 SysLog(NID_GRP, "Fail to allocate memory for Evas Object.");
237 evas_object_image_data_set(pObject, pPtr);
241 evas_object_image_data_set(pObject, NULL);
242 SysLog(NID_GRP, "Incompatible size for Evas object. w:%d h:%d bps:%d", objectWidth, objectHeight, objectBitsPerPixel);
256 Evas_Object* pObject;
257 EGLNativePixmapType nativePixmap;
258 _VisualElementImpl* pVisualElementImpl;
260 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
261 Ecore_X_Image* pEcoreImage;
265 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
266 GLuint frameBufferObject;
267 GLuint depthRenderBuffer;
268 GLuint stencilRenderBuffer;
272 bool isStencilEnabled;
283 _SglInfo(const _SglInfo& sglInfo);
284 _SglInfo& operator =(const _SglInfo& rhs);
291 : nativePixmap((Pixmap)0)
292 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
294 , pDrmBufferObject(null)
299 virtual ~_PixmapInfo(void)
301 Display* pDisplay = (Display*)ecore_x_display_get();
302 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
303 drm_slp_bo_unmap(this->pDrmBufferObject, DRM_SLP_DEVICE_CPU);
304 drm_slp_bo_unref(this->pDrmBufferObject);
305 if (this->pDrmBufMgr)
307 close(this->pDrmBufMgr->drm_fd);
309 drm_slp_bufmgr_destroy(this->pDrmBufMgr);
310 DRI2DestroyDrawable(pDisplay, this->nativePixmap);
312 XFreePixmap(pDisplay, this->nativePixmap);
317 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
318 drm_slp_bufmgr pDrmBufMgr;
319 drm_slp_bo pDrmBufferObject;
323 void _EvasObjectImageChange(_SglInfo* pSglInfo);
326 _OnBoundsChanged(void* pData)
328 _SglInfo* pSglInfo = (_SglInfo*)pData;
329 _SglIndex readSurface = 0;
330 _SglIndex drawSurface = 0;
331 bool needMakeCurrent = false;
332 EGLBoolean ret = EGL_FALSE;
335 VisualElementSurface* pVisualElementSurface = null;
336 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = null;
338 result r = E_SUCCESS;
339 Tizen::Graphics::FloatRectangle rect;
341 if (pSglInfo == null || pSglInfo->sglIndex <= INVALID_SGL_INDEX)
346 readSurface = (_SglIndex)_SglGetCurrentSurface(EGL_READ);
347 drawSurface = (_SglIndex)_SglGetCurrentSurface(EGL_DRAW);
348 if (readSurface == pSglInfo->sglIndex || drawSurface == pSglInfo->sglIndex)
350 needMakeCurrent = true;
353 ret = eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
354 if (ret == EGL_FALSE)
359 ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
360 if (ret == EGL_FALSE)
365 if (pSglInfo->pVisualElementImpl == null)
370 rect = pSglInfo->pVisualElementImpl->GetBounds();
371 width = int(rect.width);
372 height = int(rect.height);
373 if (width <= 0 || height <=0)
378 if (isEvasNativeSetEnabled)
380 if (pSglInfo->pControl == null)
385 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pSglInfo->pControl);
386 if (pControlImpl == null)
391 VisualElement* pVE = pControlImpl->GetCore().GetVisualElement();
397 Control* pFrame = pSglInfo->pControl;
398 Control* pTemp = pFrame->GetParent();
402 pTemp = pTemp->GetParent();
405 Dimension size(width, height);
406 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
412 pVisualElementSurface = new (std::nothrow) VisualElementSurface();
413 if (pVisualElementSurface == null)
418 r = pVisualElementSurface->Construct(*pWindow->GetDisplayContext(), size);
419 pVE->SetSurface(pVisualElementSurface);
423 pVisualElementSurface = pSglInfo->pVisualElementImpl->GetSurfaceN();
424 if (pVisualElementSurface == null)
430 if (pSglInfo->pBitmap != null)
432 delete pSglInfo->pBitmap;
433 pSglInfo->pBitmap = null;
436 pSglInfo->pBitmap = new (std::nothrow) Tizen::Graphics::Bitmap;
437 if (pSglInfo->pBitmap == null)
442 r = pSglInfo->pBitmap->Construct(Tizen::Graphics::Rectangle(0, 0, width, height));
448 pSglInfo->nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, pSglInfo->pBitmap);
449 if (pSglInfo->nativePixmap == 0)
454 pSglInfo->surface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, pSglInfo->nativePixmap, null);
455 if (pSglInfo->surface == EGL_NO_SURFACE)
462 eglMakeCurrent(pSglInfo->display, pSglInfo->surface, pSglInfo->surface, pSglInfo->context);
464 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
465 _SaveCurrentContext(pSglInfo->display, pSglInfo->surface, pSglInfo->surface, pSglInfo->context);
469 pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
470 if (pVisualElementSurfaceImpl == null)
475 pSglInfo->pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
476 if (pSglInfo->pObject == null)
481 _EvasObjectImageChange(pSglInfo);
486 delete pSglInfo->pBitmap;
487 pSglInfo->pBitmap = null;
491 delete pVisualElementSurface;
497 eglMakeCurrent(pSglInfo->display, pSglInfo->surface, pSglInfo->surface, pSglInfo->context);
499 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
500 _SaveCurrentContext(pSglInfo->display, pSglInfo->surface, pSglInfo->surface, pSglInfo->context);
506 SysLog(NID_GRP, "_OnBoundsChanged failed!! pSglInfo:%#x", (unsigned int)pSglInfo);
509 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
511 _OnBoundsChangedFbo(void* pData)
513 _SglInfo* pSglInfo = (_SglInfo*)pData;
515 if (pSglInfo == null || pSglInfo->pVisualElementImpl == null)
517 SysLog(NID_GRP, "FBO Invalid data");
521 FloatRectangle rect = pSglInfo->pVisualElementImpl->GetBounds();
522 pSglInfo->fboWidth = int(rect.width);
523 pSglInfo->fboHeight = int(rect.height);
525 if (pSglInfo->glVersion == 1)
527 eglMakeCurrent(pSglInfo->display
530 , pSglInfo->context);
532 _GlesFboTerminate_1(pSglInfo->frameBufferObject
533 , pSglInfo->depthRenderBuffer
534 , pSglInfo->stencilRenderBuffer
535 , pSglInfo->textureId
538 _GlesFboInitialize_1(pSglInfo->fboWidth
539 , pSglInfo->fboHeight
540 , pSglInfo->frameBufferObject
541 , pSglInfo->depthRenderBuffer
542 , pSglInfo->stencilRenderBuffer
543 , pSglInfo->colorSize
544 , pSglInfo->depthSize
545 , pSglInfo->stencilSize
546 , pSglInfo->textureId
549 else if (pSglInfo->glVersion == 2)
551 eglMakeCurrent(pSglInfo->display
554 , pSglInfo->context);
556 _GlesFboTerminate_2(pSglInfo->frameBufferObject
557 , pSglInfo->depthRenderBuffer
558 , pSglInfo->stencilRenderBuffer
559 , pSglInfo->textureId
563 _GlesFboInitialize_2(pSglInfo->fboWidth
564 , pSglInfo->fboHeight
565 , pSglInfo->frameBufferObject
566 , pSglInfo->depthRenderBuffer
567 , pSglInfo->stencilRenderBuffer
568 , pSglInfo->colorSize
569 , pSglInfo->depthSize
570 , pSglInfo->stencilSize
571 , pSglInfo->textureId
577 SysLog(NID_GRP, "ambiguous gl Version %d", pSglInfo->glVersion);
580 #endif //#if defined(FGRAPHICS_INTERNAL_USE_FBO)
582 class _SglInfoTableManipulator
585 _SglInfoTableManipulator()
587 result r = __SglMutex.Create();
588 SysTryLog(NID_GRP, r == E_SUCCESS, "Failed to create mutex. [%s]", GetErrorMessage(r));
589 __SglIndexLastUsed = INVALID_SGL_INDEX;
590 __SglInitialized = false;
593 ~_SglInfoTableManipulator()
598 FindNextEmptySlotOfSglInfoTable()
600 if (!__SglInitialized)
602 if (CreateSglInfoTable() == false)
604 return INVALID_SGL_INDEX;
608 _SglIndex sglIndex = INVALID_SGL_INDEX;
609 _SglIndex index = __SglIndexLastUsed;
611 __SglMutex.Acquire();
612 for (int i = 1; i < MAX_SGL_INDEX; i++)
616 if (index >= MAX_SGL_INDEX)
621 if (__SglInfoTable[index] == null)
624 __SglIndexLastUsed = index;
628 __SglMutex.Release();
631 if (sglIndex <= INVALID_SGL_INDEX)
633 return INVALID_SGL_INDEX;
644 __SglMutex.Acquire();
646 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
648 __SglInfoTable[i] = null;
651 __SglInfoTable[0] = new (std::nothrow) _SglInfo;
652 if (__SglInfoTable[0] != null)
655 __SglInitialized = true;
658 __SglMutex.Release();
664 DestroySglInfoTable()
666 __SglMutex.Acquire();
668 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
670 if (__SglInfoTable[i] != null)
672 delete __SglInfoTable[i];
673 __SglInfoTable[i] = null;
676 __SglInitialized = false;
678 __SglMutex.Release();
682 LockSglInfoTable(_SglIndex index)
684 __SglMutex.Acquire();
686 if (index < INVALID_SGL_INDEX || index >= MAX_SGL_INDEX)
691 return __SglInfoTable[index];
697 __SglMutex.Release();
703 _SglInfo* newSglInfo = new (std::nothrow) _SglInfo;
704 if (newSglInfo == null)
706 SysLog(NID_GRP, "CreateSglIndex fail to allocate _SglInfo!!");
707 return INVALID_SGL_INDEX;
710 int sglIndex = FindNextEmptySlotOfSglInfoTable();
711 if (sglIndex == INVALID_SGL_INDEX)
715 SysLog(NID_GRP, "CreateSglIndex failed!!");
716 return INVALID_SGL_INDEX;
719 __SglMutex.Acquire();
720 __SglInfoTable[sglIndex] = newSglInfo;
721 __SglMutex.Release();
727 DestroySglIndex(_SglIndex sglIndex)
729 if (sglIndex < 1 || sglIndex >= MAX_SGL_INDEX)
731 SysLog(NID_GRP, "sglIndex:%#x is out of range.", (unsigned int)sglIndex);
735 __SglMutex.Acquire();
737 if (sglIndex <= INVALID_SGL_INDEX || __SglInfoTable[sglIndex] == null)
739 __SglMutex.Release();
741 SysLog(NID_GRP, "DestroySglIndex failed!! sglIndex:%#x", (unsigned int)sglIndex);
745 delete __SglInfoTable[sglIndex];
746 __SglInfoTable[sglIndex] = null;
748 __SglMutex.Release();
754 GetSglIndexForSurface(EGLSurface surface)
756 __SglMutex.Acquire();
759 for (int i = 0; i < MAX_SGL_INDEX; i++)
761 if (__SglInfoTable[i] != null && __SglInfoTable[i]->surface == surface)
768 __SglMutex.Release();
773 static _SglInfoTableManipulator* GetInstance(void)
775 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
779 pthread_once(&once_block, __InitSglInfoTableManipulator);
782 return __pTheInstance;
786 static void __InitSglInfoTableManipulator(void)
788 static _SglInfoTableManipulator instance;
789 __pTheInstance = &instance;
793 Runtime::Mutex __SglMutex;
794 _SglInfo* __SglInfoTable[MAX_SGL_INDEX];
795 _SglIndex __SglIndexLastUsed;
796 bool __SglInitialized;
798 static _SglInfoTableManipulator* __pTheInstance;
800 _SglInfoTableManipulator* _SglInfoTableManipulator::__pTheInstance = null;
803 _PixmapSurfaceDestroyCallback(void* pCallbackParam)
805 delete (_PixmapInfo*)pCallbackParam;
808 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
810 _PixmapLockCallBack(void* pCallbackParam)
812 drm_slp_bo_map((drm_slp_bo)pCallbackParam, DRM_SLP_DEVICE_CPU, DRM_SLP_OPTION_READ | DRM_SLP_OPTION_WRITE);
816 _PixmapUnlockCallBack(void* pCallbackParam)
818 drm_slp_bo_unmap((drm_slp_bo)pCallbackParam, DRM_SLP_DEVICE_CPU);
823 _IsEvasGlEnabled(void)
825 const char* pString = elm_config_preferred_engine_get();
826 String engineName(pString);
828 if (engineName.Contains(String("opengl_x11")))
830 SysLog(NID_GRP, "gl backend : %s", pString);
833 else if (engineName.Contains(String("software_x11")))
835 SysLog(NID_GRP, "sw backend : %s", pString);
840 pString = elm_config_engine_get();
841 String engineName(pString);
842 if (engineName.Contains(String("opengl_x11")))
844 SysLog(NID_GRP, "system gl backend : %s", pString);
849 SysLog(NID_GRP, "system sw backend : %s", pString);
854 _EvasObjectImageChange(_SglInfo* pSglInfo)
856 if (isEvasNativeSetEnabled)
858 Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
864 Evas_Engine_Info_GL_X11* pEvasInfo = (Evas_Engine_Info_GL_X11 *)evas_engine_info_get(pEvas);
865 if (pEvasInfo == null)
869 Evas_Native_Surface nativeSurface = {0, };
870 nativeSurface.type = EVAS_NATIVE_SURFACE_X11;
871 nativeSurface.version = EVAS_NATIVE_SURFACE_VERSION;
872 nativeSurface.data.x11.pixmap = (unsigned long)pSglInfo->nativePixmap;
873 nativeSurface.data.x11.visual = pEvasInfo->info.visual;
874 evas_object_image_native_surface_set(pSglInfo->pObject, &nativeSurface);
876 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
877 _PostRenderCallback(NULL);
882 Tizen::Graphics::BufferInfo bufferInfo;
883 pSglInfo->pBitmap->Lock(bufferInfo);
884 evas_object_image_data_set(pSglInfo->pObject, bufferInfo.pPixels);
885 pSglInfo->pBitmap->Unlock();
889 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
890 int __registerCallbackCount = 0;
891 EGLDisplay __previousDisplay = EGL_NO_DISPLAY;
892 EGLSurface __previousDrawSurface = EGL_NO_SURFACE;
893 EGLSurface __previousReadSurface = EGL_NO_SURFACE;
894 EGLContext __previousContext = EGL_NO_CONTEXT;
897 _PostRenderCallback(Ecore_Evas* ee)
899 EGLBoolean ret = eglMakeCurrent(__previousDisplay, __previousDrawSurface, __previousReadSurface, __previousContext);
900 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
901 , (unsigned int)__previousDisplay
902 , (unsigned int)__previousDrawSurface
903 , (unsigned int)__previousReadSurface
904 , (unsigned int)__previousContext
905 , (unsigned int)eglGetError());
909 _SaveCurrentContext(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
911 __previousDisplay = dpy;
912 __previousDrawSurface = draw;
913 __previousReadSurface = read;
914 __previousContext = ctx;
918 _RegisterRenderCallback(Evas_Object* pObject)
920 if (__registerCallbackCount == 0)
922 Evas* pEvas = evas_object_evas_get(pObject);
928 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
929 if (pEcoreEvas == null)
934 ecore_evas_callback_post_render_set(pEcoreEvas, _PostRenderCallback);
936 __registerCallbackCount++;
940 _UnregisterRenderCallback(Evas_Object* pObject)
942 __registerCallbackCount--;
944 if (__registerCallbackCount == 0)
946 Evas* pEvas = evas_object_evas_get(pObject);
952 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
953 if (pEcoreEvas == null)
958 ecore_evas_callback_post_render_set(pEcoreEvas, NULL);
961 #endif //#if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
973 return eglGetError();
977 _SglGetDisplay(EGLNativeDisplayType displayId)
979 if (displayId == (EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)
981 return eglGetDisplay((EGLNativeDisplayType) ecore_x_display_get());
984 return eglGetDisplay((EGLNativeDisplayType) displayId);
988 _SglInitialize(EGLDisplay dpy, EGLint* pMajor, EGLint* pMinor)
990 return eglInitialize(dpy, pMajor, pMinor);
994 _SglTerminate(EGLDisplay dpy)
996 _GlesInterfaceTerminate_1();
997 _GlesInterfaceTerminate_2();
999 _SglInfoTableManipulator::GetInstance()->DestroySglInfoTable();
1001 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1002 if (_fboContext != EGL_NO_CONTEXT)
1004 eglDestroyContext(dpy, _fboContext);
1005 _fboContext = EGL_NO_CONTEXT;
1009 if (!_IsEvasGlEnabled())
1018 _SglQueryString(EGLDisplay dpy, EGLint name)
1020 return eglQueryString(dpy, name);
1024 _SglGetConfigs(EGLDisplay dpy, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
1026 return eglGetConfigs(dpy, pConfigs, configSize, pNumConfig);
1030 _SglChooseConfig(EGLDisplay dpy, const EGLint* pAttribList, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
1032 return eglChooseConfig(dpy, pAttribList, pConfigs, configSize, pNumConfig);
1036 _SglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* pValue)
1038 return eglGetConfigAttrib(dpy, config, attribute, pValue);
1042 _SglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* pAttribList)
1044 _SglIndex sglIndex = INVALID_SGL_INDEX;
1045 Tizen::Graphics::Bitmap* pBitmap = null;
1046 VisualElementSurface* pVisualElementSurface = null;
1047 Object* pObj = (Object*)win;
1048 VisualElement* pVE = dynamic_cast<VisualElement*>(pObj);
1049 Tizen::Ui::Control* pControl = dynamic_cast<Tizen::Ui::Control*>(pObj);
1050 #if !defined(_OSP_EMUL_)
1051 Tizen::Ui::Controls::Frame* pFrame = dynamic_cast<Tizen::Ui::Controls::Frame*>(pControl);
1053 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1055 if (pControl == null && pVE == null)
1060 #if !defined(_OSP_EMUL_)
1061 if (pFrame != null && !_IsEvasGlEnabled())
1063 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
1064 _WindowImpl* pWindowImpl = dynamic_cast<_WindowImpl*> (pControlImpl);
1065 if (pWindowImpl == null)
1070 EGLNativeWindowType nativeWindow = (EGLNativeWindowType)pWindowImpl->GetNativeHandle();
1072 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1073 if (sglIndex <= INVALID_SGL_INDEX)
1078 EGLSurface windowSurface = eglCreateWindowSurface(dpy, config, nativeWindow, pAttribList);
1079 if (windowSurface == EGL_NO_SURFACE)
1081 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1086 _VisualElementImpl* visualElementImpl = _VisualElementImpl::GetInstance(*pControlImpl->GetCore().GetVisualElement());
1087 if (visualElementImpl == null)
1089 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1094 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1096 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1097 pSglInfo->pFrame = pFrame;
1098 eglGetConfigAttrib(dpy, config, EGL_BUFFER_SIZE, &pSglInfo->colorSize);
1099 eglGetConfigAttrib(dpy, config, EGL_DEPTH_SIZE, &pSglInfo->depthSize);
1100 eglGetConfigAttrib(dpy, config, EGL_STENCIL_SIZE, &pSglInfo->stencilSize);
1102 pSglInfo->display = dpy;
1103 pSglInfo->pVisualElementImpl = visualElementImpl;
1104 pSglInfo->pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChangedFbo, pSglInfo);
1106 pSglInfo->surface = windowSurface;
1108 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1111 return (EGLSurface)sglIndex;
1114 #endif //#if !defined(_OSP_EMUL_)
1116 _VisualElementImpl* pVisualElementImpl = null;
1117 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = null;
1120 result r = E_SUCCESS;
1121 Tizen::Graphics::FloatRectangle rect;
1122 _SglInfo* pSglInfo = null;
1126 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
1127 if (pControlImpl == null)
1131 pVE = pControlImpl->GetCore().GetVisualElement();
1134 pVisualElementImpl = _VisualElementImpl::GetInstance(*pVE);
1135 if (pVisualElementImpl == null)
1140 rect = pVisualElementImpl->GetBounds();
1141 width = int(rect.width);
1142 height = int(rect.height);
1143 if (width <= 0 || height <= 0)
1148 #if defined (FGRAPHICS_INTERNAL_USE_EVAS_NATIVE_SURFACE)
1149 isEvasNativeSetEnabled = _IsEvasGlEnabled();
1151 isEvasNativeSetEnabled = false;
1154 if (isEvasNativeSetEnabled)
1156 Control* pFrame = pControl;
1157 Control* pTemp = pFrame->GetParent();
1158 while(pTemp != null)
1161 pTemp = pTemp->GetParent();
1164 Dimension size(width, height);
1165 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
1166 if (pWindow == null)
1171 pVisualElementSurface = new (std::nothrow) VisualElementSurface();
1172 if (pVisualElementSurface == null)
1177 r = pVisualElementSurface->Construct(*pWindow->GetDisplayContext(), size);
1178 pVE->SetSurface(pVisualElementSurface);
1182 pVisualElementSurface = pVisualElementImpl->GetSurfaceN();
1183 if (pVisualElementSurface == null)
1189 pBitmap = new (std::nothrow) Tizen::Graphics::Bitmap;
1190 if (pBitmap == null)
1195 r = pBitmap->Construct(Tizen::Graphics::Rectangle(0, 0, width, height));
1201 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)pBitmap, null);
1202 if (sglIndex <= INVALID_SGL_INDEX)
1207 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1209 pSglInfo->sglIndex = sglIndex;
1210 pSglInfo->display = dpy;
1211 pSglInfo->config = config;
1212 pSglInfo->pBitmap = pBitmap;
1213 pSglInfo->pVisualElementImpl = pVisualElementImpl;
1214 pSglInfo->pControl = pControl;
1216 pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChanged, pSglInfo);
1218 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1220 pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
1221 if (pVisualElementSurfaceImpl == null)
1226 pSglInfo->pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
1227 if (pSglInfo->pObject == null)
1232 _EvasObjectImageChange(pSglInfo);
1234 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1235 if (isEvasNativeSetEnabled)
1237 _RegisterRenderCallback(pSglInfo->pObject);
1241 return (EGLSurface)sglIndex;
1247 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1251 delete pVisualElementSurface;
1255 SysLog(NID_GRP, "_SglCreateWindowSurface failed!! dpy:%#x config:%#x pControl:%#x pAttribList:%#x",
1256 (unsigned int)dpy, (unsigned int)config, (unsigned int)pControl, (unsigned int)pAttribList);
1257 return eglCreateWindowSurface(dpy, config, (EGLNativeWindowType) 0, pAttribList);
1261 _SglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* pAttribList)
1263 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1264 _SglIndex sglIndex = INVALID_SGL_INDEX;
1266 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1267 if (sglIndex <= INVALID_SGL_INDEX)
1269 SysLog(NID_GRP, "_SglCreatePbufferSurface failed!! dpy:%#x config:%#x pAttribList:%#x",
1270 (unsigned int)dpy, (unsigned int)config, (unsigned int)pAttribList);
1272 return eglCreatePbufferSurface(EGL_NO_DISPLAY, config, pAttribList);
1275 EGLSurface pbufferSurface = eglCreatePbufferSurface(dpy, config, pAttribList);
1276 if (pbufferSurface == EGL_NO_SURFACE)
1278 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1283 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1285 pSglInfo->surface = pbufferSurface;
1287 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1290 return (EGLSurface)sglIndex;
1293 _OSP_LOCAL_ EGLNativePixmapType
1294 _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pBitmap)
1298 int bitsPerPixel = 0;
1299 Display* pNativeDisplay = null;
1300 Drawable nativeWindow = 0;
1301 result r = E_FAILURE;
1302 Tizen::Graphics::BufferInfo bufferInfo;
1303 _PixmapInfo* pPixmapInfo = null;
1304 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1305 unsigned int attachments[] = { DRI2BufferFrontLeft };
1306 char* pDeviceName = null;
1307 char* pDriverName = null;
1308 DRI2Buffer* pDri2Buffer = null;
1311 int dri2BufferCount = 0;
1315 drm_magic_t magic = 0;
1317 _SglInfo* pSglInfo = null;
1318 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1320 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1321 if (pBitmap == null || sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1323 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1326 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1328 r = pBitmap->Lock(bufferInfo);
1334 width = bufferInfo.width;
1335 height = bufferInfo.height;
1336 bitsPerPixel = bufferInfo.bitsPerPixel;
1338 r = pBitmap->Unlock();
1339 if (r != E_SUCCESS || width <= 0 || height <= 0 || bitsPerPixel <= 0)
1344 pNativeDisplay = (Display*) ecore_x_display_get();
1345 nativeWindow = DefaultRootWindow(pNativeDisplay);
1347 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1348 if (pPixmapInfo == null)
1353 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height,
1354 ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1355 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1360 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1361 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1362 XSync(pNativeDisplay, False);
1364 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1366 if (!ret || pDeviceName == null)
1371 drmFile = open(pDeviceName, O_RDWR);
1378 drmGetMagic(drmFile, &magic);
1379 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1385 pPixmapInfo->pDrmBufMgr = drm_slp_bufmgr_init(drmFile, null);
1386 if (pPixmapInfo->pDrmBufMgr == null)
1391 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1392 if (pDri2Buffer == null)
1397 pPixmapInfo->pDrmBufferObject = drm_slp_bo_import(pPixmapInfo->pDrmBufMgr, pDri2Buffer->name);
1399 if (pPixmapInfo->pDrmBufferObject == null)
1404 pData = (void*)drm_slp_bo_get_handle(pPixmapInfo->pDrmBufferObject, DRM_SLP_DEVICE_CPU);
1410 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pData, width * bitsPerPixel / 8,
1411 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1417 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1418 _PixmapLockCallBack, pPixmapInfo->pDrmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pDrmBufferObject))
1424 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1426 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1428 pSglInfo->pEcoreImage = ecore_x_image_new(width
1430 , ecore_x_default_visual_get(pNativeDisplay, ecore_x_default_screen_get())
1431 , ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1433 if (pSglInfo->pEcoreImage == null)
1435 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1439 ecore_x_image_get(pSglInfo->pEcoreImage
1440 , pPixmapInfo->nativePixmap, 0, 0, 0, 0
1448 void* pSource = ecore_x_image_data_get(pSglInfo->pEcoreImage, &bpl, &rows, &bpp);
1450 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pSource, width * bitsPerPixel / 8,
1451 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1454 ecore_x_image_free(pSglInfo->pEcoreImage);
1455 pSglInfo->pEcoreImage = null;
1456 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1458 SysLog(NID_GRP, "change buffer failed! pSource %#x %d %d %d", (unsigned int)pSource, bpl, rows, bpp);
1462 pSglInfo->width = width;
1463 pSglInfo->height = height;
1465 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1467 #endif //#if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1468 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1470 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1473 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1474 drm_slp_bo_unmap(pPixmapInfo->pDrmBufferObject, DRM_SLP_DEVICE_CPU);
1475 drm_slp_bo_unref(pPixmapInfo->pDrmBufferObject);
1479 drm_slp_bufmgr_destroy(pPixmapInfo->pDrmBufMgr);
1487 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1489 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1497 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1498 return (EGLNativePixmapType)0;
1501 _OSP_LOCAL_ EGLNativePixmapType
1502 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1504 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1507 int bitsPerPixel = 0;
1508 Display* pNativeDisplay = null;
1509 Drawable nativeWindow = 0;
1510 unsigned int attachments[] = { DRI2BufferFrontLeft };
1511 char* pDeviceName = null;
1512 char* pDriverName = null;
1513 DRI2Buffer* pDri2Buffer = null;
1516 int dri2BufferCount = 0;
1519 result r = E_FAILURE;
1520 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1521 drm_magic_t magic = 0;
1522 _PixmapInfo* pPixmapInfo = null;
1524 if (pBitmap == null)
1529 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1530 if (pBitmapImpl == null)
1535 width = bufferInfo.width;
1536 height = bufferInfo.height;
1537 bitsPerPixel = bufferInfo.bitsPerPixel;
1539 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1544 pNativeDisplay = (Display*) ecore_x_display_get();
1545 nativeWindow = DefaultRootWindow(pNativeDisplay);
1547 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1548 if (pPixmapInfo == null)
1553 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height, bitsPerPixel);
1554 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1558 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1559 XSync(pNativeDisplay, False);
1561 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1563 if (!ret || pDeviceName == null)
1568 drmFile = open(pDeviceName, O_RDWR);
1575 drmGetMagic(drmFile, &magic);
1576 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1582 pPixmapInfo->pDrmBufMgr = drm_slp_bufmgr_init(drmFile, null);
1583 if (pPixmapInfo->pDrmBufMgr == null)
1588 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1589 if (pDri2Buffer == null)
1594 pPixmapInfo->pDrmBufferObject = drm_slp_bo_import(pPixmapInfo->pDrmBufMgr, pDri2Buffer->name);
1596 if (pPixmapInfo->pDrmBufferObject == null)
1601 bufferInfo.pPixels = (void*)drm_slp_bo_get_handle(pPixmapInfo->pDrmBufferObject, DRM_SLP_DEVICE_CPU);
1602 if (bufferInfo.pPixels == null)
1607 bufferInfo.bitsPerPixel = 32;
1608 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1609 bufferInfo.pitch = bufferInfo.width*bufferInfo.bitsPerPixel/4;
1610 memset(bufferInfo.pPixels, 0, bufferInfo.width * bufferInfo.height * 4);
1611 r = pBitmapImpl->Construct(bufferInfo);
1617 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1618 _PixmapLockCallBack, pPixmapInfo->pDrmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pDrmBufferObject))
1623 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1626 drm_slp_bo_unmap(pPixmapInfo->pDrmBufferObject, DRM_SLP_DEVICE_CPU);
1627 drm_slp_bo_unref(pPixmapInfo->pDrmBufferObject);
1631 drm_slp_bufmgr_destroy(pPixmapInfo->pDrmBufMgr);
1639 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1640 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1648 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1649 return (EGLNativePixmapType)0;
1651 return (EGLNativePixmapType)0;
1652 #endif //#if !defined(FGRAPHICS_INTERNAL_USE_DRM)
1656 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1658 _SglIndex sglIndex = INVALID_SGL_INDEX;
1659 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1660 EGLNativePixmapType eglNativePixmap = 0;
1661 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1662 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1664 if (pBitmap == null)
1669 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1670 if (sglIndex <= INVALID_SGL_INDEX)
1675 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1676 if (eglNativePixmap == 0)
1681 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1682 if (pixmapSurface == EGL_NO_SURFACE)
1684 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1689 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1691 pSglInfo->nativePixmap = eglNativePixmap;
1692 pSglInfo->surface = pixmapSurface;
1694 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1697 return (EGLSurface)sglIndex;
1700 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1704 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1705 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1706 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1710 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1712 EGLBoolean ret = EGL_FALSE;
1713 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1715 _SglIndex sglIndex = (_SglIndex)surface;
1716 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1718 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1720 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1721 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy, (unsigned int)surface);
1722 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1725 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1726 if (pSglInfo->isFboAvailable && pSglInfo->pFrame != null)
1728 if (pSglInfo->glVersion == 1)
1730 _GlesFboTerminate_1(pSglInfo->frameBufferObject
1731 , pSglInfo->depthRenderBuffer
1732 , pSglInfo->stencilRenderBuffer
1733 , pSglInfo->textureId);
1735 else if (pSglInfo->glVersion == 2)
1737 _GlesFboTerminate_2(pSglInfo->frameBufferObject
1738 , pSglInfo->depthRenderBuffer
1739 , pSglInfo->stencilRenderBuffer
1740 , pSglInfo->textureId
1741 , pSglInfo->program);
1745 SysLog(NID_GRP, "ambiguous gl Version %d", pSglInfo->glVersion);
1749 ret = eglDestroySurface(dpy, pSglInfo->surface);
1750 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1752 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1758 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1760 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1762 _SglIndex sglIndex = (_SglIndex)surface;
1763 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1765 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1767 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1768 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1769 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1770 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1773 EGLBoolean ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1774 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1780 _SglBindAPI(EGLenum api)
1782 return eglBindAPI(api);
1788 return eglQueryAPI();
1794 return eglWaitClient();
1798 _SglReleaseThread(void)
1800 return eglReleaseThread();
1804 _SglCreatePbufferFromClientBuffer(
1805 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1807 _SglIndex sglIndex = INVALID_SGL_INDEX;
1808 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1810 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1811 if (sglIndex <= INVALID_SGL_INDEX)
1813 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1814 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1815 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1817 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1820 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1821 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1823 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1828 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1830 pSglInfo->surface = pbufferFromClientBuffer;
1832 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1835 return (EGLSurface)sglIndex;
1839 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1841 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1843 _SglIndex sglIndex = (_SglIndex)surface;
1844 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1846 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1848 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1849 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1850 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1851 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1853 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1856 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1857 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1863 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1865 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1867 _SglIndex sglIndex = (_SglIndex)surface;
1868 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1870 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1872 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1873 SysLog(NID_GRP, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1874 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1876 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1879 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1880 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1886 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1888 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1890 _SglIndex sglIndex = (_SglIndex)surface;
1891 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1893 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1895 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1896 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1897 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1899 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1902 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1903 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1909 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1911 return eglSwapInterval(dpy, interval);
1915 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1917 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1918 EGLContext ret = EGL_NO_CONTEXT;
1919 if (shareContext == EGL_NO_CONTEXT)
1921 if (_fboContext == EGL_NO_CONTEXT)
1923 _fboContext = eglCreateContext(dpy, config, EGL_NO_CONTEXT, pAttribList);
1924 if (_fboContext == EGL_NO_CONTEXT)
1926 return EGL_NO_CONTEXT;
1930 ret = eglCreateContext(dpy, config, _fboContext, pAttribList);
1934 ret = eglCreateContext(dpy, config, shareContext, pAttribList);
1938 return eglCreateContext(dpy, config, shareContext, pAttribList);
1943 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1945 return eglDestroyContext(dpy, ctx);
1949 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1951 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1953 _SglIndex sglIndexDraw = (_SglIndex)draw;
1954 _SglIndex sglIndexRead = (_SglIndex)read;
1956 EGLSurface sglInfoReadSurface;
1958 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1960 if (sglInfoRead == null)
1962 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1963 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1964 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1965 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1967 sglInfoReadSurface = sglInfoRead->surface;
1969 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1972 _SglInfo* sglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1973 if (sglInfoDraw == null)
1975 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1976 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1977 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1978 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1981 sglInfoDraw->context = ctx;
1983 EGLBoolean ret = eglMakeCurrent(dpy, sglInfoDraw->surface, sglInfoReadSurface, ctx);
1985 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1986 _SaveCurrentContext(dpy, sglInfoDraw->surface, sglInfoReadSurface, ctx);
1989 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
1990 if (ret != EGL_TRUE || sglInfoDraw->surface == EGL_NO_SURFACE
1991 || sglInfoReadSurface == EGL_NO_SURFACE
1992 || ctx == EGL_NO_CONTEXT)
1994 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1998 if (sglInfoDraw->glVersion == 0)
2000 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &sglInfoDraw->glVersion);
2001 #if defined(_OSP_EMUL_) //fixme
2002 sglInfoDraw->isFboAvailable = false;
2006 if (sglInfoDraw->pFrame != null)
2008 if (sglInfoDraw->isFboAvailable)
2010 if (sglInfoDraw->frameBufferObject == 0)
2016 sglInfoDraw->pFrame->GetBounds(x, y, width, height);
2018 sglInfoDraw->fboWidth = width;
2019 sglInfoDraw->fboHeight = height;
2021 if (sglInfoDraw->glVersion == 1)
2023 sglInfoDraw->isFboAvailable = _GlesFboInitialize_1(sglInfoDraw->fboWidth
2024 , sglInfoDraw->fboHeight
2025 , sglInfoDraw->frameBufferObject, sglInfoDraw->depthRenderBuffer
2026 , sglInfoDraw->stencilRenderBuffer, sglInfoDraw->colorSize
2027 , sglInfoDraw->depthSize, sglInfoDraw->stencilSize
2028 , sglInfoDraw->textureId);
2030 else if (sglInfoDraw->glVersion == 2)
2032 sglInfoDraw->isFboAvailable = _GlesFboInitialize_2(sglInfoDraw->fboWidth
2033 , sglInfoDraw->fboHeight
2034 , sglInfoDraw->frameBufferObject, sglInfoDraw->depthRenderBuffer
2035 , sglInfoDraw->stencilRenderBuffer, sglInfoDraw->colorSize
2036 , sglInfoDraw->depthSize, sglInfoDraw->stencilSize
2037 , sglInfoDraw->textureId, sglInfoDraw->program);
2041 SysLog(NID_GRP, "ambiguous gl Version %d", sglInfoDraw->glVersion);
2042 sglInfoDraw->isFboAvailable = false;
2047 if (sglInfoDraw->glVersion == 1)
2049 _GlesFboBinding_1(sglInfoDraw->frameBufferObject);
2051 else if (sglInfoDraw->glVersion == 2)
2053 _GlesFboBinding_2(sglInfoDraw->frameBufferObject);
2057 SysLog(NID_GRP, "ambiguous gl Version %d", sglInfoDraw->glVersion);
2064 if (sglInfoDraw->frameBufferObject != 0 && sglInfoDraw->isFboAvailable)
2066 if (sglInfoDraw->glVersion == 1)
2068 _GlesFboBinding_1(0);
2070 else if (sglInfoDraw->glVersion == 2)
2072 _GlesFboBinding_2(0);
2076 SysLog(NID_GRP, "ambiguous gl Version %d", sglInfoDraw->glVersion);
2081 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2087 _SglGetCurrentContext()
2089 return eglGetCurrentContext();
2093 _SglGetCurrentSurface(EGLint readDraw)
2095 EGLSurface surface = EGL_NO_SURFACE;
2096 _SglIndex sglIndex = INVALID_SGL_INDEX;
2098 surface = eglGetCurrentSurface(readDraw);
2099 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
2101 if (sglIndex < INVALID_SGL_INDEX)
2103 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
2104 return EGL_NO_SURFACE;
2107 return (EGLSurface)sglIndex;
2111 _SglGetCurrentDisplay(void)
2113 return eglGetCurrentDisplay();
2117 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
2119 return eglQueryContext(dpy, ctx, attribute, pValue);
2129 _SglWaitNative(EGLint engine)
2131 return eglWaitNative(engine);
2134 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
2137 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
2139 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2141 _SglIndex sglIndex = (_SglIndex)surface;
2142 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2144 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2146 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2147 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy, (unsigned int)sglIndex);
2149 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
2152 if (pSglInfo->pBitmap != null)
2154 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2155 _SglUpdateBufferOSP(dpy, surface);
2157 if (!isEvasNativeSetEnabled)
2163 if (isEvasNativeSetEnabled)
2165 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2169 if (pSglInfo->pVisualElementImpl != null)
2171 pSglInfo->pVisualElementImpl->SetFlushNeeded();
2175 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2180 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
2181 if (pSglInfo->pFrame != null)
2183 if (pSglInfo->isFboAvailable)
2185 if (pSglInfo->glVersion == 1)
2187 _GlesFboSwapBuffers_1(pSglInfo->pFrame
2188 , pSglInfo->fboWidth
2189 , pSglInfo->fboHeight
2190 , pSglInfo->frameBufferObject
2191 , pSglInfo->textureId);
2193 else if (pSglInfo->glVersion == 2)
2195 _GlesFboSwapBuffers_2(pSglInfo->pFrame
2196 , pSglInfo->frameBufferObject
2197 , pSglInfo->textureId
2198 , pSglInfo->program);
2202 SysLog(NID_GRP, "ambiguous gl Version %d", pSglInfo->glVersion);
2203 pSglInfo->isFboAvailable = false;
2208 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2209 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2216 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2218 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2219 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2220 return eglCopyBuffers(dpy, surface, nativePixmap);
2223 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2225 __EglMustCastToProperFunctionPointerType
2226 _SglGetProcAddress(const char* pProcName)
2228 return eglGetProcAddress(pProcName);
2232 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2234 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2235 Tizen::Graphics::BufferInfo bufferInfo;
2236 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2238 _SglIndex sglIndex = (_SglIndex)surface;
2239 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2241 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2243 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2244 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2248 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2249 ecore_x_image_get(pSglInfo->pEcoreImage, pSglInfo->nativePixmap,
2250 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2252 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2257 #if defined(FGRAPHICS_INTERNAL_USE_FBO)
2259 _GlesGetCurrentFbo(void)
2261 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2263 _SglIndex sglIndex = (_SglIndex)_SglGetCurrentSurface(EGL_DRAW);
2264 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2266 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2268 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2269 SysLog(NID_GRP, "Fbo binding failed!!");
2273 GLuint ret = pSglInfo->frameBufferObject;
2274 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2280 _GlesFboEnableStencil(GLuint& frameBufferObject, GLuint& renderBuffer)
2282 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2284 _SglIndex sglIndex = (_SglIndex)_SglGetCurrentSurface(EGL_DRAW);
2285 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2287 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2289 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2293 if (!pSglInfo->isStencilEnabled)
2295 pSglInfo->isStencilEnabled = true;
2296 frameBufferObject = pSglInfo->frameBufferObject;
2297 renderBuffer = pSglInfo->stencilRenderBuffer;
2299 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2303 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2315 }} // Tizen::Graphics