OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/client/offscreen_context.h" |
| 6 |
| 7 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 8 #include "third_party/skia/include/gpu/GrContext.h" |
| 9 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 OffscreenContext::OffscreenContext() {} |
| 14 |
| 15 OffscreenContext::~OffscreenContext() { |
| 16 if (gr_context_) |
| 17 gr_context_->contextDestroyed(); |
| 18 } |
| 19 |
| 20 static void BindWebGraphicsContext3DGLContextCallback( |
| 21 const GrGLInterface* interface) { |
| 22 reinterpret_cast<WebKit::WebGraphicsContext3D*>( |
| 23 interface->fCallbackData)->makeContextCurrent(); |
| 24 } |
| 25 |
| 26 GrContext* OffscreenContext::GrContext() { |
| 27 if (gr_context_) |
| 28 return gr_context_.get(); |
| 29 |
| 30 WebKit::WebGraphicsContext3D* context3d = Context3d(); |
| 31 if (!context3d) |
| 32 return NULL; |
| 33 |
| 34 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef( |
| 35 context3d->createGrGLInterface()); |
| 36 interface->fCallback = BindWebGraphicsContext3DGLContextCallback; |
| 37 interface->fCallbackData = |
| 38 reinterpret_cast<GrGLInterfaceCallbackData>(context3d); |
| 39 |
| 40 gr_context_ = skia::AdoptRef(GrContext::Create( |
| 41 kOpenGL_Shaders_GrEngine, |
| 42 reinterpret_cast<GrPlatform3DContext>(interface.get()))); |
| 43 if (!gr_context_) |
| 44 return NULL; |
| 45 |
| 46 bool nonzero_allocation = true; |
| 47 SetGaneshContextMemoryLimit(nonzero_allocation); |
| 48 return gr_context_.get(); |
| 49 } |
| 50 |
| 51 void OffscreenContext::SetGaneshContextMemoryLimit( |
| 52 bool nonzero_allocation) { |
| 53 if (!gr_context_) |
| 54 return; |
| 55 |
| 56 if (nonzero_allocation) { |
| 57 gr_context_->setTextureCacheLimits( |
| 58 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes); |
| 59 return; |
| 60 } |
| 61 gr_context_->freeGpuResources(); |
| 62 gr_context_->setTextureCacheLimits(0, 0); |
| 63 } |
| 64 |
| 65 void OffscreenContext::DidLoseContext() { |
| 66 if (gr_context_) { |
| 67 gr_context_->contextDestroyed(); |
| 68 gr_context_.clear(); |
| 69 } |
| 70 } |
| 71 |
| 72 } // namespace content |
OLD | NEW |