| 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" | |
| 10 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 11 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 10 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 12 | 11 |
| 13 using ::base::SharedMemory; | 12 using ::base::SharedMemory; |
| 14 | 13 |
| 15 namespace gpu { | 14 namespace gpu { |
| 16 | 15 |
| 17 CommandBufferService::CommandBufferService() | 16 CommandBufferService::CommandBufferService() |
| 18 : num_entries_(0), | 17 : num_entries_(0), |
| 19 get_offset_(0), | 18 get_offset_(0), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 109 |
| 111 CommandBufferService::State CommandBufferService::FlushSync( | 110 CommandBufferService::State CommandBufferService::FlushSync( |
| 112 int32 put_offset, int32 last_known_get) { | 111 int32 put_offset, int32 last_known_get) { |
| 113 if (put_offset < 0 || put_offset > num_entries_) { | 112 if (put_offset < 0 || put_offset > num_entries_) { |
| 114 error_ = gpu::error::kOutOfBounds; | 113 error_ = gpu::error::kOutOfBounds; |
| 115 return GetState(); | 114 return GetState(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 put_offset_ = put_offset; | 117 put_offset_ = put_offset; |
| 119 | 118 |
| 120 if (put_offset_change_callback_.get()) { | 119 if (!put_offset_change_callback_.is_null()) |
| 121 put_offset_change_callback_->Run(); | 120 put_offset_change_callback_.Run(); |
| 122 } | |
| 123 | 121 |
| 124 return GetState(); | 122 return GetState(); |
| 125 } | 123 } |
| 126 | 124 |
| 127 void CommandBufferService::Flush(int32 put_offset) { | 125 void CommandBufferService::Flush(int32 put_offset) { |
| 128 if (put_offset < 0 || put_offset > num_entries_) { | 126 if (put_offset < 0 || put_offset > num_entries_) { |
| 129 error_ = gpu::error::kOutOfBounds; | 127 error_ = gpu::error::kOutOfBounds; |
| 130 return; | 128 return; |
| 131 } | 129 } |
| 132 | 130 |
| 133 put_offset_ = put_offset; | 131 put_offset_ = put_offset; |
| 134 | 132 |
| 135 if (put_offset_change_callback_.get()) { | 133 if (!put_offset_change_callback_.is_null()) |
| 136 put_offset_change_callback_->Run(); | 134 put_offset_change_callback_.Run(); |
| 137 } | |
| 138 } | 135 } |
| 139 | 136 |
| 140 void CommandBufferService::SetGetOffset(int32 get_offset) { | 137 void CommandBufferService::SetGetOffset(int32 get_offset) { |
| 141 DCHECK(get_offset >= 0 && get_offset < num_entries_); | 138 DCHECK(get_offset >= 0 && get_offset < num_entries_); |
| 142 get_offset_ = get_offset; | 139 get_offset_ = get_offset; |
| 143 } | 140 } |
| 144 | 141 |
| 145 int32 CommandBufferService::CreateTransferBuffer(size_t size, | 142 int32 CommandBufferService::CreateTransferBuffer(size_t size, |
| 146 int32 id_request) { | 143 int32 id_request) { |
| 147 SharedMemory buffer; | 144 SharedMemory buffer; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return registered_objects_[handle]; | 244 return registered_objects_[handle]; |
| 248 } | 245 } |
| 249 | 246 |
| 250 void CommandBufferService::SetToken(int32 token) { | 247 void CommandBufferService::SetToken(int32 token) { |
| 251 token_ = token; | 248 token_ = token; |
| 252 } | 249 } |
| 253 | 250 |
| 254 void CommandBufferService::SetParseError(error::Error error) { | 251 void CommandBufferService::SetParseError(error::Error error) { |
| 255 if (error_ == error::kNoError) { | 252 if (error_ == error::kNoError) { |
| 256 error_ = error; | 253 error_ = error; |
| 257 if (parse_error_callback_.get()) | 254 if (!parse_error_callback_.is_null()) |
| 258 parse_error_callback_->Run(); | 255 parse_error_callback_.Run(); |
| 259 } | 256 } |
| 260 } | 257 } |
| 261 | 258 |
| 262 void CommandBufferService::SetContextLostReason( | 259 void CommandBufferService::SetContextLostReason( |
| 263 error::ContextLostReason reason) { | 260 error::ContextLostReason reason) { |
| 264 context_lost_reason_ = reason; | 261 context_lost_reason_ = reason; |
| 265 } | 262 } |
| 266 | 263 |
| 267 void CommandBufferService::SetPutOffsetChangeCallback( | 264 void CommandBufferService::SetPutOffsetChangeCallback( |
| 268 Callback0::Type* callback) { | 265 const base::Closure& callback) { |
| 269 put_offset_change_callback_.reset(callback); | 266 put_offset_change_callback_ = callback; |
| 270 } | 267 } |
| 271 | 268 |
| 272 void CommandBufferService::SetParseErrorCallback( | 269 void CommandBufferService::SetParseErrorCallback( |
| 273 Callback0::Type* callback) { | 270 const base::Closure& callback) { |
| 274 parse_error_callback_.reset(callback); | 271 parse_error_callback_ = callback; |
| 275 } | 272 } |
| 276 | 273 |
| 277 } // namespace gpu | 274 } // namespace gpu |
| OLD | NEW |