Chromium Code Reviews| 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() { |
|
piman
2013/08/01 21:19:30
I think if the client isn't well behaved (or crash
reveman
2013/08/08 23:19:00
Done.
| |
| 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() { |
| 41 State state; | 49 State state; |
| 42 state.num_entries = num_entries_; | 50 state.num_entries = num_entries_; |
| 43 state.get_offset = get_offset_; | 51 state.get_offset = get_offset_; |
| (...skipping 156 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 gfx::GpuMemoryBuffer* CommandBufferService::CreateGpuMemoryBuffer( | |
| 219 size_t width, | |
| 220 size_t height, | |
| 221 unsigned internalformat, | |
| 222 int32* id) { | |
| 223 *id = -1; | |
| 224 | |
| 225 CHECK(gpu_memory_buffer_factory_) << "No GPU memory buffer factory provided"; | |
| 226 scoped_ptr<gfx::GpuMemoryBuffer> buffer = make_scoped_ptr( | |
|
piman
2013/08/01 21:19:30
nit: you could use linked_ptr and put that linked_
reveman
2013/08/08 23:19:00
Done.
| |
| 227 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(width, | |
| 228 height, | |
| 229 internalformat)); | |
| 230 if (!buffer) | |
|
kaanb
2013/07/31 23:44:05
buffer.get()
reveman
2013/08/01 13:32:18
scoped_ptr implements operator Testable() and can
| |
| 231 return NULL; | |
| 232 | |
| 233 static int32 next_id = 1; | |
|
piman
2013/08/01 21:19:30
Does this ID need to be shared between contexts?
reveman
2013/08/08 23:19:00
Not before but it does in latest patch. Is this a
| |
| 234 *id = next_id++; | |
|
no sievers
2013/08/01 00:38:04
Does it make sense to establish this 1:1 relations
reveman
2013/08/01 13:32:18
I don't necessarily think we are. We can add anoth
| |
| 235 | |
| 236 if (!RegisterGpuMemoryBuffer(*id, | |
| 237 buffer->GetHandle(), | |
| 238 width, | |
| 239 height, | |
| 240 internalformat)) { | |
| 241 *id = -1; | |
| 242 return NULL; | |
| 243 } | |
| 244 | |
| 245 gpu_memory_buffers_[*id] = buffer.get(); | |
| 246 return buffer.release(); | |
| 247 } | |
| 248 | |
| 249 void CommandBufferService::DestroyGpuMemoryBuffer(int32 id) { | |
| 250 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); | |
| 251 if (it != gpu_memory_buffers_.end()) { | |
| 252 delete it->second; | |
| 253 gpu_memory_buffers_.erase(it); | |
| 254 } | |
| 255 | |
| 256 image_manager_->RemoveImage(id); | |
| 257 } | |
| 258 | |
| 259 gfx::GLImage* CommandBufferService::GetImage(int32 id) { | |
| 260 return image_manager_->LookupImage(id); | |
| 261 } | |
| 262 | |
| 263 bool CommandBufferService::RegisterGpuMemoryBuffer( | |
| 264 int32 id, | |
| 265 gfx::GpuMemoryBufferHandle buffer, | |
| 266 size_t width, | |
| 267 size_t height, | |
| 268 unsigned internalformat) { | |
| 269 if (id <= 0) { | |
| 270 DVLOG(0) << "Cannot register GPU memory buffer with non-positive ID."; | |
| 271 return false; | |
| 272 } | |
| 273 | |
| 274 if (image_manager_->LookupImage(id)) { | |
| 275 DVLOG(0) << "GPU memory buffer ID already in use."; | |
| 276 return false; | |
| 277 } | |
| 278 | |
| 279 scoped_refptr<gfx::GLImage> gl_image = | |
| 280 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer, | |
| 281 gfx::Size(width, height), | |
| 282 internalformat); | |
| 283 if (!gl_image) | |
| 284 return false; | |
| 285 | |
| 286 image_manager_->AddImage(gl_image.get(), id); | |
|
piman
2013/08/01 21:19:30
Mmh, this is the id generated locally for the GpuM
reveman
2013/08/08 23:19:00
Yes, these will conflict but shouldn't be a proble
| |
| 287 return true; | |
| 288 } | |
| 289 | |
| 210 } // namespace gpu | 290 } // namespace gpu |
| OLD | NEW |