2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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);
292 tbm_bo_unref(pTbmBufferObject);
298 tbm_bufmgr_deinit(pTbmBufMgr);
299 DRI2DestroyDrawable(pDisplay, nativePixmap);
301 XFreePixmap(pDisplay, nativePixmap);
303 nativePixmap = (Pixmap)0;
304 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
306 pTbmBufferObject = null;
313 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
314 tbm_bufmgr pTbmBufMgr;
315 tbm_bo pTbmBufferObject;
320 void _EvasObjectImageChange(_SglInfo* pSglInfo);
323 _OnBoundsChanged(void* pData)
325 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
326 SysTryReturnVoidResult(NID_GRP, pSglInfo != null
327 && pSglInfo->sglIndex > INVALID_SGL_INDEX
328 && pSglInfo->pVisualElement != null
329 && pSglInfo->pWindow != null
330 , E_INVALID_STATE, "Invalid state.");
332 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
334 __pPreviousSglInfo = null;
337 bool needSglMakeCurrent = false;
338 EGLDisplay eglDisplay = eglGetCurrentDisplay();
339 EGLSurface drawSurface = _SglGetCurrentSurface(EGL_DRAW);
340 EGLSurface readSurface = _SglGetCurrentSurface(EGL_READ);
341 EGLSurface eglContext = eglGetCurrentContext();
343 if (drawSurface != EGL_NO_SURFACE && readSurface != EGL_NO_SURFACE)
345 needSglMakeCurrent = true;
349 drawSurface = eglGetCurrentSurface(EGL_DRAW);
350 readSurface = eglGetCurrentSurface(EGL_READ);
353 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
354 EGLBoolean ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
355 pSglInfo->surface = null;
356 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
358 FloatRectangle rect = pSglInfo->pVisualElement->GetBounds();
359 int width = int(rect.width);
360 int height = int(rect.height);
361 SysTryReturnVoidResult(NID_GRP, width > 0 && height > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
362 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
363 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
364 SysTryReturnVoidResult(NID_GRP, widthPhysical > 0 && heightPhysical > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", widthPhysical, heightPhysical);
366 evas_object_image_size_set(pSglInfo->pObject, widthPhysical, heightPhysical);
367 evas_object_resize(pSglInfo->pObject, widthPhysical, heightPhysical);
369 delete pSglInfo->pBitmap;
370 pSglInfo->pBitmap = null;
371 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
372 SysTryReturnVoidResult(NID_GRP, bitmap.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
373 result r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
374 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
375 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, bitmap.get());
376 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
377 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, nativePixmap, null);
378 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
380 pSglInfo->nativePixmap = nativePixmap;
381 pSglInfo->surface = eglSurface;
382 pSglInfo->isBackbuffer = true;
383 pSglInfo->wasShown = false;
384 pSglInfo->swapDone = false;
385 pSglInfo->isFirstSwap = true;
387 if (isDoublePixmapEnabled)
389 _SglInfo* pSglInfoSecond = pSglInfo->pSecondSglInfo;
390 SysTryReturnVoidResult(NID_GRP, pSglInfoSecond != null, E_INVALID_STATE, "Invalid pSecondSglInfo.");
392 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
393 ret = eglDestroySurface(pSglInfoSecond->display, pSglInfoSecond->surface);
394 pSglInfoSecond->surface = null;
395 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
397 evas_object_image_size_set(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
398 evas_object_resize(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
400 delete pSglInfoSecond->pBitmap;
401 pSglInfoSecond->pBitmap = null;
402 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
403 SysTryReturnVoidResult(NID_GRP, bitmapSecond.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
404 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
405 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
406 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfoSecond->sglIndex, bitmapSecond.get());
407 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
408 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfoSecond->display, pSglInfoSecond->config, nativePixmap, null);
409 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
411 pSglInfoSecond->nativePixmap = nativePixmap;
412 pSglInfoSecond->surface = eglSurface;
413 pSglInfoSecond->pBitmap = bitmapSecond.release();
414 pSglInfoSecond->isBackbuffer = true;
415 pSglInfoSecond->wasShown = false;
416 pSglInfoSecond->swapDone = true;
418 pSglInfo->isFirstSwap = true;
420 _EvasObjectImageChange(pSglInfoSecond);
423 pSglInfo->pBitmap = bitmap.release();
424 _EvasObjectImageChange(pSglInfo);
426 if (needSglMakeCurrent)
428 _SglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
432 eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
439 _OnDestroyed(void* pData)
441 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
443 if (pSglInfo != null)
445 pSglInfo->pVisualElement = null;
447 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
449 pSglInfo->pSecondSglInfo->pVisualElement = null;
454 class _SglInfoTableManipulator
457 _SglInfoTableManipulator()
459 result r = __SglMutex.Create();
460 SysTryLog(NID_GRP, r == E_SUCCESS, "Failed to create mutex. [%s]", GetErrorMessage(r));
461 __SglIndexLastUsed = INVALID_SGL_INDEX;
462 __SglInitialized = false;
465 ~_SglInfoTableManipulator()
470 FindNextEmptySlotOfSglInfoTable()
472 if (!__SglInitialized)
474 if (CreateSglInfoTable() == false)
476 return INVALID_SGL_INDEX;
480 _SglIndex sglIndex = INVALID_SGL_INDEX;
481 _SglIndex index = __SglIndexLastUsed;
483 __SglMutex.Acquire();
484 for (int i = 1; i < MAX_SGL_INDEX; i++)
488 if (index >= MAX_SGL_INDEX)
493 if (__SglInfoTable[index] == null)
496 __SglIndexLastUsed = index;
500 __SglMutex.Release();
503 if (sglIndex <= INVALID_SGL_INDEX)
505 return INVALID_SGL_INDEX;
516 __SglMutex.Acquire();
518 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
520 __SglInfoTable[i] = null;
523 __SglInfoTable[0] = new (std::nothrow) _SglInfo;
524 if (__SglInfoTable[0] != null)
527 __SglInitialized = true;
528 __SglInfoTable[0]->glVersion = 2;
531 __SglMutex.Release();
537 DestroySglInfoTable()
539 __SglMutex.Acquire();
541 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
543 if (__SglInfoTable[i] != null)
545 delete __SglInfoTable[i];
546 __SglInfoTable[i] = null;
549 __SglInitialized = false;
551 __SglMutex.Release();
555 LockSglInfoTable(_SglIndex index)
557 __SglMutex.Acquire();
559 if (index < INVALID_SGL_INDEX || index >= MAX_SGL_INDEX)
564 return __SglInfoTable[index];
570 __SglMutex.Release();
576 _SglInfo* newSglInfo = new (std::nothrow) _SglInfo;
577 if (newSglInfo == null)
579 SysLog(NID_GRP, "CreateSglIndex fail to allocate _SglInfo!!");
580 return INVALID_SGL_INDEX;
583 int sglIndex = FindNextEmptySlotOfSglInfoTable();
584 if (sglIndex == INVALID_SGL_INDEX)
588 SysLog(NID_GRP, "CreateSglIndex failed!!");
589 return INVALID_SGL_INDEX;
592 __SglMutex.Acquire();
593 __SglInfoTable[sglIndex] = newSglInfo;
594 __SglMutex.Release();
600 DestroySglIndex(_SglIndex sglIndex)
602 if (sglIndex < 1 || sglIndex >= MAX_SGL_INDEX)
604 SysLog(NID_GRP, "sglIndex:%#x is out of range.", (unsigned int)sglIndex);
608 __SglMutex.Acquire();
610 if (sglIndex <= INVALID_SGL_INDEX || __SglInfoTable[sglIndex] == null)
612 __SglMutex.Release();
614 SysLog(NID_GRP, "DestroySglIndex failed!! sglIndex:%#x", (unsigned int)sglIndex);
618 delete __SglInfoTable[sglIndex];
619 __SglInfoTable[sglIndex] = null;
621 __SglMutex.Release();
627 GetSglIndexForSurface(EGLSurface surface)
629 __SglMutex.Acquire();
632 for (int i = 0; i < MAX_SGL_INDEX; i++)
634 if (__SglInfoTable[i] != null && __SglInfoTable[i]->surface == surface)
641 __SglMutex.Release();
646 static _SglInfoTableManipulator* GetInstance(void)
648 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
652 pthread_once(&once_block, __InitSglInfoTableManipulator);
655 return __pTheInstance;
659 static void __InitSglInfoTableManipulator(void)
661 static _SglInfoTableManipulator instance;
662 __pTheInstance = &instance;
666 Runtime::Mutex __SglMutex;
667 _SglInfo* __SglInfoTable[MAX_SGL_INDEX];
668 _SglIndex __SglIndexLastUsed;
669 bool __SglInitialized;
671 static _SglInfoTableManipulator* __pTheInstance;
673 _SglInfoTableManipulator* _SglInfoTableManipulator::__pTheInstance = null;
676 _PixmapSurfaceDestroyCallback(void* pCallbackParam)
678 delete (_PixmapInfo*)pCallbackParam;
681 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
683 _PixmapLockCallBack(void* pCallbackParam)
685 tbm_bo_map((tbm_bo)pCallbackParam, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
689 _PixmapUnlockCallBack(void* pCallbackParam)
691 tbm_bo_unmap((tbm_bo)pCallbackParam);
696 _IsEvasGlEnabled(void)
698 const char* pString = elm_config_preferred_engine_get();
699 String engineName(pString);
701 if (engineName.Contains(String("opengl_x11")))
703 SysLog(NID_GRP, "gl backend : %s", pString);
706 else if (engineName.Contains(String("software_x11")))
708 SysLog(NID_GRP, "sw backend : %s", pString);
713 pString = elm_config_engine_get();
714 String engineName(pString);
715 if (engineName.Contains(String("opengl_x11")))
717 SysLog(NID_GRP, "system gl backend : %s", pString);
722 SysLog(NID_GRP, "system sw backend : %s", pString);
727 _EvasObjectImageChange(_SglInfo* pSglInfo)
729 if (isEvasNativeSetEnabled)
731 Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
737 Evas_Engine_Info_GL_X11* pEvasInfo = (Evas_Engine_Info_GL_X11 *)evas_engine_info_get(pEvas);
738 if (pEvasInfo == null)
742 Evas_Native_Surface nativeSurface = {0, };
743 nativeSurface.type = EVAS_NATIVE_SURFACE_X11;
744 nativeSurface.version = EVAS_NATIVE_SURFACE_VERSION;
745 nativeSurface.data.x11.pixmap = (unsigned long)pSglInfo->nativePixmap;
746 nativeSurface.data.x11.visual = pEvasInfo->info.visual;
747 evas_object_image_native_surface_set(pSglInfo->pObject, &nativeSurface);
751 BufferInfo bufferInfo;
752 pSglInfo->pBitmap->Lock(bufferInfo);
753 evas_object_image_data_set(pSglInfo->pObject, bufferInfo.pPixels);
754 pSglInfo->pBitmap->Unlock();
758 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
760 _PostRenderCallback(Ecore_Evas* ee)
762 if (__pPreviousSglInfo != null)
764 EGLDisplay display = __pPreviousSglInfo->display;
765 EGLSurface surface = __pPreviousSglInfo->surface;
766 EGLContext context = __pPreviousSglInfo->context;
768 if (isDoublePixmapEnabled)
770 _SglInfo* pBackSglInfo = null;
771 _SglInfo* pFrontSglInfo = null;
773 if (__pPreviousSglInfo->isBackbuffer)
775 pBackSglInfo = __pPreviousSglInfo;
776 pFrontSglInfo = __pPreviousSglInfo->pSecondSglInfo;
780 pBackSglInfo = __pPreviousSglInfo->pSecondSglInfo;
781 pFrontSglInfo = __pPreviousSglInfo;
784 if (!pBackSglInfo->wasShown && __pPreviousSglInfo->pVisualElement != null)
786 __pPreviousSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
787 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
788 evas_object_hide(pBackSglInfo->pObject);
790 pBackSglInfo->wasShown = true;
791 pFrontSglInfo->swapDone = true;
794 surface = pBackSglInfo->surface;
797 EGLBoolean ret = eglMakeCurrent(display, surface, surface, context);
798 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
799 , (unsigned int)display
800 , (unsigned int)surface
801 , (unsigned int)surface
802 , (unsigned int)context
803 , (unsigned int)eglGetError());
805 if (__pPreviousSglInfo->glVersion == 1)
807 _GlClear_1(GL_COLOR_BUFFER_BIT);
811 _GlClear_2(GL_COLOR_BUFFER_BIT);
817 _SaveCurrentContext(_SglInfo* pSglInfo)
819 __pPreviousSglInfo = pSglInfo;
823 _RegisterRenderCallback(Evas_Object* pObject)
827 if (__registerCallbackCount == 0)
829 Evas* pEvas = evas_object_evas_get(pObject);
835 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
836 if (pEcoreEvas == null)
841 ecore_evas_callback_post_render_set(pEcoreEvas, _PostRenderCallback);
843 __registerCallbackCount++;
848 _UnregisterRenderCallback(Evas_Object* pObject)
852 __registerCallbackCount--;
854 if (__registerCallbackCount == 0)
856 Evas* pEvas = evas_object_evas_get(pObject);
862 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
863 if (pEcoreEvas == null)
868 ecore_evas_callback_post_render_set(pEcoreEvas, NULL);
872 #endif //#if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
884 return eglGetError();
888 _SglGetDisplay(EGLNativeDisplayType displayId)
890 if (displayId == (EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)
892 return eglGetDisplay((EGLNativeDisplayType) ecore_x_display_get());
895 return eglGetDisplay((EGLNativeDisplayType) displayId);
899 _SglInitialize(EGLDisplay dpy, EGLint* pMajor, EGLint* pMinor)
901 return eglInitialize(dpy, pMajor, pMinor);
905 _SglTerminate(EGLDisplay dpy)
907 _GlesInterfaceTerminate_1();
908 _GlesInterfaceTerminate_2();
910 _SglInfoTableManipulator::GetInstance()->DestroySglInfoTable();
912 if (!_IsEvasGlEnabled())
917 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
918 __registerCallbackCount = 0;
919 __pPreviousSglInfo = null;
927 _SglQueryString(EGLDisplay dpy, EGLint name)
929 return eglQueryString(dpy, name);
933 _SglGetConfigs(EGLDisplay dpy, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
935 return eglGetConfigs(dpy, pConfigs, configSize, pNumConfig);
939 _SglChooseConfig(EGLDisplay dpy, const EGLint* pAttribList, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
941 return eglChooseConfig(dpy, pAttribList, pConfigs, configSize, pNumConfig);
945 _SglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* pValue)
947 return eglGetConfigAttrib(dpy, config, attribute, pValue);
951 _SglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* pAttribList)
953 _SglIndex sglIndex = INVALID_SGL_INDEX;
954 Object* pObj = (Object*)win;
955 VisualElement* pVisualElement = dynamic_cast<VisualElement*> (pObj);
956 Tizen::Ui::Control* pControl = dynamic_cast<Tizen::Ui::Control*> (pObj);
957 #if 0//!defined(_OSP_EMUL_)
958 Tizen::Ui::Controls::Frame* pFrame = dynamic_cast<Tizen::Ui::Controls::Frame*> (pControl);
960 SysTryReturn(NID_GRP, pControl != null || pVisualElement != null, EGL_NO_SURFACE, E_INVALID_ARG, "Invalid NativeWindow.");
961 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
963 #if 0//!defined(_OSP_EMUL_)
964 if (pFrame != null && !_IsEvasGlEnabled())
966 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
967 _WindowImpl* pWindowImpl = dynamic_cast<_WindowImpl*> (pControlImpl);
968 SysTryReturn(NID_GRP, pWindowImpl != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window state.");
970 EGLNativeWindowType nativeWindow = (EGLNativeWindowType)pWindowImpl->GetNativeHandle();
971 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
972 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid SglIndex.");
974 EGLSurface windowSurface = eglCreateWindowSurface(dpy, config, nativeWindow, pAttribList);
975 if (windowSurface == EGL_NO_SURFACE)
977 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
982 VisualElement* pVisualElement = pControlImpl->GetCore().GetVisualElement();
983 if (pVisualElement == null)
985 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
986 return EGL_NO_SURFACE;
989 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
990 if (pVisualElementImpl == null)
992 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
993 return EGL_NO_SURFACE;
996 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
998 pSglInfo->surface = windowSurface;
1000 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1003 return (EGLSurface)sglIndex;
1006 #endif //#if !defined(_OSP_EMUL_)
1008 result r = E_SUCCESS;
1010 #if defined (FGRAPHICS_INTERNAL_USE_EVAS_NATIVE_SURFACE)
1011 isEvasNativeSetEnabled = _IsEvasGlEnabled();
1013 isEvasNativeSetEnabled = false;
1016 #if defined (FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP)
1017 isDoublePixmapEnabled = isEvasNativeSetEnabled;
1019 isDoublePixmapEnabled = false;
1022 if (pVisualElement == null)
1024 pVisualElement = pControl->GetVisualElement();
1026 SysTryReturn(NID_GRP, pVisualElement != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1028 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1029 SysTryReturn(NID_GRP, pVisualElementImpl != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1031 FloatRectangle rect = pVisualElement->GetBounds();
1032 int width = int(rect.width);
1033 int height = int(rect.height);
1034 SysTryReturn(NID_GRP, width > 0 && height > 0, EGL_NO_SURFACE, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
1036 Control* pFrame = pControl;
1037 Control* pTemp = pFrame->GetParent();
1038 while(pTemp != null)
1041 pTemp = pTemp->GetParent();
1044 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
1045 SysTryReturn(NID_GRP, pWindow != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window.");
1047 VisualElementSurface* pVisualElementSurface = pVisualElement->GetSurfaceN();
1048 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1050 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
1051 if (pVisualElementSurfaceImpl == null)
1053 SysLogException(NID_GRP, E_OPERATION_FAILED, "Propagating.");
1054 delete pVisualElementSurface;
1055 return EGL_NO_SURFACE;
1058 Evas_Object* pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
1059 delete pVisualElementSurface;
1061 Evas* pEvas = evas_object_evas_get(pObject);
1062 pObject = evas_object_image_filled_add(pEvas);
1063 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1065 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
1066 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
1068 evas_object_image_alpha_set(pObject, EINA_TRUE);
1069 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1070 evas_object_resize(pObject, widthPhysical, heightPhysical);
1071 evas_object_hide(pObject);
1073 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1074 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1075 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1077 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
1078 SysTryReturn(NID_GRP, bitmap.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1080 r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
1081 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1083 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmap.get(), null);
1084 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1086 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1087 pSglInfo->sglIndex = sglIndex;
1088 pSglInfo->display = dpy;
1089 pSglInfo->config = config;
1090 pSglInfo->pVisualElement = pVisualElement;
1091 pSglInfo->pWindow = pWindow;
1092 pSglInfo->pObject = pObject;
1093 pSglInfo->pVisualElementSurface = pVisualElementSurface;
1094 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1096 if (isDoublePixmapEnabled)
1098 pObject = evas_object_image_filled_add(pEvas);
1099 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1101 evas_object_image_alpha_set(pObject, EINA_TRUE);
1102 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1103 evas_object_resize(pObject, widthPhysical, heightPhysical);
1104 evas_object_hide(pObject);
1106 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1107 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1108 SysTryReturn(NID_GRP, pSglInfo->pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1110 delete pSglInfo->pBitmap;
1111 pSglInfo->pBitmap = null;
1113 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
1114 SysTryReturn(NID_GRP, bitmapSecond.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1116 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
1117 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1119 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmapSecond.get(), null);
1120 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1122 _SglInfo* pSglInfoSecond = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1123 pSglInfoSecond->sglIndex = sglIndex;
1124 pSglInfoSecond->display = dpy;
1125 pSglInfoSecond->config = config;
1126 pSglInfoSecond->pVisualElement = pVisualElement;
1127 pSglInfoSecond->pWindow = pWindow;
1128 pSglInfoSecond->pObject = pObject;
1129 pSglInfoSecond->pVisualElementSurface = pVisualElementSurface;
1130 pSglInfoSecond->swapDone = true;
1131 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1133 pSglInfo->pSecondSglInfo = pSglInfoSecond;
1134 pSglInfoSecond->pSecondSglInfo = pSglInfo;
1136 pSglInfoSecond->pBitmap = bitmapSecond.release();
1137 _EvasObjectImageChange(pSglInfoSecond);
1141 pVisualElement->SetSurface(pSglInfo->pVisualElementSurface);
1144 pSglInfo->pBitmap = bitmap.release();
1145 _EvasObjectImageChange(pSglInfo);
1147 pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChanged, pSglInfo);
1148 pVisualElementImpl->SetDestroyedCallback(_OnDestroyed, pSglInfo);
1149 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1150 _RegisterRenderCallback(pSglInfo->pObject);
1152 return (EGLSurface)pSglInfo->sglIndex;
1157 _SglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* pAttribList)
1159 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1160 _SglIndex sglIndex = INVALID_SGL_INDEX;
1162 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1163 if (sglIndex <= INVALID_SGL_INDEX)
1165 SysLog(NID_GRP, "_SglCreatePbufferSurface failed!! dpy:%#x config:%#x pAttribList:%#x",
1166 (unsigned int)dpy, (unsigned int)config, (unsigned int)pAttribList);
1168 return eglCreatePbufferSurface(EGL_NO_DISPLAY, config, pAttribList);
1171 EGLSurface pbufferSurface = eglCreatePbufferSurface(dpy, config, pAttribList);
1172 if (pbufferSurface == EGL_NO_SURFACE)
1174 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1179 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1181 pSglInfo->surface = pbufferSurface;
1183 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1186 return (EGLSurface)sglIndex;
1189 _OSP_LOCAL_ EGLNativePixmapType
1190 _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pBitmap)
1194 int bitsPerPixel = 0;
1195 Display* pNativeDisplay = null;
1196 Drawable nativeWindow = 0;
1197 result r = E_FAILURE;
1198 Tizen::Graphics::BufferInfo bufferInfo;
1199 _PixmapInfo* pPixmapInfo = null;
1200 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1201 unsigned int attachments[] = { DRI2BufferFrontLeft };
1202 char* pDeviceName = null;
1203 char* pDriverName = null;
1204 DRI2Buffer* pDri2Buffer = null;
1207 int dri2BufferCount = 0;
1208 tbm_bo_handle tbmData = { null, };
1211 drm_magic_t magic = 0;
1213 _SglInfo* pSglInfo = null;
1214 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1216 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1217 if (pBitmap == null || sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1219 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1222 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1224 r = pBitmap->Lock(bufferInfo);
1230 width = bufferInfo.width;
1231 height = bufferInfo.height;
1232 bitsPerPixel = bufferInfo.bitsPerPixel;
1234 r = pBitmap->Unlock();
1235 if (r != E_SUCCESS || width <= 0 || height <= 0 || bitsPerPixel <= 0)
1240 pNativeDisplay = (Display*) ecore_x_display_get();
1241 nativeWindow = DefaultRootWindow(pNativeDisplay);
1243 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1244 if (pPixmapInfo == null)
1249 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height,
1250 ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1251 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1256 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1257 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1258 XSync(pNativeDisplay, False);
1260 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1262 if (!ret || pDeviceName == null)
1267 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1270 if (pPixmapInfo->drmFd < 0)
1275 drmGetMagic(pPixmapInfo->drmFd, &magic);
1276 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1282 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1283 if (pPixmapInfo->pTbmBufMgr == null)
1288 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1289 if (pDri2Buffer == null)
1294 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1296 if (pPixmapInfo->pTbmBufferObject == null)
1301 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1302 if (tbmData.ptr == null)
1307 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, tbmData.ptr, width * bitsPerPixel / 8,
1308 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1314 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1315 _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1321 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1323 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1325 pSglInfo->pEcoreImage = ecore_x_image_new(width
1327 , ecore_x_default_visual_get(pNativeDisplay, ecore_x_default_screen_get())
1328 , ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1330 if (pSglInfo->pEcoreImage == null)
1332 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1336 ecore_x_image_get(pSglInfo->pEcoreImage
1337 , pPixmapInfo->nativePixmap, 0, 0, 0, 0
1345 void* pSource = ecore_x_image_data_get(pSglInfo->pEcoreImage, &bpl, &rows, &bpp);
1347 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pSource, width * bitsPerPixel / 8,
1348 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1351 ecore_x_image_free(pSglInfo->pEcoreImage);
1352 pSglInfo->pEcoreImage = null;
1353 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1355 SysLog(NID_GRP, "change buffer failed! pSource %#x %d %d %d", (unsigned int)pSource, bpl, rows, bpp);
1359 pSglInfo->width = width;
1360 pSglInfo->height = height;
1362 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1364 #endif //#if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1365 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1367 pBitmap->Lock(bufferInfo);
1368 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1371 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1374 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1375 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1376 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1380 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1384 close(pPixmapInfo->drmFd);
1388 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1390 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1398 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1399 return (EGLNativePixmapType)0;
1402 _OSP_LOCAL_ EGLNativePixmapType
1403 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1407 int bitsPerPixel = 0;
1408 Display* pNativeDisplay = null;
1409 Drawable nativeWindow = 0;
1410 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1411 _PixmapInfo* pPixmapInfo = null;
1412 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1413 unsigned int attachments[] = { DRI2BufferFrontLeft };
1414 char* pDeviceName = null;
1415 char* pDriverName = null;
1416 DRI2Buffer* pDri2Buffer = null;
1419 int dri2BufferCount = 0;
1420 tbm_bo_handle tbmData = { null, };
1423 result r = E_FAILURE;
1424 drm_magic_t magic = 0;
1426 if (pBitmap == null)
1431 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1432 if (pBitmapImpl == null)
1437 width = bufferInfo.width;
1438 height = bufferInfo.height;
1439 bitsPerPixel = bufferInfo.bitsPerPixel;
1441 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1446 pNativeDisplay = (Display*) ecore_x_display_get();
1447 nativeWindow = DefaultRootWindow(pNativeDisplay);
1449 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1450 if (pPixmapInfo == null)
1455 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height
1457 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1462 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1463 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1464 XSync(pNativeDisplay, False);
1466 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1468 if (!ret || pDeviceName == null)
1473 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1475 if (pPixmapInfo->drmFd < 0)
1480 drmGetMagic(pPixmapInfo->drmFd, &magic);
1481 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1487 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1488 if (pPixmapInfo->pTbmBufMgr == null)
1493 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1494 if (pDri2Buffer == null)
1499 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1501 if (pPixmapInfo->pTbmBufferObject == null)
1506 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1507 if (tbmData.ptr == null)
1511 bufferInfo.pPixels = tbmData.ptr;
1513 bufferInfo.bitsPerPixel = 32;
1514 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1515 bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;
1516 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1517 r = pBitmapImpl->Construct(bufferInfo);
1523 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap
1524 , _PixmapSurfaceDestroyCallback, pPixmapInfo
1525 , _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject
1526 ,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1530 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1532 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1534 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1536 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1537 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1541 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1545 close(pPixmapInfo->drmFd);
1549 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1550 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1559 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1560 return (EGLNativePixmapType)0;
1564 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1566 _SglIndex sglIndex = INVALID_SGL_INDEX;
1567 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1568 EGLNativePixmapType eglNativePixmap = 0;
1569 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1570 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1572 if (pBitmap == null)
1577 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1578 if (sglIndex <= INVALID_SGL_INDEX)
1583 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1584 if (eglNativePixmap == 0)
1589 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1590 if (pixmapSurface == EGL_NO_SURFACE)
1592 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1597 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1599 pSglInfo->nativePixmap = eglNativePixmap;
1600 pSglInfo->surface = pixmapSurface;
1602 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1605 return (EGLSurface)sglIndex;
1608 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1612 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1613 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1614 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1618 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1620 EGLBoolean ret = EGL_FALSE;
1621 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1623 _SglIndex sglIndex = (_SglIndex)surface;
1624 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1626 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1628 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1629 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1630 , (unsigned int)surface);
1631 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1634 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1635 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
1637 __pPreviousSglInfo = null;
1641 ret = eglDestroySurface(dpy, pSglInfo->surface);
1642 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1644 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1646 eglDestroySurface(dpy, pSglInfo->pSecondSglInfo->surface);
1647 pSglInfoTableManipulatorInstance->DestroySglIndex(pSglInfo->pSecondSglInfo->sglIndex);
1650 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1656 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1658 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1660 _SglIndex sglIndex = (_SglIndex)surface;
1661 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1663 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1665 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1666 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1667 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1668 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1671 EGLBoolean ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1672 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1678 _SglBindAPI(EGLenum api)
1680 return eglBindAPI(api);
1686 return eglQueryAPI();
1692 return eglWaitClient();
1696 _SglReleaseThread(void)
1698 return eglReleaseThread();
1702 _SglCreatePbufferFromClientBuffer(
1703 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1705 _SglIndex sglIndex = INVALID_SGL_INDEX;
1706 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1708 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1709 if (sglIndex <= INVALID_SGL_INDEX)
1711 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1712 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1713 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1715 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1718 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1719 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1721 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1726 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1728 pSglInfo->surface = pbufferFromClientBuffer;
1730 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1733 return (EGLSurface)sglIndex;
1737 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1739 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1741 _SglIndex sglIndex = (_SglIndex)surface;
1742 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1744 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1746 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1747 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1748 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1749 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1751 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1754 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1755 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1761 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1763 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1765 _SglIndex sglIndex = (_SglIndex)surface;
1766 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1768 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1770 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1771 SysLog(NID_GRP, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1772 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1774 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1777 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1778 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1784 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1786 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1788 _SglIndex sglIndex = (_SglIndex)surface;
1789 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1791 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1793 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1794 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1795 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1797 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1800 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1801 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1807 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1809 return eglSwapInterval(dpy, interval);
1813 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1815 return eglCreateContext(dpy, config, shareContext, pAttribList);
1819 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1821 return eglDestroyContext(dpy, ctx);
1825 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1827 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1829 _SglIndex sglIndexDraw = (_SglIndex)draw;
1830 _SglIndex sglIndexRead = (_SglIndex)read;
1832 EGLSurface sglInfoReadSurface;
1834 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1836 if (sglInfoRead == null)
1838 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1839 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1840 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1841 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1843 sglInfoReadSurface = sglInfoRead->surface;
1845 if (isDoublePixmapEnabled && !sglInfoRead->isBackbuffer)
1847 sglInfoReadSurface = sglInfoRead->pSecondSglInfo->surface;
1850 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1853 _SglInfo* pSglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1854 if (pSglInfoDraw == null)
1856 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1857 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1858 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1859 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1862 if (isDoublePixmapEnabled && !pSglInfoDraw->isBackbuffer && pSglInfoDraw->pSecondSglInfo != null)
1864 pSglInfoDraw = pSglInfoDraw->pSecondSglInfo;
1867 pSglInfoDraw->context = ctx;
1869 EGLBoolean ret = eglMakeCurrent(dpy, pSglInfoDraw->surface, sglInfoReadSurface, ctx);
1871 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1872 if (draw != EGL_NO_SURFACE)
1874 _SaveCurrentContext(pSglInfoDraw);
1878 if (pSglInfoDraw->glVersion == 0 && ctx != EGL_NO_CONTEXT)
1880 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &pSglInfoDraw->glVersion);
1883 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1889 _SglGetCurrentContext()
1891 return eglGetCurrentContext();
1895 _SglGetCurrentSurface(EGLint readDraw)
1897 EGLSurface surface = EGL_NO_SURFACE;
1898 _SglIndex sglIndex = INVALID_SGL_INDEX;
1900 surface = eglGetCurrentSurface(readDraw);
1901 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
1903 if (sglIndex < INVALID_SGL_INDEX)
1905 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
1906 return EGL_NO_SURFACE;
1909 return (EGLSurface)sglIndex;
1913 _SglGetCurrentDisplay(void)
1915 return eglGetCurrentDisplay();
1919 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
1921 return eglQueryContext(dpy, ctx, attribute, pValue);
1931 _SglWaitNative(EGLint engine)
1933 return eglWaitNative(engine);
1936 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
1939 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1941 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1943 _SglIndex sglIndex = (_SglIndex)surface;
1944 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1946 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1948 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1949 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1950 , (unsigned int)sglIndex);
1952 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
1955 if (pSglInfo->pBitmap != null)
1957 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1958 _SglUpdateBufferOSP(dpy, surface);
1960 if (isEvasNativeSetEnabled)
1962 if (pSglInfo->glVersion == 1)
1977 if (isEvasNativeSetEnabled)
1979 if (isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1981 if (pSglInfo->swapDone || pSglInfo->pSecondSglInfo->swapDone)
1983 _SglInfo* pBackSglInfo = null;
1984 _SglInfo* pFrontSglInfo = null;
1986 if (pSglInfo->isBackbuffer)
1988 pBackSglInfo = pSglInfo;
1989 pFrontSglInfo = pSglInfo->pSecondSglInfo;
1993 pBackSglInfo = pSglInfo->pSecondSglInfo;
1994 pFrontSglInfo = pSglInfo;
1996 pBackSglInfo->isBackbuffer = false;
1997 pFrontSglInfo->isBackbuffer = true;
1999 pFrontSglInfo->wasShown = false;
2000 pFrontSglInfo->swapDone = false;
2001 if (pSglInfo->pVisualElement != null)
2003 pSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
2005 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
2006 evas_object_hide(pBackSglInfo->pObject);
2008 if (pSglInfo->isFirstSwap)
2010 pBackSglInfo->isFirstSwap = false;
2011 pFrontSglInfo->isFirstSwap = false;
2014 BufferInfo bufferInfo;
2015 pFrontSglInfo->pBitmap->Lock(bufferInfo);
2016 pFrontSglInfo->pBitmap->Merge(Point(0, 0), *pBackSglInfo->pBitmap, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
2017 pFrontSglInfo->pBitmap->Unlock();
2023 if (pSglInfo->pObject != null)
2025 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2031 if (pSglInfo->pVisualElement != null)
2033 pSglInfo->pVisualElement->SetFlushNeeded();
2037 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2042 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2043 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2050 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2052 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2053 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2054 return eglCopyBuffers(dpy, surface, nativePixmap);
2057 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2059 __EglMustCastToProperFunctionPointerType
2060 _SglGetProcAddress(const char* pProcName)
2062 return eglGetProcAddress(pProcName);
2066 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2068 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2069 Tizen::Graphics::BufferInfo bufferInfo;
2070 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2072 _SglIndex sglIndex = (_SglIndex)surface;
2073 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2075 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2077 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2078 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2082 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2083 ecore_x_image_get(pSglInfo->pEcoreImage, (Ecore_X_Drawable)pSglInfo->nativePixmap,
2084 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2086 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2097 }} // Tizen::Graphics