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);
1396 canvas.Construct(bufferInfo);
1397 canvas.SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
1402 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1405 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1406 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1407 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1411 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1415 close(pPixmapInfo->drmFd);
1419 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1421 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1429 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1430 return (EGLNativePixmapType)0;
1433 _OSP_LOCAL_ EGLNativePixmapType
1434 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1438 int bitsPerPixel = 0;
1439 Display* pNativeDisplay = null;
1440 Drawable nativeWindow = 0;
1441 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1442 _PixmapInfo* pPixmapInfo = null;
1443 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1444 unsigned int attachments[] = { DRI2BufferFrontLeft };
1445 char* pDeviceName = null;
1446 char* pDriverName = null;
1447 DRI2Buffer* pDri2Buffer = null;
1450 int dri2BufferCount = 0;
1451 tbm_bo_handle tbmData = { null, };
1454 result r = E_FAILURE;
1455 drm_magic_t magic = 0;
1457 if (pBitmap == null)
1462 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1463 if (pBitmapImpl == null)
1468 width = bufferInfo.width;
1469 height = bufferInfo.height;
1470 bitsPerPixel = bufferInfo.bitsPerPixel;
1472 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1477 pNativeDisplay = (Display*) ecore_x_display_get();
1478 nativeWindow = DefaultRootWindow(pNativeDisplay);
1480 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1481 if (pPixmapInfo == null)
1486 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height
1488 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1493 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1494 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1495 XSync(pNativeDisplay, False);
1497 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1499 if (!ret || pDeviceName == null)
1504 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1506 if (pPixmapInfo->drmFd < 0)
1511 drmGetMagic(pPixmapInfo->drmFd, &magic);
1512 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1518 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1519 if (pPixmapInfo->pTbmBufMgr == null)
1524 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1525 if (pDri2Buffer == null)
1530 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1532 if (pPixmapInfo->pTbmBufferObject == null)
1537 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1538 if (tbmData.ptr == null)
1542 bufferInfo.pPixels = tbmData.ptr;
1544 bufferInfo.bitsPerPixel = 32;
1545 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1546 bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;
1547 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1548 r = pBitmapImpl->Construct(bufferInfo);
1554 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap
1555 , _PixmapSurfaceDestroyCallback, pPixmapInfo
1556 , _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject
1557 ,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1561 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1563 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1565 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1567 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1568 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1572 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1576 close(pPixmapInfo->drmFd);
1580 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1581 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1590 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1591 return (EGLNativePixmapType)0;
1595 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1597 _SglIndex sglIndex = INVALID_SGL_INDEX;
1598 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1599 EGLNativePixmapType eglNativePixmap = 0;
1600 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1601 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1603 if (pBitmap == null)
1608 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1609 if (sglIndex <= INVALID_SGL_INDEX)
1614 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1615 if (eglNativePixmap == 0)
1620 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1621 if (pixmapSurface == EGL_NO_SURFACE)
1623 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1628 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1630 pSglInfo->nativePixmap = eglNativePixmap;
1631 pSglInfo->surface = pixmapSurface;
1633 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1636 return (EGLSurface)sglIndex;
1639 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1643 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1644 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1645 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1649 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1651 EGLBoolean ret = EGL_FALSE;
1652 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1654 _SglIndex sglIndex = (_SglIndex)surface;
1655 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1657 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1659 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1660 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1661 , (unsigned int)surface);
1662 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1665 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1666 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
1668 __pPreviousSglInfo = null;
1672 ret = eglDestroySurface(dpy, pSglInfo->surface);
1673 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1675 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1677 eglDestroySurface(dpy, pSglInfo->pSecondSglInfo->surface);
1678 pSglInfoTableManipulatorInstance->DestroySglIndex(pSglInfo->pSecondSglInfo->sglIndex);
1681 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1687 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1689 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1691 _SglIndex sglIndex = (_SglIndex)surface;
1692 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1694 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1696 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1697 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1698 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1699 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1702 EGLBoolean ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1703 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1709 _SglBindAPI(EGLenum api)
1711 return eglBindAPI(api);
1717 return eglQueryAPI();
1723 return eglWaitClient();
1727 _SglReleaseThread(void)
1729 return eglReleaseThread();
1733 _SglCreatePbufferFromClientBuffer(
1734 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1736 _SglIndex sglIndex = INVALID_SGL_INDEX;
1737 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1739 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1740 if (sglIndex <= INVALID_SGL_INDEX)
1742 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1743 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1744 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1746 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1749 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1750 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1752 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1757 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1759 pSglInfo->surface = pbufferFromClientBuffer;
1761 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1764 return (EGLSurface)sglIndex;
1768 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1770 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1772 _SglIndex sglIndex = (_SglIndex)surface;
1773 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1775 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1777 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1778 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1779 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1780 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1782 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1785 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1786 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1792 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1794 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1796 _SglIndex sglIndex = (_SglIndex)surface;
1797 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1799 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1801 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1802 SysLog(NID_GRP, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1803 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1805 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1808 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1809 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1815 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1817 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1819 _SglIndex sglIndex = (_SglIndex)surface;
1820 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1822 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1824 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1825 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1826 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1828 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1831 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1832 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1838 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1840 return eglSwapInterval(dpy, interval);
1844 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1846 return eglCreateContext(dpy, config, shareContext, pAttribList);
1850 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1852 return eglDestroyContext(dpy, ctx);
1856 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1858 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1860 _SglIndex sglIndexDraw = (_SglIndex)draw;
1861 _SglIndex sglIndexRead = (_SglIndex)read;
1863 EGLSurface sglInfoReadSurface;
1865 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1867 if (sglInfoRead == null)
1869 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1870 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1871 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1872 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1874 sglInfoReadSurface = sglInfoRead->surface;
1876 if (__isDoublePixmapEnabled && !sglInfoRead->isBackbuffer && sglInfoRead->pSecondSglInfo != null)
1878 sglInfoReadSurface = sglInfoRead->pSecondSglInfo->surface;
1881 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1884 _SglInfo* pSglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1885 if (pSglInfoDraw == null)
1887 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1888 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1889 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1890 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1893 if (__isDoublePixmapEnabled && !pSglInfoDraw->isBackbuffer && pSglInfoDraw->pSecondSglInfo != null)
1895 pSglInfoDraw = pSglInfoDraw->pSecondSglInfo;
1898 pSglInfoDraw->context = ctx;
1900 EGLBoolean ret = eglMakeCurrent(dpy, pSglInfoDraw->surface, sglInfoReadSurface, ctx);
1902 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1903 if (draw != EGL_NO_SURFACE)
1905 _SaveCurrentContext(pSglInfoDraw);
1909 if (pSglInfoDraw->glVersion == 0 && ctx != EGL_NO_CONTEXT)
1911 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &pSglInfoDraw->glVersion);
1914 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1920 _SglGetCurrentContext()
1922 return eglGetCurrentContext();
1926 _SglGetCurrentSurface(EGLint readDraw)
1928 EGLSurface surface = EGL_NO_SURFACE;
1929 _SglIndex sglIndex = INVALID_SGL_INDEX;
1931 surface = eglGetCurrentSurface(readDraw);
1932 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
1934 if (sglIndex < INVALID_SGL_INDEX)
1936 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
1937 return EGL_NO_SURFACE;
1940 return (EGLSurface)sglIndex;
1944 _SglGetCurrentDisplay(void)
1946 return eglGetCurrentDisplay();
1950 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
1952 return eglQueryContext(dpy, ctx, attribute, pValue);
1962 _SglWaitNative(EGLint engine)
1964 return eglWaitNative(engine);
1967 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
1970 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1972 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1974 _SglIndex sglIndex = (_SglIndex)surface;
1975 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1977 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1979 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1980 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1981 , (unsigned int)sglIndex);
1983 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
1986 if (pSglInfo->pBitmap != null)
1988 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1989 _SglUpdateBufferOSP(dpy, surface);
1991 if(__evasEngineType == ENGINE_TYPE_OPENGL_X11)
1993 if (pSglInfo->glVersion == 1)
2008 if(__evasEngineType == ENGINE_TYPE_SOFEWARE_X11 || __evasEngineType == ENGINE_TYPE_OPENGL_X11)
2010 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
2012 if (pSglInfo->swapDone || pSglInfo->pSecondSglInfo->swapDone)
2014 _SglInfo* pBackSglInfo = null;
2015 _SglInfo* pFrontSglInfo = null;
2017 if (pSglInfo->isBackbuffer)
2019 pBackSglInfo = pSglInfo;
2020 pFrontSglInfo = pSglInfo->pSecondSglInfo;
2024 pBackSglInfo = pSglInfo->pSecondSglInfo;
2025 pFrontSglInfo = pSglInfo;
2028 pFrontSglInfo->swapDone = false;
2030 if (pSglInfo->pVisualElement != null)
2032 pSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
2034 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
2035 evas_object_hide(pBackSglInfo->pObject);
2037 if (pSglInfo->isFirstSwap)
2039 pBackSglInfo->isFirstSwap = false;
2040 pFrontSglInfo->isFirstSwap = false;
2043 BufferInfo bufferInfo;
2044 pFrontSglInfo->pBitmap->Lock(bufferInfo);
2045 pFrontSglInfo->pBitmap->Merge(Point(0, 0), *pBackSglInfo->pBitmap, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
2046 pFrontSglInfo->pBitmap->Unlock();
2052 if (pSglInfo->pObject != null)
2054 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2060 if (pSglInfo->pVisualElement != null)
2062 pSglInfo->pVisualElement->SetFlushNeeded();
2067 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2072 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2073 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2080 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2082 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2083 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2084 return eglCopyBuffers(dpy, surface, nativePixmap);
2087 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2089 __EglMustCastToProperFunctionPointerType
2090 _SglGetProcAddress(const char* pProcName)
2092 return eglGetProcAddress(pProcName);
2096 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2098 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2099 Tizen::Graphics::BufferInfo bufferInfo;
2100 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2102 _SglIndex sglIndex = (_SglIndex)surface;
2103 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2105 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2107 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2108 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2112 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2113 ecore_x_image_get(pSglInfo->pEcoreImage, (Ecore_X_Drawable)pSglInfo->nativePixmap,
2114 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2116 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2127 }} // Tizen::Graphics