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

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

Issue 1900993002: Move SharedMemoryLimits out of WebGraphicsContext3DCommandBufferImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@limits
Patch Set: move-limits: rebase Created 4 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <functional> 11 #include <functional>
12 12
13 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/trace_event/memory_dump_manager.h" 17 #include "base/trace_event/memory_dump_manager.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 19 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
20 #include "gpu/command_buffer/client/shared_memory_limits.h"
20 #include "gpu/command_buffer/common/buffer.h" 21 #include "gpu/command_buffer/common/buffer.h"
21 22
22 namespace gpu { 23 namespace gpu {
23 namespace { 24 namespace {
24 25
25 // Generates process-unique IDs to use for tracing a MappedMemoryManager's 26 // Generates process-unique IDs to use for tracing a MappedMemoryManager's
26 // chunks. 27 // chunks.
27 base::StaticAtomicSequenceNumber g_next_mapped_memory_manager_tracing_id; 28 base::StaticAtomicSequenceNumber g_next_mapped_memory_manager_tracing_id;
28 29
29 } // namespace 30 } // namespace
30 31
31 MemoryChunk::MemoryChunk(int32_t shm_id, 32 MemoryChunk::MemoryChunk(int32_t shm_id,
32 scoped_refptr<gpu::Buffer> shm, 33 scoped_refptr<gpu::Buffer> shm,
33 CommandBufferHelper* helper) 34 CommandBufferHelper* helper)
34 : shm_id_(shm_id), 35 : shm_id_(shm_id),
35 shm_(shm), 36 shm_(shm),
36 allocator_(shm->size(), helper, shm->memory()) {} 37 allocator_(shm->size(), helper, shm->memory()) {}
37 38
38 MemoryChunk::~MemoryChunk() {} 39 MemoryChunk::~MemoryChunk() {}
39 40
40 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, 41 MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper,
41 size_t unused_memory_reclaim_limit) 42 size_t unused_memory_reclaim_limit)
42 : chunk_size_multiple_(FencedAllocator::kAllocAlignment), 43 : chunk_size_multiple_(FencedAllocator::kAllocAlignment),
43 helper_(helper), 44 helper_(helper),
44 allocated_memory_(0), 45 allocated_memory_(0),
45 max_free_bytes_(unused_memory_reclaim_limit), 46 max_free_bytes_(unused_memory_reclaim_limit),
46 max_allocated_bytes_(kNoLimit), 47 max_allocated_bytes_(SharedMemoryLimits::kNoLimit),
47 tracing_id_(g_next_mapped_memory_manager_tracing_id.GetNext()) { 48 tracing_id_(g_next_mapped_memory_manager_tracing_id.GetNext()) {
48 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 49 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
49 // Don't register a dump provider in these cases. 50 // Don't register a dump provider in these cases.
50 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 51 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
51 if (base::ThreadTaskRunnerHandle::IsSet()) { 52 if (base::ThreadTaskRunnerHandle::IsSet()) {
52 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 53 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
53 this, "gpu::MappedMemoryManager", base::ThreadTaskRunnerHandle::Get()); 54 this, "gpu::MappedMemoryManager", base::ThreadTaskRunnerHandle::Get());
54 } 55 }
55 } 56 }
56 57
(...skipping 23 matching lines...) Expand all
80 DCHECK(mem); 81 DCHECK(mem);
81 *shm_id = chunk->shm_id(); 82 *shm_id = chunk->shm_id();
82 *shm_offset = chunk->GetOffset(mem); 83 *shm_offset = chunk->GetOffset(mem);
83 return mem; 84 return mem;
84 } 85 }
85 } 86 }
86 87
87 // If there is a memory limit being enforced and total free 88 // If there is a memory limit being enforced and total free
88 // memory (allocated_memory_ - total_bytes_in_use) is larger than 89 // memory (allocated_memory_ - total_bytes_in_use) is larger than
89 // the limit try waiting. 90 // the limit try waiting.
90 if (max_free_bytes_ != kNoLimit && 91 if (max_free_bytes_ != SharedMemoryLimits::kNoLimit &&
91 (allocated_memory_ - total_bytes_in_use) >= max_free_bytes_) { 92 (allocated_memory_ - total_bytes_in_use) >= max_free_bytes_) {
92 TRACE_EVENT0("gpu", "MappedMemoryManager::Alloc::wait"); 93 TRACE_EVENT0("gpu", "MappedMemoryManager::Alloc::wait");
93 for (auto& chunk : chunks_) { 94 for (auto& chunk : chunks_) {
94 if (chunk->GetLargestFreeSizeWithWaiting() >= size) { 95 if (chunk->GetLargestFreeSizeWithWaiting() >= size) {
95 void* mem = chunk->Alloc(size); 96 void* mem = chunk->Alloc(size);
96 DCHECK(mem); 97 DCHECK(mem);
97 *shm_id = chunk->shm_id(); 98 *shm_id = chunk->shm_id();
98 *shm_offset = chunk->GetOffset(mem); 99 *shm_offset = chunk->GetOffset(mem);
99 return mem; 100 return mem;
100 } 101 }
101 } 102 }
102 } 103 }
103 } 104 }
104 105
105 if (max_allocated_bytes_ != kNoLimit && 106 if (max_allocated_bytes_ != SharedMemoryLimits::kNoLimit &&
106 (allocated_memory_ + size) > max_allocated_bytes_) { 107 (allocated_memory_ + size) > max_allocated_bytes_) {
107 return nullptr; 108 return nullptr;
108 } 109 }
109 110
110 // Make a new chunk to satisfy the request. 111 // Make a new chunk to satisfy the request.
111 CommandBuffer* cmd_buf = helper_->command_buffer(); 112 CommandBuffer* cmd_buf = helper_->command_buffer();
112 unsigned int chunk_size = 113 unsigned int chunk_size =
113 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) * 114 ((size + chunk_size_multiple_ - 1) / chunk_size_multiple_) *
114 chunk_size_multiple_; 115 chunk_size_multiple_;
115 int32_t id = -1; 116 int32_t id = -1;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { 211 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) {
211 Release(); 212 Release();
212 213
213 if (new_size) { 214 if (new_size) {
214 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); 215 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_);
215 size_ = buffer_ ? new_size : 0; 216 size_ = buffer_ ? new_size : 0;
216 } 217 }
217 } 218 }
218 219
219 } // namespace gpu 220 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698