Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: gpu/command_buffer/client/transfer_buffer.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/client/transfer_buffer.h ('k') | gpu/command_buffer/common/buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (!buffer_->backing())
103 return nullptr;
104 return buffer_->backing()->shared_memory();
105 }
106
99 void TransferBuffer::AllocateRingBuffer(unsigned int size) { 107 void TransferBuffer::AllocateRingBuffer(unsigned int size) {
100 for (;size >= min_buffer_size_; size /= 2) { 108 for (;size >= min_buffer_size_; size /= 2) {
101 int32_t id = -1; 109 int32_t id = -1;
102 scoped_refptr<gpu::Buffer> buffer = 110 scoped_refptr<gpu::Buffer> buffer =
103 helper_->command_buffer()->CreateTransferBuffer(size, &id); 111 helper_->command_buffer()->CreateTransferBuffer(size, &id);
104 if (id != -1) { 112 if (id != -1) {
105 DCHECK(buffer.get()); 113 DCHECK(buffer.get());
106 buffer_ = buffer; 114 buffer_ = buffer;
107 ring_buffer_.reset(new RingBuffer( 115 ring_buffer_.reset(new RingBuffer(
108 alignment_, 116 alignment_,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 Release(); 223 Release();
216 // 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
217 // 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
218 // 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.
219 // 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
220 // worth the complication. 228 // worth the complication.
221 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_); 229 buffer_ = transfer_buffer_->AllocUpTo(new_size, &size_);
222 } 230 }
223 231
224 } // namespace gpu 232 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/transfer_buffer.h ('k') | gpu/command_buffer/common/buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698