Skip to content

Commit

Permalink
mus/gpu: Introduce the GpuServiceHost mojom interface.
Browse files Browse the repository at this point in the history
GpuServiceInternal uses the new host interface to notify the window
server when something happens. The window server does not actually
do anything in response yet.

BUG=643746, 630895

Review-Url: https://codereview.chromium.org/2559113002
Cr-Commit-Position: refs/heads/master@{#437335}
  • Loading branch information
sadrulhc authored and Commit bot committed Dec 8, 2016
1 parent ad0b468 commit b92e8e9
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _typemap_imports = [
"//mojo/public/cpp/bindings/tests/chromium_typemaps.gni",
"//net/interfaces/typemaps.gni",
"//services/service_manager/public/cpp/typemaps.gni",
"//services/ui/gpu/interfaces/typemaps.gni",
"//services/ui/public/interfaces/display/typemaps.gni",
"//services/ui/public/interfaces/ime/typemaps.gni",
"//services/video_capture/public/interfaces/typemaps.gni",
Expand Down
31 changes: 21 additions & 10 deletions services/ui/gpu/gpu_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ void GpuMain::OnStart() {
}

void GpuMain::CreateGpuService(mojom::GpuServiceInternalRequest request,
const CreateGpuServiceCallback& callback) {
mojom::GpuServiceHostPtr gpu_host) {
// |this| will outlive the gpu thread and so it's safe to use
// base::Unretained here.
gpu_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&GpuMain::CreateGpuServiceOnGpuThread, base::Unretained(this),
base::Passed(std::move(request)),
base::ThreadTaskRunnerHandle::Get(), callback));
base::Passed(gpu_host.PassInterface())));
}

void GpuMain::CreateDisplayCompositor(
Expand Down Expand Up @@ -150,7 +150,6 @@ void GpuMain::InitOnGpuThread(
gpu_service_internal_ = base::MakeUnique<GpuServiceInternal>(
gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(),
gpu_memory_buffer_factory_.get(), io_runner);
gpu_service_internal_->Initialize();
}

void GpuMain::CreateDisplayCompositorInternal(
Expand All @@ -171,7 +170,17 @@ void GpuMain::CreateDisplayCompositorInternal(
mojom::GpuServiceInternalRequest gpu_service_request =
mojo::GetProxy(&gpu_service);

CreateGpuService(std::move(gpu_service_request), CreateGpuServiceCallback());
if (gpu_thread_.task_runner()->BelongsToCurrentThread()) {
// If the DisplayCompositor creation was delayed because GpuServiceInternal
// had not been created yet, then this is called, in gpu thread, right after
// GpuServiceInternal is created.
BindGpuInternalOnGpuThread(std::move(gpu_service_request));
} else {
gpu_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&GpuMain::BindGpuInternalOnGpuThread, base::Unretained(this),
base::Passed(std::move(gpu_service_request))));
}

compositor_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&GpuMain::CreateDisplayCompositorOnCompositorThread,
Expand Down Expand Up @@ -211,20 +220,22 @@ void GpuMain::TearDownOnGpuThread() {

void GpuMain::CreateGpuServiceOnGpuThread(
mojom::GpuServiceInternalRequest request,
scoped_refptr<base::SingleThreadTaskRunner> origin_runner,
const CreateGpuServiceCallback& callback) {
mojom::GpuServiceHostPtrInfo gpu_host_info) {
mojom::GpuServiceHostPtr gpu_host;
gpu_host.Bind(std::move(gpu_host_info));
gpu_service_internal_->InitializeWithHost(std::move(gpu_host));
gpu_service_internal_->Bind(std::move(request));

if (pending_display_compositor_request_.is_pending()) {
CreateDisplayCompositorInternal(
std::move(pending_display_compositor_request_),
std::move(pending_display_compositor_client_info_));
}
}

if (!callback.is_null()) {
origin_runner->PostTask(
FROM_HERE, base::Bind(callback, gpu_service_internal_->gpu_info()));
}
void GpuMain::BindGpuInternalOnGpuThread(
mojom::GpuServiceInternalRequest request) {
gpu_service_internal_->Bind(std::move(request));
}

void GpuMain::PreSandboxStartup() {
Expand Down
9 changes: 4 additions & 5 deletions services/ui/gpu/gpu_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GpuMain : public gpu::GpuSandboxHelper, public mojom::GpuMain {

// mojom::GpuMain implementation:
void CreateGpuService(mojom::GpuServiceInternalRequest request,
const CreateGpuServiceCallback& callback) override;
mojom::GpuServiceHostPtr gpu_host) override;
void CreateDisplayCompositor(
cc::mojom::DisplayCompositorRequest request,
cc::mojom::DisplayCompositorClientPtr client) override;
Expand All @@ -50,10 +50,9 @@ class GpuMain : public gpu::GpuSandboxHelper, public mojom::GpuMain {
mojom::GpuServiceInternalPtrInfo gpu_service_info,
cc::mojom::DisplayCompositorRequest request,
cc::mojom::DisplayCompositorClientPtrInfo client_info);
void CreateGpuServiceOnGpuThread(
mojom::GpuServiceInternalRequest request,
scoped_refptr<base::SingleThreadTaskRunner> origin_runner,
const CreateGpuServiceCallback& callback);
void CreateGpuServiceOnGpuThread(mojom::GpuServiceInternalRequest request,
mojom::GpuServiceHostPtrInfo gpu_host_info);
void BindGpuInternalOnGpuThread(mojom::GpuServiceInternalRequest request);

void TearDownOnCompositorThread();
void TearDownOnGpuThread();
Expand Down
67 changes: 35 additions & 32 deletions services/ui/gpu/gpu_service_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@ GpuServiceInternal::~GpuServiceInternal() {
shutdown_event_.Signal();
}

void GpuServiceInternal::InitializeWithHost(mojom::GpuServiceHostPtr gpu_host) {
DCHECK(CalledOnValidThread());
DCHECK(!gpu_host_);
gpu_host_ = std::move(gpu_host);
gpu_info_.video_decode_accelerator_capabilities =
media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
gpu_info_.video_encode_accelerator_supported_profiles =
media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
gpu_info_.jpeg_decode_accelerator_supported =
media::GpuJpegDecodeAccelerator::IsSupported();
gpu_host_->DidInitialize(gpu_info_);

DCHECK(!owned_sync_point_manager_);
const bool allow_threaded_wait = false;
owned_sync_point_manager_.reset(
new gpu::SyncPointManager(allow_threaded_wait));

// Defer creation of the render thread. This is to prevent it from handling
// IPC messages before the sandbox has been enabled and all other necessary
// initialization has succeeded.
gpu_channel_manager_.reset(new gpu::GpuChannelManager(
gpu_preferences_, this, watchdog_thread_.get(),
base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
&shutdown_event_, owned_sync_point_manager_.get(),
gpu_memory_buffer_factory_));

media_gpu_channel_manager_.reset(
new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
}

void GpuServiceInternal::Bind(mojom::GpuServiceInternalRequest request) {
bindings_.AddBinding(this, std::move(request));
}
Expand Down Expand Up @@ -88,28 +118,28 @@ void GpuServiceInternal::DestroyGpuMemoryBuffer(
}

void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) {
NOTIMPLEMENTED();
gpu_host_->DidCreateOffscreenContext(active_url);
}

void GpuServiceInternal::DidDestroyChannel(int client_id) {
media_gpu_channel_manager_->RemoveChannel(client_id);
NOTIMPLEMENTED();
gpu_host_->DidDestroyChannel(client_id);
}

void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) {
NOTIMPLEMENTED();
gpu_host_->DidDestroyOffscreenContext(active_url);
}

void GpuServiceInternal::DidLoseContext(bool offscreen,
gpu::error::ContextLostReason reason,
const GURL& active_url) {
NOTIMPLEMENTED();
gpu_host_->DidLoseContext(offscreen, reason, active_url);
}

void GpuServiceInternal::StoreShaderToDisk(int client_id,
const std::string& key,
const std::string& shader) {
NOTIMPLEMENTED();
gpu_host_->StoreShaderToDisk(client_id, key, shader);
}

#if defined(OS_WIN)
Expand All @@ -124,33 +154,6 @@ void GpuServiceInternal::SetActiveURL(const GURL& url) {
// TODO(penghuang): implement this function.
}

void GpuServiceInternal::Initialize() {
DCHECK(CalledOnValidThread());
gpu_info_.video_decode_accelerator_capabilities =
media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
gpu_info_.video_encode_accelerator_supported_profiles =
media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
gpu_info_.jpeg_decode_accelerator_supported =
media::GpuJpegDecodeAccelerator::IsSupported();

DCHECK(!owned_sync_point_manager_);
const bool allow_threaded_wait = false;
owned_sync_point_manager_.reset(
new gpu::SyncPointManager(allow_threaded_wait));

// Defer creation of the render thread. This is to prevent it from handling
// IPC messages before the sandbox has been enabled and all other necessary
// initialization has succeeded.
gpu_channel_manager_.reset(new gpu::GpuChannelManager(
gpu_preferences_, this, watchdog_thread_.get(),
base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
&shutdown_event_, owned_sync_point_manager_.get(),
gpu_memory_buffer_factory_));

media_gpu_channel_manager_.reset(
new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
}

void GpuServiceInternal::EstablishGpuChannel(
int32_t client_id,
uint64_t client_tracing_id,
Expand Down
4 changes: 3 additions & 1 deletion services/ui/gpu/gpu_service_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "gpu/ipc/service/x_util.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/ui/gpu/interfaces/gpu_service_host.mojom.h"
#include "services/ui/gpu/interfaces/gpu_service_internal.mojom.h"
#include "ui/gfx/native_widget_types.h"

Expand Down Expand Up @@ -52,6 +53,7 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate,

~GpuServiceInternal() override;

void InitializeWithHost(mojom::GpuServiceHostPtr gpu_host);
void Bind(mojom::GpuServiceInternalRequest request);

private:
Expand Down Expand Up @@ -94,7 +96,6 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate,
gpu::SurfaceHandle child_window) override;
#endif
void SetActiveURL(const GURL& url) override;
void Initialize();

// mojom::GpuServiceInternal:
void EstablishGpuChannel(
Expand Down Expand Up @@ -128,6 +129,7 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate,
// Information about the GPU, such as device and vendor ID.
gpu::GPUInfo gpu_info_;

mojom::GpuServiceHostPtr gpu_host_;
std::unique_ptr<gpu::SyncPointManager> owned_sync_point_manager_;
std::unique_ptr<gpu::GpuChannelManager> gpu_channel_manager_;
std::unique_ptr<media::MediaGpuChannelManager> media_gpu_channel_manager_;
Expand Down
3 changes: 3 additions & 0 deletions services/ui/gpu/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import("//mojo/public/tools/bindings/mojom.gni")

mojom("interfaces") {
sources = [
"context_lost_reason.mojom",
"gpu_main.mojom",
"gpu_service_host.mojom",
"gpu_service_internal.mojom",
]

public_deps = [
"//gpu/ipc/common:interfaces",
"//services/ui/public/interfaces",
"//url/mojo:url_mojom_gurl",
]
}
15 changes: 15 additions & 0 deletions services/ui/gpu/interfaces/context_lost_reason.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module ui.mojom;

enum ContextLostReason {
GUILTY,
INNOCENT,
UNKNOWN,
OUT_OF_MEMORY,
MAKE_CURRENT_FAILED,
GPU_CHANNEL_LOST,
INVALID_GPU_MESSAGE,
};
12 changes: 12 additions & 0 deletions services/ui/gpu/interfaces/context_lost_reason.typemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

mojom = "//services/ui/gpu/interfaces/context_lost_reason.mojom"
public_headers = [ "//gpu/command_buffer/common/constants.h" ]
traits_headers = [ "//services/ui/gpu/interfaces/context_lost_reason_traits.h" ]
public_deps = [
"//gpu/command_buffer/common",
]

type_mappings = [ "ui.mojom.ContextLostReason=gpu::error::ContextLostReason" ]
68 changes: 68 additions & 0 deletions services/ui/gpu/interfaces/context_lost_reason_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_UI_GPU_INTERFACES_CONTEXT_LOST_REASON_TRAITS_H_
#define SERVICES_UI_GPU_INTERFACES_CONTEXT_LOST_REASON_TRAITS_H_

#include "gpu/command_buffer/common/constants.h"
#include "services/ui/gpu/interfaces/context_lost_reason.mojom.h"

namespace mojo {

template <>
struct EnumTraits<ui::mojom::ContextLostReason, gpu::error::ContextLostReason> {
static ui::mojom::ContextLostReason ToMojom(
gpu::error::ContextLostReason reason) {
switch (reason) {
case gpu::error::kGuilty:
return ui::mojom::ContextLostReason::GUILTY;
case gpu::error::kInnocent:
return ui::mojom::ContextLostReason::INNOCENT;
case gpu::error::kUnknown:
return ui::mojom::ContextLostReason::UNKNOWN;
case gpu::error::kOutOfMemory:
return ui::mojom::ContextLostReason::OUT_OF_MEMORY;
case gpu::error::kMakeCurrentFailed:
return ui::mojom::ContextLostReason::MAKE_CURRENT_FAILED;
case gpu::error::kGpuChannelLost:
return ui::mojom::ContextLostReason::GPU_CHANNEL_LOST;
case gpu::error::kInvalidGpuMessage:
return ui::mojom::ContextLostReason::INVALID_GPU_MESSAGE;
}
NOTREACHED();
return ui::mojom::ContextLostReason::UNKNOWN;
}

static bool FromMojom(ui::mojom::ContextLostReason reason,
gpu::error::ContextLostReason* out) {
switch (reason) {
case ui::mojom::ContextLostReason::GUILTY:
*out = gpu::error::kGuilty;
return true;
case ui::mojom::ContextLostReason::INNOCENT:
*out = gpu::error::kInnocent;
return true;
case ui::mojom::ContextLostReason::UNKNOWN:
*out = gpu::error::kUnknown;
return true;
case ui::mojom::ContextLostReason::OUT_OF_MEMORY:
*out = gpu::error::kOutOfMemory;
return true;
case ui::mojom::ContextLostReason::MAKE_CURRENT_FAILED:
*out = gpu::error::kMakeCurrentFailed;
return true;
case ui::mojom::ContextLostReason::GPU_CHANNEL_LOST:
*out = gpu::error::kGpuChannelLost;
return true;
case ui::mojom::ContextLostReason::INVALID_GPU_MESSAGE:
*out = gpu::error::kInvalidGpuMessage;
return true;
}
return false;
}
};

} // namespace mojo

#endif // SERVICES_UI_GPU_INTERFACES_CONTEXT_LOST_REASON_TRAITS_H_
6 changes: 3 additions & 3 deletions services/ui/gpu/interfaces/gpu_main.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module ui.mojom;

import "cc/ipc/display_compositor.mojom";
import "gpu/ipc/common/gpu_info.mojom";
import "services/ui/gpu/interfaces/gpu_service_host.mojom";
import "services/ui/gpu/interfaces/gpu_service_internal.mojom";

// This is the primordial interface used to (re)start the mus-gpu bundle
Expand All @@ -15,6 +15,6 @@ interface GpuMain {
cc.mojom.DisplayCompositor& display_compositor,
cc.mojom.DisplayCompositorClient display_compositor_client);

CreateGpuService(GpuServiceInternal& gpu_service) =>
(gpu.mojom.GpuInfo gpu_info);
CreateGpuService(GpuServiceInternal& gpu_service,
GpuServiceHost gpu_host);
};
22 changes: 22 additions & 0 deletions services/ui/gpu/interfaces/gpu_service_host.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module ui.mojom;

import "gpu/ipc/common/gpu_info.mojom";
import "services/ui/gpu/interfaces/context_lost_reason.mojom";
import "url/mojo/url.mojom";

interface GpuServiceHost {
DidInitialize(gpu.mojom.GpuInfo gpu_info);
DidCreateOffscreenContext(url.mojom.Url url);
DidDestroyOffscreenContext(url.mojom.Url url);

DidDestroyChannel(int32 client_id);
DidLoseContext(bool offscreen,
ContextLostReason reason,
url.mojom.Url active_url);

StoreShaderToDisk(int32 client_id, string key, string shader);
};
1 change: 1 addition & 0 deletions services/ui/gpu/interfaces/typemaps.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typemaps = [ "//services/ui/gpu/interfaces/context_lost_reason.typemap" ]
Loading

0 comments on commit b92e8e9

Please sign in to comment.