Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: gpu/command_buffer/client/gpu_memory_buffer_tracker.cc

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Add missing parameter in GLES2Implementation ctor in GLES2Implementation unittest Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/client/gpu_memory_buffer_tracker.h ('k') | gpu/command_buffer/client/image_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/gpu_memory_buffer_tracker.cc
diff --git a/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc b/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b336796edb06109a8a992b39b9b55721c71763ce
--- /dev/null
+++ b/gpu/command_buffer/client/gpu_memory_buffer_tracker.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "../client/gpu_memory_buffer_tracker.h"
+
+#include "../client/gles2_implementation.h"
+#include "../client/gpu_memory_buffer.h"
+#include "../client/image_factory.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace gpu {
+namespace gles2 {
+
+GpuMemoryBufferTracker::GpuMemoryBufferTracker(ImageFactory* factory)
+ : buffers_(),
+ factory_(factory) {
+}
+
+GpuMemoryBufferTracker::~GpuMemoryBufferTracker() {
+ while (!buffers_.empty()) {
+ RemoveBuffer(buffers_.begin()->first);
+ }
+}
+
+GLuint GpuMemoryBufferTracker::CreateBuffer(
+ GLsizei width, GLsizei height, GLenum internalformat) {
+ GLuint image_id = 0;
+ DCHECK(factory_);
+ scoped_ptr<GpuMemoryBuffer> buffer =
+ factory_->CreateGpuMemoryBuffer(width, height, internalformat, &image_id);
+
+ std::pair<BufferMap::iterator, bool> result =
+ buffers_.insert(std::make_pair(image_id, buffer.release()));
+ GPU_DCHECK(result.second);
+
+ return image_id;
+}
+
+GpuMemoryBuffer* GpuMemoryBufferTracker::GetBuffer(GLuint image_id) {
+ BufferMap::iterator it = buffers_.find(image_id);
+ return (it != buffers_.end()) ? it->second : NULL;
+}
+
+void GpuMemoryBufferTracker::RemoveBuffer(GLuint image_id) {
+ BufferMap::iterator buffer_it = buffers_.find(image_id);
+ if (buffer_it != buffers_.end()) {
+ GpuMemoryBuffer* buffer = buffer_it->second;
+ buffers_.erase(buffer_it);
+ delete buffer;
+ }
+ DCHECK(factory_);
+ factory_->DeleteGpuMemoryBuffer(image_id);
+}
+
+} // namespace gles2
+} // namespace gpu
« no previous file with comments | « gpu/command_buffer/client/gpu_memory_buffer_tracker.h ('k') | gpu/command_buffer/client/image_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698