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(
25 size_t width
, size_t height
, int32 internalformat
) {
28 gfx::GpuMemoryBuffer
* buffer
= gpu_control_
->CreateGpuMemoryBuffer(
29 width
, height
, internalformat
, &image_id
);
33 std::pair
<BufferMap::iterator
, bool> result
=
34 buffers_
.insert(std::make_pair(image_id
, buffer
));
35 DCHECK(result
.second
);
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
);
50 gpu_control_
->DestroyGpuMemoryBuffer(image_id
);