Commit 34881ada authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Update OzonePlatform::AfterSandboxEntry() according to spec

OzonePlatform::AfterSandboxEntry() should only be called when GPU is run
as a separate process (whether it is sandboxed or not). If GPU is
in-process, the embedders should not call AfterSandboxEntry(). This CL
updates ozone embedders and ozone implementations to adhere to this
requirement. Comments are also updated to reflect this requirement
clearly.

BUG=998113

Change-Id: I86a479131df463137185fc3217ce12dab107159e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807700Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699788}
parent 816f83e7
......@@ -508,7 +508,6 @@ void GpuInit::InitializeInProcess(base::CommandLine* command_line,
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->GetSupportedFormatsForTexturing();
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
#endif
bool needs_more_info = true;
#if !defined(IS_CHROMECAST)
......
......@@ -75,7 +75,6 @@ void RenderingHelper::InitializeOneOff(bool use_gl, base::WaitableEvent* done) {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
#endif
if (!use_gl_) {
......
......@@ -824,7 +824,6 @@ class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
done->Signal();
}
#endif
......
......@@ -40,7 +40,6 @@ void InitializeOneOffHelper(bool init_extensions) {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
#endif
#if defined(OS_LINUX)
......@@ -119,7 +118,6 @@ void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
#endif
InitializeOneOffImplementation(kGLImplementationMockGL, false);
......@@ -131,7 +129,6 @@ void GLSurfaceTestSupport::InitializeOneOffWithStubBindings() {
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
#endif
InitializeOneOffImplementation(kGLImplementationStubGL, false);
......
......@@ -81,7 +81,6 @@ int main(int argc, char** argv) {
->SetCurrentLayoutByName("us");
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper;
if (!ui::OzonePlatform::GetInstance()
......
......@@ -56,7 +56,6 @@ int main(int argc, char** argv) {
->SetCurrentLayoutByName("us");
ui::OzonePlatform::InitializeForGPU(params);
ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper;
if (!ui::OzonePlatform::GetInstance()
......
......@@ -184,7 +184,6 @@ class OzonePlatformGbm : public OzonePlatform {
// 3. multi-process mode where host and viz components communicate
// via mojo IPC.
single_process_ = args.single_process;
using_mojo_ = args.using_mojo;
host_thread_ = base::PlatformThread::CurrentRef();
......@@ -263,14 +262,19 @@ class OzonePlatformGbm : public OzonePlatform {
std::make_unique<DrmOverlayManagerGpu>(drm_thread_proxy_.get());
}
if (using_mojo_ && single_process_ &&
host_thread_ == base::PlatformThread::CurrentRef()) {
CHECK(host_drm_device_) << "Mojo single-thread mode requires "
"InitializeUI to be called first.";
// If gpu is in a separate process, rest of the initialization happens after
// entering the sandbox.
if (!single_process())
return;
// One-thread execution does not permit use of the sandbox.
AfterSandboxEntry();
// In single process/mojo mode we need to make sure DrainBindingRequest is
// executed on this thread before we start the drm device.
const bool block_for_drm_thread = using_mojo_;
StartDrmThread(block_for_drm_thread);
if (using_mojo_ && host_thread_ == base::PlatformThread::CurrentRef()) {
CHECK(has_initialized_ui()) << "Mojo single-thread mode requires "
"InitializeUI to be called first.";
// Connect host and gpu here since OnGpuServiceLaunched() is not called in
// the single-threaded mode.
ui::ozone::mojom::DrmDevicePtr drm_device_ptr;
......@@ -286,21 +290,28 @@ class OzonePlatformGbm : public OzonePlatform {
}
// The DRM thread needs to be started late because we need to wait for the
// sandbox to start. This entry point in the Ozne API gives platforms
// sandbox to start. This entry point in the Ozone API gives platforms
// flexibility in handing this requirement.
void AfterSandboxEntry() override {
CHECK(drm_thread_proxy_) << "AfterSandboxEntry before InitializeForGPU is "
"invalid startup order.\n";
if (using_mojo_ && single_process_) {
// In single process/mojo mode we need to make sure DrainBindingRequest
// is executed on this thread before we start the drm device.
DCHECK(!single_process());
CHECK(has_initialized_gpu()) << "AfterSandboxEntry before InitializeForGPU "
"is invalid startup order.";
const bool block_for_drm_thread = false;
StartDrmThread(block_for_drm_thread);
}
private:
// Starts the DRM thread. |blocking| determines if the call should be blocked
// until the thread is started.
void StartDrmThread(bool blocking) {
if (blocking) {
base::WaitableEvent done_event;
drm_thread_proxy_->StartDrmThread(base::BindOnce(
&base::WaitableEvent::Signal, base::Unretained(&done_event)));
done_event.Wait();
DrainBindingRequests();
} else {
// Defer the actual startup of the DRM thread to here.
auto safe_binding_resquest_drainer = CreateSafeOnceCallback(
base::BindOnce(&OzonePlatformGbm::DrainBindingRequests,
weak_factory_.GetWeakPtr()));
......@@ -309,9 +320,7 @@ class OzonePlatformGbm : public OzonePlatform {
}
}
private:
bool using_mojo_ = false;
bool single_process_ = false;
// Objects in the GPU process.
std::unique_ptr<DrmThreadProxy> drm_thread_proxy_;
......
......@@ -18,12 +18,7 @@
namespace ui {
namespace {
bool g_platform_initialized_ui = false;
bool g_platform_initialized_gpu = false;
OzonePlatform* g_instance = nullptr;
} // namespace
OzonePlatform::OzonePlatform() {
......@@ -35,10 +30,12 @@ OzonePlatform::~OzonePlatform() = default;
// static
void OzonePlatform::InitializeForUI(const InitParams& args) {
if (g_platform_initialized_ui)
EnsureInstance();
if (g_instance->initialized_ui_)
return;
g_platform_initialized_ui = true;
EnsureInstance()->InitializeUI(args);
g_instance->initialized_ui_ = true;
g_instance->single_process_ = args.single_process;
g_instance->InitializeUI(args);
// This is deliberately created after initializing so that the platform can
// create its own version of DDM.
DeviceDataManager::CreateInstance();
......@@ -46,10 +43,12 @@ void OzonePlatform::InitializeForUI(const InitParams& args) {
// static
void OzonePlatform::InitializeForGPU(const InitParams& args) {
if (g_platform_initialized_gpu)
EnsureInstance();
if (g_instance->initialized_gpu_)
return;
g_platform_initialized_gpu = true;
EnsureInstance()->InitializeGPU(args);
g_instance->initialized_gpu_ = true;
g_instance->single_process_ = args.single_process;
g_instance->InitializeGPU(args);
}
// static
......@@ -103,7 +102,7 @@ OzonePlatform::GetPlatformProperties() {
const OzonePlatform::InitializedHostProperties&
OzonePlatform::GetInitializedHostProperties() {
DCHECK(g_platform_initialized_ui);
DCHECK(initialized_ui_);
static InitializedHostProperties host_properties;
return host_properties;
......@@ -111,11 +110,9 @@ OzonePlatform::GetInitializedHostProperties() {
void OzonePlatform::AddInterfaces(service_manager::BinderRegistry* registry) {}
void OzonePlatform::AfterSandboxEntry() {}
// static
bool OzonePlatform::has_initialized_ui() {
return g_platform_initialized_ui;
void OzonePlatform::AfterSandboxEntry() {
// This should not be called in single-process mode.
DCHECK(!single_process_);
}
} // namespace ui
......@@ -186,20 +186,31 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// The GPU-specific portion of Ozone would typically run in a sandboxed
// process for additional security. Some startup might need to wait until
// after the sandbox has been configured. The embedder should use this method
// to specify that the sandbox is configured and that GPU-side setup should
// complete. A default do-nothing implementation is provided to permit
// platform implementations to ignore sandboxing and any associated launch
// ordering issues.
// after the sandbox has been configured.
// When the GPU is in a separate process, the embedder should call this method
// after it has configured (or failed to configure) the sandbox so that the
// GPU-side setup is completed. If the GPU is in-process, there is no
// sandboxing and the embedder should not call this method.
// A default do-nothing implementation is provided to permit platform
// implementations to ignore sandboxing and any associated launch ordering
// issues.
virtual void AfterSandboxEntry();
protected:
static bool has_initialized_ui();
bool has_initialized_ui() const { return initialized_ui_; }
bool has_initialized_gpu() const { return initialized_gpu_; }
bool single_process() const { return single_process_; }
private:
virtual void InitializeUI(const InitParams& params) = 0;
virtual void InitializeGPU(const InitParams& params) = 0;
bool initialized_ui_ = false;
bool initialized_gpu_ = false;
bool single_process_ = false;
DISALLOW_COPY_AND_ASSIGN(OzonePlatform);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment