| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <memory> |
| 11 | 12 |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 15 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 15 #include "gpu/command_buffer/common/command_buffer_shared.h" | 16 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 16 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 17 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 17 | 18 |
| 18 using ::base::SharedMemory; | 19 using ::base::SharedMemory; |
| 19 | 20 |
| 20 namespace gpu { | 21 namespace gpu { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 put_offset_ = 0; | 99 put_offset_ = 0; |
| 99 SetGetOffset(0); | 100 SetGetOffset(0); |
| 100 if (!get_buffer_change_callback_.is_null()) { | 101 if (!get_buffer_change_callback_.is_null()) { |
| 101 get_buffer_change_callback_.Run(ring_buffer_id_); | 102 get_buffer_change_callback_.Run(ring_buffer_id_); |
| 102 } | 103 } |
| 103 | 104 |
| 104 UpdateState(); | 105 UpdateState(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void CommandBufferService::SetSharedStateBuffer( | 108 void CommandBufferService::SetSharedStateBuffer( |
| 108 scoped_ptr<BufferBacking> shared_state_buffer) { | 109 std::unique_ptr<BufferBacking> shared_state_buffer) { |
| 109 shared_state_buffer_ = std::move(shared_state_buffer); | 110 shared_state_buffer_ = std::move(shared_state_buffer); |
| 110 DCHECK(shared_state_buffer_->GetSize() >= sizeof(*shared_state_)); | 111 DCHECK(shared_state_buffer_->GetSize() >= sizeof(*shared_state_)); |
| 111 | 112 |
| 112 shared_state_ = | 113 shared_state_ = |
| 113 static_cast<CommandBufferSharedState*>(shared_state_buffer_->GetMemory()); | 114 static_cast<CommandBufferSharedState*>(shared_state_buffer_->GetMemory()); |
| 114 | 115 |
| 115 UpdateState(); | 116 UpdateState(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void CommandBufferService::SetGetOffset(int32_t get_offset) { | 119 void CommandBufferService::SetGetOffset(int32_t get_offset) { |
| 119 DCHECK(get_offset >= 0 && get_offset < num_entries_); | 120 DCHECK(get_offset >= 0 && get_offset < num_entries_); |
| 120 get_offset_ = get_offset; | 121 get_offset_ = get_offset; |
| 121 } | 122 } |
| 122 | 123 |
| 123 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size, | 124 scoped_refptr<Buffer> CommandBufferService::CreateTransferBuffer(size_t size, |
| 124 int32_t* id) { | 125 int32_t* id) { |
| 125 *id = -1; | 126 *id = -1; |
| 126 | 127 |
| 127 scoped_ptr<SharedMemory> shared_memory(new SharedMemory()); | 128 std::unique_ptr<SharedMemory> shared_memory(new SharedMemory()); |
| 128 if (!shared_memory->CreateAndMapAnonymous(size)) { | 129 if (!shared_memory->CreateAndMapAnonymous(size)) { |
| 129 if (error_ == error::kNoError) | 130 if (error_ == error::kNoError) |
| 130 error_ = gpu::error::kOutOfBounds; | 131 error_ = gpu::error::kOutOfBounds; |
| 131 return NULL; | 132 return NULL; |
| 132 } | 133 } |
| 133 | 134 |
| 134 static int32_t next_id = 1; | 135 static int32_t next_id = 1; |
| 135 *id = next_id++; | 136 *id = next_id++; |
| 136 | 137 |
| 137 if (!RegisterTransferBuffer( | 138 if (!RegisterTransferBuffer( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 put_offset_ = 0; | 156 put_offset_ = 0; |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 159 scoped_refptr<Buffer> CommandBufferService::GetTransferBuffer(int32_t id) { | 160 scoped_refptr<Buffer> CommandBufferService::GetTransferBuffer(int32_t id) { |
| 160 return transfer_buffer_manager_->GetTransferBuffer(id); | 161 return transfer_buffer_manager_->GetTransferBuffer(id); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool CommandBufferService::RegisterTransferBuffer( | 164 bool CommandBufferService::RegisterTransferBuffer( |
| 164 int32_t id, | 165 int32_t id, |
| 165 scoped_ptr<BufferBacking> buffer) { | 166 std::unique_ptr<BufferBacking> buffer) { |
| 166 return transfer_buffer_manager_->RegisterTransferBuffer(id, | 167 return transfer_buffer_manager_->RegisterTransferBuffer(id, |
| 167 std::move(buffer)); | 168 std::move(buffer)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void CommandBufferService::SetToken(int32_t token) { | 171 void CommandBufferService::SetToken(int32_t token) { |
| 171 token_ = token; | 172 token_ = token; |
| 172 UpdateState(); | 173 UpdateState(); |
| 173 } | 174 } |
| 174 | 175 |
| 175 void CommandBufferService::SetParseError(error::Error error) { | 176 void CommandBufferService::SetParseError(error::Error error) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 const GetBufferChangedCallback& callback) { | 199 const GetBufferChangedCallback& callback) { |
| 199 get_buffer_change_callback_ = callback; | 200 get_buffer_change_callback_ = callback; |
| 200 } | 201 } |
| 201 | 202 |
| 202 void CommandBufferService::SetParseErrorCallback( | 203 void CommandBufferService::SetParseErrorCallback( |
| 203 const base::Closure& callback) { | 204 const base::Closure& callback) { |
| 204 parse_error_callback_ = callback; | 205 parse_error_callback_ = callback; |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace gpu | 208 } // namespace gpu |
| OLD | NEW |