Closed Bug 1739448 Opened 3 years ago Closed 3 years ago

Implement a prototype for GPU-accelerated Canvas2D (DrawTargetWebgl)

Categories

(Core :: Graphics: Canvas2D, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
96 Branch
Tracking Status
firefox96 --- fixed

People

(Reporter: lsalzman, Assigned: lsalzman)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Per discussions, implement a first draft of a WebGL-backed Canvas2D, that will work across all platforms, be sufficient to accelerate Fishbowl, and is suitable for testing and further development to a wider set of Canvas2D testcases.

sk_sp requires its type to be defined at the point of sk_sp declaration.
Just use RefPtr instead which does not have this limitation so we can move
some Skia includes out of the Moz2D headers.

This mainly provides DrawTargetWebgl, which implements the subset of the DrawTarget
API necessary for integration with CanvasRenderingContext2D. It translates them to
suitable commands for its internal ClientWebGLContext, which then manages remoting
WebGL requests to the parent/GPU process.

Currently two shaders are used for drawing Canvas2D primitives, but can be expanded
in the future. These are an image shader and a solid color shader.

The core of this implementation revolves around TexturePacker and TextureHandle,
which cope with the necessity of frequently uploading SourceSurfaces for use with
WebGL. TexturePacker implements a bin-packing algorithm for packing these uploads
into texture pages, which can either be SharedTextures if they are reasonably small,
or StandaloneTextures if they are too big to pack in a SharedTexture. Each upload
is assigned a TextureHandle which is used to manage it in a move-to-front cache,
so that we can easily eject TextureHandles from the back of the cache if we have
too many. These TextureHandles are associated with the SourceSurface that spawned
them to more easily manage their lifetimes.

There are further dependent caches for dealing with blurred shadows and with text.
Shadows are cached in an uploaded texture bound to the SourceSurface that generated
them. Text is handled by caching entire runs in the GlyphCache (keyed by both their
rendering parameters and their glyphs). The text is first rasterized to a surface
and then uploaded to a texture in the GlyphCache which can be reused should the
text be encountered again.

To deal with commands we can't accelerate, a separate internal DrawTargetSkia is
also maintained. The context of the WebGL framebuffer is copied into it so that
drawing can then proceed in software from there. It remains in this fallover state
until the next frame, when it resets back to using the WebGL framebuffer again.

This acceleration is disabled by default. To enable it, you must toggle the pref
"gfx.canvas.accelerated" to true. This should be suitably different from the naming
of the previous SkiaGL prefs to not alias with them. There are a few dependent prefs
that follow from the previous SkiaGL prefs for setting the size limitations for
acceleration and also limitations for the internal texture cache.

Depends on D130387

Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/feac99f1dae3 Reduce Skia header pollution in Moz2D from sk_sp. r=gfx-reviewers,jgilbert https://hg.mozilla.org/integration/autoland/rev/7b82837e2f56 Implement a prototype WebGL-backed Canvas2D. r=gfx-reviewers,nical,jrmuizel

Backed out 2 changesets (Bug 1739448) for causing geckoview failures on 1246775-1.html.
Backout link
Push with failures
Failure Log

Flags: needinfo?(lsalzman)
Flags: needinfo?(lsalzman)
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/66c30950518d Reduce Skia header pollution in Moz2D from sk_sp. r=gfx-reviewers,jgilbert https://hg.mozilla.org/integration/autoland/rev/e3051b96067a Implement a prototype WebGL-backed Canvas2D. r=gfx-reviewers,nical,jrmuizel
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 96 Branch
Blocks: gpu-canvas
Summary: Implement a prototype for GPU-accelerated Canvas2D → Implement a prototype for GPU-accelerated Canvas2D (DrawTargetWebgl)
See Also: → 1602299
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: