2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2016-06-11 05:27:24 +03:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef _include_mozilla_gfx_ipc_GPUProcessHost_h_
|
|
|
|
#define _include_mozilla_gfx_ipc_GPUProcessHost_h_
|
|
|
|
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
2016-06-11 05:37:03 +03:00
|
|
|
#include "mozilla/ipc/ProtocolUtils.h"
|
2016-06-11 05:27:24 +03:00
|
|
|
#include "mozilla/ipc/TaskFactory.h"
|
|
|
|
|
2019-05-26 05:33:12 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
class SharedPreferenceSerializer;
|
|
|
|
}
|
|
|
|
} // namespace mozilla
|
2016-06-11 05:37:03 +03:00
|
|
|
class nsITimer;
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class GPUChild;
|
|
|
|
|
|
|
|
// GPUProcessHost is the "parent process" container for a subprocess handle and
|
|
|
|
// IPC connection. It owns the parent process IPDL actor, which in this case,
|
|
|
|
// is a GPUChild.
|
|
|
|
//
|
|
|
|
// GPUProcessHosts are allocated and managed by GPUProcessManager. For all
|
|
|
|
// intents and purposes it is a singleton, though more than one may be allocated
|
|
|
|
// at a time due to its shutdown being asynchronous.
|
2017-07-05 18:47:40 +03:00
|
|
|
class GPUProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
|
2016-06-11 05:37:03 +03:00
|
|
|
friend class GPUChild;
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
public:
|
|
|
|
class Listener {
|
|
|
|
public:
|
|
|
|
virtual void OnProcessLaunchComplete(GPUProcessHost* aHost) {}
|
2016-06-11 05:37:03 +03:00
|
|
|
|
|
|
|
// The GPUProcessHost has unexpectedly shutdown or had its connection
|
|
|
|
// severed. This is not called if an error occurs after calling
|
|
|
|
// Shutdown().
|
|
|
|
virtual void OnProcessUnexpectedShutdown(GPUProcessHost* aHost) {}
|
2016-11-06 22:01:52 +03:00
|
|
|
|
2017-06-15 21:34:00 +03:00
|
|
|
virtual void OnRemoteProcessDeviceReset(GPUProcessHost* aHost) {}
|
2016-06-11 05:27:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit GPUProcessHost(Listener* listener);
|
|
|
|
|
|
|
|
// Launch the subprocess asynchronously. On failure, false is returned.
|
2018-03-15 17:31:28 +03:00
|
|
|
// Otherwise, true is returned, and the OnProcessLaunchComplete listener
|
|
|
|
// callback will be invoked either when a connection has been established, or
|
|
|
|
// if a connection could not be established due to an asynchronous error.
|
2018-05-08 17:31:52 +03:00
|
|
|
//
|
|
|
|
// @param aExtraOpts (StringVector)
|
|
|
|
// Extra options to pass to the subprocess.
|
|
|
|
bool Launch(StringVector aExtraOpts);
|
2016-06-11 05:27:24 +03:00
|
|
|
|
|
|
|
// If the process is being launched, block until it has launched and
|
|
|
|
// connected. If a launch task is pending, it will fire immediately.
|
|
|
|
//
|
|
|
|
// Returns true if the process is successfully connected; false otherwise.
|
|
|
|
bool WaitForLaunch();
|
|
|
|
|
|
|
|
// Inform the process that it should clean up its resources and shut down.
|
|
|
|
// This initiates an asynchronous shutdown sequence. After this method
|
|
|
|
// returns, it is safe for the caller to forget its pointer to the
|
|
|
|
// GPUProcessHost.
|
|
|
|
//
|
|
|
|
// After this returns, the attached Listener is no longer used.
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Return the actor for the top-level actor of the process. If the process
|
|
|
|
// has not connected yet, this returns null.
|
|
|
|
GPUChild* GetActor() const { return mGPUChild.get(); }
|
|
|
|
|
2016-07-18 07:24:28 +03:00
|
|
|
// Return a unique id for this process, guaranteed not to be shared with any
|
|
|
|
// past or future instance of GPUProcessHost.
|
|
|
|
uint64_t GetProcessToken() const;
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
bool IsConnected() const { return !!mGPUChild; }
|
|
|
|
|
2016-10-20 18:33:40 +03:00
|
|
|
// Return the time stamp for when we tried to launch the GPU process. This is
|
|
|
|
// currently used for Telemetry so that we can determine how long GPU
|
|
|
|
// processes take to spin up. Note this doesn't denote a successful launch,
|
|
|
|
// just when we attempted launch.
|
|
|
|
TimeStamp GetLaunchTime() const { return mLaunchTime; }
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
// Called on the IO thread.
|
|
|
|
void OnChannelConnected(int32_t peer_pid) override;
|
|
|
|
void OnChannelError() override;
|
|
|
|
|
2016-06-11 05:37:03 +03:00
|
|
|
void SetListener(Listener* aListener);
|
|
|
|
|
2016-10-31 22:44:40 +03:00
|
|
|
// Used for tests and diagnostics
|
|
|
|
void KillProcess();
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
private:
|
2019-02-05 03:15:20 +03:00
|
|
|
~GPUProcessHost();
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
// Called on the main thread.
|
|
|
|
void OnChannelConnectedTask();
|
|
|
|
void OnChannelErrorTask();
|
|
|
|
|
|
|
|
// Called on the main thread after a connection has been established.
|
|
|
|
void InitAfterConnect(bool aSucceeded);
|
|
|
|
|
2016-06-11 05:37:03 +03:00
|
|
|
// Called on the main thread when the mGPUChild actor is shutting down.
|
|
|
|
void OnChannelClosed();
|
|
|
|
|
|
|
|
// Kill the remote process, triggering IPC shutdown.
|
|
|
|
void KillHard(const char* aReason);
|
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
void DestroyProcess();
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(GPUProcessHost);
|
|
|
|
|
|
|
|
Listener* mListener;
|
2017-07-05 18:47:40 +03:00
|
|
|
mozilla::ipc::TaskFactory<GPUProcessHost> mTaskFactory;
|
2016-06-11 05:27:24 +03:00
|
|
|
|
|
|
|
enum class LaunchPhase { Unlaunched, Waiting, Complete };
|
|
|
|
LaunchPhase mLaunchPhase;
|
|
|
|
|
|
|
|
UniquePtr<GPUChild> mGPUChild;
|
2016-07-18 07:24:28 +03:00
|
|
|
uint64_t mProcessToken;
|
2016-06-11 05:37:03 +03:00
|
|
|
|
2019-05-26 05:33:12 +03:00
|
|
|
UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
|
|
|
|
|
2016-06-11 05:37:03 +03:00
|
|
|
bool mShutdownRequested;
|
2016-07-18 07:24:28 +03:00
|
|
|
bool mChannelClosed;
|
2016-10-20 18:33:40 +03:00
|
|
|
|
|
|
|
TimeStamp mLaunchTime;
|
2016-06-11 05:27:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _include_mozilla_gfx_ipc_GPUProcessHost_h_
|