Chromium Code Reviews| Index: android_webview/browser/context_provider_in_process.cc |
| diff --git a/ui/compositor/test/in_process_context_provider.cc b/android_webview/browser/context_provider_in_process.cc |
| similarity index 61% |
| copy from ui/compositor/test/in_process_context_provider.cc |
| copy to android_webview/browser/context_provider_in_process.cc |
| index d59736ff86d2730a1cf6cb39897fe317b73bd4f4..43a9b5d5879f16b378643df200a4a2bddd9ca0b3 100644 |
| --- a/ui/compositor/test/in_process_context_provider.cc |
| +++ b/android_webview/browser/context_provider_in_process.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ui/compositor/test/in_process_context_provider.h" |
| +#include "android_webview/browser/context_provider_in_process.h" |
| #include "base/bind.h" |
| #include "base/callback_helpers.h" |
| @@ -10,6 +10,7 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/trace_event/trace_event.h" |
| #include "cc/output/managed_memory_policy.h" |
| +#include "gpu/blink/webgraphicscontext3d_impl.h" |
| #include "gpu/command_buffer/client/gl_in_process_context.h" |
| #include "gpu/command_buffer/client/gles2_implementation.h" |
| #include "gpu/command_buffer/client/gles2_lib.h" |
| @@ -17,7 +18,7 @@ |
| #include "third_party/skia/include/gpu/GrContext.h" |
| #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| -namespace ui { |
| +namespace android_webview { |
| namespace { |
| @@ -38,74 +39,65 @@ base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
| } // namespace |
| // static |
| -scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( |
| - const gpu::gles2::ContextCreationAttribHelper& attribs, |
| - bool lose_context_when_out_of_memory, |
| - gfx::AcceleratedWidget window, |
| +scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( |
| + scoped_refptr<gfx::GLSurface> surface, |
| + scoped_refptr<gpu::InProcessCommandBuffer::Service> service, |
| const std::string& debug_name) { |
| - return new InProcessContextProvider( |
| - attribs, lose_context_when_out_of_memory, window, debug_name); |
| + return new ContextProviderInProcess(surface, service, debug_name); |
| } |
| -// static |
| -scoped_refptr<InProcessContextProvider> |
| -InProcessContextProvider::CreateOffscreen( |
| - bool lose_context_when_out_of_memory) { |
| - gpu::gles2::ContextCreationAttribHelper attribs; |
| - attribs.alpha_size = 8; |
| - attribs.blue_size = 8; |
| - attribs.green_size = 8; |
| - attribs.red_size = 8; |
| - attribs.depth_size = 0; |
| - attribs.stencil_size = 8; |
| - attribs.samples = 0; |
| - attribs.sample_buffers = 0; |
| - attribs.fail_if_major_perf_caveat = false; |
| - attribs.bind_generates_resource = false; |
| - return new InProcessContextProvider( |
| - attribs, lose_context_when_out_of_memory, gfx::kNullAcceleratedWidget, |
| - "Offscreen"); |
| -} |
| - |
| -InProcessContextProvider::InProcessContextProvider( |
| - const gpu::gles2::ContextCreationAttribHelper& attribs, |
| - bool lose_context_when_out_of_memory, |
| - gfx::AcceleratedWidget window, |
| +ContextProviderInProcess::ContextProviderInProcess( |
| + scoped_refptr<gfx::GLSurface> surface, |
| + scoped_refptr<gpu::InProcessCommandBuffer::Service> service, |
| const std::string& debug_name) |
| - : attribs_(attribs), |
| - lose_context_when_out_of_memory_(lose_context_when_out_of_memory), |
| - window_(window), |
| + : surface_(surface), |
| + service_(service), |
| debug_name_(debug_name), |
| destroyed_(false) { |
| DCHECK(main_thread_checker_.CalledOnValidThread()); |
| context_thread_checker_.DetachFromThread(); |
| } |
| -InProcessContextProvider::~InProcessContextProvider() { |
| +ContextProviderInProcess::~ContextProviderInProcess() { |
| DCHECK(main_thread_checker_.CalledOnValidThread() || |
| context_thread_checker_.CalledOnValidThread()); |
| } |
| -bool InProcessContextProvider::BindToCurrentThread() { |
| +bool ContextProviderInProcess::BindToCurrentThread() { |
| // This is called on the thread the context will be used. |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| if (!context_) { |
| - gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| + blink::WebGraphicsContext3D::Attributes attributes; |
| + attributes.antialias = false; |
| + attributes.depth = false; |
| + attributes.stencil = false; |
| + attributes.shareResources = true; |
| + attributes.noAutomaticFlushes = true; |
| + gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; |
| + gpu_blink::WebGraphicsContext3DImpl::ConvertAttributes(attributes, |
| + &attribs_for_gles2); |
| + attribs_for_gles2.lose_context_when_out_of_memory = true; |
| + |
| context_.reset(gpu::GLInProcessContext::Create( |
| - nullptr, /* service */ |
| - nullptr, /* surface */ |
| - !window_, /* is_offscreen */ |
| - window_, gfx::Size(1, 1), nullptr, /* share_context */ |
| - true, /* share_resources */ |
| - attribs_, gpu_preference, gpu::GLInProcessContextSharedMemoryLimits(), |
| - nullptr, nullptr)); |
| + service_, |
| + surface_, |
| + surface_->IsOffscreen(), |
| + gfx::kNullAcceleratedWidget, |
| + surface_->GetSize(), |
| + NULL /* share_context */, |
| + false /* share_resources */, |
| + attribs_for_gles2, |
| + gfx::PreferDiscreteGpu, |
| + gpu::GLInProcessContextSharedMemoryLimits(), |
| + nullptr, |
| + nullptr)); |
| if (!context_) |
| return false; |
| context_->SetContextLostCallback(base::Bind( |
| - &InProcessContextProvider::OnLostContext, base::Unretained(this))); |
| + &ContextProviderInProcess::OnLostContext, base::Unretained(this))); |
| } |
| capabilities_.gpu = context_->GetImplementation()->capabilities(); |
| @@ -119,18 +111,18 @@ bool InProcessContextProvider::BindToCurrentThread() { |
| } |
| cc::ContextProvider::Capabilities |
| -InProcessContextProvider::ContextCapabilities() { |
| +ContextProviderInProcess::ContextCapabilities() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| return capabilities_; |
| } |
| -gpu::gles2::GLES2Interface* InProcessContextProvider::ContextGL() { |
| +gpu::gles2::GLES2Interface* ContextProviderInProcess::ContextGL() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| return context_->GetImplementation(); |
| } |
| -gpu::ContextSupport* InProcessContextProvider::ContextSupport() { |
| +gpu::ContextSupport* ContextProviderInProcess::ContextSupport() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| return context_->GetImplementation(); |
| @@ -138,12 +130,12 @@ gpu::ContextSupport* InProcessContextProvider::ContextSupport() { |
| static void BindGrContextCallback(const GrGLInterface* interface) { |
| cc::ContextProvider* context_provider = |
| - reinterpret_cast<InProcessContextProvider*>(interface->fCallbackData); |
| + reinterpret_cast<ContextProviderInProcess*>(interface->fCallbackData); |
| gles2::SetGLContext(context_provider->ContextGL()); |
| } |
| -class GrContext* InProcessContextProvider::GrContext() { |
| +class GrContext* ContextProviderInProcess::GrContext() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| if (gr_context_) |
| @@ -165,24 +157,24 @@ class GrContext* InProcessContextProvider::GrContext() { |
| return gr_context_.get(); |
| } |
| -void InProcessContextProvider::SetupLock() { |
| +void ContextProviderInProcess::SetupLock() { |
|
boliu
2015/04/20 10:06:05
context_->SetLock(&context_lock_);
tfarina
2015/04/22 02:09:04
Done.
|
| } |
| -base::Lock* InProcessContextProvider::GetLock() { |
| +base::Lock* ContextProviderInProcess::GetLock() { |
| return &context_lock_; |
| } |
| -bool InProcessContextProvider::IsContextLost() { |
| +bool ContextProviderInProcess::IsContextLost() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| base::AutoLock lock(destroyed_lock_); |
| return destroyed_; |
| } |
| -void InProcessContextProvider::VerifyContexts() { |
| +void ContextProviderInProcess::VerifyContexts() { |
| } |
|
boliu
2015/04/20 10:06:05
Hmm, nothing in cc calls VerifyContexts. There's o
tfarina
2015/04/22 02:09:04
Done.
|
| -void InProcessContextProvider::DeleteCachedResources() { |
| +void ContextProviderInProcess::DeleteCachedResources() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| if (gr_context_) { |
| @@ -192,24 +184,24 @@ void InProcessContextProvider::DeleteCachedResources() { |
| } |
| } |
| -bool InProcessContextProvider::DestroyedOnMainThread() { |
| +bool ContextProviderInProcess::DestroyedOnMainThread() { |
| DCHECK(main_thread_checker_.CalledOnValidThread()); |
| base::AutoLock lock(destroyed_lock_); |
| return destroyed_; |
| } |
| -void InProcessContextProvider::SetLostContextCallback( |
| +void ContextProviderInProcess::SetLostContextCallback( |
| const LostContextCallback& lost_context_callback) { |
| lost_context_callback_ = lost_context_callback; |
| } |
| -void InProcessContextProvider::SetMemoryPolicyChangedCallback( |
| +void ContextProviderInProcess::SetMemoryPolicyChangedCallback( |
| const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
| // There's no memory manager for the in-process implementation. |
| } |
| -void InProcessContextProvider::OnLostContext() { |
| +void ContextProviderInProcess::OnLostContext() { |
| DCHECK(context_thread_checker_.CalledOnValidThread()); |
| { |
| base::AutoLock lock(destroyed_lock_); |