Closed Bug 1765911 Opened 3 years ago Closed 3 years ago

DrawTargetWebgl's PathCache can keep SourceSurfaces alive even when they aren't used

Categories

(Core :: Graphics: Canvas2D, defect)

defect

Tracking

()

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- fixed

People

(Reporter: lsalzman, Assigned: lsalzman)

Details

Attachments

(1 file)

The PathCache in DrawTargetWebgl uses Patterns are part of the keys for cache entries. Since a SurfacePattern holds a strong reference via RefPtr to a SourceSurface, if it is the only reference to that SourceSurface, it will keep it alive, even though there is no other external way to construct SurfacePattern that would ever point to the same SourceSurface.

Currently calling Pattern::Clone() produces a heap-allocated Pattern with RefPtrs
to any internal resources such as SourceSurfaces or GradientStops. While this is
okay if the Pattern is transient, this causes problems if the clone is long-lived
and causes via the RefPtr the stored resource to stay alive, even when there are
no other external references to the resource.

In the case of DrawTargetWebgl's PathCache, we need to be able to create Pattern
clones that have internal weak references, while also still supporting the original
use-case of strong references. To this end we template-ize some of the Pattern
derivatives so that we can make either strong or weak versions according to use-case.
This case way we store a weak clone of a Pattern in the PathCache key, the reference
will automatically invalidate itself when all other external strong references to it
go away, without having to do external crawling of the PathCache to constantly prune
the last reference manually.

Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0c0cf6af7665 Support cloning Patterns with internal weak references. r=aosmond
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: