gecko-dev/widget/InProcessCompositorWidget.cpp
Jamie Nicol a9dd0d2943 Bug 1741156 - Initial GPU process implementation on Android. r=aosmond,agi
Declare a GPU process and corresponding Service in the
AndroidManifest. This is of a new class GeckoServiceGpuProcess which
inherits from GeckoServiceChildProcess, and provides a binder
interface ICompositorSurfaceManager which allows the parent process to
set the compositor Surface for a given widget ID, and the compositor
in the GPU process to look up the Surface for a widget ID. The
ICompositorSurfaceManager interface is exposed to the parent process
through a new method getCompositorSurfaceManager() in the
IChildProcess interface.

Add a new connection type for GPU processes to GeckoProcessManager,
along with a function to look up the GPU process connection and fetch
the ICompositorSurfaceManager binder. When the GPU process is launched
we store the returned binder in the GPUProcessHost, and when each
widget's compositor is created we store a reference to the binder in
the UiCompositorControllerChild.

Each nsWindow is given a unique ID, and whenever the Surface changes
due to an Android resume event, it sends the new surface for that ID
to the GPU process (if enabled) by calling
ICompositorSurfaceManager.onSurfaceChanged().

Stop inheriting AndroidCompositorWidget from InProcessCompositorWidget
and instead inherit from CompositorWidget directly. This class holds a
reference to the Surface that will be rendered in to. The
CompositorBridgeParent notifies the CompositorWidget whenever it has
been resumed, allowing it to fetch the new Surface. For the
cross-process CompositorWidgetParent implementation it fetches that
Surface from the CompositorSurfaceManagerService, whereas the
InProcessAndroidCompositorWidget can read it directly from the real
widget.

AndroidCompositorWidget::GetClientSize() can now calculate its size
from the Surface, rather than racily reading the value from the
nsWindow. This means RenderCompositorEGL and RenderCompositorOGLSWGL
can now use GetClientSize() again rather than querying their own size
from the Surface.

With this patch, setting layers.gpu-process.enabled to true will cause
us to launch a GPU process and render from it. We do not yet
gracefully recover from a GPU process crash, nor can we render
anything using SurfaceTextures (eg video or webgl). Those will come in
future patches.

Differential Revision: https://phabricator.services.mozilla.com/D131231
2021-11-29 20:52:31 +00:00

137 lines
4.3 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "InProcessCompositorWidget.h"
#include "mozilla/VsyncDispatcher.h"
#include "nsBaseWidget.h"
namespace mozilla {
namespace widget {
// Platforms with no OOP compositor process support use
// InProcessCompositorWidget by default.
#if !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
/* static */
RefPtr<CompositorWidget> CompositorWidget::CreateLocal(
const CompositorWidgetInitData& aInitData,
const layers::CompositorOptions& aOptions, nsIWidget* aWidget) {
// We're getting crashes from storing a NULL mWidget, and this is the
// only remaining explanation that doesn't involve memory corruption,
// so placing a release assert here. For even more sanity-checking, we
// do it after the static_cast.
nsBaseWidget* widget = static_cast<nsBaseWidget*>(aWidget);
MOZ_RELEASE_ASSERT(widget);
return new InProcessCompositorWidget(aOptions, widget);
}
#endif
InProcessCompositorWidget::InProcessCompositorWidget(
const layers::CompositorOptions& aOptions, nsBaseWidget* aWidget)
: CompositorWidget(aOptions),
mWidget(aWidget),
mCanary(CANARY_VALUE),
mWidgetSanity(aWidget) {
// The only method of construction that is used outside of unit tests is
// ::CreateLocal, above. That method of construction asserts that mWidget
// is not assigned a NULL value. And yet mWidget is NULL in some crash
// reports that involve other class methods. Adding a release assert here
// will give us the earliest possible notification that we're headed for
// a crash.
MOZ_RELEASE_ASSERT(mWidget);
}
bool InProcessCompositorWidget::PreRender(WidgetRenderingContext* aContext) {
CheckWidgetSanity();
return mWidget->PreRender(aContext);
}
void InProcessCompositorWidget::PostRender(WidgetRenderingContext* aContext) {
CheckWidgetSanity();
mWidget->PostRender(aContext);
}
RefPtr<layers::NativeLayerRoot>
InProcessCompositorWidget::GetNativeLayerRoot() {
CheckWidgetSanity();
return mWidget->GetNativeLayerRoot();
}
already_AddRefed<gfx::DrawTarget>
InProcessCompositorWidget::StartRemoteDrawing() {
CheckWidgetSanity();
return mWidget->StartRemoteDrawing();
}
already_AddRefed<gfx::DrawTarget>
InProcessCompositorWidget::StartRemoteDrawingInRegion(
const LayoutDeviceIntRegion& aInvalidRegion,
layers::BufferMode* aBufferMode) {
CheckWidgetSanity();
return mWidget->StartRemoteDrawingInRegion(aInvalidRegion, aBufferMode);
}
void InProcessCompositorWidget::EndRemoteDrawing() {
CheckWidgetSanity();
mWidget->EndRemoteDrawing();
}
void InProcessCompositorWidget::EndRemoteDrawingInRegion(
gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
CheckWidgetSanity();
mWidget->EndRemoteDrawingInRegion(aDrawTarget, aInvalidRegion);
}
void InProcessCompositorWidget::CleanupRemoteDrawing() {
CheckWidgetSanity();
mWidget->CleanupRemoteDrawing();
}
void InProcessCompositorWidget::CleanupWindowEffects() {
CheckWidgetSanity();
mWidget->CleanupWindowEffects();
}
bool InProcessCompositorWidget::InitCompositor(
layers::Compositor* aCompositor) {
CheckWidgetSanity();
return mWidget->InitCompositor(aCompositor);
}
LayoutDeviceIntSize InProcessCompositorWidget::GetClientSize() {
CheckWidgetSanity();
return mWidget->GetClientSize();
}
uint32_t InProcessCompositorWidget::GetGLFrameBufferFormat() {
CheckWidgetSanity();
return mWidget->GetGLFrameBufferFormat();
}
uintptr_t InProcessCompositorWidget::GetWidgetKey() {
CheckWidgetSanity();
return reinterpret_cast<uintptr_t>(mWidget);
}
nsIWidget* InProcessCompositorWidget::RealWidget() { return mWidget; }
void InProcessCompositorWidget::ObserveVsync(VsyncObserver* aObserver) {
CheckWidgetSanity();
if (RefPtr<CompositorVsyncDispatcher> cvd =
mWidget->GetCompositorVsyncDispatcher()) {
cvd->SetCompositorVsyncObserver(aObserver);
}
}
const char* InProcessCompositorWidget::CANARY_VALUE =
reinterpret_cast<char*>(0x1a1a1a1a);
void InProcessCompositorWidget::CheckWidgetSanity() {
MOZ_RELEASE_ASSERT(mWidgetSanity == mWidget);
MOZ_RELEASE_ASSERT(mCanary == CANARY_VALUE);
}
} // namespace widget
} // namespace mozilla