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

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

Issue 213353005: Refactor gpu::Buffer to allow different types of backing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix pointer alignment in tests Created 6 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 | Annotate | Revision Log
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/command_buffer_service.h" 5 #include "gpu/command_buffer/service/command_buffer_service.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 num_entries_ = size / sizeof(CommandBufferEntry); 96 num_entries_ = size / sizeof(CommandBufferEntry);
97 put_offset_ = 0; 97 put_offset_ = 0;
98 SetGetOffset(0); 98 SetGetOffset(0);
99 if (!get_buffer_change_callback_.is_null()) { 99 if (!get_buffer_change_callback_.is_null()) {
100 get_buffer_change_callback_.Run(ring_buffer_id_); 100 get_buffer_change_callback_.Run(ring_buffer_id_);
101 } 101 }
102 102
103 UpdateState(); 103 UpdateState();
104 } 104 }
105 105
106 bool CommandBufferService::SetSharedStateBuffer( 106 void CommandBufferService::SetSharedStateBuffer(
107 scoped_ptr<base::SharedMemory> shared_state_shm) { 107 scoped_ptr<BufferBacking> shared_state_buffer) {
108 shared_state_shm_.reset(shared_state_shm.release()); 108 shared_state_buffer_ = shared_state_buffer.Pass();
109 if (!shared_state_shm_->Map(sizeof(*shared_state_))) 109 DCHECK(shared_state_buffer_->GetSize() >= sizeof(*shared_state_));
110 return false;
111 110
112 shared_state_ = 111 shared_state_ =
113 static_cast<CommandBufferSharedState*>(shared_state_shm_->memory()); 112 static_cast<CommandBufferSharedState*>(shared_state_buffer_->GetMemory());
114 113
115 UpdateState(); 114 UpdateState();
116 return true;
117 } 115 }
118 116
119 void CommandBufferService::SetGetOffset(int32 get_offset) { 117 void CommandBufferService::SetGetOffset(int32 get_offset) {
120 DCHECK(get_offset >= 0 && get_offset < num_entries_); 118 DCHECK(get_offset >= 0 && get_offset < num_entries_);
121 get_offset_ = get_offset; 119 get_offset_ = get_offset;
122 } 120 }
123 121
124 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size, 122 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size,
125 int32* id) { 123 int32* id) {
126 *id = -1; 124 *id = -1;
127 125
128 scoped_ptr<SharedMemory> shared_memory(new SharedMemory()); 126 scoped_ptr<SharedMemory> shared_memory(new SharedMemory());
129 if (!shared_memory->CreateAndMapAnonymous(size)) 127 if (!shared_memory->CreateAndMapAnonymous(size))
130 return NULL; 128 return NULL;
131 129
132 static int32 next_id = 1; 130 static int32 next_id = 1;
133 *id = next_id++; 131 *id = next_id++;
134 132
135 if (!RegisterTransferBuffer(*id, shared_memory.Pass(), size)) { 133 if (!RegisterTransferBuffer(
134 *id, MakeBackingFromSharedMemory(shared_memory.Pass(), size))) {
136 *id = -1; 135 *id = -1;
137 return NULL; 136 return NULL;
138 } 137 }
139 138
140 return GetTransferBuffer(*id); 139 return GetTransferBuffer(*id);
141 } 140 }
142 141
143 void CommandBufferService::DestroyTransferBuffer(int32 id) { 142 void CommandBufferService::DestroyTransferBuffer(int32 id) {
144 transfer_buffer_manager_->DestroyTransferBuffer(id); 143 transfer_buffer_manager_->DestroyTransferBuffer(id);
145 if (id == ring_buffer_id_) { 144 if (id == ring_buffer_id_) {
146 ring_buffer_id_ = -1; 145 ring_buffer_id_ = -1;
147 ring_buffer_ = NULL; 146 ring_buffer_ = NULL;
148 num_entries_ = 0; 147 num_entries_ = 0;
149 get_offset_ = 0; 148 get_offset_ = 0;
150 put_offset_ = 0; 149 put_offset_ = 0;
151 } 150 }
152 } 151 }
153 152
154 scoped_refptr<Buffer> CommandBufferService::GetTransferBuffer(int32 id) { 153 scoped_refptr<Buffer> CommandBufferService::GetTransferBuffer(int32 id) {
155 return transfer_buffer_manager_->GetTransferBuffer(id); 154 return transfer_buffer_manager_->GetTransferBuffer(id);
156 } 155 }
157 156
158 bool CommandBufferService::RegisterTransferBuffer( 157 bool CommandBufferService::RegisterTransferBuffer(
159 int32 id, 158 int32 id,
160 scoped_ptr<base::SharedMemory> shared_memory, 159 scoped_ptr<BufferBacking> buffer) {
161 size_t size) { 160 return transfer_buffer_manager_->RegisterTransferBuffer(id, buffer.Pass());
162 return transfer_buffer_manager_->RegisterTransferBuffer(
163 id, shared_memory.Pass(), size);
164 } 161 }
165 162
166 void CommandBufferService::SetToken(int32 token) { 163 void CommandBufferService::SetToken(int32 token) {
167 token_ = token; 164 token_ = token;
168 UpdateState(); 165 UpdateState();
169 } 166 }
170 167
171 void CommandBufferService::SetParseError(error::Error error) { 168 void CommandBufferService::SetParseError(error::Error error) {
172 if (error_ == error::kNoError) { 169 if (error_ == error::kNoError) {
173 error_ = error; 170 error_ = error;
(...skipping 16 matching lines...) Expand all
190 const GetBufferChangedCallback& callback) { 187 const GetBufferChangedCallback& callback) {
191 get_buffer_change_callback_ = callback; 188 get_buffer_change_callback_ = callback;
192 } 189 }
193 190
194 void CommandBufferService::SetParseErrorCallback( 191 void CommandBufferService::SetParseErrorCallback(
195 const base::Closure& callback) { 192 const base::Closure& callback) {
196 parse_error_callback_ = callback; 193 parse_error_callback_ = callback;
197 } 194 }
198 195
199 } // namespace gpu 196 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/command_buffer_service.h ('k') | gpu/command_buffer/service/common_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698