Use CSS4 image-rendering to determing image scaling quality
authorallan.jensen@digia.com <allan.jensen@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2013 16:19:39 +0000 (16:19 +0000)
committerallan.jensen@digia.com <allan.jensen@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2013 16:19:39 +0000 (16:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=113405

Reviewed by Simon Fraser.

Source/WebCore:

Implement the new CSS4 image-rendering property values.

Image scaling now uses low-quality (pixelated) scaling for
crisp-edges, pixelated and optimizeSpeed values, and always
use high quality (smooth) scaling for -webkit-smooth and
optimizeQuality. The latter can be used to disable low quality
scaling during CSS animations or live resizing.

The new values are protected with a new CSS4_IMAGES feature, but
the crisp-edge value has been introduced before to displace the
deprecated -webkit-optimize-contrast value, and optimizeSpeed
and optimizeQuality values are supported for SVG compatibility.

* css/CSSParser.cpp:
(WebCore::isValidKeywordPropertyAndValue):
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator EImageRendering):
* css/CSSValueKeywords.in:
* rendering/RenderBoxModelObject.cpp:
(WebCore::ImageQualityController::shouldPaintAtLowQuality):
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::paintReplaced):
* rendering/style/RenderStyleConstants.h:

Tools:

Introduce new flag to enable experimental support for CSS4 Images.

* Scripts/webkitperl/FeatureList.pm:

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderHTMLCanvas.cpp
Source/WebCore/rendering/style/RenderStyleConstants.h
Tools/ChangeLog
Tools/Scripts/webkitperl/FeatureList.pm

index c3c99cd..cb15d6b 100644 (file)
@@ -1,3 +1,35 @@
+2013-04-04  Allan Sandfeld Jensen  <allan.jensen@digia.com>
+
+        Use CSS4 image-rendering to determing image scaling quality
+        https://bugs.webkit.org/show_bug.cgi?id=113405
+
+        Reviewed by Simon Fraser.
+
+        Implement the new CSS4 image-rendering property values.
+
+        Image scaling now uses low-quality (pixelated) scaling for
+        crisp-edges, pixelated and optimizeSpeed values, and always
+        use high quality (smooth) scaling for -webkit-smooth and
+        optimizeQuality. The latter can be used to disable low quality
+        scaling during CSS animations or live resizing.
+
+        The new values are protected with a new CSS4_IMAGES feature, but
+        the crisp-edge value has been introduced before to displace the
+        deprecated -webkit-optimize-contrast value, and optimizeSpeed
+        and optimizeQuality values are supported for SVG compatibility.
+
+        * css/CSSParser.cpp:
+        (WebCore::isValidKeywordPropertyAndValue):
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::operator EImageRendering):
+        * css/CSSValueKeywords.in:
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::ImageQualityController::shouldPaintAtLowQuality):
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::paintReplaced):
+        * rendering/style/RenderStyleConstants.h:
+
 2013-04-11  Adenilson Cavalcanti  <cavalcantii@gmail.com>
 
         Build fix: use of uninitialized variable in ScrollingStateTree
index 6f37d77..2d086f6 100644 (file)
@@ -726,9 +726,17 @@ static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int
         if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
             return true;
         break;
-    case CSSPropertyImageRendering: // auto | optimizeContrast
-        if (valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast)
+    case CSSPropertyImageRendering: // auto | crisp-edges | pixelated | -webkit-smooth | optimizeSpeed | optimizeQuality | -webkit-optimize-contrast
+#if ENABLE(CSS4_IMAGES)
+        if (valueID == CSSValueAuto || valueID == CSSValueCrispEdges || valueID == CSSValuePixelated
+            || valueID == CSSValueWebkitSmooth || valueID == CSSValueWebkitOptimizeContrast
+            || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality)
             return true;
+#else
+        if (valueID == CSSValueAuto || valueID == CSSValueCrispEdges || valueID == CSSValueWebkitOptimizeContrast
+            || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality)
+            return true;
+#endif
         break;
     case CSSPropertyListStylePosition: // inside | outside | inherit
         if (valueID == CSSValueInside || valueID == CSSValueOutside)
index b79a4e7..6b989b7 100644 (file)
@@ -4031,15 +4031,21 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EImageRendering e)
     case ImageRenderingAuto:
         m_value.ident = CSSValueAuto;
         break;
+    case ImageRenderingCrispEdges:
+        m_value.ident = CSSValueCrispEdges;
+        break;
+    case ImageRenderingPixelated:
+        m_value.ident = CSSValuePixelated;
+        break;
+    case ImageRenderingSmooth:
+        m_value.ident = CSSValueWebkitSmooth;
+        break;
     case ImageRenderingOptimizeSpeed:
         m_value.ident = CSSValueOptimizespeed;
         break;
     case ImageRenderingOptimizeQuality:
         m_value.ident = CSSValueOptimizequality;
         break;
-    case ImageRenderingOptimizeContrast:
-        m_value.ident = CSSValueWebkitOptimizeContrast;
-        break;
     }
 }
 
@@ -4048,12 +4054,17 @@ template<> inline CSSPrimitiveValue::operator EImageRendering() const
     switch (m_value.ident) {
     case CSSValueAuto:
         return ImageRenderingAuto;
+    case CSSValueWebkitOptimizeContrast:
+    case CSSValueCrispEdges:
+        return ImageRenderingCrispEdges;
+    case CSSValuePixelated:
+        return ImageRenderingPixelated;
+    case CSSValueWebkitSmooth:
+        return ImageRenderingSmooth;
     case CSSValueOptimizespeed:
         return ImageRenderingOptimizeSpeed;
     case CSSValueOptimizequality:
         return ImageRenderingOptimizeQuality;
-    case CSSValueWebkitOptimizeContrast:
-        return ImageRenderingOptimizeContrast;
     }
 
     ASSERT_NOT_REACHED();
index 25e0277..7234ba6 100644 (file)
@@ -932,8 +932,11 @@ on
 off
 
 // image-rendering
-//auto
-//optimizeSpeed
+// auto
+// optimizeSpeed
+crisp-edges
+pixelated
+-webkit-smooth
 optimizeQuality
 -webkit-optimize-contrast
 
index 12c89e7..490e2d7 100644 (file)
@@ -161,9 +161,18 @@ bool ImageQualityController::shouldPaintAtLowQuality(GraphicsContext* context, R
     if (!image || !image->isBitmapImage() || context->paintingDisabled())
         return false;
 
-    if (object->style()->imageRendering() == ImageRenderingOptimizeContrast)
+    switch (object->style()->imageRendering()) {
+    case ImageRenderingOptimizeSpeed:
+    case ImageRenderingCrispEdges:
+    case ImageRenderingPixelated:
         return true;
-    
+    case ImageRenderingOptimizeQuality:
+    case ImageRenderingSmooth:
+        return false;
+    case ImageRenderingAuto:
+        break;
+    }
+
     // Make sure to use the unzoomed image size, since if a full page zoom is in effect, the image
     // is actually being scaled.
     IntSize imageSize(image->width(), image->height());
index bfa1c4f..0c0796c 100644 (file)
@@ -68,7 +68,7 @@ void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
         }
     }
 
-    bool useLowQualityScale = style()->imageRendering() == ImageRenderingOptimizeContrast;
+    bool useLowQualityScale = style()->imageRendering() == ImageRenderingPixelated || style()->imageRendering() == ImageRenderingCrispEdges || style()->imageRendering() == ImageRenderingOptimizeSpeed;
     static_cast<HTMLCanvasElement*>(node())->paint(paintInfo.context, rect, useLowQualityScale);
 }
 
index ce932dd..85b794f 100644 (file)
@@ -479,7 +479,10 @@ enum TextOrientation { TextOrientationVerticalRight, TextOrientationUpright, Tex
 
 enum TextOverflow { TextOverflowClip = 0, TextOverflowEllipsis };
 
-enum EImageRendering { ImageRenderingAuto, ImageRenderingOptimizeSpeed, ImageRenderingOptimizeQuality, ImageRenderingOptimizeContrast };
+enum EImageRendering {
+    ImageRenderingAuto, ImageRenderingOptimizeSpeed, ImageRenderingOptimizeQuality,
+    ImageRenderingCrispEdges, ImageRenderingPixelated, ImageRenderingSmooth
+};
 
 enum ImageResolutionSource { ImageResolutionSpecified = 0, ImageResolutionFromImage };
 
index 47348ff..02dd85b 100644 (file)
@@ -1,3 +1,14 @@
+2013-04-04  Allan Sandfeld Jensen  <allan.jensen@digia.com>
+
+        Use CSS4 image-rendering to determing image scaling quality
+        https://bugs.webkit.org/show_bug.cgi?id=113405
+
+        Reviewed by Simon Fraser.
+
+        Introduce new flag to enable experimental support for CSS4 Images.
+
+        * Scripts/webkitperl/FeatureList.pm:
+
 2013-04-11  Ryosuke Niwa  <rniwa@webkit.org>
 
         Remove code for Chromium from wkbuild.py
index b140813..80552f4 100644 (file)
@@ -53,6 +53,7 @@ my (
     $css3ConditionalRulesSupport,
     $css3TextSupport,
     $css3TextLineBreakSupport,
+    $css4ImagesSupport,
     $cssBoxDecorationBreakSupport,
     $cssDeviceAdaptation,
     $cssExclusionsSupport,
@@ -198,6 +199,9 @@ my @features = (
     { option => "css3-text-line-break", desc => "Toggle CSS3 Text Line Break support",
       define => "ENABLE_CSS3_TEXT_LINE_BREAK", default => 0, value => \$css3TextLineBreakSupport },
 
+    { option => "css4-images", desc => "Toggle CSS4 Images support",
+      define => "ENABLE_CSS4_IMAGES", default => 0, value => \$css4ImagesSupport },
+
     { option => "css-box-decoration-break", desc => "Toggle CSS box-decoration-break support",
       define => "ENABLE_CSS_BOX_DECORATION_BREAK", default => 1, value => \$cssBoxDecorationBreakSupport },