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

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

Issue 2289553002: gpu: Introduce GpuInit. (Closed)
Patch Set: . Created 4 years, 3 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_service_proxy.h ('k') | 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/common/gpu_type_converters.h" 13 #include "services/ui/common/gpu_type_converters.h"
14 #include "services/ui/gpu/gpu_service_internal.h"
15 #include "services/ui/ws/gpu_service_proxy_delegate.h" 14 #include "services/ui/ws/gpu_service_proxy_delegate.h"
16 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" 15 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h"
17 16
18 namespace ui { 17 namespace ui {
19 namespace ws { 18 namespace ws {
20 19
21 namespace { 20 namespace {
22 21
23 const int32_t kInternalGpuChannelClientId = 1; 22 const int32_t kInternalGpuChannelClientId = 1;
24 const uint64_t kInternalGpuChannelClientTracingId = 1; 23 const uint64_t kInternalGpuChannelClientTracingId = 1;
25 24
26 } // namespace 25 } // namespace
27 26
28 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) 27 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
29 : delegate_(delegate), 28 : delegate_(delegate),
30 next_client_id_(kInternalGpuChannelClientId), 29 next_client_id_(kInternalGpuChannelClientId),
31 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 30 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
32 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 31 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
33 base::WaitableEvent::InitialState::NOT_SIGNALED) { 32 base::WaitableEvent::InitialState::NOT_SIGNALED) {
34 // TODO(sad): Once GPU process is split, this would look like: 33 // TODO(sad): Once GPU process is split, this would look like:
35 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); 34 // connector->ConnectToInterface("mojo:gpu", &gpu_service_);
36 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); 35 gpu_main_.Add(GetProxy(&gpu_service_));
37 gpu_service_->Initialize( 36 gpu_service_->Initialize(
38 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); 37 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
39 } 38 }
40 39
41 GpuServiceProxy::~GpuServiceProxy() {} 40 GpuServiceProxy::~GpuServiceProxy() {}
42 41
43 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { 42 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
44 bindings_.AddBinding(this, std::move(request)); 43 bindings_.AddBinding(this, std::move(request));
45 } 44 }
46 45
47 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { 46 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
48 gpu_info_ = gpu_info; 47 gpu_info_ = gpu_info;
49 48
50 constexpr bool is_gpu_host = true; 49 constexpr bool is_gpu_host = true;
51 gpu_service_->EstablishGpuChannel( 50 gpu_service_->EstablishGpuChannel(
52 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, 51 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId,
53 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, 52 is_gpu_host, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished,
54 base::Unretained(this))); 53 base::Unretained(this)));
55 next_client_id_ = kInternalGpuChannelClientId + 1; 54 next_client_id_ = kInternalGpuChannelClientId + 1;
56 } 55 }
57 56
58 void GpuServiceProxy::OnInternalGpuChannelEstablished( 57 void GpuServiceProxy::OnInternalGpuChannelEstablished(
59 mojo::ScopedMessagePipeHandle channel_handle) { 58 mojo::ScopedMessagePipeHandle channel_handle) {
60 io_thread_.reset(new base::Thread("GPUIOThread")); 59 io_thread_.reset(new base::Thread("GPUIOThread"));
61 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 60 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
62 thread_options.priority = base::ThreadPriority::NORMAL; 61 thread_options.priority = base::ThreadPriority::NORMAL;
63 CHECK(io_thread_->StartWithOptions(thread_options)); 62 CHECK(io_thread_->StartWithOptions(thread_options));
64 63
65 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager( 64 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager(
66 GpuServiceInternal::GetInstance(), kInternalGpuChannelClientId)); 65 gpu_main_.gpu_service(), kInternalGpuChannelClientId));
67 gpu_channel_ = gpu::GpuChannelHost::Create( 66 gpu_channel_ = gpu::GpuChannelHost::Create(
68 this, kInternalGpuChannelClientId, gpu_info_, 67 this, kInternalGpuChannelClientId, gpu_info_,
69 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, 68 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
70 gpu_memory_buffer_manager_.get()); 69 gpu_memory_buffer_manager_.get());
71 if (delegate_) 70 if (delegate_)
72 delegate_->OnGpuChannelEstablished(gpu_channel_); 71 delegate_->OnGpuChannelEstablished(gpu_channel_);
73 } 72 }
74 73
75 void GpuServiceProxy::OnGpuChannelEstablished( 74 void GpuServiceProxy::OnGpuChannelEstablished(
76 const EstablishGpuChannelCallback& callback, 75 const EstablishGpuChannelCallback& callback,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( 118 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory(
120 size_t size) { 119 size_t size) {
121 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); 120 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
122 if (!shm->CreateAnonymous(size)) 121 if (!shm->CreateAnonymous(size))
123 shm.reset(); 122 shm.reset();
124 return shm; 123 return shm;
125 } 124 }
126 125
127 } // namespace ws 126 } // namespace ws
128 } // namespace ui 127 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/gpu_service_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698