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

Side by Side Diff: services/ui/gpu/gpu_service_internal.cc

Issue 2481263002: Introduce Display Compositor mojo interface. Use InProcessContextProvider. (Closed)
Patch Set: Speculative fix for android build issue Created 4 years, 1 month 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 "services/ui/gpu/gpu_service_internal.h" 5 #include "services/ui/gpu/gpu_service_internal.h"
6 6
7 #include "base/bind.h"
7 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
8 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "cc/output/in_process_context_provider.h"
10 #include "gpu/command_buffer/service/gpu_switches.h" 12 #include "gpu/command_buffer/service/gpu_switches.h"
11 #include "gpu/command_buffer/service/sync_point_manager.h" 13 #include "gpu/command_buffer/service/sync_point_manager.h"
12 #include "gpu/config/gpu_info_collector.h" 14 #include "gpu/config/gpu_info_collector.h"
13 #include "gpu/config/gpu_switches.h" 15 #include "gpu/config/gpu_switches.h"
14 #include "gpu/config/gpu_util.h" 16 #include "gpu/config/gpu_util.h"
15 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 17 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
16 #include "gpu/ipc/common/memory_stats.h" 18 #include "gpu/ipc/common/memory_stats.h"
19 #include "gpu/ipc/gpu_in_process_thread_service.h"
20 #include "gpu/ipc/service/gpu_channel_manager.h"
17 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 21 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
18 #include "gpu/ipc/service/gpu_watchdog_thread.h" 22 #include "gpu/ipc/service/gpu_watchdog_thread.h"
19 #include "ipc/ipc_channel_handle.h" 23 #include "ipc/ipc_channel_handle.h"
20 #include "ipc/ipc_sync_message_filter.h" 24 #include "ipc/ipc_sync_message_filter.h"
21 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" 25 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
22 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" 26 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h"
23 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" 27 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
24 #include "media/gpu/ipc/service/media_gpu_channel_manager.h" 28 #include "media/gpu/ipc/service/media_gpu_channel_manager.h"
29 #include "mojo/public/cpp/bindings/strong_binding.h"
30 #include "services/ui/surfaces/display_compositor.h"
31 #include "services/ui/surfaces/mus_gpu_memory_buffer_manager.h"
25 #include "ui/gl/gl_implementation.h" 32 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/gl_switches.h" 33 #include "ui/gl/gl_switches.h"
27 #include "ui/gl/gpu_switching_manager.h" 34 #include "ui/gl/gpu_switching_manager.h"
28 #include "ui/gl/init/gl_factory.h" 35 #include "ui/gl/init/gl_factory.h"
29 #include "url/gurl.h" 36 #include "url/gurl.h"
30 37
31 namespace ui { 38 namespace ui {
32 39
33 GpuServiceInternal::GpuServiceInternal( 40 GpuServiceInternal::GpuServiceInternal(
34 const gpu::GPUInfo& gpu_info, 41 const gpu::GPUInfo& gpu_info,
35 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 42 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
36 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 43 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
37 scoped_refptr<base::SingleThreadTaskRunner> io_runner) 44 scoped_refptr<base::SingleThreadTaskRunner> io_runner)
38 : io_runner_(std::move(io_runner)), 45 : io_runner_(std::move(io_runner)),
39 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 46 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
40 base::WaitableEvent::InitialState::NOT_SIGNALED), 47 base::WaitableEvent::InitialState::NOT_SIGNALED),
41 watchdog_thread_(std::move(watchdog_thread)), 48 watchdog_thread_(std::move(watchdog_thread)),
42 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 49 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
43 gpu_info_(gpu_info), 50 gpu_info_(gpu_info),
44 binding_(this) {} 51 compositor_thread_("DisplayCompositorThread") {
52 compositor_thread_.Start();
53 }
45 54
46 GpuServiceInternal::~GpuServiceInternal() { 55 GpuServiceInternal::~GpuServiceInternal() {
47 binding_.Close(); 56 bindings_.CloseAllBindings();
48 media_gpu_channel_manager_.reset(); 57 media_gpu_channel_manager_.reset();
49 gpu_channel_manager_.reset(); 58 gpu_channel_manager_.reset();
50 owned_sync_point_manager_.reset(); 59 owned_sync_point_manager_.reset();
51 60
52 // Signal this event before destroying the child process. That way all 61 // Signal this event before destroying the child process. That way all
53 // background threads can cleanup. 62 // background threads can cleanup.
54 // For example, in the renderer the RenderThread instances will be able to 63 // For example, in the renderer the RenderThread instances will be able to
55 // notice shutdown before the render process begins waiting for them to exit. 64 // notice shutdown before the render process begins waiting for them to exit.
56 shutdown_event_.Signal(); 65 shutdown_event_.Signal();
57 } 66 }
58 67
59 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) { 68 void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) {
60 binding_.Close(); 69 bindings_.AddBinding(this, std::move(request));
61 binding_.Bind(std::move(request));
62 } 70 }
63 71
64 void GpuServiceInternal::CreateGpuMemoryBuffer( 72 void GpuServiceInternal::CreateGpuMemoryBuffer(
65 gfx::GpuMemoryBufferId id, 73 gfx::GpuMemoryBufferId id,
66 const gfx::Size& size, 74 const gfx::Size& size,
67 gfx::BufferFormat format, 75 gfx::BufferFormat format,
68 gfx::BufferUsage usage, 76 gfx::BufferUsage usage,
69 int client_id, 77 int client_id,
70 gpu::SurfaceHandle surface_handle, 78 gpu::SurfaceHandle surface_handle,
71 const CreateGpuMemoryBufferCallback& callback) { 79 const CreateGpuMemoryBufferCallback& callback) {
72 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
73 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( 81 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
74 id, size, format, usage, client_id, surface_handle)); 82 id, size, format, usage, client_id, surface_handle));
75 } 83 }
76 84
77 void GpuServiceInternal::DestroyGpuMemoryBuffer( 85 void GpuServiceInternal::DestroyGpuMemoryBuffer(
78 gfx::GpuMemoryBufferId id, 86 gfx::GpuMemoryBufferId id,
79 int client_id, 87 int client_id,
80 const gpu::SyncToken& sync_token) { 88 const gpu::SyncToken& sync_token) {
81 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
82 if (gpu_channel_manager_) 90 if (gpu_channel_manager_)
83 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); 91 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
84 } 92 }
85 93
94 void GpuServiceInternal::CreateDisplayCompositor(
95 cc::mojom::DisplayCompositorRequest request,
96 cc::mojom::DisplayCompositorClientPtr client) {
97 DCHECK(CalledOnValidThread());
98 DCHECK(!gpu_command_service_);
99 gpu_command_service_ = new gpu::GpuInProcessThreadService(
100 base::ThreadTaskRunnerHandle::Get(), owned_sync_point_manager_.get(),
101 gpu_channel_manager_->mailbox_manager(),
102 gpu_channel_manager_->share_group());
103 mojom::GpuServiceInternalPtr gpu_service_ptr;
104 Add(mojo::GetProxy(&gpu_service_ptr));
105 compositor_thread_.task_runner()->PostTask(
106 FROM_HERE,
107 base::Bind(&GpuServiceInternal::CreateDisplayCompositorOnCompositorThread,
108 base::Unretained(this),
109 base::Passed(gpu_service_ptr.PassInterface()),
110 base::Passed(&request), base::Passed(client.PassInterface())));
111 }
112
113 void GpuServiceInternal::CreateDisplayCompositorOnCompositorThread(
114 mojom::GpuServiceInternalPtrInfo gpu_service_info,
115 cc::mojom::DisplayCompositorRequest request,
116 cc::mojom::DisplayCompositorClientPtrInfo client_info) {
117 DCHECK(compositor_thread_.task_runner()->BelongsToCurrentThread());
118 mojom::GpuServiceInternalPtr gpu_service_ptr;
119 gpu_service_ptr.Bind(std::move(gpu_service_info));
120
121 cc::mojom::DisplayCompositorClientPtr client_ptr;
122 client_ptr.Bind(std::move(client_info));
123
124 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager =
125 base::MakeUnique<MusGpuMemoryBufferManager>(std::move(gpu_service_ptr),
126 1 /* client_id */);
127 // |gpu_memory_buffer_factory_| is null in tests.
128 gpu::ImageFactory* image_factory =
129 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory()
130 : nullptr;
131 mojo::MakeStrongBinding(
132 base::MakeUnique<DisplayCompositor>(gpu_command_service_,
133 std::move(gpu_memory_buffer_manager),
134 image_factory, std::move(client_ptr)),
135 std::move(request));
136 }
86 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) { 137 void GpuServiceInternal::DidCreateOffscreenContext(const GURL& active_url) {
87 NOTIMPLEMENTED(); 138 NOTIMPLEMENTED();
88 } 139 }
89 140
90 void GpuServiceInternal::DidDestroyChannel(int client_id) { 141 void GpuServiceInternal::DidDestroyChannel(int client_id) {
91 media_gpu_channel_manager_->RemoveChannel(client_id); 142 media_gpu_channel_manager_->RemoveChannel(client_id);
92 NOTIMPLEMENTED(); 143 NOTIMPLEMENTED();
93 } 144 }
94 145
95 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) { 146 void GpuServiceInternal::DidDestroyOffscreenContext(const GURL& active_url) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // IPC messages before the sandbox has been enabled and all other necessary 189 // IPC messages before the sandbox has been enabled and all other necessary
139 // initialization has succeeded. 190 // initialization has succeeded.
140 gpu_channel_manager_.reset(new gpu::GpuChannelManager( 191 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
141 gpu_preferences_, this, watchdog_thread_.get(), 192 gpu_preferences_, this, watchdog_thread_.get(),
142 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), 193 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
143 &shutdown_event_, owned_sync_point_manager_.get(), 194 &shutdown_event_, owned_sync_point_manager_.get(),
144 gpu_memory_buffer_factory_)); 195 gpu_memory_buffer_factory_));
145 196
146 media_gpu_channel_manager_.reset( 197 media_gpu_channel_manager_.reset(
147 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); 198 new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
199
148 callback.Run(gpu_info_); 200 callback.Run(gpu_info_);
149 } 201 }
150 202
151 void GpuServiceInternal::EstablishGpuChannel( 203 void GpuServiceInternal::EstablishGpuChannel(
152 int32_t client_id, 204 int32_t client_id,
153 uint64_t client_tracing_id, 205 uint64_t client_tracing_id,
154 bool is_gpu_host, 206 bool is_gpu_host,
155 const EstablishGpuChannelCallback& callback) { 207 const EstablishGpuChannelCallback& callback) {
156 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
157 209
158 if (!gpu_channel_manager_) { 210 if (!gpu_channel_manager_) {
159 callback.Run(mojo::ScopedMessagePipeHandle()); 211 callback.Run(mojo::ScopedMessagePipeHandle());
160 return; 212 return;
161 } 213 }
162 214
163 const bool preempts = is_gpu_host; 215 const bool preempts = is_gpu_host;
164 const bool allow_view_command_buffers = is_gpu_host; 216 const bool allow_view_command_buffers = is_gpu_host;
165 const bool allow_real_time_streams = is_gpu_host; 217 const bool allow_real_time_streams = is_gpu_host;
166 mojo::ScopedMessagePipeHandle channel_handle; 218 mojo::ScopedMessagePipeHandle channel_handle;
167 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel( 219 IPC::ChannelHandle handle = gpu_channel_manager_->EstablishChannel(
168 client_id, client_tracing_id, preempts, allow_view_command_buffers, 220 client_id, client_tracing_id, preempts, allow_view_command_buffers,
169 allow_real_time_streams); 221 allow_real_time_streams);
170 channel_handle.reset(handle.mojo_handle); 222 channel_handle.reset(handle.mojo_handle);
171 media_gpu_channel_manager_->AddChannel(client_id); 223 media_gpu_channel_manager_->AddChannel(client_id);
172 callback.Run(std::move(channel_handle)); 224 callback.Run(std::move(channel_handle));
173 } 225 }
174 226
175 } // namespace ui 227 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698