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

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: Back to a single OffscreenContext class 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/skia/include/gpu/GrContext.h"
8 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
9
10 namespace content {
11
12 OffscreenContext::OffscreenContext(OffscreenContextClient* client)
13 : client_(client) {
14 }
15
16 OffscreenContext::~OffscreenContext() {
17 if (gr_context_)
18 gr_context_->contextDestroyed();
19 if (context3d_) {
20 context3d_->setContextLostCallback(NULL);
21 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
22 }
23 }
24
25 WebKit::WebGraphicsContext3D* OffscreenContext::Context3d() {
26 if (context3d_)
27 return context3d_.get();
28
29 context3d_.reset(client_->CreateOffscreenContext());
30 if (context3d_ &&
31 (!context3d_->makeContextCurrent() ||
32 context3d_->getGraphicsResetStatusARB()))
33 context3d_.reset();
34
35 client_->DidCreateContext(this, !!context3d_);
36 if (!context3d_)
37 return NULL;
38
39 context3d_->setContextLostCallback(this);
40 // TODO(danakj): Talk to the GPU mem manager directly.
41 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
42 return context3d_.get();
43 }
44
45 static void BindWebGraphicsContext3DGLContextCallback(
46 const GrGLInterface* interface) {
47 reinterpret_cast<WebKit::WebGraphicsContext3D*>(
48 interface->fCallbackData)->makeContextCurrent();
49 }
50
51 GrContext* OffscreenContext::GrContext() {
52 if (gr_context_)
53 return gr_context_.get();
54
55 WebKit::WebGraphicsContext3D* context3d = Context3d();
56 if (!context3d)
57 return NULL;
58
59 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
60 context3d->createGrGLInterface());
61 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
62 interface->fCallbackData =
63 reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
64
65 gr_context_ = skia::AdoptRef(GrContext::Create(
66 kOpenGL_Shaders_GrEngine,
67 reinterpret_cast<GrPlatform3DContext>(interface.get())));
68 if (!gr_context_)
69 return NULL;
70
71 bool nonzero_allocation = true;
72 SetGaneshContextMemoryLimit(nonzero_allocation);
73 return gr_context_.get();
74 }
75
76 void OffscreenContext::SetGaneshContextMemoryLimit(
77 bool nonzero_allocation) {
78 if (!gr_context_)
79 return;
80
81 if (nonzero_allocation) {
82 gr_context_->setTextureCacheLimits(
83 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
84 return;
85 }
86 gr_context_->freeGpuResources();
87 gr_context_->setTextureCacheLimits(0, 0);
88 }
89
90 void OffscreenContext::onContextLost() {
91 // Save the contexts until the notifications are done, but requests for a
92 // context should create a new one.
93 scoped_ptr<WebKit::WebGraphicsContext3D> context3d =
94 context3d_.Pass();
95 if (context3d)
96 context3d->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
97
98 skia::RefPtr<class GrContext> gr_context = gr_context_;
99 if (gr_context_) {
100 gr_context_->contextDestroyed();
101 gr_context_.clear();
102 }
103
104 client_->DidLoseContext(this);
105 }
106
107 // WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation.
108 void OffscreenContext::onMemoryAllocationChanged(
109 WebKit::WebGraphicsMemoryAllocation allocation) {
110 SetGaneshContextMemoryLimit(!!allocation.gpuResourceSizeInBytes);
111 }
112
113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698