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>
45 #include <FBaseSysLog.h>
46 #include <FGrpBitmap.h>
47 #include <FGrpCoordinateSystem.h>
48 #include <FUiControl.h>
49 #include <FUiCtrlForm.h>
50 #include <FUiCtrlFrame.h>
51 #include <FUiWindow.h>
53 #include <FUi_EcoreEvasMgr.h>
54 #include <FUi_EcoreEvas.h>
56 #include <FGrp_BitmapTool.h>
57 #include <FGrp_BitmapImpl.h>
58 #include <FUi_ControlImpl.h>
59 #include <FUi_Control.h>
60 #include <FUi_WindowImpl.h>
61 #include <FUiAnim_VisualElementSurfaceImpl.h>
62 #include <FUiAnim_VisualElementImpl.h>
70 #include <elm_config.h>
72 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
76 #include <tbm_bufmgr.h>
80 typedef int _SglIndex;
83 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList);
84 EGLSurface _SglGetCurrentSurface(EGLint readDraw);
85 EGLNativePixmapType _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pixmap);
86 EGLNativePixmapType _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo);
88 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
89 void _GlesInterfaceTerminate_1();
90 void _GlesInterfaceTerminate_2();
93 #include <GLES2/gl2.h>
95 void _GlFlush_1(void);
96 void _GlFlush_2(void);
97 void _GlClear_1(GLbitfield mask);
98 void _GlClear_2(GLbitfield mask);
100 EGLBoolean _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
102 using namespace Tizen::Ui::Controls;
108 using namespace Tizen::Ui::Animations;
109 using namespace Tizen::Ui;
110 using namespace Tizen::Base;
112 namespace Tizen { namespace Graphics
123 #define FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT
124 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
125 void _PostRenderCallback(Ecore_Evas* ee);
126 void _SaveCurrentContext(_SglInfo* pSglInfo);
127 void _UnregisterRenderCallback(Evas_Object* pObject);
128 int __registerCallbackCount = 0;
129 _SglInfo* __pPreviousSglInfo = null;
132 #if !defined (_OSP_EMUL_)
133 #define FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP
138 ENGINE_TYPE_SOFEWARE_X11 = 0,
139 ENGINE_TYPE_OPENGL_X11,
143 _engineType __evasEngineType = ENGINE_TYPE_SOFEWARE_X11;
144 bool __isDoublePixmapEnabled = false;
146 void _OnBoundsChanged(void* pData);
148 const int INVALID_SGL_INDEX = 0;
149 const int MAX_SGL_INDEX = 100;
155 : sglIndex(INVALID_SGL_INDEX)
156 , display(EGL_NO_DISPLAY)
157 , surface(EGL_NO_SURFACE)
158 , context(EGL_NO_CONTEXT)
159 , config((EGLConfig)0)
162 , nativePixmap((EGLNativePixmapType)0)
163 , pVisualElement(null)
164 , pVisualElementSurface(null)
167 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
175 , pSecondSglInfo(null)
179 virtual ~_SglInfo(void)
181 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
182 if (pEcoreImage != null)
184 ecore_x_image_free(pEcoreImage);
193 if (pVisualElement != null)
195 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
196 if (pVisualElementImpl != null)
198 pVisualElementImpl->SetDestroyedCallback(null, null);
202 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
203 _UnregisterRenderCallback(pObject);
205 evas_object_del(pObject);
206 delete pVisualElementSurface;
209 bool needAllocateObject = true;
210 if (__isDoublePixmapEnabled)
214 needAllocateObject = false;
217 if (needAllocateObject)
219 if (pVisualElement != null)
221 pVisualElement->SetSurface(null);
225 sglIndex = INVALID_SGL_INDEX;
226 display = EGL_NO_DISPLAY;
227 surface = EGL_NO_SURFACE;
228 context = EGL_NO_CONTEXT;
229 config = (EGLConfig)0;
232 nativePixmap = (EGLNativePixmapType)0;
233 pVisualElement = null;
234 pVisualElementSurface = null;
237 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
245 pSecondSglInfo = null;
255 Evas_Object* pObject;
256 EGLNativePixmapType nativePixmap;
257 VisualElement* pVisualElement;
258 VisualElementSurface* pVisualElementSurface;
260 Tizen::Ui::Window* pWindow;
261 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
262 Ecore_X_Image* pEcoreImage;
269 _SglInfo* pSecondSglInfo;
272 _SglInfo(const _SglInfo& sglInfo);
273 _SglInfo& operator =(const _SglInfo& rhs);
280 : nativePixmap((Pixmap)0)
281 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
283 , pTbmBufferObject(null)
289 virtual ~_PixmapInfo(void)
291 Display* pDisplay = (Display*)ecore_x_display_get();
292 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
293 tbm_bo_unmap(pTbmBufferObject);
294 tbm_bo_unref(pTbmBufferObject);
300 tbm_bufmgr_deinit(pTbmBufMgr);
301 DRI2DestroyDrawable(pDisplay, nativePixmap);
303 XFreePixmap(pDisplay, nativePixmap);
305 nativePixmap = (Pixmap)0;
306 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
308 pTbmBufferObject = null;
315 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
316 tbm_bufmgr pTbmBufMgr;
317 tbm_bo pTbmBufferObject;
322 void _EvasObjectImageChange(_SglInfo* pSglInfo);
325 _OnBoundsChanged(void* pData)
327 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
328 SysTryReturnVoidResult(NID_GRP, pSglInfo != null
329 && pSglInfo->sglIndex > INVALID_SGL_INDEX
330 && pSglInfo->pVisualElement != null
331 && pSglInfo->pWindow != null
332 , E_INVALID_STATE, "Invalid state.");
334 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
336 __pPreviousSglInfo = null;
339 bool needSglMakeCurrent = false;
340 EGLDisplay eglDisplay = eglGetCurrentDisplay();
341 EGLSurface drawSurface = _SglGetCurrentSurface(EGL_DRAW);
342 EGLSurface readSurface = _SglGetCurrentSurface(EGL_READ);
343 EGLSurface eglContext = eglGetCurrentContext();
345 if (drawSurface != EGL_NO_SURFACE && readSurface != EGL_NO_SURFACE)
347 needSglMakeCurrent = true;
351 drawSurface = eglGetCurrentSurface(EGL_DRAW);
352 readSurface = eglGetCurrentSurface(EGL_READ);
355 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
356 EGLBoolean ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
357 pSglInfo->surface = null;
358 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
360 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
361 if (pSglInfo->pEcoreImage != null)
363 ecore_x_image_free(pSglInfo->pEcoreImage);
364 pSglInfo->pEcoreImage = null;
368 FloatRectangle rect = pSglInfo->pVisualElement->GetBounds();
369 int width = int(rect.width);
370 int height = int(rect.height);
371 SysTryReturnVoidResult(NID_GRP, width > 0 && height > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
372 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
373 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
374 SysTryReturnVoidResult(NID_GRP, widthPhysical > 0 && heightPhysical > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", widthPhysical, heightPhysical);
376 evas_object_image_size_set(pSglInfo->pObject, widthPhysical, heightPhysical);
377 evas_object_resize(pSglInfo->pObject, widthPhysical, heightPhysical);
379 delete pSglInfo->pBitmap;
380 pSglInfo->pBitmap = null;
381 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
382 SysTryReturnVoidResult(NID_GRP, bitmap.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
383 result r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
384 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
385 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, bitmap.get());
386 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
387 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, nativePixmap, null);
388 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
390 pSglInfo->nativePixmap = nativePixmap;
391 pSglInfo->surface = eglSurface;
392 pSglInfo->isBackbuffer = true;
393 pSglInfo->swapDone = false;
394 pSglInfo->isFirstSwap = true;
396 if (__isDoublePixmapEnabled)
398 _SglInfo* pSglInfoSecond = pSglInfo->pSecondSglInfo;
399 SysTryReturnVoidResult(NID_GRP, pSglInfoSecond != null, E_INVALID_STATE, "Invalid pSecondSglInfo.");
401 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
402 ret = eglDestroySurface(pSglInfoSecond->display, pSglInfoSecond->surface);
403 pSglInfoSecond->surface = null;
404 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
406 evas_object_image_size_set(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
407 evas_object_resize(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
409 delete pSglInfoSecond->pBitmap;
410 pSglInfoSecond->pBitmap = null;
411 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
412 SysTryReturnVoidResult(NID_GRP, bitmapSecond.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
413 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
414 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
415 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfoSecond->sglIndex, bitmapSecond.get());
416 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
417 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfoSecond->display, pSglInfoSecond->config, nativePixmap, null);
418 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
420 pSglInfoSecond->nativePixmap = nativePixmap;
421 pSglInfoSecond->surface = eglSurface;
422 pSglInfoSecond->pBitmap = bitmapSecond.release();
423 pSglInfoSecond->isBackbuffer = true;
424 pSglInfoSecond->swapDone = true;
426 pSglInfo->isFirstSwap = true;
428 _EvasObjectImageChange(pSglInfoSecond);
431 pSglInfo->pBitmap = bitmap.release();
432 _EvasObjectImageChange(pSglInfo);
434 BufferInfo bufferInfo;
435 pSglInfo->pBitmap->Lock(bufferInfo);
436 pSglInfo->pBitmap->Unlock();
438 if (needSglMakeCurrent)
440 _SglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
444 eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
451 _OnDestroyed(void* pData)
453 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
455 if (pSglInfo != null)
457 pSglInfo->pVisualElement = null;
459 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
461 pSglInfo->pSecondSglInfo->pVisualElement = null;
466 class _SglInfoTableManipulator
469 _SglInfoTableManipulator()
471 result r = __SglMutex.Create();
472 SysTryLog(NID_GRP, r == E_SUCCESS, "Failed to create mutex. [%s]", GetErrorMessage(r));
473 __SglIndexLastUsed = INVALID_SGL_INDEX;
474 __SglInitialized = false;
477 ~_SglInfoTableManipulator()
482 FindNextEmptySlotOfSglInfoTable()
484 if (!__SglInitialized)
486 if (CreateSglInfoTable() == false)
488 return INVALID_SGL_INDEX;
492 _SglIndex sglIndex = INVALID_SGL_INDEX;
493 _SglIndex index = __SglIndexLastUsed;
495 __SglMutex.Acquire();
496 for (int i = 1; i < MAX_SGL_INDEX; i++)
500 if (index >= MAX_SGL_INDEX)
505 if (__SglInfoTable[index] == null)
508 __SglIndexLastUsed = index;
512 __SglMutex.Release();
515 if (sglIndex <= INVALID_SGL_INDEX)
517 return INVALID_SGL_INDEX;
528 __SglMutex.Acquire();
530 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
532 __SglInfoTable[i] = null;
535 __SglInfoTable[0] = new (std::nothrow) _SglInfo;
536 if (__SglInfoTable[0] != null)
539 __SglInitialized = true;
540 __SglInfoTable[0]->glVersion = 2;
543 __SglMutex.Release();
549 DestroySglInfoTable()
551 __SglMutex.Acquire();
553 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
555 if (__SglInfoTable[i] != null)
557 delete __SglInfoTable[i];
558 __SglInfoTable[i] = null;
561 __SglInitialized = false;
563 __SglMutex.Release();
567 LockSglInfoTable(_SglIndex index)
569 __SglMutex.Acquire();
571 if (index < INVALID_SGL_INDEX || index >= MAX_SGL_INDEX)
576 return __SglInfoTable[index];
582 __SglMutex.Release();
588 _SglInfo* newSglInfo = new (std::nothrow) _SglInfo;
589 if (newSglInfo == null)
591 SysLog(NID_GRP, "CreateSglIndex fail to allocate _SglInfo!!");
592 return INVALID_SGL_INDEX;
595 int sglIndex = FindNextEmptySlotOfSglInfoTable();
596 if (sglIndex == INVALID_SGL_INDEX)
600 SysLog(NID_GRP, "CreateSglIndex failed!!");
601 return INVALID_SGL_INDEX;
604 __SglMutex.Acquire();
605 __SglInfoTable[sglIndex] = newSglInfo;
606 __SglMutex.Release();
612 DestroySglIndex(_SglIndex sglIndex)
614 if (sglIndex < 1 || sglIndex >= MAX_SGL_INDEX)
616 SysLog(NID_GRP, "sglIndex:%#x is out of range.", (unsigned int)sglIndex);
620 __SglMutex.Acquire();
622 if (sglIndex <= INVALID_SGL_INDEX || __SglInfoTable[sglIndex] == null)
624 __SglMutex.Release();
626 SysLog(NID_GRP, "DestroySglIndex failed!! sglIndex:%#x", (unsigned int)sglIndex);
630 delete __SglInfoTable[sglIndex];
631 __SglInfoTable[sglIndex] = null;
633 __SglMutex.Release();
639 GetSglIndexForSurface(EGLSurface surface)
641 __SglMutex.Acquire();
644 for (int i = 0; i < MAX_SGL_INDEX; i++)
646 if (__SglInfoTable[i] != null && __SglInfoTable[i]->surface == surface)
653 __SglMutex.Release();
658 static _SglInfoTableManipulator* GetInstance(void)
660 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
664 pthread_once(&once_block, __InitSglInfoTableManipulator);
667 return __pTheInstance;
671 static void __InitSglInfoTableManipulator(void)
673 static _SglInfoTableManipulator instance;
674 __pTheInstance = &instance;
678 Runtime::Mutex __SglMutex;
679 _SglInfo* __SglInfoTable[MAX_SGL_INDEX];
680 _SglIndex __SglIndexLastUsed;
681 bool __SglInitialized;
683 static _SglInfoTableManipulator* __pTheInstance;
685 _SglInfoTableManipulator* _SglInfoTableManipulator::__pTheInstance = null;
688 _PixmapSurfaceDestroyCallback(void* pCallbackParam)
690 delete (_PixmapInfo*)pCallbackParam;
693 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
695 _PixmapLockCallBack(void* pCallbackParam)
697 tbm_bo_map((tbm_bo)pCallbackParam, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
701 _PixmapUnlockCallBack(void* pCallbackParam)
703 tbm_bo_unmap((tbm_bo)pCallbackParam);
708 _GetEvasEngineType(Evas_Object* pObject)
712 const char* pString = elm_config_preferred_engine_get();
713 String engineName(pString);
714 SysLog(NID_GRP, "evas backend : %s", pString);
716 if (engineName.Contains(String("opengl_x11")))
718 return ENGINE_TYPE_OPENGL_X11;
722 return ENGINE_TYPE_SOFEWARE_X11;
727 Evas* pEvas = evas_object_evas_get(pObject);
730 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEvas failed.");
731 return ENGINE_TYPE_SOFEWARE_X11;
734 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
735 if (pEcoreEvas == null)
737 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEcoreEvas failed.");
738 return ENGINE_TYPE_SOFEWARE_X11;
741 const char* pString = ecore_evas_engine_name_get(pEcoreEvas);
742 String engineName(pString);
743 SysLog(NID_GRP, "evas backend : %s", pString);
745 if (engineName.Contains(String("opengl_x11")))
747 return ENGINE_TYPE_OPENGL_X11;
749 else if (engineName.Contains(String("software_x11")))
751 return ENGINE_TYPE_SOFEWARE_X11;
755 return ENGINE_TYPE_ETC;
761 _EvasObjectImageChange(_SglInfo* pSglInfo)
763 if(__evasEngineType == ENGINE_TYPE_SOFEWARE_X11 || __evasEngineType == ENGINE_TYPE_OPENGL_X11)
765 Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
768 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEvas failed.");
772 Evas_Native_Surface nativeSurface = {0, };
773 nativeSurface.type = EVAS_NATIVE_SURFACE_X11;
774 nativeSurface.version = EVAS_NATIVE_SURFACE_VERSION;
775 nativeSurface.data.x11.pixmap = (unsigned long)pSglInfo->nativePixmap;
776 nativeSurface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
777 evas_object_image_native_surface_set(pSglInfo->pObject, &nativeSurface);
781 BufferInfo bufferInfo;
782 pSglInfo->pBitmap->Lock(bufferInfo);
783 evas_object_image_data_set(pSglInfo->pObject, bufferInfo.pPixels);
784 pSglInfo->pBitmap->Unlock();
788 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
790 _PostRenderCallback(Ecore_Evas* ee)
792 if (__pPreviousSglInfo != null)
794 EGLDisplay display = __pPreviousSglInfo->display;
795 EGLSurface surface = __pPreviousSglInfo->surface;
796 EGLContext context = __pPreviousSglInfo->context;
798 if (__isDoublePixmapEnabled)
800 _SglInfo* pBackSglInfo = null;
801 _SglInfo* pFrontSglInfo = null;
803 if (__pPreviousSglInfo->isBackbuffer)
805 pBackSglInfo = __pPreviousSglInfo;
806 pFrontSglInfo = __pPreviousSglInfo->pSecondSglInfo;
810 pBackSglInfo = __pPreviousSglInfo->pSecondSglInfo;
811 pFrontSglInfo = __pPreviousSglInfo;
814 if (!pFrontSglInfo->swapDone && __pPreviousSglInfo->pVisualElement != null)
816 pBackSglInfo->isBackbuffer = false;
817 pFrontSglInfo->isBackbuffer = true;
818 pFrontSglInfo->swapDone = true;
820 __pPreviousSglInfo->pVisualElement->SetSurface(pBackSglInfo->pVisualElementSurface);
821 evas_object_image_pixels_dirty_set(pBackSglInfo->pObject, EINA_TRUE);
822 evas_object_hide(pFrontSglInfo->pObject);
825 surface = pFrontSglInfo->surface;
828 EGLBoolean ret = eglMakeCurrent(display, surface, surface, context);
829 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
830 , (unsigned int)display
831 , (unsigned int)surface
832 , (unsigned int)surface
833 , (unsigned int)context
834 , (unsigned int)eglGetError());
839 _SaveCurrentContext(_SglInfo* pSglInfo)
841 __pPreviousSglInfo = pSglInfo;
845 _RegisterRenderCallback(Evas_Object* pObject)
847 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11 && pObject != null)
849 if (__registerCallbackCount == 0)
851 Evas* pEvas = evas_object_evas_get(pObject);
857 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
858 if (pEcoreEvas == null)
863 ecore_evas_callback_post_render_set(pEcoreEvas, _PostRenderCallback);
865 __registerCallbackCount++;
870 _UnregisterRenderCallback(Evas_Object* pObject)
872 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11 && pObject != null)
874 __registerCallbackCount--;
876 if (__registerCallbackCount == 0)
878 Evas* pEvas = evas_object_evas_get(pObject);
884 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
885 if (pEcoreEvas == null)
890 ecore_evas_callback_post_render_set(pEcoreEvas, NULL);
894 #endif //#if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
906 return eglGetError();
910 _SglGetDisplay(EGLNativeDisplayType displayId)
912 if (displayId == (EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)
914 return eglGetDisplay((EGLNativeDisplayType) ecore_x_display_get());
917 return eglGetDisplay((EGLNativeDisplayType) displayId);
921 _SglInitialize(EGLDisplay dpy, EGLint* pMajor, EGLint* pMinor)
923 __evasEngineType = _GetEvasEngineType(null);
924 return eglInitialize(dpy, pMajor, pMinor);
928 _SglTerminate(EGLDisplay dpy)
930 _GlesInterfaceTerminate_1();
931 _GlesInterfaceTerminate_2();
933 _SglInfoTableManipulator::GetInstance()->DestroySglInfoTable();
935 if (__evasEngineType != ENGINE_TYPE_OPENGL_X11)
940 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
941 __registerCallbackCount = 0;
942 __pPreviousSglInfo = null;
950 _SglQueryString(EGLDisplay dpy, EGLint name)
952 return eglQueryString(dpy, name);
956 _SglGetConfigs(EGLDisplay dpy, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
958 return eglGetConfigs(dpy, pConfigs, configSize, pNumConfig);
962 _SglChooseConfig(EGLDisplay dpy, const EGLint* pAttribList, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
964 return eglChooseConfig(dpy, pAttribList, pConfigs, configSize, pNumConfig);
968 _SglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* pValue)
970 return eglGetConfigAttrib(dpy, config, attribute, pValue);
974 _SglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* pAttribList)
976 _SglIndex sglIndex = INVALID_SGL_INDEX;
977 Object* pObj = (Object*)win;
978 VisualElement* pVisualElement = dynamic_cast<VisualElement*> (pObj);
979 Tizen::Ui::Control* pControl = dynamic_cast<Tizen::Ui::Control*> (pObj);
980 #if 0//!defined(_OSP_EMUL_)
981 Tizen::Ui::Controls::Frame* pFrame = dynamic_cast<Tizen::Ui::Controls::Frame*> (pControl);
983 SysTryReturn(NID_GRP, pControl != null || pVisualElement != null, EGL_NO_SURFACE, E_INVALID_ARG, "Invalid NativeWindow.");
984 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
986 #if 0//!defined(_OSP_EMUL_)
987 if (pFrame != null && _GetEvasEngineType(null) != ENGINE_TYPE_OPENGL_X11)
989 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
990 _WindowImpl* pWindowImpl = dynamic_cast<_WindowImpl*> (pControlImpl);
991 SysTryReturn(NID_GRP, pWindowImpl != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window state.");
993 EGLNativeWindowType nativeWindow = (EGLNativeWindowType)pWindowImpl->GetNativeHandle();
994 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
995 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid SglIndex.");
997 EGLSurface windowSurface = eglCreateWindowSurface(dpy, config, nativeWindow, pAttribList);
998 if (windowSurface == EGL_NO_SURFACE)
1000 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1005 VisualElement* pVisualElement = pControlImpl->GetCore().GetVisualElement();
1006 if (pVisualElement == null)
1008 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1009 return EGL_NO_SURFACE;
1012 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1013 if (pVisualElementImpl == null)
1015 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1016 return EGL_NO_SURFACE;
1019 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1021 pSglInfo->surface = windowSurface;
1023 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1026 return (EGLSurface)sglIndex;
1029 #endif //#if !defined(_OSP_EMUL_)
1031 result r = E_SUCCESS;
1033 if (pVisualElement == null)
1035 pVisualElement = pControl->GetVisualElement();
1037 SysTryReturn(NID_GRP, pVisualElement != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1039 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1040 SysTryReturn(NID_GRP, pVisualElementImpl != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1042 FloatRectangle rect = pVisualElement->GetBounds();
1043 int width = int(rect.width);
1044 int height = int(rect.height);
1045 SysTryReturn(NID_GRP, width > 0 && height > 0, EGL_NO_SURFACE, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
1047 Control* pFrame = pControl;
1048 Control* pTemp = pFrame->GetParent();
1049 while(pTemp != null)
1052 pTemp = pTemp->GetParent();
1055 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
1056 SysTryReturn(NID_GRP, pWindow != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window.");
1058 VisualElementSurface* pVisualElementSurface = pVisualElement->GetSurfaceN();
1059 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1061 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
1062 if (pVisualElementSurfaceImpl == null)
1064 SysLogException(NID_GRP, E_OPERATION_FAILED, "Propagating.");
1065 delete pVisualElementSurface;
1066 return EGL_NO_SURFACE;
1069 Evas_Object* pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
1070 delete pVisualElementSurface;
1072 Evas* pEvas = evas_object_evas_get(pObject);
1073 pObject = evas_object_image_filled_add(pEvas);
1074 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1076 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
1077 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
1079 evas_object_image_alpha_set(pObject, EINA_TRUE);
1080 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1081 evas_object_resize(pObject, widthPhysical, heightPhysical);
1082 evas_object_hide(pObject);
1084 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1085 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1086 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1088 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
1089 SysTryReturn(NID_GRP, bitmap.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1091 r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
1092 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1094 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmap.get(), null);
1095 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1097 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1098 pSglInfo->sglIndex = sglIndex;
1099 pSglInfo->display = dpy;
1100 pSglInfo->config = config;
1101 pSglInfo->pVisualElement = pVisualElement;
1102 pSglInfo->pWindow = pWindow;
1103 pSglInfo->pObject = pObject;
1104 pSglInfo->pVisualElementSurface = pVisualElementSurface;
1105 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1107 __evasEngineType = _GetEvasEngineType(pObject);
1109 #if defined (FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP)
1110 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11)
1112 __isDoublePixmapEnabled = true;
1116 __isDoublePixmapEnabled = false;
1119 __isDoublePixmapEnabled = false;
1122 if (__isDoublePixmapEnabled)
1124 pObject = evas_object_image_filled_add(pEvas);
1125 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1127 evas_object_image_alpha_set(pObject, EINA_TRUE);
1128 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1129 evas_object_resize(pObject, widthPhysical, heightPhysical);
1130 evas_object_hide(pObject);
1132 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1133 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1134 SysTryReturn(NID_GRP, pSglInfo->pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1136 delete pSglInfo->pBitmap;
1137 pSglInfo->pBitmap = null;
1139 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
1140 SysTryReturn(NID_GRP, bitmapSecond.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1142 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
1143 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1145 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmapSecond.get(), null);
1146 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1148 _SglInfo* pSglInfoSecond = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1149 pSglInfoSecond->sglIndex = sglIndex;
1150 pSglInfoSecond->display = dpy;
1151 pSglInfoSecond->config = config;
1152 pSglInfoSecond->pVisualElement = pVisualElement;
1153 pSglInfoSecond->pWindow = pWindow;
1154 pSglInfoSecond->pObject = pObject;
1155 pSglInfoSecond->pVisualElementSurface = pVisualElementSurface;
1156 pSglInfoSecond->swapDone = true;
1157 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1159 pSglInfo->pSecondSglInfo = pSglInfoSecond;
1160 pSglInfoSecond->pSecondSglInfo = pSglInfo;
1162 pSglInfoSecond->pBitmap = bitmapSecond.release();
1163 _EvasObjectImageChange(pSglInfoSecond);
1167 pVisualElement->SetSurface(pSglInfo->pVisualElementSurface);
1170 pSglInfo->pBitmap = bitmap.release();
1171 _EvasObjectImageChange(pSglInfo);
1173 pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChanged, pSglInfo);
1174 pVisualElementImpl->SetDestroyedCallback(_OnDestroyed, pSglInfo);
1175 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1176 _RegisterRenderCallback(pSglInfo->pObject);
1178 return (EGLSurface)pSglInfo->sglIndex;
1183 _SglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* pAttribList)
1185 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1186 _SglIndex sglIndex = INVALID_SGL_INDEX;
1188 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1189 if (sglIndex <= INVALID_SGL_INDEX)
1191 SysLog(NID_GRP, "_SglCreatePbufferSurface failed!! dpy:%#x config:%#x pAttribList:%#x",
1192 (unsigned int)dpy, (unsigned int)config, (unsigned int)pAttribList);
1194 return eglCreatePbufferSurface(EGL_NO_DISPLAY, config, pAttribList);
1197 EGLSurface pbufferSurface = eglCreatePbufferSurface(dpy, config, pAttribList);
1198 if (pbufferSurface == EGL_NO_SURFACE)
1200 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1205 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1207 pSglInfo->surface = pbufferSurface;
1209 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1212 return (EGLSurface)sglIndex;
1215 _OSP_LOCAL_ EGLNativePixmapType
1216 _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pBitmap)
1220 int bitsPerPixel = 0;
1221 Display* pNativeDisplay = null;
1222 Drawable nativeWindow = 0;
1223 result r = E_FAILURE;
1224 Tizen::Graphics::BufferInfo bufferInfo;
1225 _PixmapInfo* pPixmapInfo = null;
1226 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1227 unsigned int attachments[] = { DRI2BufferFrontLeft };
1228 char* pDeviceName = null;
1229 char* pDriverName = null;
1230 DRI2Buffer* pDri2Buffer = null;
1233 int dri2BufferCount = 0;
1234 tbm_bo_handle tbmData = { null, };
1237 drm_magic_t magic = 0;
1239 _SglInfo* pSglInfo = null;
1240 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1242 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1243 if (pBitmap == null || sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1245 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1248 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1250 r = pBitmap->Lock(bufferInfo);
1256 width = bufferInfo.width;
1257 height = bufferInfo.height;
1258 bitsPerPixel = bufferInfo.bitsPerPixel;
1260 r = pBitmap->Unlock();
1261 if (r != E_SUCCESS || width <= 0 || height <= 0 || bitsPerPixel <= 0)
1266 pNativeDisplay = (Display*) ecore_x_display_get();
1267 nativeWindow = DefaultRootWindow(pNativeDisplay);
1269 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1270 if (pPixmapInfo == null)
1275 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height,
1276 ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1277 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1282 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1283 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1284 XSync(pNativeDisplay, False);
1286 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1288 if (!ret || pDeviceName == null)
1293 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1296 if (pPixmapInfo->drmFd < 0)
1301 drmGetMagic(pPixmapInfo->drmFd, &magic);
1302 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1308 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1309 if (pPixmapInfo->pTbmBufMgr == null)
1314 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1315 if (pDri2Buffer == null)
1320 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1322 if (pPixmapInfo->pTbmBufferObject == null)
1327 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1328 if (tbmData.ptr == null)
1333 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, tbmData.ptr, width * bitsPerPixel / 8,
1334 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1340 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1341 _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1347 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1349 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1351 pSglInfo->pEcoreImage = ecore_x_image_new(width
1353 , ecore_x_default_visual_get(pNativeDisplay, ecore_x_default_screen_get())
1354 , ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1356 if (pSglInfo->pEcoreImage == null)
1358 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1362 ecore_x_image_get(pSglInfo->pEcoreImage
1363 , pPixmapInfo->nativePixmap, 0, 0, 0, 0
1371 void* pSource = ecore_x_image_data_get(pSglInfo->pEcoreImage, &bpl, &rows, &bpp);
1373 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pSource, width * bitsPerPixel / 8,
1374 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1377 ecore_x_image_free(pSglInfo->pEcoreImage);
1378 pSglInfo->pEcoreImage = null;
1379 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1381 SysLog(NID_GRP, "change buffer failed! pSource %#x %d %d %d", (unsigned int)pSource, bpl, rows, bpp);
1385 pSglInfo->width = width;
1386 pSglInfo->height = height;
1388 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1390 #endif //#if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1391 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1393 pBitmap->Lock(bufferInfo);
1394 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1397 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1400 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1401 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1402 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1406 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1410 close(pPixmapInfo->drmFd);
1414 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1416 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1424 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1425 return (EGLNativePixmapType)0;
1428 _OSP_LOCAL_ EGLNativePixmapType
1429 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1433 int bitsPerPixel = 0;
1434 Display* pNativeDisplay = null;
1435 Drawable nativeWindow = 0;
1436 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1437 _PixmapInfo* pPixmapInfo = null;
1438 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1439 unsigned int attachments[] = { DRI2BufferFrontLeft };
1440 char* pDeviceName = null;
1441 char* pDriverName = null;
1442 DRI2Buffer* pDri2Buffer = null;
1445 int dri2BufferCount = 0;
1446 tbm_bo_handle tbmData = { null, };
1449 result r = E_FAILURE;
1450 drm_magic_t magic = 0;
1452 if (pBitmap == null)
1457 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1458 if (pBitmapImpl == null)
1463 width = bufferInfo.width;
1464 height = bufferInfo.height;
1465 bitsPerPixel = bufferInfo.bitsPerPixel;
1467 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1472 pNativeDisplay = (Display*) ecore_x_display_get();
1473 nativeWindow = DefaultRootWindow(pNativeDisplay);
1475 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1476 if (pPixmapInfo == null)
1481 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height
1483 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1488 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1489 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1490 XSync(pNativeDisplay, False);
1492 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1494 if (!ret || pDeviceName == null)
1499 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1501 if (pPixmapInfo->drmFd < 0)
1506 drmGetMagic(pPixmapInfo->drmFd, &magic);
1507 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1513 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1514 if (pPixmapInfo->pTbmBufMgr == null)
1519 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1520 if (pDri2Buffer == null)
1525 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1527 if (pPixmapInfo->pTbmBufferObject == null)
1532 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1533 if (tbmData.ptr == null)
1537 bufferInfo.pPixels = tbmData.ptr;
1539 bufferInfo.bitsPerPixel = 32;
1540 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1541 bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;
1542 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1543 r = pBitmapImpl->Construct(bufferInfo);
1549 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap
1550 , _PixmapSurfaceDestroyCallback, pPixmapInfo
1551 , _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject
1552 ,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1556 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1558 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1560 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1562 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1563 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1567 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1571 close(pPixmapInfo->drmFd);
1575 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1576 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1585 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1586 return (EGLNativePixmapType)0;
1590 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1592 _SglIndex sglIndex = INVALID_SGL_INDEX;
1593 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1594 EGLNativePixmapType eglNativePixmap = 0;
1595 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1596 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1598 if (pBitmap == null)
1603 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1604 if (sglIndex <= INVALID_SGL_INDEX)
1609 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1610 if (eglNativePixmap == 0)
1615 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1616 if (pixmapSurface == EGL_NO_SURFACE)
1618 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1623 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1625 pSglInfo->nativePixmap = eglNativePixmap;
1626 pSglInfo->surface = pixmapSurface;
1628 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1631 return (EGLSurface)sglIndex;
1634 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1638 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1639 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1640 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1644 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1646 EGLBoolean ret = EGL_FALSE;
1647 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1649 _SglIndex sglIndex = (_SglIndex)surface;
1650 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1652 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1654 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1655 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1656 , (unsigned int)surface);
1657 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1660 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1661 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
1663 __pPreviousSglInfo = null;
1667 ret = eglDestroySurface(dpy, pSglInfo->surface);
1668 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1670 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1672 eglDestroySurface(dpy, pSglInfo->pSecondSglInfo->surface);
1673 pSglInfoTableManipulatorInstance->DestroySglIndex(pSglInfo->pSecondSglInfo->sglIndex);
1676 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1682 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1684 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1686 _SglIndex sglIndex = (_SglIndex)surface;
1687 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1689 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1691 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1692 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1693 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1694 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1697 EGLBoolean ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1698 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1704 _SglBindAPI(EGLenum api)
1706 return eglBindAPI(api);
1712 return eglQueryAPI();
1718 return eglWaitClient();
1722 _SglReleaseThread(void)
1724 return eglReleaseThread();
1728 _SglCreatePbufferFromClientBuffer(
1729 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1731 _SglIndex sglIndex = INVALID_SGL_INDEX;
1732 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1734 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1735 if (sglIndex <= INVALID_SGL_INDEX)
1737 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1738 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1739 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1741 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1744 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1745 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1747 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1752 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1754 pSglInfo->surface = pbufferFromClientBuffer;
1756 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1759 return (EGLSurface)sglIndex;
1763 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1765 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1767 _SglIndex sglIndex = (_SglIndex)surface;
1768 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1770 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1772 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1773 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1774 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1775 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1777 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1780 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1781 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1787 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1789 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1791 _SglIndex sglIndex = (_SglIndex)surface;
1792 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1794 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1796 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1797 SysLog(NID_GRP, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1798 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1800 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1803 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1804 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1810 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1812 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1814 _SglIndex sglIndex = (_SglIndex)surface;
1815 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1817 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1819 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1820 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1821 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1823 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1826 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1827 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1833 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1835 return eglSwapInterval(dpy, interval);
1839 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1841 return eglCreateContext(dpy, config, shareContext, pAttribList);
1845 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1847 return eglDestroyContext(dpy, ctx);
1851 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1853 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1855 _SglIndex sglIndexDraw = (_SglIndex)draw;
1856 _SglIndex sglIndexRead = (_SglIndex)read;
1858 EGLSurface sglInfoReadSurface;
1860 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1862 if (sglInfoRead == null)
1864 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1865 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1866 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1867 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1869 sglInfoReadSurface = sglInfoRead->surface;
1871 if (__isDoublePixmapEnabled && !sglInfoRead->isBackbuffer && sglInfoRead->pSecondSglInfo != null)
1873 sglInfoReadSurface = sglInfoRead->pSecondSglInfo->surface;
1876 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1879 _SglInfo* pSglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1880 if (pSglInfoDraw == null)
1882 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1883 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1884 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1885 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1888 if (__isDoublePixmapEnabled && !pSglInfoDraw->isBackbuffer && pSglInfoDraw->pSecondSglInfo != null)
1890 pSglInfoDraw = pSglInfoDraw->pSecondSglInfo;
1893 pSglInfoDraw->context = ctx;
1895 EGLBoolean ret = eglMakeCurrent(dpy, pSglInfoDraw->surface, sglInfoReadSurface, ctx);
1897 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1898 if (draw != EGL_NO_SURFACE)
1900 _SaveCurrentContext(pSglInfoDraw);
1904 if (pSglInfoDraw->glVersion == 0 && ctx != EGL_NO_CONTEXT)
1906 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &pSglInfoDraw->glVersion);
1909 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1915 _SglGetCurrentContext()
1917 return eglGetCurrentContext();
1921 _SglGetCurrentSurface(EGLint readDraw)
1923 EGLSurface surface = EGL_NO_SURFACE;
1924 _SglIndex sglIndex = INVALID_SGL_INDEX;
1926 surface = eglGetCurrentSurface(readDraw);
1927 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
1929 if (sglIndex < INVALID_SGL_INDEX)
1931 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
1932 return EGL_NO_SURFACE;
1935 return (EGLSurface)sglIndex;
1939 _SglGetCurrentDisplay(void)
1941 return eglGetCurrentDisplay();
1945 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
1947 return eglQueryContext(dpy, ctx, attribute, pValue);
1957 _SglWaitNative(EGLint engine)
1959 return eglWaitNative(engine);
1962 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
1965 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1967 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1969 _SglIndex sglIndex = (_SglIndex)surface;
1970 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1972 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1974 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1975 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1976 , (unsigned int)sglIndex);
1978 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
1981 if (pSglInfo->pBitmap != null)
1983 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1984 _SglUpdateBufferOSP(dpy, surface);
1986 if(__evasEngineType == ENGINE_TYPE_OPENGL_X11)
1988 if (pSglInfo->glVersion == 1)
2003 if(__evasEngineType == ENGINE_TYPE_SOFEWARE_X11 || __evasEngineType == ENGINE_TYPE_OPENGL_X11)
2005 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
2007 if (pSglInfo->swapDone || pSglInfo->pSecondSglInfo->swapDone)
2009 _SglInfo* pBackSglInfo = null;
2010 _SglInfo* pFrontSglInfo = null;
2012 if (pSglInfo->isBackbuffer)
2014 pBackSglInfo = pSglInfo;
2015 pFrontSglInfo = pSglInfo->pSecondSglInfo;
2019 pBackSglInfo = pSglInfo->pSecondSglInfo;
2020 pFrontSglInfo = pSglInfo;
2023 pFrontSglInfo->swapDone = false;
2025 if (pSglInfo->pVisualElement != null)
2027 pSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
2029 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
2030 evas_object_hide(pBackSglInfo->pObject);
2032 if (pSglInfo->isFirstSwap)
2034 pBackSglInfo->isFirstSwap = false;
2035 pFrontSglInfo->isFirstSwap = false;
2038 BufferInfo bufferInfo;
2039 pFrontSglInfo->pBitmap->Lock(bufferInfo);
2040 pFrontSglInfo->pBitmap->Merge(Point(0, 0), *pBackSglInfo->pBitmap, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
2041 pFrontSglInfo->pBitmap->Unlock();
2047 if (pSglInfo->pObject != null)
2049 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2055 if (pSglInfo->pVisualElement != null)
2057 pSglInfo->pVisualElement->SetFlushNeeded();
2062 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2067 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2068 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2075 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2077 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2078 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2079 return eglCopyBuffers(dpy, surface, nativePixmap);
2082 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2084 __EglMustCastToProperFunctionPointerType
2085 _SglGetProcAddress(const char* pProcName)
2087 return eglGetProcAddress(pProcName);
2091 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2093 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2094 Tizen::Graphics::BufferInfo bufferInfo;
2095 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2097 _SglIndex sglIndex = (_SglIndex)surface;
2098 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2100 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2102 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2103 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2107 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2108 ecore_x_image_get(pSglInfo->pEcoreImage, (Ecore_X_Drawable)pSglInfo->nativePixmap,
2109 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2111 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2122 }} // Tizen::Graphics