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/debug/trace_event.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" |
11 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 13 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
12 #include "gpu/command_buffer/common/command_buffer_shared.h" | 14 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 15 #include "gpu/command_buffer/service/image_manager.h" |
13 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 16 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 17 #include "ui/gl/gl_image.h" |
14 | 18 |
15 using ::base::SharedMemory; | 19 using ::base::SharedMemory; |
16 | 20 |
17 namespace gpu { | 21 namespace gpu { |
18 | 22 |
19 CommandBufferService::CommandBufferService( | 23 CommandBufferService::CommandBufferService( |
20 TransferBufferManagerInterface* transfer_buffer_manager) | 24 TransferBufferManagerInterface* transfer_buffer_manager, |
| 25 gles2::ImageManager* image_manager, |
| 26 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
21 : ring_buffer_id_(-1), | 27 : ring_buffer_id_(-1), |
22 shared_state_(NULL), | 28 shared_state_(NULL), |
23 num_entries_(0), | 29 num_entries_(0), |
24 get_offset_(0), | 30 get_offset_(0), |
25 put_offset_(0), | 31 put_offset_(0), |
26 transfer_buffer_manager_(transfer_buffer_manager), | 32 transfer_buffer_manager_(transfer_buffer_manager), |
27 token_(0), | 33 token_(0), |
28 generation_(0), | 34 generation_(0), |
29 error_(error::kNoError), | 35 error_(error::kNoError), |
30 context_lost_reason_(error::kUnknown) { | 36 context_lost_reason_(error::kUnknown), |
| 37 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 38 image_manager_(image_manager) { |
31 } | 39 } |
32 | 40 |
33 CommandBufferService::~CommandBufferService() { | 41 CommandBufferService::~CommandBufferService() { |
34 } | 42 } |
35 | 43 |
36 bool CommandBufferService::Initialize() { | 44 bool CommandBufferService::Initialize() { |
37 return true; | 45 return true; |
38 } | 46 } |
39 | 47 |
40 CommandBufferService::State CommandBufferService::GetState() { | 48 CommandBufferService::State CommandBufferService::GetState() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void CommandBufferService::SetParseErrorCallback( | 208 void CommandBufferService::SetParseErrorCallback( |
201 const base::Closure& callback) { | 209 const base::Closure& callback) { |
202 parse_error_callback_ = callback; | 210 parse_error_callback_ = callback; |
203 } | 211 } |
204 | 212 |
205 uint32 CommandBufferService::InsertSyncPoint() { | 213 uint32 CommandBufferService::InsertSyncPoint() { |
206 NOTREACHED(); | 214 NOTREACHED(); |
207 return 0; | 215 return 0; |
208 } | 216 } |
209 | 217 |
| 218 bool CommandBufferService::RegisterGpuMemoryBuffer( |
| 219 int32 id, |
| 220 gfx::GpuMemoryBufferHandle buffer, |
| 221 size_t width, |
| 222 size_t height, |
| 223 unsigned internalformat) { |
| 224 if (id <= 0) { |
| 225 DVLOG(0) << "Cannot register GPU memory buffer with non-positive ID."; |
| 226 return false; |
| 227 } |
| 228 |
| 229 if (image_manager_->LookupImage(id)) { |
| 230 DVLOG(0) << "GPU memory buffer ID already in use."; |
| 231 return false; |
| 232 } |
| 233 |
| 234 scoped_refptr<gfx::GLImage> gl_image = |
| 235 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer, |
| 236 gfx::Size(width, height)); |
| 237 if (!gl_image) |
| 238 return false; |
| 239 |
| 240 image_manager_->AddImage(gl_image.get(), id); |
| 241 return true; |
| 242 } |
| 243 |
| 244 gfx::GpuMemoryBuffer* CommandBufferService::CreateGpuMemoryBuffer( |
| 245 size_t width, |
| 246 size_t height, |
| 247 unsigned internalformat, |
| 248 int32* id) { |
| 249 *id = -1; |
| 250 |
| 251 CHECK(gpu_memory_buffer_factory_) << "No GPU memory buffer factory provided"; |
| 252 scoped_ptr<gfx::GpuMemoryBuffer> buffer = make_scoped_ptr( |
| 253 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(width, |
| 254 height, |
| 255 internalformat)); |
| 256 if (!buffer) |
| 257 return NULL; |
| 258 |
| 259 static int32 next_id = 1; |
| 260 *id = next_id++; |
| 261 |
| 262 if (!RegisterGpuMemoryBuffer(*id, |
| 263 buffer->GetHandle(), |
| 264 width, |
| 265 height, |
| 266 internalformat)) { |
| 267 *id = -1; |
| 268 return NULL; |
| 269 } |
| 270 |
| 271 gpu_memory_buffers_[*id] = buffer.get(); |
| 272 return buffer.release(); |
| 273 } |
| 274 |
| 275 void CommandBufferService::DestroyGpuMemoryBuffer(int32 id) { |
| 276 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); |
| 277 if (it != gpu_memory_buffers_.end()) { |
| 278 delete it->second; |
| 279 gpu_memory_buffers_.erase(it); |
| 280 } |
| 281 |
| 282 image_manager_->RemoveImage(id); |
| 283 } |
| 284 |
210 } // namespace gpu | 285 } // namespace gpu |
OLD | NEW |