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

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

Issue 8340003: Make GLES2Implementation use a larger chunk size for mapping functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typos and formatting Created 9 years, 1 month 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 | Annotate | Revision Log
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 <algorithm> 5 #include <algorithm>
6 #include <functional> 6 #include <functional>
7 7
8 #include "../client/mapped_memory.h" 8 #include "../client/mapped_memory.h"
9 #include "../client/cmd_buffer_helper.h" 9 #include "../client/cmd_buffer_helper.h"
10 10
11 namespace gpu { 11 namespace gpu {
12 namespace { 12 namespace {
13 void DeleteMemoryChunk(MemoryChunk* chunk) { 13 void DeleteMemoryChunk(MemoryChunk* chunk) {
14 delete chunk; 14 delete chunk;
15 } 15 }
16 } 16 }
17 17
18 MemoryChunk::MemoryChunk( 18 MemoryChunk::MemoryChunk(
19 int32 shm_id, gpu::Buffer shm, CommandBufferHelper* helper) 19 int32 shm_id, gpu::Buffer shm, CommandBufferHelper* helper)
20 : shm_id_(shm_id), 20 : shm_id_(shm_id),
21 shm_(shm), 21 shm_(shm),
22 allocator_(shm.size, helper, shm.ptr) { 22 allocator_(shm.size, helper, shm.ptr) {
23 } 23 }
24 24
25 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper) 25 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper)
26 : helper_(helper) { 26 : chunk_size_multiple_(1),
27 helper_(helper) {
27 } 28 }
28 29
29 MappedMemoryManager::~MappedMemoryManager() { 30 MappedMemoryManager::~MappedMemoryManager() {
30 std::for_each(chunks_.begin(), 31 std::for_each(chunks_.begin(),
31 chunks_.end(), 32 chunks_.end(),
32 std::pointer_to_unary_function<MemoryChunk*, void>( 33 std::pointer_to_unary_function<MemoryChunk*, void>(
33 DeleteMemoryChunk)); 34 DeleteMemoryChunk));
34 } 35 }
35 36
36 void* MappedMemoryManager::Alloc( 37 void* MappedMemoryManager::Alloc(
37 unsigned int size, int32* shm_id, unsigned int* shm_offset) { 38 unsigned int size, int32* shm_id, unsigned int* shm_offset) {
38 GPU_DCHECK(shm_id); 39 GPU_DCHECK(shm_id);
39 GPU_DCHECK(shm_offset); 40 GPU_DCHECK(shm_offset);
40 // See if any of the chucks can satisfy this request. 41 // See if any of the chucks can satisfy this request.
41 for (size_t ii = 0; ii < chunks_.size(); ++ii) { 42 for (size_t ii = 0; ii < chunks_.size(); ++ii) {
42 MemoryChunk* chunk = chunks_[ii]; 43 MemoryChunk* chunk = chunks_[ii];
43 chunk->FreeUnused(); 44 chunk->FreeUnused();
44 if (chunk->GetLargestFreeSizeWithoutWaiting() >= size) { 45 if (chunk->GetLargestFreeSizeWithoutWaiting() >= size) {
45 void* mem = chunk->Alloc(size); 46 void* mem = chunk->Alloc(size);
46 GPU_DCHECK(mem); 47 GPU_DCHECK(mem);
47 *shm_id = chunk->shm_id(); 48 *shm_id = chunk->shm_id();
48 *shm_offset = chunk->GetOffset(mem); 49 *shm_offset = chunk->GetOffset(mem);
49 return mem; 50 return mem;
50 } 51 }
51 } 52 }
52 53
53 // Make a new chunk to satisfy the request. 54 // Make a new chunk to satisfy the request.
54 CommandBuffer* cmd_buf = helper_->command_buffer(); 55 CommandBuffer* cmd_buf = helper_->command_buffer();
55 int32 id = cmd_buf->CreateTransferBuffer(size, -1); 56 unsigned int chunk_size =
57 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) *
58 chunk_size_multiple_;
59 int32 id = cmd_buf->CreateTransferBuffer(chunk_size, -1);
56 if (id == -1) { 60 if (id == -1) {
57 return NULL; 61 return NULL;
58 } 62 }
59 gpu::Buffer shm = cmd_buf->GetTransferBuffer(id); 63 gpu::Buffer shm = cmd_buf->GetTransferBuffer(id);
60 MemoryChunk* mc = new MemoryChunk(id, shm, helper_); 64 MemoryChunk* mc = new MemoryChunk(id, shm, helper_);
61 chunks_.push_back(mc); 65 chunks_.push_back(mc);
62 void* mem = mc->Alloc(size); 66 void* mem = mc->Alloc(size);
63 GPU_DCHECK(mem); 67 GPU_DCHECK(mem);
64 *shm_id = mc->shm_id(); 68 *shm_id = mc->shm_id();
65 *shm_offset = mc->GetOffset(mem); 69 *shm_offset = mc->GetOffset(mem);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } else { 104 } else {
101 ++iter; 105 ++iter;
102 } 106 }
103 } 107 }
104 } 108 }
105 109
106 } // namespace gpu 110 } // namespace gpu
107 111
108 112
109 113
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