Closed Bug 1815404 Opened 3 years ago Closed 3 years ago

CanvasBidiProcessor::DrawText allocates and deallocates gfxContext all the time?

Categories

(Core :: Graphics: Canvas2D, defect, P3)

defect

Tracking

()

RESOLVED FIXED
112 Branch
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?

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'll try to fix this.

Assignee: nobody → bwerth
Severity: -- → S3
Priority: -- → P3
Blocks: gfx-triage
Flags: needinfo?(jfkthame)

Jonathan, is it possible here to just bypass gfxContext and make the text code just operate directly on a DrawTarget?

(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.

Flags: needinfo?(jfkthame)

(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.

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.

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.)

I'll step out of the way so Jonathan can land this.

Assignee: bwerth → jfkthame
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2108d4594151 The drawTarget wrapped by a gfxContext never changes, so doesn't need to be stored in AzureState. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/6525cdd895fc Remove refcounting from gfxContext. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/55e12278c9a8 Eliminate gfxContext::CreatePreservingTransformOrNull, and replace callers with stack-allocated gfxContext. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/380a2f111a72 Replace most uses of gfxContext::CreateOrNull with stack-allocated contexts. r=gfx-reviewers,lsalzman
No longer blocks: gfx-triage
Regressions: 1820587
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: