Minor refactor in SharedPlatformSurface. 89/5389/4
authorKondapally Kalyan <kalyan.kondapally@intel.com>
Tue, 2 Jul 2013 09:57:02 +0000 (12:57 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 8 Jul 2013 21:58:52 +0000 (14:58 -0700)
This patch does the following changes in SharedPlatformSurface:
1)Removes un-necessary code.
2)Use SurfaceAttributes as the key instead of generating a new one
  each time a context is created.
3)Ensure's we always restore previous surface and context correctly.
Change-Id: Ic883dd2ea1e573914cc930b2eda58655989c470e

Source/WebCore/platform/graphics/efl/tizen/SharedPlatformSurfaceTizen.cpp

index fd206de..dbff45b 100755 (executable)
 
 namespace WebCore {
 
-static bool vendorNeedsMakeCurrent()
-{
-    static bool queryDone = false;
-    static bool needsMakeCurrent = true;
-
-    if (!queryDone) {
-        queryDone = true;
-        if (EGLHelper::isVendor("imagination") || EGLHelper::isVendor("mesa") || EGLHelper::isVendor("arm"))
-            needsMakeCurrent = false;
-    }
-
-    return needsMakeCurrent;
-}
-
 class PixmapContextPool {
 protected:
     PixmapContextPool(void);
@@ -70,7 +56,7 @@ public:
     GLPlatformContext* getContext(GLPlatformSurface* surface);
 
 private:
-    typedef HashMap<int, OwnPtr<GLPlatformContext> > PixmapContextMap;
+    typedef HashMap<GLPlatformSurface::SurfaceAttributes, OwnPtr<GLPlatformContext> > PixmapContextMap;
     PixmapContextMap m_pixmapContexts;
 };
 
@@ -86,18 +72,13 @@ PixmapContextPool::~PixmapContextPool()
 GLPlatformContext* PixmapContextPool::getContext(GLPlatformSurface* surface)
 {
     GLPlatformSurface::SurfaceAttributes attributes = surface->attributes();
-    bool hasAlpha = attributes & GLPlatformSurface::SupportAlpha;
-    bool hasDepth = attributes & GLPlatformSurface::SupportDepth;
-    bool hasStencil = attributes & GLPlatformSurface::SupportStencil;
-    bool isLockable = attributes & GLPlatformSurface::Lockable;
-    int contextId = ((isLockable) | (hasAlpha << 1) | (hasDepth << 2) | (hasStencil << 3));
-    GLPlatformContext* pixmapContext = m_pixmapContexts.get(contextId);
+    GLPlatformContext* pixmapContext = m_pixmapContexts.get(attributes);
 
     if (!pixmapContext) {
         OwnPtr<GLPlatformContext> context = GLPlatformContext::createContext(GraphicsContext3D::RenderOffscreen);
         if (context && context->initialize(surface)) {
             pixmapContext = context.get();
-            m_pixmapContexts.add(contextId, context.release());
+            m_pixmapContexts.add(attributes, context.release());
         } else
             pixmapContext = 0;
     }
@@ -115,19 +96,7 @@ PassOwnPtr<SharedPlatformSurfaceTizen> SharedPlatformSurfaceTizen::create(const
 
 bool SharedPlatformSurfaceTizen::supportsLockSurfaceExtension()
 {
-    static bool extSupportQueried = false;
-    static bool supportLockSurfaceExt = false;
-
-    if (extSupportQueried)
-        return supportLockSurfaceExt;
-
-    extSupportQueried = true;
-    EGLDisplay display = EGLHelper::currentDisplay();
-
-    if (display == EGL_NO_DISPLAY)
-        return false;
-
-    supportLockSurfaceExt = GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_lock_surface");
+    static bool supportLockSurfaceExt = GLPlatformContext::supportsEGLExtension(EGLHelper::currentDisplay(), "EGL_KHR_lock_surface");
     return supportLockSurfaceExt;
 }
 
@@ -140,10 +109,26 @@ SharedPlatformSurfaceTizen::SharedPlatformSurfaceTizen(const IntSize& size)
 
 SharedPlatformSurfaceTizen::~SharedPlatformSurfaceTizen()
 {
-    if (m_offScreenSurface) {
-        m_offScreenContext->releaseCurrent();
+    if (!m_offScreenSurface)
+        return;
+
+    GLPlatformContext* previousContext = GLPlatformContext::getCurrent();
+    GLPlatformSurface* previousSurface = GLPlatformSurface::getCurrent();
+    if (previousSurface == m_offScreenSurface.get())
+        previousSurface = 0;
+
+    if (makeContextCurrent()) {
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        glBindTexture(GL_TEXTURE_2D, 0);
         m_offScreenSurface->destroy();
+        if (!previousContext || !previousSurface) {
+            m_offScreenContext->releaseCurrent();
+            return;
+        }
     }
+
+    if (previousContext && previousSurface)
+        previousContext->makeCurrent(previousSurface);
 }
 
 bool SharedPlatformSurfaceTizen::initialize(GLPlatformSurface::SurfaceAttributes attributes)
@@ -184,7 +169,8 @@ bool SharedPlatformSurfaceTizen::makeContextCurrent()
 
 bool SharedPlatformSurfaceTizen::lockSurface()
 {
-    if (vendorNeedsMakeCurrent())
+    static bool needsMakeCurrent = !(EGLHelper::isVendor("imagination") || EGLHelper::isVendor("mesa") || EGLHelper::isVendor("arm"));
+    if (needsMakeCurrent)
         makeContextCurrent();
 
     return m_offScreenSurface->lockSurface();