RESOLVED FIXED Bug 222110
color(lab ...) should serialize as color(lab ...) not lab() according to latest CSS Color 4 spec
https://bugs.webkit.org/show_bug.cgi?id=222110
Summary color(lab ...) should serialize as color(lab ...) not lab() according to late...
Sam Weinig
Reported 2021-02-18 08:55:55 PST
color(lab ...) should serialize as color(lab ...) not lab() according to latest CSS Color 4 spec.
Attachments
Patch (57.45 KB, patch)
2021-02-18 20:03 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (57.54 KB, patch)
2021-02-18 20:09 PST, Sam Weinig
no flags
Patch (62.75 KB, patch)
2021-02-20 10:34 PST, Sam Weinig
no flags
Sam Weinig
Comment 1 2021-02-18 08:59:20 PST
I'm going to take this opportunity to add some new functionality to WebCore::Color to have it store a bit saying whether to use the color(...) serialization or default serialization for an underlying color type. For some color types (like DisplayP3, for instance), the default is the color(...) serialization, so this bit won't have any effect, but it will allow us to do the optimization I have been wanting to do for a while to store color(srgb ...) colors that can be represented as SRGBA<uint8_t> losslessly in the efficient form and still retain the correct serialization.
Sam Weinig
Comment 2 2021-02-18 20:03:03 PST
Sam Weinig
Comment 3 2021-02-18 20:09:47 PST
Sam Weinig
Comment 4 2021-02-18 20:10:22 PST
I'm not sure how I feel about this change. It turned out bigger than I anticipated.
Dean Jackson
Comment 5 2021-02-19 04:05:30 PST
Comment on attachment 420911 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=420911&action=review > Source/WebCore/platform/graphics/Color.cpp:129 > + auto result = colorWithOverridenAlpha(underlyingColor, alpha); Not new in this patch, but there is a typo in Overridden. > Source/WebCore/platform/graphics/Color.h:198 > + enum class AllFlags { It is common to have this All* enum? I would have thought you call this one Flags and the earlier one FlagsSubset or something?
Darin Adler
Comment 6 2021-02-19 08:52:14 PST
Comment on attachment 420911 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=420911&action=review > Source/WebCore/platform/graphics/Color.h:85 > + Color(SRGBA<uint8_t>, OptionSet<Flags>); > + Color(Optional<SRGBA<uint8_t>>, OptionSet<Flags>); Could we use default values for the flags to reduce the total number of constructors? Would not want to sacrifice runtime efficiency, but would love to have the list be much shorter.
Darin Adler
Comment 7 2021-02-19 08:52:54 PST
(In reply to Sam Weinig from comment #1) > I'm going to take this opportunity to add some new functionality to > WebCore::Color to have it store a bit saying whether to use the color(...) > serialization or default serialization for an underlying color type. > > For some color types (like DisplayP3, for instance), the default is the > color(...) serialization, so this bit won't have any effect, but it will > allow us to do the optimization I have been wanting to do for a while to > store color(srgb ...) colors that can be represented as SRGBA<uint8_t> > losslessly in the efficient form and still retain the correct serialization. I don’t understand why this is separate state in the Color object rather than a property of the color space.
Sam Weinig
Comment 8 2021-02-19 11:04:11 PST
(In reply to Darin Adler from comment #7) > (In reply to Sam Weinig from comment #1) > > I'm going to take this opportunity to add some new functionality to > > WebCore::Color to have it store a bit saying whether to use the color(...) > > serialization or default serialization for an underlying color type. > > > > For some color types (like DisplayP3, for instance), the default is the > > color(...) serialization, so this bit won't have any effect, but it will > > allow us to do the optimization I have been wanting to do for a while to > > store color(srgb ...) colors that can be represented as SRGBA<uint8_t> > > losslessly in the efficient form and still retain the correct serialization. > > I don’t understand why this is separate state in the Color object rather > than a property of the color space. Currently, color spaces don't have any additional state, so I used the fact that Color does have extra state and serialization always goes through Color to store it. Another approach would be to add new values to the ColorSpace enum (and unfortunately new color types as well, since we map from color type to ColorSpace enum) for the colors that can have an alternative serialization. For this, that would mean adding a ColorSpace::LabUsingColorSerialization and a LabUsingColorSerialization<float> type. Not horrible, but also not ideal when we can just use a bit from Color.
Sam Weinig
Comment 9 2021-02-19 11:05:04 PST
(In reply to Darin Adler from comment #6) > Comment on attachment 420911 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=420911&action=review > > > Source/WebCore/platform/graphics/Color.h:85 > > + Color(SRGBA<uint8_t>, OptionSet<Flags>); > > + Color(Optional<SRGBA<uint8_t>>, OptionSet<Flags>); > > Could we use default values for the flags to reduce the total number of > constructors? Would not want to sacrifice runtime efficiency, but would love > to have the list be much shorter. Yes, we can. I think it is extremely unlikely to cause any runtime change in release builds at all. Will fix.
Sam Weinig
Comment 10 2021-02-19 11:06:28 PST
(In reply to Dean Jackson from comment #5) > Comment on attachment 420911 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=420911&action=review > > > Source/WebCore/platform/graphics/Color.cpp:129 > > + auto result = colorWithOverridenAlpha(underlyingColor, alpha); > > Not new in this patch, but there is a typo in Overridden. :). Will fix. > > > Source/WebCore/platform/graphics/Color.h:198 > > + enum class AllFlags { > > It is common to have this All* enum? I would have thought you call this one > Flags and the earlier one FlagsSubset or something? I want the public enum to be called Flags, so this one had to be called something else. I agree AllFlags is not perfect. Maybe FlagsAndInternalState?
Darin Adler
Comment 11 2021-02-19 11:56:17 PST
I would choose the name FlagsIncludingInternal or since it’s C++ and the language calls it "private", FlagsIncludingPrivate.
Darin Adler
Comment 12 2021-02-19 11:57:25 PST
Irritating that we can’t use inheritance or anything like that. For the common flags I would at least suggest using the same symbolic constants to prove they match. Not sure how to check that the private flags don’t accidentally overlap the public.
Sam Weinig
Comment 13 2021-02-19 12:31:44 PST
(In reply to Darin Adler from comment #12) > Irritating that we can’t use inheritance or anything like that. For the > common flags I would at least suggest using the same symbolic constants to > prove they match. Not sure how to check that the private flags don’t > accidentally overlap the public. I do currently do a static_assert for the common ones: + static_assert(static_cast<unsigned>(Flags::Semantic) == static_cast<unsigned>(AllFlags::Semantic)); + static_assert(static_cast<unsigned>(Flags::UseColorFunctionSerialization) == static_cast<unsigned>(AllFlags::UseColorFunctionSerialization)); Did you mean something past that? Another options might be to fake it like this: ``` class Color { public: struct Flags { enum Flag : uint16_t; static constexpr Flag Semantic = 1 << 0; static constexpr Flag UseColorFunctionSerialization = 1 << 1; }; ... private: struct FlagsIncludingPrivate : Flags { static constexpr Flag Valid = 1 << 2; static constexpr Flag Extended = 1 << 3; static constexpr Flag HashTableEmptyValue = 1 << 4; static constexpr Flag HashTableDeletedValue = 1 << 5; }; ``` And then I think I could use OptionSet<Flags::Flag> everywhere, but only internally would the additional names be available.
Dean Jackson
Comment 14 2021-02-19 13:12:15 PST
(In reply to Darin Adler from comment #12) > Irritating that we can’t use inheritance or anything like that. Time to adopt Swift!!
Dean Jackson
Comment 15 2021-02-19 13:13:51 PST
Comment on attachment 420911 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=420911&action=review > Source/WebCore/platform/graphics/Color.cpp:127 > return callOnUnderlyingType(WTF::makeVisitor( I want to make this comment because I felt smart for finding it, but also dumb for not being confident in saying it..... you don't need a visitor any more since you now only have one function.
Sam Weinig
Comment 16 2021-02-20 10:34:48 PST
EWS
Comment 17 2021-02-20 16:48:06 PST
Committed r273211: <https://commits.webkit.org/r273211> All reviewed patches have been landed. Closing bug and clearing flags on attachment 421092 [details].
Radar WebKit Bug Importer
Comment 18 2021-02-20 16:49:14 PST
Simon Fraser (smfr)
Comment 19 2021-03-17 21:48:14 PDT
When you change Color data layout please also remember to fix Tools/lldb/lldb_webkit.py
Note You need to log in before you can comment on or make changes to this bug.