Use GL_EXT_texture_format_BGRA8888 and GL_EXt_unpack_subimage 86/3886/1
authorKondapally Kalyan <kalyan.kondapally@intel.com>
Fri, 7 Jun 2013 00:04:24 +0000 (03:04 +0300)
committerKondapally Kalyan <kalyan.kondapally@intel.com>
Fri, 7 Jun 2013 00:04:24 +0000 (03:04 +0300)
With shared surface support disabled, we would be uploading data
to textures. In this scenario it would be efficient to use
both the above mentioned extensions. This patch adds the needed
support in TextureMapperGL.

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

index f29c35a..f587d32 100755 (executable)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "TextureMapperGL.h"
 
+#include "GLPlatformContext.h"
 #include "GraphicsContext.h"
 #include "Image.h"
 #include "NotImplemented.h"
 #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;
@@ -423,7 +436,7 @@ void TextureMapperGL::drawBorder(const Color& color, float width, const FloatRec
     GL_CMD(glLineWidth(width));
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-       drawQuad(targetRect, modelViewMatrix, program.get(), GL_LINE_LOOP, color.hasAlpha(), true);
+    drawQuad(targetRect, modelViewMatrix, program.get(), GL_LINE_LOOP, color.hasAlpha(), true);
 #else
     drawQuad(targetRect, modelViewMatrix, program.get(), GL_LINE_LOOP, color.hasAlpha());
 #endif
@@ -471,7 +484,7 @@ void TextureMapperGL::drawTexture(const BitmapTexture& texture, const FloatRect&
 
     const BitmapTextureGL& textureGL = static_cast<const BitmapTextureGL&>(texture);
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-       drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, textureGL.size(), true, exposedEdges);
+    drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, textureGL.size(), true, exposedEdges);
 #else
     drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, exposedEdges);
 #endif
@@ -525,7 +538,7 @@ void TextureMapperGL::drawTextureRectangleARB(uint32_t texture, Flags flags, con
     bool needsBlending = (flags & SupportsBlending) || opacity < 0.99 || maskTexture;
     drawQuad(targetRect, modelViewMatrix, program.get(), GL_TRIANGLE_FAN, needsBlending);
 }
-#endif // defined(GL_ARB_texture_rectangle) 
+#endif // defined(GL_ARB_texture_rectangle)
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
 void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const IntSize& platformSurfaceSize, bool premultipliedAlpha, unsigned exposedEdges)
@@ -747,7 +760,7 @@ void TextureMapperGL::drawTexturedQuadWithProgram(TextureMapperShaderProgram* pr
 
     bool needsBlending = (flags & SupportsBlending) || opacity < 0.99;
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-       drawQuad(quadToDraw, modelViewMatrix, program, GL_TRIANGLE_FAN, needsBlending, premultipliedAlpha);
+    drawQuad(quadToDraw, modelViewMatrix, program, GL_TRIANGLE_FAN, needsBlending, premultipliedAlpha);
 #else
     drawQuad(quadToDraw, modelViewMatrix, program, GL_TRIANGLE_FAN, needsBlending);
 #endif
@@ -774,11 +787,13 @@ static void swizzleBGRAToRGBA(uint32_t* data, const IntRect& rect, int stride =
     }
 }
 
+// If GL_EXT_texture_format_BGRA8888 is supported in the OpenGLES
+// internal and external formats need to be BGRA
 static bool driverSupportsBGRASwizzling()
 {
 #if defined(TEXMAP_OPENGL_ES_2)
-    // FIXME: Implement reliable detection. See also https://bugs.webkit.org/show_bug.cgi?id=81103.
-    return false;
+    static bool supportsBGRASwizzling = GLPlatformContext::supportsGLExtension("GL_EXT_texture_format_BGRA8888");
+    return supportsBGRASwizzling;
 #else
     return true;
 #endif
@@ -787,8 +802,8 @@ static bool driverSupportsBGRASwizzling()
 static bool driverSupportsSubImage()
 {
 #if defined(TEXMAP_OPENGL_ES_2)
-    // FIXME: Implement reliable detection.
-    return false;
+    static bool supportsSubImage = GLPlatformContext::supportsGLExtension("GL_EXT_unpack_subimage");
+    return supportsSubImage;
 #else
     return true;
 #endif
@@ -811,7 +826,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 +876,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)