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

Unified Diff: content/common/gpu/client/offscreen_context.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: Back to a single OffscreenContext class 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/offscreen_context.cc
diff --git a/content/common/gpu/client/offscreen_context.cc b/content/common/gpu/client/offscreen_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5ab693edf6dbe1d721f1ed44e50bf8572e89a5f8
--- /dev/null
+++ b/content/common/gpu/client/offscreen_context.cc
@@ -0,0 +1,113 @@
+// 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.h"
+
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
+
+namespace content {
+
+OffscreenContext::OffscreenContext(OffscreenContextClient* client)
+ : client_(client) {
+}
+
+OffscreenContext::~OffscreenContext() {
+ if (gr_context_)
+ gr_context_->contextDestroyed();
+ if (context3d_) {
+ context3d_->setContextLostCallback(NULL);
+ context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
+ }
+}
+
+WebKit::WebGraphicsContext3D* OffscreenContext::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();
+}
+
+static void BindWebGraphicsContext3DGLContextCallback(
+ const GrGLInterface* interface) {
+ reinterpret_cast<WebKit::WebGraphicsContext3D*>(
+ interface->fCallbackData)->makeContextCurrent();
+}
+
+GrContext* OffscreenContext::GrContext() {
+ if (gr_context_)
+ return gr_context_.get();
+
+ WebKit::WebGraphicsContext3D* context3d = Context3d();
+ if (!context3d)
+ return NULL;
+
+ skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
+ context3d->createGrGLInterface());
+ interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
+ interface->fCallbackData =
+ reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
+
+ gr_context_ = skia::AdoptRef(GrContext::Create(
+ kOpenGL_Shaders_GrEngine,
+ reinterpret_cast<GrPlatform3DContext>(interface.get())));
+ if (!gr_context_)
+ return NULL;
+
+ bool nonzero_allocation = true;
+ SetGaneshContextMemoryLimit(nonzero_allocation);
+ return gr_context_.get();
+}
+
+void OffscreenContext::SetGaneshContextMemoryLimit(
+ bool nonzero_allocation) {
+ if (!gr_context_)
+ return;
+
+ if (nonzero_allocation) {
+ gr_context_->setTextureCacheLimits(
+ kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
+ return;
+ }
+ gr_context_->freeGpuResources();
+ gr_context_->setTextureCacheLimits(0, 0);
+}
+
+void OffscreenContext::onContextLost() {
+ // Save the contexts until the notifications are done, but requests for a
+ // context should create a new one.
+ scoped_ptr<WebKit::WebGraphicsContext3D> context3d =
+ context3d_.Pass();
+ if (context3d)
+ context3d->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
+
+ skia::RefPtr<class GrContext> gr_context = gr_context_;
+ if (gr_context_) {
+ gr_context_->contextDestroyed();
+ gr_context_.clear();
+ }
+
+ client_->DidLoseContext(this);
+}
+
+// WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation.
+void OffscreenContext::onMemoryAllocationChanged(
+ WebKit::WebGraphicsMemoryAllocation allocation) {
+ SetGaneshContextMemoryLimit(!!allocation.gpuResourceSizeInBytes);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698