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 scoped_ptr<base::SharedMemory> shared_memory, | 43 scoped_ptr<BufferBacking> buffer_backing) { |
44 size_t size) { | |
45 if (id <= 0) { | 44 if (id <= 0) { |
46 DVLOG(0) << "Cannot register transfer buffer with non-positive ID."; | 45 DVLOG(0) << "Cannot register transfer buffer with non-positive ID."; |
47 return false; | 46 return false; |
48 } | 47 } |
49 | 48 |
50 // Fail if the ID is in use. | 49 // Fail if the ID is in use. |
51 if (registered_buffers_.find(id) != registered_buffers_.end()) { | 50 if (registered_buffers_.find(id) != registered_buffers_.end()) { |
52 DVLOG(0) << "Buffer ID already in use."; | 51 DVLOG(0) << "Buffer ID already in use."; |
53 return false; | 52 return false; |
54 } | 53 } |
55 | 54 |
56 // Register the shared memory with the ID. | 55 // Register the shared memory with the ID. |
57 scoped_refptr<Buffer> buffer = new gpu::Buffer(shared_memory.Pass(), size); | 56 scoped_refptr<Buffer> buffer(new gpu::Buffer(buffer_backing.Pass())); |
58 | 57 |
59 // Check buffer alignment is sane. | 58 // Check buffer alignment is sane. |
60 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & | 59 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & |
61 (kCommandBufferEntrySize - 1))); | 60 (kCommandBufferEntrySize - 1))); |
62 | 61 |
63 shared_memory_bytes_allocated_ += size; | 62 shared_memory_bytes_allocated_ += buffer->size(); |
64 TRACE_COUNTER_ID1( | 63 TRACE_COUNTER_ID1( |
65 "gpu", "GpuTransferBufferMemory", this, shared_memory_bytes_allocated_); | 64 "gpu", "GpuTransferBufferMemory", this, shared_memory_bytes_allocated_); |
66 | 65 |
67 registered_buffers_[id] = buffer; | 66 registered_buffers_[id] = buffer; |
68 | 67 |
69 return true; | 68 return true; |
70 } | 69 } |
71 | 70 |
72 void TransferBufferManager::DestroyTransferBuffer(int32 id) { | 71 void TransferBufferManager::DestroyTransferBuffer(int32 id) { |
73 BufferMap::iterator it = registered_buffers_.find(id); | 72 BufferMap::iterator it = registered_buffers_.find(id); |
(...skipping 16 matching lines...) Expand all Loading... |
90 | 89 |
91 BufferMap::iterator it = registered_buffers_.find(id); | 90 BufferMap::iterator it = registered_buffers_.find(id); |
92 if (it == registered_buffers_.end()) | 91 if (it == registered_buffers_.end()) |
93 return NULL; | 92 return NULL; |
94 | 93 |
95 return it->second; | 94 return it->second; |
96 } | 95 } |
97 | 96 |
98 } // namespace gpu | 97 } // namespace gpu |
99 | 98 |
OLD | NEW |