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.
31 #if defined(_OSP_EMUL_)
32 #define FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER
34 #define FGRAPHICS_INTERNAL_USE_DRM
37 #define FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING
38 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
42 #include <Ecore_Evas.h>
44 #include <Evas_Engine_GL_X11.h>
46 #include <FBaseSysLog.h>
47 #include <FGrpBitmap.h>
48 #include <FGrpCoordinateSystem.h>
49 #include <FUiControl.h>
50 #include <FUiCtrlForm.h>
51 #include <FUiCtrlFrame.h>
52 #include <FUiWindow.h>
54 #include <FUi_EcoreEvasMgr.h>
55 #include <FUi_EcoreEvas.h>
57 #include <FGrp_BitmapTool.h>
58 #include <FGrp_BitmapImpl.h>
59 #include <FUi_ControlImpl.h>
60 #include <FUi_Control.h>
61 #include <FUi_WindowImpl.h>
62 #include <FUiAnim_VisualElementSurfaceImpl.h>
63 #include <FUiAnim_VisualElementImpl.h>
71 #include <elm_config.h>
73 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
77 #include <tbm_bufmgr.h>
81 typedef int _SglIndex;
84 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList);
85 EGLSurface _SglGetCurrentSurface(EGLint readDraw);
86 EGLNativePixmapType _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pixmap);
87 EGLNativePixmapType _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo);
89 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
90 void _GlesInterfaceTerminate_1();
91 void _GlesInterfaceTerminate_2();
94 #include <GLES2/gl2.h>
96 void _GlFlush_1(void);
97 void _GlFlush_2(void);
98 void _GlClear_1(GLbitfield mask);
99 void _GlClear_2(GLbitfield mask);
101 EGLBoolean _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
103 using namespace Tizen::Ui::Controls;
109 using namespace Tizen::Ui::Animations;
110 using namespace Tizen::Ui;
111 using namespace Tizen::Base;
113 namespace Tizen { namespace Graphics
124 #define FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT
125 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
126 void _PostRenderCallback(Ecore_Evas* ee);
127 void _SaveCurrentContext(_SglInfo* pSglInfo);
128 void _UnregisterRenderCallback(Evas_Object* pObject);
129 int __registerCallbackCount = 0;
130 _SglInfo* __pPreviousSglInfo = null;
133 #if !defined (_OSP_EMUL_)
134 #define FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP
136 bool isDoublePixmapEnabled = false;
138 #define FGRAPHICS_INTERNAL_USE_EVAS_NATIVE_SURFACE
139 bool isEvasNativeSetEnabled = false;
141 void _OnBoundsChanged(void* pData);
143 const int INVALID_SGL_INDEX = 0;
144 const int MAX_SGL_INDEX = 100;
150 : sglIndex(INVALID_SGL_INDEX)
151 , display(EGL_NO_DISPLAY)
152 , surface(EGL_NO_SURFACE)
153 , context(EGL_NO_CONTEXT)
154 , config((EGLConfig)0)
157 , nativePixmap((EGLNativePixmapType)0)
158 , pVisualElement(null)
159 , pVisualElementSurface(null)
162 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
171 , pSecondSglInfo(null)
175 virtual ~_SglInfo(void)
177 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
178 if (pEcoreImage != null)
180 ecore_x_image_free(pEcoreImage);
184 SysTryReturnVoidResult(NID_GRP, pObject != null, E_OPERATION_FAILED, "Invalid object.");
186 if (pVisualElement != null)
188 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
189 if (pVisualElementImpl != null)
191 pVisualElementImpl->SetDestroyedCallback(null, null);
195 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
196 _UnregisterRenderCallback(pObject);
198 evas_object_del(pObject);
199 delete pVisualElementSurface;
202 bool needAllocateObject = true;
203 if (isEvasNativeSetEnabled)
205 if (isDoublePixmapEnabled)
209 needAllocateObject = false;
213 if (needAllocateObject)
215 if (pVisualElement != null)
217 pVisualElement->SetSurface(null);
221 sglIndex = INVALID_SGL_INDEX;
222 display = EGL_NO_DISPLAY;
223 surface = EGL_NO_SURFACE;
224 context = EGL_NO_CONTEXT;
225 config = (EGLConfig)0;
228 nativePixmap = (EGLNativePixmapType)0;
229 pVisualElement = null;
230 pVisualElementSurface = null;
233 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
242 pSecondSglInfo = null;
252 Evas_Object* pObject;
253 EGLNativePixmapType nativePixmap;
254 VisualElement* pVisualElement;
255 VisualElementSurface* pVisualElementSurface;
257 Tizen::Ui::Window* pWindow;
258 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
259 Ecore_X_Image* pEcoreImage;
267 _SglInfo* pSecondSglInfo;
270 _SglInfo(const _SglInfo& sglInfo);
271 _SglInfo& operator =(const _SglInfo& rhs);
278 : nativePixmap((Pixmap)0)
279 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
281 , pTbmBufferObject(null)
287 virtual ~_PixmapInfo(void)
289 Display* pDisplay = (Display*)ecore_x_display_get();
290 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
291 tbm_bo_unmap(pTbmBufferObject);
297 tbm_bufmgr_deinit(pTbmBufMgr);
298 DRI2DestroyDrawable(pDisplay, nativePixmap);
300 XFreePixmap(pDisplay, nativePixmap);
302 nativePixmap = (Pixmap)0;
303 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
305 pTbmBufferObject = null;
312 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
313 tbm_bufmgr pTbmBufMgr;
314 tbm_bo pTbmBufferObject;
319 void _EvasObjectImageChange(_SglInfo* pSglInfo);
322 _OnBoundsChanged(void* pData)
324 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
325 SysTryReturnVoidResult(NID_GRP, pSglInfo != null
326 && pSglInfo->sglIndex > INVALID_SGL_INDEX
327 && pSglInfo->pVisualElement != null
328 && pSglInfo->pWindow != null
329 , E_INVALID_STATE, "Invalid state.");
331 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
333 __pPreviousSglInfo = null;
336 bool needSglMakeCurrent = false;
337 EGLDisplay eglDisplay = eglGetCurrentDisplay();
338 EGLSurface drawSurface = _SglGetCurrentSurface(EGL_DRAW);
339 EGLSurface readSurface = _SglGetCurrentSurface(EGL_READ);
340 EGLSurface eglContext = eglGetCurrentContext();
342 if (drawSurface != EGL_NO_SURFACE && readSurface != EGL_NO_SURFACE)
344 needSglMakeCurrent = true;
348 drawSurface = eglGetCurrentSurface(EGL_DRAW);
349 readSurface = eglGetCurrentSurface(EGL_READ);
352 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
353 EGLBoolean ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
354 pSglInfo->surface = null;
355 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
357 FloatRectangle rect = pSglInfo->pVisualElement->GetBounds();
358 int width = int(rect.width);
359 int height = int(rect.height);
360 SysTryReturnVoidResult(NID_GRP, width > 0 && height > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
361 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
362 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
363 SysTryReturnVoidResult(NID_GRP, widthPhysical > 0 && heightPhysical > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", widthPhysical, heightPhysical);
365 evas_object_image_size_set(pSglInfo->pObject, widthPhysical, heightPhysical);
366 evas_object_resize(pSglInfo->pObject, widthPhysical, heightPhysical);
368 delete pSglInfo->pBitmap;
369 pSglInfo->pBitmap = null;
370 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
371 SysTryReturnVoidResult(NID_GRP, bitmap.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
372 result r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
373 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
374 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, bitmap.get());
375 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
376 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, nativePixmap, null);
377 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
379 pSglInfo->nativePixmap = nativePixmap;
380 pSglInfo->surface = eglSurface;
381 pSglInfo->isBackbuffer = true;
382 pSglInfo->wasShown = false;
383 pSglInfo->swapDone = false;
384 pSglInfo->isFirstSwap = true;
386 if (isDoublePixmapEnabled)
388 _SglInfo* pSglInfoSecond = pSglInfo->pSecondSglInfo;
389 SysTryReturnVoidResult(NID_GRP, pSglInfoSecond != null, E_INVALID_STATE, "Invalid pSecondSglInfo.");
391 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
392 ret = eglDestroySurface(pSglInfoSecond->display, pSglInfoSecond->surface);
393 pSglInfoSecond->surface = null;
394 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
396 evas_object_image_size_set(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
397 evas_object_resize(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
399 delete pSglInfoSecond->pBitmap;
400 pSglInfoSecond->pBitmap = null;
401 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
402 SysTryReturnVoidResult(NID_GRP, bitmapSecond.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
403 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
404 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
405 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfoSecond->sglIndex, bitmapSecond.get());
406 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
407 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfoSecond->display, pSglInfoSecond->config, nativePixmap, null);
408 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
410 pSglInfoSecond->nativePixmap = nativePixmap;
411 pSglInfoSecond->surface = eglSurface;
412 pSglInfoSecond->pBitmap = bitmapSecond.release();
413 pSglInfoSecond->isBackbuffer = true;
414 pSglInfoSecond->wasShown = false;
415 pSglInfoSecond->swapDone = true;
417 pSglInfo->isFirstSwap = true;
419 _EvasObjectImageChange(pSglInfoSecond);
422 pSglInfo->pBitmap = bitmap.release();
423 _EvasObjectImageChange(pSglInfo);
425 if (needSglMakeCurrent)
427 _SglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
431 eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
438 _OnDestroyed(void* pData)
440 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
442 if (pSglInfo != null)
444 pSglInfo->pVisualElement = null;
446 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
448 pSglInfo->pSecondSglInfo->pVisualElement = null;
453 class _SglInfoTableManipulator
456 _SglInfoTableManipulator()
458 result r = __SglMutex.Create();
459 SysTryLog(NID_GRP, r == E_SUCCESS, "Failed to create mutex. [%s]", GetErrorMessage(r));
460 __SglIndexLastUsed = INVALID_SGL_INDEX;
461 __SglInitialized = false;
464 ~_SglInfoTableManipulator()
469 FindNextEmptySlotOfSglInfoTable()
471 if (!__SglInitialized)
473 if (CreateSglInfoTable() == false)
475 return INVALID_SGL_INDEX;
479 _SglIndex sglIndex = INVALID_SGL_INDEX;
480 _SglIndex index = __SglIndexLastUsed;
482 __SglMutex.Acquire();
483 for (int i = 1; i < MAX_SGL_INDEX; i++)
487 if (index >= MAX_SGL_INDEX)
492 if (__SglInfoTable[index] == null)
495 __SglIndexLastUsed = index;
499 __SglMutex.Release();
502 if (sglIndex <= INVALID_SGL_INDEX)
504 return INVALID_SGL_INDEX;
515 __SglMutex.Acquire();
517 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
519 __SglInfoTable[i] = null;
522 __SglInfoTable[0] = new (std::nothrow) _SglInfo;
523 if (__SglInfoTable[0] != null)
526 __SglInitialized = true;
527 __SglInfoTable[0]->glVersion = 2;
530 __SglMutex.Release();
536 DestroySglInfoTable()
538 __SglMutex.Acquire();
540 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
542 if (__SglInfoTable[i] != null)
544 delete __SglInfoTable[i];
545 __SglInfoTable[i] = null;
548 __SglInitialized = false;
550 __SglMutex.Release();
554 LockSglInfoTable(_SglIndex index)
556 __SglMutex.Acquire();
558 if (index < INVALID_SGL_INDEX || index >= MAX_SGL_INDEX)
563 return __SglInfoTable[index];
569 __SglMutex.Release();
575 _SglInfo* newSglInfo = new (std::nothrow) _SglInfo;
576 if (newSglInfo == null)
578 SysLog(NID_GRP, "CreateSglIndex fail to allocate _SglInfo!!");
579 return INVALID_SGL_INDEX;
582 int sglIndex = FindNextEmptySlotOfSglInfoTable();
583 if (sglIndex == INVALID_SGL_INDEX)
587 SysLog(NID_GRP, "CreateSglIndex failed!!");
588 return INVALID_SGL_INDEX;
591 __SglMutex.Acquire();
592 __SglInfoTable[sglIndex] = newSglInfo;
593 __SglMutex.Release();
599 DestroySglIndex(_SglIndex sglIndex)
601 if (sglIndex < 1 || sglIndex >= MAX_SGL_INDEX)
603 SysLog(NID_GRP, "sglIndex:%#x is out of range.", (unsigned int)sglIndex);
607 __SglMutex.Acquire();
609 if (sglIndex <= INVALID_SGL_INDEX || __SglInfoTable[sglIndex] == null)
611 __SglMutex.Release();
613 SysLog(NID_GRP, "DestroySglIndex failed!! sglIndex:%#x", (unsigned int)sglIndex);
617 delete __SglInfoTable[sglIndex];
618 __SglInfoTable[sglIndex] = null;
620 __SglMutex.Release();
626 GetSglIndexForSurface(EGLSurface surface)
628 __SglMutex.Acquire();
631 for (int i = 0; i < MAX_SGL_INDEX; i++)
633 if (__SglInfoTable[i] != null && __SglInfoTable[i]->surface == surface)
640 __SglMutex.Release();
645 static _SglInfoTableManipulator* GetInstance(void)
647 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
651 pthread_once(&once_block, __InitSglInfoTableManipulator);
654 return __pTheInstance;
658 static void __InitSglInfoTableManipulator(void)
660 static _SglInfoTableManipulator instance;
661 __pTheInstance = &instance;
665 Runtime::Mutex __SglMutex;
666 _SglInfo* __SglInfoTable[MAX_SGL_INDEX];
667 _SglIndex __SglIndexLastUsed;
668 bool __SglInitialized;
670 static _SglInfoTableManipulator* __pTheInstance;
672 _SglInfoTableManipulator* _SglInfoTableManipulator::__pTheInstance = null;
675 _PixmapSurfaceDestroyCallback(void* pCallbackParam)
677 delete (_PixmapInfo*)pCallbackParam;
680 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
682 _PixmapLockCallBack(void* pCallbackParam)
684 tbm_bo_map((tbm_bo)pCallbackParam, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
688 _PixmapUnlockCallBack(void* pCallbackParam)
690 tbm_bo_unmap((tbm_bo)pCallbackParam);
695 _IsEvasGlEnabled(void)
697 const char* pString = elm_config_preferred_engine_get();
698 String engineName(pString);
700 if (engineName.Contains(String("opengl_x11")))
702 SysLog(NID_GRP, "gl backend : %s", pString);
705 else if (engineName.Contains(String("software_x11")))
707 SysLog(NID_GRP, "sw backend : %s", pString);
712 pString = elm_config_engine_get();
713 String engineName(pString);
714 if (engineName.Contains(String("opengl_x11")))
716 SysLog(NID_GRP, "system gl backend : %s", pString);
721 SysLog(NID_GRP, "system sw backend : %s", pString);
726 _EvasObjectImageChange(_SglInfo* pSglInfo)
728 if (isEvasNativeSetEnabled)
730 Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
736 Evas_Engine_Info_GL_X11* pEvasInfo = (Evas_Engine_Info_GL_X11 *)evas_engine_info_get(pEvas);
737 if (pEvasInfo == null)
741 Evas_Native_Surface nativeSurface = {0, };
742 nativeSurface.type = EVAS_NATIVE_SURFACE_X11;
743 nativeSurface.version = EVAS_NATIVE_SURFACE_VERSION;
744 nativeSurface.data.x11.pixmap = (unsigned long)pSglInfo->nativePixmap;
745 nativeSurface.data.x11.visual = pEvasInfo->info.visual;
746 evas_object_image_native_surface_set(pSglInfo->pObject, &nativeSurface);
750 BufferInfo bufferInfo;
751 pSglInfo->pBitmap->Lock(bufferInfo);
752 evas_object_image_data_set(pSglInfo->pObject, bufferInfo.pPixels);
753 pSglInfo->pBitmap->Unlock();
757 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
759 _PostRenderCallback(Ecore_Evas* ee)
761 if (__pPreviousSglInfo != null)
763 EGLDisplay display = __pPreviousSglInfo->display;
764 EGLSurface surface = __pPreviousSglInfo->surface;
765 EGLContext context = __pPreviousSglInfo->context;
767 if (isDoublePixmapEnabled)
769 _SglInfo* pBackSglInfo = null;
770 _SglInfo* pFrontSglInfo = null;
772 if (__pPreviousSglInfo->isBackbuffer)
774 pBackSglInfo = __pPreviousSglInfo;
775 pFrontSglInfo = __pPreviousSglInfo->pSecondSglInfo;
779 pBackSglInfo = __pPreviousSglInfo->pSecondSglInfo;
780 pFrontSglInfo = __pPreviousSglInfo;
783 if (!pBackSglInfo->wasShown && __pPreviousSglInfo->pVisualElement != null)
785 __pPreviousSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
786 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
787 evas_object_hide(pBackSglInfo->pObject);
789 pBackSglInfo->wasShown = true;
790 pFrontSglInfo->swapDone = true;
793 surface = pBackSglInfo->surface;
796 EGLBoolean ret = eglMakeCurrent(display, surface, surface, context);
797 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
798 , (unsigned int)display
799 , (unsigned int)surface
800 , (unsigned int)surface
801 , (unsigned int)context
802 , (unsigned int)eglGetError());
804 if (__pPreviousSglInfo->glVersion == 1)
806 _GlClear_1(GL_COLOR_BUFFER_BIT);
810 _GlClear_2(GL_COLOR_BUFFER_BIT);
816 _SaveCurrentContext(_SglInfo* pSglInfo)
818 __pPreviousSglInfo = pSglInfo;
822 _RegisterRenderCallback(Evas_Object* pObject)
826 if (__registerCallbackCount == 0)
828 Evas* pEvas = evas_object_evas_get(pObject);
834 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
835 if (pEcoreEvas == null)
840 ecore_evas_callback_post_render_set(pEcoreEvas, _PostRenderCallback);
842 __registerCallbackCount++;
847 _UnregisterRenderCallback(Evas_Object* pObject)
851 __registerCallbackCount--;
853 if (__registerCallbackCount == 0)
855 Evas* pEvas = evas_object_evas_get(pObject);
861 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
862 if (pEcoreEvas == null)
867 ecore_evas_callback_post_render_set(pEcoreEvas, NULL);
871 #endif //#if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
883 return eglGetError();
887 _SglGetDisplay(EGLNativeDisplayType displayId)
889 if (displayId == (EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)
891 return eglGetDisplay((EGLNativeDisplayType) ecore_x_display_get());
894 return eglGetDisplay((EGLNativeDisplayType) displayId);
898 _SglInitialize(EGLDisplay dpy, EGLint* pMajor, EGLint* pMinor)
900 return eglInitialize(dpy, pMajor, pMinor);
904 _SglTerminate(EGLDisplay dpy)
906 _GlesInterfaceTerminate_1();
907 _GlesInterfaceTerminate_2();
909 _SglInfoTableManipulator::GetInstance()->DestroySglInfoTable();
911 if (!_IsEvasGlEnabled())
916 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
917 __registerCallbackCount = 0;
918 __pPreviousSglInfo = null;
926 _SglQueryString(EGLDisplay dpy, EGLint name)
928 return eglQueryString(dpy, name);
932 _SglGetConfigs(EGLDisplay dpy, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
934 return eglGetConfigs(dpy, pConfigs, configSize, pNumConfig);
938 _SglChooseConfig(EGLDisplay dpy, const EGLint* pAttribList, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
940 return eglChooseConfig(dpy, pAttribList, pConfigs, configSize, pNumConfig);
944 _SglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* pValue)
946 return eglGetConfigAttrib(dpy, config, attribute, pValue);
950 _SglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* pAttribList)
952 _SglIndex sglIndex = INVALID_SGL_INDEX;
953 Object* pObj = (Object*)win;
954 VisualElement* pVisualElement = dynamic_cast<VisualElement*> (pObj);
955 Tizen::Ui::Control* pControl = dynamic_cast<Tizen::Ui::Control*> (pObj);
956 #if 0//!defined(_OSP_EMUL_)
957 Tizen::Ui::Controls::Frame* pFrame = dynamic_cast<Tizen::Ui::Controls::Frame*> (pControl);
959 SysTryReturn(NID_GRP, pControl != null || pVisualElement != null, EGL_NO_SURFACE, E_INVALID_ARG, "Invalid NativeWindow.");
960 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
962 #if 0//!defined(_OSP_EMUL_)
963 if (pFrame != null && !_IsEvasGlEnabled())
965 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
966 _WindowImpl* pWindowImpl = dynamic_cast<_WindowImpl*> (pControlImpl);
967 SysTryReturn(NID_GRP, pWindowImpl != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window state.");
969 EGLNativeWindowType nativeWindow = (EGLNativeWindowType)pWindowImpl->GetNativeHandle();
970 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
971 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid SglIndex.");
973 EGLSurface windowSurface = eglCreateWindowSurface(dpy, config, nativeWindow, pAttribList);
974 if (windowSurface == EGL_NO_SURFACE)
976 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
981 VisualElement* pVisualElement = pControlImpl->GetCore().GetVisualElement();
982 if (pVisualElement == null)
984 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
985 return EGL_NO_SURFACE;
988 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
989 if (pVisualElementImpl == null)
991 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
992 return EGL_NO_SURFACE;
995 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
997 pSglInfo->surface = windowSurface;
999 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1002 return (EGLSurface)sglIndex;
1005 #endif //#if !defined(_OSP_EMUL_)
1007 result r = E_SUCCESS;
1009 #if defined (FGRAPHICS_INTERNAL_USE_EVAS_NATIVE_SURFACE)
1010 isEvasNativeSetEnabled = _IsEvasGlEnabled();
1012 isEvasNativeSetEnabled = false;
1015 #if defined (FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP)
1016 isDoublePixmapEnabled = isEvasNativeSetEnabled;
1018 isDoublePixmapEnabled = false;
1021 if (pVisualElement == null)
1023 pVisualElement = pControl->GetVisualElement();
1025 SysTryReturn(NID_GRP, pVisualElement != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1027 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1028 SysTryReturn(NID_GRP, pVisualElementImpl != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1030 FloatRectangle rect = pVisualElement->GetBounds();
1031 int width = int(rect.width);
1032 int height = int(rect.height);
1033 SysTryReturn(NID_GRP, width > 0 && height > 0, EGL_NO_SURFACE, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
1035 Control* pFrame = pControl;
1036 Control* pTemp = pFrame->GetParent();
1037 while(pTemp != null)
1040 pTemp = pTemp->GetParent();
1043 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
1044 SysTryReturn(NID_GRP, pWindow != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window.");
1046 VisualElementSurface* pVisualElementSurface = pVisualElement->GetSurfaceN();
1047 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1049 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
1050 if (pVisualElementSurfaceImpl == null)
1052 SysLogException(NID_GRP, E_OPERATION_FAILED, "Propagating.");
1053 delete pVisualElementSurface;
1054 return EGL_NO_SURFACE;
1057 Evas_Object* pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
1058 delete pVisualElementSurface;
1060 Evas* pEvas = evas_object_evas_get(pObject);
1061 pObject = evas_object_image_filled_add(pEvas);
1062 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1064 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
1065 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
1067 evas_object_image_alpha_set(pObject, EINA_TRUE);
1068 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1069 evas_object_resize(pObject, widthPhysical, heightPhysical);
1070 evas_object_hide(pObject);
1072 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1073 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1074 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1076 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
1077 SysTryReturn(NID_GRP, bitmap.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1079 r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
1080 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1082 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmap.get(), null);
1083 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1085 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1086 pSglInfo->sglIndex = sglIndex;
1087 pSglInfo->display = dpy;
1088 pSglInfo->config = config;
1089 pSglInfo->pVisualElement = pVisualElement;
1090 pSglInfo->pWindow = pWindow;
1091 pSglInfo->pObject = pObject;
1092 pSglInfo->pVisualElementSurface = pVisualElementSurface;
1093 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1095 if (isDoublePixmapEnabled)
1097 pObject = evas_object_image_filled_add(pEvas);
1098 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1100 evas_object_image_alpha_set(pObject, EINA_TRUE);
1101 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1102 evas_object_resize(pObject, widthPhysical, heightPhysical);
1103 evas_object_hide(pObject);
1105 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1106 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1107 SysTryReturn(NID_GRP, pSglInfo->pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1109 delete pSglInfo->pBitmap;
1110 pSglInfo->pBitmap = null;
1112 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
1113 SysTryReturn(NID_GRP, bitmapSecond.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1115 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
1116 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1118 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmapSecond.get(), null);
1119 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1121 _SglInfo* pSglInfoSecond = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1122 pSglInfoSecond->sglIndex = sglIndex;
1123 pSglInfoSecond->display = dpy;
1124 pSglInfoSecond->config = config;
1125 pSglInfoSecond->pVisualElement = pVisualElement;
1126 pSglInfoSecond->pWindow = pWindow;
1127 pSglInfoSecond->pObject = pObject;
1128 pSglInfoSecond->pVisualElementSurface = pVisualElementSurface;
1129 pSglInfoSecond->swapDone = true;
1130 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1132 pSglInfo->pSecondSglInfo = pSglInfoSecond;
1133 pSglInfoSecond->pSecondSglInfo = pSglInfo;
1135 pSglInfoSecond->pBitmap = bitmapSecond.release();
1136 _EvasObjectImageChange(pSglInfoSecond);
1140 pVisualElement->SetSurface(pSglInfo->pVisualElementSurface);
1143 pSglInfo->pBitmap = bitmap.release();
1144 _EvasObjectImageChange(pSglInfo);
1146 pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChanged, pSglInfo);
1147 pVisualElementImpl->SetDestroyedCallback(_OnDestroyed, pSglInfo);
1148 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1149 _RegisterRenderCallback(pSglInfo->pObject);
1151 return (EGLSurface)pSglInfo->sglIndex;
1156 _SglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* pAttribList)
1158 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1159 _SglIndex sglIndex = INVALID_SGL_INDEX;
1161 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1162 if (sglIndex <= INVALID_SGL_INDEX)
1164 SysLog(NID_GRP, "_SglCreatePbufferSurface failed!! dpy:%#x config:%#x pAttribList:%#x",
1165 (unsigned int)dpy, (unsigned int)config, (unsigned int)pAttribList);
1167 return eglCreatePbufferSurface(EGL_NO_DISPLAY, config, pAttribList);
1170 EGLSurface pbufferSurface = eglCreatePbufferSurface(dpy, config, pAttribList);
1171 if (pbufferSurface == EGL_NO_SURFACE)
1173 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1178 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1180 pSglInfo->surface = pbufferSurface;
1182 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1185 return (EGLSurface)sglIndex;
1188 _OSP_LOCAL_ EGLNativePixmapType
1189 _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pBitmap)
1193 int bitsPerPixel = 0;
1194 Display* pNativeDisplay = null;
1195 Drawable nativeWindow = 0;
1196 result r = E_FAILURE;
1197 Tizen::Graphics::BufferInfo bufferInfo;
1198 _PixmapInfo* pPixmapInfo = null;
1199 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1200 unsigned int attachments[] = { DRI2BufferFrontLeft };
1201 char* pDeviceName = null;
1202 char* pDriverName = null;
1203 DRI2Buffer* pDri2Buffer = null;
1206 int dri2BufferCount = 0;
1207 tbm_bo_handle tbmData = { null, };
1210 drm_magic_t magic = 0;
1212 _SglInfo* pSglInfo = null;
1213 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1215 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1216 if (pBitmap == null || sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1218 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1221 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1223 r = pBitmap->Lock(bufferInfo);
1229 width = bufferInfo.width;
1230 height = bufferInfo.height;
1231 bitsPerPixel = bufferInfo.bitsPerPixel;
1233 r = pBitmap->Unlock();
1234 if (r != E_SUCCESS || width <= 0 || height <= 0 || bitsPerPixel <= 0)
1239 pNativeDisplay = (Display*) ecore_x_display_get();
1240 nativeWindow = DefaultRootWindow(pNativeDisplay);
1242 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1243 if (pPixmapInfo == null)
1248 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height,
1249 ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1250 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1255 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1256 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1257 XSync(pNativeDisplay, False);
1259 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1261 if (!ret || pDeviceName == null)
1266 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1269 if (pPixmapInfo->drmFd < 0)
1274 drmGetMagic(pPixmapInfo->drmFd, &magic);
1275 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1281 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1282 if (pPixmapInfo->pTbmBufMgr == null)
1287 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1288 if (pDri2Buffer == null)
1293 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1295 if (pPixmapInfo->pTbmBufferObject == null)
1300 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1301 if (tbmData.ptr == null)
1306 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, tbmData.ptr, width * bitsPerPixel / 8,
1307 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1313 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1314 _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1320 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1322 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1324 pSglInfo->pEcoreImage = ecore_x_image_new(width
1326 , ecore_x_default_visual_get(pNativeDisplay, ecore_x_default_screen_get())
1327 , ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1329 if (pSglInfo->pEcoreImage == null)
1331 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1335 ecore_x_image_get(pSglInfo->pEcoreImage
1336 , pPixmapInfo->nativePixmap, 0, 0, 0, 0
1344 void* pSource = ecore_x_image_data_get(pSglInfo->pEcoreImage, &bpl, &rows, &bpp);
1346 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pSource, width * bitsPerPixel / 8,
1347 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1350 ecore_x_image_free(pSglInfo->pEcoreImage);
1351 pSglInfo->pEcoreImage = null;
1352 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1354 SysLog(NID_GRP, "change buffer failed! pSource %#x %d %d %d", (unsigned int)pSource, bpl, rows, bpp);
1358 pSglInfo->width = width;
1359 pSglInfo->height = height;
1361 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1363 #endif //#if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1364 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1366 pBitmap->Lock(bufferInfo);
1367 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1370 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1373 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1374 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1378 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1382 close(pPixmapInfo->drmFd);
1386 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1388 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1396 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1397 return (EGLNativePixmapType)0;
1400 _OSP_LOCAL_ EGLNativePixmapType
1401 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1405 int bitsPerPixel = 0;
1406 Display* pNativeDisplay = null;
1407 Drawable nativeWindow = 0;
1408 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1409 _PixmapInfo* pPixmapInfo = null;
1410 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1411 unsigned int attachments[] = { DRI2BufferFrontLeft };
1412 char* pDeviceName = null;
1413 char* pDriverName = null;
1414 DRI2Buffer* pDri2Buffer = null;
1417 int dri2BufferCount = 0;
1418 tbm_bo_handle tbmData = { null, };
1421 result r = E_FAILURE;
1422 drm_magic_t magic = 0;
1424 if (pBitmap == null)
1429 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1430 if (pBitmapImpl == null)
1435 width = bufferInfo.width;
1436 height = bufferInfo.height;
1437 bitsPerPixel = bufferInfo.bitsPerPixel;
1439 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1444 pNativeDisplay = (Display*) ecore_x_display_get();
1445 nativeWindow = DefaultRootWindow(pNativeDisplay);
1447 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1448 if (pPixmapInfo == null)
1453 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height
1455 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1460 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1461 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1462 XSync(pNativeDisplay, False);
1464 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1466 if (!ret || pDeviceName == null)
1471 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1473 if (pPixmapInfo->drmFd < 0)
1478 drmGetMagic(pPixmapInfo->drmFd, &magic);
1479 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1485 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1486 if (pPixmapInfo->pTbmBufMgr == null)
1491 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1492 if (pDri2Buffer == null)
1497 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1499 if (pPixmapInfo->pTbmBufferObject == null)
1504 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1505 if (tbmData.ptr == null)
1509 bufferInfo.pPixels = tbmData.ptr;
1511 bufferInfo.bitsPerPixel = 32;
1512 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1513 bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;
1514 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1515 r = pBitmapImpl->Construct(bufferInfo);
1521 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap
1522 , _PixmapSurfaceDestroyCallback, pPixmapInfo
1523 , _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject
1524 ,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1528 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1530 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1532 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1534 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1538 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1542 close(pPixmapInfo->drmFd);
1546 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1547 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1556 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1557 return (EGLNativePixmapType)0;
1561 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1563 _SglIndex sglIndex = INVALID_SGL_INDEX;
1564 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1565 EGLNativePixmapType eglNativePixmap = 0;
1566 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1567 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1569 if (pBitmap == null)
1574 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1575 if (sglIndex <= INVALID_SGL_INDEX)
1580 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1581 if (eglNativePixmap == 0)
1586 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1587 if (pixmapSurface == EGL_NO_SURFACE)
1589 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1594 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1596 pSglInfo->nativePixmap = eglNativePixmap;
1597 pSglInfo->surface = pixmapSurface;
1599 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1602 return (EGLSurface)sglIndex;
1605 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1609 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1610 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1611 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1615 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1617 EGLBoolean ret = EGL_FALSE;
1618 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1620 _SglIndex sglIndex = (_SglIndex)surface;
1621 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1623 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1625 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1626 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1627 , (unsigned int)surface);
1628 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1631 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1632 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
1634 __pPreviousSglInfo = null;
1638 ret = eglDestroySurface(dpy, pSglInfo->surface);
1639 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1641 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1643 eglDestroySurface(dpy, pSglInfo->pSecondSglInfo->surface);
1644 pSglInfoTableManipulatorInstance->DestroySglIndex(pSglInfo->pSecondSglInfo->sglIndex);
1647 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1653 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1655 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1657 _SglIndex sglIndex = (_SglIndex)surface;
1658 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1660 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1662 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1663 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1664 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1665 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1668 EGLBoolean ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1669 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1675 _SglBindAPI(EGLenum api)
1677 return eglBindAPI(api);
1683 return eglQueryAPI();
1689 return eglWaitClient();
1693 _SglReleaseThread(void)
1695 return eglReleaseThread();
1699 _SglCreatePbufferFromClientBuffer(
1700 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1702 _SglIndex sglIndex = INVALID_SGL_INDEX;
1703 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1705 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1706 if (sglIndex <= INVALID_SGL_INDEX)
1708 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1709 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1710 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1712 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1715 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1716 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1718 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1723 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1725 pSglInfo->surface = pbufferFromClientBuffer;
1727 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1730 return (EGLSurface)sglIndex;
1734 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1736 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1738 _SglIndex sglIndex = (_SglIndex)surface;
1739 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1741 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1743 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1744 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1745 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1746 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1748 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1751 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1752 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1758 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
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, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1769 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1771 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1774 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1775 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1781 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1783 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1785 _SglIndex sglIndex = (_SglIndex)surface;
1786 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1788 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1790 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1791 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1792 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1794 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1797 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1798 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1804 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1806 return eglSwapInterval(dpy, interval);
1810 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1812 return eglCreateContext(dpy, config, shareContext, pAttribList);
1816 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1818 return eglDestroyContext(dpy, ctx);
1822 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1824 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1826 _SglIndex sglIndexDraw = (_SglIndex)draw;
1827 _SglIndex sglIndexRead = (_SglIndex)read;
1829 EGLSurface sglInfoReadSurface;
1831 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1833 if (sglInfoRead == null)
1835 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1836 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1837 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1838 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1840 sglInfoReadSurface = sglInfoRead->surface;
1842 if (isDoublePixmapEnabled && !sglInfoRead->isBackbuffer)
1844 sglInfoReadSurface = sglInfoRead->pSecondSglInfo->surface;
1847 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1850 _SglInfo* pSglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1851 if (pSglInfoDraw == null)
1853 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1854 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1855 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1856 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1859 if (isDoublePixmapEnabled && !pSglInfoDraw->isBackbuffer && pSglInfoDraw->pSecondSglInfo != null)
1861 pSglInfoDraw = pSglInfoDraw->pSecondSglInfo;
1864 pSglInfoDraw->context = ctx;
1866 EGLBoolean ret = eglMakeCurrent(dpy, pSglInfoDraw->surface, sglInfoReadSurface, ctx);
1868 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1869 if (draw != EGL_NO_SURFACE)
1871 _SaveCurrentContext(pSglInfoDraw);
1875 if (pSglInfoDraw->glVersion == 0 && ctx != EGL_NO_CONTEXT)
1877 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &pSglInfoDraw->glVersion);
1880 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1886 _SglGetCurrentContext()
1888 return eglGetCurrentContext();
1892 _SglGetCurrentSurface(EGLint readDraw)
1894 EGLSurface surface = EGL_NO_SURFACE;
1895 _SglIndex sglIndex = INVALID_SGL_INDEX;
1897 surface = eglGetCurrentSurface(readDraw);
1898 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
1900 if (sglIndex < INVALID_SGL_INDEX)
1902 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
1903 return EGL_NO_SURFACE;
1906 return (EGLSurface)sglIndex;
1910 _SglGetCurrentDisplay(void)
1912 return eglGetCurrentDisplay();
1916 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
1918 return eglQueryContext(dpy, ctx, attribute, pValue);
1928 _SglWaitNative(EGLint engine)
1930 return eglWaitNative(engine);
1933 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
1936 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1938 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1940 _SglIndex sglIndex = (_SglIndex)surface;
1941 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1943 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1945 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1946 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1947 , (unsigned int)sglIndex);
1949 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
1952 if (pSglInfo->pBitmap != null)
1954 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1955 _SglUpdateBufferOSP(dpy, surface);
1957 if (isEvasNativeSetEnabled)
1959 if (pSglInfo->glVersion == 1)
1974 if (isEvasNativeSetEnabled)
1976 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1978 if (pSglInfo->swapDone || pSglInfo->pSecondSglInfo->swapDone)
1980 _SglInfo* pBackSglInfo = null;
1981 _SglInfo* pFrontSglInfo = null;
1983 if (pSglInfo->isBackbuffer)
1985 pBackSglInfo = pSglInfo;
1986 pFrontSglInfo = pSglInfo->pSecondSglInfo;
1990 pBackSglInfo = pSglInfo->pSecondSglInfo;
1991 pFrontSglInfo = pSglInfo;
1993 pBackSglInfo->isBackbuffer = false;
1994 pFrontSglInfo->isBackbuffer = true;
1996 pFrontSglInfo->wasShown = false;
1997 pFrontSglInfo->swapDone = false;
1998 if (pSglInfo->pVisualElement != null)
2000 pSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
2002 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
2003 evas_object_hide(pBackSglInfo->pObject);
2005 if (pSglInfo->isFirstSwap)
2007 pBackSglInfo->isFirstSwap = false;
2008 pFrontSglInfo->isFirstSwap = false;
2011 BufferInfo bufferInfo;
2012 pFrontSglInfo->pBitmap->Lock(bufferInfo);
2013 pFrontSglInfo->pBitmap->Merge(Point(0, 0), *pBackSglInfo->pBitmap, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
2014 pFrontSglInfo->pBitmap->Unlock();
2020 if (pSglInfo->pObject != null)
2022 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2028 if (pSglInfo->pVisualElement != null)
2030 pSglInfo->pVisualElement->SetFlushNeeded();
2034 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2039 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2040 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2047 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2049 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2050 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2051 return eglCopyBuffers(dpy, surface, nativePixmap);
2054 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2056 __EglMustCastToProperFunctionPointerType
2057 _SglGetProcAddress(const char* pProcName)
2059 return eglGetProcAddress(pProcName);
2063 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2065 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2066 Tizen::Graphics::BufferInfo bufferInfo;
2067 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2069 _SglIndex sglIndex = (_SglIndex)surface;
2070 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2072 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2074 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2075 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2079 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2080 ecore_x_image_get(pSglInfo->pEcoreImage, (Ecore_X_Drawable)pSglInfo->nativePixmap,
2081 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2083 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2094 }} // Tizen::Graphics