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 |