Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: services/ui/ws/gpu_host.cc

Issue 2741343003: Update liftetime management of GpuClient (Closed)
Patch Set: fix x11 re-definition Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/gpu_host.h ('k') | services/ui/ws/gpu_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/ws/gpu_host.h" 5 #include "services/ui/ws/gpu_host.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "gpu/ipc/client/gpu_channel_host.h" 12 #include "gpu/ipc/client/gpu_channel_host.h"
13 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" 13 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h" 14 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "mojo/public/cpp/system/buffer.h" 15 #include "mojo/public/cpp/system/buffer.h"
16 #include "mojo/public/cpp/system/platform_handle.h" 16 #include "mojo/public/cpp/system/platform_handle.h"
17 #include "services/service_manager/public/cpp/connection.h" 17 #include "services/service_manager/public/cpp/connection.h"
18 #include "services/ui/common/server_gpu_memory_buffer_manager.h" 18 #include "services/ui/common/server_gpu_memory_buffer_manager.h"
19 #include "services/ui/ws/gpu_client.h"
19 #include "services/ui/ws/gpu_host_delegate.h" 20 #include "services/ui/ws/gpu_host_delegate.h"
20 #include "ui/gfx/buffer_format_util.h" 21 #include "ui/gfx/buffer_format_util.h"
21 22
22 #if defined(OS_WIN) 23 #if defined(OS_WIN)
23 #include "ui/gfx/win/rendering_window_manager.h" 24 #include "ui/gfx/win/rendering_window_manager.h"
24 #endif 25 #endif
25 26
26 namespace ui { 27 namespace ui {
27 namespace ws { 28 namespace ws {
28 29
29 namespace { 30 namespace {
30 31
31 // The client Id 1 is reserved for the display compositor. 32 // The client Id 1 is reserved for the display compositor.
32 const int32_t kInternalGpuChannelClientId = 2; 33 const int32_t kInternalGpuChannelClientId = 2;
33 34
34 // The implementation that relays requests from clients to the real
35 // service implementation in the GPU process over mojom.GpuService.
36 class GpuClient : public mojom::Gpu {
37 public:
38 GpuClient(int client_id,
39 gpu::GPUInfo* gpu_info,
40 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager,
41 mojom::GpuService* gpu_service)
42 : client_id_(client_id),
43 gpu_info_(gpu_info),
44 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
45 gpu_service_(gpu_service) {
46 DCHECK(gpu_memory_buffer_manager_);
47 DCHECK(gpu_service_);
48 }
49 ~GpuClient() override {
50 gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_);
51 }
52
53 private:
54 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback,
55 mojo::ScopedMessagePipeHandle channel_handle) {
56 callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
57 }
58
59 // mojom::Gpu overrides:
60 void EstablishGpuChannel(
61 const EstablishGpuChannelCallback& callback) override {
62 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful
63 // tracing id.
64 const uint64_t client_tracing_id = 0;
65 constexpr bool is_gpu_host = false;
66 gpu_service_->EstablishGpuChannel(
67 client_id_, client_tracing_id, is_gpu_host,
68 base::Bind(&GpuClient::OnGpuChannelEstablished, base::Unretained(this),
69 callback));
70 }
71
72 void CreateGpuMemoryBuffer(
73 gfx::GpuMemoryBufferId id,
74 const gfx::Size& size,
75 gfx::BufferFormat format,
76 gfx::BufferUsage usage,
77 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override {
78 auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle(
79 id, client_id_, size, format, usage, gpu::kNullSurfaceHandle);
80 callback.Run(handle);
81 }
82
83 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
84 const gpu::SyncToken& sync_token) override {
85 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_,
86 sync_token);
87 }
88
89 const int client_id_;
90
91 // The objects these pointers refer to are owned by the GpuHost object.
92 const gpu::GPUInfo* gpu_info_;
93 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_;
94 mojom::GpuService* gpu_service_;
95
96 DISALLOW_COPY_AND_ASSIGN(GpuClient);
97 };
98
99 } // namespace 35 } // namespace
100 36
101 GpuHost::GpuHost(GpuHostDelegate* delegate) 37 GpuHost::GpuHost(GpuHostDelegate* delegate)
102 : delegate_(delegate), 38 : delegate_(delegate),
103 next_client_id_(kInternalGpuChannelClientId + 1), 39 next_client_id_(kInternalGpuChannelClientId + 1),
104 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 40 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
105 gpu_host_binding_(this) { 41 gpu_host_binding_(this) {
106 // TODO(sad): Once GPU process is split, this would look like: 42 // TODO(sad): Once GPU process is split, this would look like:
107 // connector->BindInterface("gpu", &gpu_main_); 43 // connector->BindInterface("gpu", &gpu_main_);
108 gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_)); 44 gpu_main_impl_ = base::MakeUnique<GpuMain>(MakeRequest(&gpu_main_));
109 gpu_main_impl_->OnStart(); 45 gpu_main_impl_->OnStart();
110 46
111 // TODO(sad): Correctly initialize gpu::GpuPreferences (like it is initialized 47 // TODO(sad): Correctly initialize gpu::GpuPreferences (like it is initialized
112 // in GpuProcessHost::Init()). 48 // in GpuProcessHost::Init()).
113 gpu::GpuPreferences preferences; 49 gpu::GpuPreferences preferences;
114 gpu_main_->CreateGpuService(MakeRequest(&gpu_service_), 50 gpu_main_->CreateGpuService(MakeRequest(&gpu_service_),
115 gpu_host_binding_.CreateInterfacePtrAndBind(), 51 gpu_host_binding_.CreateInterfacePtrAndBind(),
116 preferences, mojo::ScopedSharedBufferHandle()); 52 preferences, mojo::ScopedSharedBufferHandle());
117 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>( 53 gpu_memory_buffer_manager_ = base::MakeUnique<ServerGpuMemoryBufferManager>(
118 gpu_service_.get(), next_client_id_++); 54 gpu_service_.get(), next_client_id_++);
119 } 55 }
120 56
121 GpuHost::~GpuHost() {} 57 GpuHost::~GpuHost() {}
122 58
123 void GpuHost::Add(mojom::GpuRequest request) { 59 void GpuHost::Add(mojom::GpuRequest request) {
124 mojo::MakeStrongBinding( 60 AddInternal(std::move(request));
125 base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_,
126 gpu_memory_buffer_manager_.get(),
127 gpu_service_.get()),
128 std::move(request));
129 } 61 }
130 62
131 void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { 63 void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
132 #if defined(OS_WIN) 64 #if defined(OS_WIN)
133 gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget); 65 gfx::RenderingWindowManager::GetInstance()->RegisterParent(widget);
134 #endif 66 #endif
135 } 67 }
136 68
137 void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) { 69 void GpuHost::OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget) {
138 #if defined(OS_WIN) 70 #if defined(OS_WIN)
139 gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget); 71 gfx::RenderingWindowManager::GetInstance()->UnregisterParent(widget);
140 #endif 72 #endif
141 } 73 }
142 74
143 void GpuHost::CreateDisplayCompositor( 75 void GpuHost::CreateDisplayCompositor(
144 cc::mojom::DisplayCompositorRequest request, 76 cc::mojom::DisplayCompositorRequest request,
145 cc::mojom::DisplayCompositorClientPtr client) { 77 cc::mojom::DisplayCompositorClientPtr client) {
146 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client)); 78 gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client));
147 } 79 }
148 80
81 GpuClient* GpuHost::AddInternal(mojom::GpuRequest request) {
82 auto client(base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_,
83 gpu_memory_buffer_manager_.get(),
84 gpu_service_.get()));
85 GpuClient* client_ref = client.get();
86 gpu_bindings_.AddBinding(std::move(client), std::move(request));
87 return client_ref;
88 }
89
149 void GpuHost::OnBadMessageFromGpu() { 90 void GpuHost::OnBadMessageFromGpu() {
150 // TODO(sad): Received some unexpected message from the gpu process. We 91 // TODO(sad): Received some unexpected message from the gpu process. We
151 // should kill the process and restart it. 92 // should kill the process and restart it.
152 NOTIMPLEMENTED(); 93 NOTIMPLEMENTED();
153 } 94 }
154 95
155 void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) { 96 void GpuHost::DidInitialize(const gpu::GPUInfo& gpu_info) {
156 gpu_info_ = gpu_info; 97 gpu_info_ = gpu_info;
157 delegate_->OnGpuServiceInitialized(); 98 delegate_->OnGpuServiceInitialized();
158 } 99 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 void GpuHost::StoreShaderToDisk(int32_t client_id, 133 void GpuHost::StoreShaderToDisk(int32_t client_id,
193 const std::string& key, 134 const std::string& key,
194 const std::string& shader) {} 135 const std::string& shader) {}
195 136
196 void GpuHost::RecordLogMessage(int32_t severity, 137 void GpuHost::RecordLogMessage(int32_t severity,
197 const std::string& header, 138 const std::string& header,
198 const std::string& message) {} 139 const std::string& message) {}
199 140
200 } // namespace ws 141 } // namespace ws
201 } // namespace ui 142 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/gpu_host.h ('k') | services/ui/ws/gpu_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698