CanvasBidiProcessor::DrawText allocates and deallocates gfxContext all the time?
Categories
(Core :: Graphics: Canvas2D, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox112 | --- | fixed |
People
(Reporter: smaug, Assigned: jfkthame)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3-anyone])
Attachments
(4 external files)
Unless I'm missing something (though I did even debug this a bit) https://searchfox.org/mozilla-central/rev/188d0f76a73e0671d12e744a71e9f5701668cc37/dom/canvas/CanvasRenderingContext2D.cpp#3848 creates a temporary gfxContext which is then deleted at the end of the method.
This shows up in Proxx-Tables-Canvas test
https://share.firefox.dev/3lfsIAm
Could we have some variant of gfxContext which was stack allocated or something?
Comment 1•3 years ago
|
||
or perhaps the answer is to save the current context via ::Save, set whatever transform is needed etc and then ::Restore the original at the end.
Comment 2•3 years ago
|
||
I'll try to fix this.
Updated•3 years ago
|
Updated•3 years ago
|
Comment 3•3 years ago
|
||
Jonathan, is it possible here to just bypass gfxContext and make the text code just operate directly on a DrawTarget?
Updated•3 years ago
|
| Assignee | ||
Comment 4•3 years ago
|
||
(In reply to Lee Salzman [:lsalzman] from comment #3)
Jonathan, is it possible here to just bypass gfxContext and make the text code just operate directly on a DrawTarget?
In principle, I think it should be possible; in practice, distinctly non-trivial, as we currently manage a bunch of things such as colors, patterns, transforms (incl. save/restore), etc through the gfxContext. There's probably no fundamental reason we can't migrate all that to be directly DrawTarget-based, but I suspect it'd be a pretty extensive/invasive change.
Comment 5•3 years ago
|
||
(In reply to Robert Longson [:longsonr] from comment #1)
or perhaps the answer is to save the current context via ::Save, set whatever transform is needed etc and then ::Restore the original at the end.
I don't think we have a current context, that's why we're making one here. Currently gfxContext is refcounted but it might be possible to remove that and then stack allocate it.
Comment 6•3 years ago
|
||
One trouble that we might run into here is that we I think the gfxContext may get passed into the SVG code where it gets stored and stuff.
| Assignee | ||
Comment 7•3 years ago
|
||
I think we can do this, because AFAICS we don't end up passing gfxContexts to anything that stores them and outlives its caller, and as such, it's sufficient for the caller to own the context and just pass in a raw pointer. (But I may have missed something, obviously!)
I've pushed an experimental patch stack to try, to see how it looks:
https://treeherder.mozilla.org/jobs?repo=try&revision=f3a37f666879e58ac88bf8c1c11df39ce9a2ecb5
If this works, it should eliminate much of the gfxContext alloc/dealloc overhead, by moving most uses to the stack. (Currently I've left a few places using heap allocation (and UniquePtr rather than RefPtr to own it), though with a bit more effort we might be able to eliminate those as well.)
| Assignee | ||
Comment 8•3 years ago
|
||
| Assignee | ||
Comment 9•3 years ago
|
||
Depends on D170367
| Assignee | ||
Comment 10•3 years ago
|
||
Depends on D170369
| Assignee | ||
Comment 11•3 years ago
|
||
Depends on D170370
Comment 12•3 years ago
|
||
I'll step out of the way so Jonathan can land this.
Comment 13•3 years ago
|
||
Comment 14•3 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/2108d4594151
https://hg.mozilla.org/mozilla-central/rev/6525cdd895fc
https://hg.mozilla.org/mozilla-central/rev/55e12278c9a8
https://hg.mozilla.org/mozilla-central/rev/380a2f111a72
Updated•3 years ago
|
Description
•