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 "webkit/gpu/grcontext_for_webgraphicscontext3d.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 webkit { | |
12 namespace gpu { | |
13 | |
14 static void BindWebGraphicsContext3DGLContextCallback( | |
15 const GrGLInterface* interface) { | |
16 reinterpret_cast<WebKit::WebGraphicsContext3D*>( | |
17 interface->fCallbackData)->makeContextCurrent(); | |
18 } | |
19 | |
20 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D( | |
21 WebKit::WebGraphicsContext3D* context3d) { | |
22 if (!context3d) | |
23 return; | |
24 | |
25 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef( | |
26 context3d->createGrGLInterface()); | |
27 if (!interface) | |
28 return; | |
29 | |
30 interface->fCallback = BindWebGraphicsContext3DGLContextCallback; | |
31 interface->fCallbackData = | |
32 reinterpret_cast<GrGLInterfaceCallbackData>(context3d); | |
33 | |
34 gr_context_ = skia::AdoptRef(GrContext::Create( | |
35 kOpenGL_GrBackend, | |
36 reinterpret_cast<GrBackendContext>(interface.get()))); | |
37 if (!gr_context_) | |
38 return; | |
39 | |
40 bool nonzero_allocation = true; | |
41 SetMemoryLimit(nonzero_allocation); | |
42 } | |
43 | |
44 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() { | |
45 if (gr_context_) | |
46 gr_context_->contextDestroyed(); | |
47 } | |
48 | |
49 void GrContextForWebGraphicsContext3D::SetMemoryLimit(bool nonzero_allocation) { | |
50 if (!gr_context_) | |
51 return; | |
52 | |
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; | |
60 | |
61 gr_context_->setTextureCacheLimits( | |
62 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes); | |
63 } else { | |
64 gr_context_->freeGpuResources(); | |
65 gr_context_->setTextureCacheLimits(0, 0); | |
66 } | |
67 } | |
68 | |
69 } // namespace gpu | |
70 } // namespace webkit | |
OLD | NEW |