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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unset texture and texture_ref after deleting Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
13 13
14 namespace gpu { 14 namespace gpu {
15 15
16 MemoryChunk::MemoryChunk(int32 shm_id, 16 MemoryChunk::MemoryChunk(int32 shm_id,
17 scoped_refptr<gpu::Buffer> shm, 17 scoped_refptr<gpu::Buffer> shm,
18 CommandBufferHelper* helper) 18 CommandBufferHelper* helper,
19 const base::Closure& poll_callback)
19 : shm_id_(shm_id), 20 : shm_id_(shm_id),
20 shm_(shm), 21 shm_(shm),
21 allocator_(shm->size(), helper, shm->memory()) {} 22 allocator_(shm->size(), helper, poll_callback, shm->memory()) {}
22 23
23 MemoryChunk::~MemoryChunk() {} 24 MemoryChunk::~MemoryChunk() {}
24 25
25 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, 26 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper,
27 const base::Closure& poll_callback,
26 size_t unused_memory_reclaim_limit) 28 size_t unused_memory_reclaim_limit)
27 : chunk_size_multiple_(1), 29 : chunk_size_multiple_(1),
28 helper_(helper), 30 helper_(helper),
31 poll_callback_(poll_callback),
29 allocated_memory_(0), 32 allocated_memory_(0),
30 max_free_bytes_(unused_memory_reclaim_limit) { 33 max_free_bytes_(unused_memory_reclaim_limit) {
31 } 34 }
32 35
33 MappedMemoryManager::~MappedMemoryManager() { 36 MappedMemoryManager::~MappedMemoryManager() {
34 CommandBuffer* cmd_buf = helper_->command_buffer(); 37 CommandBuffer* cmd_buf = helper_->command_buffer();
35 for (MemoryChunkVector::iterator iter = chunks_.begin(); 38 for (MemoryChunkVector::iterator iter = chunks_.begin();
36 iter != chunks_.end(); ++iter) { 39 iter != chunks_.end(); ++iter) {
37 MemoryChunk* chunk = *iter; 40 MemoryChunk* chunk = *iter;
38 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); 41 cmd_buf->DestroyTransferBuffer(chunk->shm_id());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Make a new chunk to satisfy the request. 84 // Make a new chunk to satisfy the request.
82 CommandBuffer* cmd_buf = helper_->command_buffer(); 85 CommandBuffer* cmd_buf = helper_->command_buffer();
83 unsigned int chunk_size = 86 unsigned int chunk_size =
84 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * 87 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) *
85 chunk_size_multiple_; 88 chunk_size_multiple_;
86 int32 id = -1; 89 int32 id = -1;
87 scoped_refptr<gpu::Buffer> shm = 90 scoped_refptr<gpu::Buffer> shm =
88 cmd_buf->CreateTransferBuffer(chunk_size, &id); 91 cmd_buf->CreateTransferBuffer(chunk_size, &id);
89 if (id < 0) 92 if (id < 0)
90 return NULL; 93 return NULL;
91 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); 94 MemoryChunk* mc = new MemoryChunk(id, shm, helper_, poll_callback_);
92 allocated_memory_ += mc->GetSize(); 95 allocated_memory_ += mc->GetSize();
93 chunks_.push_back(mc); 96 chunks_.push_back(mc);
94 void* mem = mc->Alloc(size); 97 void* mem = mc->Alloc(size);
95 DCHECK(mem); 98 DCHECK(mem);
96 *shm_id = mc->shm_id(); 99 *shm_id = mc->shm_id();
97 *shm_offset = mc->GetOffset(mem); 100 *shm_offset = mc->GetOffset(mem);
98 return mem; 101 return mem;
99 } 102 }
100 103
101 void MappedMemoryManager::Free(void* pointer) { 104 void MappedMemoryManager::Free(void* pointer) {
(...skipping 28 matching lines...) Expand all
130 cmd_buf->DestroyTransferBuffer(chunk->shm_id()); 133 cmd_buf->DestroyTransferBuffer(chunk->shm_id());
131 allocated_memory_ -= chunk->GetSize(); 134 allocated_memory_ -= chunk->GetSize();
132 iter = chunks_.erase(iter); 135 iter = chunks_.erase(iter);
133 } else { 136 } else {
134 ++iter; 137 ++iter;
135 } 138 }
136 } 139 }
137 } 140 }
138 141
139 } // namespace gpu 142 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/mapped_memory.h ('k') | gpu/command_buffer/client/mapped_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698