OLD | NEW |
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/client/command_buffer_proxy_impl.h" | 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 244 } |
245 | 245 |
246 void CommandBufferProxyImpl::SetGetBuffer(int32 shm_id) { | 246 void CommandBufferProxyImpl::SetGetBuffer(int32 shm_id) { |
247 if (last_state_.error != gpu::error::kNoError) | 247 if (last_state_.error != gpu::error::kNoError) |
248 return; | 248 return; |
249 | 249 |
250 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); | 250 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); |
251 last_put_offset_ = -1; | 251 last_put_offset_ = -1; |
252 } | 252 } |
253 | 253 |
254 void CommandBufferProxyImpl::SetGetOffset(int32 get_offset) { | |
255 // Not implemented in proxy. | |
256 NOTREACHED(); | |
257 } | |
258 | |
259 scoped_refptr<gpu::Buffer> CommandBufferProxyImpl::CreateTransferBuffer( | 254 scoped_refptr<gpu::Buffer> CommandBufferProxyImpl::CreateTransferBuffer( |
260 size_t size, | 255 size_t size, |
261 int32* id) { | 256 int32* id) { |
262 *id = -1; | 257 *id = -1; |
263 | 258 |
264 if (last_state_.error != gpu::error::kNoError) | 259 if (last_state_.error != gpu::error::kNoError) |
265 return NULL; | 260 return NULL; |
266 | 261 |
267 int32 new_id = channel_->ReserveTransferBufferId(); | 262 int32 new_id = channel_->ReserveTransferBufferId(); |
268 DCHECK(transfer_buffers_.find(new_id) == transfer_buffers_.end()); | |
269 | 263 |
270 scoped_ptr<base::SharedMemory> shared_memory( | 264 scoped_ptr<base::SharedMemory> shared_memory( |
271 channel_->factory()->AllocateSharedMemory(size)); | 265 channel_->factory()->AllocateSharedMemory(size)); |
272 if (!shared_memory) | 266 if (!shared_memory) |
273 return NULL; | 267 return NULL; |
274 | 268 |
275 DCHECK(!shared_memory->memory()); | 269 DCHECK(!shared_memory->memory()); |
276 if (!shared_memory->Map(size)) | 270 if (!shared_memory->Map(size)) |
277 return NULL; | 271 return NULL; |
278 | 272 |
279 // This handle is owned by the GPU process and must be passed to it or it | 273 // This handle is owned by the GPU process and must be passed to it or it |
280 // will leak. In otherwords, do not early out on error between here and the | 274 // will leak. In otherwords, do not early out on error between here and the |
281 // sending of the RegisterTransferBuffer IPC below. | 275 // sending of the RegisterTransferBuffer IPC below. |
282 base::SharedMemoryHandle handle = | 276 base::SharedMemoryHandle handle = |
283 channel_->ShareToGpuProcess(shared_memory->handle()); | 277 channel_->ShareToGpuProcess(shared_memory->handle()); |
284 if (!base::SharedMemory::IsHandleValid(handle)) | 278 if (!base::SharedMemory::IsHandleValid(handle)) |
285 return NULL; | 279 return NULL; |
286 | 280 |
287 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, | 281 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, |
288 new_id, | 282 new_id, |
289 handle, | 283 handle, |
290 size))) { | 284 size))) { |
291 return NULL; | 285 return NULL; |
292 } | 286 } |
293 | 287 |
294 *id = new_id; | 288 *id = new_id; |
295 scoped_refptr<gpu::Buffer> buffer = | 289 scoped_refptr<gpu::Buffer> buffer = |
296 new gpu::Buffer(shared_memory.Pass(), size); | 290 new gpu::Buffer(shared_memory.Pass(), size); |
297 transfer_buffers_[new_id] = buffer; | |
298 return buffer; | 291 return buffer; |
299 } | 292 } |
300 | 293 |
301 void CommandBufferProxyImpl::DestroyTransferBuffer(int32 id) { | 294 void CommandBufferProxyImpl::DestroyTransferBuffer(int32 id) { |
302 if (last_state_.error != gpu::error::kNoError) | 295 if (last_state_.error != gpu::error::kNoError) |
303 return; | 296 return; |
304 | 297 |
305 // Remove the transfer buffer from the client side cache. | |
306 TransferBufferMap::iterator it = transfer_buffers_.find(id); | |
307 if (it != transfer_buffers_.end()) | |
308 transfer_buffers_.erase(it); | |
309 | |
310 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); | 298 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); |
311 } | 299 } |
312 | 300 |
313 scoped_refptr<gpu::Buffer> CommandBufferProxyImpl::GetTransferBuffer(int32 id) { | |
314 if (last_state_.error != gpu::error::kNoError) | |
315 return NULL; | |
316 | |
317 // Check local cache to see if there is already a client side shared memory | |
318 // object for this id. | |
319 TransferBufferMap::iterator it = transfer_buffers_.find(id); | |
320 if (it != transfer_buffers_.end()) { | |
321 return it->second; | |
322 } | |
323 | |
324 // Assuming we are in the renderer process, the service is responsible for | |
325 // duplicating the handle. This might not be true for NaCl. | |
326 base::SharedMemoryHandle handle = base::SharedMemoryHandle(); | |
327 uint32 size; | |
328 if (!Send(new GpuCommandBufferMsg_GetTransferBuffer(route_id_, | |
329 id, | |
330 &handle, | |
331 &size))) { | |
332 return NULL; | |
333 } | |
334 | |
335 // Cache the transfer buffer shared memory object client side. | |
336 scoped_ptr<base::SharedMemory> shared_memory( | |
337 new base::SharedMemory(handle, false)); | |
338 | |
339 // Map the shared memory on demand. | |
340 if (!shared_memory->memory()) { | |
341 if (!shared_memory->Map(size)) | |
342 return NULL; | |
343 } | |
344 | |
345 scoped_refptr<gpu::Buffer> buffer = | |
346 new gpu::Buffer(shared_memory.Pass(), size); | |
347 transfer_buffers_[id] = buffer; | |
348 | |
349 return buffer; | |
350 } | |
351 | |
352 void CommandBufferProxyImpl::SetToken(int32 token) { | |
353 // Not implemented in proxy. | |
354 NOTREACHED(); | |
355 } | |
356 | |
357 void CommandBufferProxyImpl::SetParseError( | |
358 gpu::error::Error error) { | |
359 // Not implemented in proxy. | |
360 NOTREACHED(); | |
361 } | |
362 | |
363 void CommandBufferProxyImpl::SetContextLostReason( | |
364 gpu::error::ContextLostReason reason) { | |
365 // Not implemented in proxy. | |
366 NOTREACHED(); | |
367 } | |
368 | |
369 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 301 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
370 return capabilities_; | 302 return capabilities_; |
371 } | 303 } |
372 | 304 |
373 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( | 305 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( |
374 size_t width, | 306 size_t width, |
375 size_t height, | 307 size_t height, |
376 unsigned internalformat, | 308 unsigned internalformat, |
377 int32* id) { | 309 int32* id) { |
378 *id = -1; | 310 *id = -1; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 const GpuConsoleMessageCallback& callback) { | 518 const GpuConsoleMessageCallback& callback) { |
587 console_message_callback_ = callback; | 519 console_message_callback_ = callback; |
588 } | 520 } |
589 | 521 |
590 void CommandBufferProxyImpl::TryUpdateState() { | 522 void CommandBufferProxyImpl::TryUpdateState() { |
591 if (last_state_.error == gpu::error::kNoError) | 523 if (last_state_.error == gpu::error::kNoError) |
592 shared_state()->Read(&last_state_); | 524 shared_state()->Read(&last_state_); |
593 } | 525 } |
594 | 526 |
595 } // namespace content | 527 } // namespace content |
OLD | NEW |