OLD | NEW |
---|---|
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" |
11 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 11 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
12 #include "gpu/command_buffer/common/command_buffer_shared.h" | 12 #include "gpu/command_buffer/common/command_buffer_shared.h" |
13 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 13 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
14 | 14 |
15 using ::base::SharedMemory; | 15 using ::base::SharedMemory; |
16 using ::base::AutoLock; | |
16 | 17 |
17 namespace gpu { | 18 namespace gpu { |
18 | 19 |
19 CommandBufferService::CommandBufferService( | 20 CommandBufferService::CommandBufferService( |
20 TransferBufferManagerInterface* transfer_buffer_manager) | 21 TransferBufferManagerInterface* transfer_buffer_manager) |
21 : ring_buffer_id_(-1), | 22 : ring_buffer_id_(-1), |
22 shared_state_(NULL), | 23 shared_state_(NULL), |
23 num_entries_(0), | 24 num_entries_(0), |
24 get_offset_(0), | 25 get_offset_(0), |
25 put_offset_(0), | 26 put_offset_(0), |
26 transfer_buffer_manager_(transfer_buffer_manager), | 27 transfer_buffer_manager_(transfer_buffer_manager), |
27 token_(0), | 28 token_(0), |
29 async_token_(0), | |
28 generation_(0), | 30 generation_(0), |
29 error_(error::kNoError), | 31 error_(error::kNoError), |
30 context_lost_reason_(error::kUnknown) { | 32 context_lost_reason_(error::kUnknown) { |
31 } | 33 } |
32 | 34 |
33 CommandBufferService::~CommandBufferService() { | 35 CommandBufferService::~CommandBufferService() { |
34 } | 36 } |
35 | 37 |
36 bool CommandBufferService::Initialize() { | 38 bool CommandBufferService::Initialize() { |
37 return true; | 39 return true; |
38 } | 40 } |
39 | 41 |
40 CommandBufferService::State CommandBufferService::GetState() { | 42 CommandBufferService::State CommandBufferService::GetState() { |
43 AutoLock lock(lock_); | |
44 return GetStateImpl(); | |
45 } | |
46 | |
47 CommandBufferService::State CommandBufferService::GetStateImpl() { | |
reveman
2014/01/22 17:30:04
Please add a lock_.AssertAcquired() call here to p
| |
41 State state; | 48 State state; |
42 state.num_entries = num_entries_; | 49 state.num_entries = num_entries_; |
43 state.get_offset = get_offset_; | 50 state.get_offset = get_offset_; |
44 state.put_offset = put_offset_; | 51 state.put_offset = put_offset_; |
45 state.token = token_; | 52 state.token = token_; |
53 state.async_token = async_token_; | |
46 state.error = error_; | 54 state.error = error_; |
47 state.context_lost_reason = context_lost_reason_; | 55 state.context_lost_reason = context_lost_reason_; |
48 state.generation = ++generation_; | 56 state.generation = ++generation_; |
49 | 57 |
50 return state; | 58 return state; |
51 } | 59 } |
52 | 60 |
53 CommandBufferService::State CommandBufferService::GetLastState() { | 61 CommandBufferService::State CommandBufferService::GetLastState() { |
54 return GetState(); | 62 return GetState(); |
55 } | 63 } |
56 | 64 |
57 int32 CommandBufferService::GetLastToken() { | 65 int32 CommandBufferService::GetLastToken() { |
58 return GetState().token; | 66 return GetState().token; |
59 } | 67 } |
60 | 68 |
61 void CommandBufferService::UpdateState() { | 69 void CommandBufferService::UpdateState() { |
70 AutoLock lock(lock_); | |
62 if (shared_state_) { | 71 if (shared_state_) { |
63 CommandBufferService::State state = GetState(); | 72 CommandBufferService::State state = GetStateImpl(); |
64 shared_state_->Write(state); | 73 shared_state_->Write(state); |
65 } | 74 } |
66 } | 75 } |
67 | 76 |
68 CommandBufferService::State CommandBufferService::FlushSync( | 77 CommandBufferService::State CommandBufferService::FlushSync( |
69 int32 put_offset, int32 last_known_get) { | 78 int32 put_offset, int32 last_known_get) { |
70 if (put_offset < 0 || put_offset > num_entries_) { | 79 if (put_offset < 0 || put_offset > num_entries_) { |
71 error_ = gpu::error::kOutOfBounds; | 80 error_ = gpu::error::kOutOfBounds; |
72 return GetState(); | 81 return GetState(); |
73 } | 82 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 return transfer_buffer_manager_->RegisterTransferBuffer(id, | 176 return transfer_buffer_manager_->RegisterTransferBuffer(id, |
168 shared_memory, | 177 shared_memory, |
169 size); | 178 size); |
170 } | 179 } |
171 | 180 |
172 void CommandBufferService::SetToken(int32 token) { | 181 void CommandBufferService::SetToken(int32 token) { |
173 token_ = token; | 182 token_ = token; |
174 UpdateState(); | 183 UpdateState(); |
175 } | 184 } |
176 | 185 |
186 void CommandBufferService::SetAsyncToken(uint32 token) { | |
187 async_token_ = token; | |
reveman
2014/01/22 17:30:04
Do you need to acquire the lock before writing to
| |
188 UpdateState(); | |
189 } | |
190 | |
177 void CommandBufferService::SetParseError(error::Error error) { | 191 void CommandBufferService::SetParseError(error::Error error) { |
178 if (error_ == error::kNoError) { | 192 if (error_ == error::kNoError) { |
179 error_ = error; | 193 error_ = error; |
180 if (!parse_error_callback_.is_null()) | 194 if (!parse_error_callback_.is_null()) |
181 parse_error_callback_.Run(); | 195 parse_error_callback_.Run(); |
182 } | 196 } |
183 } | 197 } |
184 | 198 |
185 void CommandBufferService::SetContextLostReason( | 199 void CommandBufferService::SetContextLostReason( |
186 error::ContextLostReason reason) { | 200 error::ContextLostReason reason) { |
187 context_lost_reason_ = reason; | 201 context_lost_reason_ = reason; |
188 } | 202 } |
189 | 203 |
190 void CommandBufferService::SetPutOffsetChangeCallback( | 204 void CommandBufferService::SetPutOffsetChangeCallback( |
191 const base::Closure& callback) { | 205 const base::Closure& callback) { |
192 put_offset_change_callback_ = callback; | 206 put_offset_change_callback_ = callback; |
193 } | 207 } |
194 | 208 |
195 void CommandBufferService::SetGetBufferChangeCallback( | 209 void CommandBufferService::SetGetBufferChangeCallback( |
196 const GetBufferChangedCallback& callback) { | 210 const GetBufferChangedCallback& callback) { |
197 get_buffer_change_callback_ = callback; | 211 get_buffer_change_callback_ = callback; |
198 } | 212 } |
199 | 213 |
200 void CommandBufferService::SetParseErrorCallback( | 214 void CommandBufferService::SetParseErrorCallback( |
201 const base::Closure& callback) { | 215 const base::Closure& callback) { |
202 parse_error_callback_ = callback; | 216 parse_error_callback_ = callback; |
203 } | 217 } |
204 | 218 |
205 } // namespace gpu | 219 } // namespace gpu |
OLD | NEW |