| 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 "gpu/command_buffer/service/transfer_buffer_manager.h" | 5 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 DCHECK(!shared_memory_bytes_allocated_); | 34 DCHECK(!shared_memory_bytes_allocated_); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool TransferBufferManager::Initialize() { | 37 bool TransferBufferManager::Initialize() { |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool TransferBufferManager::RegisterTransferBuffer( | 41 bool TransferBufferManager::RegisterTransferBuffer( |
| 42 int32 id, | 42 int32 id, |
| 43 base::SharedMemory* shared_memory, | 43 scoped_ptr<base::SharedMemory> shared_memory, |
| 44 size_t size) { | 44 size_t size) { |
| 45 if (id <= 0) { | 45 if (id <= 0) { |
| 46 DVLOG(0) << "Cannot register transfer buffer with non-positive ID."; | 46 DVLOG(0) << "Cannot register transfer buffer with non-positive ID."; |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Fail if the ID is in use. | 50 // Fail if the ID is in use. |
| 51 if (registered_buffers_.find(id) != registered_buffers_.end()) { | 51 if (registered_buffers_.find(id) != registered_buffers_.end()) { |
| 52 DVLOG(0) << "Buffer ID already in use."; | 52 DVLOG(0) << "Buffer ID already in use."; |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Duplicate the handle. | 56 // Register the shared memory with the ID. |
| 57 base::SharedMemoryHandle duped_shared_memory_handle; | 57 scoped_refptr<Buffer> buffer = new gpu::Buffer(shared_memory.Pass(), size); |
| 58 if (!shared_memory->ShareToProcess(base::GetCurrentProcessHandle(), | |
| 59 &duped_shared_memory_handle)) { | |
| 60 DVLOG(0) << "Failed to duplicate shared memory handle."; | |
| 61 return false; | |
| 62 } | |
| 63 scoped_ptr<SharedMemory> duped_shared_memory( | |
| 64 new SharedMemory(duped_shared_memory_handle, false)); | |
| 65 | |
| 66 // Map the shared memory into this process. This validates the size. | |
| 67 if (!duped_shared_memory->Map(size)) { | |
| 68 DVLOG(0) << "Failed to map shared memory."; | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 // If it could be mapped register the shared memory with the ID. | |
| 73 scoped_refptr<Buffer> buffer = | |
| 74 make_scoped_refptr(new gpu::Buffer(duped_shared_memory.Pass(), size)); | |
| 75 | 58 |
| 76 // Check buffer alignment is sane. | 59 // Check buffer alignment is sane. |
| 77 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & | 60 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & |
| 78 (kCommandBufferEntrySize - 1))); | 61 (kCommandBufferEntrySize - 1))); |
| 79 | 62 |
| 80 shared_memory_bytes_allocated_ += size; | 63 shared_memory_bytes_allocated_ += size; |
| 81 TRACE_COUNTER_ID1( | 64 TRACE_COUNTER_ID1( |
| 82 "gpu", "GpuTransferBufferMemory", this, shared_memory_bytes_allocated_); | 65 "gpu", "GpuTransferBufferMemory", this, shared_memory_bytes_allocated_); |
| 83 | 66 |
| 84 registered_buffers_[id] = buffer; | 67 registered_buffers_[id] = buffer; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 | 90 |
| 108 BufferMap::iterator it = registered_buffers_.find(id); | 91 BufferMap::iterator it = registered_buffers_.find(id); |
| 109 if (it == registered_buffers_.end()) | 92 if (it == registered_buffers_.end()) |
| 110 return NULL; | 93 return NULL; |
| 111 | 94 |
| 112 return it->second; | 95 return it->second; |
| 113 } | 96 } |
| 114 | 97 |
| 115 } // namespace gpu | 98 } // namespace gpu |
| 116 | 99 |
| OLD | NEW |