Implement globalCompositeOperation "clear"
Categories
(Core :: Graphics: Canvas2D, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox113 | --- | fixed |
People
(Reporter: evilpies, Assigned: evilpies)
References
(Blocks 1 open bug)
Details
Attachments
(4 files)
Clear is the first entry in the <composite-mode> list: https://drafts.fxtf.org/compositing/#compositemode.
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 1•2 years ago
|
||
Depends on D171019
Assignee | ||
Comment 2•2 years ago
|
||
Depends on D171020
Assignee | ||
Comment 3•2 years ago
|
||
I have been starring at the code in DrawTargetD2D1 for a while now and I am still not sure how to implement clear
there. It's obvious to me that we can't use D2DCompositionMode
, because clear is not part of D2D1_COMPOSITE_MODE. I guess there must be some other way of doing this in D2D.
Somewhat related I am puzzled why CONIC_GRADIENT/RADIAL_GRADIENT in FinalizeDrawing
only handle blending and not compositing modes.
Comment 4•2 years ago
|
||
Ultimately you will have to implement something in FinalizeDrawing that does something like ClearRect, i.e. a brush with color white.
Assignee | ||
Comment 5•2 years ago
•
|
||
I don't really understand how to get the correct bounds for the clear. I just don't have enough experience with graphics and D2D in particular to make much progress here myself. Maybe someone else wants to finish this up. I think most of the other stuff is in acceptable state.
Updated•2 years ago
|
Comment 6•2 years ago
•
|
||
I believe if you just do something like the following it should just work: https://paste.mozilla.org/kdbv8uM5
Make sure D2DSupportsCompositeMode(CompositionOp::OP_CLEAR) returns false. Rather, you don't need to modify the D2DSupportsCompositeMode/D2DCompositionMode at all in your patch if you just do things like I show above.
Assignee | ||
Comment 7•2 years ago
|
||
This results in the whole canvas being cleared. I had tried something similar before as well.
Comment 8•2 years ago
|
||
It's an unbounded operator as you spceified it, so that's what it should do if there is no clip?
Assignee | ||
Comment 9•2 years ago
•
|
||
Here is an example: https://jsfiddle.net/o1e6s8q9/. This should show the page background where the two rects are being drawn.
Comment 10•2 years ago
|
||
(In reply to Tom S [:evilpie] from comment #9)
Here is an example: https://jsfiddle.net/o1e6s8q9/. This should show the page background where the two rects are being drawn.
That's not what I would expect based on how you specified the operator - that it is not bound by the mask. For example, look at how the 'copy' operator behaves in that demo. That's how an operator not bound by mask would behave. So the whole canvas should be cleared as it is currently specified.
Do we have any third-party tests that indicate whether clear is actually supposed to be bound by the mask or not?
Assignee | ||
Comment 11•2 years ago
|
||
That's not what I would expect based on how you specified the operator - that it is not bound by the mask.
If you mean IsOperatorBoundByMask
that was not really intentional, I thought this would give me access to the clipped bounds.
Do we have any third-party tests that indicate whether clear is actually supposed to be bound by the mask or not?
Sadly not in WPT at least. Chrome and Safari both seem to have a bounded clear as the jsfiddle shows. I think it's possible that this behavior was inherited from cairo?
CAIRO_OPERATOR_CLEAR: clear destination layer (bounded) (Since 1.0)
Comment 12•2 years ago
•
|
||
For bounded operators, we need a different approach then. We will probably have to override the pattern supplied by CreateBrushForPattern(aSource) to return a clear pattern, and override the blend mode. Looks like this would be dest-out to be compatible with D2D layers and such, but here's a patch that might work (so long as IsOperatorBoundByMask is fixed):
Assignee | ||
Comment 13•2 years ago
|
||
I hadn't seen your patch so I wrote something similar based on your comments. My approach basically requires us to lie for IsOperatorBoundByMask
, which is not great.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 14•2 years ago
|
||
This implements OP_CLEAR by ensuring the shader always outputs a mask value that
represents coverage. Clear color is then blended in proportion to the coverage
value.
Updated•2 years ago
|
Comment 15•2 years ago
|
||
Comment 16•2 years ago
|
||
Comment 18•2 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/77863ad34930
https://hg.mozilla.org/mozilla-central/rev/4cf858f7a3d6
https://hg.mozilla.org/mozilla-central/rev/5e069b4ea9ac
https://hg.mozilla.org/mozilla-central/rev/f7afb890b556
Description
•