Index: content/common/gpu/client/offscreen_context_command_buffer.cc |
diff --git a/content/common/gpu/client/offscreen_context_command_buffer.cc b/content/common/gpu/client/offscreen_context_command_buffer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..166b2d9db9d78ddd2afeef6f72137636eb1d3c19 |
--- /dev/null |
+++ b/content/common/gpu/client/offscreen_context_command_buffer.cc |
@@ -0,0 +1,62 @@ |
+// 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 "content/common/gpu/client/offscreen_context_command_buffer.h" |
+ |
+namespace content { |
+ |
+OffscreenContextCommandBuffer::OffscreenContextCommandBuffer( |
+ OffscreenContextCommandBufferClient* client) |
+ : client_(client) { |
+} |
+ |
+OffscreenContextCommandBuffer::~OffscreenContextCommandBuffer() { |
+ if (context3d_) { |
+ context3d_->setContextLostCallback(NULL); |
+ context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
+ } |
+} |
+ |
+WebGraphicsContext3DCommandBufferImpl* OffscreenContextCommandBuffer:: |
+ Context3d() { |
+ if (context3d_) |
+ return context3d_.get(); |
+ |
+ context3d_.reset(client_->CreateOffscreenContext()); |
+ if (context3d_ && |
+ (!context3d_->makeContextCurrent() || |
+ context3d_->getGraphicsResetStatusARB())) |
+ context3d_.reset(); |
+ |
+ client_->DidCreateContext(this, !!context3d_); |
+ if (!context3d_) |
+ return NULL; |
+ |
+ context3d_->setContextLostCallback(this); |
+ // TODO(danakj): Talk to the GPU mem manager directly. |
+ context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); |
+ return context3d_.get(); |
+} |
+ |
+void OffscreenContextCommandBuffer::onContextLost() { |
+ // Save the context3d until the notifications are done, but requests for a |
+ // context should create a new one. |
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d = |
+ context3d_.Pass(); |
+ if (context3d) |
+ context3d->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
+ |
+ // Inform the superclass. |
+ DidLoseContext(); |
+ |
+ client_->DidLoseContext(this); |
+} |
+ |
+// WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation. |
+void OffscreenContextCommandBuffer::onMemoryAllocationChanged( |
+ WebKit::WebGraphicsMemoryAllocation allocation) { |
+ SetGaneshContextMemoryLimit(!!allocation.gpuResourceSizeInBytes); |
+} |
+ |
+} // namespace content |