Closed Bug 1758555 Opened 2 years ago Closed 2 years ago

Share fonts across WebRender namespaces

Categories

(Core :: Graphics: WebRender, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: lsalzman, Assigned: lsalzman)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Currently, each WebRenderBridge manages its own set of font keys within an IdNamespace, and since each tab is assigned its own IdNamespace, the same font can be redundantly allocated many times across a single window or multiple windows. We should try to de-duplicate these redundant fonts somehow.

This replaces the sharing of SharedFontInstanceMap with a new structure
SharedFontResources that can be used to trade a mechanism between threads
of a single Renderer instance for de-duplicating fonts and font instances.

SharedFontResources stores maps of FontTemplates and FontInstances as well
as a new FontKeyMap and FontInstanceKeyMap which handles the mapping of
namespace-local font keys to a shared key. The shared key then maps to
the real, de-duplicated resource (template or instance) which has a lifetime
beyond that of any individual namespace that may refer to it. Reference
counting is used to track the lifetime of the shared key so that when no key
map entries refer to the shared key any longer, it will then expire and
be cleaned up. This does cause some complications with clearing a namespace
in that rather than simply crawling through a table looking for resources
with a given IdNamespace, we have to check for shared keys that have expired
when clearing a namespace caused the last references to their mappings
to be removed.

Given that ApiResources handles the up-front addition of font templates
and instances, while ResourceCache within the RenderBackend handles deletion,
most of these mappings have to be shared between threads, which is why they
live within SharedFontResources. When resource updates are processed by
either ApiResources or ResourceCache, we create a shared key as necessary to
add the font resource, and then delete the shared font resource when a resource
update caused the last reference to the resource's shared key to expire.

This only tries to de-duplicate fonts within a single Renderer (window). Since
each Renderer has its own texture cache and dependent glyph cache, sharing
across multiple windows would require extra complication with storing font
bitmaps outside of the texture cache and outside the Renderer instance itself.
For the sake of simplicity and to better understand how de-duplication impacts
performance, this patch only tries to address sharing within a single window.

Summary: Shared fonts across namespaces → Share fonts across WebRender namespaces
Pushed by lsalzman@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6200d15c46ab
Share font keys across multiple namespaces within a Renderer. r=nical,gfx-reviewers
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
See Also: → 1759891
Regressions: 1759891
Blocks: 1745591
Regressions: 1761437
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: