fix bug on OnBoundsChanged
authorSukwon Suh <sukwon.suh@samsung.com>
Wed, 10 Apr 2013 10:31:15 +0000 (19:31 +0900)
committerSukwon Suh <sukwon.suh@samsung.com>
Wed, 10 Apr 2013 11:30:26 +0000 (20:30 +0900)
Change-Id: If920a6ba3f020f4a2b2f6edafb82461356a686f4
Signed-off-by: Sukwon Suh <sukwon.suh@samsung.com>
src/graphics/opengl/FGrpEgl.cpp

index 4bed4bf..70ee234 100644 (file)
@@ -224,6 +224,15 @@ public:
 
                SysTryReturnVoidResult(NID_GRP, pObject != null, E_OPERATION_FAILED, "Invalid object.");
 
+               if (pVisualElement != null)
+               {
+                       _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*pVisualElement);
+                       if (pVisualElementImpl != null)
+                       {
+                               pVisualElementImpl->SetDestroyedCallback(null, null);
+                       }
+               }
+
                bool needAllocateObject = true;
 
 #if defined(FGRAPHICS_INTERNAL_USE_RESTORE_CONTEXT)
@@ -236,6 +245,7 @@ public:
                        {
                                if (!isBackbuffer)
                                {
+                                       evas_object_del(pObject);
                                        delete pVisualElementSurface;
                                        delete pBitmap;
                                        needAllocateObject = false;
@@ -247,6 +257,7 @@ public:
                {
                        if (pVisualElement != null)
                        {
+                               evas_object_del(pObject);
                                delete pVisualElementSurface;
                                pVisualElement->SetSurface(null);
                        }
@@ -354,11 +365,22 @@ _OnBoundsChanged(void* pData)
                __pPreviousSglInfo = null;
        }
 
+       bool needSglMakeCurrent = false;
        EGLDisplay eglDisplay = eglGetCurrentDisplay();
-       EGLSurface readSurface = eglGetCurrentSurface(EGL_READ);
-       EGLSurface drawSurface = eglGetCurrentSurface(EGL_DRAW);
+       EGLSurface drawSurface = _SglGetCurrentSurface(EGL_DRAW);
+       EGLSurface readSurface = _SglGetCurrentSurface(EGL_READ);
        EGLSurface eglContext = eglGetCurrentContext();
 
+       if (drawSurface != EGL_NO_SURFACE && readSurface != EGL_NO_SURFACE)
+       {
+               needSglMakeCurrent = true;
+       }
+       else
+       {
+               drawSurface = eglGetCurrentSurface(EGL_DRAW);
+               readSurface = eglGetCurrentSurface(EGL_READ);
+       }
+
        eglMakeCurrent(pSglInfo->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        EGLBoolean ret = eglDestroySurface(pSglInfo->display, pSglInfo->surface);
        pSglInfo->surface = null;
@@ -368,46 +390,26 @@ _OnBoundsChanged(void* pData)
        int width = int(rect.width);
        int height = int(rect.height);
        SysTryReturnVoidResult(NID_GRP, width > 0 && height > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", width, height);
-
-       Evas* pEvas = evas_object_evas_get(pSglInfo->pObject);
-       Evas_Object* pObject = evas_object_image_filled_add(pEvas);
-       SysTryReturnVoidResult(NID_GRP, pObject != null, E_INVALID_STATE, "Invalid object.");
-
-       delete pSglInfo->pVisualElementSurface;
-       pSglInfo->pVisualElementSurface = null;
-       pSglInfo->pObject = null;
-
        int widthPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalX(rect.width));
        int heightPhysical = static_cast<int> (CoordinateSystem::ConvertToPhysicalY(rect.height));
+       SysTryReturnVoidResult(NID_GRP, widthPhysical > 0 && heightPhysical > 0, E_OUT_OF_RANGE, "Invalid size. w:%d h:%d", widthPhysical, heightPhysical);
 
-       evas_object_image_alpha_set(pObject, EINA_TRUE);
-       evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
-       evas_object_resize(pObject, widthPhysical, heightPhysical);
-       evas_object_hide(pObject);
-
-       VisualElementSurface* pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
-                       *pSglInfo->pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
-       SysTryReturnVoidResult(NID_GRP, pVisualElementSurface != null, E_OPERATION_FAILED, "Creating VisualElementSurface failed.");
+       evas_object_image_size_set(pSglInfo->pObject, widthPhysical, heightPhysical);
+       evas_object_resize(pSglInfo->pObject, widthPhysical, heightPhysical);
 
        delete pSglInfo->pBitmap;
        pSglInfo->pBitmap = null;
-
        std::auto_ptr <Bitmap> bitmap(new (std::nothrow) Bitmap);
        SysTryReturnVoidResult(NID_GRP, bitmap.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
-
        result r = bitmap.get()->Construct(Rectangle(0, 0, width, height));
        SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
-
        EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfo->sglIndex, bitmap.get());
        SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
-
        EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfo->display, pSglInfo->config, nativePixmap, null);
        SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
 
        pSglInfo->nativePixmap = nativePixmap;
        pSglInfo->surface = eglSurface;
-       pSglInfo->pObject = pObject;
-       pSglInfo->pVisualElementSurface = pVisualElementSurface;
        pSglInfo->isBackbuffer = true;
        pSglInfo->wasShown = false;
        pSglInfo->swapDone = false;
@@ -423,58 +425,43 @@ _OnBoundsChanged(void* pData)
                pSglInfoSecond->surface = null;
                SysTryReturnVoidResult(NID_GRP, ret == EGL_TRUE, E_OPERATION_FAILED, "eglDestroySurface failed.");
 
-               delete pSglInfoSecond->pVisualElementSurface;
-               pSglInfoSecond->pVisualElementSurface = null;
-               pSglInfoSecond->pObject = null;
-
-               pObject = evas_object_image_filled_add(pEvas);
-               SysTryReturnVoidResult(NID_GRP, pObject != null, E_INVALID_STATE, "Invalid object.");
-
-               evas_object_image_alpha_set(pObject, EINA_TRUE);
-               evas_object_image_size_set(pObject, widthPhysical, heightPhysical);
-               evas_object_resize(pObject, widthPhysical, heightPhysical);
-               evas_object_hide(pObject);
-
-               pVisualElementSurface = _VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(
-                               *pSglInfo->pWindow->GetDisplayContext(), (Handle)pObject, Dimension(width, height));
-               SysTryReturnVoidResult(NID_GRP, pVisualElementSurface != null, E_OPERATION_FAILED, "Creating VisualElementSurface failed.");
+               evas_object_image_size_set(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
+               evas_object_resize(pSglInfoSecond->pObject, widthPhysical, heightPhysical);
 
                delete pSglInfoSecond->pBitmap;
                pSglInfoSecond->pBitmap = null;
-
                std::auto_ptr <Bitmap> bitmapSecond(new (std::nothrow) Bitmap);
                SysTryReturnVoidResult(NID_GRP, bitmapSecond.get() != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
-
                r = bitmapSecond.get()->Construct(Rectangle(0, 0, width, height));
                SysTryReturnVoidResult(NID_GRP, r == E_SUCCESS, r, "Propagating.");
-
                EGLNativePixmapType nativePixmap = _CreateNativePixmap(pSglInfoSecond->sglIndex, bitmapSecond.get());
                SysTryReturnVoidResult(NID_GRP, nativePixmap != (EGLNativePixmapType)0, E_OPERATION_FAILED, "Propagating.");
-
                EGLSurface eglSurface = eglCreatePixmapSurface(pSglInfoSecond->display, pSglInfoSecond->config, nativePixmap, null);
                SysTryReturnVoidResult(NID_GRP, eglSurface != EGL_NO_SURFACE, E_OPERATION_FAILED, "eglCreatePixmapSurface failed.");
 
                pSglInfoSecond->nativePixmap = nativePixmap;
                pSglInfoSecond->surface = eglSurface;
-               pSglInfoSecond->pObject = pObject;
-               pSglInfoSecond->pVisualElementSurface = pVisualElementSurface;
                pSglInfoSecond->pBitmap = bitmapSecond.release();
                pSglInfoSecond->isBackbuffer = true;
                pSglInfoSecond->wasShown = false;
                pSglInfoSecond->swapDone = true;
+
                pSglInfo->isFirstSwap =  true;
 
                _EvasObjectImageChange(pSglInfoSecond);
        }
-       else
-       {
-               pSglInfo->pVisualElement->SetSurface(pVisualElementSurface);
-       }
 
        pSglInfo->pBitmap = bitmap.release();
        _EvasObjectImageChange(pSglInfo);
 
-       eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
+       if (needSglMakeCurrent)
+       {
+               _SglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
+       }
+       else
+       {
+               eglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
+       }
 
        return;
 }