Bug 235604 - DrawGlyphsRecorder::recordDrawGlyphs() triggers the creation of out of line Colors
Summary: DrawGlyphsRecorder::recordDrawGlyphs() triggers the creation of out of line C...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Cameron McCormack (:heycam)
URL:
Keywords: InRadar
: 239953 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-01-25 13:30 PST by Simon Fraser (smfr)
Modified: 2022-05-05 16:16 PDT (History)
7 users (show)

See Also:


Attachments
Patch (7.38 KB, patch)
2022-05-03 23:31 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (7.42 KB, patch)
2022-05-04 14:50 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2022-01-25 13:30:12 PST
DrawGlyphsRecorder::recordDrawGlyphs() has code that converts CGColors to Colors, via Color::createAndPreserveColorSpace(). However, if the CSS color is, say #FF0000, which is inline, this CG-related code will make an out-of-line sRGB color, which will then compare as different to the inline color.
Comment 1 Radar WebKit Bug Importer 2022-02-01 13:31:15 PST
<rdar://problem/88345680>
Comment 2 Sam Weinig 2022-02-01 14:40:44 PST
I think heycam did this deliberately for https://trac.webkit.org/changeset/281470/webkit (https://bugs.webkit.org/show_bug.cgi?id=229024).

I believe the issue is that the colors lose state when when they go into the CGContextDelegateRef so we don't know what they originally were and so we err on the side of more bits.
Comment 3 Sam Weinig 2022-02-01 14:42:01 PST
Perhaps the thing to fix here is whatever code is doing the comparison you mention. Where is that?
Comment 4 Simon Fraser (smfr) 2022-02-01 15:01:05 PST
That's just Color's operator==
Comment 5 Cameron McCormack (:heycam) 2022-02-02 13:26:35 PST
Simon, where is the display list code doing the comparison of colors, and what does it  use it for?

If it's important for Color::operator== to distinguish equivalent colors specified using different syntaxes, we could add a different comparison function.
Comment 6 Simon Fraser (smfr) 2022-02-02 13:32:54 PST
I found this while investigating rdar://84602660. It affects the behavior of updateGraphicsContext(GraphicsContext& context, const TextPaintStyle& paintStyle, FillColorType fillColorType).
Comment 7 Simon Fraser (smfr) 2022-02-02 13:33:28 PST
Specifically the fill colors compare as different here:

    if (mode.contains(TextDrawingMode::Fill) && (fillColor != context.fillColor()))
        context.setFillColor(fillColor);
Comment 8 Sam Weinig 2022-02-03 18:24:20 PST
When Cameron wrote that code, we were using bounded SRGB for both color(srgb ...) and legacy rgb. Now, we use extended sRGB for color(srgb ) but still use bounded sRGB for legacy.

So, we could consider smuggling / encoding whether to use 8-bit / inline based on whether the CGColorRef is using bounded sRGB or extended sRGB for the color space.
Comment 9 Cameron McCormack (:heycam) 2022-05-03 17:16:45 PDT
*** Bug 239953 has been marked as a duplicate of this bug. ***
Comment 10 Cameron McCormack (:heycam) 2022-05-03 23:31:15 PDT
Created attachment 458775 [details]
Patch
Comment 11 Cameron McCormack (:heycam) 2022-05-04 14:50:27 PDT
Created attachment 458827 [details]
Patch
Comment 12 EWS 2022-05-05 16:16:44 PDT
Committed r293867 (250329@main): <https://commits.webkit.org/250329@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 458827 [details].