Make ColorSpace an enum class
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Dec 2019 05:59:22 +0000 (05:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Dec 2019 05:59:22 +0000 (05:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204970

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-12-07
Reviewed by Sam Weinig.

Source/WebCore:

So it can be encoded and decoded through the IPC messages.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
* html/CustomPaintCanvas.cpp:
(WebCore::CustomPaintCanvas::copiedImage const):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::createImageBuffer const):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawTextInternal):
* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::drawImage):
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::drawPattern):
* platform/graphics/Color.cpp:
(WebCore::operator<<):
* platform/graphics/Color.h:
(WebCore::Color::Color):
* platform/graphics/ColorSpace.h:
(): Deleted.
* platform/graphics/CustomPaintImage.cpp:
(WebCore::CustomPaintImage::drawPattern):
* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::create):
(WebCore::ExtendedColor::cssText const):
* platform/graphics/ExtendedColor.h:
* platform/graphics/GradientImage.cpp:
(WebCore::GradientImage::drawPattern):
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::transformColorSpace):
* platform/graphics/ImageBuffer.h:
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::createCompatibleBuffer):
* platform/graphics/cg/ColorCG.cpp:
(WebCore::leakCGColor):
* platform/graphics/cg/GraphicsContextCG.h:
(WebCore::cachedCGColorSpace):
* platform/graphics/filters/FEFlood.h:
* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::drawLighting):
* platform/graphics/filters/FETile.cpp:
(WebCore::FETile::platformApplySoftware):
* platform/graphics/filters/FilterEffect.h:
* platform/graphics/filters/SourceGraphic.h:
(WebCore::SourceGraphic::SourceGraphic):
* platform/graphics/win/ImageBufferDirect2D.cpp:
(WebCore::ImageBuffer::createCompatibleBuffer):
* platform/mac/ThemeMac.mm:
(WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext):
* rendering/CSSFilter.cpp:
(WebCore::CSSFilter::buildReferenceFilter):
(WebCore::CSSFilter::build):
(WebCore::CSSFilter::apply):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
* rendering/RenderLayerBacking.cpp:
(WebCore::patternForTouchAction):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintProgressBar):
* rendering/svg/RenderSVGResourceClipper.cpp:
(WebCore::RenderSVGResourceClipper::applyClippingToContext):
* rendering/svg/RenderSVGResourceFilter.cpp:
(WebCore::RenderSVGResourceFilter::buildPrimitives const):
(WebCore::RenderSVGResourceFilter::applyResource):
(WebCore::RenderSVGResourceFilter::postApplyResource):
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::createMaskAndSwapContextForTextGradient):
* rendering/svg/RenderSVGResourceMasker.cpp:
(WebCore::RenderSVGResourceMasker::applyResource):
(WebCore::RenderSVGResourceMasker::drawContentIntoMaskImage):
* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::createTileImage const):
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::bufferForeground):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::drawPatternForContainer):
* svg/graphics/filters/SVGFEImage.cpp:
(WebCore::FEImage::platformApplySoftware):

Source/WebKit:

* Shared/WebCoreArgumentCoders.h:

Tools:

* TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp:
(TestWebKitAPI::TEST):
(TestWebKitAPI::makeColor):

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

42 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Source/WebCore/html/CustomPaintCanvas.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/platform/graphics/ColorSpace.h
Source/WebCore/platform/graphics/CustomPaintImage.cpp
Source/WebCore/platform/graphics/ExtendedColor.cpp
Source/WebCore/platform/graphics/ExtendedColor.h
Source/WebCore/platform/graphics/GradientImage.cpp
Source/WebCore/platform/graphics/ImageBuffer.cpp
Source/WebCore/platform/graphics/ImageBuffer.h
Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
Source/WebCore/platform/graphics/cg/ColorCG.cpp
Source/WebCore/platform/graphics/cg/GraphicsContextCG.h
Source/WebCore/platform/graphics/filters/FEFlood.h
Source/WebCore/platform/graphics/filters/FELighting.cpp
Source/WebCore/platform/graphics/filters/FETile.cpp
Source/WebCore/platform/graphics/filters/FilterEffect.h
Source/WebCore/platform/graphics/filters/SourceGraphic.h
Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp
Source/WebCore/platform/mac/ThemeMac.mm
Source/WebCore/rendering/CSSFilter.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp
Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp
Source/WebCore/rendering/svg/RenderSVGResourceMasker.cpp
Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp
Source/WebCore/rendering/svg/SVGRenderingContext.cpp
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebCore/svg/graphics/filters/SVGFEImage.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp

index ded8f8d..f4df189 100644 (file)
@@ -1,3 +1,89 @@
+2019-12-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Make ColorSpace an enum class
+        https://bugs.webkit.org/show_bug.cgi?id=204970
+
+        Reviewed by Sam Weinig.
+
+        So it can be encoded and decoded through the IPC messages.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
+        * html/CustomPaintCanvas.cpp:
+        (WebCore::CustomPaintCanvas::copiedImage const):
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::createImageBuffer const):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawTextInternal):
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::drawImage):
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::drawPattern):
+        * platform/graphics/Color.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/Color.h:
+        (WebCore::Color::Color):
+        * platform/graphics/ColorSpace.h:
+        (): Deleted.
+        * platform/graphics/CustomPaintImage.cpp:
+        (WebCore::CustomPaintImage::drawPattern):
+        * platform/graphics/ExtendedColor.cpp:
+        (WebCore::ExtendedColor::create):
+        (WebCore::ExtendedColor::cssText const):
+        * platform/graphics/ExtendedColor.h:
+        * platform/graphics/GradientImage.cpp:
+        (WebCore::GradientImage::drawPattern):
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::transformColorSpace):
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::createCompatibleBuffer):
+        * platform/graphics/cg/ColorCG.cpp:
+        (WebCore::leakCGColor):
+        * platform/graphics/cg/GraphicsContextCG.h:
+        (WebCore::cachedCGColorSpace):
+        * platform/graphics/filters/FEFlood.h:
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::drawLighting):
+        * platform/graphics/filters/FETile.cpp:
+        (WebCore::FETile::platformApplySoftware):
+        * platform/graphics/filters/FilterEffect.h:
+        * platform/graphics/filters/SourceGraphic.h:
+        (WebCore::SourceGraphic::SourceGraphic):
+        * platform/graphics/win/ImageBufferDirect2D.cpp:
+        (WebCore::ImageBuffer::createCompatibleBuffer):
+        * platform/mac/ThemeMac.mm:
+        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext):
+        * rendering/CSSFilter.cpp:
+        (WebCore::CSSFilter::buildReferenceFilter):
+        (WebCore::CSSFilter::build):
+        (WebCore::CSSFilter::apply):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::patternForTouchAction):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintProgressBar):
+        * rendering/svg/RenderSVGResourceClipper.cpp:
+        (WebCore::RenderSVGResourceClipper::applyClippingToContext):
+        * rendering/svg/RenderSVGResourceFilter.cpp:
+        (WebCore::RenderSVGResourceFilter::buildPrimitives const):
+        (WebCore::RenderSVGResourceFilter::applyResource):
+        (WebCore::RenderSVGResourceFilter::postApplyResource):
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::createMaskAndSwapContextForTextGradient):
+        * rendering/svg/RenderSVGResourceMasker.cpp:
+        (WebCore::RenderSVGResourceMasker::applyResource):
+        (WebCore::RenderSVGResourceMasker::drawContentIntoMaskImage):
+        * rendering/svg/RenderSVGResourcePattern.cpp:
+        (WebCore::RenderSVGResourcePattern::createTileImage const):
+        * rendering/svg/SVGRenderingContext.cpp:
+        (WebCore::SVGRenderingContext::bufferForeground):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::drawPatternForContainer):
+        * svg/graphics/filters/SVGFEImage.cpp:
+        (WebCore::FEImage::platformApplySoftware):
+
 2019-12-07  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Convert InlineLayoutUnit/Point/Rect to LayoutUnit/Point/Rect when crossing inline/block boundary
index 1e0922b..f502c6f 100644 (file)
@@ -651,10 +651,10 @@ static Color parseColorFunctionParameters(CSSParserTokenRange& range)
     ColorSpace colorSpace;
     switch (args.peek().id()) {
     case CSSValueSRGB:
-        colorSpace = ColorSpaceSRGB;
+        colorSpace = ColorSpace::SRGB;
         break;
     case CSSValueDisplayP3:
-        colorSpace = ColorSpaceDisplayP3;
+        colorSpace = ColorSpace::DisplayP3;
         break;
     default:
         return Color();
index 43d6a5a..f4b7707 100644 (file)
@@ -93,7 +93,7 @@ Image* CustomPaintCanvas::copiedImage() const
     if (!width() || !height())
         return nullptr;
 
-    m_copiedBuffer = ImageBuffer::create(size(), Unaccelerated, 1, ColorSpaceSRGB, nullptr);
+    m_copiedBuffer = ImageBuffer::create(size(), Unaccelerated, 1, ColorSpace::SRGB, nullptr);
     if (!m_copiedBuffer)
         return nullptr;
 
index eea964a..23d9b34 100644 (file)
@@ -888,7 +888,7 @@ void HTMLCanvasElement::createImageBuffer() const
     RenderingMode renderingMode = shouldAccelerate(size()) ? Accelerated : Unaccelerated;
 
     auto hostWindow = (document().view() && document().view()->root()) ? document().view()->root()->hostWindow() : nullptr;
-    setImageBuffer(ImageBuffer::create(size(), renderingMode, 1, ColorSpaceSRGB, hostWindow));
+    setImageBuffer(ImageBuffer::create(size(), renderingMode, 1, ColorSpace::SRGB, hostWindow));
 
 #if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
     if (m_context && m_context->is2d()) {
index 323dd4e..d76f17d 100644 (file)
@@ -545,7 +545,7 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
             fontProxy.drawBidiText(*c, textRun, location + offset, FontCascade::UseFallbackIfFontNotReady);
         }
 
-        auto maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), ColorSpaceSRGB, *c);
+        auto maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), ColorSpace::SRGB, *c);
         if (!maskImage)
             return;
 
index 9727743..3fa6d8a 100644 (file)
@@ -1640,7 +1640,7 @@ ExceptionOr<void> CanvasRenderingContext2DBase::drawImage(CanvasBase& sourceCanv
         didDrawEntireCanvas();
     } else if (state().globalComposite == CompositeOperator::Copy) {
         if (&sourceCanvas == &canvasBase()) {
-            if (auto copy = buffer->copyRectToBuffer(srcRect, ColorSpaceSRGB, *c)) {
+            if (auto copy = buffer->copyRectToBuffer(srcRect, ColorSpace::SRGB, *c)) {
                 clearCanvas();
                 c->drawImageBuffer(*copy, dstRect, { { }, srcRect.size() }, { state().globalComposite, state().globalBlend });
             }
index 2761a52..3ce1381 100644 (file)
@@ -301,7 +301,7 @@ void BitmapImage::drawPattern(GraphicsContext& ctxt, const FloatRect& destRect,
     }
 
     if (!m_cachedImage) {
-        auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(tileRect.size()), ColorSpaceSRGB, ctxt);
+        auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(tileRect.size()), ColorSpace::SRGB, ctxt);
         if (!buffer)
             return;
 
index 5f94529..ec143a0 100644 (file)
@@ -650,13 +650,13 @@ TextStream& operator<<(TextStream& ts, const Color& color)
 TextStream& operator<<(TextStream& ts, ColorSpace colorSpace)
 {
     switch (colorSpace) {
-    case ColorSpaceSRGB:
+    case ColorSpace::SRGB:
         ts << "sRGB";
         break;
-    case ColorSpaceLinearRGB:
+    case ColorSpace::LinearRGB:
         ts << "LinearRGB";
         break;
-    case ColorSpaceDisplayP3:
+    case ColorSpace::DisplayP3:
         ts << "DisplayP3";
         break;
     }
index 605357c..8e35e09 100644 (file)
@@ -385,7 +385,7 @@ inline bool RGBA::hasAlpha() const
 inline Color::Color(RGBA color, ColorSpace space)
 {
     setRGB(color.m_integer);
-    ASSERT_UNUSED(space, space == ColorSpaceSRGB);
+    ASSERT_UNUSED(space, space == ColorSpace::SRGB);
 }
 
 inline bool operator==(const Color& a, const Color& b)
index 11d017f..0aa274a 100644 (file)
 
 namespace WebCore {
 
-enum ColorSpace {
-    ColorSpaceSRGB,
-    ColorSpaceLinearRGB,
-    ColorSpaceDisplayP3
+enum class ColorSpace : uint8_t {
+    SRGB,
+    LinearRGB,
+    DisplayP3
 };
     
 } // namespace WebCore
index 6590415..8400515 100644 (file)
@@ -198,7 +198,7 @@ void CustomPaintImage::drawPattern(GraphicsContext& destContext, const FloatRect
     adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
     adjustedSrcRect.scale(xScale, yScale);
 
-    auto buffer = ImageBuffer::createCompatibleBuffer(adjustedSize, ColorSpaceSRGB, destContext);
+    auto buffer = ImageBuffer::createCompatibleBuffer(adjustedSize, ColorSpace::SRGB, destContext);
     if (!buffer)
         return;
     doCustomPaint(buffer->context(), adjustedSize);
index 2a3c83e..eb0e02d 100644 (file)
@@ -33,9 +33,9 @@
 
 namespace WebCore {
 
-Ref<ExtendedColor> ExtendedColor::create(float r, float g, float b, float a, ColorSpace colorSpace)
+Ref<ExtendedColor> ExtendedColor::create(float red, float green, float blue, float alpha, ColorSpace colorSpace)
 {
-    return adoptRef(*new ExtendedColor(r, g, b, a, colorSpace));
+    return adoptRef(*new ExtendedColor(red, green, blue, alpha, colorSpace));
 }
 
 String ExtendedColor::cssText() const
@@ -45,10 +45,10 @@ String ExtendedColor::cssText() const
     builder.appendLiteral("color(");
 
     switch (m_colorSpace) {
-    case ColorSpaceSRGB:
+    case ColorSpace::SRGB:
         builder.appendLiteral("srgb ");
         break;
-    case ColorSpaceDisplayP3:
+    case ColorSpace::DisplayP3:
         builder.appendLiteral("display-p3 ");
         break;
     default:
index 37c68ed..1277f94 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 
 class ExtendedColor : public RefCounted<ExtendedColor> {
 public:
-    static Ref<ExtendedColor> create(float r, float g, float b, float a, ColorSpace = ColorSpace::ColorSpaceSRGB);
+    static Ref<ExtendedColor> create(float red, float green, float blue, float alpha, ColorSpace = ColorSpace::SRGB);
 
     float red() const { return m_red; }
     float green() const { return m_green; }
@@ -60,7 +60,7 @@ private:
     float m_blue { 0 };
     float m_alpha { 0 };
 
-    ColorSpace m_colorSpace { ColorSpace::ColorSpaceSRGB };
+    ColorSpace m_colorSpace { ColorSpace::SRGB };
 };
 
 }
index f3ec0a1..08ba9c9 100644 (file)
@@ -71,7 +71,7 @@ void GradientImage::drawPattern(GraphicsContext& destContext, const FloatRect& d
     unsigned generatorHash = m_gradient->hash();
 
     if (!m_cachedImage || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !areEssentiallyEqual(destContext.scaleFactor(), m_cachedScaleFactor)) {
-        auto imageBuffer = ImageBuffer::createCompatibleBuffer(adjustedSize, ColorSpaceSRGB, destContext);
+        auto imageBuffer = ImageBuffer::createCompatibleBuffer(adjustedSize, ColorSpace::SRGB, destContext);
         if (!imageBuffer)
             return;
 
index fb536b3..0e8daf1 100644 (file)
@@ -126,11 +126,11 @@ void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
         return;
 
     // only sRGB <-> linearRGB are supported at the moment
-    if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceSRGB)
-        || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceSRGB))
+    if ((srcColorSpace != ColorSpace::LinearRGB && srcColorSpace != ColorSpace::SRGB)
+        || (dstColorSpace != ColorSpace::LinearRGB && dstColorSpace != ColorSpace::SRGB))
         return;
 
-    if (dstColorSpace == ColorSpaceLinearRGB) {
+    if (dstColorSpace == ColorSpace::LinearRGB) {
         static const std::array<uint8_t, 256> linearRgbLUT = [] {
             std::array<uint8_t, 256> array;
             for (unsigned i = 0; i < 256; i++) {
@@ -141,7 +141,7 @@ void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
             return array;
         }();
         platformTransformColorSpace(linearRgbLUT);
-    } else if (dstColorSpace == ColorSpaceSRGB) {
+    } else if (dstColorSpace == ColorSpace::SRGB) {
         static const std::array<uint8_t, 256> deviceRgbLUT= [] {
             std::array<uint8_t, 256> array;
             for (unsigned i = 0; i < 256; i++) {
index 2baa8e2..11880ca 100644 (file)
@@ -69,9 +69,9 @@ class ImageBuffer {
     friend class IOSurface;
 public:
     // Will return a null pointer on allocation failure.
-    WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, float resolutionScale = 1, ColorSpace = ColorSpaceSRGB, const HostWindow* = nullptr);
+    WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, float resolutionScale = 1, ColorSpace = ColorSpace::SRGB, const HostWindow* = nullptr);
 #if USE(DIRECT2D)
-    WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, const GraphicsContext*, float resolutionScale = 1, ColorSpace = ColorSpaceSRGB, const HostWindow* = nullptr);
+    WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, const GraphicsContext*, float resolutionScale = 1, ColorSpace = ColorSpace::SRGB, const HostWindow* = nullptr);
 #endif
 
     // Create an image buffer compatible with the context and copy rect from this buffer into this new one.
index 5e55f30..557106c 100644 (file)
@@ -321,7 +321,7 @@ ImageBuffer::~ImageBuffer() = default;
 
 std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context)
 {
-    return createCompatibleBuffer(size, ColorSpaceSRGB, context);
+    return createCompatibleBuffer(size, ColorSpace::SRGB, context);
 }
 
 GraphicsContext& ImageBuffer::context() const
index 109c640..cdffa3f 100644 (file)
@@ -111,11 +111,11 @@ static CGColorRef leakCGColor(const Color& color)
         components[2] = extendedColor.blue();
         components[3] = extendedColor.alpha();
         switch (extendedColor.colorSpace()) {
-        case ColorSpaceSRGB:
+        case ColorSpace::SRGB:
             return CGColorCreate(sRGBColorSpaceRef(), components);
-        case ColorSpaceDisplayP3:
+        case ColorSpace::DisplayP3:
             return CGColorCreate(displayP3ColorSpaceRef(), components);
-        case ColorSpaceLinearRGB:
+        case ColorSpace::LinearRGB:
             // FIXME: Do we ever create CGColorRefs in these spaces? It may only be ImageBuffers.
             return CGColorCreate(sRGBColorSpaceRef(), components);
         }
index d037040..5d59d15 100644 (file)
@@ -41,11 +41,11 @@ CGAffineTransform getUserToBaseCTM(CGContextRef);
 static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
 {
     switch (colorSpace) {
-    case ColorSpaceSRGB:
+    case ColorSpace::SRGB:
         return sRGBColorSpaceRef();
-    case ColorSpaceLinearRGB:
+    case ColorSpace::LinearRGB:
         return linearRGBColorSpaceRef();
-    case ColorSpaceDisplayP3:
+    case ColorSpace::DisplayP3:
         return displayP3ColorSpaceRef();
     }
     ASSERT_NOT_REACHED();
index 48c31a0..f6691e4 100644 (file)
@@ -40,8 +40,8 @@ public:
 #if !USE(CG)
     // feFlood does not perform color interpolation of any kind, so the result is always in the current
     // color space regardless of the value of color-interpolation-filters.
-    void setOperatingColorSpace(ColorSpace) override { FilterEffect::setResultColorSpace(ColorSpaceSRGB); }
-    void setResultColorSpace(ColorSpace) override { FilterEffect::setResultColorSpace(ColorSpaceSRGB); }
+    void setOperatingColorSpace(ColorSpace) override { FilterEffect::setResultColorSpace(ColorSpace::SRGB); }
+    void setResultColorSpace(ColorSpace) override { FilterEffect::setResultColorSpace(ColorSpace::SRGB); }
 #endif
 
 private:
index 707ead9..0ba51b7 100644 (file)
@@ -403,7 +403,7 @@ bool FELighting::drawLighting(Uint8ClampedArray& pixels, int width, int height)
     data.widthDecreasedByOne = width - 1;
     data.heightDecreasedByOne = height - 1;
     
-    FloatComponents lightColor = (operatingColorSpace() == ColorSpaceLinearRGB) ? sRGBColorToLinearComponents(m_lightingColor) : FloatComponents(m_lightingColor);
+    FloatComponents lightColor = (operatingColorSpace() == ColorSpace::LinearRGB) ? sRGBColorToLinearComponents(m_lightingColor) : FloatComponents(m_lightingColor);
     paintingData.initialLightingData.colorVector = FloatPoint3D(lightColor.components[0], lightColor.components[1], lightColor.components[2]);
     m_lightSource->initPaintingData(*this, paintingData);
 
index 707c6eb..1a80185 100644 (file)
@@ -64,7 +64,7 @@ void FETile::platformApplySoftware()
         tileRect.scale(filter.filterResolution().width(), filter.filterResolution().height());
     }
 
-    auto tileImage = SVGRenderingContext::createImageBuffer(tileRect, tileRect, ColorSpaceSRGB, filter().renderingMode());
+    auto tileImage = SVGRenderingContext::createImageBuffer(tileRect, tileRect, ColorSpace::SRGB, filter().renderingMode());
     if (!tileImage)
         return;
 
index 19f6fb4..c966fcc 100644 (file)
@@ -211,8 +211,8 @@ private:
     // Should the effect clip to its primitive region, or expand to use the combined region of its inputs.
     bool m_clipsToBounds { true };
 
-    ColorSpace m_operatingColorSpace { ColorSpaceLinearRGB };
-    ColorSpace m_resultColorSpace { ColorSpaceSRGB };
+    ColorSpace m_operatingColorSpace { ColorSpace::LinearRGB };
+    ColorSpace m_resultColorSpace { ColorSpace::SRGB };
 };
 
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const FilterEffect&);
index 3615f0e..428629b 100644 (file)
@@ -36,7 +36,7 @@ private:
     SourceGraphic(Filter& filter)
         : FilterEffect(filter)
     {
-        setOperatingColorSpace(ColorSpaceSRGB);
+        setOperatingColorSpace(ColorSpace::SRGB);
     }
 
     const char* filterName() const final { return "SourceGraphic"; }
index 55f3ce1..5e9cf05 100644 (file)
@@ -66,7 +66,7 @@ std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize
     RenderingMode renderingMode = context.renderingMode();
     IntSize scaledSize = ImageBuffer::compatibleBufferSize(size, context);
     bool success = false;
-    std::unique_ptr<ImageBuffer> buffer(new ImageBuffer(scaledSize, 1, ColorSpaceSRGB, renderingMode, nullptr, &context, success));
+    std::unique_ptr<ImageBuffer> buffer(new ImageBuffer(scaledSize, 1, ColorSpace::SRGB, renderingMode, nullptr, &context, success));
 
     if (!success)
         return nullptr;
index 272824e..66cb69b 100644 (file)
@@ -698,7 +698,7 @@ bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell *cell, GraphicsCont
     bool needsRepaint = false;
     if (useImageBuffer) {
         NSRect imageBufferDrawRect = NSRect(FloatRect(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, rect.width(), rect.height()));
-        auto imageBuffer = ImageBuffer::createCompatibleBuffer(rect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context);
+        auto imageBuffer = ImageBuffer::createCompatibleBuffer(rect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpace::SRGB, context);
         if (!imageBuffer)
             return needsRepaint;
         {
index 6d595a2..160257b 100644 (file)
@@ -121,7 +121,7 @@ RefPtr<FilterEffect> CSSFilter::buildReferenceFilter(RenderElement& renderer, Fi
 
         effectElement.setStandardAttributes(effect.get());
         if (effectElement.renderer())
-            effect->setOperatingColorSpace(effectElement.renderer()->style().svgStyle().colorInterpolationFilters() == ColorInterpolation::LinearRGB ? ColorSpaceLinearRGB : ColorSpaceSRGB);
+            effect->setOperatingColorSpace(effectElement.renderer()->style().svgStyle().colorInterpolationFilters() == ColorInterpolation::LinearRGB ? ColorSpace::LinearRGB : ColorSpace::SRGB);
 
         builder->add(effectElement.result(), effect);
         m_effects.append(*effect);
@@ -289,7 +289,7 @@ bool CSSFilter::build(RenderElement& renderer, const FilterOperations& operation
             // Unlike SVG Filters and CSSFilterImages, filter functions on the filter
             // property applied here should not clip to their primitive subregions.
             effect->setClipsToBounds(consumer == FilterConsumer::FilterFunction);
-            effect->setOperatingColorSpace(ColorSpaceSRGB);
+            effect->setOperatingColorSpace(ColorSpace::SRGB);
             
             if (filterOperation.type() != FilterOperation::REFERENCE) {
                 effect->inputEffects().append(WTFMove(previousEffect));
@@ -366,7 +366,7 @@ void CSSFilter::apply()
 {
     auto& effect = m_effects.last().get();
     effect.apply();
-    effect.transformResultColorSpace(ColorSpaceSRGB);
+    effect.transformResultColorSpace(ColorSpace::SRGB);
 }
 
 LayoutRect CSSFilter::computeSourceImageRectForDirtyRect(const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect)
index e5b7558..c8c7bf1 100644 (file)
@@ -861,7 +861,7 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
         maskRect.intersect(snappedIntRect(paintInfo.rect));
 
         // Now create the mask.
-        maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), ColorSpaceSRGB, context);
+        maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), ColorSpace::SRGB, context);
         if (!maskImage)
             return;
         paintMaskForTextFillBox(maskImage.get(), maskRect, box, scrolledPaintRect);
index d0828a2..8eb5bc2 100644 (file)
@@ -2927,7 +2927,7 @@ static RefPtr<Pattern> patternForTouchAction(TouchAction touchAction, FloatSize
 
     const FloatSize tileSize { 32, 18 };
 
-    auto imageBuffer = ImageBuffer::createCompatibleBuffer(tileSize, ColorSpaceSRGB, destContext);
+    auto imageBuffer = ImageBuffer::createCompatibleBuffer(tileSize, ColorSpace::SRGB, destContext);
     if (!imageBuffer)
         return nullptr;
 
index 6574b50..cd8af6e 100644 (file)
@@ -1471,7 +1471,7 @@ bool RenderThemeMac::paintProgressBar(const RenderObject& renderObject, const Pa
     trackInfo.reserved = 0;
     trackInfo.filler1 = 0;
 
-    std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size(), deviceScaleFactor, ColorSpaceSRGB, paintInfo.context());
+    std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size(), deviceScaleFactor, ColorSpace::SRGB, paintInfo.context());
     if (!imageBuffer)
         return true;
 
index cf5d35b..08e4928 100644 (file)
@@ -142,7 +142,7 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderElement& renderer, c
 
     if (shouldCreateClipperMaskImage && !repaintRect.isEmpty()) {
         // FIXME (149469): This image buffer should not be unconditionally unaccelerated. Making it match the context breaks nested clipping, though.
-        clipperMaskImage = SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, ColorSpaceSRGB, Unaccelerated, &context);
+        clipperMaskImage = SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, ColorSpace::SRGB, Unaccelerated, &context);
         if (!clipperMaskImage)
             return false;
 
index d823a02..75b59b6 100644 (file)
@@ -103,7 +103,7 @@ std::unique_ptr<SVGFilterBuilder> RenderSVGResourceFilter::buildPrimitives(SVGFi
         element.setStandardAttributes(effect.get());
         effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilterPrimitiveStandardAttributes>(&element, filterElement().primitiveUnits(), targetBoundingBox));
         if (element.renderer())
-            effect->setOperatingColorSpace(element.renderer()->style().svgStyle().colorInterpolationFilters() == ColorInterpolation::LinearRGB ? ColorSpaceLinearRGB : ColorSpaceSRGB);
+            effect->setOperatingColorSpace(element.renderer()->style().svgStyle().colorInterpolationFilters() == ColorInterpolation::LinearRGB ? ColorSpace::LinearRGB : ColorSpace::SRGB);
         builder->add(element.result(), WTFMove(effect));
     }
     return builder;
@@ -192,7 +192,7 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
     effectiveTransform.multiply(filterData->shearFreeAbsoluteTransform);
 
     RenderingMode renderingMode = renderer.settings().acceleratedFiltersEnabled() ? Accelerated : Unaccelerated;
-    auto sourceGraphic = SVGRenderingContext::createImageBuffer(filterData->drawingRegion, effectiveTransform, ColorSpaceLinearRGB, renderingMode, context);
+    auto sourceGraphic = SVGRenderingContext::createImageBuffer(filterData->drawingRegion, effectiveTransform, ColorSpace::LinearRGB, renderingMode, context);
     if (!sourceGraphic) {
         ASSERT(!m_rendererFilterDataMap.contains(&renderer));
         filterData->savedContext = context;
@@ -271,7 +271,7 @@ void RenderSVGResourceFilter::postApplyResource(RenderElement& renderer, Graphic
             filterData.state = FilterData::Applying;
             lastEffect->apply();
             lastEffect->correctFilterResultIfNeeded();
-            lastEffect->transformResultColorSpace(ColorSpaceSRGB);
+            lastEffect->transformResultColorSpace(ColorSpace::SRGB);
         }
         filterData.state = FilterData::Built;
 
index 552ce5a..cf3f9ea 100644 (file)
@@ -60,7 +60,7 @@ static inline bool createMaskAndSwapContextForTextGradient(GraphicsContext*& con
     AffineTransform absoluteTransform = SVGRenderingContext::calculateTransformationToOutermostCoordinateSystem(*textRootBlock);
     FloatRect repaintRect = textRootBlock->repaintRectInLocalCoordinates();
 
-    auto maskImage = SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, ColorSpaceSRGB, context->renderingMode());
+    auto maskImage = SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, ColorSpace::SRGB, context->renderingMode());
     if (!maskImage)
         return false;
 
index 4c819b9..1787e18 100644 (file)
@@ -69,7 +69,7 @@ bool RenderSVGResourceMasker::applyResource(RenderElement& renderer, const Rende
 
     if (!maskerData->maskImage && !repaintRect.isEmpty()) {
         const SVGRenderStyle& svgStyle = style().svgStyle();
-        ColorSpace colorSpace = svgStyle.colorInterpolation() == ColorInterpolation::LinearRGB ? ColorSpaceLinearRGB : ColorSpaceSRGB;
+        ColorSpace colorSpace = svgStyle.colorInterpolation() == ColorInterpolation::LinearRGB ? ColorSpace::LinearRGB : ColorSpace::SRGB;
         // FIXME (149470): This image buffer should not be unconditionally unaccelerated. Making it match the context breaks alpha masking, though.
         maskerData->maskImage = SVGRenderingContext::createImageBuffer(repaintRect, absoluteTransform, colorSpace, Unaccelerated, context);
         if (!maskerData->maskImage)
@@ -113,7 +113,7 @@ bool RenderSVGResourceMasker::drawContentIntoMaskImage(MaskerData* maskerData, C
     }
 
 #if !USE(CG)
-    maskerData->maskImage->transformColorSpace(ColorSpaceSRGB, colorSpace);
+    maskerData->maskImage->transformColorSpace(ColorSpace::SRGB, colorSpace);
 #else
     UNUSED_PARAM(colorSpace);
 #endif
index 31bc5f1..1c3c854 100644 (file)
@@ -255,7 +255,7 @@ bool RenderSVGResourcePattern::buildTileImageTransform(RenderElement& renderer,
 std::unique_ptr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const PatternAttributes& attributes, const FloatRect& tileBoundaries, const FloatRect& absoluteTileBoundaries, const AffineTransform& tileImageTransform, FloatRect& clampedAbsoluteTileBoundaries, RenderingMode renderingMode) const
 {
     clampedAbsoluteTileBoundaries = ImageBuffer::clampedRect(absoluteTileBoundaries);
-    auto tileImage = SVGRenderingContext::createImageBuffer(absoluteTileBoundaries, clampedAbsoluteTileBoundaries, ColorSpaceSRGB, renderingMode);
+    auto tileImage = SVGRenderingContext::createImageBuffer(absoluteTileBoundaries, clampedAbsoluteTileBoundaries, ColorSpace::SRGB, renderingMode);
     if (!tileImage)
         return nullptr;
 
index aa92d63..d78694a 100644 (file)
@@ -351,7 +351,7 @@ bool SVGRenderingContext::bufferForeground(std::unique_ptr<ImageBuffer>& imageBu
 
     // Create a new buffer and paint the foreground into it.
     if (!imageBuffer) {
-        if ((imageBuffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(boundingBox.size()), ColorSpaceSRGB, m_paintInfo->context()))) {
+        if ((imageBuffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(boundingBox.size()), ColorSpace::SRGB, m_paintInfo->context()))) {
             GraphicsContext& bufferedRenderingContext = imageBuffer->context();
             bufferedRenderingContext.translate(-boundingBox.location());
             PaintInfo bufferedInfo(*m_paintInfo);
index c3537e3..7e86079 100644 (file)
@@ -279,7 +279,7 @@ void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
     FloatRect imageBufferSize = zoomedContainerRect;
     imageBufferSize.scale(imageBufferScale.width(), imageBufferScale.height());
 
-    std::unique_ptr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(imageBufferSize.size()), 1, ColorSpaceSRGB, context);
+    std::unique_ptr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(imageBufferSize.size()), 1, ColorSpace::SRGB, context);
     if (!buffer) // Failed to allocate buffer.
         return;
     drawForContainer(buffer->context(), containerSize, containerZoom, initialFragmentURL, imageBufferSize, zoomedContainerRect);
index c584eb5..8f138a2 100644 (file)
@@ -93,8 +93,8 @@ void FEImage::platformApplySoftware()
     if (!m_image && !renderer)
         return;
 
-    // FEImage results are always in ColorSpaceSRGB
-    setResultColorSpace(ColorSpaceSRGB);
+    // FEImage results are always in ColorSpace::SRGB
+    setResultColorSpace(ColorSpace::SRGB);
 
     ImageBuffer* resultImage = createImageBufferResult();
     if (!resultImage)
index 9f2fd3e..e93b5ff 100644 (file)
@@ -1,3 +1,12 @@
+2019-12-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Make ColorSpace an enum class
+        https://bugs.webkit.org/show_bug.cgi?id=204970
+
+        Reviewed by Sam Weinig.
+
+        * Shared/WebCoreArgumentCoders.h:
+
 2019-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] WKWebView touch event gesture recognition should not block the application process main thread when possible
index 235d5e9..1711b68 100644 (file)
@@ -796,9 +796,9 @@ namespace WTF {
 template<> struct EnumTraits<WebCore::ColorSpace> {
     using values = EnumValues<
     WebCore::ColorSpace,
-    WebCore::ColorSpace::ColorSpaceSRGB,
-    WebCore::ColorSpace::ColorSpaceLinearRGB,
-    WebCore::ColorSpace::ColorSpaceDisplayP3
+    WebCore::ColorSpace::SRGB,
+    WebCore::ColorSpace::LinearRGB,
+    WebCore::ColorSpace::DisplayP3
     >;
 };
 
index 0e30081..8b9cbb9 100644 (file)
@@ -1,3 +1,14 @@
+2019-12-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Make ColorSpace an enum class
+        https://bugs.webkit.org/show_bug.cgi?id=204970
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/Tests/WebCore/ExtendedColor.cpp:
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::makeColor):
+
 2019-12-06  Jonathan Bedard  <jbedard@apple.com>
 
         Python 3: Add support in webkitpy.tool (Follow-up, part 2)
index 607777d..7512ad7 100644 (file)
@@ -35,7 +35,7 @@ namespace TestWebKitAPI {
 
 TEST(ExtendedColor, Constructor)
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
     EXPECT_FLOAT_EQ(1.0, c1.asExtended().red());
     EXPECT_FLOAT_EQ(0.5, c1.asExtended().green());
@@ -47,7 +47,7 @@ TEST(ExtendedColor, Constructor)
 
 TEST(ExtendedColor, CopyConstructor)
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
 
     Color c2(c1);
@@ -63,7 +63,7 @@ TEST(ExtendedColor, CopyConstructor)
 
 TEST(ExtendedColor, Assignment)
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
 
     Color c2 = c1;
@@ -79,7 +79,7 @@ TEST(ExtendedColor, Assignment)
 
 TEST(ExtendedColor, MoveConstructor)
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
 
     Color c2(WTFMove(c1));
@@ -98,7 +98,7 @@ TEST(ExtendedColor, MoveConstructor)
 
 TEST(ExtendedColor, MoveAssignment)
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
 
     Color c2 = WTFMove(c1);
@@ -118,7 +118,7 @@ TEST(ExtendedColor, MoveAssignment)
 
 TEST(ExtendedColor, BasicReferenceCounting)
 {
-    Color* c1 = new Color(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color* c1 = new Color(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1->isExtended());
 
     Color* c2 = new Color(*c1);
@@ -142,7 +142,7 @@ TEST(ExtendedColor, BasicReferenceCounting)
 
 Color makeColor()
 {
-    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpaceDisplayP3);
+    Color c1(1.0, 0.5, 0.25, 1.0, ColorSpace::DisplayP3);
     EXPECT_TRUE(c1.isExtended());
     EXPECT_EQ(1u, c1.asExtended().refCount());