| 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 // A class to Manage a growing transfer buffer. | 5 // A class to Manage a growing transfer buffer. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/transfer_buffer.h" | 7 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 unsigned int TransferBuffer::GetSize() const { | 91 unsigned int TransferBuffer::GetSize() const { |
| 92 return HaveBuffer() ? ring_buffer_->GetLargestFreeOrPendingSize() : 0; | 92 return HaveBuffer() ? ring_buffer_->GetLargestFreeOrPendingSize() : 0; |
| 93 } | 93 } |
| 94 | 94 |
| 95 unsigned int TransferBuffer::GetFreeSize() const { | 95 unsigned int TransferBuffer::GetFreeSize() const { |
| 96 return HaveBuffer() ? ring_buffer_->GetTotalFreeSizeNoWaiting() : 0; | 96 return HaveBuffer() ? ring_buffer_->GetTotalFreeSizeNoWaiting() : 0; |
| 97 } | 97 } |
| 98 | 98 |
| 99 base::SharedMemory* TransferBuffer::GetSharedMemory() const { |
| 100 if (!HaveBuffer()) |
| 101 return nullptr; |
| 102 return buffer_->backing()->shared_memory(); |
| 103 } |
| 104 |
| 99 void TransferBuffer::AllocateRingBuffer(unsigned int size) { | 105 void TransferBuffer::AllocateRingBuffer(unsigned int size) { |
| 100 for (;size >= min_buffer_size_; size /= 2) { | 106 for (;size >= min_buffer_size_; size /= 2) { |
| 101 int32_t id = -1; | 107 int32_t id = -1; |
| 102 scoped_refptr<gpu::Buffer> buffer = | 108 scoped_refptr<gpu::Buffer> buffer = |
| 103 helper_->command_buffer()->CreateTransferBuffer(size, &id); | 109 helper_->command_buffer()->CreateTransferBuffer(size, &id); |
| 104 if (id != -1) { | 110 if (id != -1) { |
| 105 DCHECK(buffer.get()); | 111 DCHECK(buffer.get()); |
| 106 buffer_ = buffer; | 112 buffer_ = buffer; |
| 107 ring_buffer_.reset(new RingBuffer( | 113 ring_buffer_.reset(new RingBuffer( |
| 108 alignment_, | 114 alignment_, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 Release(); | 221 Release(); |
| 216 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so | 222 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so |
| 217 // that address will return a pointer just like malloc, and so that GetShmId | 223 // that address will return a pointer just like malloc, and so that GetShmId |
| 218 // will be valid. That has the side effect that we'll insert a token on free. | 224 // will be valid. That has the side effect that we'll insert a token on free. |
| 219 // We could add code skip the token for a zero size buffer but it doesn't seem | 225 // We could add code skip the token for a zero size buffer but it doesn't seem |
| 220 // worth the complication. | 226 // worth the complication. |
| 221 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); | 227 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); |
| 222 } | 228 } |
| 223 | 229 |
| 224 } // namespace gpu | 230 } // namespace gpu |
| OLD | NEW |