| 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 "base/bits.h" | 9 #include "base/bits.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 bool TransferBuffer::HaveBuffer() const { | 67 bool TransferBuffer::HaveBuffer() const { |
| 68 DCHECK(buffer_id_ == -1 || buffer_.get()); | 68 DCHECK(buffer_id_ == -1 || buffer_.get()); |
| 69 return buffer_id_ != -1; | 69 return buffer_id_ != -1; |
| 70 } | 70 } |
| 71 | 71 |
| 72 RingBuffer::Offset TransferBuffer::GetOffset(void* pointer) const { | 72 RingBuffer::Offset TransferBuffer::GetOffset(void* pointer) const { |
| 73 return ring_buffer_->GetOffset(pointer); | 73 return ring_buffer_->GetOffset(pointer); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void TransferBuffer::DiscardBlock(void* p) { |
| 77 ring_buffer_->DiscardBlock(p); |
| 78 } |
| 79 |
| 76 void TransferBuffer::FreePendingToken(void* p, unsigned int token) { | 80 void TransferBuffer::FreePendingToken(void* p, unsigned int token) { |
| 77 ring_buffer_->FreePendingToken(p, token); | 81 ring_buffer_->FreePendingToken(p, token); |
| 78 if (bytes_since_last_flush_ >= size_to_flush_ && size_to_flush_ > 0) { | 82 if (bytes_since_last_flush_ >= size_to_flush_ && size_to_flush_ > 0) { |
| 79 helper_->Flush(); | 83 helper_->Flush(); |
| 80 bytes_since_last_flush_ = 0; | 84 bytes_since_last_flush_ = 0; |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 | 87 |
| 84 void TransferBuffer::AllocateRingBuffer(unsigned int size) { | 88 void TransferBuffer::AllocateRingBuffer(unsigned int size) { |
| 85 for (;size >= min_buffer_size_; size /= 2) { | 89 for (;size >= min_buffer_size_; size /= 2) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 185 } |
| 182 | 186 |
| 183 void ScopedTransferBufferPtr::Release() { | 187 void ScopedTransferBufferPtr::Release() { |
| 184 if (buffer_) { | 188 if (buffer_) { |
| 185 transfer_buffer_->FreePendingToken(buffer_, helper_->InsertToken()); | 189 transfer_buffer_->FreePendingToken(buffer_, helper_->InsertToken()); |
| 186 buffer_ = NULL; | 190 buffer_ = NULL; |
| 187 size_ = 0; | 191 size_ = 0; |
| 188 } | 192 } |
| 189 } | 193 } |
| 190 | 194 |
| 195 void ScopedTransferBufferPtr::Discard() { |
| 196 if (buffer_) { |
| 197 transfer_buffer_->DiscardBlock(buffer_); |
| 198 buffer_ = NULL; |
| 199 size_ = 0; |
| 200 } |
| 201 } |
| 202 |
| 191 void ScopedTransferBufferPtr::Reset(unsigned int new_size) { | 203 void ScopedTransferBufferPtr::Reset(unsigned int new_size) { |
| 192 Release(); | 204 Release(); |
| 193 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so | 205 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so |
| 194 // that address will return a pointer just like malloc, and so that GetShmId | 206 // that address will return a pointer just like malloc, and so that GetShmId |
| 195 // will be valid. That has the side effect that we'll insert a token on free. | 207 // will be valid. That has the side effect that we'll insert a token on free. |
| 196 // We could add code skip the token for a zero size buffer but it doesn't seem | 208 // We could add code skip the token for a zero size buffer but it doesn't seem |
| 197 // worth the complication. | 209 // worth the complication. |
| 198 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); | 210 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); |
| 199 } | 211 } |
| 200 | 212 |
| 201 } // namespace gpu | 213 } // namespace gpu |
| OLD | NEW |