[Title] Use extensions GL_EXT_texture_format_BGRA8888 and GL_EXT_unpack_subimage...
authorKondapally Kalyan <kalyan.kondapally@intel.com>
Wed, 8 May 2013 11:50:42 +0000 (14:50 +0300)
committerKondapally Kalyan <kalyan.kondapally@intel.com>
Wed, 8 May 2013 11:50:42 +0000 (14:50 +0300)
[Issue#] TIVI-641
[Problem] GenX drivers dont support Lock Surface.
[Solution] GenX drivers dont support EGLLockSurface extension and thus Locked surface and shared surface usage had to be disabled
           for IVI. In this sceanrio where we would end up using BitmapTextureGL, it would be efficient to take into use
           GL_EXT_texture_format_BGRA8888 and GL_EXT_unpack_subimage when available. This patch adds support for taking this
           extensions into use as needed.

Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

index f29c35a..a611e8a 100755 (executable)
 #define GL_BGRA 0x80E1
 #endif
 
+#if !defined(GL_UNPACK_ROW_LENGTH)
+#define GL_UNPACK_ROW_LENGTH 0x0CF2
+#endif
+
+#if !defined(GL_UNPACK_SKIP_PIXELS)
+#define GL_UNPACK_SKIP_PIXELS 0x0CF4
+#endif
+
+#if !defined(GL_UNPACK_SKIP_ROWS)
+#define GL_UNPACK_SKIP_ROWS 0x0CF3
+#endif
+
 namespace WebCore {
 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
 static int gAngle = 0;
@@ -774,24 +786,46 @@ static void swizzleBGRAToRGBA(uint32_t* data, const IntRect& rect, int stride =
     }
 }
 
-static bool driverSupportsBGRASwizzling()
+static HashSet<String> parseExtensions(const String& extensionsString)
 {
-#if defined(TEXMAP_OPENGL_ES_2)
-    // FIXME: Implement reliable detection. See also https://bugs.webkit.org/show_bug.cgi?id=81103.
-    return false;
-#else
+    Vector<String> extNames;
+    extensionsString.split(" ", extNames);
+    HashSet<String> splitExtNames;
+    unsigned size = extNames.size();
+    for (unsigned i = 0; i < size; ++i)
+      splitExtNames.add(extNames[i]);
+    extNames.clear();
+
+    return splitExtNames;
+}
+
+static bool supportsGLExtension(const String& name)
+{
+    static HashSet<String> supportedExtensions;
+
+    if (!supportedExtensions.size()) {
+        String rawExtensions = reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS));
+        supportedExtensions = parseExtensions(rawExtensions);
+    }
+
+    if (supportedExtensions.contains(name))
     return true;
-#endif
+
+    return false;
+}
+
+// If GL_EXT_texture_format_BGRA8888 is supported in the OpenGLES
+// internal and external formats need to be BGRA
+static bool driverSupportsBGRASwizzling()
+{
+    static bool supportsBGRASwizzling = supportsGLExtension("GL_EXT_texture_format_BGRA8888");
+    return supportsBGRASwizzling;
 }
 
 static bool driverSupportsSubImage()
 {
-#if defined(TEXMAP_OPENGL_ES_2)
-    // FIXME: Implement reliable detection.
-    return false;
-#else
-    return true;
-#endif
+    static bool supportsSubImage = supportsGLExtension("GL_EXT_unpack_subimage");
+    return supportsSubImage;
 }
 
 void BitmapTextureGL::didReset()
@@ -811,7 +845,7 @@ void BitmapTextureGL::didReset()
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
-    GL_CMD(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureSize.width(), m_textureSize.height(), 0, format, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0));
+    GL_CMD(glTexImage2D(GL_TEXTURE_2D, 0, format, m_textureSize.width(), m_textureSize.height(), 0, format, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0));
 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
     // some graphics driver did not support odd texture size.
     if (m_textureSize.width() % 2)
@@ -861,18 +895,16 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
         GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, temporaryData.data()));
 #endif
         return;
+    } else {
+        // Use the OpenGL sub-image extension, now that we know it's available.
+        GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel));
+        GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, sourceOffset.y()));
+        GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, sourceOffset.x()));
+        GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));
+        GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
+        GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, 0));
+        GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0));
     }
-
-#if !defined(TEXMAP_OPENGL_ES_2)
-    // Use the OpenGL sub-image extension, now that we know it's available.
-    GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel));
-    GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, sourceOffset.y()));
-    GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, sourceOffset.x()));
-    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));
-    GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
-    GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, 0));
-    GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0));
-#endif
 }
 
 void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, const IntPoint& offset)