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.
5 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
7 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
8 #include "third_party/skia/include/gpu/GrContext.h"
9 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
14 static void BindWebGraphicsContext3DGLContextCallback(
15 const GrGLInterface* interface) {
16 reinterpret_cast<WebKit::WebGraphicsContext3D*>(
17 interface->fCallbackData)->makeContextCurrent();
20 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
21 WebKit::WebGraphicsContext3D* context3d) {
25 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
26 context3d->createGrGLInterface());
30 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
31 interface->fCallbackData =
32 reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
34 gr_context_ = skia::AdoptRef(GrContext::Create(
36 reinterpret_cast<GrBackendContext>(interface.get())));
40 bool nonzero_allocation = true;
41 SetMemoryLimit(nonzero_allocation);
44 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() {
46 gr_context_->contextDestroyed();
49 void GrContextForWebGraphicsContext3D::SetMemoryLimit(bool nonzero_allocation) {
53 if (nonzero_allocation) {
54 // The limit of the number of textures we hold in the GrContext's
55 // bitmap->texture cache.
56 static const int kMaxGaneshTextureCacheCount = 2048;
57 // The limit of the bytes allocated toward textures in the GrContext's
58 // bitmap->texture cache.
59 static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
61 gr_context_->setTextureCacheLimits(
62 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
64 gr_context_->freeGpuResources();
65 gr_context_->setTextureCacheLimits(0, 0);