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 "../client/gpu_memory_buffer_tracker.h" |
| 6 |
| 7 #include "../client/gles2_implementation.h" |
| 8 #include "../client/gpu_memory_buffer.h" |
| 9 #include "../client/image_factory.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 |
| 12 namespace gpu { |
| 13 namespace gles2 { |
| 14 |
| 15 GpuMemoryBufferTracker::GpuMemoryBufferTracker(ImageFactory* factory) |
| 16 : buffers_(), |
| 17 factory_(factory) { |
| 18 } |
| 19 |
| 20 GpuMemoryBufferTracker::~GpuMemoryBufferTracker() { |
| 21 while (!buffers_.empty()) { |
| 22 RemoveBuffer(buffers_.begin()->first); |
| 23 } |
| 24 } |
| 25 |
| 26 GLuint GpuMemoryBufferTracker::CreateBuffer( |
| 27 GLsizei width, GLsizei height, GLenum internalformat) { |
| 28 GLuint image_id = 0; |
| 29 DCHECK(factory_); |
| 30 scoped_ptr<GpuMemoryBuffer> buffer = |
| 31 factory_->CreateGpuMemoryBuffer(width, height, internalformat, &image_id); |
| 32 |
| 33 std::pair<BufferMap::iterator, bool> result = |
| 34 buffers_.insert(std::make_pair(image_id, buffer.release())); |
| 35 GPU_DCHECK(result.second); |
| 36 |
| 37 return image_id; |
| 38 } |
| 39 |
| 40 GpuMemoryBuffer* GpuMemoryBufferTracker::GetBuffer(GLuint image_id) { |
| 41 BufferMap::iterator it = buffers_.find(image_id); |
| 42 return (it != buffers_.end()) ? it->second : NULL; |
| 43 } |
| 44 |
| 45 void GpuMemoryBufferTracker::RemoveBuffer(GLuint image_id) { |
| 46 BufferMap::iterator buffer_it = buffers_.find(image_id); |
| 47 if (buffer_it != buffers_.end()) { |
| 48 GpuMemoryBuffer* buffer = buffer_it->second; |
| 49 buffers_.erase(buffer_it); |
| 50 delete buffer; |
| 51 } |
| 52 DCHECK(factory_); |
| 53 factory_->DeleteGpuMemoryBuffer(image_id); |
| 54 } |
| 55 |
| 56 } // namespace gles2 |
| 57 } // namespace gpu |
OLD | NEW |