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

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

Issue 2550583002: gpu: Thread-safe command buffer state lookup. (Closed)
Patch Set: jbauman's review Created 4 years 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/command_buffer_service.h" 5 #include "gpu/command_buffer/service/command_buffer_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 24 matching lines...) Expand all
35 std::unique_ptr<char[]> memory_; 35 std::unique_ptr<char[]> memory_;
36 size_t size_; 36 size_t size_;
37 DISALLOW_COPY_AND_ASSIGN(MemoryBufferBacking); 37 DISALLOW_COPY_AND_ASSIGN(MemoryBufferBacking);
38 }; 38 };
39 39
40 } // anonymous namespace 40 } // anonymous namespace
41 41
42 CommandBufferService::CommandBufferService( 42 CommandBufferService::CommandBufferService(
43 TransferBufferManagerInterface* transfer_buffer_manager) 43 TransferBufferManagerInterface* transfer_buffer_manager)
44 : ring_buffer_id_(-1), 44 : ring_buffer_id_(-1),
45 shared_state_(NULL), 45 shared_state_(nullptr),
46 num_entries_(0), 46 num_entries_(0),
47 get_offset_(0), 47 get_offset_(0),
48 put_offset_(0), 48 put_offset_(0),
49 transfer_buffer_manager_(transfer_buffer_manager), 49 transfer_buffer_manager_(transfer_buffer_manager),
50 token_(0), 50 token_(0),
51 release_count_(0),
51 generation_(0), 52 generation_(0),
52 error_(error::kNoError), 53 error_(error::kNoError),
53 context_lost_reason_(error::kUnknown) { 54 context_lost_reason_(error::kUnknown) {}
54 }
55 55
56 CommandBufferService::~CommandBufferService() { 56 CommandBufferService::~CommandBufferService() {}
57 }
58 57
59 CommandBufferService::State CommandBufferService::GetLastState() { 58 CommandBufferService::State CommandBufferService::GetLastState() {
60 State state; 59 State state;
61 state.get_offset = get_offset_; 60 state.get_offset = get_offset_;
62 state.token = token_; 61 state.token = token_;
62 state.release_count = release_count_;
63 state.error = error_; 63 state.error = error_;
64 state.context_lost_reason = context_lost_reason_; 64 state.context_lost_reason = context_lost_reason_;
65 state.generation = ++generation_; 65 state.generation = ++generation_;
66 66
67 return state; 67 return state;
68 } 68 }
69 69
70 int32_t CommandBufferService::GetLastToken() {
71 return GetLastState().token;
72 }
73
74 void CommandBufferService::UpdateState() { 70 void CommandBufferService::UpdateState() {
75 if (shared_state_) { 71 if (shared_state_) {
76 CommandBufferService::State state = GetLastState(); 72 CommandBufferService::State state = GetLastState();
77 shared_state_->Write(state); 73 shared_state_->Write(state);
78 } 74 }
79 } 75 }
80 76
81 void CommandBufferService::WaitForTokenInRange(int32_t start, int32_t end) { 77 CommandBuffer::State CommandBufferService::WaitForTokenInRange(int32_t start,
78 int32_t end) {
82 DCHECK(error_ != error::kNoError || InRange(start, end, token_)); 79 DCHECK(error_ != error::kNoError || InRange(start, end, token_));
80 return GetLastState();
83 } 81 }
84 82
85 void CommandBufferService::WaitForGetOffsetInRange(int32_t start, int32_t end) { 83 CommandBuffer::State CommandBufferService::WaitForGetOffsetInRange(
84 int32_t start,
85 int32_t end) {
86 DCHECK(error_ != error::kNoError || InRange(start, end, get_offset_)); 86 DCHECK(error_ != error::kNoError || InRange(start, end, get_offset_));
87 return GetLastState();
87 } 88 }
88 89
89 void CommandBufferService::Flush(int32_t put_offset) { 90 void CommandBufferService::Flush(int32_t put_offset) {
90 if (put_offset < 0 || put_offset >= num_entries_) { 91 if (put_offset < 0 || put_offset >= num_entries_) {
91 error_ = gpu::error::kOutOfBounds; 92 error_ = gpu::error::kOutOfBounds;
92 return; 93 return;
93 } 94 }
94 95
95 put_offset_ = put_offset; 96 put_offset_ = put_offset;
96 97
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 static_cast<CommandBufferSharedState*>(shared_state_buffer_->GetMemory()); 130 static_cast<CommandBufferSharedState*>(shared_state_buffer_->GetMemory());
130 131
131 UpdateState(); 132 UpdateState();
132 } 133 }
133 134
134 void CommandBufferService::SetGetOffset(int32_t get_offset) { 135 void CommandBufferService::SetGetOffset(int32_t get_offset) {
135 DCHECK(get_offset >= 0 && get_offset < num_entries_); 136 DCHECK(get_offset >= 0 && get_offset < num_entries_);
136 get_offset_ = get_offset; 137 get_offset_ = get_offset;
137 } 138 }
138 139
140 void CommandBufferService::SetReleaseCount(uint64_t release_count) {
141 DCHECK(release_count >= release_count_);
142 release_count_ = release_count;
143 UpdateState();
144 }
145
139 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size, 146 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size,
140 int32_t* id) { 147 int32_t* id) {
141 static int32_t next_id = 1; 148 static int32_t next_id = 1;
142 *id = next_id++; 149 *id = next_id++;
143 auto result = CreateTransferBufferWithId(size, *id); 150 auto result = CreateTransferBufferWithId(size, *id);
144 if (!result) 151 if (!result)
145 *id = -1; 152 *id = -1;
146 return result; 153 return result;
147 } 154 }
148 155
(...skipping 25 matching lines...) Expand all
174 if (!RegisterTransferBuffer(id, 181 if (!RegisterTransferBuffer(id,
175 base::MakeUnique<MemoryBufferBacking>(size))) { 182 base::MakeUnique<MemoryBufferBacking>(size))) {
176 if (error_ == error::kNoError) 183 if (error_ == error::kNoError)
177 error_ = gpu::error::kOutOfBounds; 184 error_ = gpu::error::kOutOfBounds;
178 return NULL; 185 return NULL;
179 } 186 }
180 187
181 return GetTransferBuffer(id); 188 return GetTransferBuffer(id);
182 } 189 }
183 190
184
185 void CommandBufferService::SetToken(int32_t token) { 191 void CommandBufferService::SetToken(int32_t token) {
186 token_ = token; 192 token_ = token;
187 UpdateState(); 193 UpdateState();
188 } 194 }
189 195
190 void CommandBufferService::SetParseError(error::Error error) { 196 void CommandBufferService::SetParseError(error::Error error) {
191 if (error_ == error::kNoError) { 197 if (error_ == error::kNoError) {
192 error_ = error; 198 error_ = error;
193 if (!parse_error_callback_.is_null()) 199 if (!parse_error_callback_.is_null())
194 parse_error_callback_.Run(); 200 parse_error_callback_.Run();
(...skipping 18 matching lines...) Expand all
213 const GetBufferChangedCallback& callback) { 219 const GetBufferChangedCallback& callback) {
214 get_buffer_change_callback_ = callback; 220 get_buffer_change_callback_ = callback;
215 } 221 }
216 222
217 void CommandBufferService::SetParseErrorCallback( 223 void CommandBufferService::SetParseErrorCallback(
218 const base::Closure& callback) { 224 const base::Closure& callback) {
219 parse_error_callback_ = callback; 225 parse_error_callback_ = callback;
220 } 226 }
221 227
222 } // namespace gpu 228 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/command_buffer_service.h ('k') | gpu/command_buffer/tests/gl_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698