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

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

Issue 2379263002: services/ui: Fix setting client id for gpu channels. (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | 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_service_proxy.h" 5 #include "services/ui/ws/gpu_service_proxy.h"
6 6
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "gpu/ipc/client/gpu_channel_host.h" 11 #include "gpu/ipc/client/gpu_channel_host.h"
12 #include "services/shell/public/cpp/connection.h" 12 #include "services/shell/public/cpp/connection.h"
13 #include "services/ui/ws/gpu_service_proxy_delegate.h" 13 #include "services/ui/ws/gpu_service_proxy_delegate.h"
14 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" 14 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h"
15 15
16 namespace ui { 16 namespace ui {
17 namespace ws { 17 namespace ws {
18 18
19 namespace { 19 namespace {
20 20
21 const int32_t kInternalGpuChannelClientId = 1; 21 const int32_t kInternalGpuChannelClientId = 1;
22 const uint64_t kInternalGpuChannelClientTracingId = 1; 22 const uint64_t kInternalGpuChannelClientTracingId = 1;
23 23
24 } // namespace 24 } // namespace
25 25
26 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) 26 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
27 : delegate_(delegate), 27 : delegate_(delegate),
28 next_client_id_(kInternalGpuChannelClientId), 28 next_client_id_(kInternalGpuChannelClientId + 1),
29 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 29 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
30 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 30 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
31 base::WaitableEvent::InitialState::NOT_SIGNALED) { 31 base::WaitableEvent::InitialState::NOT_SIGNALED) {
32 gpu_main_.OnStart(); 32 gpu_main_.OnStart();
33 // TODO(sad): Once GPU process is split, this would look like: 33 // TODO(sad): Once GPU process is split, this would look like:
34 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); 34 // connector->ConnectToInterface("mojo:gpu", &gpu_service_);
35 gpu_main_.Create(GetProxy(&gpu_service_)); 35 gpu_main_.Create(GetProxy(&gpu_service_));
36 gpu_service_->Initialize( 36 gpu_service_->Initialize(
37 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); 37 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
38 } 38 }
39 39
40 GpuServiceProxy::~GpuServiceProxy() { 40 GpuServiceProxy::~GpuServiceProxy() {
41 if (gpu_channel_) 41 if (gpu_channel_)
42 gpu_channel_->DestroyChannel(); 42 gpu_channel_->DestroyChannel();
43 } 43 }
44 44
45 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { 45 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
46 bindings_.AddBinding(this, std::move(request)); 46 bindings_.AddBinding(this, std::move(request));
47 } 47 }
48 48
49 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { 49 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
50 gpu_info_ = gpu_info; 50 gpu_info_ = gpu_info;
51 51
52 constexpr bool is_gpu_host = true; 52 constexpr bool is_gpu_host = true;
53 gpu_service_->EstablishGpuChannel( 53 gpu_service_->EstablishGpuChannel(
54 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, 54 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId,
55 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, 55 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished,
56 base::Unretained(this))); 56 base::Unretained(this)));
57 next_client_id_ = kInternalGpuChannelClientId + 1;
58 } 57 }
59 58
60 void GpuServiceProxy::OnInternalGpuChannelEstablished( 59 void GpuServiceProxy::OnInternalGpuChannelEstablished(
61 mojo::ScopedMessagePipeHandle channel_handle) { 60 mojo::ScopedMessagePipeHandle channel_handle) {
62 io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread"); 61 io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread");
63 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 62 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
64 thread_options.priority = base::ThreadPriority::NORMAL; 63 thread_options.priority = base::ThreadPriority::NORMAL;
65 CHECK(io_thread_->StartWithOptions(thread_options)); 64 CHECK(io_thread_->StartWithOptions(thread_options));
66 65
67 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( 66 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
68 gpu_service_.get(), kInternalGpuChannelClientId); 67 gpu_service_.get(), kInternalGpuChannelClientId);
69 gpu_channel_ = gpu::GpuChannelHost::Create( 68 gpu_channel_ = gpu::GpuChannelHost::Create(
70 this, kInternalGpuChannelClientId, gpu_info_, 69 this, kInternalGpuChannelClientId, gpu_info_,
71 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, 70 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
72 gpu_memory_buffer_manager_.get()); 71 gpu_memory_buffer_manager_.get());
73 if (delegate_) 72 if (delegate_)
74 delegate_->OnGpuChannelEstablished(gpu_channel_); 73 delegate_->OnGpuChannelEstablished(gpu_channel_);
75 } 74 }
76 75
77 void GpuServiceProxy::OnGpuChannelEstablished( 76 void GpuServiceProxy::OnGpuChannelEstablished(
78 const EstablishGpuChannelCallback& callback, 77 const EstablishGpuChannelCallback& callback,
79 int32_t client_id, 78 int32_t client_id,
80 mojo::ScopedMessagePipeHandle channel_handle) { 79 mojo::ScopedMessagePipeHandle channel_handle) {
81 callback.Run(client_id, std::move(channel_handle), gpu_info_); 80 callback.Run(client_id, std::move(channel_handle), gpu_info_);
82 } 81 }
83 82
84 void GpuServiceProxy::EstablishGpuChannel( 83 void GpuServiceProxy::EstablishGpuChannel(
85 const EstablishGpuChannelCallback& callback) { 84 const EstablishGpuChannelCallback& callback) {
86 const int client_id = ++next_client_id_; 85 const int client_id = next_client_id_++;
87 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing 86 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing
88 // id. 87 // id.
89 const uint64_t client_tracing_id = 0; 88 const uint64_t client_tracing_id = 0;
90 constexpr bool is_gpu_host = false; 89 constexpr bool is_gpu_host = false;
91 gpu_service_->EstablishGpuChannel( 90 gpu_service_->EstablishGpuChannel(
92 client_id, client_tracing_id, is_gpu_host, 91 client_id, client_tracing_id, is_gpu_host,
93 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, 92 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished,
94 base::Unretained(this), callback, client_id)); 93 base::Unretained(this), callback, client_id));
95 } 94 }
96 95
(...skipping 24 matching lines...) Expand all
121 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( 120 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory(
122 size_t size) { 121 size_t size) {
123 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); 122 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
124 if (!shm->CreateAnonymous(size)) 123 if (!shm->CreateAnonymous(size))
125 shm.reset(); 124 shm.reset();
126 return shm; 125 return shm;
127 } 126 }
128 127
129 } // namespace ws 128 } // namespace ws
130 } // namespace ui 129 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698