Integration of the Skia displacement mapping into WebKit
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 16:10:26 +0000 (16:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2013 16:10:26 +0000 (16:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112927

Patch by Alexis Hetu <sugoi@chromium.org> on 2013-03-25
Reviewed by Stephen White.

Added displacement mapping to effect-reference.html and
effect-reference-hw.html

* WebCore.gypi:
* platform/graphics/filters/FEDisplacementMap.h:
(FEDisplacementMap):
Adding Skia specific declarations
* platform/graphics/filters/skia/FEDisplacementMapSkia.cpp: Added.
(WebCore):
(WebCore::toSkiaMode):
Provides conversion between the WebKit displacement mapping mode and
the Skia displacement mapping mode
(WebCore::FEDisplacementMap::platformApplySkia):
Displacement through the Skia API. (Accelerated only for now)
(WebCore::FEDisplacementMap::createImageFilter):
Displacement image filter creation through the Skia API.

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

LayoutTests/css3/filters/effect-reference-hw.html
LayoutTests/css3/filters/effect-reference.html
LayoutTests/platform/chromium-win/css3/filters/effect-reference-expected.png
LayoutTests/platform/chromium-win/css3/filters/effect-reference-expected.txt
LayoutTests/platform/chromium-win/css3/filters/effect-reference-hw-expected.png
LayoutTests/platform/chromium-win/css3/filters/effect-reference-hw-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/filters/FEDisplacementMap.h
Source/WebCore/platform/graphics/filters/skia/FEDisplacementMapSkia.cpp [new file with mode: 0644]

index 9ade562..40fbc8e 100644 (file)
@@ -34,6 +34,9 @@
     <filter id="convolvematrix">
       <feConvolveMatrix order="3 3" kernelMatrix="1 1 1   1 -7 1   1 1 1" bias ="0.3"/>
     </filter>
+    <filter id="displacement">
+      <feDisplacementMap scale="10" xChannelSelector="R" yChannelSelector="G"/>
+    </filter>
   </defs>
 </svg>
 <style>
@@ -51,3 +54,4 @@ img {
 <img style="-webkit-filter: url(#lighting); filter: url(#lighting);" src="resources/reference.png">
 <img style="-webkit-filter: url(#offset); filter: url(#offset);" src="resources/reference.png">
 <img style="-webkit-filter: url(#convolvematrix); filter: url(#convolvematrix);" src="resources/reference.png">
+<img style="-webkit-filter: url(#displacement); filter: url(#displacement);" src="resources/reference.png">
index c0f29b3..0d4f786 100644 (file)
@@ -34,6 +34,9 @@
     <filter id="convolvematrix">
       <feConvolveMatrix order="3 3" kernelMatrix="1 1 1   1 -7 1   1 1 1" bias ="0.3"/>
     </filter>
+    <filter id="displacement">
+      <feDisplacementMap scale="10" xChannelSelector="R" yChannelSelector="G"/>
+    </filter>
   </defs>
 </svg>
 <style>
@@ -50,3 +53,4 @@ img {
 <img style="-webkit-filter: url(#lighting); filter: url(#lighting);" src="resources/reference.png">
 <img style="-webkit-filter: url(#offset); filter: url(#offset);" src="resources/reference.png">
 <img style="-webkit-filter: url(#convolvematrix); filter: url(#convolvematrix);" src="resources/reference.png">
+<img style="-webkit-filter: url(#displacement); filter: url(#displacement);" src="resources/reference.png">
index fd9369f..2379a5f 100644 (file)
Binary files a/LayoutTests/platform/chromium-win/css3/filters/effect-reference-expected.png and b/LayoutTests/platform/chromium-win/css3/filters/effect-reference-expected.png differ
index 7f984cd..2d2c867 100644 (file)
@@ -38,6 +38,10 @@ layer at (0,0) size 800x600
           RenderSVGResourceFilter {filter} [id="convolvematrix"] [filterUnits=objectBoundingBox] [primitiveUnits=userSpaceOnUse]
             [feConvolveMatrix order="width=3 height=3" kernelMatrix="[1.00, 1.00, 1.00, 1.00, -7.00, 1.00, 1.00, 1.00, 1.00]" divisor="1.00" bias="0.30" target="(1,1)" edgeMode="DUPLICATE" kernelUnitLength="(1,1)" preserveAlpha="0"]
               [SourceGraphic]
+          RenderSVGResourceFilter {filter} [id="displacement"] [filterUnits=objectBoundingBox] [primitiveUnits=userSpaceOnUse]
+            [feDisplacementMap scale="10.00" xChannelSelector="RED" yChannelSelector="GREEN"]
+              [SourceGraphic]
+              [SourceGraphic]
       RenderText {#text} at (0,95) size 4x19
         text run at (0,95) width 4: " "
       RenderText {#text} at (0,0) size 0x0
@@ -58,6 +62,8 @@ layer at (0,0) size 800x600
         text run at (548,210) width 4: " "
       RenderText {#text} at (732,210) size 4x19
         text run at (732,210) width 4: " "
+      RenderText {#text} at (180,325) size 4x19
+        text run at (180,325) width 4: " "
       RenderText {#text} at (0,0) size 0x0
 layer at (206,18) size 160x90
   RenderImage {IMG} at (198,10) size 160x90
@@ -75,3 +81,5 @@ layer at (570,133) size 160x90
   RenderImage {IMG} at (562,125) size 160x90
 layer at (18,248) size 160x90
   RenderImage {IMG} at (10,240) size 160x90
+layer at (202,248) size 160x90
+  RenderImage {IMG} at (194,240) size 160x90
index c37d32e..a72c11d 100644 (file)
Binary files a/LayoutTests/platform/chromium-win/css3/filters/effect-reference-hw-expected.png and b/LayoutTests/platform/chromium-win/css3/filters/effect-reference-hw-expected.png differ
index b4611f5..b699d81 100644 (file)
@@ -38,6 +38,10 @@ layer at (0,0) size 800x600
           RenderSVGResourceFilter {filter} [id="convolvematrix"] [filterUnits=objectBoundingBox] [primitiveUnits=userSpaceOnUse]
             [feConvolveMatrix order="width=3 height=3" kernelMatrix="[1.00, 1.00, 1.00, 1.00, -7.00, 1.00, 1.00, 1.00, 1.00]" divisor="1.00" bias="0.30" target="(1,1)" edgeMode="DUPLICATE" kernelUnitLength="(1,1)" preserveAlpha="0"]
               [SourceGraphic]
+          RenderSVGResourceFilter {filter} [id="displacement"] [filterUnits=objectBoundingBox] [primitiveUnits=userSpaceOnUse]
+            [feDisplacementMap scale="10.00" xChannelSelector="RED" yChannelSelector="GREEN"]
+              [SourceGraphic]
+              [SourceGraphic]
       RenderText {#text} at (0,95) size 4x19
         text run at (0,95) width 4: " "
       RenderText {#text} at (0,0) size 0x0
@@ -57,6 +61,8 @@ layer at (0,0) size 800x600
         text run at (548,210) width 4: " "
       RenderText {#text} at (732,210) size 4x19
         text run at (732,210) width 4: " "
+      RenderText {#text} at (180,325) size 4x19
+        text run at (180,325) width 4: " "
       RenderText {#text} at (0,0) size 0x0
 layer at (22,18) size 160x90
   RenderImage {IMG} at (14,10) size 160x90
@@ -76,3 +82,5 @@ layer at (570,133) size 160x90
   RenderImage {IMG} at (562,125) size 160x90
 layer at (18,248) size 160x90
   RenderImage {IMG} at (10,240) size 160x90
+layer at (202,248) size 160x90
+  RenderImage {IMG} at (194,240) size 160x90
index b33499f..e0c8ea9 100644 (file)
@@ -1,3 +1,27 @@
+2013-03-25  Alexis Hetu  <sugoi@chromium.org>
+
+        Integration of the Skia displacement mapping into WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=112927
+
+        Reviewed by Stephen White.
+
+        Added displacement mapping to effect-reference.html and
+        effect-reference-hw.html
+
+        * WebCore.gypi:
+        * platform/graphics/filters/FEDisplacementMap.h:
+        (FEDisplacementMap):
+        Adding Skia specific declarations
+        * platform/graphics/filters/skia/FEDisplacementMapSkia.cpp: Added.
+        (WebCore):
+        (WebCore::toSkiaMode):
+        Provides conversion between the WebKit displacement mapping mode and
+        the Skia displacement mapping mode
+        (WebCore::FEDisplacementMap::platformApplySkia):
+        Displacement through the Skia API. (Accelerated only for now)
+        (WebCore::FEDisplacementMap::createImageFilter):
+        Displacement image filter creation through the Skia API.
+
 2013-03-25  Vladislav Kaznacheev  <kaznacheev@chromium.org>
 
         Web Inspector: Graduate some new Inspector APIs to public
index c5da237..70d6bb9 100644 (file)
             'platform/graphics/filters/skia/FEColorMatrixSkia.cpp',
             'platform/graphics/filters/skia/FEComponentTransferSkia.cpp',
             'platform/graphics/filters/skia/FEConvolveMatrixSkia.cpp',
+            'platform/graphics/filters/skia/FEDisplacementMapSkia.cpp',
             'platform/graphics/filters/skia/FEGaussianBlurSkia.cpp',
             'platform/graphics/filters/skia/FEMorphologySkia.cpp',
             'platform/graphics/filters/skia/FELightingSkia.cpp',
index 1b4170e..815bcf8 100644 (file)
@@ -63,6 +63,11 @@ public:
 private:
     FEDisplacementMap(Filter*, ChannelSelectorType xChannelSelector, ChannelSelectorType yChannelSelector, float);
 
+#if USE(SKIA)
+    virtual bool platformApplySkia();
+    virtual SkImageFilter* createImageFilter(SkiaImageFilterBuilder*);
+#endif
+
     ChannelSelectorType m_xChannelSelector;
     ChannelSelectorType m_yChannelSelector;
     float m_scale;
diff --git a/Source/WebCore/platform/graphics/filters/skia/FEDisplacementMapSkia.cpp b/Source/WebCore/platform/graphics/filters/skia/FEDisplacementMapSkia.cpp
new file mode 100644 (file)
index 0000000..22f1b73
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 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 ENABLE(FILTERS)
+#include "FEDisplacementMap.h"
+
+#include "NativeImageSkia.h"
+#include "SkBitmapSource.h"
+#include "SkDisplacementMapEffect.h"
+#include "SkiaImageFilterBuilder.h"
+
+namespace WebCore {
+
+static SkDisplacementMapEffect::ChannelSelectorType toSkiaMode(ChannelSelectorType type)
+{
+    switch (type) {
+    case CHANNEL_R:
+        return SkDisplacementMapEffect::kR_ChannelSelectorType;
+    case CHANNEL_G:
+        return SkDisplacementMapEffect::kG_ChannelSelectorType;
+    case CHANNEL_B:
+        return SkDisplacementMapEffect::kB_ChannelSelectorType;
+    case CHANNEL_A:
+        return SkDisplacementMapEffect::kA_ChannelSelectorType;
+    case CHANNEL_UNKNOWN:
+    default:
+        return SkDisplacementMapEffect::kUnknown_ChannelSelectorType;
+    }
+}
+
+bool FEDisplacementMap::platformApplySkia()
+{
+    // For now, only use the skia implementation for accelerated rendering.
+    if (filter()->renderingMode() != Accelerated)
+        return false;
+
+    FilterEffect* in = inputEffect(0);
+    FilterEffect* in2 = inputEffect(1);
+
+    if (!in || !in2) 
+        return false;
+
+    ImageBuffer* resultImage = createImageBufferResult();
+    if (!resultImage)
+        return false;
+
+    RefPtr<Image> color = in->asImageBuffer()->copyImage(DontCopyBackingStore);
+    RefPtr<Image> displ = in2->asImageBuffer()->copyImage(DontCopyBackingStore);
+
+    NativeImageSkia* colorNativeImage = color->nativeImageForCurrentFrame();
+    NativeImageSkia* displNativeImage = displ->nativeImageForCurrentFrame();
+
+    if (!colorNativeImage || !displNativeImage)
+        return false;
+
+    SkBitmap colorBitmap = colorNativeImage->bitmap();
+    SkBitmap displBitmap = displNativeImage->bitmap();
+
+    SkAutoTUnref<SkImageFilter> colorSource(new SkBitmapSource(colorBitmap));
+    SkAutoTUnref<SkImageFilter> displSource(new SkBitmapSource(displBitmap));
+    SkDisplacementMapEffect::ChannelSelectorType typeX = toSkiaMode(m_xChannelSelector);
+    SkDisplacementMapEffect::ChannelSelectorType typeY = toSkiaMode(m_yChannelSelector);
+    SkAutoTUnref<SkImageFilter> displEffect(new SkDisplacementMapEffect(
+        typeX, typeY, SkFloatToScalar(m_scale), displSource, colorSource));
+    SkPaint paint;
+    paint.setImageFilter(displEffect);
+    resultImage->context()->platformContext()->drawBitmap(colorBitmap, 0, 0, &paint);
+    return true;
+}
+
+SkImageFilter* FEDisplacementMap::createImageFilter(SkiaImageFilterBuilder* builder)
+{
+    SkImageFilter* color = builder->build(inputEffect(0));
+    SkImageFilter* displ = builder->build(inputEffect(1));
+    SkDisplacementMapEffect::ChannelSelectorType typeX = toSkiaMode(m_xChannelSelector);
+    SkDisplacementMapEffect::ChannelSelectorType typeY = toSkiaMode(m_yChannelSelector);
+    return new SkDisplacementMapEffect(typeX, typeY, SkFloatToScalar(m_scale), displ, color);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILTERS)