OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return false; | 80 return false; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 84 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
85 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 85 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
86 bool handled = true; | 86 bool handled = true; |
87 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 87 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
88 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, | 88 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
89 OnInitialize); | 89 OnInitialize); |
90 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetGetBuffer, | |
91 OnSetGetBuffer); | |
92 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, | 90 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, |
93 OnSetParent); | 91 OnSetParent); |
94 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); | 92 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); |
95 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetStateFast, | 93 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetStateFast, |
96 OnGetStateFast); | 94 OnGetStateFast); |
97 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 95 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
98 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Rescheduled, OnRescheduled); | 96 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Rescheduled, OnRescheduled); |
99 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateTransferBuffer, | 97 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateTransferBuffer, |
100 OnCreateTransferBuffer); | 98 OnCreateTransferBuffer); |
101 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_RegisterTransferBuffer, | 99 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_RegisterTransferBuffer, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 surface_ = NULL; | 152 surface_ = NULL; |
155 } | 153 } |
156 | 154 |
157 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { | 155 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
158 Destroy(); | 156 Destroy(); |
159 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); | 157 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
160 Send(reply_message); | 158 Send(reply_message); |
161 } | 159 } |
162 | 160 |
163 void GpuCommandBufferStub::OnInitialize( | 161 void GpuCommandBufferStub::OnInitialize( |
| 162 base::SharedMemoryHandle ring_buffer, |
| 163 int32 size, |
164 IPC::Message* reply_message) { | 164 IPC::Message* reply_message) { |
165 DCHECK(!command_buffer_.get()); | 165 DCHECK(!command_buffer_.get()); |
166 | 166 |
167 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "TryCreateGLContext"); | 167 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "TryCreateGLContext"); |
168 | 168 |
169 command_buffer_.reset(new gpu::CommandBufferService); | 169 command_buffer_.reset(new gpu::CommandBufferService); |
170 | 170 |
171 if (!command_buffer_->Initialize()) { | 171 #if defined(OS_WIN) |
| 172 // Windows dups the shared memory handle it receives into the current process |
| 173 // and closes it when this variable goes out of scope. |
| 174 base::SharedMemory shared_memory(ring_buffer, |
| 175 false, |
| 176 channel_->renderer_process()); |
| 177 #else |
| 178 // POSIX receives a dup of the shared memory handle and closes the dup when |
| 179 // this variable goes out of scope. |
| 180 base::SharedMemory shared_memory(ring_buffer, false); |
| 181 #endif |
| 182 |
| 183 if (!command_buffer_->Initialize(&shared_memory, size)) { |
172 DLOG(ERROR) << "CommandBufferService failed to initialize.\n"; | 184 DLOG(ERROR) << "CommandBufferService failed to initialize.\n"; |
173 OnInitializeFailed(reply_message); | 185 OnInitializeFailed(reply_message); |
174 return; | 186 return; |
175 } | 187 } |
176 | 188 |
177 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); | 189 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); |
178 | 190 |
179 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), | 191 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
180 decoder_.get(), | 192 decoder_.get(), |
181 NULL)); | 193 NULL)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (CommandLine::ForCurrentProcess()->HasSwitch( | 255 if (CommandLine::ForCurrentProcess()->HasSwitch( |
244 switches::kEnableGPUServiceLogging)) { | 256 switches::kEnableGPUServiceLogging)) { |
245 decoder_->set_debug(true); | 257 decoder_->set_debug(true); |
246 } | 258 } |
247 | 259 |
248 SetSwapInterval(); | 260 SetSwapInterval(); |
249 | 261 |
250 command_buffer_->SetPutOffsetChangeCallback( | 262 command_buffer_->SetPutOffsetChangeCallback( |
251 base::Bind(&gpu::GpuScheduler::PutChanged, | 263 base::Bind(&gpu::GpuScheduler::PutChanged, |
252 base::Unretained(scheduler_.get()))); | 264 base::Unretained(scheduler_.get()))); |
253 command_buffer_->SetGetBufferChangeCallback( | |
254 base::Bind(&gpu::GpuScheduler::SetGetBuffer, | |
255 base::Unretained(scheduler_.get()))); | |
256 command_buffer_->SetParseErrorCallback( | 265 command_buffer_->SetParseErrorCallback( |
257 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); | 266 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
258 scheduler_->SetScheduledCallback( | 267 scheduler_->SetScheduledCallback( |
259 base::Bind(&GpuChannel::OnScheduled, base::Unretained(channel_))); | 268 base::Bind(&GpuChannel::OnScheduled, base::Unretained(channel_))); |
260 | 269 |
261 if (watchdog_) { | 270 if (watchdog_) { |
262 scheduler_->SetCommandProcessedCallback( | 271 scheduler_->SetCommandProcessedCallback( |
263 base::Bind(&GpuCommandBufferStub::OnCommandProcessed, | 272 base::Bind(&GpuCommandBufferStub::OnCommandProcessed, |
264 base::Unretained(this))); | 273 base::Unretained(this))); |
265 } | 274 } |
266 | 275 |
267 if (parent_stub_for_initialization_) { | 276 if (parent_stub_for_initialization_) { |
268 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), | 277 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), |
269 parent_texture_for_initialization_); | 278 parent_texture_for_initialization_); |
270 parent_stub_for_initialization_.reset(); | 279 parent_stub_for_initialization_.reset(); |
271 parent_texture_for_initialization_ = 0; | 280 parent_texture_for_initialization_ = 0; |
272 } | 281 } |
273 | 282 |
274 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); | 283 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
275 Send(reply_message); | 284 Send(reply_message); |
276 | 285 |
277 UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "CreateGLContextSuccess", | 286 UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "CreateGLContextSuccess", |
278 "offscreen", surface_->IsOffscreen()); | 287 "offscreen", surface_->IsOffscreen()); |
279 } | 288 } |
280 | 289 |
281 void GpuCommandBufferStub::OnSetGetBuffer( | |
282 int32 shm_id, IPC::Message* reply_message) { | |
283 command_buffer_->SetGetBuffer(shm_id); | |
284 Send(reply_message); | |
285 } | |
286 | |
287 void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, | 290 void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, |
288 uint32 parent_texture_id, | 291 uint32 parent_texture_id, |
289 IPC::Message* reply_message) { | 292 IPC::Message* reply_message) { |
290 | 293 |
291 GpuCommandBufferStub* parent_stub = NULL; | 294 GpuCommandBufferStub* parent_stub = NULL; |
292 if (parent_route_id != MSG_ROUTING_NONE) { | 295 if (parent_route_id != MSG_ROUTING_NONE) { |
293 parent_stub = channel_->LookupCommandBuffer(parent_route_id); | 296 parent_stub = channel_->LookupCommandBuffer(parent_route_id); |
294 } | 297 } |
295 | 298 |
296 bool result = true; | 299 bool result = true; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 465 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
463 channel_->RemoveRoute(decoder_route_id); | 466 channel_->RemoveRoute(decoder_route_id); |
464 video_decoders_.Remove(decoder_route_id); | 467 video_decoders_.Remove(decoder_route_id); |
465 } | 468 } |
466 | 469 |
467 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 470 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
468 surface_->SetVisible(visible); | 471 surface_->SetVisible(visible); |
469 } | 472 } |
470 | 473 |
471 #endif // defined(ENABLE_GPU) | 474 #endif // defined(ENABLE_GPU) |
OLD | NEW |