OLD | NEW |
---|---|
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" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | |
10 #include "base/threading/thread_task_runner_handle.h" | |
11 #include "gpu/ipc/client/gpu_channel_host.h" | |
7 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
8 #include "services/ui/common/gpu_type_converters.h" | 13 #include "services/ui/common/gpu_type_converters.h" |
9 #include "services/ui/gpu/gpu_service_internal.h" | 14 #include "services/ui/gpu/gpu_service_internal.h" |
15 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" | |
10 | 16 |
11 namespace ui { | 17 namespace ui { |
18 namespace ws { | |
12 | 19 |
13 namespace { | 20 namespace { |
14 | 21 |
15 const int32_t kLocalGpuChannelClientId = 1; | 22 const int32_t kInternalGpuChannelClientId = 1; |
23 const uint64_t kInternalGpuChannelClientTracingId = 1; | |
16 | 24 |
17 } // namespace | 25 } // namespace |
18 | 26 |
19 GpuServiceProxy::GpuServiceProxy() : next_client_id_(kLocalGpuChannelClientId) { | 27 GpuServiceProxy::GpuServiceProxy(Delegate* delegate) |
28 : delegate_(delegate), | |
29 next_client_id_(kInternalGpuChannelClientId), | |
30 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
31 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
32 base::WaitableEvent::InitialState::NOT_SIGNALED) { | |
20 // TODO(sad): Once GPU process is split, this would look like: | 33 // TODO(sad): Once GPU process is split, this would look like: |
21 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); | 34 // connector->ConnectToInterface("mojo:gpu", &gpu_service_); |
22 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); | 35 GpuServiceInternal::GetInstance()->Add(GetProxy(&gpu_service_)); |
23 gpu_service_->Initialize( | 36 gpu_service_->Initialize( |
24 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); | 37 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); |
25 } | 38 } |
26 | 39 |
27 GpuServiceProxy::~GpuServiceProxy() {} | 40 GpuServiceProxy::~GpuServiceProxy() {} |
28 | 41 |
29 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { | 42 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { |
30 bindings_.AddBinding(this, std::move(request)); | 43 bindings_.AddBinding(this, std::move(request)); |
31 } | 44 } |
32 | 45 |
33 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { | 46 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { |
34 gpu_info_ = gpu_info; | 47 gpu_info_ = gpu_info; |
48 | |
49 constexpr bool privileged = true; | |
50 gpu_service_->EstablishGpuChannel( | |
51 kInternalGpuChannelClientId, kInternalGpuChannelClientTracingId, | |
52 privileged, base::Bind(&GpuServiceProxy::OnInternalGpuChannelEstablished, | |
53 base::Unretained(this))); | |
54 next_client_id_ = kInternalGpuChannelClientId + 1; | |
55 } | |
56 | |
57 void GpuServiceProxy::OnInternalGpuChannelEstablished( | |
58 mojo::ScopedMessagePipeHandle channel_handle) { | |
59 io_thread_.reset(new base::Thread("GPUIOThread")); | |
Fady Samuel
2016/08/26 16:27:59
A TODO might be useful to verify whether we need t
sadrul
2016/08/26 17:23:50
GpuChannelHost creates a sync ipc-channel, and tha
| |
60 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | |
61 thread_options.priority = base::ThreadPriority::NORMAL; | |
62 CHECK(io_thread_->StartWithOptions(thread_options)); | |
63 | |
64 gpu_memory_buffer_manager_.reset(new MusGpuMemoryBufferManager( | |
65 GpuServiceInternal::GetInstance(), kInternalGpuChannelClientId)); | |
66 gpu_channel_ = gpu::GpuChannelHost::Create( | |
67 this, kInternalGpuChannelClientId, gpu_info_, | |
68 IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, | |
69 gpu_memory_buffer_manager_.get()); | |
70 if (delegate_) | |
71 delegate_->OnGpuChannelEstablished(gpu_channel_); | |
35 } | 72 } |
36 | 73 |
37 void GpuServiceProxy::OnGpuChannelEstablished( | 74 void GpuServiceProxy::OnGpuChannelEstablished( |
38 const EstablishGpuChannelCallback& callback, | 75 const EstablishGpuChannelCallback& callback, |
39 int32_t client_id, | 76 int32_t client_id, |
40 mojo::ScopedMessagePipeHandle channel_handle) { | 77 mojo::ScopedMessagePipeHandle channel_handle) { |
41 callback.Run(client_id, std::move(channel_handle), gpu_info_); | 78 callback.Run(client_id, std::move(channel_handle), gpu_info_); |
42 } | 79 } |
43 | 80 |
44 void GpuServiceProxy::EstablishGpuChannel( | 81 void GpuServiceProxy::EstablishGpuChannel( |
45 const EstablishGpuChannelCallback& callback) { | 82 const EstablishGpuChannelCallback& callback) { |
46 const int client_id = ++next_client_id_; | 83 const int client_id = ++next_client_id_; |
47 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing | 84 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing |
48 // id. | 85 // id. |
49 const uint64_t client_tracing_id = 0; | 86 const uint64_t client_tracing_id = 0; |
87 constexpr bool privileged = false; | |
50 gpu_service_->EstablishGpuChannel( | 88 gpu_service_->EstablishGpuChannel( |
51 client_id, client_tracing_id, | 89 client_id, client_tracing_id, privileged, |
52 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, | 90 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, |
53 base::Unretained(this), callback, client_id)); | 91 base::Unretained(this), callback, client_id)); |
54 } | 92 } |
55 | 93 |
56 void GpuServiceProxy::CreateGpuMemoryBuffer( | 94 void GpuServiceProxy::CreateGpuMemoryBuffer( |
57 mojom::GpuMemoryBufferIdPtr id, | 95 mojom::GpuMemoryBufferIdPtr id, |
58 const gfx::Size& size, | 96 const gfx::Size& size, |
59 gfx::BufferFormat format, | 97 gfx::BufferFormat format, |
60 gfx::BufferUsage usage, | 98 gfx::BufferUsage usage, |
61 uint64_t surface_id, | 99 uint64_t surface_id, |
62 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { | 100 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { |
63 NOTIMPLEMENTED(); | 101 NOTIMPLEMENTED(); |
64 } | 102 } |
65 | 103 |
66 void GpuServiceProxy::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, | 104 void GpuServiceProxy::DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, |
67 const gpu::SyncToken& sync_token) { | 105 const gpu::SyncToken& sync_token) { |
68 NOTIMPLEMENTED(); | 106 NOTIMPLEMENTED(); |
69 } | 107 } |
70 | 108 |
109 bool GpuServiceProxy::IsMainThread() { | |
110 return main_thread_task_runner_->BelongsToCurrentThread(); | |
111 } | |
112 | |
113 scoped_refptr<base::SingleThreadTaskRunner> | |
114 GpuServiceProxy::GetIOThreadTaskRunner() { | |
115 return io_thread_->task_runner(); | |
116 } | |
117 | |
118 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( | |
119 size_t size) { | |
120 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | |
121 if (!shm->CreateAnonymous(size)) | |
122 shm.reset(); | |
123 return shm; | |
124 } | |
125 | |
126 } // namespace ws | |
71 } // namespace ui | 127 } // namespace ui |
OLD | NEW |