cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / gpu / command_buffer / client / gpu_memory_buffer_tracker.cc
bloba957cc4b8dc9cbcd274b4d91c567d74334014d1b
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.
5 #include "gpu/command_buffer/client/gpu_memory_buffer_tracker.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/command_buffer/client/gles2_implementation.h"
9 #include "gpu/command_buffer/common/gpu_control.h"
11 namespace gpu {
12 namespace gles2 {
14 GpuMemoryBufferTracker::GpuMemoryBufferTracker(GpuControl* gpu_control)
15 : gpu_control_(gpu_control) {
18 GpuMemoryBufferTracker::~GpuMemoryBufferTracker() {
19 while (!buffers_.empty()) {
20 RemoveBuffer(buffers_.begin()->first);
24 int32 GpuMemoryBufferTracker::CreateBuffer(
25 size_t width, size_t height, int32 internalformat) {
26 int32 image_id = 0;
27 DCHECK(gpu_control_);
28 gfx::GpuMemoryBuffer* buffer = gpu_control_->CreateGpuMemoryBuffer(
29 width, height, internalformat, &image_id);
30 if (!buffer)
31 return 0;
33 std::pair<BufferMap::iterator, bool> result =
34 buffers_.insert(std::make_pair(image_id, buffer));
35 GPU_DCHECK(result.second);
37 return image_id;
40 gfx::GpuMemoryBuffer* GpuMemoryBufferTracker::GetBuffer(int32 image_id) {
41 BufferMap::iterator it = buffers_.find(image_id);
42 return (it != buffers_.end()) ? it->second : NULL;
45 void GpuMemoryBufferTracker::RemoveBuffer(int32 image_id) {
46 BufferMap::iterator buffer_it = buffers_.find(image_id);
47 if (buffer_it != buffers_.end())
48 buffers_.erase(buffer_it);
49 DCHECK(gpu_control_);
50 gpu_control_->DestroyGpuMemoryBuffer(image_id);
53 } // namespace gles2
54 } // namespace gpu