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

Side by Side Diff: content/common/gpu/client/offscreen_context.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: Put OffscreenContext class in content/common/gpu/client for renderer 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 "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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698