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.
30 #include <EGL/eglext.h>
32 #if defined(_OSP_EMUL_)
33 #define FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER
35 #define FGRAPHICS_INTERNAL_USE_DRM
38 #define FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING
39 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
43 #include <Ecore_Evas.h>
46 #include <FBaseSysLog.h>
47 #include <FGrpBitmap.h>
48 #include <FGrpCoordinateSystem.h>
49 #include <FUiControl.h>
50 #include <FUiCtrlForm.h>
51 #include <FUiCtrlFrame.h>
52 #include <FUiWindow.h>
54 #include <FUi_EcoreEvasMgr.h>
55 #include <FUi_EcoreEvas.h>
57 #include <FGrp_BitmapTool.h>
58 #include <FGrp_BitmapImpl.h>
59 #include <FUi_ControlImpl.h>
60 #include <FUi_Control.h>
61 #include <FUi_WindowImpl.h>
62 #include <FUiAnim_VisualElementSurfaceImpl.h>
63 #include <FUiAnim_VisualElementImpl.h>
64 #include <FUiAnim_DisplayManager.h>
71 #include <elm_config.h>
73 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
77 #include <tbm_bufmgr.h>
81 typedef int _SglIndex;
84 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList);
85 EGLSurface _SglGetCurrentSurface(EGLint readDraw);
86 EGLNativePixmapType _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pixmap);
87 EGLNativePixmapType _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo);
89 #if defined(FGRAPHICS_INTERNAL_USE_DYNAMIC_LOADING)
90 void _GlesInterfaceTerminate_1();
91 void _GlesInterfaceTerminate_2();
94 #include <GLES2/gl2.h>
96 void _GlFlush_1(void);
97 void _GlFlush_2(void);
98 void _GlClear_1(GLbitfield mask);
99 void _GlClear_2(GLbitfield mask);
101 EGLBoolean _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
103 using namespace Tizen::Ui::Controls;
109 using namespace Tizen::Ui::Animations;
110 using namespace Tizen::Ui;
111 using namespace Tizen::Base;
113 namespace Tizen { namespace Graphics
124 #define FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT
125 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
126 void _RestoreContext(void);
127 void _PostRenderCallback(Ecore_Evas* ee);
128 void _SaveCurrentContext(_SglInfo* pSglInfo);
129 void _UnregisterRenderCallback(Evas_Object* pObject);
130 int __registerCallbackCount = 0;
131 _SglInfo* __pPreviousSglInfo = null;
134 #if !defined (_OSP_EMUL_)
135 #define FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP
140 ENGINE_TYPE_SOFEWARE_X11 = 0,
141 ENGINE_TYPE_OPENGL_X11,
145 _engineType __evasEngineType = ENGINE_TYPE_SOFEWARE_X11;
146 bool __isDoublePixmapEnabled = false;
148 void _OnBoundsChanged(void* pData);
150 const int INVALID_SGL_INDEX = 0;
151 const int MAX_SGL_INDEX = 100;
157 : sglIndex(INVALID_SGL_INDEX)
158 , display(EGL_NO_DISPLAY)
159 , surface(EGL_NO_SURFACE)
160 , context(EGL_NO_CONTEXT)
161 , config((EGLConfig)0)
164 , nativePixmap((EGLNativePixmapType)0)
165 , pVisualElement(null)
166 , pVisualElementSurface(null)
169 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
177 , pSecondSglInfo(null)
178 , pBitmapPointer(null)
179 , pBitmapLocked(null)
183 virtual ~_SglInfo(void)
185 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
186 if (pEcoreImage != null)
188 ecore_x_image_free(pEcoreImage);
197 if (pVisualElement != null)
199 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
200 if (pVisualElementImpl != null)
202 pVisualElementImpl->SetDestroyedCallback(null, null);
206 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
207 _UnregisterRenderCallback(pObject);
209 evas_object_del(pObject);
210 delete pVisualElementSurface;
213 bool needAllocateObject = true;
214 if (__isDoublePixmapEnabled)
218 needAllocateObject = false;
221 if (needAllocateObject)
223 if (pVisualElement != null)
225 pVisualElement->SetSurface(null);
229 sglIndex = INVALID_SGL_INDEX;
230 display = EGL_NO_DISPLAY;
231 surface = EGL_NO_SURFACE;
232 context = EGL_NO_CONTEXT;
233 config = (EGLConfig)0;
236 nativePixmap = (EGLNativePixmapType)0;
237 pVisualElement = null;
238 pVisualElementSurface = null;
241 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
249 pSecondSglInfo = null;
259 Evas_Object* pObject;
260 EGLNativePixmapType nativePixmap;
261 VisualElement* pVisualElement;
262 VisualElementSurface* pVisualElementSurface;
264 Tizen::Ui::Window* pWindow;
265 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
266 Ecore_X_Image* pEcoreImage;
273 _SglInfo* pSecondSglInfo;
274 void* pBitmapPointer;
275 Bitmap* pBitmapLocked;
278 _SglInfo(const _SglInfo& sglInfo);
279 _SglInfo& operator =(const _SglInfo& rhs);
286 : nativePixmap((Pixmap)0)
287 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
289 , pTbmBufferObject(null)
295 virtual ~_PixmapInfo(void)
297 Display* pDisplay = (Display*)ecore_x_display_get();
298 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
299 tbm_bo_unmap(pTbmBufferObject);
300 tbm_bo_unref(pTbmBufferObject);
306 tbm_bufmgr_deinit(pTbmBufMgr);
307 DRI2DestroyDrawable(pDisplay, nativePixmap);
309 XFreePixmap(pDisplay, nativePixmap);
311 nativePixmap = (Pixmap)0;
312 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
314 pTbmBufferObject = null;
321 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
322 tbm_bufmgr pTbmBufMgr;
323 tbm_bo pTbmBufferObject;
328 void _EvasObjectImageChange(_SglInfo* pSglInfo);
331 _OnBoundsChanged(void* pData)
333 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
334 SysTryReturnVoidResult(NID_GRP, pSglInfo != null
335 && pSglInfo->sglIndex > INVALID_SGL_INDEX
336 && pSglInfo->pVisualElement != null
337 && pSglInfo->pWindow != null
338 , E_INVALID_STATE, "Invalid state.");
340 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
342 __pPreviousSglInfo = null;
345 bool needSglMakeCurrent = false;
346 EGLDisplay eglDisplay = eglGetCurrentDisplay();
347 EGLSurface drawSurface = _SglGetCurrentSurface(EGL_DRAW);
348 EGLSurface readSurface = _SglGetCurrentSurface(EGL_READ);
349 EGLSurface eglContext = eglGetCurrentContext();
351 if (drawSurface != EGL_NO_SURFACE && readSurface != EGL_NO_SURFACE)
353 needSglMakeCurrent = true;
357 drawSurface = eglGetCurrentSurface(EGL_DRAW);
358 readSurface = eglGetCurrentSurface(EGL_READ);
361 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
362 EGLBoolean ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
363 pSglInfo->surface = null;
364 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
366 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
367 if (pSglInfo->pEcoreImage != null)
369 ecore_x_image_free(pSglInfo->pEcoreImage);
370 pSglInfo->pEcoreImage = null;
374 FloatRectangle rect = pSglInfo->pVisualElement->GetBounds();
375 int width = int(rect.width);
376 int height = int(rect.height);
377 SysTryReturnVoidResult(NID_GRP, width > 0 && height > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
378 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
379 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
380 SysTryReturnVoidResult(NID_GRP, widthPhysical > 0 && heightPhysical > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", widthPhysical, heightPhysical);
382 evas_object_image_size_set(pSglInfo->pObject, widthPhysical, heightPhysical);
383 evas_object_resize(pSglInfo->pObject, widthPhysical, heightPhysical);
385 delete pSglInfo->pBitmap;
386 pSglInfo->pBitmap = null;
387 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
388 SysTryReturnVoidResult(NID_GRP, bitmap.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
389 result r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
390 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
391 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, bitmap.get());
392 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
393 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, nativePixmap, null);
394 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
396 pSglInfo->nativePixmap = nativePixmap;
397 pSglInfo->surface = eglSurface;
398 pSglInfo->isBackbuffer = true;
399 pSglInfo->swapDone = false;
400 pSglInfo->isFirstSwap = true;
402 if (__isDoublePixmapEnabled)
404 _SglInfo* pSglInfoSecond = pSglInfo->pSecondSglInfo;
405 SysTryReturnVoidResult(NID_GRP, pSglInfoSecond != null, E_INVALID_STATE, "Invalid pSecondSglInfo.");
407 eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
408 ret = eglDestroySurface(pSglInfoSecond->display, pSglInfoSecond->surface);
409 pSglInfoSecond->surface = null;
410 SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
412 evas_object_image_size_set(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
413 evas_object_resize(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
415 delete pSglInfoSecond->pBitmap;
416 pSglInfoSecond->pBitmap = null;
417 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
418 SysTryReturnVoidResult(NID_GRP, bitmapSecond.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
419 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
420 SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
421 EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfoSecond->sglIndex, bitmapSecond.get());
422 SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
423 EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfoSecond->display, pSglInfoSecond->config, nativePixmap, null);
424 SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
426 pSglInfoSecond->nativePixmap = nativePixmap;
427 pSglInfoSecond->surface = eglSurface;
428 pSglInfoSecond->pBitmap = bitmapSecond.release();
429 pSglInfoSecond->isBackbuffer = true;
430 pSglInfoSecond->swapDone = true;
432 pSglInfo->isFirstSwap = true;
434 _EvasObjectImageChange(pSglInfoSecond);
437 pSglInfo->pBitmap = bitmap.release();
438 _EvasObjectImageChange(pSglInfo);
440 BufferInfo bufferInfo;
441 pSglInfo->pBitmap->Lock(bufferInfo);
442 pSglInfo->pBitmap->Unlock();
444 if (needSglMakeCurrent)
446 _SglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
450 eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
457 _OnDestroyed(void* pData)
459 _SglInfo* pSglInfo = dynamic_cast<_SglInfo*> ((_SglInfo*)pData);
461 if (pSglInfo != null)
463 pSglInfo->pVisualElement = null;
465 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
467 pSglInfo->pSecondSglInfo->pVisualElement = null;
472 class _SglInfoTableManipulator
475 _SglInfoTableManipulator()
477 result r = __SglMutex.Create();
478 SysTryLog(NID_GRP, r == E_SUCCESS, "Failed to create mutex. [%s]", GetErrorMessage(r));
479 __SglIndexLastUsed = INVALID_SGL_INDEX;
480 __SglInitialized = false;
483 ~_SglInfoTableManipulator()
488 FindNextEmptySlotOfSglInfoTable()
490 if (!__SglInitialized)
492 if (CreateSglInfoTable() == false)
494 return INVALID_SGL_INDEX;
498 _SglIndex sglIndex = INVALID_SGL_INDEX;
499 _SglIndex index = __SglIndexLastUsed;
501 __SglMutex.Acquire();
502 for (int i = 1; i < MAX_SGL_INDEX; i++)
506 if (index >= MAX_SGL_INDEX)
511 if (__SglInfoTable[index] == null)
514 __SglIndexLastUsed = index;
518 __SglMutex.Release();
521 if (sglIndex <= INVALID_SGL_INDEX)
523 return INVALID_SGL_INDEX;
534 __SglMutex.Acquire();
536 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
538 __SglInfoTable[i] = null;
541 __SglInfoTable[0] = new (std::nothrow) _SglInfo;
542 if (__SglInfoTable[0] != null)
545 __SglInitialized = true;
546 __SglInfoTable[0]->glVersion = 2;
549 __SglMutex.Release();
555 DestroySglInfoTable()
557 __SglMutex.Acquire();
559 for (int i = 0 ; i < MAX_SGL_INDEX; i++)
561 if (__SglInfoTable[i] != null)
563 delete __SglInfoTable[i];
564 __SglInfoTable[i] = null;
567 __SglInitialized = false;
569 __SglMutex.Release();
573 LockSglInfoTable(_SglIndex index)
575 __SglMutex.Acquire();
577 if (index < INVALID_SGL_INDEX || index >= MAX_SGL_INDEX)
582 return __SglInfoTable[index];
588 __SglMutex.Release();
594 _SglInfo* newSglInfo = new (std::nothrow) _SglInfo;
595 if (newSglInfo == null)
597 SysLog(NID_GRP, "CreateSglIndex fail to allocate _SglInfo!!");
598 return INVALID_SGL_INDEX;
601 int sglIndex = FindNextEmptySlotOfSglInfoTable();
602 if (sglIndex == INVALID_SGL_INDEX)
606 SysLog(NID_GRP, "CreateSglIndex failed!!");
607 return INVALID_SGL_INDEX;
610 __SglMutex.Acquire();
611 __SglInfoTable[sglIndex] = newSglInfo;
612 __SglMutex.Release();
618 DestroySglIndex(_SglIndex sglIndex)
620 if (sglIndex < 1 || sglIndex >= MAX_SGL_INDEX)
622 SysLog(NID_GRP, "sglIndex:%#x is out of range.", (unsigned int)sglIndex);
626 __SglMutex.Acquire();
628 if (sglIndex <= INVALID_SGL_INDEX || __SglInfoTable[sglIndex] == null)
630 __SglMutex.Release();
632 SysLog(NID_GRP, "DestroySglIndex failed!! sglIndex:%#x", (unsigned int)sglIndex);
636 delete __SglInfoTable[sglIndex];
637 __SglInfoTable[sglIndex] = null;
639 __SglMutex.Release();
645 GetSglIndexForSurface(EGLSurface surface)
647 __SglMutex.Acquire();
650 for (int i = 0; i < MAX_SGL_INDEX; i++)
652 if (__SglInfoTable[i] != null && __SglInfoTable[i]->surface == surface)
659 __SglMutex.Release();
664 static _SglInfoTableManipulator* GetInstance(void)
666 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
670 pthread_once(&once_block, __InitSglInfoTableManipulator);
673 return __pTheInstance;
677 static void __InitSglInfoTableManipulator(void)
679 static _SglInfoTableManipulator instance;
680 __pTheInstance = &instance;
684 Runtime::Mutex __SglMutex;
685 _SglInfo* __SglInfoTable[MAX_SGL_INDEX];
686 _SglIndex __SglIndexLastUsed;
687 bool __SglInitialized;
689 static _SglInfoTableManipulator* __pTheInstance;
691 _SglInfoTableManipulator* _SglInfoTableManipulator::__pTheInstance = null;
694 _PixmapSurfaceDestroyCallback(void* pCallbackParam)
696 delete (_PixmapInfo*)pCallbackParam;
699 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
701 _PixmapLockCallBack(void* pCallbackParam)
703 tbm_bo_map((tbm_bo)pCallbackParam, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
707 _PixmapUnlockCallBack(void* pCallbackParam)
709 tbm_bo_unmap((tbm_bo)pCallbackParam);
714 _GetEvasEngineType(Evas_Object* pObject)
718 const char* pString = elm_config_preferred_engine_get();
719 String engineName(pString);
720 SysLog(NID_GRP, "evas backend : %s", pString);
722 if (engineName.Contains(String("opengl_x11")))
724 _DisplayManager* pDisplayManger = _DisplayManager::GetInstance();
725 pDisplayManger->SetRestoreContextCallback(_RestoreContext);
726 return ENGINE_TYPE_OPENGL_X11;
730 return ENGINE_TYPE_SOFEWARE_X11;
735 Evas* pEvas = evas_object_evas_get(pObject);
738 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEvas failed.");
739 return ENGINE_TYPE_SOFEWARE_X11;
742 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
743 if (pEcoreEvas == null)
745 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEcoreEvas failed.");
746 return ENGINE_TYPE_SOFEWARE_X11;
749 const char* pString = ecore_evas_engine_name_get(pEcoreEvas);
750 String engineName(pString);
751 SysLog(NID_GRP, "evas backend : %s", pString);
753 if (engineName.Contains(String("opengl_x11")))
755 _DisplayManager* pDisplayManger = _DisplayManager::GetInstance();
756 pDisplayManger->SetRestoreContextCallback(_RestoreContext);
757 return ENGINE_TYPE_OPENGL_X11;
759 else if (engineName.Contains(String("software_x11")))
761 return ENGINE_TYPE_SOFEWARE_X11;
765 return ENGINE_TYPE_ETC;
771 _EvasObjectImageChange(_SglInfo* pSglInfo)
773 if(__evasEngineType == ENGINE_TYPE_SOFEWARE_X11 || __evasEngineType == ENGINE_TYPE_OPENGL_X11)
775 Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
778 SysLogException(NID_GRP, E_OPERATION_FAILED, "Getting pEvas failed.");
782 Evas_Native_Surface nativeSurface = {0, };
783 nativeSurface.type = EVAS_NATIVE_SURFACE_X11;
784 nativeSurface.version = EVAS_NATIVE_SURFACE_VERSION;
785 nativeSurface.data.x11.pixmap = (unsigned long)pSglInfo->nativePixmap;
786 nativeSurface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
787 evas_object_image_native_surface_set(pSglInfo->pObject, &nativeSurface);
791 BufferInfo bufferInfo;
792 pSglInfo->pBitmap->Lock(bufferInfo);
793 evas_object_image_data_set(pSglInfo->pObject, bufferInfo.pPixels);
794 pSglInfo->pBitmap->Unlock();
798 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
800 _RestoreContext(void)
802 if (__pPreviousSglInfo != null)
804 EGLDisplay display = __pPreviousSglInfo->display;
805 EGLSurface surface = __pPreviousSglInfo->surface;
806 EGLContext context = __pPreviousSglInfo->context;
808 if (__isDoublePixmapEnabled)
810 _SglInfo* pBackSglInfo = null;
811 _SglInfo* pFrontSglInfo = null;
813 if (__pPreviousSglInfo->isBackbuffer)
815 pBackSglInfo = __pPreviousSglInfo;
816 pFrontSglInfo = __pPreviousSglInfo->pSecondSglInfo;
820 pBackSglInfo = __pPreviousSglInfo->pSecondSglInfo;
821 pFrontSglInfo = __pPreviousSglInfo;
824 surface = pBackSglInfo->surface;
827 EGLBoolean ret = eglMakeCurrent(display, surface, surface, context);
828 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
829 , (unsigned int)display
830 , (unsigned int)surface
831 , (unsigned int)surface
832 , (unsigned int)context
833 , (unsigned int)eglGetError());
838 _PostRenderCallback(Ecore_Evas* ee)
840 if (__pPreviousSglInfo != null)
842 EGLDisplay display = __pPreviousSglInfo->display;
843 EGLSurface surface = __pPreviousSglInfo->surface;
844 EGLContext context = __pPreviousSglInfo->context;
846 if (__isDoublePixmapEnabled)
848 _SglInfo* pBackSglInfo = null;
849 _SglInfo* pFrontSglInfo = null;
851 if (__pPreviousSglInfo->isBackbuffer)
853 pBackSglInfo = __pPreviousSglInfo;
854 pFrontSglInfo = __pPreviousSglInfo->pSecondSglInfo;
858 pBackSglInfo = __pPreviousSglInfo->pSecondSglInfo;
859 pFrontSglInfo = __pPreviousSglInfo;
862 if (!pFrontSglInfo->swapDone && __pPreviousSglInfo->pVisualElement != null)
864 pBackSglInfo->isBackbuffer = false;
865 pFrontSglInfo->isBackbuffer = true;
866 pFrontSglInfo->swapDone = true;
868 __pPreviousSglInfo->pVisualElement->SetSurface(pBackSglInfo->pVisualElementSurface);
869 evas_object_image_pixels_dirty_set(pBackSglInfo->pObject, EINA_TRUE);
870 evas_object_hide(pFrontSglInfo->pObject);
873 surface = pFrontSglInfo->surface;
876 EGLBoolean ret = eglMakeCurrent(display, surface, surface, context);
877 SysTryLog(NID_GRP, ret == EGL_TRUE, "fail to restore previous surface and context. %#x %#x %#x %#x egl error:%#x"
878 , (unsigned int)display
879 , (unsigned int)surface
880 , (unsigned int)surface
881 , (unsigned int)context
882 , (unsigned int)eglGetError());
887 _SaveCurrentContext(_SglInfo* pSglInfo)
889 __pPreviousSglInfo = pSglInfo;
893 _RegisterRenderCallback(Evas_Object* pObject)
895 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11 && pObject != null)
897 if (__registerCallbackCount == 0)
899 Evas* pEvas = evas_object_evas_get(pObject);
905 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
906 if (pEcoreEvas == null)
911 ecore_evas_callback_post_render_set(pEcoreEvas, _PostRenderCallback);
913 __registerCallbackCount++;
918 _UnregisterRenderCallback(Evas_Object* pObject)
920 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11 && pObject != null)
922 __registerCallbackCount--;
924 if (__registerCallbackCount == 0)
926 Evas* pEvas = evas_object_evas_get(pObject);
932 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
933 if (pEcoreEvas == null)
938 ecore_evas_callback_post_render_set(pEcoreEvas, NULL);
942 #endif //#if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
954 return eglGetError();
958 _SglGetDisplay(EGLNativeDisplayType displayId)
960 if (displayId == (EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)
962 return eglGetDisplay((EGLNativeDisplayType) ecore_x_display_get());
965 return eglGetDisplay((EGLNativeDisplayType) displayId);
969 _SglInitialize(EGLDisplay dpy, EGLint* pMajor, EGLint* pMinor)
971 __evasEngineType = _GetEvasEngineType(null);
972 return eglInitialize(dpy, pMajor, pMinor);
976 _SglTerminate(EGLDisplay dpy)
978 _GlesInterfaceTerminate_1();
979 _GlesInterfaceTerminate_2();
981 _SglInfoTableManipulator::GetInstance()->DestroySglInfoTable();
983 if (__evasEngineType != ENGINE_TYPE_OPENGL_X11)
988 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
989 __registerCallbackCount = 0;
990 __pPreviousSglInfo = null;
998 _SglQueryString(EGLDisplay dpy, EGLint name)
1000 return eglQueryString(dpy, name);
1004 _SglGetConfigs(EGLDisplay dpy, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
1006 return eglGetConfigs(dpy, pConfigs, configSize, pNumConfig);
1010 _SglChooseConfig(EGLDisplay dpy, const EGLint* pAttribList, EGLConfig* pConfigs, EGLint configSize, EGLint* pNumConfig)
1012 return eglChooseConfig(dpy, pAttribList, pConfigs, configSize, pNumConfig);
1016 _SglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* pValue)
1018 return eglGetConfigAttrib(dpy, config, attribute, pValue);
1022 _SglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* pAttribList)
1024 _SglIndex sglIndex = INVALID_SGL_INDEX;
1025 Object* pObj = (Object*)win;
1026 VisualElement* pVisualElement = dynamic_cast<VisualElement*> (pObj);
1027 Tizen::Ui::Control* pControl = dynamic_cast<Tizen::Ui::Control*> (pObj);
1028 #if 0//!defined(_OSP_EMUL_)
1029 Tizen::Ui::Controls::Frame* pFrame = dynamic_cast<Tizen::Ui::Controls::Frame*> (pControl);
1031 SysTryReturn(NID_GRP, pControl != null || pVisualElement != null, EGL_NO_SURFACE, E_INVALID_ARG, "Invalid NativeWindow.");
1032 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1034 #if 0//!defined(_OSP_EMUL_)
1035 if (pFrame != null && _GetEvasEngineType(null) != ENGINE_TYPE_OPENGL_X11)
1037 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(*pControl);
1038 _WindowImpl* pWindowImpl = dynamic_cast<_WindowImpl*> (pControlImpl);
1039 SysTryReturn(NID_GRP, pWindowImpl != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window state.");
1041 EGLNativeWindowType nativeWindow = (EGLNativeWindowType)pWindowImpl->GetNativeHandle();
1042 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1043 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid SglIndex.");
1045 EGLSurface windowSurface = eglCreateWindowSurface(dpy, config, nativeWindow, pAttribList);
1046 if (windowSurface == EGL_NO_SURFACE)
1048 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1053 VisualElement* pVisualElement = pControlImpl->GetCore().GetVisualElement();
1054 if (pVisualElement == null)
1056 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1057 return EGL_NO_SURFACE;
1060 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1061 if (pVisualElementImpl == null)
1063 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1064 return EGL_NO_SURFACE;
1067 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1069 pSglInfo->surface = windowSurface;
1071 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1074 return (EGLSurface)sglIndex;
1077 #endif //#if !defined(_OSP_EMUL_)
1079 result r = E_SUCCESS;
1081 if (pVisualElement == null)
1083 pVisualElement = pControl->GetVisualElement();
1085 SysTryReturn(NID_GRP, pVisualElement != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1087 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
1088 SysTryReturn(NID_GRP, pVisualElementImpl != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1090 FloatRectangle rect = pVisualElement->GetBounds();
1091 int width = int(rect.width);
1092 int height = int(rect.height);
1093 SysTryReturn(NID_GRP, width > 0 && height > 0, EGL_NO_SURFACE, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
1095 Control* pFrame = pControl;
1096 Control* pTemp = pFrame->GetParent();
1097 while(pTemp != null)
1100 pTemp = pTemp->GetParent();
1103 Tizen::Ui::Window* pWindow = dynamic_cast<Tizen::Ui::Window*> (pFrame);
1104 SysTryReturn(NID_GRP, pWindow != null, EGL_NO_SURFACE, E_INVALID_STATE, "Invalid window.");
1106 VisualElementSurface* pVisualElementSurface = pVisualElement->GetSurfaceN();
1107 SysTryReturn(NID_GRP, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1109 _VisualElementSurfaceImpl* pVisualElementSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pVisualElementSurface);
1110 if (pVisualElementSurfaceImpl == null)
1112 SysLogException(NID_GRP, E_OPERATION_FAILED, "Propagating.");
1113 delete pVisualElementSurface;
1114 return EGL_NO_SURFACE;
1117 Evas_Object* pObject = (Evas_Object*)pVisualElementSurfaceImpl->GetNativeHandle();
1118 delete pVisualElementSurface;
1120 Evas* pEvas = evas_object_evas_get(pObject);
1121 pObject = evas_object_image_filled_add(pEvas);
1122 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1124 int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
1125 int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
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, pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1136 std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
1137 SysTryReturn(NID_GRP, bitmap.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1139 r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
1140 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1142 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmap.get(), null);
1143 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1145 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1146 pSglInfo->sglIndex = sglIndex;
1147 pSglInfo->display = dpy;
1148 pSglInfo->config = config;
1149 pSglInfo->pVisualElement = pVisualElement;
1150 pSglInfo->pWindow = pWindow;
1151 pSglInfo->pObject = pObject;
1152 pSglInfo->pVisualElementSurface = pVisualElementSurface;
1153 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1155 __evasEngineType = _GetEvasEngineType(pObject);
1157 #if defined (FGRAPHICS_INTERNAL_USE_DOUBLE_PIXMAP)
1158 if (__evasEngineType == ENGINE_TYPE_OPENGL_X11)
1160 __isDoublePixmapEnabled = true;
1164 __isDoublePixmapEnabled = false;
1167 __isDoublePixmapEnabled = false;
1170 if (__isDoublePixmapEnabled)
1172 pObject = evas_object_image_filled_add(pEvas);
1173 SysTryReturn(NID_GRP, pObject != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Invalid object.");
1175 evas_object_image_alpha_set(pObject, EINA_TRUE);
1176 evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
1177 evas_object_resize(pObject, widthPhysical, heightPhysical);
1178 evas_object_hide(pObject);
1180 pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
1181 *pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
1182 SysTryReturn(NID_GRP, pSglInfo->pVisualElementSurface != null, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1184 delete pSglInfo->pBitmap;
1185 pSglInfo->pBitmap = null;
1187 std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
1188 SysTryReturn(NID_GRP, bitmapSecond.get() != null, EGL_NO_SURFACE, E_OUT_OF_MEMORY, "The memory is insufficient.");
1190 r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
1191 SysTryReturn(NID_GRP, r == E_SUCCESS, EGL_NO_SURFACE, r, "Propagating.");
1193 sglIndex = (_SglIndex)_SglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)bitmapSecond.get(), null);
1194 SysTryReturn(NID_GRP, sglIndex > INVALID_SGL_INDEX, EGL_NO_SURFACE, E_OPERATION_FAILED, "Propagating.");
1196 _SglInfo* pSglInfoSecond = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1197 pSglInfoSecond->sglIndex = sglIndex;
1198 pSglInfoSecond->display = dpy;
1199 pSglInfoSecond->config = config;
1200 pSglInfoSecond->pVisualElement = pVisualElement;
1201 pSglInfoSecond->pWindow = pWindow;
1202 pSglInfoSecond->pObject = pObject;
1203 pSglInfoSecond->pVisualElementSurface = pVisualElementSurface;
1204 pSglInfoSecond->swapDone = true;
1205 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1207 pSglInfo->pSecondSglInfo = pSglInfoSecond;
1208 pSglInfoSecond->pSecondSglInfo = pSglInfo;
1210 pSglInfoSecond->pBitmap = bitmapSecond.release();
1211 _EvasObjectImageChange(pSglInfoSecond);
1215 pVisualElement->SetSurface(pSglInfo->pVisualElementSurface);
1218 pSglInfo->pBitmap = bitmap.release();
1219 _EvasObjectImageChange(pSglInfo);
1221 pVisualElementImpl->SetBoundsChangedCallback(_OnBoundsChanged, pSglInfo);
1222 pVisualElementImpl->SetDestroyedCallback(_OnDestroyed, pSglInfo);
1223 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1224 _RegisterRenderCallback(pSglInfo->pObject);
1226 return (EGLSurface)pSglInfo->sglIndex;
1231 _SglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* pAttribList)
1233 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1234 _SglIndex sglIndex = INVALID_SGL_INDEX;
1236 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1237 if (sglIndex <= INVALID_SGL_INDEX)
1239 SysLog(NID_GRP, "_SglCreatePbufferSurface failed!! dpy:%#x config:%#x pAttribList:%#x",
1240 (unsigned int)dpy, (unsigned int)config, (unsigned int)pAttribList);
1242 return eglCreatePbufferSurface(EGL_NO_DISPLAY, config, pAttribList);
1245 EGLSurface pbufferSurface = eglCreatePbufferSurface(dpy, config, pAttribList);
1246 if (pbufferSurface == EGL_NO_SURFACE)
1248 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1253 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1255 pSglInfo->surface = pbufferSurface;
1257 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1260 return (EGLSurface)sglIndex;
1263 _OSP_LOCAL_ EGLNativePixmapType
1264 _CreateNativePixmap(_SglIndex sglIndex, Tizen::Graphics::Bitmap* pBitmap)
1268 int bitsPerPixel = 0;
1269 Display* pNativeDisplay = null;
1270 Drawable nativeWindow = 0;
1271 result r = E_FAILURE;
1272 Tizen::Graphics::BufferInfo bufferInfo;
1273 _PixmapInfo* pPixmapInfo = null;
1274 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1275 unsigned int attachments[] = { DRI2BufferFrontLeft };
1276 char* pDeviceName = null;
1277 char* pDriverName = null;
1278 DRI2Buffer* pDri2Buffer = null;
1281 int dri2BufferCount = 0;
1282 tbm_bo_handle tbmData = { null, };
1285 drm_magic_t magic = 0;
1287 _SglInfo* pSglInfo = null;
1288 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1290 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1291 if (pBitmap == null || sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1293 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1296 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1298 r = pBitmap->Lock(bufferInfo);
1304 width = bufferInfo.width;
1305 height = bufferInfo.height;
1306 bitsPerPixel = bufferInfo.bitsPerPixel;
1308 r = pBitmap->Unlock();
1309 if (r != E_SUCCESS || width <= 0 || height <= 0 || bitsPerPixel <= 0)
1314 pNativeDisplay = (Display*) ecore_x_display_get();
1315 nativeWindow = DefaultRootWindow(pNativeDisplay);
1317 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1318 if (pPixmapInfo == null)
1323 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height,
1324 ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1325 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1330 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1331 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1332 XSync(pNativeDisplay, False);
1334 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1336 if (!ret || pDeviceName == null)
1341 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1344 if (pPixmapInfo->drmFd < 0)
1349 drmGetMagic(pPixmapInfo->drmFd, &magic);
1350 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1356 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1357 if (pPixmapInfo->pTbmBufMgr == null)
1362 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1363 if (pDri2Buffer == null)
1368 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1370 if (pPixmapInfo->pTbmBufferObject == null)
1375 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1376 if (tbmData.ptr == null)
1381 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, tbmData.ptr, width * bitsPerPixel / 8,
1382 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1388 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap, _PixmapSurfaceDestroyCallback, pPixmapInfo,
1389 _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1395 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1397 pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1399 pSglInfo->pEcoreImage = ecore_x_image_new(width
1401 , ecore_x_default_visual_get(pNativeDisplay, ecore_x_default_screen_get())
1402 , ecore_x_default_depth_get(pNativeDisplay, ecore_x_default_screen_get()));
1404 if (pSglInfo->pEcoreImage == null)
1406 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1410 ecore_x_image_get(pSglInfo->pEcoreImage
1411 , pPixmapInfo->nativePixmap, 0, 0, 0, 0
1419 void* pSource = ecore_x_image_data_get(pSglInfo->pEcoreImage, &bpl, &rows, &bpp);
1421 r = Tizen::Graphics::_BitmapTool::ChangeBuffer(*pBitmap, pSource, width * bitsPerPixel / 8,
1422 _PixmapSurfaceDestroyCallback, (void*)pPixmapInfo);
1425 ecore_x_image_free(pSglInfo->pEcoreImage);
1426 pSglInfo->pEcoreImage = null;
1427 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1429 SysLog(NID_GRP, "change buffer failed! pSource %#x %d %d %d", (unsigned int)pSource, bpl, rows, bpp);
1433 pSglInfo->width = width;
1434 pSglInfo->height = height;
1436 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1438 #endif //#if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
1439 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1441 pBitmap->Lock(bufferInfo);
1444 canvas.Construct(bufferInfo);
1445 canvas.SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
1450 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1453 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1454 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1455 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1459 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1463 close(pPixmapInfo->drmFd);
1467 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1469 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1477 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1478 return (EGLNativePixmapType)0;
1481 _OSP_LOCAL_ EGLNativePixmapType
1482 _CreateNativePixmapEx(Tizen::Graphics::Bitmap* pBitmap, Tizen::Graphics::BufferInfo bufferInfo)
1486 int bitsPerPixel = 0;
1487 Display* pNativeDisplay = null;
1488 Drawable nativeWindow = 0;
1489 Tizen::Graphics::_BitmapImpl* pBitmapImpl = null;
1490 _PixmapInfo* pPixmapInfo = null;
1491 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1492 unsigned int attachments[] = { DRI2BufferFrontLeft };
1493 char* pDeviceName = null;
1494 char* pDriverName = null;
1495 DRI2Buffer* pDri2Buffer = null;
1498 int dri2BufferCount = 0;
1499 tbm_bo_handle tbmData = { null, };
1502 result r = E_FAILURE;
1503 drm_magic_t magic = 0;
1505 if (pBitmap == null)
1510 pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(*pBitmap);
1511 if (pBitmapImpl == null)
1516 width = bufferInfo.width;
1517 height = bufferInfo.height;
1518 bitsPerPixel = bufferInfo.bitsPerPixel;
1520 if (width <= 0 || height <= 0 || bitsPerPixel <= 0)
1525 pNativeDisplay = (Display*) ecore_x_display_get();
1526 nativeWindow = DefaultRootWindow(pNativeDisplay);
1528 pPixmapInfo = new (std::nothrow) _PixmapInfo;
1529 if (pPixmapInfo == null)
1534 pPixmapInfo->nativePixmap = XCreatePixmap(pNativeDisplay, nativeWindow, width, height
1536 if (pPixmapInfo->nativePixmap == (Pixmap)0)
1541 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1542 DRI2CreateDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1543 XSync(pNativeDisplay, False);
1545 ret = DRI2Connect(pNativeDisplay, nativeWindow, &pDriverName, &pDeviceName);
1547 if (!ret || pDeviceName == null)
1552 pPixmapInfo->drmFd = open(pDeviceName, O_RDWR);
1554 if (pPixmapInfo->drmFd < 0)
1559 drmGetMagic(pPixmapInfo->drmFd, &magic);
1560 ret = DRI2Authenticate(pNativeDisplay, nativeWindow, (unsigned int)magic);
1566 pPixmapInfo->pTbmBufMgr = tbm_bufmgr_init(pPixmapInfo->drmFd);
1567 if (pPixmapInfo->pTbmBufMgr == null)
1572 pDri2Buffer = DRI2GetBuffers(pNativeDisplay, pPixmapInfo->nativePixmap, &dri2Width, &dri2Height, attachments, 1, &dri2BufferCount);
1573 if (pDri2Buffer == null)
1578 pPixmapInfo->pTbmBufferObject = tbm_bo_import(pPixmapInfo->pTbmBufMgr, pDri2Buffer->name);
1580 if (pPixmapInfo->pTbmBufferObject == null)
1585 tbmData = tbm_bo_get_handle(pPixmapInfo->pTbmBufferObject, TBM_DEVICE_CPU);
1586 if (tbmData.ptr == null)
1590 bufferInfo.pPixels = tbmData.ptr;
1592 bufferInfo.bitsPerPixel = 32;
1593 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
1594 bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;
1595 memset(bufferInfo.pPixels, 0, bufferInfo.pitch * bufferInfo.height);
1596 r = pBitmapImpl->Construct(bufferInfo);
1602 if (!Tizen::Graphics::_BitmapTool::SetCallback(*pBitmap
1603 , _PixmapSurfaceDestroyCallback, pPixmapInfo
1604 , _PixmapLockCallBack, pPixmapInfo->pTbmBufferObject
1605 ,_PixmapUnlockCallBack, pPixmapInfo->pTbmBufferObject))
1609 #endif //#if defined(FGRAPHICS_INTERNAL_USE_DRM)
1611 return (EGLNativePixmapType)pPixmapInfo->nativePixmap;
1613 #if defined(FGRAPHICS_INTERNAL_USE_DRM)
1615 tbm_bo_unmap(pPixmapInfo->pTbmBufferObject);
1616 tbm_bo_unref(pPixmapInfo->pTbmBufferObject);
1620 tbm_bufmgr_deinit(pPixmapInfo->pTbmBufMgr);
1624 close(pPixmapInfo->drmFd);
1628 DRI2DestroyDrawable(pNativeDisplay, pPixmapInfo->nativePixmap);
1629 XFreePixmap(pNativeDisplay, pPixmapInfo->nativePixmap);
1638 SysLog(NID_GRP, "_CreateNativePixmap failed!! pBitmap:%#x", (unsigned int)pBitmap);
1639 return (EGLNativePixmapType)0;
1643 _SglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* pAttribList)
1645 _SglIndex sglIndex = INVALID_SGL_INDEX;
1646 Tizen::Graphics::Bitmap* pBitmap = dynamic_cast<Tizen::Graphics::Bitmap*>((Tizen::Graphics::Bitmap*)pixmap);
1647 EGLNativePixmapType eglNativePixmap = 0;
1648 EGLSurface pixmapSurface = EGL_NO_SURFACE;
1649 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1651 if (pBitmap == null)
1656 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1657 if (sglIndex <= INVALID_SGL_INDEX)
1662 eglNativePixmap = _CreateNativePixmap(sglIndex, pBitmap);
1663 if (eglNativePixmap == 0)
1668 pixmapSurface = eglCreatePixmapSurface(dpy, config, eglNativePixmap, pAttribList);
1669 if (pixmapSurface == EGL_NO_SURFACE)
1671 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1676 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1678 pSglInfo->nativePixmap = eglNativePixmap;
1679 pSglInfo->surface = pixmapSurface;
1681 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1684 return (EGLSurface)sglIndex;
1687 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1691 SysLog(NID_GRP, "_SglCreatePixmapSurface failed!! dpy:%#x config:%#x pixmap:%#x pAttribList:%#x",
1692 (unsigned int)dpy, (unsigned int)config, (unsigned int)pixmap, (unsigned int)pAttribList);
1693 return eglCreatePixmapSurface(EGL_NO_DISPLAY, config, (EGLNativePixmapType) 0, pAttribList);
1697 _SglDestroySurface(EGLDisplay dpy, EGLSurface surface)
1699 EGLBoolean ret = EGL_FALSE;
1700 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1702 _SglIndex sglIndex = (_SglIndex)surface;
1703 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1705 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1707 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1708 SysLog(NID_GRP, "_SglDestroySurface failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
1709 , (unsigned int)surface);
1710 return eglDestroySurface(dpy, EGL_NO_SURFACE);
1713 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1714 if (pSglInfo == __pPreviousSglInfo || pSglInfo->pSecondSglInfo == __pPreviousSglInfo)
1716 __pPreviousSglInfo = null;
1720 ret = eglDestroySurface(dpy, pSglInfo->surface);
1721 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1723 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
1725 eglDestroySurface(dpy, pSglInfo->pSecondSglInfo->surface);
1726 pSglInfoTableManipulatorInstance->DestroySglIndex(pSglInfo->pSecondSglInfo->sglIndex);
1729 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1735 _SglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* pValue)
1737 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1739 _SglIndex sglIndex = (_SglIndex)surface;
1740 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1742 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1744 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1745 SysLog(NID_GRP, "_SglQuerySurface failed!! dpy:%#x sglIndex:%#x attribute:%#x pValue:%#x",
1746 (unsigned int)dpy, (unsigned int)sglIndex, (unsigned int)attribute, (unsigned int)pValue);
1747 return eglQuerySurface(dpy, EGL_NO_SURFACE, attribute, pValue);
1750 EGLBoolean ret = EGL_FALSE;
1751 if (attribute == EGL_BITMAP_POINTER_KHR)
1753 *pValue = (EGLint)pSglInfo->pBitmapPointer;
1758 ret = eglQuerySurface(dpy, pSglInfo->surface, attribute, pValue);
1761 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1767 _SglBindAPI(EGLenum api)
1769 return eglBindAPI(api);
1775 return eglQueryAPI();
1781 return eglWaitClient();
1785 _SglReleaseThread(void)
1787 return eglReleaseThread();
1791 _SglCreatePbufferFromClientBuffer(
1792 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint* pAttribList)
1794 _SglIndex sglIndex = INVALID_SGL_INDEX;
1795 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1797 sglIndex = pSglInfoTableManipulatorInstance->CreateSglIndex();
1798 if (sglIndex <= INVALID_SGL_INDEX)
1800 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!!"
1801 " dpy:%#x buftype:%#x buffer:%#x config:%#x pAttribList:%#x",
1802 (unsigned int)dpy, (unsigned int)buftype, (unsigned int)buffer, (unsigned int)config, (unsigned int)pAttribList);
1804 return eglCreatePbufferFromClientBuffer(null, (EGLenum)0, null, null, null);
1807 EGLSurface pbufferFromClientBuffer = eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, pAttribList);
1808 if (pbufferFromClientBuffer == EGL_NO_SURFACE)
1810 pSglInfoTableManipulatorInstance->DestroySglIndex(sglIndex);
1815 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1817 pSglInfo->surface = pbufferFromClientBuffer;
1819 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1822 return (EGLSurface)sglIndex;
1826 _SglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1828 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1830 _SglIndex sglIndex = (_SglIndex)surface;
1831 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1833 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1835 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1836 SysLog(NID_GRP, "_SglCreatePbufferFromClientBuffer failed!! "
1837 "dpy:%#x surface:%#x attribute:%#x value:%#x",
1838 (unsigned int)dpy, (unsigned int)surface, (unsigned int)attribute, (unsigned int)value);
1840 return eglSurfaceAttrib(dpy, EGL_NO_SURFACE, attribute, value);
1843 EGLBoolean ret = eglSurfaceAttrib(dpy, pSglInfo->surface, attribute, value);
1844 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1850 _SglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1852 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1854 _SglIndex sglIndex = (_SglIndex)surface;
1855 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1857 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1859 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1860 SysLog(NID_GRP, "_SglBindTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1861 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1863 return eglBindTexImage(dpy, EGL_NO_SURFACE, buffer);
1866 EGLBoolean ret = eglBindTexImage(dpy, pSglInfo->surface, buffer);
1867 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1873 _SglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1875 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1877 _SglIndex sglIndex = (_SglIndex)surface;
1878 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
1880 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
1882 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1883 SysLog(NID_GRP, "_SglReleaseTexImage failed!! dpy:%#x surface:%#x buffer:%#x",
1884 (unsigned int)dpy, (unsigned int)surface, (unsigned int)buffer);
1886 return eglReleaseTexImage(dpy, EGL_NO_SURFACE, buffer);
1889 EGLBoolean ret = eglReleaseTexImage(dpy, pSglInfo->surface, buffer);
1890 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1896 _SglSwapInterval(EGLDisplay dpy, EGLint interval)
1898 return eglSwapInterval(dpy, interval);
1902 _SglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareContext, const EGLint* pAttribList)
1904 return eglCreateContext(dpy, config, shareContext, pAttribList);
1908 _SglDestroyContext(EGLDisplay dpy, EGLContext ctx)
1910 return eglDestroyContext(dpy, ctx);
1914 _SglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
1916 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
1918 _SglIndex sglIndexDraw = (_SglIndex)draw;
1919 _SglIndex sglIndexRead = (_SglIndex)read;
1921 EGLSurface sglInfoReadSurface;
1923 _SglInfo* sglInfoRead = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexRead);
1925 if (sglInfoRead == null)
1927 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1928 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1929 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1930 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1932 sglInfoReadSurface = sglInfoRead->surface;
1934 if (__isDoublePixmapEnabled && !sglInfoRead->isBackbuffer && sglInfoRead->pSecondSglInfo != null)
1936 sglInfoReadSurface = sglInfoRead->pSecondSglInfo->surface;
1939 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1942 _SglInfo* pSglInfoDraw = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndexDraw);
1943 if (pSglInfoDraw == null)
1945 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1946 SysLog(NID_GRP, "_SglMakeCurrent failed!! dpy:%#x draw:%#x read:%#x ctx:%#x",
1947 (unsigned int)dpy, (unsigned int)draw, (unsigned int)read, (unsigned int)ctx);
1948 return eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
1951 if (__isDoublePixmapEnabled && !pSglInfoDraw->isBackbuffer && pSglInfoDraw->pSecondSglInfo != null)
1953 pSglInfoDraw = pSglInfoDraw->pSecondSglInfo;
1956 pSglInfoDraw->context = ctx;
1958 EGLBoolean ret = eglMakeCurrent(dpy, pSglInfoDraw->surface, sglInfoReadSurface, ctx);
1960 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
1961 if (draw != EGL_NO_SURFACE)
1963 _SaveCurrentContext(pSglInfoDraw);
1967 if (pSglInfoDraw->glVersion == 0 && ctx != EGL_NO_CONTEXT)
1969 eglQueryContext(dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &pSglInfoDraw->glVersion);
1972 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
1978 _SglGetCurrentContext()
1980 return eglGetCurrentContext();
1984 _SglGetCurrentSurface(EGLint readDraw)
1986 EGLSurface surface = EGL_NO_SURFACE;
1987 _SglIndex sglIndex = INVALID_SGL_INDEX;
1989 surface = eglGetCurrentSurface(readDraw);
1990 sglIndex = _SglInfoTableManipulator::GetInstance()->GetSglIndexForSurface(surface);
1992 if (sglIndex < INVALID_SGL_INDEX)
1994 SysLog(NID_GRP, "_SglGetCurrentSurface failed!! readDraw:%#x", (unsigned int)readDraw);
1995 return EGL_NO_SURFACE;
1998 return (EGLSurface)sglIndex;
2002 _SglGetCurrentDisplay(void)
2004 return eglGetCurrentDisplay();
2008 _SglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* pValue)
2010 return eglQueryContext(dpy, ctx, attribute, pValue);
2020 _SglWaitNative(EGLint engine)
2022 return eglWaitNative(engine);
2025 EGLBoolean _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface);
2028 _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
2030 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2032 _SglIndex sglIndex = (_SglIndex)surface;
2033 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2035 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2037 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2038 SysLog(NID_GRP, "_SglSwapBuffers failed!! dpy:%#x sglIndex:%#x", (unsigned int)dpy
2039 , (unsigned int)sglIndex);
2041 return eglSwapBuffers(dpy, EGL_NO_SURFACE);
2044 if (pSglInfo->pBitmap != null)
2046 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2047 _SglUpdateBufferOSP(dpy, surface);
2049 if(__evasEngineType == ENGINE_TYPE_OPENGL_X11)
2051 if (pSglInfo->glVersion == 1)
2066 if(__evasEngineType == ENGINE_TYPE_SOFEWARE_X11 || __evasEngineType == ENGINE_TYPE_OPENGL_X11)
2068 if (__isDoublePixmapEnabled && pSglInfo->pSecondSglInfo != null)
2070 if (pSglInfo->swapDone || pSglInfo->pSecondSglInfo->swapDone)
2072 _SglInfo* pBackSglInfo = null;
2073 _SglInfo* pFrontSglInfo = null;
2075 if (pSglInfo->isBackbuffer)
2077 pBackSglInfo = pSglInfo;
2078 pFrontSglInfo = pSglInfo->pSecondSglInfo;
2082 pBackSglInfo = pSglInfo->pSecondSglInfo;
2083 pFrontSglInfo = pSglInfo;
2086 pFrontSglInfo->swapDone = false;
2088 if (pSglInfo->pVisualElement != null)
2090 pSglInfo->pVisualElement->SetSurface(pFrontSglInfo->pVisualElementSurface);
2092 evas_object_image_pixels_dirty_set(pFrontSglInfo->pObject, EINA_TRUE);
2093 evas_object_hide(pBackSglInfo->pObject);
2095 if (pSglInfo->isFirstSwap)
2097 pBackSglInfo->isFirstSwap = false;
2098 pFrontSglInfo->isFirstSwap = false;
2101 BufferInfo bufferInfo;
2102 pFrontSglInfo->pBitmap->Lock(bufferInfo);
2103 pFrontSglInfo->pBitmap->Merge(Point(0, 0), *pBackSglInfo->pBitmap, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
2104 pFrontSglInfo->pBitmap->Unlock();
2110 if (pSglInfo->pObject != null)
2112 evas_object_image_pixels_dirty_set(pSglInfo->pObject, EINA_TRUE);
2118 if (pSglInfo->pVisualElement != null)
2120 pSglInfo->pVisualElement->SetFlushNeeded();
2125 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2130 EGLBoolean ret = eglSwapBuffers(dpy, pSglInfo->surface);
2131 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2138 _SglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
2140 Tizen::Graphics::Bitmap* pBitmap = (Tizen::Graphics::Bitmap*)target;
2141 EGLNativePixmapType nativePixmap = _CreateNativePixmap((_SglIndex)surface, pBitmap);
2142 return eglCopyBuffers(dpy, surface, nativePixmap);
2145 typedef void (*__EglMustCastToProperFunctionPointerType)(void);
2147 EGLBoolean _SglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list)
2149 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2151 _SglIndex sglIndex = (_SglIndex)surface;
2152 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2154 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null || pSglInfo->pBitmap == null || pSglInfo->pBitmapLocked != null)
2156 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2157 SysLog(NID_GRP, "_SglLockSurfaceKHR failed!! dpy:%#x sglIndex:%#x", (unsigned int)display
2158 , (unsigned int)surface);
2162 _SglInfo* pSglInfoLock = pSglInfo;
2163 BufferInfo bufferInfo;
2164 if(!pSglInfo->isBackbuffer && pSglInfo->pSecondSglInfo != null)
2166 pSglInfoLock = pSglInfo->pSecondSglInfo;
2169 pSglInfoLock->pBitmap->Lock(bufferInfo);
2170 pSglInfo->pBitmapPointer = bufferInfo.pPixels;
2171 pSglInfo->pBitmapLocked = pSglInfoLock->pBitmap;
2172 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2177 EGLBoolean _SglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface)
2179 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2181 _SglIndex sglIndex = (_SglIndex)surface;
2182 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2184 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null || pSglInfo->pBitmap == null || pSglInfo->pBitmapLocked == null)
2186 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2187 SysLog(NID_GRP, "_SglUnlockSurfaceKHR failed!! dpy:%#x sglIndex:%#x", (unsigned int)display
2188 , (unsigned int)surface);
2192 pSglInfo->pBitmapLocked->Unlock();
2193 pSglInfo->pBitmapPointer = null;
2194 pSglInfo->pBitmapLocked = null;
2195 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2200 __EglMustCastToProperFunctionPointerType
2201 _SglGetProcAddress(const char* pProcName)
2203 String name(pProcName);
2205 if (name.CompareTo(String("eglLockSurfaceKHR")) == 0)
2207 return (__EglMustCastToProperFunctionPointerType)_SglLockSurfaceKHR;
2209 else if (name.CompareTo(String("eglUnlockSurfaceKHR")) == 0)
2211 return (__EglMustCastToProperFunctionPointerType)_SglUnlockSurfaceKHR;
2214 return eglGetProcAddress(pProcName);
2218 _SglUpdateBufferOSP(EGLDisplay dpy, EGLSurface surface)
2220 #if defined(FGRAPHICS_INTERNAL_USE_EGLCOPYBUFFER)
2221 Tizen::Graphics::BufferInfo bufferInfo;
2222 _SglInfoTableManipulator* pSglInfoTableManipulatorInstance = _SglInfoTableManipulator::GetInstance();
2224 _SglIndex sglIndex = (_SglIndex)surface;
2225 _SglInfo* pSglInfo = pSglInfoTableManipulatorInstance->LockSglInfoTable(sglIndex);
2227 if (sglIndex <= INVALID_SGL_INDEX || pSglInfo == null)
2229 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2230 SysLog(NID_GRP, "_SglUpdateBufferOSP failed!!");
2234 eglCopyBuffers(dpy, pSglInfo->surface, pSglInfo->nativePixmap);
2235 ecore_x_image_get(pSglInfo->pEcoreImage, (Ecore_X_Drawable)pSglInfo->nativePixmap,
2236 0, 0, 0, 0, pSglInfo->width, pSglInfo->height);
2238 pSglInfoTableManipulatorInstance->UnlockSglInfoTable();
2249 }} // Tizen::Graphics