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

Side by Side Diff: ui/compositor/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: add cc::GaneshResourceProvider 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 "ui/compositor/offscreen_context.h"
6
7 #include "third_party/skia/include/gpu/GrContext.h"
8 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
9 #include "ui/compositor/compositor.h"
10
11 namespace ui {
12
13 OffscreenContext::OffscreenContext(
14 ContextFactory* context_factory,
15 OffscreenContextClient* client)
16 : context_factory_(context_factory),
17 client_(client) {
18 }
19
20 OffscreenContext::~OffscreenContext() {
21 if (context3d_)
22 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
23 if (gr_context_)
24 gr_context_->contextDestroyed();
25 }
26
27 WebKit::WebGraphicsContext3D* OffscreenContext::Context3d() {
28 if (context3d_)
29 return context3d_.get();
30
31 context3d_.reset(context_factory_->CreateOffscreenContext());
32 if (context3d_ &&
33 (!context3d_->makeContextCurrent() ||
34 context3d_->getGraphicsResetStatusARB()))
35 context3d_.reset();
36
37 DidCreateContext(!!context3d_);
38 if (!context3d_)
39 return NULL;
40
41 context3d_->setContextLostCallback(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 if (!context3d_)
55 return NULL;
56
57 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
58 context3d_->createGrGLInterface());
59 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
60 interface->fCallbackData =
61 reinterpret_cast<GrGLInterfaceCallbackData>(context3d_.get());
62
63 gr_context_ = skia::AdoptRef(GrContext::Create(
64 kOpenGL_Shaders_GrEngine,
65 reinterpret_cast<GrPlatform3DContext>(interface.get())));
66 if (!gr_context_)
67 return NULL;
68
69 gr_context_->setTextureCacheLimits(
70 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
71 return gr_context_.get();
72 }
73
74 void OffscreenContext::DidCreateContext(bool success) {
75 client_->DidCreateContext(this, success);
76 }
77
78 void OffscreenContext::onContextLost() {
79 if (context3d_) {
80 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
81 }
82 scoped_ptr<WebKit::WebGraphicsContext3D> context3d = context3d_.Pass();
83
84 skia::RefPtr<class GrContext> gr_context = gr_context_;
85 if (gr_context_) {
86 gr_context_->contextDestroyed();
87 gr_context_.clear();
88 }
89
90 client_->DidLoseContext(this);
91 }
92
93 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698