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 "base/debug/trace_event.h"
8 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
9 #include "third_party/skia/include/gpu/GrContext.h"
10 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
15 static void BindWebGraphicsContext3DGLContextCallback(
16 const GrGLInterface* interface) {
17 reinterpret_cast<blink::WebGraphicsContext3D*>(
18 interface->fCallbackData)->makeContextCurrent();
21 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
22 blink::WebGraphicsContext3D* context3d) {
26 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
27 context3d->createGrGLInterface());
31 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
32 interface->fCallbackData =
33 reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
35 gr_context_ = skia::AdoptRef(GrContext::Create(
37 reinterpret_cast<GrBackendContext>(interface.get())));
39 // The limit of the number of textures we hold in the GrContext's
40 // bitmap->texture cache.
41 static const int kMaxGaneshTextureCacheCount = 2048;
42 // The limit of the bytes allocated toward textures in the GrContext's
43 // bitmap->texture cache.
44 static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
46 gr_context_->setTextureCacheLimits(kMaxGaneshTextureCacheCount,
47 kMaxGaneshTextureCacheBytes);
51 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() {
54 void GrContextForWebGraphicsContext3D::OnLostContext() {
56 gr_context_->contextDestroyed();
59 void GrContextForWebGraphicsContext3D::FreeGpuResources() {
61 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", \
62 TRACE_EVENT_SCOPE_THREAD);
63 gr_context_->freeGpuResources();