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

Side by Side Diff: components/mus/gpu/gpu_service_mus.cc

Issue 2020293003: Use mus::MojoGpuMemoryBufferManager in mus::GpuService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 6 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
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 "components/mus/gpu/gpu_service_mus.h" 5 #include "components/mus/gpu/gpu_service_mus.h"
6 6
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/mus/gpu/gpu_memory_buffer_manager_mus_local.h" 11 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h"
12 #include "gpu/command_buffer/service/gpu_switches.h" 12 #include "gpu/command_buffer/service/gpu_switches.h"
13 #include "gpu/command_buffer/service/sync_point_manager.h" 13 #include "gpu/command_buffer/service/sync_point_manager.h"
14 #include "gpu/config/gpu_info_collector.h" 14 #include "gpu/config/gpu_info_collector.h"
15 #include "gpu/config/gpu_switches.h" 15 #include "gpu/config/gpu_switches.h"
16 #include "gpu/config/gpu_util.h" 16 #include "gpu/config/gpu_util.h"
17 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
18 #include "gpu/ipc/common/memory_stats.h" 18 #include "gpu/ipc/common/memory_stats.h"
19 #include "gpu/ipc/common/surface_handle.h" 19 #include "gpu/ipc/common/surface_handle.h"
20 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 20 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
21 #include "ipc/ipc_channel_handle.h" 21 #include "ipc/ipc_channel_handle.h"
22 #include "ipc/ipc_sync_message_filter.h" 22 #include "ipc/ipc_sync_message_filter.h"
23 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" 23 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
24 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" 24 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h"
25 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" 25 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
26 #include "media/gpu/ipc/service/media_service.h" 26 #include "media/gpu/ipc/service/media_service.h"
27 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_switches.h" 28 #include "ui/gl/gl_switches.h"
29 #include "ui/gl/gpu_switching_manager.h" 29 #include "ui/gl/gpu_switching_manager.h"
30 #include "url/gurl.h" 30 #include "url/gurl.h"
31 31
32 namespace mus { 32 namespace mus {
33 namespace { 33 namespace {
34 34
35 const int kLocalGpuChannelClientId = 1; 35 const int kLocalGpuChannelClientId = 1;
36 const uint64_t kLocalGpuChannelClientTracingId = 1; 36 const uint64_t kLocalGpuChannelClientTracingId = 1;
37 37
38 void EstablishGpuChannelDone( 38 void EstablishGpuChannelDone(
39 int client_id,
39 std::unique_ptr<IPC::ChannelHandle> channel_handle, 40 std::unique_ptr<IPC::ChannelHandle> channel_handle,
40 const GpuServiceMus::EstablishGpuChannelCallback& callback) { 41 const GpuServiceMus::EstablishGpuChannelCallback& callback) {
41 callback.Run(*channel_handle); 42 callback.Run(channel_handle ? client_id : -1, *channel_handle);
42 } 43 }
43 } 44 }
44 45
45 GpuServiceMus::GpuServiceMus() 46 GpuServiceMus::GpuServiceMus()
46 : main_message_loop_(base::MessageLoop::current()), 47 : next_client_id_(kLocalGpuChannelClientId),
48 main_message_loop_(base::MessageLoop::current()),
47 shutdown_event_(true, false), 49 shutdown_event_(true, false),
48 gpu_thread_("GpuThread"), 50 gpu_thread_("GpuThread"),
49 io_thread_("GpuIOThread") { 51 io_thread_("GpuIOThread") {
50 Initialize(); 52 Initialize();
51 } 53 }
52 54
53 GpuServiceMus::~GpuServiceMus() { 55 GpuServiceMus::~GpuServiceMus() {
54 // Signal this event before destroying the child process. That way all 56 // Signal this event before destroying the child process. That way all
55 // background threads can cleanup. 57 // background threads can cleanup.
56 // For example, in the renderer the RenderThread instances will be able to 58 // For example, in the renderer the RenderThread instances will be able to
57 // notice shutdown before the render process begins waiting for them to exit. 59 // notice shutdown before the render process begins waiting for them to exit.
58 shutdown_event_.Signal(); 60 shutdown_event_.Signal();
59 io_thread_.Stop(); 61 io_thread_.Stop();
60 } 62 }
61 63
62 void GpuServiceMus::EstablishGpuChannel( 64 void GpuServiceMus::EstablishGpuChannel(
63 int client_id,
64 uint64_t client_tracing_id, 65 uint64_t client_tracing_id,
65 bool preempts, 66 bool preempts,
66 bool allow_view_command_buffers, 67 bool allow_view_command_buffers,
67 bool allow_real_time_streams, 68 bool allow_real_time_streams,
68 const EstablishGpuChannelCallback& callback) { 69 const EstablishGpuChannelCallback& callback) {
69 DCHECK_GT(client_id, kLocalGpuChannelClientId); 70 DCHECK(CalledOnValidThread());
70 71
71 if (!gpu_channel_manager_) { 72 if (!gpu_channel_manager_) {
72 callback.Run(IPC::ChannelHandle()); 73 callback.Run(-1, IPC::ChannelHandle());
73 return; 74 return;
74 } 75 }
75 76
77 const int client_id = ++next_client_id_;
76 std::unique_ptr<IPC::ChannelHandle> channel_handle(new IPC::ChannelHandle); 78 std::unique_ptr<IPC::ChannelHandle> channel_handle(new IPC::ChannelHandle);
77 gpu_thread_.task_runner()->PostTaskAndReply( 79 gpu_thread_.task_runner()->PostTaskAndReply(
78 FROM_HERE, 80 FROM_HERE,
79 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread, 81 base::Bind(&GpuServiceMus::EstablishGpuChannelOnGpuThread,
80 base::Unretained(this), client_id, client_tracing_id, preempts, 82 base::Unretained(this), client_id, client_tracing_id, preempts,
81 allow_view_command_buffers, allow_real_time_streams, 83 allow_view_command_buffers, allow_real_time_streams,
82 base::Unretained(channel_handle.get())), 84 base::Unretained(channel_handle.get())),
83 base::Bind(&EstablishGpuChannelDone, base::Passed(&channel_handle), 85 base::Bind(&EstablishGpuChannelDone, client_id,
84 callback)); 86 base::Passed(&channel_handle), callback));
85 } 87 }
86 88
87 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer( 89 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBuffer(
88 gfx::GpuMemoryBufferId id, 90 gfx::GpuMemoryBufferId id,
89 const gfx::Size& size, 91 const gfx::Size& size,
90 gfx::BufferFormat format, 92 gfx::BufferFormat format,
91 gfx::BufferUsage usage, 93 gfx::BufferUsage usage,
92 int client_id, 94 int client_id,
93 int32_t surface_handle) { 95 int32_t surface_handle) {
96 DCHECK(CalledOnValidThread());
94 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( 97 return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
95 id, size, format, usage, client_id, 98 id, size, format, usage, client_id,
96 static_cast<gpu::SurfaceHandle>(surface_handle)); 99 static_cast<gpu::SurfaceHandle>(surface_handle));
97 } 100 }
98 101
99 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle( 102 gfx::GpuMemoryBufferHandle GpuServiceMus::CreateGpuMemoryBufferFromeHandle(
100 gfx::GpuMemoryBufferHandle buffer_handle, 103 gfx::GpuMemoryBufferHandle buffer_handle,
101 gfx::GpuMemoryBufferId id, 104 gfx::GpuMemoryBufferId id,
102 const gfx::Size& size, 105 const gfx::Size& size,
103 gfx::BufferFormat format, 106 gfx::BufferFormat format,
104 int client_id) { 107 int client_id) {
108 DCHECK(CalledOnValidThread());
109
105 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle( 110 return gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle(
106 buffer_handle, id, size, format, client_id); 111 buffer_handle, id, size, format, client_id);
107 } 112 }
108 113
109 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, 114 void GpuServiceMus::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
110 int client_id, 115 int client_id,
111 const gpu::SyncToken& sync_token) { 116 const gpu::SyncToken& sync_token) {
117 DCHECK(CalledOnValidThread());
118
112 if (gpu_channel_manager_) 119 if (gpu_channel_manager_)
113 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); 120 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
114 } 121 }
115 122
116 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) { 123 void GpuServiceMus::DidCreateOffscreenContext(const GURL& active_url) {
117 NOTIMPLEMENTED(); 124 NOTIMPLEMENTED();
118 } 125 }
119 126
120 void GpuServiceMus::DidDestroyChannel(int client_id) { 127 void GpuServiceMus::DidDestroyChannel(int client_id) {
121 media_service_->RemoveChannel(client_id); 128 media_service_->RemoveChannel(client_id);
(...skipping 26 matching lines...) Expand all
148 gpu::SurfaceHandle child_window) { 155 gpu::SurfaceHandle child_window) {
149 NOTIMPLEMENTED(); 156 NOTIMPLEMENTED();
150 } 157 }
151 #endif 158 #endif
152 159
153 void GpuServiceMus::SetActiveURL(const GURL& url) { 160 void GpuServiceMus::SetActiveURL(const GURL& url) {
154 NOTIMPLEMENTED(); 161 NOTIMPLEMENTED();
155 } 162 }
156 163
157 void GpuServiceMus::Initialize() { 164 void GpuServiceMus::Initialize() {
165 DCHECK(CalledOnValidThread());
158 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0); 166 base::Thread::Options thread_options(base::MessageLoop::TYPE_DEFAULT, 0);
159 thread_options.priority = base::ThreadPriority::NORMAL; 167 thread_options.priority = base::ThreadPriority::NORMAL;
160 CHECK(gpu_thread_.StartWithOptions(thread_options)); 168 CHECK(gpu_thread_.StartWithOptions(thread_options));
161 169
162 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); 170 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
163 thread_options.priority = base::ThreadPriority::NORMAL; 171 thread_options.priority = base::ThreadPriority::NORMAL;
164 #if defined(OS_ANDROID) 172 #if defined(OS_ANDROID)
165 // TODO(reveman): Remove this in favor of setting it explicitly for each type 173 // TODO(reveman): Remove this in favor of setting it explicitly for each type
166 // of process. 174 // of process.
167 thread_options.priority = base::ThreadPriority::DISPLAY; 175 thread_options.priority = base::ThreadPriority::DISPLAY;
168 #endif 176 #endif
169 CHECK(io_thread_.StartWithOptions(thread_options)); 177 CHECK(io_thread_.StartWithOptions(thread_options));
170 178
171 IPC::ChannelHandle channel_handle; 179 IPC::ChannelHandle channel_handle;
172 bool manual_reset = true; 180 bool manual_reset = true;
173 bool initially_signaled = false; 181 bool initially_signaled = false;
174 base::WaitableEvent event(manual_reset, initially_signaled); 182 base::WaitableEvent event(manual_reset, initially_signaled);
175 gpu_thread_.task_runner()->PostTask( 183 gpu_thread_.task_runner()->PostTask(
176 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread, 184 FROM_HERE, base::Bind(&GpuServiceMus::InitializeOnGpuThread,
177 base::Unretained(this), &channel_handle, &event)); 185 base::Unretained(this), &channel_handle, &event));
178 event.Wait(); 186 event.Wait();
179 187
180 gpu_memory_buffer_manager_mus_local_.reset(new GpuMemoryBufferManagerMusLocal( 188 gpu_memory_buffer_manager_local_.reset(new MojoGpuMemoryBufferManager);
181 kLocalGpuChannelClientId, kLocalGpuChannelClientTracingId));
182 gpu_channel_local_ = gpu::GpuChannelHost::Create( 189 gpu_channel_local_ = gpu::GpuChannelHost::Create(
183 this, kLocalGpuChannelClientId, gpu_info_, channel_handle, 190 this, kLocalGpuChannelClientId, gpu_info_, channel_handle,
184 &shutdown_event_, gpu_memory_buffer_manager_mus_local_.get()); 191 &shutdown_event_, gpu_memory_buffer_manager_local_.get());
185 } 192 }
186 193
187 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, 194 void GpuServiceMus::InitializeOnGpuThread(IPC::ChannelHandle* channel_handle,
188 base::WaitableEvent* event) { 195 base::WaitableEvent* event) {
189 gpu_info_.video_decode_accelerator_capabilities = 196 gpu_info_.video_decode_accelerator_capabilities =
190 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 197 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
191 gpu_info_.video_encode_accelerator_supported_profiles = 198 gpu_info_.video_encode_accelerator_supported_profiles =
192 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 199 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
193 gpu_info_.jpeg_decode_accelerator_supported = 200 gpu_info_.jpeg_decode_accelerator_supported =
194 media::GpuJpegDecodeAccelerator::IsSupported(); 201 media::GpuJpegDecodeAccelerator::IsSupported();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return shm; 272 return shm;
266 } 273 }
267 274
268 // static 275 // static
269 GpuServiceMus* GpuServiceMus::GetInstance() { 276 GpuServiceMus* GpuServiceMus::GetInstance() {
270 return base::Singleton<GpuServiceMus, 277 return base::Singleton<GpuServiceMus,
271 base::LeakySingletonTraits<GpuServiceMus>>::get(); 278 base::LeakySingletonTraits<GpuServiceMus>>::get();
272 } 279 }
273 280
274 } // namespace mus 281 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698