| 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/process_util.h" | 9 #include "base/process_util.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 | 13 |
| 13 using ::base::SharedMemory; | 14 using ::base::SharedMemory; |
| 14 | 15 |
| 15 namespace gpu { | 16 namespace gpu { |
| 16 | 17 |
| 17 CommandBufferService::CommandBufferService() | 18 CommandBufferService::CommandBufferService() |
| 18 : ring_buffer_id_(-1), | 19 : ring_buffer_id_(-1), |
| 20 shared_state_(NULL), |
| 19 num_entries_(0), | 21 num_entries_(0), |
| 20 get_offset_(0), | 22 get_offset_(0), |
| 21 put_offset_(0), | 23 put_offset_(0), |
| 22 token_(0), | 24 token_(0), |
| 23 generation_(0), | 25 generation_(0), |
| 24 error_(error::kNoError), | 26 error_(error::kNoError), |
| 25 context_lost_reason_(error::kUnknown), | 27 context_lost_reason_(error::kUnknown), |
| 26 shared_memory_bytes_allocated_(0) { | 28 shared_memory_bytes_allocated_(0) { |
| 27 // Element zero is always NULL. | 29 // Element zero is always NULL. |
| 28 registered_objects_.push_back(Buffer()); | 30 registered_objects_.push_back(Buffer()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 state.context_lost_reason = context_lost_reason_; | 54 state.context_lost_reason = context_lost_reason_; |
| 53 state.generation = ++generation_; | 55 state.generation = ++generation_; |
| 54 | 56 |
| 55 return state; | 57 return state; |
| 56 } | 58 } |
| 57 | 59 |
| 58 CommandBufferService::State CommandBufferService::GetLastState() { | 60 CommandBufferService::State CommandBufferService::GetLastState() { |
| 59 return GetState(); | 61 return GetState(); |
| 60 } | 62 } |
| 61 | 63 |
| 64 void CommandBufferService::UpdateState() { |
| 65 if (shared_state_) { |
| 66 CommandBufferService::State state = GetState(); |
| 67 shared_state_->Write(state); |
| 68 } |
| 69 } |
| 70 |
| 62 CommandBufferService::State CommandBufferService::FlushSync( | 71 CommandBufferService::State CommandBufferService::FlushSync( |
| 63 int32 put_offset, int32 last_known_get) { | 72 int32 put_offset, int32 last_known_get) { |
| 64 if (put_offset < 0 || put_offset > num_entries_) { | 73 if (put_offset < 0 || put_offset > num_entries_) { |
| 65 error_ = gpu::error::kOutOfBounds; | 74 error_ = gpu::error::kOutOfBounds; |
| 66 return GetState(); | 75 return GetState(); |
| 67 } | 76 } |
| 68 | 77 |
| 69 put_offset_ = put_offset; | 78 put_offset_ = put_offset; |
| 70 | 79 |
| 71 if (!put_offset_change_callback_.is_null()) | 80 if (!put_offset_change_callback_.is_null()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 DCHECK_EQ(put_offset_, get_offset_); // Only if it's empty. | 100 DCHECK_EQ(put_offset_, get_offset_); // Only if it's empty. |
| 92 ring_buffer_ = GetTransferBuffer(transfer_buffer_id); | 101 ring_buffer_ = GetTransferBuffer(transfer_buffer_id); |
| 93 DCHECK(ring_buffer_.ptr); | 102 DCHECK(ring_buffer_.ptr); |
| 94 ring_buffer_id_ = transfer_buffer_id; | 103 ring_buffer_id_ = transfer_buffer_id; |
| 95 num_entries_ = ring_buffer_.size / sizeof(CommandBufferEntry); | 104 num_entries_ = ring_buffer_.size / sizeof(CommandBufferEntry); |
| 96 put_offset_ = 0; | 105 put_offset_ = 0; |
| 97 SetGetOffset(0); | 106 SetGetOffset(0); |
| 98 if (!get_buffer_change_callback_.is_null()) { | 107 if (!get_buffer_change_callback_.is_null()) { |
| 99 get_buffer_change_callback_.Run(ring_buffer_id_); | 108 get_buffer_change_callback_.Run(ring_buffer_id_); |
| 100 } | 109 } |
| 110 |
| 111 UpdateState(); |
| 112 } |
| 113 |
| 114 void CommandBufferService::SetSharedStateBuffer(int32 transfer_buffer_id) { |
| 115 gpu::Buffer buffer = GetTransferBuffer(transfer_buffer_id); |
| 116 shared_state_ = reinterpret_cast<CommandBufferSharedState*>(buffer.ptr); |
| 117 |
| 118 UpdateState(); |
| 101 } | 119 } |
| 102 | 120 |
| 103 void CommandBufferService::SetGetOffset(int32 get_offset) { | 121 void CommandBufferService::SetGetOffset(int32 get_offset) { |
| 104 DCHECK(get_offset >= 0 && get_offset < num_entries_); | 122 DCHECK(get_offset >= 0 && get_offset < num_entries_); |
| 105 get_offset_ = get_offset; | 123 get_offset_ = get_offset; |
| 106 } | 124 } |
| 107 | 125 |
| 108 int32 CommandBufferService::CreateTransferBuffer(size_t size, | 126 int32 CommandBufferService::CreateTransferBuffer(size_t size, |
| 109 int32 id_request) { | 127 int32 id_request) { |
| 110 SharedMemory buffer; | 128 SharedMemory buffer; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 const GetBufferChangedCallback& callback) { | 270 const GetBufferChangedCallback& callback) { |
| 253 get_buffer_change_callback_ = callback; | 271 get_buffer_change_callback_ = callback; |
| 254 } | 272 } |
| 255 | 273 |
| 256 void CommandBufferService::SetParseErrorCallback( | 274 void CommandBufferService::SetParseErrorCallback( |
| 257 const base::Closure& callback) { | 275 const base::Closure& callback) { |
| 258 parse_error_callback_ = callback; | 276 parse_error_callback_ = callback; |
| 259 } | 277 } |
| 260 | 278 |
| 261 } // namespace gpu | 279 } // namespace gpu |
| OLD | NEW |