Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webkit/common/gpu/context_provider_in_process.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/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "cc/output/managed_memory_policy.h" | 10 #include "cc/output/managed_memory_policy.h" |
| 11 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 11 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 12 #include "gpu/command_buffer/client/gles2_implementation.h" | 12 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 13 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | 13 #include "third_party/skia/include/gpu/GrContext.h" |
| 14 #include "third_party/skia/include/gpu/gl/SkNullGLContext.h" | |
| 14 | 15 |
| 15 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; | 16 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 16 | 17 |
| 17 namespace webkit { | 18 namespace android_webview { |
| 18 namespace gpu { | |
| 19 | 19 |
| 20 class ContextProviderInProcess::LostContextCallbackProxy | 20 class ContextProviderInProcess::LostContextCallbackProxy |
| 21 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 21 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 22 public: | 22 public: |
| 23 explicit LostContextCallbackProxy(ContextProviderInProcess* provider) | 23 explicit LostContextCallbackProxy(ContextProviderInProcess* provider) |
| 24 : provider_(provider) { | 24 : provider_(provider) { |
| 25 provider_->context3d_->setContextLostCallback(this); | 25 provider_->context3d_->setContextLostCallback(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual ~LostContextCallbackProxy() { | 28 virtual ~LostContextCallbackProxy() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( | 41 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( |
| 42 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d, | 42 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d, |
| 43 const std::string& debug_name) { | 43 const std::string& debug_name) { |
| 44 if (!context3d) | 44 if (!context3d) |
| 45 return NULL; | 45 return NULL; |
| 46 return new ContextProviderInProcess(context3d.Pass(), debug_name); | 46 return new ContextProviderInProcess(context3d.Pass(), debug_name); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // static | |
| 50 scoped_refptr<ContextProviderInProcess> | |
| 51 ContextProviderInProcess::CreateOffscreen( | |
| 52 bool lose_context_when_out_of_memory) { | |
| 53 blink::WebGraphicsContext3D::Attributes attributes; | |
| 54 attributes.depth = false; | |
| 55 attributes.stencil = true; | |
| 56 attributes.antialias = false; | |
| 57 attributes.shareResources = true; | |
| 58 attributes.noAutomaticFlushes = true; | |
| 59 | |
| 60 return Create( | |
| 61 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | |
| 62 attributes, lose_context_when_out_of_memory), | |
| 63 "Offscreen"); | |
| 64 } | |
| 65 | |
| 66 ContextProviderInProcess::ContextProviderInProcess( | 49 ContextProviderInProcess::ContextProviderInProcess( |
| 67 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d, | 50 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d, |
| 68 const std::string& debug_name) | 51 const std::string& debug_name) |
| 69 : context3d_(context3d.Pass()), | 52 : context3d_(context3d.Pass()), |
| 70 destroyed_(false), | 53 destroyed_(false), |
| 71 debug_name_(debug_name) { | 54 debug_name_(debug_name) { |
| 72 DCHECK(main_thread_checker_.CalledOnValidThread()); | 55 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 73 DCHECK(context3d_); | 56 DCHECK(context3d_); |
| 74 context_thread_checker_.DetachFromThread(); | 57 context_thread_checker_.DetachFromThread(); |
| 75 } | 58 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 DCHECK(context_thread_checker_.CalledOnValidThread()); | 130 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 148 | 131 |
| 149 return context3d_->GetContextSupport(); | 132 return context3d_->GetContextSupport(); |
| 150 } | 133 } |
| 151 | 134 |
| 152 class GrContext* ContextProviderInProcess::GrContext() { | 135 class GrContext* ContextProviderInProcess::GrContext() { |
| 153 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 136 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 154 DCHECK(context_thread_checker_.CalledOnValidThread()); | 137 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 155 | 138 |
| 156 if (gr_context_) | 139 if (gr_context_) |
| 157 return gr_context_->get(); | 140 return gr_context_.get(); |
| 158 | 141 |
| 159 gr_context_.reset(new GrContextForWebGraphicsContext3D(context3d_.get())); | 142 skia::RefPtr<class SkGLContext> gl_context = |
|
tfarina
2015/04/13 22:52:28
I copied this from cc/test/test_context_provide.cc
boliu
2015/04/14 00:29:52
You are creating a *new* context for GrContext, bu
| |
| 160 return gr_context_->get(); | 143 skia::AdoptRef(SkNullGLContext::Create(kNone_GrGLStandard)); |
| 144 gl_context->makeCurrent(); | |
| 145 gr_context_ = skia::AdoptRef(GrContext::Create( | |
| 146 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(gl_context->gl()))); | |
| 147 | |
| 148 // If GlContext is already lost, also abandon the new GrContext. | |
| 149 if (IsContextLost()) | |
| 150 gr_context_->abandonContext(); | |
| 151 | |
| 152 return gr_context_.get(); | |
| 161 } | 153 } |
| 162 | 154 |
| 163 void ContextProviderInProcess::SetupLock() { | 155 void ContextProviderInProcess::SetupLock() { |
| 164 context3d_->SetLock(&context_lock_); | 156 context3d_->SetLock(&context_lock_); |
| 165 } | 157 } |
| 166 | 158 |
| 167 base::Lock* ContextProviderInProcess::GetLock() { | 159 base::Lock* ContextProviderInProcess::GetLock() { |
| 168 return &context_lock_; | 160 return &context_lock_; |
| 169 } | 161 } |
| 170 | 162 |
| 171 bool ContextProviderInProcess::IsContextLost() { | 163 bool ContextProviderInProcess::IsContextLost() { |
| 172 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 164 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 173 DCHECK(context_thread_checker_.CalledOnValidThread()); | 165 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 174 | 166 |
| 175 return context3d_->isContextLost(); | 167 return context3d_->isContextLost(); |
| 176 } | 168 } |
| 177 | 169 |
| 178 void ContextProviderInProcess::VerifyContexts() { | 170 void ContextProviderInProcess::VerifyContexts() { |
| 179 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 171 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 180 DCHECK(context_thread_checker_.CalledOnValidThread()); | 172 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 181 | 173 |
| 182 if (context3d_->isContextLost()) | 174 if (context3d_->isContextLost()) |
| 183 OnLostContext(); | 175 OnLostContext(); |
| 184 } | 176 } |
| 185 | 177 |
| 186 void ContextProviderInProcess::DeleteCachedResources() { | 178 void ContextProviderInProcess::DeleteCachedResources() { |
| 187 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 188 | |
| 189 if (gr_context_) | |
| 190 gr_context_->FreeGpuResources(); | |
| 191 } | 179 } |
| 192 | 180 |
| 193 void ContextProviderInProcess::OnLostContext() { | 181 void ContextProviderInProcess::OnLostContext() { |
| 194 DCHECK(context_thread_checker_.CalledOnValidThread()); | 182 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 195 { | 183 { |
| 196 base::AutoLock lock(destroyed_lock_); | 184 base::AutoLock lock(destroyed_lock_); |
| 197 if (destroyed_) | 185 if (destroyed_) |
| 198 return; | 186 return; |
| 199 destroyed_ = true; | 187 destroyed_ = true; |
| 200 } | 188 } |
| 201 if (!lost_context_callback_.is_null()) | 189 if (!lost_context_callback_.is_null()) |
| 202 base::ResetAndReturn(&lost_context_callback_).Run(); | 190 base::ResetAndReturn(&lost_context_callback_).Run(); |
| 203 if (gr_context_) | 191 if (gr_context_) |
| 204 gr_context_->OnLostContext(); | 192 gr_context_->abandonContext(); |
| 205 } | 193 } |
| 206 | 194 |
| 207 bool ContextProviderInProcess::DestroyedOnMainThread() { | 195 bool ContextProviderInProcess::DestroyedOnMainThread() { |
| 208 DCHECK(main_thread_checker_.CalledOnValidThread()); | 196 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 209 | 197 |
| 210 base::AutoLock lock(destroyed_lock_); | 198 base::AutoLock lock(destroyed_lock_); |
| 211 return destroyed_; | 199 return destroyed_; |
| 212 } | 200 } |
| 213 | 201 |
| 214 void ContextProviderInProcess::SetLostContextCallback( | 202 void ContextProviderInProcess::SetLostContextCallback( |
| 215 const LostContextCallback& lost_context_callback) { | 203 const LostContextCallback& lost_context_callback) { |
| 216 DCHECK(context_thread_checker_.CalledOnValidThread()); | 204 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 217 DCHECK(lost_context_callback_.is_null() || | 205 DCHECK(lost_context_callback_.is_null() || |
| 218 lost_context_callback.is_null()); | 206 lost_context_callback.is_null()); |
| 219 lost_context_callback_ = lost_context_callback; | 207 lost_context_callback_ = lost_context_callback; |
| 220 } | 208 } |
| 221 | 209 |
| 222 void ContextProviderInProcess::SetMemoryPolicyChangedCallback( | 210 void ContextProviderInProcess::SetMemoryPolicyChangedCallback( |
| 223 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 211 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
| 224 // There's no memory manager for the in-process implementation. | 212 // There's no memory manager for the in-process implementation. |
| 225 } | 213 } |
| 226 | 214 |
| 227 } // namespace gpu | 215 } // namespace android_webview |
| 228 } // namespace webkit | |
| OLD | NEW |