Title: [193418] branches/safari-601-branch

Diff

Modified: branches/safari-601-branch/LayoutTests/ChangeLog (193417 => 193418)


--- branches/safari-601-branch/LayoutTests/ChangeLog	2015-12-04 17:10:22 UTC (rev 193417)
+++ branches/safari-601-branch/LayoutTests/ChangeLog	2015-12-04 17:10:26 UTC (rev 193418)
@@ -1,5 +1,22 @@
 2015-12-03  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r190383. rdar://problem/23732393
+
+    2015-09-30  Katlyn Graff  <kgr...@apple.com>
+
+            Tests support for imageSmoothingQuality attribute of Canvas element.
+            https://bugs.webkit.org/show_bug.cgi?id=149541
+
+            Reviewed by Ryosuke Niwa.
+
+            Tests low, medium, high, and default values, value persistence when
+            imageSmoothingEnabled is changed, and invalid input.
+
+            * fast/canvas/canvas-imageSmoothingQuality-expected.txt: Added.
+            * fast/canvas/canvas-imageSmoothingQuality.html: Added.
+
+2015-12-03  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r188194. rdar://problem/23732393
 
     2015-08-08  Dean Jackson  <d...@apple.com>

Added: branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality-expected.txt (0 => 193418)


--- branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality-expected.txt	2015-12-04 17:10:26 UTC (rev 193418)
@@ -0,0 +1,40 @@
+Tests for the imageSmoothingQuality attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+PASS lowContext.imageSmoothingQuality is 'low'
+PASS mediumContext.imageSmoothingQuality is 'medium'
+PASS highContext.imageSmoothingQuality is 'high'
+
+PASS lowData is not mediumData
+PASS mediumData is not highData
+PASS lowData is not highData
+
+PASS sampleAlpha(lowData) is >= sampleAlpha(mediumData)
+PASS sampleAlpha(mediumData) is >= sampleAlpha(highData)
+
+PASS defaultContext.imageSmoothingQuality is 'low'
+
+PASS highContext.imageSmoothingEnabled = false; highContext.imageSmoothingQuality is 'high'
+PASS highContext.imageSmoothingQuality = 'medium'; highContext.imageSmoothingQuality is 'medium'
+
+highContext.imageSmoothingEnabled = true; highContext.imageSmoothingQuality = 'high';
+PASS scaleImageData(highCanvas, '3223') did not throw exception.
+PASS highContext.imageSmoothingQuality is 'high'
+PASS scaleImageData(highCanvas, 'bad_input') did not throw exception.
+PASS highContext.imageSmoothingQuality is 'high'
+PASS scaleImageData(highCanvas, 'LOW') did not throw exception.
+PASS highContext.imageSmoothingQuality is 'high'
+PASS scaleImageData(highCanvas, 'Medium') did not throw exception.
+PASS highContext.imageSmoothingQuality is 'high'
+
+highContext.save(); highContext.imageSmoothingQuality = 'medium';
+PASS highContext.restore(); highContext.imageSmoothingQuality is 'high'
+PASS scaleImageData(highCanvas, highCanvas.imageSmoothingQuality); is highData
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+ 

Added: branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality.html (0 => 193418)


--- branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/canvas/canvas-imageSmoothingQuality.html	2015-12-04 17:10:26 UTC (rev 193418)
@@ -0,0 +1,114 @@
+<!DOCTYPE html>
+<html>
+<body>
+
+<script src=""
+<canvas id="source"></canvas>
+
+<script>
+
+description("Tests for the imageSmoothingQuality attribute.");
+
+if (window.testRunner)
+   testRunner.overridePreference("WebKitCanvasUsesAcceleratedDrawing", 0);
+
+var source = document.getElementById("source");
+source.width = 60;
+source.height = 12;
+var sourceContext = source.getContext("2d");
+var sourceImage = sourceContext.createImageData(source.width, source.height);
+
+function drawBlackDot(x, y) {
+    var offset = y * 4 * source.width + x * 4;
+    sourceImage.data[offset + 0] = 0; // R
+    sourceImage.data[offset + 1] = 0; // G
+    sourceImage.data[offset + 2] = 0; // B
+    sourceImage.data[offset + 3] = 255; // Alpha
+}
+
+for (var x = 0; x < source.width; x++) {
+    drawBlackDot(x, 1)
+    drawBlackDot(x, 2);
+}
+
+sourceContext.putImageData(sourceImage, 0, 0);
+
+function scaleTestResults(quality){
+	var canvas = document.createElement("canvas");
+	canvas.id = quality + "Canvas";
+	document.body.appendChild(canvas);
+	canvas.width = sourceImage.width / 4;
+    canvas.height = sourceImage.height / 4;
+    return scaleImageData(canvas, quality);
+}
+
+function scaleImageData(destinationCanvas, quality) {
+    var context = destinationCanvas.getContext("2d");
+
+    if (quality)
+        context.imageSmoothingQuality = quality;
+
+    context.drawImage(source, 0, 0, destinationCanvas.width, destinationCanvas.height);
+    var data = "" 0, 1, 1).data;
+    context.clearRect(0, 0, destinationCanvas.width, destinationCanvas.height);
+    return JSON.stringify(data);
+}
+
+function testInvalidInput(badInput){
+	shouldNotThrow(badInput);
+	shouldBe("highContext.imageSmoothingQuality", "'high'");
+}
+
+function sampleAlpha(data){
+	return data[3];
+}
+
+debug("");
+
+var lowData = scaleTestResults("low");
+var lowContext = document.getElementById("lowCanvas").getContext('2d');
+shouldBe("lowContext.imageSmoothingQuality", "'low'");
+
+var mediumData = scaleTestResults("medium");
+var mediumContext = document.getElementById("mediumCanvas").getContext('2d');
+shouldBe("mediumContext.imageSmoothingQuality", "'medium'");
+
+var highData = scaleTestResults("high");
+var highContext = document.getElementById("highCanvas").getContext('2d');
+shouldBe("highContext.imageSmoothingQuality", "'high'");
+
+debug("");
+shouldNotBe("lowData", "mediumData");
+shouldNotBe("mediumData", "highData");
+shouldNotBe("lowData", "highData");
+
+debug("");
+shouldBeGreaterThanOrEqual("sampleAlpha(lowData)", "sampleAlpha(mediumData)");
+shouldBeGreaterThanOrEqual("sampleAlpha(mediumData)", "sampleAlpha(highData)");
+
+debug("");
+var defaultContext = sourceContext;
+shouldBe("defaultContext.imageSmoothingQuality", "'low'");
+
+debug("");
+shouldBe("highContext.imageSmoothingEnabled = false; highContext.imageSmoothingQuality", "'high'");
+shouldBe("highContext.imageSmoothingQuality = 'medium'; highContext.imageSmoothingQuality", "'medium'");
+
+debug("");
+evalAndLog("highContext.imageSmoothingEnabled = true; highContext.imageSmoothingQuality = 'high';");
+var highCanvas = document.getElementById("highCanvas");
+testInvalidInput("scaleImageData(highCanvas, '3223')");
+testInvalidInput("scaleImageData(highCanvas, 'bad_input')");
+testInvalidInput("scaleImageData(highCanvas, 'LOW')");
+testInvalidInput("scaleImageData(highCanvas, 'Medium')");
+
+debug("");
+evalAndLog("highContext.save(); highContext.imageSmoothingQuality = 'medium';");
+shouldBe("highContext.restore(); highContext.imageSmoothingQuality", "'high'");
+shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality);", "highData");
+
+debug("");
+
+</script>
+</body>
+</html>

Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (193417 => 193418)


--- branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-04 17:10:22 UTC (rev 193417)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-04 17:10:26 UTC (rev 193418)
@@ -1,5 +1,33 @@
 2015-12-03  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r190383. rdar://problem/23732393
+
+    2015-09-30  Katlyn Graff  <kgr...@apple.com>
+
+            Add support for the imageSmoothingQuality property for CanvasRenderingContext2D.
+            https://bugs.webkit.org/show_bug.cgi?id=149541
+
+            Reviewed by Ryosuke Niwa.
+
+            As documented here: https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing
+            Exposes the smooothing quality of algorithms used for scaling images. Valid input
+            values are low, medium, and high: associated algorithms are expected to vary for
+            differing hardware. setImageSmoothingQuality provides a handle into CGInterpolationQuality.
+
+            Test: fast/canvas/canvas-imageSmoothingQuality.html
+
+            * html/canvas/CanvasRenderingContext2D.cpp:
+            (WebCore::CanvasRenderingContext2D::State::State):
+            (WebCore::CanvasRenderingContext2D::State::operator=):
+            (WebCore::smoothingToInterpolationQuality):
+            (WebCore::CanvasRenderingContext2D::imageSmoothingQuality):
+            (WebCore::CanvasRenderingContext2D::setImageSmoothingQuality):
+            (WebCore::CanvasRenderingContext2D::setImageSmoothingEnabled):
+            * html/canvas/CanvasRenderingContext2D.h:
+            * html/canvas/CanvasRenderingContext2D.idl:
+
+2015-12-03  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r189427. rdar://problem/23732393
 
     2015-09-04  Myles C. Maxfield  <mmaxfi...@apple.com>

Modified: branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (193417 => 193418)


--- branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2015-12-04 17:10:22 UTC (rev 193417)
+++ branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2015-12-04 17:10:26 UTC (rev 193418)
@@ -42,7 +42,6 @@
 #include "DOMPath.h"
 #include "ExceptionCodePlaceholder.h"
 #include "FloatQuad.h"
-#include "GraphicsContext.h"
 #include "HTMLImageElement.h"
 #include "HTMLVideoElement.h"
 #include "ImageData.h"
@@ -173,6 +172,7 @@
     , hasInvertibleTransform(true)
     , lineDashOffset(0)
     , imageSmoothingEnabled(true)
+    , imageSmoothingQuality(SmoothingQuality::Low)
     , textAlign(StartTextAlign)
     , textBaseline(AlphabeticTextBaseline)
     , direction(Direction::Inherit)
@@ -199,6 +199,7 @@
     , hasInvertibleTransform(other.hasInvertibleTransform)
     , lineDashOffset(other.lineDashOffset)
     , imageSmoothingEnabled(other.imageSmoothingEnabled)
+    , imageSmoothingQuality(other.imageSmoothingQuality)
     , textAlign(other.textAlign)
     , textBaseline(other.textBaseline)
     , direction(other.direction)
@@ -229,6 +230,7 @@
     transform = other.transform;
     hasInvertibleTransform = other.hasInvertibleTransform;
     imageSmoothingEnabled = other.imageSmoothingEnabled;
+    imageSmoothingQuality = other.imageSmoothingQuality;
     textAlign = other.textAlign;
     textBaseline = other.textBaseline;
     direction = other.direction;
@@ -2526,6 +2528,63 @@
 }
 #endif
 
+static InterpolationQuality smoothingToInterpolationQuality(CanvasRenderingContext2D::SmoothingQuality quality)
+{
+    switch (quality) {
+    case CanvasRenderingContext2D::SmoothingQuality::Low:
+        return InterpolationLow;
+    case CanvasRenderingContext2D::SmoothingQuality::Medium:
+        return InterpolationMedium;
+    case CanvasRenderingContext2D::SmoothingQuality::High:
+        return InterpolationHigh;
+    }
+
+    ASSERT_NOT_REACHED();
+    return InterpolationLow;
+};
+
+String CanvasRenderingContext2D::imageSmoothingQuality() const
+{
+    switch (state().imageSmoothingQuality) {
+    case SmoothingQuality::Low:
+        return ASCIILiteral("low");
+    case SmoothingQuality::Medium:
+        return ASCIILiteral("medium");
+    case SmoothingQuality::High:
+        return ASCIILiteral("high");
+    }
+
+    ASSERT_NOT_REACHED();
+    return ASCIILiteral("low");
+}
+
+void CanvasRenderingContext2D::setImageSmoothingQuality(const String& smoothingQualityString)
+{
+    SmoothingQuality quality;
+    if (smoothingQualityString == "low")
+        quality = SmoothingQuality::Low;
+    else if (smoothingQualityString == "medium")
+        quality = SmoothingQuality::Medium;
+    else if (smoothingQualityString == "high")
+        quality = SmoothingQuality::High;
+    else {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    if (quality == state().imageSmoothingQuality)
+        return;
+
+    realizeSaves();
+    modifiableState().imageSmoothingQuality = quality;
+
+    if (!modifiableState().imageSmoothingEnabled)
+        return;
+
+    if (auto* context = drawingContext())
+        context->setImageInterpolationQuality(smoothingToInterpolationQuality(quality));
+}
+
 bool CanvasRenderingContext2D::imageSmoothingEnabled() const
 {
     return state().imageSmoothingEnabled;
@@ -2540,7 +2599,7 @@
     modifiableState().imageSmoothingEnabled = enabled;
     GraphicsContext* c = drawingContext();
     if (c)
-        c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone);
+        c->setImageInterpolationQuality(enabled ? smoothingToInterpolationQuality(state().imageSmoothingQuality) : InterpolationNone);
 }
 
 } // namespace WebCore

Modified: branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (193417 => 193418)


--- branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2015-12-04 17:10:22 UTC (rev 193417)
+++ branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2015-12-04 17:10:26 UTC (rev 193418)
@@ -34,6 +34,7 @@
 #include "ColorSpace.h"
 #include "FloatSize.h"
 #include "FontCascade.h"
+#include "GraphicsContext.h"
 #include "GraphicsTypes.h"
 #include "ImageBuffer.h"
 #include "Path.h"
@@ -228,6 +229,15 @@
     bool imageSmoothingEnabled() const;
     void setImageSmoothingEnabled(bool);
 
+    String imageSmoothingQuality() const;
+    void setImageSmoothingQuality(const String&);
+
+    enum class SmoothingQuality {
+        Low,
+        Medium,
+        High
+    };
+
 private:
     enum class Direction {
         Inherit,
@@ -281,6 +291,7 @@
         Vector<float> lineDash;
         float lineDashOffset;
         bool imageSmoothingEnabled;
+        SmoothingQuality imageSmoothingQuality;
 
         // Text state.
         TextAlign textAlign;

Modified: branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (193417 => 193418)


--- branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2015-12-04 17:10:22 UTC (rev 193417)
+++ branches/safari-601-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2015-12-04 17:10:26 UTC (rev 193418)
@@ -23,6 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+enum ImageSmoothingQuality { "low", "medium", "high" };
 enum CanvasWindingRule { "nonzero", "evenodd" };
 
 interface CanvasRenderingContext2D : CanvasRenderingContext {
@@ -188,5 +189,6 @@
 
     attribute boolean imageSmoothingEnabled;
     [ImplementedAs=imageSmoothingEnabled] attribute boolean webkitImageSmoothingEnabled;
+    attribute ImageSmoothingQuality imageSmoothingQuality;
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to