[GTK] Avoid strstr() when checking (E)GL extensions
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Oct 2016 12:36:06 +0000 (12:36 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Oct 2016 12:36:06 +0000 (12:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161958

Reviewed by Žan Doberšek.

Source/WebCore:

Add static method GLContext::isExtensionSupported() to properly search extenstions in the given extension
list, and use it instead of strstr().

* platform/graphics/GLContext.cpp:
(WebCore::GLContext::isExtensionSupported):
* platform/graphics/GLContext.h:
* platform/graphics/egl/GLContextEGL.cpp:
(WebCore::GLContextEGL::createSurfacelessContext):
* platform/graphics/glx/GLContextGLX.cpp:
(WebCore::hasSGISwapControlExtension):

Source/WebKit2:

Use GLContext::isExtensionSupported() instead of strstr().

* UIProcess/gtk/WaylandCompositor.cpp:
(WebKit::WaylandCompositor::initializeEGL):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207614 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GLContext.cpp
Source/WebCore/platform/graphics/GLContext.h
Source/WebCore/platform/graphics/egl/GLContextEGL.cpp
Source/WebCore/platform/graphics/glx/GLContextGLX.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/gtk/WaylandCompositor.cpp

index 9075865..d8e80a3 100644 (file)
@@ -1,3 +1,21 @@
+2016-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Avoid strstr() when checking (E)GL extensions
+        https://bugs.webkit.org/show_bug.cgi?id=161958
+
+        Reviewed by Žan Doberšek.
+
+        Add static method GLContext::isExtensionSupported() to properly search extenstions in the given extension
+        list, and use it instead of strstr().
+
+        * platform/graphics/GLContext.cpp:
+        (WebCore::GLContext::isExtensionSupported):
+        * platform/graphics/GLContext.h:
+        * platform/graphics/egl/GLContextEGL.cpp:
+        (WebCore::GLContextEGL::createSurfacelessContext):
+        * platform/graphics/glx/GLContextGLX.cpp:
+        (WebCore::hasSGISwapControlExtension):
+
 2016-10-20  Per Arne Vollan  <pvollan@apple.com>
 
         [Win][Direct2D] Implement ImageBufferData::getData.
index cf25b3d..6fda631 100644 (file)
@@ -149,6 +149,22 @@ GLContext* GLContext::current()
     return currentContext()->context();
 }
 
+bool GLContext::isExtensionSupported(const char* extensionList, const char* extension)
+{
+    if (!extensionList)
+        return false;
+
+    ASSERT(extension);
+    int extensionLen = strlen(extension);
+    const char* extensionListPtr = extensionList;
+    while ((extensionListPtr = strstr(extensionListPtr, extension))) {
+        if (extensionListPtr[extensionLen] == ' ' || extensionListPtr[extensionLen] == '\0')
+            return true;
+        extensionListPtr += extensionLen;
+    }
+    return false;
+}
+
 } // namespace WebCore
 
 #endif
index c82f098..b41170b 100644 (file)
@@ -48,6 +48,7 @@ public:
     static std::unique_ptr<GLContext> createOffscreenContext(PlatformDisplay* = nullptr);
     static std::unique_ptr<GLContext> createSharingContext(PlatformDisplay&);
     static GLContext* current();
+    static bool isExtensionSupported(const char* extensionList, const char* extension);
 
     PlatformDisplay& display() const { return m_display; }
 
index ae203b9..1948f2e 100644 (file)
@@ -151,7 +151,7 @@ std::unique_ptr<GLContextEGL> GLContextEGL::createSurfacelessContext(PlatformDis
         return nullptr;
 
     const char* extensions = eglQueryString(display, EGL_EXTENSIONS);
-    if (!strstr(extensions, "EGL_KHR_surfaceless_context") && !strstr(extensions, "EGL_KHR_surfaceless_opengl"))
+    if (!GLContext::isExtensionSupported(extensions, "EGL_KHR_surfaceless_context") && !GLContext::isExtensionSupported(extensions, "EGL_KHR_surfaceless_opengl"))
         return nullptr;
 
     EGLConfig config;
index 0a5b67e..e71c4f2 100644 (file)
@@ -45,8 +45,7 @@ static bool hasSGISwapControlExtension(Display* display)
         return !!glXSwapIntervalSGI;
 
     initialized = true;
-    const char* extensions = glXQueryExtensionsString(display, 0);
-    if (!strstr(extensions, "GLX_SGI_swap_control"))
+    if (!GLContext::isExtensionSupported(glXQueryExtensionsString(display, 0), "GLX_SGI_swap_control"))
         return false;
 
     glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(reinterpret_cast<const unsigned char*>("glXSwapIntervalSGI")));
index d9b7006..485ed1a 100644 (file)
@@ -1,5 +1,17 @@
 2016-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Avoid strstr() when checking (E)GL extensions
+        https://bugs.webkit.org/show_bug.cgi?id=161958
+
+        Reviewed by Žan Doberšek.
+
+        Use GLContext::isExtensionSupported() instead of strstr().
+
+        * UIProcess/gtk/WaylandCompositor.cpp:
+        (WebKit::WaylandCompositor::initializeEGL):
+
+2016-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         Wrong use of EGL_DEPTH_SIZE
         https://bugs.webkit.org/show_bug.cgi?id=155536
 
index 27f780e..a6fb661 100644 (file)
@@ -335,7 +335,7 @@ bool WaylandCompositor::initializeEGL()
         eglDestroyImage = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImage"));
     } else {
         const char* extensions = eglQueryString(PlatformDisplay::sharedDisplay().eglDisplay(), EGL_EXTENSIONS);
-        if (strstr(extensions, "EGL_KHR_image_base")) {
+        if (GLContext::isExtensionSupported(extensions, "EGL_KHR_image_base")) {
             eglCreateImage = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
             eglDestroyImage = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
         }