[Texmap] Remove platform specific code in BitmapImageGL::updateContents by using
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 03:59:30 +0000 (03:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 03:59:30 +0000 (03:59 +0000)
GraphicsContext3D::extractImageData.
https://bugs.webkit.org/show_bug.cgi?id=89867

Patch by Huang Dongsung <luxtella@company100.net> on 2012-06-25
Reviewed by Noam Rosenthal.

No new tests. Covered by existing tests.

* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore):
(WebCore::BitmapTextureGL::didReset):
(WebCore::BitmapTextureGL::updateContents):

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

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

index a99a2a8..3067ec6 100644 (file)
@@ -1,3 +1,18 @@
+2012-06-25  Huang Dongsung  <luxtella@company100.net>
+
+        [Texmap] Remove platform specific code in BitmapImageGL::updateContents by using
+        GraphicsContext3D::extractImageData.
+        https://bugs.webkit.org/show_bug.cgi?id=89867
+
+        Reviewed by Noam Rosenthal.
+
+        No new tests. Covered by existing tests.
+
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore):
+        (WebCore::BitmapTextureGL::didReset):
+        (WebCore::BitmapTextureGL::updateContents):
+
 2012-06-25  James Robinson  <jamesr@chromium.org>
 
         [chromium] Remove uncalled ManagedTexture::framebufferTexture2D
index 6e176e8..8df272c 100644 (file)
@@ -22,6 +22,7 @@
 #include "TextureMapperGL.h"
 
 #include "GraphicsContext.h"
+#include "GraphicsContext3D.h"
 #include "Image.h"
 #include "TextureMapperShaderManager.h"
 #include "Timer.h"
@@ -36,9 +37,8 @@
 #endif
 
 #if PLATFORM(QT)
-#if QT_VERSION >= 0x050000
+#if HAVE(QT5)
 #include <QOpenGLContext>
-#include <qpa/qplatformpixmap.h>
 #else
 #include <QGLContext>
 #endif // QT_VERSION
 #include <GL/glx.h>
 #endif
 
-#if USE(CAIRO)
-#include "CairoUtilities.h"
-#include "RefPtrCairo.h"
-#include <cairo.h>
-#endif
-
 #define GL_CMD(...) do { __VA_ARGS__; ASSERT_ARG(__VA_ARGS__, !glGetError()); } while (0)
 namespace WebCore {
 struct TextureMapperGLData {
@@ -447,26 +441,6 @@ bool BitmapTextureGL::canReuseWith(const IntSize& contentsSize, Flags)
 #define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE GL_UNSIGNED_BYTE
 #endif
 
-static void swizzleBGRAToRGBA(uint32_t* data, const IntRect& rect, int stride = 0)
-{
-    stride = stride ? stride : rect.width();
-    for (int y = rect.y(); y < rect.maxY(); ++y) {
-        uint32_t* p = data + y * stride;
-        for (int x = rect.x(); x < rect.maxX(); ++x)
-            p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
-    }
-}
-
-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;
-#else
-    return true;
-#endif
-}
-
 static bool driverSupportsSubImage()
 {
 #if defined(TEXMAP_OPENGL_ES_2)
@@ -486,30 +460,22 @@ void BitmapTextureGL::didReset()
     if (m_textureSize == contentSize())
         return;
 
-    GLuint format = driverSupportsBGRASwizzling() ? GL_BGRA : GL_RGBA;
-
     m_textureSize = contentSize();
     GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id));
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
     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, GL_RGBA, m_textureSize.width(), m_textureSize.height(), 0, GL_RGBA, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0));
 }
 
 
 void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect, const IntPoint& sourceOffset, int bytesPerLine)
 {
-    GLuint glFormat = GL_RGBA;
     GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id));
 
-    if (driverSupportsBGRASwizzling())
-        glFormat = GL_BGRA;
-    else
-        swizzleBGRAToRGBA(reinterpret_cast<uint32_t*>(const_cast<void*>(data)), IntRect(sourceOffset, targetRect.size()), bytesPerLine / 4);
-
     if (bytesPerLine == targetRect.width() / 4 && sourceOffset == IntPoint::zero()) {
-        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(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));
         return;
     }
 
@@ -527,7 +493,7 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
             dst += targetBytesPerLine;
         }
 
-        GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, temporaryData.data()));
+        GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, temporaryData.data()));
         return;
     }
 
@@ -536,7 +502,7 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
     GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / 4));
     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(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, 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));
@@ -547,31 +513,12 @@ void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, co
 {
     if (!image)
         return;
-    NativeImagePtr frameImage = image->nativeImageForCurrentFrame();
-    if (!frameImage)
-        return;
 
-    int bytesPerLine;
-    const char* imageData;
-
-#if PLATFORM(QT)
-    QImage qtImage;
-#if HAVE(QT5)
-    // With QPA, we can avoid a deep copy.
-    qtImage = *frameImage->handle()->buffer();
-#else
-    // This might be a deep copy, depending on other references to the pixmap.
-    qtImage = frameImage->toImage();
-#endif
-    imageData = reinterpret_cast<const char*>(qtImage.constBits());
-    bytesPerLine = qtImage.bytesPerLine();
-#elif USE(CAIRO)
-    cairo_surface_t* surface = frameImage->surface();
-    imageData = reinterpret_cast<const char*>(cairo_image_surface_get_data(surface));
-    bytesPerLine = cairo_image_surface_get_stride(surface);
-#endif
+    Vector<uint8_t> imageData;
+    GraphicsContext3D::extractImageData(image, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, false /* flipY */, true /* premultiplyAlpha */, false /* ignoreGammaAndColorProfile */, imageData);
 
-    updateContents(imageData, targetRect, offset, bytesPerLine);
+    const unsigned bytesPerPixel = 4;
+    updateContents(imageData.data(), targetRect, offset, image->width() * bytesPerPixel);
 }
 
 #if ENABLE(CSS_FILTERS)