Implement EGL Lock Surface extension runtime check 35/3335/1
authorKalyan Kondapally <kalyan.kondapally@intel.com>
Tue, 16 Apr 2013 11:05:33 +0000 (14:05 +0300)
committerMikko Ylinen <mikko.ylinen@intel.com>
Tue, 16 Apr 2013 11:05:33 +0000 (14:05 +0300)
mesa does not support EGL Lock Surface extension which causes webpage rendering
to fail if ENABLE_TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE is enabled.

ENABLE_TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE is still needed for
HW accelerated video and WebGL. With this patch,
ENABLE_TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE can be enabled and
web pages still render correctly.

Change-Id: I7e0db439896f35ad50f4d3443a229b285f11a737
Signed-off-by: Kalyan Kondapally <kalyan.kondapally@intel.com>
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
Source/WTF/wtf/Platform.h
Source/WebCore/platform/graphics/efl/SharedPlatformSurfaceEfl.cpp
Source/WebCore/platform/graphics/efl/SharedPlatformSurfaceEfl.h
Source/WebKit2/UIProcess/LayerTreeCoordinatorProxy.cpp
Source/WebKit2/UIProcess/WebLayerTreeRenderer.h
Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.cpp

index 8f1fd6d..97f59d9 100755 (executable)
 #define WTF_USE_TIZEN_TEXTURE_MAPPER 1
 #endif
 
-#if ENABLE(TIZEN_WEBKIT2) && ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-#define ENABLE_TIZEN_ACCELERATED_2D_CANVAS_EFL 1 /* Kyungjin Kim(gen.kim@samsung.com), Hyunki Baik(hyunki.baik@samsung.com) : Accelerated 2D Canvas */
-#endif
-#if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
+#if ENABLE(TIZEN_WEBKIT2) && ENABLE(ENABLE_TIZEN_ACCELERATED_2D_CANVAS_EFL)
 #if CPU(ARM)
 #define ENABLE_TIZEN_CANVAS_CAIRO_GLES_RENDERING 1 /* Kyungjin Kim(gen.kim@samsung.com), Hyunki Baik(hyunki.baik@samsung.com) : canvas cairo/GLES rendering */
 #else
index b1f4bfe..ea17e6c 100644 (file)
@@ -36,6 +36,7 @@
 #include <wtf/OwnPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/text/WTFString.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
@@ -345,6 +346,39 @@ PassOwnPtr<SharedPlatformSurfaceEfl> SharedPlatformSurfaceEfl::create(const IntS
     return pixmap.release();
 }
 
+// FIXME: This function needs a better place
+bool SharedPlatformSurfaceEfl::supportsLockSurfaceExtension()
+{
+    static bool extSupportQueried = false;
+    static bool supportLockSurfaceExt = false;
+
+    if (extSupportQueried)
+       return supportLockSurfaceExt;
+
+    extSupportQueried = true;
+    Display* nativeDisplay = 0;
+    EGLDisplay display = eglGetCurrentDisplay();
+
+    if (display == EGL_NO_DISPLAY) {
+       nativeDisplay = XOpenDisplay(0);
+       display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(nativeDisplay));
+       eglInitialize(display, 0, 0);
+    }
+
+    if (display != EGL_NO_DISPLAY) {
+       String rawExtensions = reinterpret_cast<const char*>(eglQueryString(display, EGL_EXTENSIONS));
+       Vector<String> extNames;
+       rawExtensions.lower().split(" ", extNames);
+
+       if (extNames.contains("egl_khr_lock_surface"))
+               supportLockSurfaceExt = true;
+
+       extNames.clear();
+    }
+
+    return supportLockSurfaceExt;
+}
+
 SharedPlatformSurfaceEfl::SharedPlatformSurfaceEfl(const IntSize& size, bool lockable, bool hasAlpha, bool hasDepth, bool hasStencil)
     : m_size(size)
     , m_pixmap(0)
index ce558cd..f9dc4ec 100644 (file)
@@ -39,6 +39,7 @@ class PixmapContextEfl;
 class SharedPlatformSurfaceEfl {
 public:
     static PassOwnPtr<SharedPlatformSurfaceEfl> create(const IntSize&, bool lockable, bool hasAlpha = true, bool hasDepth = true, bool hasStencil = false);
+    static bool supportsLockSurfaceExtension();
     virtual ~SharedPlatformSurfaceEfl();
     bool makeContextCurrent();
 
index db25c4f..3644f5d 100755 (executable)
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
 
+#include <EGL/egl.h>
+#include <X11/Xlib.h>
 
 namespace WebKit {
 
 using namespace WebCore;
 
+// FIXME: This function needs a better place
+static bool supportsLockSurfaceExtension()
+{
+    static bool extSupportQueried = false;
+    static bool supportLockSurfaceExt = false;
+
+    if (extSupportQueried)
+       return supportLockSurfaceExt;
+
+    extSupportQueried = true;
+    Display* nativeDisplay = 0;
+    EGLDisplay display = eglGetCurrentDisplay();
+
+    if (display == EGL_NO_DISPLAY) {
+       nativeDisplay = XOpenDisplay(0);
+       display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(nativeDisplay));
+       eglInitialize(display, 0, 0);
+    }
+
+    if (display != EGL_NO_DISPLAY) {
+       String rawExtensions = reinterpret_cast<const char*>(eglQueryString(display, EGL_EXTENSIONS));
+       Vector<String> extNames;
+       rawExtensions.lower().split(" ", extNames);
+
+       if (extNames.contains("egl_khr_lock_surface"))
+               supportLockSurfaceExt = true;
+
+       extNames.clear();
+    }
+
+    return supportLockSurfaceExt;
+}
+
 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy)
     : m_drawingAreaProxy(drawingAreaProxy)
 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
@@ -53,7 +88,7 @@ LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAr
     : m_drawingAreaProxy(drawingAreaProxy)
 {
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-    WebLayerTreeRenderer* renderer = isGLMode ? new WebLayerTreeRendererTizen(this, drawingAreaProxy) : new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode);
+    WebLayerTreeRenderer* renderer = (isGLMode && supportsLockSurfaceExtension()) ? new WebLayerTreeRendererTizen(this, drawingAreaProxy) : new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode);
     m_renderer = adoptRef(renderer);
 #else
     m_renderer = adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode));
@@ -109,16 +144,18 @@ void LayerTreeCoordinatorProxy::updateTileForLayer(int layerID, int tileID, cons
 
 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-    dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize)));
-#else
-    dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
+    if (m_renderer->isUsingPlatformSurface())
+       dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize)));
+    else
 #endif
+       dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
 #else
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-    dispatchUpdate(bind(&WebLayerTreeRenderer::updatePlatformSurfaceTile, m_renderer.get(), layerID, tileID, updateInfo.updateRect, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize));
-#else
-    dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
+    if (m_renderer->isUsingPlatformSurface())
+       dispatchUpdate(bind(&WebLayerTreeRenderer::updatePlatformSurfaceTile, m_renderer.get(), layerID, tileID, updateInfo.updateRect, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize));
+    else
 #endif
+       dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
 #endif
 }
 
index 996c54e..2c11c97 100755 (executable)
@@ -73,19 +73,22 @@ public:
         int platformSurfaceID;
         WebCore::IntSize platformSurfaceSize;
         TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset, int pmID, WebCore::IntSize pmSize)
-#else
-        TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset)
-#endif
             : sourceRect(source)
             , targetRect(target)
             , surface(newSurface)
             , offset(newOffset)
-#if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
             , platformSurfaceID(pmID)
             , platformSurfaceSize(pmSize)
-#endif
         {
         }
+#endif
+       TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset)
+           : sourceRect(source)
+           , targetRect(target)
+           , surface(newSurface)
+           , offset(newOffset)
+       {
+        }
     };
     WebLayerTreeRenderer(LayerTreeCoordinatorProxy*);
     virtual ~WebLayerTreeRenderer();
@@ -123,7 +126,6 @@ public:
     void updateTile(WebLayerID, int, const TileUpdate&);
 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
     virtual void updateTileWithUpdateInfo(WebLayerID, int, const TileUpdate&);
-    virtual bool isUsingPlatformSurface() { return false; }
 #endif
     TIZEN_VIRTUAL void flushLayerChanges();
 
@@ -137,6 +139,7 @@ public:
     TIZEN_VIRTUAL void clearBackingStores();
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
+    virtual bool isUsingPlatformSurface() { return false; }
     virtual void freePlatformSurface() { }
     virtual bool hasPlatformSurfaceToFree() { return false; }
 
@@ -283,6 +286,8 @@ public:
     virtual void removeTile(WebLayerID, int);
 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
     virtual void updateTileWithUpdateInfo(WebLayerID, int, const TileUpdate&);
+#endif
+#if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
     virtual bool isUsingPlatformSurface() { return true; }
 #endif
     virtual void flushLayerChanges();
index d453081..70f69a3 100755 (executable)
@@ -32,6 +32,7 @@
 #include "Page.h"
 #include "TextureMapperPlatformLayer.h"
 #include "TiledBackingStoreRemoteTile.h"
+#include "SharedPlatformSurfaceEfl.h"
 #include "WebPage.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/HashMap.h>
@@ -941,6 +942,7 @@ void WebGraphicsLayer::adjustContentsScale()
 
 void WebGraphicsLayer::createBackingStore()
 {
+    if (SharedPlatformSurfaceEfl::supportsLockSurfaceExtension()) {
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
     if (m_webGraphicsLayerClient->isGLAccelerationMode())
@@ -950,9 +952,10 @@ void WebGraphicsLayer::createBackingStore()
 #else
     m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemotePlatformSurfaceTileBackend::create(this)));
 #endif
-#else
-    m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
 #endif
+    } else
+        m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
+
     m_mainBackingStore->setSupportsAlpha(!contentsOpaque());
     m_mainBackingStore->setContentsScale(effectiveContentsScale());
 }