OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "gpu/command_buffer/common/cmd_buffer_common.h" |
| 10 |
9 using ::base::SharedMemory; | 11 using ::base::SharedMemory; |
10 | 12 |
11 namespace gpu { | 13 namespace gpu { |
12 | 14 |
13 CommandBufferService::CommandBufferService() | 15 CommandBufferService::CommandBufferService() |
14 : size_(0), | 16 : size_(0), |
15 get_offset_(0), | 17 get_offset_(0), |
16 put_offset_(0), | 18 put_offset_(0), |
17 token_(0), | 19 token_(0), |
18 parse_error_(0), | 20 parse_error_(0), |
19 error_status_(false) { | 21 error_status_(false) { |
20 // Element zero is always NULL. | 22 // Element zero is always NULL. |
21 registered_objects_.push_back(linked_ptr<SharedMemory>()); | 23 registered_objects_.push_back(linked_ptr<SharedMemory>()); |
22 } | 24 } |
23 | 25 |
24 CommandBufferService::~CommandBufferService() { | 26 CommandBufferService::~CommandBufferService() { |
25 } | 27 } |
26 | 28 |
27 base::SharedMemory* CommandBufferService::Initialize(int32 size) { | 29 bool CommandBufferService::Initialize(int32 size) { |
28 // Fail if already initialized. | 30 // Fail if already initialized. |
29 if (ring_buffer_.get()) | 31 if (ring_buffer_.get()) |
30 return false; | 32 return false; |
31 | 33 |
32 size_ = size; | 34 size_ = size; |
33 | 35 |
34 ring_buffer_.reset(new SharedMemory); | 36 ring_buffer_.reset(new SharedMemory); |
35 if (ring_buffer_->Create(std::wstring(), false, false, size_)) { | 37 size_t size_bytes = size * sizeof(CommandBufferEntry); |
36 if (ring_buffer_->Map(size_)) | 38 if (ring_buffer_->Create(std::wstring(), false, false, size_bytes)) { |
37 return ring_buffer_.get(); | 39 if (ring_buffer_->Map(size_bytes)) |
| 40 return true; |
38 } | 41 } |
39 | 42 |
40 ring_buffer_.reset(); | 43 ring_buffer_.reset(); |
41 return NULL; | 44 return false; |
42 } | 45 } |
43 | 46 |
44 SharedMemory* CommandBufferService::GetRingBuffer() { | 47 Buffer CommandBufferService::GetRingBuffer() { |
45 return ring_buffer_.get(); | 48 Buffer buffer; |
| 49 if (ring_buffer_.get()) { |
| 50 buffer.ptr = ring_buffer_->memory(); |
| 51 buffer.size = ring_buffer_->max_size(); |
| 52 buffer.shared_memory = ring_buffer_.get(); |
| 53 } |
| 54 return buffer; |
46 } | 55 } |
47 | 56 |
48 int32 CommandBufferService::GetSize() { | 57 int32 CommandBufferService::GetSize() { |
49 return size_; | 58 return size_; |
50 } | 59 } |
51 | 60 |
52 int32 CommandBufferService::SyncOffsets(int32 put_offset) { | 61 int32 CommandBufferService::SyncOffsets(int32 put_offset) { |
53 if (put_offset < 0 || put_offset >= size_) | 62 if (put_offset < 0 || put_offset >= size_) |
54 return -1; | 63 return -1; |
55 | 64 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Remove all null objects from the end of the vector. This allows the vector | 125 // Remove all null objects from the end of the vector. This allows the vector |
117 // to shrink when, for example, all objects are unregistered. Note that this | 126 // to shrink when, for example, all objects are unregistered. Note that this |
118 // loop never removes element zero, which is always NULL. | 127 // loop never removes element zero, which is always NULL. |
119 while (registered_objects_.size() > 1 && !registered_objects_.back().get()) { | 128 while (registered_objects_.size() > 1 && !registered_objects_.back().get()) { |
120 registered_objects_.pop_back(); | 129 registered_objects_.pop_back(); |
121 unused_registered_object_elements_.erase( | 130 unused_registered_object_elements_.erase( |
122 static_cast<int32>(registered_objects_.size())); | 131 static_cast<int32>(registered_objects_.size())); |
123 } | 132 } |
124 } | 133 } |
125 | 134 |
126 ::base::SharedMemory* CommandBufferService::GetTransferBuffer(int32 handle) { | 135 Buffer CommandBufferService::GetTransferBuffer(int32 handle) { |
127 if (handle < 0) | 136 if (handle < 0) |
128 return NULL; | 137 return Buffer(); |
129 | 138 |
130 if (static_cast<size_t>(handle) >= registered_objects_.size()) | 139 if (static_cast<size_t>(handle) >= registered_objects_.size()) |
131 return NULL; | 140 return Buffer(); |
132 | 141 |
133 return registered_objects_[handle].get(); | 142 base::SharedMemory* shared_memory = registered_objects_[handle].get(); |
| 143 if (!shared_memory) |
| 144 return Buffer(); |
| 145 |
| 146 if (!shared_memory->memory()) { |
| 147 if (!shared_memory->Map(shared_memory->max_size())) |
| 148 return Buffer(); |
| 149 } |
| 150 |
| 151 Buffer buffer; |
| 152 buffer.ptr = shared_memory->memory(); |
| 153 buffer.size = shared_memory->max_size(); |
| 154 buffer.shared_memory = shared_memory; |
| 155 return buffer; |
134 } | 156 } |
135 | 157 |
136 int32 CommandBufferService::GetToken() { | 158 int32 CommandBufferService::GetToken() { |
137 return token_; | 159 return token_; |
138 } | 160 } |
139 | 161 |
140 void CommandBufferService::SetToken(int32 token) { | 162 void CommandBufferService::SetToken(int32 token) { |
141 token_ = token; | 163 token_ = token; |
142 } | 164 } |
143 | 165 |
(...skipping 11 matching lines...) Expand all Loading... |
155 | 177 |
156 bool CommandBufferService::GetErrorStatus() { | 178 bool CommandBufferService::GetErrorStatus() { |
157 return error_status_; | 179 return error_status_; |
158 } | 180 } |
159 | 181 |
160 void CommandBufferService::RaiseErrorStatus() { | 182 void CommandBufferService::RaiseErrorStatus() { |
161 error_status_ = true; | 183 error_status_ = true; |
162 } | 184 } |
163 | 185 |
164 } // namespace gpu | 186 } // namespace gpu |
OLD | NEW |