[Chromium] Render surface anti-aliasing.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2011 20:00:58 +0000 (20:00 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Sep 2011 20:00:58 +0000 (20:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66437

Patch by David Reveman <reveman@chromium.org> on 2011-09-07
Reviewed by James Robinson.

Source/WebCore:

Add CCLayerQuad class and CCLayerQuad::Edge subclass to allow
edge computations to be shared between tiled layers and render
surfaces. Move isCCW utility function to FloatQuad class and
add to2dTransform method to TransformationMatrix class. Add
necessary anti-aliasing shaders for render surfaces and use them
to avoid aliased edges.

Tests: compositing/reflections/nested-reflection-transformed.html (existing)

* WebCore.gypi:
* platform/graphics/FloatQuad.cpp:
(WebCore::FloatQuad::isCounterclockwise):
* platform/graphics/FloatQuad.h:
* platform/graphics/chromium/LayerChromium.cpp:
(WebCore::LayerChromium::drawTexturedQuad):
* platform/graphics/chromium/LayerChromium.h:
* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::LayerRendererChromium):
(WebCore::LayerRendererChromium::headsUpDisplayProgram):
(WebCore::LayerRendererChromium::renderSurfaceProgram):
(WebCore::LayerRendererChromium::renderSurfaceProgramAA):
(WebCore::LayerRendererChromium::renderSurfaceMaskProgram):
(WebCore::LayerRendererChromium::renderSurfaceMaskProgramAA):
(WebCore::LayerRendererChromium::tilerProgramSwizzle):
(WebCore::LayerRendererChromium::canvasLayerProgram):
(WebCore::LayerRendererChromium::pluginLayerProgram):
(WebCore::LayerRendererChromium::videoLayerRGBAProgram):
(WebCore::LayerRendererChromium::videoLayerYUVProgram):
(WebCore::LayerRendererChromium::cleanupSharedObjects):
* platform/graphics/chromium/LayerRendererChromium.h:
(WebCore::LayerRendererChromium::sharedGeometryQuad):
* platform/graphics/chromium/ShaderChromium.cpp:
(WebCore::VertexShaderQuad::VertexShaderQuad):
(WebCore::VertexShaderQuad::init):
(WebCore::VertexShaderQuad::getShaderString):
(WebCore::FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA):
(WebCore::FragmentShaderRGBATexAlphaAA::init):
(WebCore::FragmentShaderRGBATexAlphaAA::getShaderString):
(WebCore::FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding):
(WebCore::FragmentTexClampAlphaAABinding::init):
(WebCore::FragmentShaderRGBATexClampAlphaAA::getShaderString):
(WebCore::FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::init):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::getShaderString):
* platform/graphics/chromium/ShaderChromium.h:
(WebCore::VertexShaderQuad::matrixLocation):
(WebCore::VertexShaderQuad::pointLocation):
(WebCore::FragmentShaderRGBATexAlphaAA::alphaLocation):
(WebCore::FragmentShaderRGBATexAlphaAA::samplerLocation):
(WebCore::FragmentShaderRGBATexAlphaAA::edgeLocation):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::alphaLocation):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::samplerLocation):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::maskSamplerLocation):
(WebCore::FragmentShaderRGBATexAlphaMaskAA::edgeLocation):
* platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp:
(WebCore::CCCanvasLayerImpl::draw):
* platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
(WebCore::CCHeadsUpDisplay::draw):
* platform/graphics/chromium/cc/CCLayerQuad.cpp: Added.
(WebCore::CCLayerQuad::Edge::Edge):
(WebCore::CCLayerQuad::CCLayerQuad):
(WebCore::CCLayerQuad::floatQuad):
(WebCore::CCLayerQuad::toFloatArray):
* platform/graphics/chromium/cc/CCLayerQuad.h: Added.
(WebCore::CCLayerQuad::Edge::Edge):
(WebCore::CCLayerQuad::Edge::x):
(WebCore::CCLayerQuad::Edge::y):
(WebCore::CCLayerQuad::Edge::z):
(WebCore::CCLayerQuad::Edge::setX):
(WebCore::CCLayerQuad::Edge::setY):
(WebCore::CCLayerQuad::Edge::setZ):
(WebCore::CCLayerQuad::Edge::set):
(WebCore::CCLayerQuad::Edge::moveX):
(WebCore::CCLayerQuad::Edge::moveY):
(WebCore::CCLayerQuad::Edge::moveZ):
(WebCore::CCLayerQuad::Edge::move):
(WebCore::CCLayerQuad::Edge::scaleX):
(WebCore::CCLayerQuad::Edge::scaleY):
(WebCore::CCLayerQuad::Edge::scaleZ):
(WebCore::CCLayerQuad::Edge::scale):
(WebCore::CCLayerQuad::Edge::intersect):
(WebCore::CCLayerQuad::CCLayerQuad):
(WebCore::CCLayerQuad::left):
(WebCore::CCLayerQuad::top):
(WebCore::CCLayerQuad::right):
(WebCore::CCLayerQuad::bottom):
(WebCore::CCLayerQuad::inflateX):
(WebCore::CCLayerQuad::inflateY):
(WebCore::CCLayerQuad::inflate):
(WebCore::CCLayerQuad::inflateAntiAliasingDistance):
* platform/graphics/chromium/cc/CCPluginLayerImpl.cpp:
(WebCore::CCPluginLayerImpl::draw):
* platform/graphics/chromium/cc/CCRenderSurface.cpp:
(WebCore::CCRenderSurface::draw):
(WebCore::CCRenderSurface::drawLayer):
(WebCore::CCRenderSurface::drawSurface):
* platform/graphics/chromium/cc/CCRenderSurface.h:
* platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:
(WebCore::CCTiledLayerImpl::draw):
(WebCore::CCTiledLayerImpl::drawTiles):
* platform/graphics/chromium/cc/CCTiledLayerImpl.h:
* platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
(WebCore::CCVideoLayerImpl::drawYUV):
(WebCore::CCVideoLayerImpl::drawRGBA):
* platform/graphics/transforms/TransformationMatrix.cpp:
(WebCore::TransformationMatrix::to2dTransform):
* platform/graphics/transforms/TransformationMatrix.h:

LayoutTests:

Update expected results.

* platform/chromium-gpu-linux/compositing/color-matching/image-color-matching-expected.png:
* platform/chromium-gpu-linux/compositing/masks/masked-ancestor-expected.png:
* platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed-expected.png:
* platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed2-expected.png:
* platform/chromium-gpu-linux/compositing/reflections/reflection-in-composited-expected.png:
* platform/chromium-gpu-linux/compositing/scaling/tiled-layer-recursion-expected.png:
* platform/chromium-gpu-linux/media/video-layer-crash-expected.png:
* platform/chromium-gpu-linux/media/video-transformed-expected.png:
* platform/chromium/test_expectations.txt:

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

32 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium-gpu-linux/compositing/color-matching/image-color-matching-expected.png
LayoutTests/platform/chromium-gpu-linux/compositing/masks/masked-ancestor-expected.png
LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed-expected.png
LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed2-expected.png
LayoutTests/platform/chromium-gpu-linux/compositing/reflections/reflection-in-composited-expected.png
LayoutTests/platform/chromium-gpu-linux/compositing/scaling/tiled-layer-recursion-expected.png
LayoutTests/platform/chromium-gpu-linux/media/video-layer-crash-expected.png
LayoutTests/platform/chromium-gpu-linux/media/video-transformed-expected.png
LayoutTests/platform/chromium/test_expectations.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/FloatQuad.cpp
Source/WebCore/platform/graphics/FloatQuad.h
Source/WebCore/platform/graphics/chromium/LayerChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerChromium.h
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
Source/WebCore/platform/graphics/chromium/ShaderChromium.cpp
Source/WebCore/platform/graphics/chromium/ShaderChromium.h
Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp
Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.h
Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp
Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp
Source/WebCore/platform/graphics/transforms/TransformationMatrix.h

index a19f9a7..bcab452 100644 (file)
@@ -1,3 +1,22 @@
+2011-09-07  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Render surface anti-aliasing.
+        https://bugs.webkit.org/show_bug.cgi?id=66437
+
+        Reviewed by James Robinson.
+
+        Update expected results.
+
+        * platform/chromium-gpu-linux/compositing/color-matching/image-color-matching-expected.png:
+        * platform/chromium-gpu-linux/compositing/masks/masked-ancestor-expected.png:
+        * platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed-expected.png:
+        * platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed2-expected.png:
+        * platform/chromium-gpu-linux/compositing/reflections/reflection-in-composited-expected.png:
+        * platform/chromium-gpu-linux/compositing/scaling/tiled-layer-recursion-expected.png:
+        * platform/chromium-gpu-linux/media/video-layer-crash-expected.png:
+        * platform/chromium-gpu-linux/media/video-transformed-expected.png:
+        * platform/chromium/test_expectations.txt:
+
 2011-09-07  Xiaomei Ji  <xji@chromium.org>
 
         Rebaseline after r93935.
index ffd95ef..8c2a693 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/color-matching/image-color-matching-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/color-matching/image-color-matching-expected.png differ
index 811faa5..cdadcdc 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/masks/masked-ancestor-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/masks/masked-ancestor-expected.png differ
index a5d11d1..111d16f 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed-expected.png differ
index 780e535..f8940d7 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed2-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/nested-reflection-transformed2-expected.png differ
index 62b6a81..267ddfa 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/reflection-in-composited-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/reflections/reflection-in-composited-expected.png differ
index 9884dc1..ad308a9 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/compositing/scaling/tiled-layer-recursion-expected.png and b/LayoutTests/platform/chromium-gpu-linux/compositing/scaling/tiled-layer-recursion-expected.png differ
index a9bb667..ba89975 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/media/video-layer-crash-expected.png and b/LayoutTests/platform/chromium-gpu-linux/media/video-layer-crash-expected.png differ
index f824eac..37892b6 100644 (file)
Binary files a/LayoutTests/platform/chromium-gpu-linux/media/video-transformed-expected.png and b/LayoutTests/platform/chromium-gpu-linux/media/video-transformed-expected.png differ
index cc4882d..cb2d4a0 100644 (file)
@@ -3459,6 +3459,15 @@ BUGCR89282 SNOWLEOPARD : fast/forms/range/input-appearance-range.html = IMAGE
 // Strange scrollbar.
 BUGWK63115 : fast/css/font-face-in-shadow-DOM.html = PASS IMAGE+TEXT
 
+BUGWK66437 WIN MAC GPU : compositing/color-matching/image-color-matching.html = IMAGE
+BUGWK66437 WIN MAC GPU : compositing/masks/masked-ancestor.html = IMAGE
+BUGWK66437 WIN MAC GPU : compositing/reflections/nested-reflection-transformed.html = IMAGE
+BUGWK66437 WIN MAC GPU : compositing/reflections/nested-reflection-transformed2.html = IMAGE
+BUGWK66437 WIN MAC GPU : compositing/reflections/reflection-in-composited.html = IMAGE
+BUGWK66437 WIN MAC GPU : compositing/scaling/tiled-layer-recursion.html = IMAGE
+BUGWK66437 WIN MAC GPU : media/video-layer-crash.html = IMAGE
+BUGWK66437 WIN MAC GPU : media/video-transformed.html = IMAGE
+
 // This test ASSERTs in skia since it was added.
 BUGWK63400 LINUX DEBUG : svg/text/svg-zoom-large-value.xhtml = CRASH TEXT
 
index 554cdf8..9e74dc7 100644 (file)
@@ -1,3 +1,119 @@
+2011-09-07  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Render surface anti-aliasing.
+        https://bugs.webkit.org/show_bug.cgi?id=66437
+
+        Reviewed by James Robinson.
+
+        Add CCLayerQuad class and CCLayerQuad::Edge subclass to allow
+        edge computations to be shared between tiled layers and render
+        surfaces. Move isCCW utility function to FloatQuad class and
+        add to2dTransform method to TransformationMatrix class. Add
+        necessary anti-aliasing shaders for render surfaces and use them
+        to avoid aliased edges.
+
+        Tests: compositing/reflections/nested-reflection-transformed.html (existing)
+
+        * WebCore.gypi:
+        * platform/graphics/FloatQuad.cpp:
+        (WebCore::FloatQuad::isCounterclockwise):
+        * platform/graphics/FloatQuad.h:
+        * platform/graphics/chromium/LayerChromium.cpp:
+        (WebCore::LayerChromium::drawTexturedQuad):
+        * platform/graphics/chromium/LayerChromium.h:
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::LayerRendererChromium):
+        (WebCore::LayerRendererChromium::headsUpDisplayProgram):
+        (WebCore::LayerRendererChromium::renderSurfaceProgram):
+        (WebCore::LayerRendererChromium::renderSurfaceProgramAA):
+        (WebCore::LayerRendererChromium::renderSurfaceMaskProgram):
+        (WebCore::LayerRendererChromium::renderSurfaceMaskProgramAA):
+        (WebCore::LayerRendererChromium::tilerProgramSwizzle):
+        (WebCore::LayerRendererChromium::canvasLayerProgram):
+        (WebCore::LayerRendererChromium::pluginLayerProgram):
+        (WebCore::LayerRendererChromium::videoLayerRGBAProgram):
+        (WebCore::LayerRendererChromium::videoLayerYUVProgram):
+        (WebCore::LayerRendererChromium::cleanupSharedObjects):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        (WebCore::LayerRendererChromium::sharedGeometryQuad):
+        * platform/graphics/chromium/ShaderChromium.cpp:
+        (WebCore::VertexShaderQuad::VertexShaderQuad):
+        (WebCore::VertexShaderQuad::init):
+        (WebCore::VertexShaderQuad::getShaderString):
+        (WebCore::FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA):
+        (WebCore::FragmentShaderRGBATexAlphaAA::init):
+        (WebCore::FragmentShaderRGBATexAlphaAA::getShaderString):
+        (WebCore::FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding):
+        (WebCore::FragmentTexClampAlphaAABinding::init):
+        (WebCore::FragmentShaderRGBATexClampAlphaAA::getShaderString):
+        (WebCore::FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::init):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::getShaderString):
+        * platform/graphics/chromium/ShaderChromium.h:
+        (WebCore::VertexShaderQuad::matrixLocation):
+        (WebCore::VertexShaderQuad::pointLocation):
+        (WebCore::FragmentShaderRGBATexAlphaAA::alphaLocation):
+        (WebCore::FragmentShaderRGBATexAlphaAA::samplerLocation):
+        (WebCore::FragmentShaderRGBATexAlphaAA::edgeLocation):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::alphaLocation):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::samplerLocation):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::maskSamplerLocation):
+        (WebCore::FragmentShaderRGBATexAlphaMaskAA::edgeLocation):
+        * platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp:
+        (WebCore::CCCanvasLayerImpl::draw):
+        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
+        (WebCore::CCHeadsUpDisplay::draw):
+        * platform/graphics/chromium/cc/CCLayerQuad.cpp: Added.
+        (WebCore::CCLayerQuad::Edge::Edge):
+        (WebCore::CCLayerQuad::CCLayerQuad):
+        (WebCore::CCLayerQuad::floatQuad):
+        (WebCore::CCLayerQuad::toFloatArray):
+        * platform/graphics/chromium/cc/CCLayerQuad.h: Added.
+        (WebCore::CCLayerQuad::Edge::Edge):
+        (WebCore::CCLayerQuad::Edge::x):
+        (WebCore::CCLayerQuad::Edge::y):
+        (WebCore::CCLayerQuad::Edge::z):
+        (WebCore::CCLayerQuad::Edge::setX):
+        (WebCore::CCLayerQuad::Edge::setY):
+        (WebCore::CCLayerQuad::Edge::setZ):
+        (WebCore::CCLayerQuad::Edge::set):
+        (WebCore::CCLayerQuad::Edge::moveX):
+        (WebCore::CCLayerQuad::Edge::moveY):
+        (WebCore::CCLayerQuad::Edge::moveZ):
+        (WebCore::CCLayerQuad::Edge::move):
+        (WebCore::CCLayerQuad::Edge::scaleX):
+        (WebCore::CCLayerQuad::Edge::scaleY):
+        (WebCore::CCLayerQuad::Edge::scaleZ):
+        (WebCore::CCLayerQuad::Edge::scale):
+        (WebCore::CCLayerQuad::Edge::intersect):
+        (WebCore::CCLayerQuad::CCLayerQuad):
+        (WebCore::CCLayerQuad::left):
+        (WebCore::CCLayerQuad::top):
+        (WebCore::CCLayerQuad::right):
+        (WebCore::CCLayerQuad::bottom):
+        (WebCore::CCLayerQuad::inflateX):
+        (WebCore::CCLayerQuad::inflateY):
+        (WebCore::CCLayerQuad::inflate):
+        (WebCore::CCLayerQuad::inflateAntiAliasingDistance):
+        * platform/graphics/chromium/cc/CCPluginLayerImpl.cpp:
+        (WebCore::CCPluginLayerImpl::draw):
+        * platform/graphics/chromium/cc/CCRenderSurface.cpp:
+        (WebCore::CCRenderSurface::draw):
+        (WebCore::CCRenderSurface::drawLayer):
+        (WebCore::CCRenderSurface::drawSurface):
+        * platform/graphics/chromium/cc/CCRenderSurface.h:
+        * platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:
+        (WebCore::CCTiledLayerImpl::draw):
+        (WebCore::CCTiledLayerImpl::drawTiles):
+        * platform/graphics/chromium/cc/CCTiledLayerImpl.h:
+        * platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
+        (WebCore::CCVideoLayerImpl::drawYUV):
+        (WebCore::CCVideoLayerImpl::drawRGBA):
+        * platform/graphics/transforms/TransformationMatrix.cpp:
+        (WebCore::TransformationMatrix::to2dTransform):
+        * platform/graphics/transforms/TransformationMatrix.h:
+
 2011-09-06  Oliver Hunt  <oliver@apple.com>
 
         Remove JSObjectWithGlobalObject
index b2a1423..039864b 100644 (file)
             'platform/graphics/chromium/cc/CCHeadsUpDisplay.h',
             'platform/graphics/chromium/cc/CCLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCLayerImpl.h',
+            'platform/graphics/chromium/cc/CCLayerQuad.cpp',
+            'platform/graphics/chromium/cc/CCLayerQuad.h',
             'platform/graphics/chromium/cc/CCLayerSorter.cpp',
             'platform/graphics/chromium/cc/CCLayerSorter.h',
             'platform/graphics/chromium/cc/CCLayerTilingData.cpp',
index d1069fb..833fa44 100644 (file)
@@ -102,4 +102,11 @@ bool FloatQuad::containsQuad(const FloatQuad& other) const
     return containsPoint(other.p1()) && containsPoint(other.p2()) && containsPoint(other.p3()) && containsPoint(other.p4());
 }
 
+bool FloatQuad::isCounterclockwise() const
+{
+    FloatPoint v1 = FloatPoint(m_p2.x() - m_p1.x(), m_p2.y() - m_p1.y());
+    FloatPoint v2 = FloatPoint(m_p3.x() - m_p2.x(), m_p3.y() - m_p2.y());
+    return (v1.x() * v2.y() - v1.y() * v2.x()) < 0;
+}
+
 } // namespace WebCore
index fa7ba89..b5e2a8c 100644 (file)
@@ -118,6 +118,10 @@ public:
         m_p4.scale(dx, dy);
     }
 
+    // Tests whether points are in clock-wise, or counter clock-wise order.
+    // Note that output is undefined when all points are colinear.
+    bool isCounterclockwise() const;
+
 private:
     FloatPoint m_p1;
     FloatPoint m_p2;
index 258edbe..bcd4d77 100644 (file)
@@ -342,8 +342,8 @@ void LayerChromium::pushPropertiesTo(CCLayerImpl* layer)
 }
 
 void LayerChromium::drawTexturedQuad(GraphicsContext3D* context, const TransformationMatrix& projectionMatrix, const TransformationMatrix& drawMatrix,
-                                     float width, float height, float opacity,
-                                     int matrixLocation, int alphaLocation)
+                                     float width, float height, float opacity, const FloatQuad& quad,
+                                     int matrixLocation, int alphaLocation, int quadLocation)
 {
     static float glMatrix[16];
 
@@ -357,6 +357,19 @@ void LayerChromium::drawTexturedQuad(GraphicsContext3D* context, const Transform
 
     GLC(context, context->uniformMatrix4fv(matrixLocation, false, &glMatrix[0], 1));
 
+    if (quadLocation != -1) {
+        float point[8];
+        point[0] = quad.p1().x();
+        point[1] = quad.p1().y();
+        point[2] = quad.p2().x();
+        point[3] = quad.p2().y();
+        point[4] = quad.p3().x();
+        point[5] = quad.p3().y();
+        point[6] = quad.p4().x();
+        point[7] = quad.p4().y();
+        GLC(context, context->uniform2fv(quadLocation, point, 4));
+    }
+
     if (alphaLocation != -1)
         GLC(context, context->uniform1f(alphaLocation, opacity));
 
index b7d4a2c..b6afc6f 100644 (file)
@@ -177,8 +177,8 @@ public:
     void setBorderWidth(float);
 
     static void drawTexturedQuad(GraphicsContext3D*, const TransformationMatrix& projectionMatrix, const TransformationMatrix& layerMatrix,
-                                 float width, float height, float opacity,
-                                 int matrixLocation, int alphaLocation);
+                                 float width, float height, float opacity, const FloatQuad&,
+                                 int matrixLocation, int alphaLocation, int quadLocation);
 
     virtual void pushPropertiesTo(CCLayerImpl*);
 
index 4519ded..11465dc 100644 (file)
@@ -165,6 +165,7 @@ LayerRendererChromium::LayerRendererChromium(CCLayerTreeHost* owner,
     , m_offscreenFramebufferId(0)
     , m_context(context)
     , m_defaultRenderSurface(0)
+    , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f))
 {
 }
 
@@ -625,7 +626,7 @@ const CCHeadsUpDisplay::Program* LayerRendererChromium::headsUpDisplayProgram()
     if (!m_headsUpDisplayProgram)
         m_headsUpDisplayProgram = adoptPtr(new CCHeadsUpDisplay::Program(m_context.get()));
     if (!m_headsUpDisplayProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::headsUpDisplayProgram::initialize", this, 0);
         m_headsUpDisplayProgram->initialize(m_context.get());
     }
     return m_headsUpDisplayProgram.get();
@@ -635,23 +636,45 @@ const CCRenderSurface::Program* LayerRendererChromium::renderSurfaceProgram()
 {
     ASSERT(m_renderSurfaceProgram);
     if (!m_renderSurfaceProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::renderSurfaceProgram::initialize", this, 0);
         m_renderSurfaceProgram->initialize(m_context.get());
     }
     return m_renderSurfaceProgram.get();
 }
 
+const CCRenderSurface::ProgramAA* LayerRendererChromium::renderSurfaceProgramAA()
+{
+    if (!m_renderSurfaceProgramAA)
+        m_renderSurfaceProgramAA = adoptPtr(new CCRenderSurface::ProgramAA(m_context.get()));
+    if (!m_renderSurfaceProgramAA->initialized()) {
+        TRACE_EVENT("LayerRendererChromium::renderSurfaceProgramAA::initialize", this, 0);
+        m_renderSurfaceProgramAA->initialize(m_context.get());
+    }
+    return m_renderSurfaceProgramAA.get();
+}
+
 const CCRenderSurface::MaskProgram* LayerRendererChromium::renderSurfaceMaskProgram()
 {
     if (!m_renderSurfaceMaskProgram)
         m_renderSurfaceMaskProgram = adoptPtr(new CCRenderSurface::MaskProgram(m_context.get()));
     if (!m_renderSurfaceMaskProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::renderSurfaceMaskProgram::initialize", this, 0);
         m_renderSurfaceMaskProgram->initialize(m_context.get());
     }
     return m_renderSurfaceMaskProgram.get();
 }
 
+const CCRenderSurface::MaskProgramAA* LayerRendererChromium::renderSurfaceMaskProgramAA()
+{
+    if (!m_renderSurfaceMaskProgramAA)
+        m_renderSurfaceMaskProgramAA = adoptPtr(new CCRenderSurface::MaskProgramAA(m_context.get()));
+    if (!m_renderSurfaceMaskProgramAA->initialized()) {
+        TRACE_EVENT("LayerRendererChromium::renderSurfaceMaskProgramAA::initialize", this, 0);
+        m_renderSurfaceMaskProgramAA->initialize(m_context.get());
+    }
+    return m_renderSurfaceMaskProgramAA.get();
+}
+
 const CCTiledLayerImpl::Program* LayerRendererChromium::tilerProgram()
 {
     ASSERT(m_tilerProgram);
@@ -662,17 +685,6 @@ const CCTiledLayerImpl::Program* LayerRendererChromium::tilerProgram()
     return m_tilerProgram.get();
 }
 
-const CCTiledLayerImpl::ProgramSwizzle* LayerRendererChromium::tilerProgramSwizzle()
-{
-    if (!m_tilerProgramSwizzle)
-        m_tilerProgramSwizzle = adoptPtr(new CCTiledLayerImpl::ProgramSwizzle(m_context.get()));
-    if (!m_tilerProgramSwizzle->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::tilerProgramSwizzle::initialize", this, 0);
-        m_tilerProgramSwizzle->initialize(m_context.get());
-    }
-    return m_tilerProgramSwizzle.get();
-}
-
 const CCTiledLayerImpl::ProgramAA* LayerRendererChromium::tilerProgramAA()
 {
     if (!m_tilerProgramAA)
@@ -684,6 +696,17 @@ const CCTiledLayerImpl::ProgramAA* LayerRendererChromium::tilerProgramAA()
     return m_tilerProgramAA.get();
 }
 
+const CCTiledLayerImpl::ProgramSwizzle* LayerRendererChromium::tilerProgramSwizzle()
+{
+    if (!m_tilerProgramSwizzle)
+        m_tilerProgramSwizzle = adoptPtr(new CCTiledLayerImpl::ProgramSwizzle(m_context.get()));
+    if (!m_tilerProgramSwizzle->initialized()) {
+        TRACE_EVENT("LayerRendererChromium::tilerProgramSwizzle::initialize", this, 0);
+        m_tilerProgramSwizzle->initialize(m_context.get());
+    }
+    return m_tilerProgramSwizzle.get();
+}
+
 const CCTiledLayerImpl::ProgramSwizzleAA* LayerRendererChromium::tilerProgramSwizzleAA()
 {
     if (!m_tilerProgramSwizzleAA)
@@ -700,7 +723,7 @@ const CCCanvasLayerImpl::Program* LayerRendererChromium::canvasLayerProgram()
     if (!m_canvasLayerProgram)
         m_canvasLayerProgram = adoptPtr(new CCCanvasLayerImpl::Program(m_context.get()));
     if (!m_canvasLayerProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::canvasLayerProgram::initialize", this, 0);
         m_canvasLayerProgram->initialize(m_context.get());
     }
     return m_canvasLayerProgram.get();
@@ -711,7 +734,7 @@ const CCPluginLayerImpl::Program* LayerRendererChromium::pluginLayerProgram()
     if (!m_pluginLayerProgram)
         m_pluginLayerProgram = adoptPtr(new CCPluginLayerImpl::Program(m_context.get()));
     if (!m_pluginLayerProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::pluginLayerProgram::initialize", this, 0);
         m_pluginLayerProgram->initialize(m_context.get());
     }
     return m_pluginLayerProgram.get();
@@ -722,7 +745,7 @@ const CCVideoLayerImpl::RGBAProgram* LayerRendererChromium::videoLayerRGBAProgra
     if (!m_videoLayerRGBAProgram)
         m_videoLayerRGBAProgram = adoptPtr(new CCVideoLayerImpl::RGBAProgram(m_context.get()));
     if (!m_videoLayerRGBAProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::videoLayerRGBAProgram::initialize", this, 0);
         m_videoLayerRGBAProgram->initialize(m_context.get());
     }
     return m_videoLayerRGBAProgram.get();
@@ -733,7 +756,7 @@ const CCVideoLayerImpl::YUVProgram* LayerRendererChromium::videoLayerYUVProgram(
     if (!m_videoLayerYUVProgram)
         m_videoLayerYUVProgram = adoptPtr(new CCVideoLayerImpl::YUVProgram(m_context.get()));
     if (!m_videoLayerYUVProgram->initialized()) {
-        TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
+        TRACE_EVENT("LayerRendererChromium::videoLayerYUVProgram::initialize", this, 0);
         m_videoLayerYUVProgram->initialize(m_context.get());
     }
     return m_videoLayerYUVProgram.get();
@@ -752,10 +775,10 @@ void LayerRendererChromium::cleanupSharedObjects()
         m_headsUpDisplayProgram->cleanup(m_context.get());
     if (m_tilerProgram)
         m_tilerProgram->cleanup(m_context.get());
-    if (m_tilerProgramSwizzle)
-        m_tilerProgramSwizzle->cleanup(m_context.get());
     if (m_tilerProgramAA)
         m_tilerProgramAA->cleanup(m_context.get());
+    if (m_tilerProgramSwizzle)
+        m_tilerProgramSwizzle->cleanup(m_context.get());
     if (m_tilerProgramSwizzleAA)
         m_tilerProgramSwizzleAA->cleanup(m_context.get());
     if (m_canvasLayerProgram)
@@ -764,8 +787,12 @@ void LayerRendererChromium::cleanupSharedObjects()
         m_pluginLayerProgram->cleanup(m_context.get());
     if (m_renderSurfaceMaskProgram)
         m_renderSurfaceMaskProgram->cleanup(m_context.get());
+    if (m_renderSurfaceMaskProgramAA)
+        m_renderSurfaceMaskProgramAA->cleanup(m_context.get());
     if (m_renderSurfaceProgram)
         m_renderSurfaceProgram->cleanup(m_context.get());
+    if (m_renderSurfaceProgramAA)
+        m_renderSurfaceProgramAA->cleanup(m_context.get());
     if (m_videoLayerRGBAProgram)
         m_videoLayerRGBAProgram->cleanup(m_context.get());
     if (m_videoLayerYUVProgram)
@@ -774,13 +801,15 @@ void LayerRendererChromium::cleanupSharedObjects()
     m_borderProgram.clear();
     m_headsUpDisplayProgram.clear();
     m_tilerProgram.clear();
-    m_tilerProgramSwizzle.clear();
     m_tilerProgramAA.clear();
+    m_tilerProgramSwizzle.clear();
     m_tilerProgramSwizzleAA.clear();
     m_canvasLayerProgram.clear();
     m_pluginLayerProgram.clear();
     m_renderSurfaceMaskProgram.clear();
+    m_renderSurfaceMaskProgramAA.clear();
     m_renderSurfaceProgram.clear();
+    m_renderSurfaceProgramAA.clear();
     m_videoLayerRGBAProgram.clear();
     m_videoLayerYUVProgram.clear();
     if (m_offscreenFramebufferId)
index f052ed6..0f10366 100644 (file)
@@ -35,6 +35,7 @@
 #if USE(ACCELERATED_COMPOSITING)
 
 #include "ContentLayerChromium.h"
+#include "FloatQuad.h"
 #include "IntRect.h"
 #include "LayerChromium.h"
 #include "VideoLayerChromium.h"
@@ -118,13 +119,16 @@ public:
     const TransformationMatrix& windowMatrix() const { return m_windowMatrix; }
 
     const GeometryBinding* sharedGeometry() const { return m_sharedGeometry.get(); }
+    const FloatQuad& sharedGeometryQuad() const { return m_sharedGeometryQuad; }
     const LayerChromium::BorderProgram* borderProgram();
     const CCHeadsUpDisplay::Program* headsUpDisplayProgram();
     const CCRenderSurface::Program* renderSurfaceProgram();
+    const CCRenderSurface::ProgramAA* renderSurfaceProgramAA();
     const CCRenderSurface::MaskProgram* renderSurfaceMaskProgram();
+    const CCRenderSurface::MaskProgramAA* renderSurfaceMaskProgramAA();
     const CCTiledLayerImpl::Program* tilerProgram();
-    const CCTiledLayerImpl::ProgramSwizzle* tilerProgramSwizzle();
     const CCTiledLayerImpl::ProgramAA* tilerProgramAA();
+    const CCTiledLayerImpl::ProgramSwizzle* tilerProgramSwizzle();
     const CCTiledLayerImpl::ProgramSwizzleAA* tilerProgramSwizzleAA();
     const CCCanvasLayerImpl::Program* canvasLayerProgram();
     const CCPluginLayerImpl::Program* pluginLayerProgram();
@@ -208,6 +212,8 @@ private:
     OwnPtr<CCPluginLayerImpl::Program> m_pluginLayerProgram;
     OwnPtr<CCRenderSurface::MaskProgram> m_renderSurfaceMaskProgram;
     OwnPtr<CCRenderSurface::Program> m_renderSurfaceProgram;
+    OwnPtr<CCRenderSurface::MaskProgramAA> m_renderSurfaceMaskProgramAA;
+    OwnPtr<CCRenderSurface::ProgramAA> m_renderSurfaceProgramAA;
     OwnPtr<CCVideoLayerImpl::RGBAProgram> m_videoLayerRGBAProgram;
     OwnPtr<CCVideoLayerImpl::YUVProgram> m_videoLayerYUVProgram;
 
@@ -221,6 +227,8 @@ private:
     CCRenderSurface* m_defaultRenderSurface;
 
     CCLayerSorter m_layerSorter;
+
+    FloatQuad m_sharedGeometryQuad;
 };
 
 // Setting DEBUG_GL_CALLS to 1 will call glGetError() after almost every GL
index ca1387f..c274b24 100644 (file)
@@ -150,6 +150,41 @@ String VertexShaderPosTexTransform::getShaderString() const
     );
 }
 
+VertexShaderQuad::VertexShaderQuad()
+    : m_matrixLocation(-1)
+    , m_pointLocation(-1)
+{
+}
+
+void VertexShaderQuad::init(GraphicsContext3D* context, unsigned program)
+{
+    m_matrixLocation = context->getUniformLocation(program, "matrix");
+    m_pointLocation = context->getUniformLocation(program, "point");
+    ASSERT(m_matrixLocation != -1 && m_pointLocation != -1);
+}
+
+String VertexShaderQuad::getShaderString() const
+{
+    return SHADER(
+        attribute vec4 a_position;
+        attribute vec2 a_texCoord;
+        uniform mat4 matrix;
+        uniform vec2 point[4];
+        varying vec2 v_texCoord;
+        void main()
+        {
+            vec2 complement = abs(a_texCoord - 1.0);
+            vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
+            pos.xy += (complement.x * complement.y) * point[0];
+            pos.xy += (a_texCoord.x * complement.y) * point[1];
+            pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
+            pos.xy += (complement.x * a_texCoord.y) * point[3];
+            gl_Position = matrix * pos;
+            v_texCoord = pos.xy + vec2(0.5);
+        }
+    );
+}
+
 VertexShaderTile::VertexShaderTile()
     : m_matrixLocation(-1)
     , m_pointLocation(-1)
@@ -247,7 +282,44 @@ String FragmentShaderRGBATexSwizzleAlpha::getShaderString() const
     );
 }
 
-FragmentTexAlphaAABinding::FragmentTexAlphaAABinding()
+FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
+    : m_samplerLocation(-1)
+    , m_alphaLocation(-1)
+    , m_edgeLocation(-1)
+{
+}
+
+void FragmentShaderRGBATexAlphaAA::init(GraphicsContext3D* context, unsigned program)
+{
+    m_samplerLocation = context->getUniformLocation(program, "s_texture");
+    m_alphaLocation = context->getUniformLocation(program, "alpha");
+    m_edgeLocation = context->getUniformLocation(program, "edge");
+
+    ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1);
+}
+
+String FragmentShaderRGBATexAlphaAA::getShaderString() const
+{
+    return SHADER(
+        precision mediump float;
+        varying vec2 v_texCoord;
+        uniform sampler2D s_texture;
+        uniform float alpha;
+        uniform vec3 edge[4];
+        void main()
+        {
+            vec4 texColor = texture2D(s_texture, v_texCoord);
+            vec3 pos = vec3(gl_FragCoord.xy, 1);
+            float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
+            float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
+            float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
+            float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
+            gl_FragColor = texColor * alpha * min(a0, a2) * min(a1, a3);
+        }
+    );
+}
+
+FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
     : m_samplerLocation(-1)
     , m_alphaLocation(-1)
     , m_fragmentTexTransformLocation(-1)
@@ -255,7 +327,7 @@ FragmentTexAlphaAABinding::FragmentTexAlphaAABinding()
 {
 }
 
-void FragmentTexAlphaAABinding::init(GraphicsContext3D* context, unsigned program)
+void FragmentTexClampAlphaAABinding::init(GraphicsContext3D* context, unsigned program)
 {
     m_samplerLocation = context->getUniformLocation(program, "s_texture");
     m_alphaLocation = context->getUniformLocation(program, "alpha");
@@ -265,7 +337,7 @@ void FragmentTexAlphaAABinding::init(GraphicsContext3D* context, unsigned progra
     ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTransformLocation != -1 && m_edgeLocation != -1);
 }
 
-String FragmentShaderRGBATexAlphaAA::getShaderString() const
+String FragmentShaderRGBATexClampAlphaAA::getShaderString() const
 {
     return SHADER(
         precision mediump float;
@@ -288,7 +360,7 @@ String FragmentShaderRGBATexAlphaAA::getShaderString() const
     );
 }
 
-String FragmentShaderRGBATexSwizzleAlphaAA::getShaderString() const
+String FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const
 {
     return SHADER(
         precision mediump float;
@@ -343,6 +415,46 @@ String FragmentShaderRGBATexAlphaMask::getShaderString() const
     );
 }
 
+FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
+    : m_samplerLocation(-1)
+    , m_maskSamplerLocation(-1)
+    , m_alphaLocation(-1)
+    , m_edgeLocation(-1)
+{
+}
+
+void FragmentShaderRGBATexAlphaMaskAA::init(GraphicsContext3D* context, unsigned program)
+{
+    m_samplerLocation = context->getUniformLocation(program, "s_texture");
+    m_maskSamplerLocation = context->getUniformLocation(program, "s_mask");
+    m_alphaLocation = context->getUniformLocation(program, "alpha");
+    m_edgeLocation = context->getUniformLocation(program, "edge");
+    ASSERT(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1);
+}
+
+String FragmentShaderRGBATexAlphaMaskAA::getShaderString() const
+{
+    return SHADER(
+        precision mediump float;
+        varying vec2 v_texCoord;
+        uniform sampler2D s_texture;
+        uniform sampler2D s_mask;
+        uniform float alpha;
+        uniform vec3 edge[4];
+        void main()
+        {
+            vec4 texColor = texture2D(s_texture, v_texCoord);
+            vec4 maskColor = texture2D(s_mask, v_texCoord);
+            vec3 pos = vec3(gl_FragCoord.xy, 1);
+            float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
+            float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
+            float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
+            float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
+            gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w * min(a0, a2) * min(a1, a3);
+        }
+    );
+}
+
 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
     : m_yTextureLocation(-1)
     , m_uTextureLocation(-1)
index 1208d3f..73c1206 100644 (file)
@@ -96,6 +96,21 @@ private:
     int m_texTransformLocation;
 };
 
+class VertexShaderQuad {
+public:
+    VertexShaderQuad();
+
+    void init(GraphicsContext3D*, unsigned program);
+    String getShaderString() const;
+
+    int matrixLocation() const { return m_matrixLocation; }
+    int pointLocation() const { return m_pointLocation; }
+
+private:
+    int m_matrixLocation;
+    int m_pointLocation;
+};
+
 class VertexShaderTile {
 public:
     VertexShaderTile();
@@ -142,9 +157,26 @@ public:
     String getShaderString() const;
 };
 
-class FragmentTexAlphaAABinding {
+class FragmentShaderRGBATexAlphaAA {
+public:
+    FragmentShaderRGBATexAlphaAA();
+
+    void init(GraphicsContext3D*, unsigned program);
+    String getShaderString() const;
+
+    int alphaLocation() const { return m_alphaLocation; }
+    int samplerLocation() const { return m_samplerLocation; }
+    int edgeLocation() const { return m_edgeLocation; }
+
+private:
+    int m_samplerLocation;
+    int m_alphaLocation;
+    int m_edgeLocation;
+};
+
+class FragmentTexClampAlphaAABinding {
 public:
-    FragmentTexAlphaAABinding();
+    FragmentTexClampAlphaAABinding();
 
     void init(GraphicsContext3D*, unsigned program);
     int alphaLocation() const { return m_alphaLocation; }
@@ -159,13 +191,13 @@ private:
     int m_edgeLocation;
 };
 
-class FragmentShaderRGBATexAlphaAA : public FragmentTexAlphaAABinding {
+class FragmentShaderRGBATexClampAlphaAA : public FragmentTexClampAlphaAABinding {
 public:
     String getShaderString() const;
 };
 
 // Swizzles the red and blue component of sampled texel.
-class FragmentShaderRGBATexSwizzleAlphaAA : public FragmentTexAlphaAABinding {
+class FragmentShaderRGBATexClampSwizzleAlphaAA : public FragmentTexClampAlphaAABinding {
 public:
     String getShaderString() const;
 };
@@ -186,6 +218,24 @@ private:
     int m_alphaLocation;
 };
 
+class FragmentShaderRGBATexAlphaMaskAA {
+public:
+    FragmentShaderRGBATexAlphaMaskAA();
+    String getShaderString() const;
+
+    void init(GraphicsContext3D*, unsigned program);
+    int alphaLocation() const { return m_alphaLocation; }
+    int samplerLocation() const { return m_samplerLocation; }
+    int maskSamplerLocation() const { return m_maskSamplerLocation; }
+    int edgeLocation() const { return m_edgeLocation; }
+
+private:
+    int m_samplerLocation;
+    int m_maskSamplerLocation;
+    int m_alphaLocation;
+    int m_edgeLocation;
+};
+
 class FragmentShaderYUVVideo {
 public:
     FragmentShaderYUVVideo();
index 0e75724..8cc223e 100644 (file)
@@ -68,9 +68,10 @@ void CCCanvasLayerImpl::draw()
     GLC(context, context->useProgram(program->program()));
     GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
     LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
-                                    bounds().width(), bounds().height(), drawOpacity(),
+                                    bounds().width(), bounds().height(), drawOpacity(), layerRenderer()->sharedGeometryQuad(),
                                     program->vertexShader().matrixLocation(),
-                                    program->fragmentShader().alphaLocation());
+                                    program->fragmentShader().alphaLocation(),
+                                    -1);
     if (!m_hasAlpha)
         context->enable(GraphicsContext3D::BLEND);
 }
index b256c67..8c08630 100644 (file)
@@ -153,8 +153,9 @@ void CCHeadsUpDisplay::draw()
     matrix.translate3d(hudSize.width() * 0.5, hudSize.height() * 0.5, 0);
     LayerChromium::drawTexturedQuad(context, m_layerRenderer->projectionMatrix(),
                                     matrix, hudSize.width(), hudSize.height(),
-                                    1.0f, program->vertexShader().matrixLocation(),
-                                    program->fragmentShader().alphaLocation());
+                                    1.0f, m_layerRenderer->sharedGeometryQuad(), program->vertexShader().matrixLocation(),
+                                    program->fragmentShader().alphaLocation(),
+                                    -1);
     m_hudTexture->unreserve();
 }
 
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.cpp
new file mode 100644 (file)
index 0000000..896b2ac
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "cc/CCLayerQuad.h"
+
+namespace WebCore {
+
+CCLayerQuad::Edge::Edge(const FloatPoint& p, const FloatPoint& q)
+{
+    ASSERT(p != q);
+
+    FloatPoint tangent(p.y() - q.y(), q.x() - p.x());
+    float cross2 = p.x() * q.y() - q.x() * p.y();
+
+    set(tangent.x(), tangent.y(), cross2);
+    scale(1.0f / tangent.length());
+}
+
+CCLayerQuad::CCLayerQuad(const FloatQuad& quad)
+{
+    // Create edges.
+    m_left = Edge(quad.p4(), quad.p1());
+    m_right = Edge(quad.p2(), quad.p3());
+    m_top = Edge(quad.p1(), quad.p2());
+    m_bottom = Edge(quad.p3(), quad.p4());
+
+    float sign = quad.isCounterclockwise() ? -1 : 1;
+    m_left.scale(sign);
+    m_right.scale(sign);
+    m_top.scale(sign);
+    m_bottom.scale(sign);
+}
+
+FloatQuad CCLayerQuad::floatQuad() const
+{
+    return FloatQuad(m_bottom.intersect(m_left),
+                     m_left.intersect(m_top),
+                     m_top.intersect(m_right),
+                     m_right.intersect(m_bottom));
+}
+
+void CCLayerQuad::toFloatArray(float flattened[12]) const
+{
+    flattened[0] = m_left.x();
+    flattened[1] = m_left.y();
+    flattened[2] = m_left.z();
+    flattened[3] = m_top.x();
+    flattened[4] = m_top.y();
+    flattened[5] = m_top.z();
+    flattened[6] = m_right.x();
+    flattened[7] = m_right.y();
+    flattened[8] = m_right.z();
+    flattened[9] = m_bottom.x();
+    flattened[10] = m_bottom.y();
+    flattened[11] = m_bottom.z();
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerQuad.h
new file mode 100644 (file)
index 0000000..fcf818e
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef CCLayerQuad_h
+#define CCLayerQuad_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "FloatPoint3D.h"
+#include "FloatQuad.h"
+
+static const float kAntiAliasingInflateDistance = 0.5f;
+
+namespace WebCore {
+
+class CCLayerQuad {
+public:
+    class Edge {
+    public:
+        Edge()
+            : m_x(0)
+            , m_y(0)
+            , m_z(0)
+        {
+        }
+        Edge(const FloatPoint&, const FloatPoint&);
+
+        float x() const { return m_x; }
+        float y() const { return m_y; }
+        float z() const { return m_z; }
+
+        void setX(float x) { m_x = x; }
+        void setY(float y) { m_y = y; }
+        void setZ(float z) { m_z = z; }
+        void set(float x, float y, float z)
+        {
+            m_x = x;
+            m_y = y;
+            m_z = z;
+        }
+
+        void moveX(float dx) { m_x += dx; }
+        void moveY(float dy) { m_y += dy; }
+        void moveZ(float dz) { m_z += dz; }
+        void move(float dx, float dy, float dz)
+        {
+            m_x += dx;
+            m_y += dy;
+            m_z += dz;
+        }
+
+        void scaleX(float sx) { m_x *= sx; }
+        void scaleY(float sy) { m_y *= sy; }
+        void scaleZ(float sz) { m_z *= sz; }
+        void scale(float sx, float sy, float sz)
+        {
+            m_x *= sx;
+            m_y *= sy;
+            m_z *= sz;
+        }
+        void scale(float s) { scale(s, s, s); }
+
+        FloatPoint intersect(const Edge& e) const
+        {
+            return FloatPoint(
+                (y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()),
+                (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y()));
+        }
+
+    private:
+        float m_x;
+        float m_y;
+        float m_z;
+    };
+
+    CCLayerQuad(const Edge& left, const Edge& top, const Edge& right, const Edge& bottom)
+        : m_left(left)
+        , m_top(top)
+        , m_right(right)
+        , m_bottom(bottom)
+    {
+    }
+    CCLayerQuad(const FloatQuad&);
+
+    Edge left() const { return m_left; }
+    Edge top() const { return m_top; }
+    Edge right() const { return m_right; }
+    Edge bottom() const { return m_bottom; }
+
+    void inflateX(float dx) { m_left.moveZ(dx); m_right.moveZ(dx); }
+    void inflateY(float dy) { m_top.moveZ(dy); m_bottom.moveZ(dy); }
+    void inflate(float d) { inflateX(d); inflateY(d); }
+    void inflateAntiAliasingDistance() { inflate(kAntiAliasingInflateDistance); }
+
+    FloatQuad floatQuad() const;
+
+    void toFloatArray(float[12]) const;
+
+private:
+    Edge m_left;
+    Edge m_top;
+    Edge m_right;
+    Edge m_bottom;
+};
+
+}
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif
index a9f450e..0f165be 100644 (file)
@@ -66,9 +66,10 @@ void CCPluginLayerImpl::draw()
     GLC(context, context->useProgram(program->program()));
     GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
     LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
-                                    bounds().width(), bounds().height(), drawOpacity(),
+                                    bounds().width(), bounds().height(), drawOpacity(), layerRenderer()->sharedGeometryQuad(),
                                     program->vertexShader().matrixLocation(),
-                                    program->fragmentShader().alphaLocation());
+                                    program->fragmentShader().alphaLocation(),
+                                    -1);
 }
 
 
index ff29ac6..2a9b0e5 100644 (file)
@@ -106,47 +106,6 @@ void CCRenderSurface::releaseContentsTexture()
     m_contentsTexture->unreserve();
 }
 
-
-void CCRenderSurface::drawSurface(CCLayerImpl* maskLayer, const TransformationMatrix& drawTransform)
-{
-    GraphicsContext3D* context3D = layerRenderer()->context();
-
-    int shaderMatrixLocation = -1;
-    int shaderAlphaLocation = -1;
-    const CCRenderSurface::Program* program = layerRenderer()->renderSurfaceProgram();
-    const CCRenderSurface::MaskProgram* maskProgram = layerRenderer()->renderSurfaceMaskProgram();
-    ASSERT(program && program->initialized());
-    bool useMask = false;
-    if (maskLayer && maskLayer->drawsContent()) {
-        if (!maskLayer->bounds().isEmpty()) {
-            context3D->makeContextCurrent();
-            GLC(context3D, context3D->useProgram(maskProgram->program()));
-            GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
-            GLC(context3D, context3D->uniform1i(maskProgram->fragmentShader().samplerLocation(), 0));
-            m_contentsTexture->bindTexture(context3D);
-            GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE1));
-            GLC(context3D, context3D->uniform1i(maskProgram->fragmentShader().maskSamplerLocation(), 1));
-            maskLayer->bindContentsTexture();
-            GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
-            shaderMatrixLocation = maskProgram->vertexShader().matrixLocation();
-            shaderAlphaLocation = maskProgram->fragmentShader().alphaLocation();
-            useMask = true;
-        }
-    }
-
-    if (!useMask) {
-        GLC(context3D, context3D->useProgram(program->program()));
-        m_contentsTexture->bindTexture(context3D);
-        GLC(context3D, context3D->uniform1i(program->fragmentShader().samplerLocation(), 0));
-        shaderMatrixLocation = program->vertexShader().matrixLocation();
-        shaderAlphaLocation = program->fragmentShader().alphaLocation();
-    }
-
-    LayerChromium::drawTexturedQuad(layerRenderer()->context(), layerRenderer()->projectionMatrix(), drawTransform,
-                                        m_contentRect.width(), m_contentRect.height(), m_drawOpacity,
-                                        shaderMatrixLocation, shaderAlphaLocation);
-}
-
 void CCRenderSurface::draw(const IntRect&)
 {
     if (m_skipsDraw || !m_contentsTexture)
@@ -168,9 +127,92 @@ void CCRenderSurface::draw(const IntRect&)
 
     // Reflection draws before the layer.
     if (m_owningLayer->replicaLayer())
-        drawSurface(replicaMaskLayer, m_replicaDrawTransform);
+        drawLayer(replicaMaskLayer, m_replicaDrawTransform);
+
+    drawLayer(m_maskLayer, m_drawTransform);
+}
+
+void CCRenderSurface::drawLayer(CCLayerImpl* maskLayer, const TransformationMatrix& drawTransform)
+{
+    TransformationMatrix renderMatrix = drawTransform;
+    // Apply a scaling factor to size the quad from 1x1 to its intended size.
+    renderMatrix.scale3d(m_contentRect.width(), m_contentRect.height(), 1);
+
+    TransformationMatrix deviceMatrix = TransformationMatrix(layerRenderer()->windowMatrix() * layerRenderer()->projectionMatrix() * renderMatrix).to2dTransform();
+
+    // Can only draw surface if device matrix is invertible.
+    if (!deviceMatrix.isInvertible())
+        return;
+
+    FloatQuad quad = deviceMatrix.mapQuad(layerRenderer()->sharedGeometryQuad());
+    CCLayerQuad layerQuad = CCLayerQuad(quad);
 
-    drawSurface(m_maskLayer, m_drawTransform);
+#if defined(OS_CHROMEOS)
+    // FIXME: Disable anti-aliasing to workaround broken driver.
+    bool useAA = false;
+#else
+    // Use anti-aliasing programs only when necessary.
+    bool useAA = (!quad.isRectilinear() || !quad.boundingBox().isExpressibleAsIntRect());
+#endif
+
+    if (useAA)
+        layerQuad.inflateAntiAliasingDistance();
+
+    bool useMask = false;
+    if (maskLayer && maskLayer->drawsContent())
+        if (!maskLayer->bounds().isEmpty())
+            useMask = true;
+
+    if (useMask) {
+        if (useAA) {
+            const MaskProgramAA* program = layerRenderer()->renderSurfaceMaskProgramAA();
+            drawSurface(maskLayer, drawTransform, deviceMatrix, layerQuad, program, program->fragmentShader().maskSamplerLocation(), program->vertexShader().pointLocation(), program->fragmentShader().edgeLocation());
+        } else {
+            const MaskProgram* program = layerRenderer()->renderSurfaceMaskProgram();
+            drawSurface(maskLayer, drawTransform, deviceMatrix, layerQuad, program, program->fragmentShader().maskSamplerLocation(), -1, -1);
+        }
+    } else {
+        if (useAA) {
+            const ProgramAA* program = layerRenderer()->renderSurfaceProgramAA();
+            drawSurface(maskLayer, drawTransform, deviceMatrix, layerQuad, program, -1, program->vertexShader().pointLocation(), program->fragmentShader().edgeLocation());
+        } else {
+            const Program* program = layerRenderer()->renderSurfaceProgram();
+            drawSurface(maskLayer, drawTransform, deviceMatrix, layerQuad, program, -1, -1, -1);
+        }
+    }
+}
+
+template <class T>
+void CCRenderSurface::drawSurface(CCLayerImpl* maskLayer, const TransformationMatrix& drawTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad& layerQuad, const T* program, int shaderMaskSamplerLocation, int shaderQuadLocation, int shaderEdgeLocation)
+{
+    GraphicsContext3D* context3D = layerRenderer()->context();
+
+    context3D->makeContextCurrent();
+    GLC(context3D, context3D->useProgram(program->program()));
+
+    GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
+    GLC(context3D, context3D->uniform1i(program->fragmentShader().samplerLocation(), 0));
+    m_contentsTexture->bindTexture(context3D);
+
+    if (shaderMaskSamplerLocation != -1) {
+        GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE1));
+        GLC(context3D, context3D->uniform1i(shaderMaskSamplerLocation, 1));
+        maskLayer->bindContentsTexture();
+        GLC(context3D, context3D->activeTexture(GraphicsContext3D::TEXTURE0));
+    }
+
+    if (shaderEdgeLocation != -1) {
+        float edge[12];
+        layerQuad.toFloatArray(edge);
+        GLC(context3D, context3D->uniform3fv(shaderEdgeLocation, edge, 4));
+    }
+
+    // Map device space quad to layer space.
+    FloatQuad quad = deviceTransform.inverse().mapQuad(layerQuad.floatQuad());
+
+    LayerChromium::drawTexturedQuad(layerRenderer()->context(), layerRenderer()->projectionMatrix(), drawTransform,
+                                    m_contentRect.width(), m_contentRect.height(), m_drawOpacity, quad,
+                                    program->vertexShader().matrixLocation(), program->fragmentShader().alphaLocation(), shaderQuadLocation);
 }
 
 String CCRenderSurface::name() const
index a7fb5b2..e4fdfe1 100644 (file)
@@ -35,6 +35,7 @@
 #include "ShaderChromium.h"
 #include "TextureManager.h"
 #include "TransformationMatrix.h"
+#include "cc/CCLayerQuad.h"
 #include <wtf/Noncopyable.h>
 
 namespace WebCore {
@@ -90,13 +91,17 @@ public:
 
     typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlpha> Program;
     typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlphaMask> MaskProgram;
+    typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaAA> ProgramAA;
+    typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA> MaskProgramAA;
 
     ManagedTexture* contentsTexture() const { return m_contentsTexture.get(); }
 
     int owningLayerId() const;
 private:
     LayerRendererChromium* layerRenderer();
-    void drawSurface(CCLayerImpl* maskLayer, const TransformationMatrix& drawTransform);
+    void drawLayer(CCLayerImpl*, const TransformationMatrix&);
+    template <class T>
+    void drawSurface(CCLayerImpl*, const TransformationMatrix& drawTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad&, const T* program, int shaderMaskSamplerLocation, int shaderQuadLocation, int shaderEdgeLocation);
 
     CCLayerImpl* m_owningLayer;
     CCLayerImpl* m_maskLayer;
index 5f5b256..1a75834 100644 (file)
 
 #include "cc/CCTiledLayerImpl.h"
 
-#include "FloatQuad.h"
 #include "LayerRendererChromium.h"
+#include "cc/CCLayerQuad.h"
 #include <wtf/text/WTFString.h>
 
 using namespace std;
 
 namespace WebCore {
 
-typedef FloatPoint3D Edge;
 class ManagedTexture;
 
 class DrawableTile : public CCLayerTilingData::Tile {
@@ -99,15 +98,26 @@ void CCTiledLayerImpl::draw()
     if (m_skipsDraw || !m_tiler || m_tiler->isEmpty() || layerRect.isEmpty() || !layerRenderer())
         return;
 
+    TransformationMatrix deviceMatrix = TransformationMatrix(layerRenderer()->windowMatrix() * layerRenderer()->projectionMatrix() * m_tilingTransform).to2dTransform();
+
+    // Don't draw any tiles when device matrix is not invertible.
+    if (!deviceMatrix.isInvertible())
+        return;
+
+    FloatQuad quad = deviceMatrix.mapQuad(FloatQuad(layerRect));
+    CCLayerQuad layerQuad = CCLayerQuad(quad);
+
 #if defined(OS_CHROMEOS)
     // FIXME: Disable anti-aliasing to workaround broken driver.
     bool useAA = false;
 #else
-    // Use anti-aliasing programs when border texels are preset and transform
-    // is not an integer translation.
-    bool useAA = (m_tiler->hasBorderTexels() && !m_tilingTransform.isIntegerTranslation());
+    // Use anti-aliasing programs only when necessary.
+    bool useAA = (m_tiler->hasBorderTexels() && (!quad.isRectilinear() || !quad.boundingBox().isExpressibleAsIntRect()));
 #endif
 
+    if (useAA)
+        layerQuad.inflateAntiAliasingDistance();
+
     GraphicsContext3D* context = layerRenderer()->context();
     if (isRootLayer()) {
         context->colorMask(true, true, true, false);
@@ -116,16 +126,22 @@ void CCTiledLayerImpl::draw()
 
     switch (m_sampledTexelFormat) {
     case LayerTextureUpdater::SampledTexelFormatRGBA:
-        if (useAA)
-            drawTiles(layerRenderer(), layerRect, m_tilingTransform, drawOpacity(), layerRenderer()->tilerProgramAA(), layerRenderer()->tilerProgramAA()->fragmentShader().fragmentTexTransformLocation(), layerRenderer()->tilerProgramAA()->fragmentShader().edgeLocation());
-        else
-            drawTiles(layerRenderer(), layerRect, m_tilingTransform, drawOpacity(), layerRenderer()->tilerProgram(), -1, -1);
+        if (useAA) {
+            const ProgramAA* program = layerRenderer()->tilerProgramAA();
+            drawTiles(layerRenderer(), layerRect, m_tilingTransform, deviceMatrix, layerQuad, drawOpacity(), program, program->fragmentShader().fragmentTexTransformLocation(), program->fragmentShader().edgeLocation());
+        } else {
+            const Program* program = layerRenderer()->tilerProgram();
+            drawTiles(layerRenderer(), layerRect, m_tilingTransform, deviceMatrix, layerQuad, drawOpacity(), program, -1, -1);
+        }
         break;
     case LayerTextureUpdater::SampledTexelFormatBGRA:
-        if (useAA)
-            drawTiles(layerRenderer(), layerRect, m_tilingTransform, drawOpacity(), layerRenderer()->tilerProgramSwizzleAA(), layerRenderer()->tilerProgramSwizzleAA()->fragmentShader().fragmentTexTransformLocation(), layerRenderer()->tilerProgramSwizzleAA()->fragmentShader().edgeLocation());
-        else
-            drawTiles(layerRenderer(), layerRect, m_tilingTransform, drawOpacity(), layerRenderer()->tilerProgramSwizzle(), -1, -1);
+        if (useAA) {
+            const ProgramSwizzleAA* program = layerRenderer()->tilerProgramSwizzleAA();
+            drawTiles(layerRenderer(), layerRect, m_tilingTransform, deviceMatrix, layerQuad, drawOpacity(), program, program->fragmentShader().fragmentTexTransformLocation(), program->fragmentShader().edgeLocation());
+        } else {
+            const ProgramSwizzle* program = layerRenderer()->tilerProgramSwizzle();
+            drawTiles(layerRenderer(), layerRect, m_tilingTransform, deviceMatrix, layerQuad, drawOpacity(), program, -1, -1);
+        }
         break;
     default:
         ASSERT_NOT_REACHED();
@@ -154,103 +170,32 @@ void CCTiledLayerImpl::syncTextureId(int i, int j, Platform3DObject textureId)
     tile->setTextureId(textureId);
 }
 
-static bool isCCW(const FloatQuad& quad)
-{
-    FloatPoint v1 = FloatPoint(quad.p2().x() - quad.p1().x(),
-                               quad.p2().y() - quad.p1().y());
-    FloatPoint v2 = FloatPoint(quad.p3().x() - quad.p2().x(),
-                               quad.p3().y() - quad.p2().y());
-    return (v1.x() * v2.y() - v1.y() * v2.x()) < 0;
-}
-
-static Edge computeEdge(const FloatPoint& p, const FloatPoint& q, float sign)
-{
-    ASSERT(p != q);
-
-    FloatPoint tangent(p.y() - q.y(), q.x() - p.x());
-    float scale = sign / tangent.length();
-    float cross2 = p.x() * q.y() - q.x() * p.y();
-
-    return Edge(tangent.x() * scale,
-                tangent.y() * scale,
-                cross2 * scale);
-}
-
-static FloatPoint intersect(const Edge& a, const Edge& b)
-{
-    return FloatPoint(
-        (a.y() * b.z() - b.y() * a.z()) / (a.x() * b.y() - b.x() * a.y()),
-        (a.x() * b.z() - b.x() * a.z()) / (b.x() * a.y() - a.x() * b.y()));
-}
-
 template <class T>
-void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const IntRect& contentRect, const TransformationMatrix& globalTransform, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation)
+void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const IntRect& contentRect, const TransformationMatrix& globalTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad& contentQuad, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation)
 {
-    TransformationMatrix matrix(layerRenderer->windowMatrix() * layerRenderer->projectionMatrix() * globalTransform);
-
-    // We don't care about Z component.
-    TransformationMatrix matrixXYW =
-        TransformationMatrix(matrix.m11(), matrix.m12(), 0, matrix.m14(),
-                             matrix.m21(), matrix.m22(), 0, matrix.m24(),
-                             matrix.m31(), matrix.m32(), 1, matrix.m34(),
-                             matrix.m41(), matrix.m42(), 0, matrix.m44());
-
-    // Don't draw any tiles when matrix is not invertible.
-    if (!matrixXYW.isInvertible())
-        return;
-
-    TransformationMatrix inverse = matrixXYW.inverse();
-
     GraphicsContext3D* context = layerRenderer->context();
     GLC(context, context->useProgram(program->program()));
     GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
     GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
 
-    // Map content rectangle to device space.
-    FloatQuad deviceQuad = matrix.mapQuad(FloatQuad(contentRect));
-
-    // Counter-clockwise?
-    float sign = isCCW(deviceQuad) ? -1 : 1;
-
-    // Compute outer edges.
-    Edge leftEdge = computeEdge(deviceQuad.p4(), deviceQuad.p1(), sign);
-    Edge rightEdge = computeEdge(deviceQuad.p2(), deviceQuad.p3(), sign);
-    Edge topEdge = computeEdge(deviceQuad.p1(), deviceQuad.p2(), sign);
-    Edge bottomEdge = computeEdge(deviceQuad.p3(), deviceQuad.p4(), sign);
+    TransformationMatrix quadTransform = deviceTransform.inverse();
 
     if (edgeLocation != -1) {
-        // Move outer edges to ensure that all partially covered pixels are
-        // processed.
-        leftEdge.move(0, 0, 0.5f);
-        rightEdge.move(0, 0, 0.5f);
-        topEdge.move(0, 0, 0.5f);
-        bottomEdge.move(0, 0, 0.5f);
-
         float edge[12];
-        edge[0] = leftEdge.x();
-        edge[1] = leftEdge.y();
-        edge[2] = leftEdge.z();
-        edge[3] = topEdge.x();
-        edge[4] = topEdge.y();
-        edge[5] = topEdge.z();
-        edge[6] = rightEdge.x();
-        edge[7] = rightEdge.y();
-        edge[8] = rightEdge.z();
-        edge[9] = bottomEdge.x();
-        edge[10] = bottomEdge.y();
-        edge[11] = bottomEdge.z();
+        contentQuad.toFloatArray(edge);
         GLC(context, context->uniform3fv(edgeLocation, edge, 4));
     }
 
-    Edge prevEdgeY = topEdge;
+    CCLayerQuad::Edge prevEdgeY = contentQuad.top();
 
     int left, top, right, bottom;
     m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom);
     IntRect layerRect = m_tiler->contentRectToLayerRect(contentRect);
+    float sign = FloatQuad(contentRect).isCounterclockwise() ? -1 : 1;
     for (int j = top; j <= bottom; ++j) {
-        Edge prevEdgeX = leftEdge;
+        CCLayerQuad::Edge prevEdgeX = contentQuad.left();
 
-        Edge edgeY = bottomEdge;
+        CCLayerQuad::Edge edgeY = contentQuad.bottom();
         if (j < (m_tiler->numTilesY() - 1)) {
             IntRect tileRect = unionRect(m_tiler->tileBounds(0, j), m_tiler->tileBounds(m_tiler->numTilesX() - 1, j));
             tileRect.intersect(layerRect);
@@ -265,11 +210,12 @@ void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const Int
             FloatPoint p2(tileRect.x(), tileRect.maxY());
 
             // Map points to device space.
-            p1 = matrix.mapPoint(p1);
-            p2 = matrix.mapPoint(p2);
+            p1 = deviceTransform.mapPoint(p1);
+            p2 = deviceTransform.mapPoint(p2);
 
             // Compute horizontal edge.
-            edgeY = computeEdge(p1, p2, sign);
+            edgeY = CCLayerQuad::Edge(p1, p2);
+            edgeY.scale(sign);
         }
 
         for (int i = left; i <= right; ++i) {
@@ -332,27 +278,25 @@ void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const Int
                 fragmentTexScaleY *= -1.0;
             }
 
-            Edge edgeX = rightEdge;
+            CCLayerQuad::Edge edgeX = contentQuad.right();
             if (i < (m_tiler->numTilesX() - 1)) {
                 FloatPoint p1(tileRect.maxX(), tileRect.y());
                 FloatPoint p2(tileRect.maxX(), tileRect.maxY());
 
                 // Map points to device space.
-                p1 = matrix.mapPoint(p1);
-                p2 = matrix.mapPoint(p2);
+                p1 = deviceTransform.mapPoint(p1);
+                p2 = deviceTransform.mapPoint(p2);
 
                 // Compute vertical edge.
-                edgeX = computeEdge(p1, p2, sign);
+                edgeX = CCLayerQuad::Edge(p1, p2);
+                edgeX.scale(sign);
             }
 
             // Create device space quad.
-            FloatQuad deviceQuad(intersect(edgeY, prevEdgeX),
-                                 intersect(prevEdgeX, prevEdgeY),
-                                 intersect(prevEdgeY, edgeX),
-                                 intersect(edgeX, edgeY));
+            CCLayerQuad deviceQuad(prevEdgeX, prevEdgeY, edgeX, edgeY);
 
             // Map quad to layer space.
-            FloatQuad quad = inverse.mapQuad(deviceQuad);
+            FloatQuad quad = quadTransform.mapQuad(deviceQuad.floatQuad());
 
             // Normalize to tileRect.
             quad.scale(1.0f / tileRect.width(), 1.0f / tileRect.height());
@@ -374,30 +318,20 @@ void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const Int
 
             GLC(context, context->uniform4f(program->vertexShader().vertexTexTransformLocation(), vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY));
 
-            float point[8];
-            point[0] = quad.p1().x();
-            point[1] = quad.p1().y();
-            point[2] = quad.p2().x();
-            point[3] = quad.p2().y();
-            point[4] = quad.p3().x();
-            point[5] = quad.p3().y();
-            point[6] = quad.p4().x();
-            point[7] = quad.p4().y();
-            GLC(context, context->uniform2fv(program->vertexShader().pointLocation(), point, 4));
-
             LayerChromium::drawTexturedQuad(context, layerRenderer->projectionMatrix(), globalTransform,
-                                            tileRect.width(), tileRect.height(), opacity,
+                                            tileRect.width(), tileRect.height(), opacity, quad,
                                             program->vertexShader().matrixLocation(),
-                                            program->fragmentShader().alphaLocation());
+                                            program->fragmentShader().alphaLocation(),
+                                            program->vertexShader().pointLocation());
 
             prevEdgeX = edgeX;
             // Reverse direction.
-            prevEdgeX.scale(-1, -1, -1);
+            prevEdgeX.scale(-1);
         }
 
         prevEdgeY = edgeY;
         // Reverse direction.
-        prevEdgeY.scale(-1, -1, -1);
+        prevEdgeY.scale(-1);
     }
 }
 
index a72d30c..ceec5f2 100644 (file)
@@ -61,8 +61,8 @@ public:
     typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleAlpha> ProgramSwizzle;
 
     // Shader program that produces anti-aliased layer edges.
-    typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexAlphaAA> ProgramAA;
-    typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleAlphaAA> ProgramSwizzleAA;
+    typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexClampAlphaAA> ProgramAA;
+    typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexClampSwizzleAlphaAA> ProgramSwizzleAA;
 
 private:
     explicit CCTiledLayerImpl(int id);
@@ -75,7 +75,7 @@ private:
 
     // Draw all tiles that intersect with contentRect.
     template <class T>
-    void drawTiles(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix&, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation);
+    void drawTiles(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix& globalTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad&, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation);
 
     TransformationMatrix m_tilingTransform;
     bool m_skipsDraw;
index 9ff1fcc..293db42 100644 (file)
@@ -135,9 +135,10 @@ void CCVideoLayerImpl::drawYUV(const CCVideoLayerImpl::YUVProgram* program) cons
     GLC(context, context->uniform3fv(program->fragmentShader().yuvAdjLocation(), const_cast<float*>(yuvAdjust), 1));
 
     LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
-                                    bounds().width(), bounds().height(), drawOpacity(),
+                                    bounds().width(), bounds().height(), drawOpacity(), FloatQuad(),
                                     program->vertexShader().matrixLocation(),
-                                    program->fragmentShader().alphaLocation());
+                                    program->fragmentShader().alphaLocation(),
+                                    -1);
 
     // Reset active texture back to texture 0.
     GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
@@ -158,9 +159,10 @@ void CCVideoLayerImpl::drawRGBA(const CCVideoLayerImpl::RGBAProgram* program) co
     GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
 
     LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
-                                    bounds().width(), bounds().height(), drawOpacity(),
+                                    bounds().width(), bounds().height(), drawOpacity(), layerRenderer()->sharedGeometryQuad(),
                                     program->vertexShader().matrixLocation(),
-                                    program->fragmentShader().alphaLocation());
+                                    program->fragmentShader().alphaLocation(),
+                                    -1);
 }
 
 
index 6366342..847817e 100644 (file)
@@ -1146,4 +1146,13 @@ bool TransformationMatrix::isIntegerTranslation() const
     return true;
 }
 
+TransformationMatrix TransformationMatrix::to2dTransform() const
+{
+    return TransformationMatrix(m_matrix[0][0], m_matrix[0][1], 0, m_matrix[0][3],
+                                m_matrix[1][0], m_matrix[1][1], 0, m_matrix[1][3],
+                                0, 0, 1, 0,
+                                m_matrix[3][0], m_matrix[3][1], 0, m_matrix[3][3]);
+}
+
+
 }
index 375abb6..c19c3c1 100644 (file)
@@ -345,6 +345,9 @@ public:
 
     bool isIntegerTranslation() const;
 
+    // This method returns the matrix without 3D components.
+    TransformationMatrix to2dTransform() const;
+
 private:
     // multiply passed 2D point by matrix (assume z=0)
     void multVecMatrix(double x, double y, double& dstX, double& dstY) const;