Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gpu/command_buffer/service/gpu_control_service.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" | |
| 9 #include "gpu/command_buffer/service/gpu_memory_buffer_manager.h" | |
| 10 | |
| 11 namespace gpu { | |
| 12 | |
| 13 GpuControlService::GpuControlService( | |
| 14 GpuMemoryBufferManagerInterface* gpu_memory_buffer_manager, | |
| 15 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
| 16 : gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | |
| 17 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | |
| 18 } | |
| 19 | |
| 20 GpuControlService::~GpuControlService() { | |
| 21 } | |
| 22 | |
| 23 gfx::GpuMemoryBuffer* GpuControlService::CreateGpuMemoryBuffer( | |
| 24 size_t width, | |
| 25 size_t height, | |
| 26 unsigned internalformat, | |
| 27 int32* id) { | |
| 28 *id = -1; | |
| 29 | |
| 30 CHECK(gpu_memory_buffer_factory_) << "No GPU memory buffer factory provided"; | |
| 31 scoped_ptr<gfx::GpuMemoryBuffer> buffer = make_scoped_ptr( | |
|
piman
2013/08/13 00:38:24
nit: if you make this a linked_ptr from the start,
reveman
2013/08/13 01:48:26
Done.
| |
| 32 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(width, | |
| 33 height, | |
| 34 internalformat)); | |
| 35 if (!buffer) | |
| 36 return NULL; | |
| 37 | |
| 38 static int32 next_id = 1; | |
| 39 *id = next_id++; | |
| 40 | |
| 41 if (!RegisterGpuMemoryBuffer(*id, | |
| 42 buffer->GetHandle(), | |
| 43 width, | |
| 44 height, | |
| 45 internalformat)) { | |
| 46 *id = -1; | |
| 47 return NULL; | |
| 48 } | |
| 49 | |
| 50 gpu_memory_buffers_[*id].reset(buffer.get()); | |
| 51 return buffer.release(); | |
| 52 } | |
| 53 | |
| 54 void GpuControlService::DestroyGpuMemoryBuffer(int32 id) { | |
| 55 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); | |
| 56 if (it != gpu_memory_buffers_.end()) | |
| 57 gpu_memory_buffers_.erase(it); | |
| 58 | |
| 59 gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id); | |
| 60 } | |
| 61 | |
| 62 bool GpuControlService::RegisterGpuMemoryBuffer( | |
| 63 int32 id, | |
| 64 gfx::GpuMemoryBufferHandle buffer, | |
| 65 size_t width, | |
| 66 size_t height, | |
| 67 unsigned internalformat) { | |
| 68 return gpu_memory_buffer_manager_->RegisterGpuMemoryBuffer(id, | |
| 69 buffer, | |
| 70 width, | |
| 71 height, | |
| 72 internalformat); | |
| 73 } | |
| 74 | |
| 75 } // namespace gpu | |
| OLD | NEW |