OLD | NEW |
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/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/callback.h" | 9 #include "base/callback.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 11 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
12 | 12 |
13 using ::base::SharedMemory; | 13 using ::base::SharedMemory; |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 | 16 |
17 CommandBufferService::CommandBufferService() | 17 CommandBufferService::CommandBufferService() |
18 : num_entries_(0), | 18 : num_entries_(0), |
19 get_offset_(0), | 19 get_offset_(0), |
20 put_offset_(0), | 20 put_offset_(0), |
21 token_(0), | 21 token_(0), |
| 22 generation_(0), |
22 error_(error::kNoError) { | 23 error_(error::kNoError) { |
23 // Element zero is always NULL. | 24 // Element zero is always NULL. |
24 registered_objects_.push_back(Buffer()); | 25 registered_objects_.push_back(Buffer()); |
25 } | 26 } |
26 | 27 |
27 CommandBufferService::~CommandBufferService() { | 28 CommandBufferService::~CommandBufferService() { |
28 delete ring_buffer_.shared_memory; | 29 delete ring_buffer_.shared_memory; |
29 | 30 |
30 for (size_t i = 0; i < registered_objects_.size(); ++i) { | 31 for (size_t i = 0; i < registered_objects_.size(); ++i) { |
31 if (registered_objects_[i].shared_memory) | 32 if (registered_objects_[i].shared_memory) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return ring_buffer_; | 91 return ring_buffer_; |
91 } | 92 } |
92 | 93 |
93 CommandBufferService::State CommandBufferService::GetState() { | 94 CommandBufferService::State CommandBufferService::GetState() { |
94 State state; | 95 State state; |
95 state.num_entries = num_entries_; | 96 state.num_entries = num_entries_; |
96 state.get_offset = get_offset_; | 97 state.get_offset = get_offset_; |
97 state.put_offset = put_offset_; | 98 state.put_offset = put_offset_; |
98 state.token = token_; | 99 state.token = token_; |
99 state.error = error_; | 100 state.error = error_; |
| 101 state.generation = ++generation_; |
100 | 102 |
101 return state; | 103 return state; |
102 } | 104 } |
103 | 105 |
104 CommandBufferService::State CommandBufferService::FlushSync(int32 put_offset) { | 106 CommandBufferService::State CommandBufferService::FlushSync( |
| 107 int32 put_offset, int32 last_known_get) { |
105 if (put_offset < 0 || put_offset > num_entries_) { | 108 if (put_offset < 0 || put_offset > num_entries_) { |
106 error_ = gpu::error::kOutOfBounds; | 109 error_ = gpu::error::kOutOfBounds; |
107 return GetState(); | 110 return GetState(); |
108 } | 111 } |
109 | 112 |
110 put_offset_ = put_offset; | 113 put_offset_ = put_offset; |
111 | 114 |
112 if (put_offset_change_callback_.get()) { | 115 if (put_offset_change_callback_.get()) { |
113 put_offset_change_callback_->Run(); | 116 put_offset_change_callback_->Run(last_known_get == get_offset_); |
114 } | 117 } |
115 | 118 |
116 return GetState(); | 119 return GetState(); |
117 } | 120 } |
118 | 121 |
119 void CommandBufferService::Flush(int32 put_offset) { | 122 void CommandBufferService::Flush(int32 put_offset) { |
120 FlushSync(put_offset); | 123 if (put_offset < 0 || put_offset > num_entries_) { |
| 124 error_ = gpu::error::kOutOfBounds; |
| 125 return; |
| 126 } |
| 127 |
| 128 put_offset_ = put_offset; |
| 129 |
| 130 if (put_offset_change_callback_.get()) { |
| 131 put_offset_change_callback_->Run(false); |
| 132 } |
121 } | 133 } |
122 | 134 |
123 void CommandBufferService::SetGetOffset(int32 get_offset) { | 135 void CommandBufferService::SetGetOffset(int32 get_offset) { |
124 DCHECK(get_offset >= 0 && get_offset < num_entries_); | 136 DCHECK(get_offset >= 0 && get_offset < num_entries_); |
125 get_offset_ = get_offset; | 137 get_offset_ = get_offset; |
126 } | 138 } |
127 | 139 |
128 int32 CommandBufferService::CreateTransferBuffer(size_t size, | 140 int32 CommandBufferService::CreateTransferBuffer(size_t size, |
129 int32 id_request) { | 141 int32 id_request) { |
130 SharedMemory buffer; | 142 SharedMemory buffer; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 token_ = token; | 246 token_ = token; |
235 } | 247 } |
236 | 248 |
237 void CommandBufferService::SetParseError(error::Error error) { | 249 void CommandBufferService::SetParseError(error::Error error) { |
238 if (error_ == error::kNoError) { | 250 if (error_ == error::kNoError) { |
239 error_ = error; | 251 error_ = error; |
240 } | 252 } |
241 } | 253 } |
242 | 254 |
243 void CommandBufferService::SetPutOffsetChangeCallback( | 255 void CommandBufferService::SetPutOffsetChangeCallback( |
244 Callback0::Type* callback) { | 256 Callback1<bool>::Type* callback) { |
245 put_offset_change_callback_.reset(callback); | 257 put_offset_change_callback_.reset(callback); |
246 } | 258 } |
247 | 259 |
248 } // namespace gpu | 260 } // namespace gpu |
OLD | NEW |