<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>235900</bug_id>
          
          <creation_ts>2022-01-31 10:48:55 -0800</creation_ts>
          <short_desc>REGRESSION(r166784): Accumulated pixel rounding errors cause gradient color stops to be misaligned</short_desc>
          <delta_ts>2024-05-30 18:18:00 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Layout and Rendering</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=241800</see_also>
          <bug_file_loc>https://codepen.io/thebabydino/pen/KKydBxw</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>131144</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Fraser (smfr)">simon.fraser</reporter>
          <assigned_to name="alan">zalan</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>bfulgham</cc>
    
    <cc>mmaxfield</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1835588</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-01-31 10:48:55 -0800</bug_when>
    <thetext>WebKit has misaligned gradient color stops in this test:
https://codepen.io/thebabydino/pen/KKydBxw

Reported by Ana Tudor: https://twitter.com/anatudor/status/1487853791147868162</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835609</commentid>
    <comment_count>1</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-01-31 11:27:06 -0800</bug_when>
    <thetext>div {
  min-height: 8em;
  background: linear-gradient(90deg, #f00 1px, #0000 0) 0/8em, linear-gradient(90deg, #00f 1px, #0000 0) 0/1.6em 50% repeat-x;
}
div + div {
  --w: min(40em, 100vw - 2em);
  background-size: calc(var(--w)/5), calc(var(--w)/25) 50%;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835805</commentid>
    <comment_count>2</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-01-31 18:41:10 -0800</bug_when>
    <thetext>RenderBoxModelObject::calculateBackgroundImageGeometry() calls pixelSnapBackgroundImageGeometryForPainting().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835808</commentid>
    <comment_count>3</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-01-31 19:08:51 -0800</bug_when>
    <thetext>Commenting out these two lines in pixelSnapBackgroundImageGeometryForPainting() makes the bug go away:

tileSize = LayoutSize(snapRectToDevicePixels(LayoutRect(destinationRect.location(), tileSize), scaleFactor).size());
phase = LayoutSize(snapRectToDevicePixels(LayoutRect(destinationRect.location(), phase), scaleFactor).size());

but I don&apos;t know if that&apos;s a safe change.

Assigning to Alan.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835809</commentid>
    <comment_count>4</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-01-31 19:35:32 -0800</bug_when>
    <thetext>Thinking more about this, the correct answer probably isn&apos;t to not pixel snap, but instead would probably be to repeatedly place the images, and then pixel snap their left and right edges (as opposed to their widths).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835811</commentid>
    <comment_count>5</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-01-31 19:39:49 -0800</bug_when>
    <thetext>Also, if this is a paint-time operation, it probably shouldn&apos;t be using LayoutUnits...

Maybe?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835818</commentid>
    <comment_count>6</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-01-31 20:15:51 -0800</bug_when>
    <thetext>&lt;rdar://problem/88309058&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1846428</commentid>
    <comment_count>7</comment_count>
      <attachid>453341</attachid>
    <who name="alan">zalan</who>
    <bug_when>2022-02-27 07:01:15 -0800</bug_when>
    <thetext>Created attachment 453341
Test reduction</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1846539</commentid>
    <comment_count>8</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2022-02-27 21:45:35 -0800</bug_when>
    <thetext>&gt;background: linear-gradient(90deg, black 1px, transparent 0) 0px/ 128px, linear-gradient(90deg, red 1px, transparent 0) 0px/ 25.6px 50px repeat-x;
I think this example should make every black line overlap a red line (1st, 6th, 11th...). However pixel-snapping translates the 25.6px value to 25.5px and while the second black line only misses the 6th red line by 0.5px (1 devices pixel on retina displays) these 0.1px pixel diffs add up on repeating backgrounds producing larger gaps over time.
I believe the solution is what Myles suggested above; not pixel-snap the tileSize, phase and space but only the destination rect.
Something like this:

-static void pixelSnapBackgroundImageGeometryForPainting(LayoutRect&amp; destinationRect, LayoutSize&amp; tileSize, LayoutSize&amp; phase, LayoutSize&amp; space, float scaleFactor)
-{
-    tileSize = LayoutSize(snapRectToDevicePixels(LayoutRect(destinationRect.location(), tileSize), scaleFactor).size());
-    phase = LayoutSize(snapRectToDevicePixels(LayoutRect(destinationRect.location(), phase), scaleFactor).size());
-    space = LayoutSize(snapRectToDevicePixels(LayoutRect(LayoutPoint(), space), scaleFactor).size());
-    destinationRect = LayoutRect(snapRectToDevicePixels(destinationRect, scaleFactor));
-}
-
 bool RenderBoxModelObject::fixedBackgroundPaintsInLocalCoordinates() const
 {
     if (!isDocumentElementRenderer())
@@ -1387,7 +1379,7 @@ BackgroundImageGeometry RenderBoxModelObject::calculateBackgroundImageGeometry(c
     }
 
     destinationRect.intersect(borderBoxRect);
-    pixelSnapBackgroundImageGeometryForPainting(destinationRect, tileSize, phase, spaceSize, deviceScaleFactor);
+    destinationRect = LayoutRect { snapRectToDevicePixels(destinationRect, deviceScaleFactor) };   &lt;- Ignore that we still use LayoutRect type here instead of FloatRect.
     return BackgroundImageGeometry(destinationRect, tileSize, phase, spaceSize, fixedAttachment);
 }

I&apos;d be more confident if someone with better understanding on background images could chime in though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1963442</commentid>
    <comment_count>9</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-06-23 16:35:30 -0700</bug_when>
    <thetext>I am still able to reproduce this bug on WebKit ToT (265489@main) using attached test case from Alan where the &apos;red&apos; does not cover &apos;blue&apos; lines and have gaps while Chrome Canary 116 and Firefox Nightly 116 works properly and have no gaps.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>453341</attachid>
            <date>2022-02-27 07:01:15 -0800</date>
            <delta_ts>2022-02-27 07:01:15 -0800</delta_ts>
            <desc>Test reduction</desc>
            <filename>235900.html</filename>
            <type>text/html</type>
            <size>253</size>
            <attacher name="alan">zalan</attacher>
            
              <data encoding="base64">PHN0eWxlPgpkaXYgewogIGhlaWdodDogNTBweDsKICB3aWR0aDogODAwcHg7CiAgYmFja2dyb3Vu
ZDogbGluZWFyLWdyYWRpZW50KDkwZGVnLCAjZjAwIDVweCwgIzAwMDAgMCkgMC8gMTI4cHgsIGxp
bmVhci1ncmFkaWVudCg5MGRlZywgIzAwZiAxcHgsICMwMDAwIDApIDAvIDI1LjYycHggMzBweCBy
ZXBlYXQteDsKfQo8L3N0eWxlPgo8ZGl2PjwvZGl2PgpQQVNTIGlmIG5vIGdhcCBiZXR3ZWVuIHRo
ZSByZWQgYW5kIHRoZSBibHVlIGxpbmVzLg==
</data>

          </attachment>
      

    </bug>

</bugzilla>