Title: [110439] trunk/Source/WebCore
Revision
110439
Author
[email protected]
Date
2012-03-12 10:09:35 -0700 (Mon, 12 Mar 2012)

Log Message

[TexMapGL] Pixel-align the transform of textures that fit pixel-for-pixel on the frame buffer.
https://bugs.webkit.org/show_bug.cgi?id=80848

Reviewed by Noam Rosenthal.

When rendering a transformed texture on the screen with a fractional
coordinate with linear filtering, the resulting pixel will be blended from
the texels around this fractional position according to their cover ratio.
This produces a slight blur of pixels which give no benefit when rendering
a texture that isn't scaled.

This patch offsets the transform by rounding the translation part of the
layer's transform to align the result to integer coordinates.
Applying the adjustment on the layer transform makes sure that all the tiles
get the same adjustment.

* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawTexture):
* platform/graphics/texmap/TextureMapperGL.h:
(WebCore::BitmapTextureGL::textureSize):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110438 => 110439)


--- trunk/Source/WebCore/ChangeLog	2012-03-12 17:08:18 UTC (rev 110438)
+++ trunk/Source/WebCore/ChangeLog	2012-03-12 17:09:35 UTC (rev 110439)
@@ -1,5 +1,30 @@
 2012-03-12  Jocelyn Turcotte  <[email protected]>
 
+        [TexMapGL] Pixel-align the transform of textures that fit pixel-for-pixel on the frame buffer.
+        https://bugs.webkit.org/show_bug.cgi?id=80848
+
+        Reviewed by Noam Rosenthal.
+
+        When rendering a transformed texture on the screen with a fractional
+        coordinate with linear filtering, the resulting pixel will be blended from
+        the texels around this fractional position according to their cover ratio.
+        This produces a slight blur of pixels which give no benefit when rendering
+        a texture that isn't scaled.
+
+        This patch offsets the transform by rounding the translation part of the
+        layer's transform to align the result to integer coordinates.
+        Applying the adjustment on the layer transform makes sure that all the tiles
+        get the same adjustment.
+
+        * platform/graphics/qt/GraphicsContext3DQt.cpp:
+        (WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::drawTexture):
+        * platform/graphics/texmap/TextureMapperGL.h:
+        (WebCore::BitmapTextureGL::textureSize):
+
+2012-03-12  Jocelyn Turcotte  <[email protected]>
+
         [TexMapGL] Use textures sized exactly to their contents.
         https://bugs.webkit.org/show_bug.cgi?id=80845
 

Modified: trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp (110438 => 110439)


--- trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-03-12 17:08:18 UTC (rev 110438)
+++ trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-03-12 17:09:35 UTC (rev 110439)
@@ -124,7 +124,8 @@
     if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
         TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
         TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::SupportsBlending : 0);
-        texmapGL->drawTexture(m_context->m_texture, flags, targetRect, matrix, opacity, mask);
+        IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
+        texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity, mask);
         return;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (110438 => 110439)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2012-03-12 17:08:18 UTC (rev 110438)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2012-03-12 17:09:35 UTC (rev 110439)
@@ -313,10 +313,10 @@
         return;
 
     const BitmapTextureGL& textureGL = static_cast<const BitmapTextureGL&>(texture);
-    drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, targetRect, matrix, opacity, mask);
+    drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, mask);
 }
 
-void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture)
+void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture)
 {
     RefPtr<TextureMapperShaderProgram> shaderInfo;
     if (maskTexture)
@@ -332,7 +332,23 @@
     const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
     GL_CMD(glVertexAttribPointer(shaderInfo->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, unitRect))
 
-    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(modelViewMatrix).multiply(TransformationMatrix(
+    TransformationMatrix adjustedModelViewMatrix(modelViewMatrix);
+    // Check if the transformed target rect has the same shape/dimensions as the drawn texture (i.e. translated only).
+    FloatQuad finalQuad = modelViewMatrix.mapQuad(FloatQuad(targetRect));
+    FloatSize finalSize = finalQuad.p3() - finalQuad.p1();
+    if (abs(textureSize.width() - finalSize.width()) < 0.001
+        && abs(textureSize.height() - finalSize.height()) < 0.001
+        && finalQuad.p2().y() == finalQuad.p1().y()
+        && finalQuad.p2().x() == finalQuad.p3().x()
+        && finalQuad.p4().x() == finalQuad.p1().x()
+        && finalQuad.p4().y() == finalQuad.p3().y()) {
+        // Pixel-align the origin of our layer's coordinate system within the frame buffer's
+        // coordinate system to avoid sub-pixel interpolation.
+        adjustedModelViewMatrix.setM41(floor(adjustedModelViewMatrix.m41() + 0.5));
+        adjustedModelViewMatrix.setM42(floor(adjustedModelViewMatrix.m42() + 0.5));
+    }
+
+    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(adjustedModelViewMatrix).multiply(TransformationMatrix(
             targetRect.width(), 0, 0, 0,
             0, targetRect.height(), 0, 0,
             0, 0, 1, 0,

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h (110438 => 110439)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h	2012-03-12 17:08:18 UTC (rev 110438)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h	2012-03-12 17:09:35 UTC (rev 110439)
@@ -49,7 +49,7 @@
 
     // reimps from TextureMapper
     virtual void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
-    virtual void drawTexture(uint32_t texture, Flags, const FloatRect&, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
+    virtual void drawTexture(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture);
     virtual void bindSurface(BitmapTexture* surface);
     virtual void beginClip(const TransformationMatrix&, const FloatRect&);
     virtual void beginPainting();
@@ -82,6 +82,7 @@
     void initializeStencil();
     ~BitmapTextureGL();
     virtual uint32_t id() const { return m_id; }
+    IntSize textureSize() const { return m_textureSize; }
     void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; }
     void updateContents(Image*, const IntRect&, const IntRect&, PixelFormat);
     void updateContents(const void*, const IntRect&);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to