Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: webkit/gpu/grcontext_for_webgraphicscontext3d.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the GrContextProvider::ScopedContexts guard classes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // The limit of the number of textures we hold in the GrContext's
15 // bitmap->texture cache.
16 static const int kMaxGaneshTextureCacheCount = 2048;
17 // The limit of the bytes allocated toward textures in the GrContext's
18 // bitmap->texture cache.
19 static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
20
21 static void BindWebGraphicsContext3DGLContextCallback(
22 const GrGLInterface* interface) {
23 reinterpret_cast<WebKit::WebGraphicsContext3D*>(
24 interface->fCallbackData)->makeContextCurrent();
25 }
26
27 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
28 WebKit::WebGraphicsContext3D* context3d) {
29 if (!context3d)
30 return;
31
32 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
33 context3d->createGrGLInterface());
34 if (!interface)
35 return;
36
37 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
38 interface->fCallbackData =
39 reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
40
41 gr_context_ = skia::AdoptRef(GrContext::Create(
42 kOpenGL_GrBackend,
43 reinterpret_cast<GrBackendContext>(interface.get())));
44 if (!gr_context_)
45 return;
46
47 bool nonzero_allocation = true;
48 SetMemoryLimit(nonzero_allocation);
49 }
50
51 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() {
52 if (gr_context_)
53 gr_context_->contextDestroyed();
54 }
55
56 void GrContextForWebGraphicsContext3D::SetMemoryLimit(bool nonzero_allocation) {
57 if (!gr_context_)
58 return;
59
60 if (nonzero_allocation) {
61 gr_context_->setTextureCacheLimits(
62 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
63 return;
64 }
65 gr_context_->freeGpuResources();
66 gr_context_->setTextureCacheLimits(0, 0);
67 }
68
69 } // namespace gpu
70 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698