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

Side by Side Diff: android_webview/browser/context_provider_in_process.cc

Issue 1083843002: android_webview: Remove dependency on webkit's ContextProviderInProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: it links Created 5 years, 8 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
« no previous file with comments | « android_webview/browser/context_provider_in_process.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/test/in_process_context_provider.h" 5 #include "android_webview/browser/context_provider_in_process.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "cc/output/managed_memory_policy.h" 12 #include "cc/output/managed_memory_policy.h"
13 #include "gpu/command_buffer/client/gl_in_process_context.h" 13 #include "gpu/command_buffer/client/gl_in_process_context.h"
14 #include "gpu/command_buffer/client/gles2_implementation.h" 14 #include "gpu/command_buffer/client/gles2_implementation.h"
15 #include "gpu/command_buffer/client/gles2_lib.h" 15 #include "gpu/command_buffer/client/gles2_lib.h"
16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" 16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
17 #include "third_party/skia/include/gpu/GrContext.h" 17 #include "third_party/skia/include/gpu/GrContext.h"
18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
19 19
20 namespace ui { 20 namespace android_webview {
21 21
22 namespace { 22 namespace {
23 23
24 // Singleton used to initialize and terminate the gles2 library. 24 // Singleton used to initialize and terminate the gles2 library.
25 class GLES2Initializer { 25 class GLES2Initializer {
26 public: 26 public:
27 GLES2Initializer() { gles2::Initialize(); } 27 GLES2Initializer() { gles2::Initialize(); }
28 28
29 ~GLES2Initializer() { gles2::Terminate(); } 29 ~GLES2Initializer() { gles2::Terminate(); }
30 30
31 private: 31 private:
32 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); 32 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
33 }; 33 };
34 34
35 base::LazyInstance<GLES2Initializer> g_gles2_initializer = 35 base::LazyInstance<GLES2Initializer> g_gles2_initializer =
36 LAZY_INSTANCE_INITIALIZER; 36 LAZY_INSTANCE_INITIALIZER;
37 37
38 } // namespace 38 } // namespace
39 39
40 // static 40 // static
41 scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( 41 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create(
tfarina 2015/04/19 02:46:33 Which parameters should I pass here?
boliu 2015/04/19 08:40:07 You can hardcode all of these values I think. Ther
tfarina 2015/04/19 13:29:53 Done.
42 const gpu::gles2::ContextCreationAttribHelper& attribs,
43 bool lose_context_when_out_of_memory,
44 gfx::AcceleratedWidget window,
45 const std::string& debug_name) { 42 const std::string& debug_name) {
46 return new InProcessContextProvider( 43 return new ContextProviderInProcess(debug_name);
47 attribs, lose_context_when_out_of_memory, window, debug_name);
48 } 44 }
49 45
50 // static 46 ContextProviderInProcess::ContextProviderInProcess(
51 scoped_refptr<InProcessContextProvider>
52 InProcessContextProvider::CreateOffscreen(
53 bool lose_context_when_out_of_memory) {
54 gpu::gles2::ContextCreationAttribHelper attribs;
55 attribs.alpha_size = 8;
56 attribs.blue_size = 8;
57 attribs.green_size = 8;
58 attribs.red_size = 8;
59 attribs.depth_size = 0;
60 attribs.stencil_size = 8;
61 attribs.samples = 0;
62 attribs.sample_buffers = 0;
63 attribs.fail_if_major_perf_caveat = false;
64 attribs.bind_generates_resource = false;
65 return new InProcessContextProvider(
66 attribs, lose_context_when_out_of_memory, gfx::kNullAcceleratedWidget,
67 "Offscreen");
68 }
69
70 InProcessContextProvider::InProcessContextProvider(
71 const gpu::gles2::ContextCreationAttribHelper& attribs,
72 bool lose_context_when_out_of_memory,
73 gfx::AcceleratedWidget window,
74 const std::string& debug_name) 47 const std::string& debug_name)
75 : attribs_(attribs), 48 : debug_name_(debug_name),
76 lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
77 window_(window),
78 debug_name_(debug_name),
79 destroyed_(false) { 49 destroyed_(false) {
80 DCHECK(main_thread_checker_.CalledOnValidThread()); 50 DCHECK(main_thread_checker_.CalledOnValidThread());
81 context_thread_checker_.DetachFromThread(); 51 context_thread_checker_.DetachFromThread();
82 } 52 }
83 53
84 InProcessContextProvider::~InProcessContextProvider() { 54 ContextProviderInProcess::~ContextProviderInProcess() {
85 DCHECK(main_thread_checker_.CalledOnValidThread() || 55 DCHECK(main_thread_checker_.CalledOnValidThread() ||
86 context_thread_checker_.CalledOnValidThread()); 56 context_thread_checker_.CalledOnValidThread());
87 } 57 }
88 58
89 bool InProcessContextProvider::BindToCurrentThread() { 59 bool ContextProviderInProcess::BindToCurrentThread() {
90 // This is called on the thread the context will be used. 60 // This is called on the thread the context will be used.
91 DCHECK(context_thread_checker_.CalledOnValidThread()); 61 DCHECK(context_thread_checker_.CalledOnValidThread());
92 62
93 if (!context_) {
94 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
tfarina 2015/04/19 02:46:33 What should goes in, in our implementation?
boliu 2015/04/19 08:40:07 Create a GLInProcessContext and use that directly.
tfarina 2015/04/19 13:29:53 Done.
95 context_.reset(gpu::GLInProcessContext::Create(
96 nullptr, /* service */
97 nullptr, /* surface */
98 !window_, /* is_offscreen */
99 window_, gfx::Size(1, 1), nullptr, /* share_context */
100 true, /* share_resources */
101 attribs_, gpu_preference, gpu::GLInProcessContextSharedMemoryLimits(),
102 nullptr, nullptr));
103
104 if (!context_)
105 return false;
106
107 context_->SetContextLostCallback(base::Bind(
108 &InProcessContextProvider::OnLostContext, base::Unretained(this)));
109 }
110
111 capabilities_.gpu = context_->GetImplementation()->capabilities(); 63 capabilities_.gpu = context_->GetImplementation()->capabilities();
112 64
113 std::string unique_context_name = 65 std::string unique_context_name =
114 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get()); 66 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get());
115 context_->GetImplementation()->TraceBeginCHROMIUM( 67 context_->GetImplementation()->TraceBeginCHROMIUM(
116 "gpu_toplevel", unique_context_name.c_str()); 68 "gpu_toplevel", unique_context_name.c_str());
117 69
118 return true; 70 return true;
119 } 71 }
120 72
121 cc::ContextProvider::Capabilities 73 cc::ContextProvider::Capabilities
122 InProcessContextProvider::ContextCapabilities() { 74 ContextProviderInProcess::ContextCapabilities() {
123 DCHECK(context_thread_checker_.CalledOnValidThread()); 75 DCHECK(context_thread_checker_.CalledOnValidThread());
124 return capabilities_; 76 return capabilities_;
125 } 77 }
126 78
127 gpu::gles2::GLES2Interface* InProcessContextProvider::ContextGL() { 79 gpu::gles2::GLES2Interface* ContextProviderInProcess::ContextGL() {
128 DCHECK(context_thread_checker_.CalledOnValidThread()); 80 DCHECK(context_thread_checker_.CalledOnValidThread());
129 81
130 return context_->GetImplementation(); 82 return context_->GetImplementation();
131 } 83 }
132 84
133 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { 85 gpu::ContextSupport* ContextProviderInProcess::ContextSupport() {
134 DCHECK(context_thread_checker_.CalledOnValidThread()); 86 DCHECK(context_thread_checker_.CalledOnValidThread());
135 87
136 return context_->GetImplementation(); 88 return context_->GetImplementation();
137 } 89 }
138 90
139 static void BindGrContextCallback(const GrGLInterface* interface) { 91 static void BindGrContextCallback(const GrGLInterface* interface) {
140 cc::ContextProvider* context_provider = 92 cc::ContextProvider* context_provider =
141 reinterpret_cast<InProcessContextProvider*>(interface->fCallbackData); 93 reinterpret_cast<ContextProviderInProcess*>(interface->fCallbackData);
142 94
143 gles2::SetGLContext(context_provider->ContextGL()); 95 gles2::SetGLContext(context_provider->ContextGL());
144 } 96 }
145 97
146 class GrContext* InProcessContextProvider::GrContext() { 98 class GrContext* ContextProviderInProcess::GrContext() {
147 DCHECK(context_thread_checker_.CalledOnValidThread()); 99 DCHECK(context_thread_checker_.CalledOnValidThread());
148 100
149 if (gr_context_) 101 if (gr_context_)
150 return gr_context_.get(); 102 return gr_context_.get();
151 103
152 // The GrGLInterface factory will make GL calls using the C GLES2 interface. 104 // The GrGLInterface factory will make GL calls using the C GLES2 interface.
153 // Make sure the gles2 library is initialized first on exactly one thread. 105 // Make sure the gles2 library is initialized first on exactly one thread.
154 g_gles2_initializer.Get(); 106 g_gles2_initializer.Get();
155 gles2::SetGLContext(ContextGL()); 107 gles2::SetGLContext(ContextGL());
156 108
157 skia::RefPtr<GrGLInterface> interface = 109 skia::RefPtr<GrGLInterface> interface =
158 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding()); 110 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
159 interface->fCallback = BindGrContextCallback; 111 interface->fCallback = BindGrContextCallback;
160 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); 112 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
161 113
162 gr_context_ = skia::AdoptRef(GrContext::Create( 114 gr_context_ = skia::AdoptRef(GrContext::Create(
163 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); 115 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
164 116
165 return gr_context_.get(); 117 return gr_context_.get();
166 } 118 }
167 119
168 void InProcessContextProvider::SetupLock() { 120 void ContextProviderInProcess::SetupLock() {
169 } 121 }
170 122
171 base::Lock* InProcessContextProvider::GetLock() { 123 base::Lock* ContextProviderInProcess::GetLock() {
172 return &context_lock_; 124 return &context_lock_;
173 } 125 }
174 126
175 bool InProcessContextProvider::IsContextLost() { 127 bool ContextProviderInProcess::IsContextLost() {
176 DCHECK(context_thread_checker_.CalledOnValidThread()); 128 DCHECK(context_thread_checker_.CalledOnValidThread());
177 129
178 base::AutoLock lock(destroyed_lock_); 130 base::AutoLock lock(destroyed_lock_);
179 return destroyed_; 131 return destroyed_;
180 } 132 }
181 133
182 void InProcessContextProvider::VerifyContexts() { 134 void ContextProviderInProcess::VerifyContexts() {
183 } 135 }
184 136
185 void InProcessContextProvider::DeleteCachedResources() { 137 void ContextProviderInProcess::DeleteCachedResources() {
186 DCHECK(context_thread_checker_.CalledOnValidThread()); 138 DCHECK(context_thread_checker_.CalledOnValidThread());
187 139
188 if (gr_context_) { 140 if (gr_context_) {
189 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", 141 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources",
190 TRACE_EVENT_SCOPE_THREAD); 142 TRACE_EVENT_SCOPE_THREAD);
191 gr_context_->freeGpuResources(); 143 gr_context_->freeGpuResources();
192 } 144 }
193 } 145 }
194 146
195 bool InProcessContextProvider::DestroyedOnMainThread() { 147 bool ContextProviderInProcess::DestroyedOnMainThread() {
196 DCHECK(main_thread_checker_.CalledOnValidThread()); 148 DCHECK(main_thread_checker_.CalledOnValidThread());
197 149
198 base::AutoLock lock(destroyed_lock_); 150 base::AutoLock lock(destroyed_lock_);
199 return destroyed_; 151 return destroyed_;
200 } 152 }
201 153
202 void InProcessContextProvider::SetLostContextCallback( 154 void ContextProviderInProcess::SetLostContextCallback(
203 const LostContextCallback& lost_context_callback) { 155 const LostContextCallback& lost_context_callback) {
204 lost_context_callback_ = lost_context_callback; 156 lost_context_callback_ = lost_context_callback;
205 } 157 }
206 158
207 void InProcessContextProvider::SetMemoryPolicyChangedCallback( 159 void ContextProviderInProcess::SetMemoryPolicyChangedCallback(
208 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { 160 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
209 // There's no memory manager for the in-process implementation. 161 // There's no memory manager for the in-process implementation.
210 } 162 }
211 163
212 void InProcessContextProvider::OnLostContext() { 164 void ContextProviderInProcess::OnLostContext() {
213 DCHECK(context_thread_checker_.CalledOnValidThread()); 165 DCHECK(context_thread_checker_.CalledOnValidThread());
214 { 166 {
215 base::AutoLock lock(destroyed_lock_); 167 base::AutoLock lock(destroyed_lock_);
216 if (destroyed_) 168 if (destroyed_)
217 return; 169 return;
218 destroyed_ = true; 170 destroyed_ = true;
219 } 171 }
220 if (!lost_context_callback_.is_null()) 172 if (!lost_context_callback_.is_null())
221 base::ResetAndReturn(&lost_context_callback_).Run(); 173 base::ResetAndReturn(&lost_context_callback_).Run();
222 if (gr_context_) 174 if (gr_context_)
223 gr_context_->abandonContext(); 175 gr_context_->abandonContext();
224 } 176 }
225 177
226 } // namespace ui 178 } // namespace ui
OLDNEW
« no previous file with comments | « android_webview/browser/context_provider_in_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698