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

Side by Side Diff: content/common/gpu/gpu_channel_manager.cc

Issue 1711533002: Decouple browser-specific GPU IPC messages from GPU service IPCs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Mark's nit Created 4 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/gpu_channel_manager.h" 5 #include "content/common/gpu/gpu_channel_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/common/gpu/establish_channel_params.h"
16 #include "content/common/gpu/gpu_channel.h" 17 #include "content/common/gpu/gpu_channel.h"
18 #include "content/common/gpu/gpu_channel_manager_delegate.h"
17 #include "content/common/gpu/gpu_memory_buffer_factory.h" 19 #include "content/common/gpu/gpu_memory_buffer_factory.h"
18 #include "content/common/gpu/gpu_memory_manager.h" 20 #include "content/common/gpu/gpu_memory_manager.h"
19 #include "content/common/gpu/gpu_messages.h" 21 #include "content/common/gpu/gpu_messages.h"
20 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
23 #include "gpu/command_buffer/common/sync_token.h"
21 #include "gpu/command_buffer/common/value_state.h" 24 #include "gpu/command_buffer/common/value_state.h"
22 #include "gpu/command_buffer/service/feature_info.h" 25 #include "gpu/command_buffer/service/feature_info.h"
23 #include "gpu/command_buffer/service/gpu_switches.h" 26 #include "gpu/command_buffer/service/gpu_switches.h"
24 #include "gpu/command_buffer/service/mailbox_manager.h" 27 #include "gpu/command_buffer/service/mailbox_manager.h"
25 #include "gpu/command_buffer/service/memory_program_cache.h" 28 #include "gpu/command_buffer/service/memory_program_cache.h"
26 #include "gpu/command_buffer/service/shader_translator_cache.h" 29 #include "gpu/command_buffer/service/shader_translator_cache.h"
27 #include "gpu/command_buffer/service/sync_point_manager.h" 30 #include "gpu/command_buffer/service/sync_point_manager.h"
28 #include "ipc/message_filter.h" 31 #include "ipc/message_filter.h"
29 #include "ipc/message_router.h" 32 #include "ipc/message_router.h"
30 #include "ui/gl/gl_bindings.h" 33 #include "ui/gl/gl_bindings.h"
31 #include "ui/gl/gl_share_group.h" 34 #include "ui/gl/gl_share_group.h"
32 35
33 namespace content { 36 namespace content {
34 37
35 namespace { 38 namespace {
36 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
37 // Amount of time we expect the GPU to stay powered up without being used. 40 // Amount of time we expect the GPU to stay powered up without being used.
38 const int kMaxGpuIdleTimeMs = 40; 41 const int kMaxGpuIdleTimeMs = 40;
39 // Maximum amount of time we keep pinging the GPU waiting for the client to 42 // Maximum amount of time we keep pinging the GPU waiting for the client to
40 // draw. 43 // draw.
41 const int kMaxKeepAliveTimeMs = 200; 44 const int kMaxKeepAliveTimeMs = 200;
42 #endif 45 #endif
43 46
44 } 47 }
45 48
46 GpuChannelManager::GpuChannelManager( 49 GpuChannelManager::GpuChannelManager(
50 GpuChannelManagerDelegate* delegate,
47 IPC::SyncChannel* channel, 51 IPC::SyncChannel* channel,
48 GpuWatchdog* watchdog, 52 GpuWatchdog* watchdog,
49 base::SingleThreadTaskRunner* task_runner, 53 base::SingleThreadTaskRunner* task_runner,
50 base::SingleThreadTaskRunner* io_task_runner, 54 base::SingleThreadTaskRunner* io_task_runner,
51 base::WaitableEvent* shutdown_event, 55 base::WaitableEvent* shutdown_event,
52 gpu::SyncPointManager* sync_point_manager, 56 gpu::SyncPointManager* sync_point_manager,
53 GpuMemoryBufferFactory* gpu_memory_buffer_factory) 57 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
54 : task_runner_(task_runner), 58 : task_runner_(task_runner),
55 io_task_runner_(io_task_runner), 59 io_task_runner_(io_task_runner),
60 delegate_(delegate),
56 channel_(channel), 61 channel_(channel),
57 watchdog_(watchdog), 62 watchdog_(watchdog),
58 shutdown_event_(shutdown_event), 63 shutdown_event_(shutdown_event),
59 share_group_(new gfx::GLShareGroup), 64 share_group_(new gfx::GLShareGroup),
60 mailbox_manager_(gpu::gles2::MailboxManager::Create()), 65 mailbox_manager_(gpu::gles2::MailboxManager::Create()),
61 gpu_memory_manager_(this), 66 gpu_memory_manager_(this),
62 sync_point_manager_(sync_point_manager), 67 sync_point_manager_(sync_point_manager),
63 sync_point_client_waiter_( 68 sync_point_client_waiter_(
64 sync_point_manager->CreateSyncPointClientWaiter()), 69 sync_point_manager->CreateSyncPointClientWaiter()),
65 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 70 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 106
102 gpu::gles2::FramebufferCompletenessCache* 107 gpu::gles2::FramebufferCompletenessCache*
103 GpuChannelManager::framebuffer_completeness_cache() { 108 GpuChannelManager::framebuffer_completeness_cache() {
104 if (!framebuffer_completeness_cache_.get()) 109 if (!framebuffer_completeness_cache_.get())
105 framebuffer_completeness_cache_ = 110 framebuffer_completeness_cache_ =
106 new gpu::gles2::FramebufferCompletenessCache; 111 new gpu::gles2::FramebufferCompletenessCache;
107 return framebuffer_completeness_cache_.get(); 112 return framebuffer_completeness_cache_.get();
108 } 113 }
109 114
110 void GpuChannelManager::RemoveChannel(int client_id) { 115 void GpuChannelManager::RemoveChannel(int client_id) {
111 Send(new GpuHostMsg_DestroyChannel(client_id)); 116 delegate_->DidDestroyChannel(client_id);
112 gpu_channels_.erase(client_id); 117 gpu_channels_.erase(client_id);
113 } 118 }
114 119
115 int GpuChannelManager::GenerateRouteID() { 120 int GpuChannelManager::GenerateRouteID() {
116 static int last_id = 0; 121 static int last_id = 0;
117 return ++last_id; 122 return ++last_id;
118 } 123 }
119 124
120 void GpuChannelManager::AddRoute(int32_t routing_id, IPC::Listener* listener) { 125 void GpuChannelManager::AddRoute(int32_t routing_id, IPC::Listener* listener) {
121 router_.AddRoute(routing_id, listener); 126 router_.AddRoute(routing_id, listener);
122 } 127 }
123 128
124 void GpuChannelManager::RemoveRoute(int32_t routing_id) { 129 void GpuChannelManager::RemoveRoute(int32_t routing_id) {
125 router_.RemoveRoute(routing_id); 130 router_.RemoveRoute(routing_id);
126 } 131 }
127 132
128 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { 133 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const {
129 const auto& it = gpu_channels_.find(client_id); 134 const auto& it = gpu_channels_.find(client_id);
130 return it != gpu_channels_.end() ? it->second : nullptr; 135 return it != gpu_channels_.end() ? it->second : nullptr;
131 } 136 }
132 137
133 bool GpuChannelManager::OnControlMessageReceived(const IPC::Message& msg) {
134 bool handled = true;
135 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg)
136 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
137 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
138 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
139 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
140 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState)
141 #if defined(OS_ANDROID)
142 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu);
143 #endif
144 IPC_MESSAGE_UNHANDLED(handled = false)
145 IPC_END_MESSAGE_MAP()
146 return handled;
147 }
148
149 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { 138 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) {
150 if (msg.routing_id() == MSG_ROUTING_CONTROL) 139 DCHECK_NE(MSG_ROUTING_CONTROL, msg.routing_id());
151 return OnControlMessageReceived(msg);
152
153 return router_.RouteMessage(msg); 140 return router_.RouteMessage(msg);
154 } 141 }
155 142
156 bool GpuChannelManager::Send(IPC::Message* msg) {
157 return channel_->Send(msg);
158 }
159
160 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( 143 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel(
161 int client_id, 144 int client_id,
162 uint64_t client_tracing_id, 145 uint64_t client_tracing_id,
163 bool preempts, 146 bool preempts,
164 bool allow_view_command_buffers, 147 bool allow_view_command_buffers,
165 bool allow_real_time_streams) { 148 bool allow_real_time_streams) {
166 return make_scoped_ptr(new GpuChannel( 149 return make_scoped_ptr(new GpuChannel(
167 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), 150 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(),
168 preempts ? preemption_flag() : nullptr, task_runner_.get(), 151 preempts ? preemption_flag() : nullptr, task_runner_.get(),
169 io_task_runner_.get(), client_id, client_tracing_id, 152 io_task_runner_.get(), client_id, client_tracing_id,
170 allow_view_command_buffers, allow_real_time_streams)); 153 allow_view_command_buffers, allow_real_time_streams));
171 } 154 }
172 155
173 void GpuChannelManager::OnEstablishChannel( 156 void GpuChannelManager::EstablishChannel(const EstablishChannelParams& params) {
174 const GpuMsg_EstablishChannel_Params& params) {
175 scoped_ptr<GpuChannel> channel(CreateGpuChannel( 157 scoped_ptr<GpuChannel> channel(CreateGpuChannel(
176 params.client_id, params.client_tracing_id, params.preempts, 158 params.client_id, params.client_tracing_id, params.preempts,
177 params.allow_view_command_buffers, params.allow_real_time_streams)); 159 params.allow_view_command_buffers, params.allow_real_time_streams));
178 if (!params.preempts) 160 if (!params.preempts)
179 channel->SetPreemptByFlag(preemption_flag_.get()); 161 channel->SetPreemptByFlag(preemption_flag_.get());
180 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_); 162 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_);
181 163
182 gpu_channels_.set(params.client_id, std::move(channel)); 164 gpu_channels_.set(params.client_id, std::move(channel));
183 165
184 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); 166 delegate_->ChannelEstablished(channel_handle);
185 } 167 }
186 168
187 void GpuChannelManager::OnCloseChannel( 169 void GpuChannelManager::CloseChannel(const IPC::ChannelHandle& channel_handle) {
188 const IPC::ChannelHandle& channel_handle) {
189 for (auto it = gpu_channels_.begin(); it != gpu_channels_.end(); ++it) { 170 for (auto it = gpu_channels_.begin(); it != gpu_channels_.end(); ++it) {
190 if (it->second->channel_id() == channel_handle.name) { 171 if (it->second->channel_id() == channel_handle.name) {
191 gpu_channels_.erase(it); 172 gpu_channels_.erase(it);
192 return; 173 return;
193 } 174 }
194 } 175 }
195 } 176 }
196 177
197 void GpuChannelManager::DestroyGpuMemoryBuffer( 178 void GpuChannelManager::InternalDestroyGpuMemoryBuffer(
198 gfx::GpuMemoryBufferId id, 179 gfx::GpuMemoryBufferId id,
199 int client_id) { 180 int client_id) {
200 io_task_runner_->PostTask( 181 io_task_runner_->PostTask(
201 FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, 182 FROM_HERE,
202 base::Unretained(this), id, client_id)); 183 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO,
184 base::Unretained(this), id, client_id));
203 } 185 }
204 186
205 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( 187 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO(
206 gfx::GpuMemoryBufferId id, 188 gfx::GpuMemoryBufferId id,
207 int client_id) { 189 int client_id) {
208 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); 190 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id);
209 } 191 }
210 192
211 void GpuChannelManager::OnDestroyGpuMemoryBuffer( 193 void GpuChannelManager::DestroyGpuMemoryBuffer(
212 gfx::GpuMemoryBufferId id, 194 gfx::GpuMemoryBufferId id,
213 int client_id, 195 int client_id,
214 const gpu::SyncToken& sync_token) { 196 const gpu::SyncToken& sync_token) {
215 if (sync_token.HasData()) { 197 if (sync_token.HasData()) {
216 scoped_refptr<gpu::SyncPointClientState> release_state = 198 scoped_refptr<gpu::SyncPointClientState> release_state =
217 sync_point_manager()->GetSyncPointClientState( 199 sync_point_manager()->GetSyncPointClientState(
218 sync_token.namespace_id(), sync_token.command_buffer_id()); 200 sync_token.namespace_id(), sync_token.command_buffer_id());
219 if (release_state) { 201 if (release_state) {
220 sync_point_client_waiter_->WaitOutOfOrder( 202 sync_point_client_waiter_->WaitOutOfOrder(
221 release_state.get(), sync_token.release_count(), 203 release_state.get(), sync_token.release_count(),
222 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, 204 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer,
223 base::Unretained(this), id, client_id)); 205 base::Unretained(this), id, client_id));
224 return; 206 return;
225 } 207 }
226 } 208 }
227 209
228 // No sync token or invalid sync token, destroy immediately. 210 // No sync token or invalid sync token, destroy immediately.
229 DestroyGpuMemoryBuffer(id, client_id); 211 InternalDestroyGpuMemoryBuffer(id, client_id);
230 } 212 }
231 213
232 void GpuChannelManager::OnUpdateValueState( 214 void GpuChannelManager::UpdateValueState(int client_id,
233 int client_id, unsigned int target, const gpu::ValueState& state) { 215 unsigned int target,
216 const gpu::ValueState& state) {
234 // Only pass updated state to the channel corresponding to the 217 // Only pass updated state to the channel corresponding to the
235 // render_widget_host where the event originated. 218 // render_widget_host where the event originated.
236 auto it = gpu_channels_.find(client_id); 219 auto it = gpu_channels_.find(client_id);
237 if (it != gpu_channels_.end()) 220 if (it != gpu_channels_.end())
238 it->second->HandleUpdateValueState(target, state); 221 it->second->HandleUpdateValueState(target, state);
239 } 222 }
240 223
241 void GpuChannelManager::OnLoadedShader(const std::string& program_proto) { 224 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) {
242 if (program_cache()) 225 if (program_cache())
243 program_cache()->LoadProgram(program_proto); 226 program_cache()->LoadProgram(program_proto);
244 } 227 }
245 228
246 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const { 229 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const {
247 uint32_t unprocessed_order_num = 0; 230 uint32_t unprocessed_order_num = 0;
248 for (auto& kv : gpu_channels_) { 231 for (auto& kv : gpu_channels_) {
249 unprocessed_order_num = 232 unprocessed_order_num =
250 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); 233 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum());
251 } 234 }
252 return unprocessed_order_num; 235 return unprocessed_order_num;
253 } 236 }
254 237
255 uint32_t GpuChannelManager::GetProcessedOrderNum() const { 238 uint32_t GpuChannelManager::GetProcessedOrderNum() const {
256 uint32_t processed_order_num = 0; 239 uint32_t processed_order_num = 0;
257 for (auto& kv : gpu_channels_) { 240 for (auto& kv : gpu_channels_) {
258 processed_order_num = 241 processed_order_num =
259 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); 242 std::max(processed_order_num, kv.second->GetProcessedOrderNum());
260 } 243 }
261 return processed_order_num; 244 return processed_order_num;
262 } 245 }
263 246
264 void GpuChannelManager::LoseAllContexts() { 247 void GpuChannelManager::LoseAllContexts() {
265 for (auto& kv : gpu_channels_) { 248 for (auto& kv : gpu_channels_) {
266 kv.second->MarkAllContextsLost(); 249 kv.second->MarkAllContextsLost();
267 } 250 }
268 task_runner_->PostTask(FROM_HERE, 251 task_runner_->PostTask(FROM_HERE,
269 base::Bind(&GpuChannelManager::OnLoseAllContexts, 252 base::Bind(&GpuChannelManager::DestroyAllChannels,
270 weak_factory_.GetWeakPtr())); 253 weak_factory_.GetWeakPtr()));
271 } 254 }
272 255
273 void GpuChannelManager::OnLoseAllContexts() { 256 void GpuChannelManager::DestroyAllChannels() {
274 gpu_channels_.clear(); 257 gpu_channels_.clear();
275 } 258 }
276 259
277 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { 260 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
278 if (!default_offscreen_surface_.get()) { 261 if (!default_offscreen_surface_.get()) {
279 default_offscreen_surface_ = 262 default_offscreen_surface_ =
280 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); 263 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size());
281 } 264 }
282 return default_offscreen_surface_.get(); 265 return default_offscreen_surface_.get();
283 } 266 }
284 267
285 #if defined(OS_ANDROID) 268 #if defined(OS_ANDROID)
286 void GpuChannelManager::DidAccessGpu() { 269 void GpuChannelManager::DidAccessGpu() {
287 last_gpu_access_time_ = base::TimeTicks::Now(); 270 last_gpu_access_time_ = base::TimeTicks::Now();
288 } 271 }
289 272
290 void GpuChannelManager::OnWakeUpGpu() { 273 void GpuChannelManager::WakeUpGpu() {
291 begin_wake_up_time_ = base::TimeTicks::Now(); 274 begin_wake_up_time_ = base::TimeTicks::Now();
292 ScheduleWakeUpGpu(); 275 ScheduleWakeUpGpu();
293 } 276 }
294 277
295 void GpuChannelManager::ScheduleWakeUpGpu() { 278 void GpuChannelManager::ScheduleWakeUpGpu() {
296 base::TimeTicks now = base::TimeTicks::Now(); 279 base::TimeTicks now = base::TimeTicks::Now();
297 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", 280 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp",
298 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), 281 "idle_time", (now - last_gpu_access_time_).InMilliseconds(),
299 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); 282 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds());
300 if (now - last_gpu_access_time_ < 283 if (now - last_gpu_access_time_ <
(...skipping 22 matching lines...) Expand all
323 } 306 }
324 } 307 }
325 if (!stub || !stub->decoder()->MakeCurrent()) 308 if (!stub || !stub->decoder()->MakeCurrent())
326 return; 309 return;
327 glFinish(); 310 glFinish();
328 DidAccessGpu(); 311 DidAccessGpu();
329 } 312 }
330 #endif 313 #endif
331 314
332 } // namespace content 315 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698