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

Unified Diff: android_webview/browser/aw_render_thread_context_provider.cc

Issue 1083843002: android_webview: Remove dependency on webkit's ContextProviderInProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for real 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/browser/aw_render_thread_context_provider.cc
diff --git a/ui/compositor/test/in_process_context_provider.cc b/android_webview/browser/aw_render_thread_context_provider.cc
similarity index 41%
copy from ui/compositor/test/in_process_context_provider.cc
copy to android_webview/browser/aw_render_thread_context_provider.cc
index d59736ff86d2730a1cf6cb39897fe317b73bd4f4..ce3114829e9fb11b16d29d98b62c25fd89bde164 100644
--- a/ui/compositor/test/in_process_context_provider.cc
+++ b/android_webview/browser/aw_render_thread_context_provider.cc
@@ -1,15 +1,15 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/aw_render_thread_context_provider.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/lazy_instance.h"
-#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 +17,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,113 +38,90 @@ 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,
- const std::string& debug_name) {
- return new InProcessContextProvider(
- attribs, lose_context_when_out_of_memory, window, debug_name);
+scoped_refptr<AwRenderThreadContextProvider>
+AwRenderThreadContextProvider::Create(
+ scoped_refptr<gfx::GLSurface> surface,
+ scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
+ return new AwRenderThreadContextProvider(surface, service);
}
-// 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,
- const std::string& debug_name)
- : attribs_(attribs),
- lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
- window_(window),
- debug_name_(debug_name),
- destroyed_(false) {
+AwRenderThreadContextProvider::AwRenderThreadContextProvider(
+ scoped_refptr<gfx::GLSurface> surface,
+ scoped_refptr<gpu::InProcessCommandBuffer::Service> service)
+ : destroyed_(false) {
DCHECK(main_thread_checker_.CalledOnValidThread());
- context_thread_checker_.DetachFromThread();
+
+ 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(
+ service,
+ surface,
+ surface->IsOffscreen(),
+ gfx::kNullAcceleratedWidget,
+ surface->GetSize(),
+ NULL /* share_context */,
+ false /* share_resources */,
+ attribs_for_gles2,
+ gfx::PreferDiscreteGpu,
+ gpu::GLInProcessContextSharedMemoryLimits(),
+ nullptr,
+ nullptr));
+
+ context_->SetContextLostCallback(base::Bind(
+ &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this)));
+
+ capabilities_.gpu = context_->GetImplementation()->capabilities();
}
-InProcessContextProvider::~InProcessContextProvider() {
- DCHECK(main_thread_checker_.CalledOnValidThread() ||
- context_thread_checker_.CalledOnValidThread());
+AwRenderThreadContextProvider::~AwRenderThreadContextProvider() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
}
-bool InProcessContextProvider::BindToCurrentThread() {
+bool AwRenderThreadContextProvider::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;
- 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));
-
- if (!context_)
- return false;
-
- context_->SetContextLostCallback(base::Bind(
- &InProcessContextProvider::OnLostContext, base::Unretained(this)));
- }
-
- capabilities_.gpu = context_->GetImplementation()->capabilities();
-
- std::string unique_context_name =
- base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get());
- context_->GetImplementation()->TraceBeginCHROMIUM(
- "gpu_toplevel", unique_context_name.c_str());
+ DCHECK(main_thread_checker_.CalledOnValidThread());
return true;
}
cc::ContextProvider::Capabilities
-InProcessContextProvider::ContextCapabilities() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+AwRenderThreadContextProvider::ContextCapabilities() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+
return capabilities_;
}
-gpu::gles2::GLES2Interface* InProcessContextProvider::ContextGL() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+gpu::gles2::GLES2Interface* AwRenderThreadContextProvider::ContextGL() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
return context_->GetImplementation();
}
-gpu::ContextSupport* InProcessContextProvider::ContextSupport() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+gpu::ContextSupport* AwRenderThreadContextProvider::ContextSupport() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
return context_->GetImplementation();
}
static void BindGrContextCallback(const GrGLInterface* interface) {
cc::ContextProvider* context_provider =
- reinterpret_cast<InProcessContextProvider*>(interface->fCallbackData);
+ reinterpret_cast<AwRenderThreadContextProvider*>(
+ interface->fCallbackData);
gles2::SetGLContext(context_provider->ContextGL());
}
-class GrContext* InProcessContextProvider::GrContext() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+class GrContext* AwRenderThreadContextProvider::GrContext() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
if (gr_context_)
return gr_context_.get();
@@ -165,25 +142,25 @@ class GrContext* InProcessContextProvider::GrContext() {
return gr_context_.get();
}
-void InProcessContextProvider::SetupLock() {
+void AwRenderThreadContextProvider::SetupLock() {
+ context_->SetLock(&context_lock_);
}
-base::Lock* InProcessContextProvider::GetLock() {
+base::Lock* AwRenderThreadContextProvider::GetLock() {
return &context_lock_;
}
-bool InProcessContextProvider::IsContextLost() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+bool AwRenderThreadContextProvider::IsContextLost() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
- base::AutoLock lock(destroyed_lock_);
return destroyed_;
}
-void InProcessContextProvider::VerifyContexts() {
+void AwRenderThreadContextProvider::VerifyContexts() {
}
-void InProcessContextProvider::DeleteCachedResources() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
+void AwRenderThreadContextProvider::DeleteCachedResources() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
if (gr_context_) {
TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources",
@@ -192,35 +169,33 @@ void InProcessContextProvider::DeleteCachedResources() {
}
}
-bool InProcessContextProvider::DestroyedOnMainThread() {
+bool AwRenderThreadContextProvider::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
- base::AutoLock lock(destroyed_lock_);
return destroyed_;
}
-void InProcessContextProvider::SetLostContextCallback(
+void AwRenderThreadContextProvider::SetLostContextCallback(
const LostContextCallback& lost_context_callback) {
lost_context_callback_ = lost_context_callback;
}
-void InProcessContextProvider::SetMemoryPolicyChangedCallback(
+void AwRenderThreadContextProvider::SetMemoryPolicyChangedCallback(
const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
// There's no memory manager for the in-process implementation.
}
-void InProcessContextProvider::OnLostContext() {
- DCHECK(context_thread_checker_.CalledOnValidThread());
- {
- base::AutoLock lock(destroyed_lock_);
- if (destroyed_)
- return;
- destroyed_ = true;
- }
+void AwRenderThreadContextProvider::OnLostContext() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+
+ if (destroyed_)
+ return;
+ destroyed_ = true;
+
if (!lost_context_callback_.is_null())
base::ResetAndReturn(&lost_context_callback_).Run();
if (gr_context_)
gr_context_->abandonContext();
}
-} // namespace ui
+} // namespace android_webview
« no previous file with comments | « android_webview/browser/aw_render_thread_context_provider.h ('k') | android_webview/browser/hardware_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698