On Wed, 22 Jul 2026 02:49:29 GMT, Sergey Bylokhov <[email protected]> wrote:

>> When we use XOR mode to clear the drawn content in Metal pipeline, it is 
>> leaving some traces.
>> We noticed similar issue when Metal pipeline was under development: 
>> [JDK-8251167](https://bugs.openjdk.org/browse/JDK-8251167). But the fix is 
>> not complete and we still see some traces. Using uiScale 1.0 with 
>> contrasting background and foreground color reveals this not so easily 
>> noticeable issue.
>> 
>> In case of Metal XOR mode is implemented using shaders and we are using an 
>> interpolated position passed from Vertex shader to determine the current 
>> position of fragment/pixel. We also add magic offsets to line vertices in 
>> MTLRenderer.DrawLine() and it can cause different approximations while 
>> calculating the interpolated position.
>> 
>> Because of this we end up in mismatch between the pixel from which we are 
>> reading the content and the pixel to which we are writing. Instead of using 
>> interpolated position we should use the rasterized position present in 
>> fragment shader to pick the appropriate pixel. When we use rasterized 
>> position mismatch doesn't happen and XOR draw clears the content properly.
>> 
>> We need this change in both `frag_col_xorMode` and `frag_txt_xorMode` 
>> shaders. Gradient and texture paint shaders are no-op in case of XOR as they 
>> use software loops, so no change is made in those shaders. Regression test 
>> is added only for color shader as mathematically i was able to reproduce 
>> issue only for color shader, but product fix is needed in case of text 
>> shader also.
>> 
>> If we use rasterized position to pick pixels we don't need fix done under 
>> [JDK-8251167](https://bugs.openjdk.org/browse/JDK-8251167), so that change 
>> is also reverted.
>> 
>> Code update is tested in CI and no regressions seen.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> test/jdk/java/awt/Graphics2D/ClearPolyLineUsingXORTest.java line 34:
> 
>> 32:  * @run     main/othervm -Dsun.java2d.metal=true -Dsun.java2d.uiScale=1
>> 33:  *                       ClearPolyLineUsingXORTest
>> 34:  */
> 
> Does the test really need to be macos specific and metal-only? can it cover 
> other platforms and ogl?

it still might be good to cover other platforms and at least default pipeline.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31981#discussion_r3633842085

Reply via email to