Index: gpu/command_buffer/client/gpu_memory_buffer_tracker_in_process.cc |
diff --git a/gpu/command_buffer/client/gpu_memory_buffer_tracker_in_process.cc b/gpu/command_buffer/client/gpu_memory_buffer_tracker_in_process.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a83bc8ff03d5861f0529b61782ecb2ab899b6c5 |
--- /dev/null |
+++ b/gpu/command_buffer/client/gpu_memory_buffer_tracker_in_process.cc |
@@ -0,0 +1,63 @@ |
+// 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_in_process.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 { |
+ |
+GpuMemoryBufferTrackerInProcess::GpuMemoryBufferTrackerInProcess( |
reveman
2013/05/10 02:06:16
Why is this in-process specific? You already have
kaanb
2013/05/13 23:00:36
Removed this file.
|
+ ImageFactory* factory, GLES2Implementation* gl) |
+ : buffers_(), |
+ factory_(factory), |
+ gl_(gl) { |
+} |
+ |
+GpuMemoryBufferTrackerInProcess::~GpuMemoryBufferTrackerInProcess() { |
+ while (!buffers_.empty()) { |
+ RemoveBuffer(buffers_.begin()->first); |
+ } |
+} |
+ |
+GLuint GpuMemoryBufferTrackerInProcess::CreateBuffer(GLsizei width, |
+ GLsizei height) { |
+ // Flush the command stream to make sure all pending commands |
+ // that may refer to the image_id are executed on the service side. |
+ gl_->Flush(); |
no sievers
2013/05/10 01:21:51
Hmm I wonder if the flush here and below should be
kaanb
2013/05/13 23:00:36
Done.
|
+ GLuint image_id = 0; |
+ scoped_ptr<GpuMemoryBuffer> buffer = |
+ factory_->CreateGpuMemoryBuffer(width, height, &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* GpuMemoryBufferTrackerInProcess::GetBuffer(GLuint image_id) { |
+ BufferMap::iterator it = buffers_.find(image_id); |
+ return (it != buffers_.end()) ? it->second : NULL; |
+} |
+ |
+void GpuMemoryBufferTrackerInProcess::RemoveBuffer(GLuint image_id) { |
+ // Flush the command stream to make sure all pending commands |
+ // that may refer to the image_id are executed on the service side. |
+ gl_->Flush(); |
+ BufferMap::iterator buffer_it = buffers_.find(image_id); |
+ if (buffer_it != buffers_.end()) { |
+ GpuMemoryBuffer* buffer = buffer_it->second; |
+ buffers_.erase(buffer_it); |
+ delete buffer; |
+ } |
+ factory_->RemoveFromManager(image_id); |
+} |
+ |
+} // namespace gles2 |
+} // namespace gpu |