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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 buffer_id_ = -1; | 60 buffer_id_ = -1; |
61 buffer_ = NULL; | 61 buffer_ = NULL; |
62 result_buffer_ = NULL; | 62 result_buffer_ = NULL; |
63 result_shm_offset_ = 0; | 63 result_shm_offset_ = 0; |
64 ring_buffer_.reset(); | 64 ring_buffer_.reset(); |
65 bytes_since_last_flush_ = 0; | 65 bytes_since_last_flush_ = 0; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 bool TransferBuffer::HaveBuffer() const { | 69 bool TransferBuffer::HaveBuffer() const { |
| 70 DCHECK(buffer_id_ == -1 || buffer_); |
70 return buffer_id_ != -1; | 71 return buffer_id_ != -1; |
71 } | 72 } |
72 | 73 |
73 RingBuffer::Offset TransferBuffer::GetOffset(void* pointer) const { | 74 RingBuffer::Offset TransferBuffer::GetOffset(void* pointer) const { |
74 return ring_buffer_->GetOffset(pointer); | 75 return ring_buffer_->GetOffset(pointer); |
75 } | 76 } |
76 | 77 |
77 void TransferBuffer::FreePendingToken(void* p, unsigned int token) { | 78 void TransferBuffer::FreePendingToken(void* p, unsigned int token) { |
78 ring_buffer_->FreePendingToken(p, token); | 79 ring_buffer_->FreePendingToken(p, token); |
79 if (bytes_since_last_flush_ >= size_to_flush_ && size_to_flush_ > 0) { | 80 if (bytes_since_last_flush_ >= size_to_flush_ && size_to_flush_ > 0) { |
80 helper_->Flush(); | 81 helper_->Flush(); |
81 bytes_since_last_flush_ = 0; | 82 bytes_since_last_flush_ = 0; |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 void TransferBuffer::AllocateRingBuffer(unsigned int size) { | 86 void TransferBuffer::AllocateRingBuffer(unsigned int size) { |
86 for (;size >= min_buffer_size_; size /= 2) { | 87 for (;size >= min_buffer_size_; size /= 2) { |
87 int32 id = -1; | 88 int32 id = -1; |
88 scoped_refptr<gpu::Buffer> buffer = | 89 scoped_refptr<gpu::Buffer> buffer = |
89 helper_->command_buffer()->CreateTransferBuffer(size, &id); | 90 helper_->command_buffer()->CreateTransferBuffer(size, &id); |
90 if (id != -1) { | 91 if (id != -1) { |
| 92 DCHECK(buffer); |
91 buffer_ = buffer; | 93 buffer_ = buffer; |
92 ring_buffer_.reset(new AlignedRingBuffer( | 94 ring_buffer_.reset(new AlignedRingBuffer( |
93 alignment_, | 95 alignment_, |
94 id, | 96 id, |
95 result_size_, | 97 result_size_, |
96 buffer_->size() - result_size_, | 98 buffer_->size() - result_size_, |
97 helper_, | 99 helper_, |
98 static_cast<char*>(buffer_->memory()) + result_size_)); | 100 static_cast<char*>(buffer_->memory()) + result_size_)); |
99 buffer_id_ = id; | 101 buffer_id_ = id; |
100 result_buffer_ = buffer_->memory(); | 102 result_buffer_ = buffer_->memory(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Release(); | 223 Release(); |
222 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so | 224 // NOTE: we allocate buffers of size 0 so that HaveBuffer will be true, so |
223 // that address will return a pointer just like malloc, and so that GetShmId | 225 // that address will return a pointer just like malloc, and so that GetShmId |
224 // will be valid. That has the side effect that we'll insert a token on free. | 226 // will be valid. That has the side effect that we'll insert a token on free. |
225 // We could add code skip the token for a zero size buffer but it doesn't seem | 227 // We could add code skip the token for a zero size buffer but it doesn't seem |
226 // worth the complication. | 228 // worth the complication. |
227 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); | 229 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); |
228 } | 230 } |
229 | 231 |
230 } // namespace gpu | 232 } // namespace gpu |
OLD | NEW |