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

Unified Diff: content/common/gpu/client/context_provider_command_buffer.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 10 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
Index: content/common/gpu/client/context_provider_command_buffer.cc
diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..76141e4a5b136d9d6cbcc439b617255df1ffbbd0
--- /dev/null
+++ b/content/common/gpu/client/context_provider_command_buffer.cc
@@ -0,0 +1,107 @@
+// 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/context_provider_command_buffer.h"
+
+#include "webkit/gpu/grcontext_for_webgraphicscontext3d.h"
+
+namespace content {
+
+class ContextProviderCommandBuffer::LostContextCallbackProxy
+ : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
+ public:
+ LostContextCallbackProxy(ContextProviderCommandBuffer* provider)
+ : provider_(provider) {
+ provider_->context3d_->setContextLostCallback(this);
+ }
+
+ virtual void onContextLost() {
+ provider_->OnLostContext();
+ }
+
+ private:
+ ContextProviderCommandBuffer* provider_;
+};
+
+class ContextProviderCommandBuffer::MemoryAllocationCallbackProxy
+ : public WebKit::WebGraphicsContext3D::
+ WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
+ public:
+ MemoryAllocationCallbackProxy(ContextProviderCommandBuffer* provider)
+ : provider_(provider) {
+ provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
+ }
+
+ void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation alloc) {
+ provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes);
+ }
+
+ private:
+ ContextProviderCommandBuffer* provider_;
+};
+
+ContextProviderCommandBuffer::ContextProviderCommandBuffer()
+ : destroyed_(false) {
+}
+
+ContextProviderCommandBuffer::~ContextProviderCommandBuffer() {}
+
+bool ContextProviderCommandBuffer::InitializeOnMainThread() {
+ if (destroyed_)
+ return false;
+ if (context3d_)
+ return true;
+
+ context3d_ = CreateOffscreenContext3d().Pass();
+ destroyed_ = !context3d_;
+ return !!context3d_;
+}
+
+bool ContextProviderCommandBuffer::BindToCurrentThread() {
+ if (lost_context_callback_proxy_)
+ return true;
+
+ bool result = context3d_->makeContextCurrent();
+ lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
+ return result;
+}
+
+WebGraphicsContext3DCommandBufferImpl*
+ContextProviderCommandBuffer::Context3d() {
+ return context3d_.get();
+}
+
+class GrContext* ContextProviderCommandBuffer::GrContext() {
+ if (gr_context_)
+ return gr_context_->get();
+
+ gr_context_.reset(
+ new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
+ memory_allocation_callback_proxy_.reset(
+ new MemoryAllocationCallbackProxy(this));
+ return gr_context_->get();
+}
+
+void ContextProviderCommandBuffer::VerifyContexts() {
+ if (!destroyed_ && context3d_->isContextLost())
+ OnLostContext();
+}
+
+void ContextProviderCommandBuffer::OnLostContext() {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+}
+
+bool ContextProviderCommandBuffer::DestroyedOnMainThread() {
+ base::AutoLock lock(destroyed_lock_);
+ return destroyed_;
+}
+
+void ContextProviderCommandBuffer::OnMemoryAllocationChanged(
+ bool nonzero_allocation) {
+ if (gr_context_)
+ gr_context_->SetMemoryLimit(nonzero_allocation);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698