Commit a9dd0d29 authored by Jamie Nicol's avatar Jamie Nicol
Browse files

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
parent e61871c8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -9,10 +9,14 @@
#include "gfxPlatform.h"
#include "mozilla/gfx/GPUChild.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/layers/SynchronousTask.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_layers.h"
#include "VRGPUChild.h"
#include "mozilla/ipc/ProcessUtils.h"
#ifdef MOZ_WIDGET_ANDROID
#  include "mozilla/java/GeckoProcessManagerWrappers.h"
#endif

namespace mozilla {
namespace gfx {
@@ -143,6 +147,22 @@ void GPUProcessHost::InitAfterConnect(bool aSucceeded) {
    MOZ_ASSERT(rv);

    mGPUChild->Init();

#ifdef MOZ_WIDGET_ANDROID
    nsCOMPtr<nsIEventTarget> launcherThread(GetIPCLauncher());
    MOZ_ASSERT(launcherThread);
    layers::SynchronousTask task(
        "GeckoProcessManager::GetCompositorSurfaceManager");

    launcherThread->Dispatch(NS_NewRunnableFunction(
        "GeckoProcessManager::GetCompositorSurfaceManager", [&]() {
          layers::AutoCompleteTask complete(&task);
          mCompositorSurfaceManager =
              java::GeckoProcessManager::GetCompositorSurfaceManager();
        }));

    task.Wait();
#endif
  }

  if (mListener) {
@@ -227,5 +247,12 @@ void GPUProcessHost::DestroyProcess() {
      NS_NewRunnableFunction("DestroyProcessRunnable", [this] { Destroy(); }));
}

#ifdef MOZ_WIDGET_ANDROID
java::CompositorSurfaceManager::Param
GPUProcessHost::GetCompositorSurfaceManager() {
  return mCompositorSurfaceManager;
}
#endif

}  // namespace gfx
}  // namespace mozilla
+15 −0
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/TaskFactory.h"

#ifdef MOZ_WIDGET_ANDROID
#  include "mozilla/java/CompositorSurfaceManagerWrappers.h"
#endif

namespace mozilla {
namespace ipc {
class SharedPreferenceSerializer;
@@ -100,6 +104,10 @@ class GPUProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
  // Used for tests and diagnostics
  void KillProcess();

#ifdef MOZ_WIDGET_ANDROID
  java::CompositorSurfaceManager::Param GetCompositorSurfaceManager();
#endif

 private:
  ~GPUProcessHost();

@@ -135,6 +143,13 @@ class GPUProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
  bool mChannelClosed;

  TimeStamp mLaunchTime;

#ifdef MOZ_WIDGET_ANDROID
  // Binder interface used to send compositor surfaces to GPU process. There is
  // one instance per GPU process which gets initialized after launch, then
  // multiple compositors can take a reference to it.
  java::CompositorSurfaceManager::GlobalRef mCompositorSurfaceManager;
#endif
};

}  // namespace gfx
+5 −0
Original line number Diff line number Diff line
@@ -388,6 +388,11 @@ GPUProcessManager::CreateUiCompositorController(nsBaseWidget* aWidget,
    mGPUChild->SendInitUiCompositorController(aId, std::move(parentPipe));
    result = UiCompositorControllerChild::CreateForGPUProcess(
        mProcessToken, std::move(childPipe));

    if (result) {
      result->SetCompositorSurfaceManager(
          mProcess->GetCompositorSurfaceManager());
    }
  }
  if (result) {
    result->SetBaseWidget(aWidget);
+2 −0
Original line number Diff line number Diff line
@@ -619,6 +619,8 @@ void CompositorBridgeParent::ResumeComposition() {

  MonitorAutoLock lock(mResumeCompositionMonitor);

  mWidget->OnResumeComposition();

  bool resumed = mWrBridge->Resume();
  if (!resumed) {
#ifdef MOZ_WIDGET_ANDROID
+32 −0
Original line number Diff line number Diff line
@@ -318,5 +318,37 @@ void UiCompositorControllerChild::SendCachedValues() {
  }
}

#ifdef MOZ_WIDGET_ANDROID
void UiCompositorControllerChild::SetCompositorSurfaceManager(
    java::CompositorSurfaceManager::Param aCompositorSurfaceManager) {
  MOZ_ASSERT(!mCompositorSurfaceManager,
             "SetCompositorSurfaceManager must only be called once.");
  MOZ_ASSERT(mProcessToken != 0,
             "SetCompositorSurfaceManager must only be called for GPU process "
             "controllers.");
  mCompositorSurfaceManager = aCompositorSurfaceManager;
};

void UiCompositorControllerChild::OnCompositorSurfaceChanged(
    int32_t aWidgetId, java::sdk::Surface::Param aSurface) {
  // If mCompositorSurfaceManager is not set then there is no GPU process and
  // we do not need to do anything.
  if (mCompositorSurfaceManager == nullptr) {
    return;
  }

  nsresult result =
      mCompositorSurfaceManager->OnSurfaceChanged(aWidgetId, aSurface);

  // If our remote binder has died then notify the GPU process manager.
  if (NS_FAILED(result)) {
    if (mProcessToken) {
      gfx::GPUProcessManager::Get()->NotifyRemoteActorDestroyed(mProcessToken);
      mProcessToken = 0;
    }
  }
}
#endif

}  // namespace layers
}  // namespace mozilla
Loading