Make SurfaceAllocator work with GPU process on Android
Categories
(GeckoView :: Sandboxing, task, P3)
Tracking
(firefox98 fixed)
Tracking | Status | |
---|---|---|
firefox98 | --- | fixed |
People
(Reporter: jnicol, Assigned: jnicol)
References
Details
Attachments
(1 file, 1 obsolete file)
(deleted),
text/x-phabricator-request
|
Details |
On Android we use SurfaceTexture
s and Surface
s to render video and webgl. These are allocated by content processes using the SurfaceAllocator
, which connects to a SurfaceAllocatorService
running in the parent process. The content process renders in to the Surface
(by attaching it to a media codec, or creating a GL context with it for webgl), and the compositor renders the output SurfaceTexture
in the parent process.
With the GPU process this poses a difficulty, as we need to allocate SurfaceTextures in either the parent process or GPU process, depending on whether the GPU process is enabled. Additionally, we don't want to run extra android Services in child processes such as the GPU process, as process management is tricky and we want to contain it to a single place.
My plan is to make SurfaceAllocatorService
not really an android "Service" any more. Just an object which implements the ISurfaceAllocator
interface. We'll add a function ISurfaceAllocator getSurfaceAllocator()
to IProcessManager
, from which child processes can request the ISurfaceAllocator
interface from the parent process. The parent process implementation of this will either return a local SurfaceAllocatorService
instance, or call the new method getCompositorSurface
in IChildProcess
to get the allocator from the GPU process.
We also need to handle the case where the GPU process has died, and the Surface
s in our content process are no longer valid. As far as I can tell Android does not expose an API to detect this, you just get lots of error messages in the logcat from the media and egl systems when attempting to render in to them. We can however use the binder death notification to determine when the GPU process has died, and set our own flag on the surfaces to say they are invalid. When media or webgl encounter an invalid surface we make them attempt to allocate new ones, and re-establish a connection to the new process' SurfaceAllocator while doing so.
Assignee | ||
Comment 1•3 years ago
|
||
On Android we use SurfaceTextures and Surfaces to render video and
webgl. These are allocated by content processes using the
SurfaceAllocator, which connects to a SurfaceAllocatorService running
in the parent process. The content process renders in to the
Surface (by attaching it to a media codec, or creating a GL context
with it for webgl), and the compositor renders the output
SurfaceTexture in the parent process.
With the GPU process this poses a difficulty, as we need to allocate
SurfaceTextures in either the parent process or GPU process, depending
on whether the GPU process is enabled. Additionally, we don't want to
run extra android Services in child processes such as the GPU process,
as process management is tricky and we want to contain it to a single
place.
This patch makes it so that SurfaceAllocatorService is not really an
android Service any more, just an singleton object which implements
the ISurfaceAllocator interface. It is renamed to
RemoteSurfaceAllocator to reflect that. A new method
getProcessManager() is added to the IProcessManager interface, which
child processes can use to fetch the surface allocator. It returns
either the parent process instance, or fetches the instance from the
GPU process using IChildProcess.getSurfaceAllocator().
Assignee | ||
Comment 2•3 years ago
|
||
Make the SurfaceAllocator save a reference to all Surfaces it has
allocated. When the connection to the remote allocator dies, mark all
of those surfaces as released.
Make GLScreenBuffer (webgl) and RemoteVideoDecoder (video) detect when
the Surfaces they are outputting into have been released, and allocate
new ones. For video decoding on Android Marshmallow and later, we can
use MediaCodec.setOutputSurface to swap the output surface
dynamically. On older Android versions we must reconfigure the codec.
Depends on D133107
Updated•3 years ago
|
Assignee | ||
Comment 3•3 years ago
|
||
I'm going to move the second patch to a separate bug and land the first one by itself. As it's useful to have basic video and webgl support working even if they don't yet recover from GPU process crashes
Comment 4•3 years ago
|
||
Comment on attachment 9254151 [details]
Bug 1742569 - Handle GPU process crash when rendering video and webgl on Android. r?agi,jgilbert
Revision D133108 was moved to bug 1750234. Setting attachment 9254151 [details] to obsolete.
Comment 6•3 years ago
|
||
bugherder |
Comment 7•2 years ago
|
||
Moving GPU process bugs to the new GeckoView::Sandboxing component.
Description
•