Title: [96118] trunk/Source/WebCore
Revision
96118
Author
[email protected]
Date
2011-09-27 09:28:17 -0700 (Tue, 27 Sep 2011)

Log Message

[Texmap][Qt] Refactor texture-upload to allow direct chunk update
https://bugs.webkit.org/show_bug.cgi?id=68808

Add a function to BitmapTexture for direct pixel updates.
Modify BitmapTextureGL::endPaint to use that function. Since the BGRA
to RGBA swizzling is done inside that function, there's no need for the
RGBA32PremultipliedBuffer class to contain such function. Also,
RGBA32PremultipliedBuffer was renamed to BGRA32PremultipliedBuffer, correcting
an old mistake.

Reviewed by Andreas Kling.

No new tests. Existing tests in LayoutTests/compositing test this.

* platform/graphics/opengl/TextureMapperGL.cpp:
(WebCore::BitmapTextureGL::beginPaint):
(WebCore::BitmapTextureGL::endPaint):
(WebCore::swizzleBGRAToRGBA):
(WebCore::BitmapTextureGL::updateContents):
* platform/graphics/opengl/TextureMapperGL.h:
(WebCore::BGRA32PremultimpliedBuffer::~BGRA32PremultimpliedBuffer):
* platform/graphics/qt/TextureMapperQt.cpp:
(WebCore::BitmapTextureQt::updateContents):
(WebCore::BGRA32PremultimpliedBufferQt::data):
(WebCore::BGRA32PremultimpliedBuffer::create):
* platform/graphics/qt/TextureMapperQt.h:
* platform/graphics/texmap/TextureMapper.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (96117 => 96118)


--- trunk/Source/WebCore/ChangeLog	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/ChangeLog	2011-09-27 16:28:17 UTC (rev 96118)
@@ -1,3 +1,33 @@
+2011-09-27  No'am Rosenthal  <[email protected]>
+
+        [Texmap][Qt] Refactor texture-upload to allow direct chunk update
+        https://bugs.webkit.org/show_bug.cgi?id=68808
+
+        Add a function to BitmapTexture for direct pixel updates.
+        Modify BitmapTextureGL::endPaint to use that function. Since the BGRA
+        to RGBA swizzling is done inside that function, there's no need for the 
+        RGBA32PremultipliedBuffer class to contain such function. Also,
+        RGBA32PremultipliedBuffer was renamed to BGRA32PremultipliedBuffer, correcting
+        an old mistake.
+
+        Reviewed by Andreas Kling.
+
+        No new tests. Existing tests in LayoutTests/compositing test this.
+
+        * platform/graphics/opengl/TextureMapperGL.cpp:
+        (WebCore::BitmapTextureGL::beginPaint):
+        (WebCore::BitmapTextureGL::endPaint):
+        (WebCore::swizzleBGRAToRGBA):
+        (WebCore::BitmapTextureGL::updateContents):
+        * platform/graphics/opengl/TextureMapperGL.h:
+        (WebCore::BGRA32PremultimpliedBuffer::~BGRA32PremultimpliedBuffer):
+        * platform/graphics/qt/TextureMapperQt.cpp:
+        (WebCore::BitmapTextureQt::updateContents):
+        (WebCore::BGRA32PremultimpliedBufferQt::data):
+        (WebCore::BGRA32PremultimpliedBuffer::create):
+        * platform/graphics/qt/TextureMapperQt.h:
+        * platform/graphics/texmap/TextureMapper.h:
+
 2011-09-23  Tor Arne Vestbø  <[email protected]>
 
         [Qt] Fix build against Qt5 after refactor of widgets out of QtGUi

Modified: trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp (96117 => 96118)


--- trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp	2011-09-27 16:28:17 UTC (rev 96118)
@@ -238,6 +238,7 @@
     inline FloatSize relativeSize() const { return m_relativeSize; }
     void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; }
 
+    void updateContents(PixelFormat, const IntRect&, void*);
     void pack()
     {
         // This is currently a stub.
@@ -265,7 +266,7 @@
     FloatSize m_relativeSize;
     bool m_opaque;
     IntSize m_textureSize;
-    RefPtr<RGBA32PremultimpliedBuffer> m_buffer;
+    OwnPtr<BGRA32PremultimpliedBuffer> m_buffer;
     IntRect m_dirtyRect;
     GLuint m_fbo;
     GLuint m_rbo;
@@ -523,7 +524,7 @@
 
 PlatformGraphicsContext* BitmapTextureGL::beginPaint(const IntRect& dirtyRect)
 {
-    m_buffer = RGBA32PremultimpliedBuffer::create();
+    m_buffer = BGRA32PremultimpliedBuffer::create();
     m_dirtyRect = dirtyRect;
     return m_buffer->beginPaint(dirtyRect, m_opaque);
 }
@@ -533,15 +534,62 @@
     if (!m_buffer)
         return;
     m_buffer->endPaint();
+    updateContents(BGRAFormat, m_dirtyRect, m_buffer->data());
     GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
+    m_buffer.clear();
+}
+
 #ifdef TEXMAP_OPENGL_ES_2
-    // FIXME: use shaders for RGBA->BGRA swap if this becomes a performance issue.
-    m_buffer->swapRGB();
-    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirtyRect.x(), m_dirtyRect.y(), m_dirtyRect.width(), m_dirtyRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, m_buffer->data()))
+static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size)
+{
+    int width = size.width();
+    int height = size.height();
+    for (int y = 0; y < height; ++y) {
+        uint32_t* p = data + y * width;
+        for (int x = 0; x < width; ++x)
+            p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
+    }
+}
+#endif
+
+void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits)
+{
+    GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
+#ifdef TEXMAP_OPENGL_ES_2
+    bool shouldSwizzle = false;
+#endif
+
+    GLint glFormat = GL_RGBA;
+    switch (pixelFormat) {
+    case RGBAFormat:
+        glFormat = GL_RGBA;
+        break;
+    case RGBFormat:
+        glFormat = GL_RGB;
+        break;
+    case BGRAFormat:
+#ifdef TEXMAP_OPENGL_ES_2
+        shouldSwizzle = true;
+        glFormat = GL_RGBA;
 #else
-    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirtyRect.x(), m_dirtyRect.y(), m_dirtyRect.width(), m_dirtyRect.height(), GL_BGRA, GL_UNSIGNED_BYTE, m_buffer->data()))
+        glFormat = GL_BGRA;
 #endif
-    m_buffer.clear();
+        break;
+    case BGRFormat:
+#ifdef TEXMAP_OPENGL_ES_2
+        shouldSwizzle = true;
+        glFormat = GL_RGB;
+#else
+        glFormat = GL_BGR;
+#endif
+         break;
+    }
+
+#ifdef TEXMAP_OPENGL_ES_2
+    if (shouldSwizzle)
+        swizzleBGRAToRGBA(static_cast<uint32_t*>(bits), rect.size());
+#endif
+    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits))
 }
 
 void BitmapTextureGL::setContentsToImage(Image* image)

Modified: trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h (96117 => 96118)


--- trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h	2011-09-27 16:28:17 UTC (rev 96118)
@@ -63,14 +63,13 @@
 };
 
 // An offscreen buffer to be rendered by software.
-class RGBA32PremultimpliedBuffer : public RefCounted<RGBA32PremultimpliedBuffer> {
+class BGRA32PremultimpliedBuffer : public RefCounted<BGRA32PremultimpliedBuffer> {
 public:
-    virtual ~RGBA32PremultimpliedBuffer() {}
+    virtual ~BGRA32PremultimpliedBuffer() { }
     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect, bool opaque) = 0;
-    virtual void swapRGB() = 0;
     virtual void endPaint() = 0;
-    virtual const void* data() const = 0;
-    static PassRefPtr<RGBA32PremultimpliedBuffer> create();
+    virtual void* data() = 0;
+    static PassOwnPtr<BGRA32PremultimpliedBuffer> create();
 };
 
 static inline int nextPowerOfTwo(int num)

Modified: trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp (96117 => 96118)


--- trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp	2011-09-27 16:28:17 UTC (rev 96118)
@@ -62,6 +62,21 @@
     m_painter.end();
 }
 
+void BitmapTextureQt::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits)
+{
+    m_painter.begin(&m_pixmap);
+    QImage::Format qtFormat = QImage::Format_ARGB32_Premultiplied;
+    if (pixelFormat == BGRFormat || pixelFormat == RGBFormat)
+        qtFormat = QImage::Format_RGB32;
+    QImage image(static_cast<uchar*>(bits), rect.width(), rect.height(), qtFormat);
+    if (pixelFormat == BGRFormat || pixelFormat == BGRAFormat)
+        image = image.rgbSwapped();
+    m_painter.setCompositionMode(QPainter::CompositionMode_Source);
+    m_painter.drawImage(rect, image);
+    m_painter.end();
+}
+
+
 bool BitmapTextureQt::save(const String& path)
 {
     return m_pixmap.save(path, "PNG");
@@ -214,7 +229,7 @@
 }
 
 #if USE(TEXTURE_MAPPER_GL)
-class RGBA32PremultimpliedBufferQt : public RGBA32PremultimpliedBuffer {
+class BGRA32PremultimpliedBufferQt : public BGRA32PremultimpliedBuffer {
 public:
     virtual PlatformGraphicsContext* beginPaint(const IntRect& rect, bool opaque)
     {
@@ -228,22 +243,17 @@
         return &m_painter;
     }
 
-    void swapRGB()
-    {
-        m_image = m_image.rgbSwapped();
-    }
-
     virtual void endPaint() { m_painter.end(); }
-    virtual const void* data() const { return m_image.constBits(); }
+    virtual void* data() { return m_image.bits(); }
 
 private:
     QPainter m_painter;
     QImage m_image;
 };
 
-PassRefPtr<RGBA32PremultimpliedBuffer> RGBA32PremultimpliedBuffer::create()
+PassOwnPtr<BGRA32PremultimpliedBuffer> BGRA32PremultimpliedBuffer::create()
 {
-    return adoptRef(new RGBA32PremultimpliedBufferQt());
+    return adoptPtr(new BGRA32PremultimpliedBufferQt());
 }
 
 uint64_t uidForImage(Image* image)

Modified: trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.h (96117 => 96118)


--- trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.h	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/platform/graphics/qt/TextureMapperQt.h	2011-09-27 16:28:17 UTC (rev 96118)
@@ -41,6 +41,7 @@
     virtual void pack();
     virtual void unpack();
     virtual bool isPacked() const { return m_isPacked; }
+    virtual void updateContents(PixelFormat, const IntRect&, void* bits);
 
     QPainter* painter() { return &m_painter; }
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h (96117 => 96118)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h	2011-09-27 16:21:37 UTC (rev 96117)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h	2011-09-27 16:28:17 UTC (rev 96118)
@@ -46,6 +46,7 @@
 // A 2D texture that can be the target of software or GL rendering.
 class BitmapTexture  : public RefCounted<BitmapTexture> {
 public:
+    enum PixelFormat { BGRAFormat, RGBAFormat, BGRFormat, RGBFormat };
     BitmapTexture() : m_lockCount(0) {}
     virtual ~BitmapTexture() { }
     virtual void destroy() { }
@@ -66,6 +67,10 @@
 
     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect) = 0;
     virtual void endPaint() = 0;
+
+    // For performance reasons, BitmapTexture might modify the bits directly (swizzle).
+    // Thus, this method is only recommended for buffer update, such as used by WebKit2.
+    virtual void updateContents(PixelFormat, const IntRect&, void* bits) = 0;
     virtual PlatformGraphicsContext* beginPaintMedia()
     {
         return beginPaint(IntRect(0, 0, size().width(), size().height()));
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to