Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (207264 => 207265)
--- trunk/Source/WebCore/CMakeLists.txt 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-10-13 01:14:15 UTC (rev 207265)
@@ -2203,6 +2203,7 @@
platform/graphics/Color.cpp
platform/graphics/CrossfadeGeneratedImage.cpp
platform/graphics/DisplayRefreshMonitorClient.cpp
+ platform/graphics/ExtendedColor.cpp
platform/graphics/FloatPoint.cpp
platform/graphics/FloatPoint3D.cpp
platform/graphics/FloatPolygon.cpp
Modified: trunk/Source/WebCore/ChangeLog (207264 => 207265)
--- trunk/Source/WebCore/ChangeLog 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/ChangeLog 2016-10-13 01:14:15 UTC (rev 207265)
@@ -1,3 +1,90 @@
+2016-10-11 Dean Jackson <[email protected]>
+
+ Add preliminary support for extended colors to WebCore::Color
+ https://bugs.webkit.org/show_bug.cgi?id=162878
+ <rdar://problem/28596413>
+
+ Reviewed by Darin Adler.
+
+ Add an ExtendedColor class that will hold the data necessary
+ for wider-than-sRGB (and more precise) colors. In order to
+ avoid increasing the size of Color, implement a tagged
+ pointer that is either referencing an ExtendedColor, or
+ is a 64-bit number with the top 32-bits being the RGBA, and
+ the bottom 2 bits indicating an invalid RGBA or a valid RGBA,
+ plus the tag.
+
+ Add copy constructors and operator= so that the new Color objects
+ are correctly copied.
+
+ There isn't yet a way to create an ExtendedColor. That's coming
+ in a followup patch (and will require changes to the CSS parser).
+
+ Covered by existing tests, and new API tests in Color.
+
+ * CMakeLists.txt:
+ * WebCore.xcodeproj/project.pbxproj: Add new files.
+
+ * platform/graphics/Color.cpp: Update everything to use m_rgbaAndFlags
+ instead of m_color + m_valid.
+ (WebCore::Color::Color):
+ (WebCore::Color::~Color):
+ (WebCore::Color::operator=):
+ (WebCore::Color::nameForRenderTreeAsText):
+ (WebCore::Color::setNamedColor):
+ (WebCore::Color::light):
+ (WebCore::Color::dark):
+ (WebCore::Color::setValid):
+ (WebCore::Color::setExtended):
+ (WebCore::Color::isExtended):
+ (WebCore::Color::asExtended):
+ * platform/graphics/Color.h: Implement the tagged union.
+ (WebCore::Color::Color):
+ (WebCore::Color::isValid):
+ (WebCore::Color::red):
+ (WebCore::Color::green):
+ (WebCore::Color::blue):
+ (WebCore::Color::alpha):
+ (WebCore::Color::rgb):
+ (WebCore::Color::setRGB):
+ (WebCore::operator==):
+
+ * platform/graphics/ExtendedColor.cpp: New file. Holds floating point
+ red, green, blue and alpha, plus a color space.
+ (WebCore::ExtendedColor::create):
+ (WebCore::ExtendedColor::~ExtendedColor):
+ (WebCore::ExtendedColor::ref):
+ (WebCore::ExtendedColor::deref):
+ * platform/graphics/ExtendedColor.h:
+ (WebCore::ExtendedColor::red):
+ (WebCore::ExtendedColor::green):
+ (WebCore::ExtendedColor::blue):
+ (WebCore::ExtendedColor::alpha):
+ (WebCore::ExtendedColor::colorSpace):
+ (WebCore::ExtendedColor::ExtendedColor):
+
+ * platform/graphics/cg/ColorCG.cpp: Update the constructors for
+ the platform specific color classes.
+ (WebCore::Color::Color):
+ * platform/graphics/gtk/ColorGtk.cpp:
+ (WebCore::Color::Color):
+ * platform/graphics/win/ColorDirect2D.cpp:
+ (WebCore::Color::Color):
+
+ * rendering/RenderEmbeddedObject.cpp: Use NeverDestroyed.
+ (WebCore::replacementTextRoundedRectPressedColor):
+ (WebCore::replacementTextRoundedRectColor):
+ (WebCore::replacementTextColor):
+ (WebCore::unavailablePluginBorderColor):
+
+ * rendering/RenderFrameSet.cpp: Ditto.
+ (WebCore::borderStartEdgeColor):
+ (WebCore::borderEndEdgeColor):
+ (WebCore::borderFillColor):
+
+ * rendering/RenderTableCell.cpp: This grows in size slightly
+ because it can no longer pack bits.
+
2016-10-12 Antoine Quint <[email protected]>
[Modern Media Controls] Sliders: scrubber and volume
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (207264 => 207265)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-10-13 01:14:15 UTC (rev 207265)
@@ -1381,6 +1381,8 @@
31C422461D74EB9A00F12342 /* JSPerformanceTimingCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31C422451D74EB9A00F12342 /* JSPerformanceTimingCustom.cpp */; };
31D591B316697A6C00E6BF02 /* PlugInClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 31D591B116697A6C00E6BF02 /* PlugInClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
31DCD29D1AB4FBDE0072E817 /* AnimationTrigger.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DCD29C1AB4FBDE0072E817 /* AnimationTrigger.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */; };
+ 31DCDF441DA1C45400EA5B93 /* ExtendedColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */; settings = {ATTRIBUTES = (Private, ); }; };
31DEA4551B39F4D900F77178 /* WebSystemBackdropLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 31DEA4531B39F4D900F77178 /* WebSystemBackdropLayer.mm */; };
31DEA4561B39F4D900F77178 /* WebSystemBackdropLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DEA4541B39F4D900F77178 /* WebSystemBackdropLayer.h */; };
31DF63571AF187DD0078FD91 /* NSColorSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DF63561AF187DD0078FD91 /* NSColorSPI.h */; };
@@ -8349,6 +8351,8 @@
31C422451D74EB9A00F12342 /* JSPerformanceTimingCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPerformanceTimingCustom.cpp; sourceTree = "<group>"; };
31D591B116697A6C00E6BF02 /* PlugInClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlugInClient.h; sourceTree = "<group>"; };
31DCD29C1AB4FBDE0072E817 /* AnimationTrigger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationTrigger.h; sourceTree = "<group>"; };
+ 31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
+ 31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendedColor.h; sourceTree = "<group>"; };
31DEA4531B39F4D900F77178 /* WebSystemBackdropLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSystemBackdropLayer.mm; sourceTree = "<group>"; };
31DEA4541B39F4D900F77178 /* WebSystemBackdropLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSystemBackdropLayer.h; sourceTree = "<group>"; };
31DF63561AF187DD0078FD91 /* NSColorSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorSPI.h; sourceTree = "<group>"; };
@@ -20733,6 +20737,8 @@
CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */,
B27535380B053814002CE64F /* Color.cpp */,
B27535390B053814002CE64F /* Color.h */,
+ 31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
+ 31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
9382DF5710A8D5C900925652 /* ColorSpace.h */,
2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */,
2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */,
@@ -24928,6 +24934,7 @@
510192D618B6B9B7007FC7A1 /* ImageControlsRootElement.h in Headers */,
510192D218B6B9AB007FC7A1 /* ImageControlsRootElementMac.h in Headers */,
A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */,
+ 31DCDF441DA1C45400EA5B93 /* ExtendedColor.h in Headers */,
555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */,
97205AB61239291000B17380 /* ImageDocument.h in Headers */,
F55B3DC21251F12D003EF269 /* ImageInputType.h in Headers */,
@@ -30376,6 +30383,7 @@
B2227AEF0D00BF220071B782 /* SVGViewElement.cpp in Sources */,
B2227AF20D00BF220071B782 /* SVGViewSpec.cpp in Sources */,
8485228A1190173C006EDC7F /* SVGVKernElement.cpp in Sources */,
+ 31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */,
B2227AF50D00BF220071B782 /* SVGZoomAndPan.cpp in Sources */,
B2E4EC970D00C22B00432643 /* SVGZoomEvent.cpp in Sources */,
E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */,
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -225,10 +225,16 @@
Color::Color(const String& name)
{
if (name[0] == '#') {
+ RGBA32 color;
+ bool valid;
+
if (name.is8Bit())
- m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color);
+ valid = parseHexColor(name.characters8() + 1, name.length() - 1, color);
else
- m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
+ valid = parseHexColor(name.characters16() + 1, name.length() - 1, color);
+
+ if (valid)
+ setRGB(color);
} else
setNamedColor(name);
}
@@ -235,15 +241,64 @@
Color::Color(const char* name)
{
+ RGBA32 color;
+ bool valid;
if (name[0] == '#')
- m_valid = parseHexColor((String)&name[1], m_color);
+ valid = parseHexColor((String)&name[1], color);
else {
const NamedColor* foundColor = findColor(name, strlen(name));
- m_color = foundColor ? foundColor->ARGBValue : 0;
- m_valid = foundColor;
+ color = foundColor ? foundColor->ARGBValue : 0;
+ valid = foundColor;
}
+
+ if (valid)
+ setRGB(color);
}
+Color::Color(const Color& other)
+ : m_colorData(other.m_colorData)
+{
+ if (isExtended())
+ m_colorData.extendedColor->ref();
+}
+
+Color::Color(Color&& other)
+{
+ *this = WTFMove(other);
+}
+
+Color::~Color()
+{
+ if (isExtended())
+ m_colorData.extendedColor->deref();
+}
+
+Color& Color::operator=(const Color& other)
+{
+ if (*this == other)
+ return *this;
+
+ if (isExtended())
+ m_colorData.extendedColor->deref();
+
+ m_colorData = other.m_colorData;
+
+ if (isExtended())
+ m_colorData.extendedColor->ref();
+ return *this;
+}
+
+Color& Color::operator=(Color&& other)
+{
+ if (*this == other)
+ return *this;
+
+ m_colorData = other.m_colorData;
+ other.m_colorData.rgbaAndFlags = invalidRGBAColor;
+
+ return *this;
+}
+
String Color::serialized() const
{
if (!hasAlpha()) {
@@ -291,6 +346,7 @@
String Color::nameForRenderTreeAsText() const
{
+ // FIXME: Handle ExtendedColors.
if (alpha() < 0xFF)
return String::format("#%02X%02X%02X%02X", red(), green(), blue(), alpha());
return String::format("#%02X%02X%02X", red(), green(), blue());
@@ -315,14 +371,16 @@
void Color::setNamedColor(const String& name)
{
const NamedColor* foundColor = findNamedColor(name);
- m_color = foundColor ? foundColor->ARGBValue : 0;
- m_valid = foundColor;
+ if (foundColor)
+ setRGB(foundColor->ARGBValue);
+ else
+ m_colorData.rgbaAndFlags = invalidRGBAColor;
}
Color Color::light() const
{
// Hardcode this common case for speed.
- if (m_color == black)
+ if (rgb() == black)
return lightenedBlack;
const float scaleFactor = nextafterf(256.0f, 0.0f);
@@ -347,7 +405,7 @@
Color Color::dark() const
{
// Hardcode this common case for speed.
- if (m_color == white)
+ if (rgb() == white)
return darkenedWhite;
const float scaleFactor = nextafterf(256.0f, 0.0f);
@@ -561,4 +619,30 @@
return ts << color.nameForRenderTreeAsText();
}
+void Color::tagAsValid()
+{
+ m_colorData.rgbaAndFlags |= validRGBAColor;
+}
+
+void Color::tagAsExtended()
+{
+ // FIXME: Is this method necessary? Will colors ever change from RGBA32 to Extended?
+ // Valid colors should not change type.
+ ASSERT(!isValid());
+ m_colorData.rgbaAndFlags &= ~(invalidRGBAColor);
+}
+
+bool Color::isExtended() const
+{
+ return !(m_colorData.rgbaAndFlags & invalidRGBAColor);
+}
+
+ExtendedColor* Color::asExtended() const
+{
+ ASSERT(isExtended());
+ if (!isExtended())
+ return nullptr;
+ return m_colorData.extendedColor;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/Color.h (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/Color.h 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2016-10-13 01:14:15 UTC (rev 207265)
@@ -23,10 +23,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef Color_h
-#define Color_h
+#pragma once
#include "ColorSpace.h"
+#include "ExtendedColor.h"
#include "PlatformExportMacros.h"
#include <algorithm>
#include <cmath>
@@ -107,19 +107,48 @@
class Color {
WTF_MAKE_FAST_ALLOCATED;
public:
- Color() : m_color(0), m_valid(false) { }
- Color(RGBA, ColorSpace);
+ Color() { }
// FIXME: Remove all these constructors and creation functions and replace the ones that are still needed with free functions.
- Color(RGBA32 color, bool valid = true) : m_color(color), m_valid(valid) { ASSERT(!m_color || m_valid); }
- Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
- Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
- // Color is currently limited to 32bit RGBA, perhaps some day we'll support better colors
- Color(float r, float g, float b, float a) : m_color(makeRGBA32FromFloats(r, g, b, a)), m_valid(true) { }
+
+ Color(RGBA32 color, bool valid = true)
+ {
+ if (valid)
+ setRGB(color);
+ }
+
+ Color(int r, int g, int b)
+ {
+ setRGB(r, g, b);
+ }
+
+ Color(int r, int g, int b, int a)
+ {
+ setRGB(makeRGBA(r, g, b, a));
+ }
+
+ Color(float r, float g, float b, float a)
+ {
+ setRGB(makeRGBA32FromFloats(r, g, b, a));
+ }
+
// Creates a new color from the specific CMYK and alpha values.
- Color(float c, float m, float y, float k, float a) : m_color(makeRGBAFromCMYKA(c, m, y, k, a)), m_valid(true) { }
+ Color(float c, float m, float y, float k, float a)
+ {
+ setRGB(makeRGBAFromCMYKA(c, m, y, k, a));
+ }
+
WEBCORE_EXPORT explicit Color(const String&);
explicit Color(const char*);
+
+ // FIXME: Add constructor for ExtendedColor type.
+
+ Color(RGBA, ColorSpace);
+ WEBCORE_EXPORT Color(const Color&);
+ WEBCORE_EXPORT Color(Color&&);
+
+ WEBCORE_EXPORT ~Color();
+
static Color createUnchecked(int r, int g, int b)
{
RGBA32 color = 0xFF000000 | r << 16 | g << 8 | b;
@@ -143,19 +172,19 @@
void setNamedColor(const String&);
- // FIXME: Remove this after moving clients to all use OptionalColor instead.
- bool isValid() const { return m_valid; }
+ bool isValid() const { return m_colorData.rgbaAndFlags & validRGBAColorBit; }
bool hasAlpha() const { return alpha() < 255; }
- int red() const { return redChannel(m_color); }
- int green() const { return greenChannel(m_color); }
- int blue() const { return blueChannel(m_color); }
- int alpha() const { return alphaChannel(m_color); }
+ int red() const { return redChannel(rgb()); }
+ int green() const { return greenChannel(rgb()); }
+ int blue() const { return blueChannel(rgb()); }
+ int alpha() const { return alphaChannel(rgb()); }
- RGBA32 rgb() const { return m_color; } // Preserve the alpha.
- void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
- void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
+ RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); }
+ void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
+ void setRGB(RGBA32);
+
WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
WEBCORE_EXPORT void getRGBA(double& r, double& g, double& b, double& a) const;
WEBCORE_EXPORT void getHSL(double& h, double& s, double& l) const;
@@ -208,9 +237,31 @@
static const RGBA32 compositionFill = 0xFFE1DD55;
#endif
+ WEBCORE_EXPORT bool isExtended() const;
+ WEBCORE_EXPORT ExtendedColor* asExtended() const;
+
+ WEBCORE_EXPORT Color& operator=(const Color&);
+ WEBCORE_EXPORT Color& operator=(Color&&);
+
+ friend bool operator==(const Color& a, const Color& b);
+
private:
- RGBA32 m_color;
- bool m_valid;
+
+ // 0x_______00 is an ExtendedColor pointer.
+ // 0x_______01 is an invalid RGBA32.
+ // 0x_______11 is a valid RGBA32.
+ static const uint64_t extendedColor = 0x0;
+ static const uint64_t invalidRGBAColor = 0x1;
+ static const uint64_t validRGBAColorBit = 0x2;
+ static const uint64_t validRGBAColor = 0x3;
+
+ WEBCORE_EXPORT void tagAsValid();
+ void tagAsExtended();
+
+ union {
+ uint64_t rgbaAndFlags { invalidRGBAColor };
+ ExtendedColor* extendedColor;
+ } m_colorData;
};
bool operator==(const Color&, const Color&);
@@ -270,15 +321,14 @@
}
inline Color::Color(RGBA color, ColorSpace space)
- : m_color(color.m_integer)
- , m_valid(true)
{
+ setRGB(color.m_integer);
ASSERT_UNUSED(space, space == ColorSpaceSRGB);
}
inline bool operator==(const Color& a, const Color& b)
{
- return a.rgb() == b.rgb() && a.isValid() == b.isValid();
+ return a.m_colorData.rgbaAndFlags == b.m_colorData.rgbaAndFlags;
}
inline bool operator!=(const Color& a, const Color& b)
@@ -315,8 +365,12 @@
return overrideAlpha ? colorWithOverrideAlpha(color, overrideAlpha.value()) : color;
}
+inline void Color::setRGB(RGBA32 rgb)
+{
+ m_colorData.rgbaAndFlags = static_cast<uint64_t>(rgb) << 32;
+ tagAsValid();
+}
+
WEBCORE_EXPORT TextStream& operator<<(TextStream&, const Color&);
} // namespace WebCore
-
-#endif // Color_h
Copied: trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp (from rev 207263, trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp) (0 => 207265)
--- trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016 Apple 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 INC. ``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 INC. OR
+ * 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"
+#include "ExtendedColor.h"
+
+#include "ColorSpace.h"
+
+namespace WebCore {
+
+Ref<ExtendedColor> ExtendedColor::create(float r, float g, float b, float a, ColorSpace colorSpace)
+{
+ return adoptRef(*new ExtendedColor(r, g, b, a, colorSpace));
+}
+
+}
Copied: trunk/Source/WebCore/platform/graphics/ExtendedColor.h (from rev 207263, trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp) (0 => 207265)
--- trunk/Source/WebCore/platform/graphics/ExtendedColor.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.h 2016-10-13 01:14:15 UTC (rev 207265)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 Apple 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 INC. ``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 INC. OR
+ * 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.
+ */
+
+#pragma once
+
+#include "ColorSpace.h"
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class ExtendedColor : public RefCounted<ExtendedColor> {
+public:
+ static Ref<ExtendedColor> create(float r, float g, float b, float a, ColorSpace = ColorSpace::ColorSpaceSRGB);
+
+ float red() const { return m_red; }
+ float green() const { return m_green; }
+ float blue() const { return m_blue; }
+ float alpha() const { return m_alpha; }
+
+ ColorSpace colorSpace() const { return m_colorSpace; }
+
+private:
+ ExtendedColor(float r, float g, float b, float a, ColorSpace colorSpace)
+ : m_red(r)
+ , m_green(g)
+ , m_blue(b)
+ , m_alpha(a)
+ , m_colorSpace(colorSpace)
+ { }
+
+ float m_red { 0 };
+ float m_green { 0 };
+ float m_blue { 0 };
+ float m_alpha { 0 };
+
+ ColorSpace m_colorSpace { ColorSpace::ColorSpaceSRGB };
+};
+
+}
Modified: trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -1371,8 +1371,8 @@
// Use having a transform as a key to making the tile wash layer. If every layer gets a wash,
// they start to obscure useful information.
if ((!m_transform.isIdentity() || m_usingTiledBacking) && !m_visibleTileWashLayer) {
- static Color washFillColor(255, 0, 0, 50);
- static Color washBorderColor(255, 0, 0, 100);
+ static NeverDestroyed<Color> washFillColor(255, 0, 0, 50);
+ static NeverDestroyed<Color> washBorderColor(255, 0, 0, 100);
m_visibleTileWashLayer = createPlatformCALayer(PlatformCALayer::LayerTypeLayer, this);
String name = String::format("Visible Tile Wash Layer %p", m_visibleTileWashLayer->platformLayer());
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -73,8 +73,7 @@
Color::Color(CGColorRef color)
{
if (!color) {
- m_color = 0;
- m_valid = false;
+ m_colorData.rgbaAndFlags = invalidRGBAColor;
return;
}
@@ -111,8 +110,7 @@
ASSERT_NOT_REACHED();
}
- m_color = makeRGBA(r * 255, g * 255, b * 255, a * 255);
- m_valid = true;
+ setRGB(makeRGBA(r * 255, g * 255, b * 255, a * 255));
}
static CGColorRef leakCGColor(const Color& color)
Modified: trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -26,19 +26,17 @@
namespace WebCore {
Color::Color(const GdkColor& c)
- : m_color(makeRGB(c.red >> 8, c.green >> 8, c.blue >> 8))
- , m_valid(true)
{
+ setRGB(makeRGB(c.red >> 8, c.green >> 8, c.blue >> 8));
}
#ifndef GTK_API_VERSION_2
Color::Color(const GdkRGBA& c)
- : m_color(makeRGBA(static_cast<int>(c.red * 255),
- static_cast<int>(c.green * 255),
- static_cast<int>(c.blue * 255),
- static_cast<int>(c.alpha * 255)))
- , m_valid(true)
{
+ setRGB(makeRGBA(static_cast<int>(c.red * 255),
+ static_cast<int>(c.green * 255),
+ static_cast<int>(c.blue * 255),
+ static_cast<int>(c.alpha * 255)));
}
Color::operator GdkRGBA() const
Modified: trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp (207264 => 207265)
--- trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -35,8 +35,7 @@
Color::Color(D2D1_COLOR_F color)
{
- m_color = makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255);
- m_valid = true;
+ setRGB(makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255));
}
Color::operator D2D1_COLOR_F() const
Modified: trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp (207264 => 207265)
--- trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -75,25 +75,25 @@
static const Color& replacementTextRoundedRectPressedColor()
{
- static const Color pressed(105, 105, 105, 242);
+ static NeverDestroyed<Color> pressed(105, 105, 105, 242);
return pressed;
}
static const Color& replacementTextRoundedRectColor()
{
- static const Color standard(125, 125, 125, 242);
+ static NeverDestroyed<Color> standard(125, 125, 125, 242);
return standard;
}
static const Color& replacementTextColor()
{
- static const Color standard(240, 240, 240, 255);
+ static NeverDestroyed<Color> standard(240, 240, 240, 255);
return standard;
}
static const Color& unavailablePluginBorderColor()
{
- static const Color standard(255, 255, 255, 216);
+ static NeverDestroyed<Color> standard(255, 255, 255, 216);
return standard;
}
Modified: trunk/Source/WebCore/rendering/RenderFrameSet.cpp (207264 => 207265)
--- trunk/Source/WebCore/rendering/RenderFrameSet.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/rendering/RenderFrameSet.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -69,19 +69,19 @@
static const Color& borderStartEdgeColor()
{
- static const Color color(170, 170, 170);
+ static NeverDestroyed<Color> color(170, 170, 170);
return color;
}
static const Color& borderEndEdgeColor()
{
- static const Color color = Color::black;
+ static NeverDestroyed<Color> color = Color::black;
return color;
}
static const Color& borderFillColor()
{
- static const Color color(208, 208, 208);
+ static NeverDestroyed<Color> color(208, 208, 208);
return color;
}
Modified: trunk/Source/WebCore/rendering/RenderTableCell.cpp (207264 => 207265)
--- trunk/Source/WebCore/rendering/RenderTableCell.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/rendering/RenderTableCell.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -52,7 +52,7 @@
};
COMPILE_ASSERT(sizeof(RenderTableCell) == sizeof(SameSizeAsRenderTableCell), RenderTableCell_should_stay_small);
-COMPILE_ASSERT(sizeof(CollapsedBorderValue) == 16, CollapsedBorderValue_should_stay_small);
+COMPILE_ASSERT(sizeof(CollapsedBorderValue) <= 24, CollapsedBorderValue_should_stay_small);
RenderTableCell::RenderTableCell(Element& element, RenderStyle&& style)
: RenderBlockFlow(element, WTFMove(style))
Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (207264 => 207265)
--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2016-10-13 01:14:15 UTC (rev 207265)
@@ -325,7 +325,7 @@
const Color& RenderThemeIOS::shadowColor() const
{
- static Color color(0.0f, 0.0f, 0.0f, 0.7f);
+ static NeverDestroyed<Color> color(0.0f, 0.0f, 0.0f, 0.7f);
return color;
}
Modified: trunk/Source/WebKit/mac/WebView/WebIndicateLayer.mm (207264 => 207265)
--- trunk/Source/WebKit/mac/WebView/WebIndicateLayer.mm 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Source/WebKit/mac/WebView/WebIndicateLayer.mm 2016-10-13 01:14:15 UTC (rev 207265)
@@ -32,6 +32,7 @@
#import <WebCore/ColorMac.h>
#import <WebCore/QuartzCoreSPI.h>
#import <WebCore/WAKWindow.h>
+#import <wtf/NeverDestroyed.h>
using namespace WebCore;
@@ -49,7 +50,7 @@
self.contentsScale = [[_webView window] screenScale];
// Blue highlight color.
- static Color highlightColor(111.0f / 255.0f, 168.0f / 255.0f, 220.0f / 255.0f, 0.66f);
+ static NeverDestroyed<Color> highlightColor(111.0f / 255.0f, 168.0f / 255.0f, 220.0f / 255.0f, 0.66f);
self.backgroundColor = cachedCGColor(highlightColor);
return self;
Modified: trunk/Tools/ChangeLog (207264 => 207265)
--- trunk/Tools/ChangeLog 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Tools/ChangeLog 2016-10-13 01:14:15 UTC (rev 207265)
@@ -1,3 +1,16 @@
+2016-10-11 Dean Jackson <[email protected]>
+
+ Add preliminary support for extended colors to WebCore::Color
+ https://bugs.webkit.org/show_bug.cgi?id=162878
+ <rdar://problem/28596413>
+
+ Reviewed by Darin Adler.
+
+ A new API test for Colors.
+
+ * TestWebKitAPI/Tests/WebCore/Color.cpp:
+ (TestWebKitAPI::TEST):
+
2016-10-12 Ryan Haddad <[email protected]>
Unreviewed, rolling out r207225.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp (207264 => 207265)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp 2016-10-13 00:07:28 UTC (rev 207264)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp 2016-10-13 01:14:15 UTC (rev 207265)
@@ -144,4 +144,47 @@
EXPECT_DOUBLE_EQ(0.75294117647058822, v);
}
+TEST(Color, Validity)
+{
+ Color invalidColor;
+ EXPECT_FALSE(invalidColor.isValid());
+ EXPECT_FALSE(invalidColor.isExtended());
+
+ Color otherInvalidColor = invalidColor;
+ EXPECT_FALSE(otherInvalidColor.isValid());
+ EXPECT_FALSE(otherInvalidColor.isExtended());
+
+ Color validColor(255, 0, 0);
+ EXPECT_TRUE(validColor.isValid());
+ EXPECT_FALSE(validColor.isExtended());
+
+ Color otherValidColor = validColor;
+ EXPECT_TRUE(otherValidColor.isValid());
+ EXPECT_FALSE(otherValidColor.isExtended());
+
+ validColor = Color(1, 2, 3, 4);
+ EXPECT_TRUE(validColor.isValid());
+ EXPECT_FALSE(validColor.isExtended());
+ EXPECT_EQ(validColor.red(), 1);
+ EXPECT_EQ(validColor.green(), 2);
+ EXPECT_EQ(validColor.blue(), 3);
+ EXPECT_EQ(validColor.alpha(), 4);
+
+ Color yetAnotherValidColor(WTFMove(validColor));
+ EXPECT_TRUE(yetAnotherValidColor.isValid());
+ EXPECT_FALSE(yetAnotherValidColor.isExtended());
+ EXPECT_EQ(yetAnotherValidColor.red(), 1);
+ EXPECT_EQ(yetAnotherValidColor.green(), 2);
+ EXPECT_EQ(yetAnotherValidColor.blue(), 3);
+ EXPECT_EQ(yetAnotherValidColor.alpha(), 4);
+
+ otherValidColor = WTFMove(yetAnotherValidColor);
+ EXPECT_TRUE(otherValidColor.isValid());
+ EXPECT_FALSE(otherValidColor.isExtended());
+ EXPECT_EQ(otherValidColor.red(), 1);
+ EXPECT_EQ(otherValidColor.green(), 2);
+ EXPECT_EQ(otherValidColor.blue(), 3);
+ EXPECT_EQ(otherValidColor.alpha(), 4);
+}
+
} // namespace TestWebKitAPI