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

Side by Side Diff: gpu/command_buffer/service/transfer_buffer_manager.cc

Issue 1542513002: Switch to standard integer types in gpu/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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) 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 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 5 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
6 6
7 #include <stdint.h>
8
7 #include <limits> 9 #include <limits>
8 10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
12 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
14 #include "base/trace_event/memory_allocator_dump.h" 16 #include "base/trace_event/memory_allocator_dump.h"
15 #include "base/trace_event/memory_dump_manager.h" 17 #include "base/trace_event/memory_dump_manager.h"
16 #include "base/trace_event/process_memory_dump.h" 18 #include "base/trace_event/process_memory_dump.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // so don't register a dump provider. 50 // so don't register a dump provider.
49 if (memory_tracker_) { 51 if (memory_tracker_) {
50 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 52 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
51 this, "gpu::TransferBufferManager", 53 this, "gpu::TransferBufferManager",
52 base::ThreadTaskRunnerHandle::Get()); 54 base::ThreadTaskRunnerHandle::Get());
53 } 55 }
54 return true; 56 return true;
55 } 57 }
56 58
57 bool TransferBufferManager::RegisterTransferBuffer( 59 bool TransferBufferManager::RegisterTransferBuffer(
58 int32 id, 60 int32_t id,
59 scoped_ptr<BufferBacking> buffer_backing) { 61 scoped_ptr<BufferBacking> buffer_backing) {
60 if (id <= 0) { 62 if (id <= 0) {
61 DVLOG(0) << "Cannot register transfer buffer with non-positive ID."; 63 DVLOG(0) << "Cannot register transfer buffer with non-positive ID.";
62 return false; 64 return false;
63 } 65 }
64 66
65 // Fail if the ID is in use. 67 // Fail if the ID is in use.
66 if (registered_buffers_.find(id) != registered_buffers_.end()) { 68 if (registered_buffers_.find(id) != registered_buffers_.end()) {
67 DVLOG(0) << "Buffer ID already in use."; 69 DVLOG(0) << "Buffer ID already in use.";
68 return false; 70 return false;
69 } 71 }
70 72
71 // Register the shared memory with the ID. 73 // Register the shared memory with the ID.
72 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing))); 74 scoped_refptr<Buffer> buffer(new gpu::Buffer(std::move(buffer_backing)));
73 75
74 // Check buffer alignment is sane. 76 // Check buffer alignment is sane.
75 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) & 77 DCHECK(!(reinterpret_cast<uintptr_t>(buffer->memory()) &
76 (kCommandBufferEntrySize - 1))); 78 (kCommandBufferEntrySize - 1)));
77 79
78 shared_memory_bytes_allocated_ += buffer->size(); 80 shared_memory_bytes_allocated_ += buffer->size();
79 81
80 registered_buffers_[id] = buffer; 82 registered_buffers_[id] = buffer;
81 83
82 return true; 84 return true;
83 } 85 }
84 86
85 void TransferBufferManager::DestroyTransferBuffer(int32 id) { 87 void TransferBufferManager::DestroyTransferBuffer(int32_t id) {
86 BufferMap::iterator it = registered_buffers_.find(id); 88 BufferMap::iterator it = registered_buffers_.find(id);
87 if (it == registered_buffers_.end()) { 89 if (it == registered_buffers_.end()) {
88 DVLOG(0) << "Transfer buffer ID was not registered."; 90 DVLOG(0) << "Transfer buffer ID was not registered.";
89 return; 91 return;
90 } 92 }
91 93
92 DCHECK(shared_memory_bytes_allocated_ >= it->second->size()); 94 DCHECK(shared_memory_bytes_allocated_ >= it->second->size());
93 shared_memory_bytes_allocated_ -= it->second->size(); 95 shared_memory_bytes_allocated_ -= it->second->size();
94 96
95 registered_buffers_.erase(it); 97 registered_buffers_.erase(it);
96 } 98 }
97 99
98 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32 id) { 100 scoped_refptr<Buffer> TransferBufferManager::GetTransferBuffer(int32_t id) {
99 if (id == 0) 101 if (id == 0)
100 return NULL; 102 return NULL;
101 103
102 BufferMap::iterator it = registered_buffers_.find(id); 104 BufferMap::iterator it = registered_buffers_.find(id);
103 if (it == registered_buffers_.end()) 105 if (it == registered_buffers_.end())
104 return NULL; 106 return NULL;
105 107
106 return it->second; 108 return it->second;
107 } 109 }
108 110
109 bool TransferBufferManager::OnMemoryDump( 111 bool TransferBufferManager::OnMemoryDump(
110 const base::trace_event::MemoryDumpArgs& args, 112 const base::trace_event::MemoryDumpArgs& args,
111 base::trace_event::ProcessMemoryDump* pmd) { 113 base::trace_event::ProcessMemoryDump* pmd) {
112 for (const auto& buffer_entry : registered_buffers_) { 114 for (const auto& buffer_entry : registered_buffers_) {
113 int32 buffer_id = buffer_entry.first; 115 int32_t buffer_id = buffer_entry.first;
114 const Buffer* buffer = buffer_entry.second.get(); 116 const Buffer* buffer = buffer_entry.second.get();
115 std::string dump_name = 117 std::string dump_name =
116 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d", 118 base::StringPrintf("gpu/transfer_memory/client_%d/buffer_%d",
117 memory_tracker_->ClientId(), buffer_id); 119 memory_tracker_->ClientId(), buffer_id);
118 base::trace_event::MemoryAllocatorDump* dump = 120 base::trace_event::MemoryAllocatorDump* dump =
119 pmd->CreateAllocatorDump(dump_name); 121 pmd->CreateAllocatorDump(dump_name);
120 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 122 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
121 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 123 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
122 buffer->size()); 124 buffer->size());
123 auto guid = 125 auto guid =
124 GetBufferGUIDForTracing(memory_tracker_->ClientTracingId(), buffer_id); 126 GetBufferGUIDForTracing(memory_tracker_->ClientTracingId(), buffer_id);
125 pmd->CreateSharedGlobalAllocatorDump(guid); 127 pmd->CreateSharedGlobalAllocatorDump(guid);
126 pmd->AddOwnershipEdge(dump->guid(), guid); 128 pmd->AddOwnershipEdge(dump->guid(), guid);
127 } 129 }
128 130
129 return true; 131 return true;
130 } 132 }
131 133
132 } // namespace gpu 134 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/transfer_buffer_manager.h ('k') | gpu/command_buffer/service/transfer_buffer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698