1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// 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.
#include "services/ui/ws/gpu_host.h"
#include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/ui/common/server_gpu_memory_buffer_manager.h"
#include "services/ui/ws/gpu_client.h"
#include "services/ui/ws/gpu_host_delegate.h"
#include "ui/gfx/buffer_format_util.h"
#if defined(OS_WIN)
#include "ui/gfx/win/rendering_window_manager.h"
#endif
namespace ui {
namespace ws {
namespace {
// The client Id 1 is reserved for the frame sink manager.
const int32_t kInternalGpuChannelClientId = 2;
} // namespace
GpuHost::GpuHost(GpuHostDelegate* delegate)
: delegate_(delegate),
next_client_id_(kInternalGpuChannelClientId + 1),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
gpu_host_binding_(this) {
// TODO(sad): Once GPU process is split, this would look like:
// connector->BindInterface("gpu", &gpu_main_);
gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_));
// TODO(sad): Correctly initialize gpu::GpuPreferences (like it is initialized
// in GpuProcessHost::Init()).
gpu::GpuPreferences preferences;
gpu_main_->CreateGpuService(MakeRequest(&gpu_service_),
gpu_host_binding_.CreateInterfacePtrAndBind(),
preferences, mojo::ScopedSharedBufferHandle());
gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>(
gpu_service_.get(), next_client_id_++);
}
GpuHost::~GpuHost() {}
void GpuHost::Add(mojom::GpuRequest request) {
AddInternal(std::move(request));
}
void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
#if defined(OS_WIN)
gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget);
#endif
}
void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) {
#if defined(OS_WIN)
gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget);
#endif
}
void GpuHost::CreateFrameSinkManager(
cc::mojom::FrameSinkManagerRequest request,
cc::mojom::FrameSinkManagerClientPtr client) {
gpu_main_->CreateFrameSinkManager(std::move(request), std::move(client));
}
GpuClient* GpuHost::AddInternal(mojom::GpuRequest request) {
auto client(base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_,
gpu_memory_buffer_manager_.get(),
gpu_service_.get()));
GpuClient* client_ref = client.get();
gpu_bindings_.AddBinding(std::move(client), std::move(request));
return client_ref;
}
void GpuHost::OnBadMessageFromGpu() {
// TODO(sad): Received some unexpected message from the gpu process. We
// should kill the process and restart it.
NOTIMPLEMENTED();
}
void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info) {
gpu_info_ = gpu_info;
delegate_->OnGpuServiceInitialized();
}
void GpuHost::DidFailInitialize() {}
void GpuHost::DidCreateOffscreenContext(const GURL& url) {}
void GpuHost::DidDestroyOffscreenContext(const GURL& url) {}
void GpuHost::DidDestroyChannel(int32_t client_id) {}
void GpuHost::DidLoseContext(bool offscreen,
gpu::error::ContextLostReason reason,
const GURL& active_url) {}
void GpuHost::SetChildSurface(gpu::SurfaceHandle parent,
gpu::SurfaceHandle child) {
#if defined(OS_WIN)
// Verify that |parent| was created by the window server.
DWORD process_id = 0;
DWORD thread_id = GetWindowThreadProcessId(parent, &process_id);
if (!thread_id || process_id != ::GetCurrentProcessId()) {
OnBadMessageFromGpu();
return;
}
// TODO(sad): Also verify that |child| was created by the mus-gpu process.
if (!gfx::RenderingWindowManager::GetInstance()->RegisterChild(parent,
child)) {
OnBadMessageFromGpu();
}
#else
NOTREACHED();
#endif
}
void GpuHost::StoreShaderToDisk(int32_t client_id,
const std::string& key,
const std::string& shader) {}
void GpuHost::RecordLogMessage(int32_t severity,
const std::string& header,
const std::string& message) {}
} // namespace ws
} // namespace ui
|