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

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

Powered by Google App Engine
This is Rietveld 408576698