Bug 259306 - REGRESSION (Safari 17 beta): WebGL contexts drawn into canvas contexts are upside-down when premultipliedAlpha is false
Summary: REGRESSION (Safari 17 beta): WebGL contexts drawn into canvas contexts are up...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari 17
Hardware: All All
: P2 Normal
Assignee: Dan Glastonbury
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-07-18 06:16 PDT by Paul Neave
Modified: 2023-09-03 13:50 PDT (History)
5 users (show)

See Also:


Attachments
Demo of Safari 17 upside-down webgl-canvas bug (2.50 KB, text/html)
2023-07-18 06:16 PDT, Paul Neave
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Neave 2023-07-18 06:16:10 PDT
Created attachment 467067 [details]
Demo of Safari 17 upside-down webgl-canvas bug

In Safari 17 (Mac TP and iOS 17 beta), when drawing a WebGL1 context into a 2D canvas context, pixels are flipped in the y-axis (upside-down) when 'premultipliedAlpha' is set to false.

Please view the attachment in Safari 16 (or any other browser) and compare to Safari 17. The first rectangle is the WebGL canvas. The second rectangle is the 2D canvas. In Safari 17, the second image appears upside-down. This only occurs when premultipliedAlpha is set to false.
Comment 1 Radar WebKit Bug Importer 2023-07-18 08:49:11 PDT
<rdar://problem/112472666>
Comment 2 Dean Jackson 2023-07-18 17:35:53 PDT
Ouch!
Comment 3 Dean Jackson 2023-07-19 12:45:30 PDT
Note that the comments in the test case are slightly wrong.

// 2D canvas is rendered upside-down if premultipliedAlpha is set to true above

This should be "is set to false above".

The description in this report is correct though. When premultipliedAlpha is false (not the default value), the render from GL into 2D is upside down.
Comment 4 Dean Jackson 2023-07-19 12:53:25 PDT
Copying from the internal analysis:

https://commits.webkit.org/262518@main seems to be the cause.

And I assume it is the call to `readCompositedResults()` or `paintRenderingResultsToPixelBuffer()` that produces a NativeImage that is a different orientation to the one we'd get otherwise. They are always flipped when rendering into the 2D canvas.
Comment 5 Paul Neave 2023-07-20 02:20:45 PDT
(In reply to Dean Jackson from comment #3)
> Note that the comments in the test case are slightly wrong.
> 
> // 2D canvas is rendered upside-down if premultipliedAlpha is set to true
> above
> 
> This should be "is set to false above".
> 
> The description in this report is correct though. When premultipliedAlpha is
> false (not the default value), the render from GL into 2D is upside down.

Thanks Dean, yes that's correct - that was a typo.
Comment 6 Dan Glastonbury 2023-07-20 22:07:16 PDT
Pull request: https://github.com/WebKit/WebKit/pull/15970
Comment 7 EWS 2023-07-21 20:43:40 PDT
Committed 266225@main (ae8167890120): <https://commits.webkit.org/266225@main>

Reviewed commits have been landed. Closing PR #15970 and removing active labels.
Comment 8 Patrick Martin 2023-09-01 16:05:58 PDT
This may also be happening with WebGL 1 & OffscreenCanvas.toImageBitmap and bitmaprendererer contexts. I need to double check, but I'm definitely getting similar behavior with my library that uses that method.
Comment 9 Paul Neave 2023-09-02 12:45:52 PDT
(In reply to Patrick Martin from comment #8)
> This may also be happening with WebGL 1 & OffscreenCanvas.toImageBitmap and
> bitmaprendererer contexts. I need to double check, but I'm definitely
> getting similar behavior with my library that uses that method.

Oh no! Can you create a simple example to demonstrate this? It might be worth submitting a new bug report as this bug is regarding premultipliedAlpha, which is now fixed.
Comment 10 Patrick Martin 2023-09-02 16:59:09 PDT
(In reply to Paul Neave from comment #9)
> (In reply to Patrick Martin from comment #8)
> > This may also be happening with WebGL 1 & OffscreenCanvas.toImageBitmap and
> > bitmaprendererer contexts. I need to double check, but I'm definitely
> > getting similar behavior with my library that uses that method.
> 
> Oh no! Can you create a simple example to demonstrate this? It might be
> worth submitting a new bug report as this bug is regarding
> premultipliedAlpha, which is now fixed.

Bug 261069 has been submitted for that issue.