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/client/gpu_control.h"
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(size_t width
,
30 gfx::GpuMemoryBuffer
* buffer
= gpu_control_
->CreateGpuMemoryBuffer(
31 width
, height
, internalformat
, usage
, &image_id
);
35 std::pair
<BufferMap::iterator
, bool> result
=
36 buffers_
.insert(std::make_pair(image_id
, buffer
));
37 DCHECK(result
.second
);
42 gfx::GpuMemoryBuffer
* GpuMemoryBufferTracker::GetBuffer(int32 image_id
) {
43 BufferMap::iterator it
= buffers_
.find(image_id
);
44 return (it
!= buffers_
.end()) ? it
->second
: NULL
;
47 void GpuMemoryBufferTracker::RemoveBuffer(int32 image_id
) {
48 BufferMap::iterator buffer_it
= buffers_
.find(image_id
);
49 if (buffer_it
!= buffers_
.end())
50 buffers_
.erase(buffer_it
);
52 gpu_control_
->DestroyGpuMemoryBuffer(image_id
);