Closed Bug 1742569 Opened 2 years ago Closed 2 years ago

Make SurfaceAllocator work with GPU process on Android

Categories

(GeckoView :: Sandboxing, task, P3)

Unspecified
Android

Tracking

(firefox98 fixed)

RESOLVED FIXED
98 Branch
Tracking Status
firefox98 --- fixed

People

(Reporter: jnicol, Assigned: jnicol)

References

Details

Attachments

(1 file, 1 obsolete file)

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.

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

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

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

Priority: -- → P3

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

Blocks: 1750234

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.

Attachment #9254151 - Attachment is obsolete: true
Pushed by jnicol@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9b4ae3d9d2ac
Create RemoteSurfaceAllocator in either parent or GPU process. r=agi,gfx-reviewers,aosmond
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch

Moving GPU process bugs to the new GeckoView::Sandboxing component.

Component: General → Sandboxing
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: