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

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: Put OffscreenContext class in content/common/gpu/client for renderer 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..46c222ff961fda7d2ff7b5007124e845141a56a9
--- /dev/null
+++ b/content/common/gpu/client/offscreen_context.cc
@@ -0,0 +1,72 @@
+// 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/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
+
+namespace content {
+
+OffscreenContext::OffscreenContext() {}
+
+OffscreenContext::~OffscreenContext() {
+ if (gr_context_)
+ gr_context_->contextDestroyed();
+}
+
+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::DidLoseContext() {
+ if (gr_context_) {
+ gr_context_->contextDestroyed();
+ gr_context_.clear();
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698