Commit 29c37c90 authored by tfarina's avatar tfarina Committed by Commit bot

android_webview: Remove dependency on webkit's ContextProviderInProcess.

Instead build our own simplified version, so we don't need to depend on
webkit/common/gpu.

This should help ease the transition of
https://codereview.chromium.org/920443003.

Tested on Android (with Nexus 5 device) with the following command
lines:

$ ./build/gyp_chromium -DOS=android -Goutput_dir=out_android
$ ninja -C out_android/Debug android_webview_apk android_webview_test_apk
$ export CHROMIUM_OUT_DIR=out_android
$ build/android/adb_install_apk.py --apk=AndroidWebView.apk --debug
$ build/android/test_runner.py instrumentation --test-apk=AndroidWebViewTest \
  --test_data webview:android_webview/test/data/device_files --debug

BUG=338338
TEST=see above
R=boliu@chromium.org

Review URL: https://codereview.chromium.org/1083843002

Cr-Commit-Position: refs/heads/master@{#326968}
parent 09f1fa1a
......@@ -19,5 +19,4 @@ include_rules = [
"+ui/android",
"+ui/base",
"+ui/gfx",
"+webkit/common/gpu"
]
......@@ -176,8 +176,10 @@
'../gpu/blink/gpu_blink.gyp:gpu_blink',
'../gpu/command_buffer/command_buffer.gyp:gles2_utils',
'../gpu/gpu.gyp:command_buffer_service',
'../gpu/gpu.gyp:gles2_implementation',
'../gpu/gpu.gyp:gl_in_process_context',
'../gpu/gpu.gyp:gles2_c_lib',
'../gpu/gpu.gyp:gles2_implementation',
'../gpu/skia_bindings/skia_bindings.gyp:gpu_skia_bindings',
'../media/media.gyp:media',
'../printing/printing.gyp:printing',
'../skia/skia.gyp:skia',
......@@ -185,7 +187,6 @@
'../ui/gl/gl.gyp:gl',
'../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs',
'../v8/tools/gyp/v8.gyp:v8',
'../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu',
'android_webview_pak',
'android_webview_version',
],
......@@ -236,6 +237,8 @@
'browser/aw_quota_manager_bridge.h',
'browser/aw_quota_permission_context.cc',
'browser/aw_quota_permission_context.h',
'browser/aw_render_thread_context_provider.cc',
'browser/aw_render_thread_context_provider.h',
'browser/aw_request_interceptor.cc',
'browser/aw_request_interceptor.h',
'browser/aw_resource_context.cc',
......
......@@ -29,8 +29,6 @@ include_rules = [
"+ui/gfx",
"+ui/gl",
"+webkit/gpu",
# Temporary until we bundle our own favicon. See
# AwContentBrowserClient::GetDefaultFavicon
"!ui/resources/grit/ui_resources.h",
......
// 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 "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/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"
#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
namespace android_webview {
namespace {
// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
public:
GLES2Initializer() { gles2::Initialize(); }
~GLES2Initializer() { gles2::Terminate(); }
private:
DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
};
base::LazyInstance<GLES2Initializer> g_gles2_initializer =
LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
scoped_refptr<AwRenderThreadContextProvider>
AwRenderThreadContextProvider::Create(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
return new AwRenderThreadContextProvider(surface, service);
}
AwRenderThreadContextProvider::AwRenderThreadContextProvider(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service)
: destroyed_(false) {
DCHECK(main_thread_checker_.CalledOnValidThread());
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();
}
AwRenderThreadContextProvider::~AwRenderThreadContextProvider() {
DCHECK(main_thread_checker_.CalledOnValidThread());
}
bool AwRenderThreadContextProvider::BindToCurrentThread() {
// This is called on the thread the context will be used.
DCHECK(main_thread_checker_.CalledOnValidThread());
return true;
}
cc::ContextProvider::Capabilities
AwRenderThreadContextProvider::ContextCapabilities() {
DCHECK(main_thread_checker_.CalledOnValidThread());
return capabilities_;
}
gpu::gles2::GLES2Interface* AwRenderThreadContextProvider::ContextGL() {
DCHECK(main_thread_checker_.CalledOnValidThread());
return context_->GetImplementation();
}
gpu::ContextSupport* AwRenderThreadContextProvider::ContextSupport() {
DCHECK(main_thread_checker_.CalledOnValidThread());
return context_->GetImplementation();
}
static void BindGrContextCallback(const GrGLInterface* interface) {
cc::ContextProvider* context_provider =
reinterpret_cast<AwRenderThreadContextProvider*>(
interface->fCallbackData);
gles2::SetGLContext(context_provider->ContextGL());
}
class GrContext* AwRenderThreadContextProvider::GrContext() {
DCHECK(main_thread_checker_.CalledOnValidThread());
if (gr_context_)
return gr_context_.get();
// The GrGLInterface factory will make GL calls using the C GLES2 interface.
// Make sure the gles2 library is initialized first on exactly one thread.
g_gles2_initializer.Get();
gles2::SetGLContext(ContextGL());
skia::RefPtr<GrGLInterface> interface =
skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
interface->fCallback = BindGrContextCallback;
interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
gr_context_ = skia::AdoptRef(GrContext::Create(
kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
return gr_context_.get();
}
void AwRenderThreadContextProvider::SetupLock() {
context_->SetLock(&context_lock_);
}
base::Lock* AwRenderThreadContextProvider::GetLock() {
return &context_lock_;
}
bool AwRenderThreadContextProvider::IsContextLost() {
DCHECK(main_thread_checker_.CalledOnValidThread());
return destroyed_;
}
void AwRenderThreadContextProvider::VerifyContexts() {
}
void AwRenderThreadContextProvider::DeleteCachedResources() {
DCHECK(main_thread_checker_.CalledOnValidThread());
if (gr_context_) {
TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources",
TRACE_EVENT_SCOPE_THREAD);
gr_context_->freeGpuResources();
}
}
bool AwRenderThreadContextProvider::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
return destroyed_;
}
void AwRenderThreadContextProvider::SetLostContextCallback(
const LostContextCallback& lost_context_callback) {
lost_context_callback_ = lost_context_callback;
}
void AwRenderThreadContextProvider::SetMemoryPolicyChangedCallback(
const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
// There's no memory manager for the in-process implementation.
}
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 android_webview
// 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.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_RENDER_THREAD_CONTEXT_PROVIDER_H_
#define ANDROID_WEBVIEW_BROWSER_AW_RENDER_THREAD_CONTEXT_PROVIDER_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "cc/output/context_provider.h"
#include "gpu/command_buffer/service/in_process_command_buffer.h"
#include "skia/ext/refptr.h"
namespace gfx {
class GLSurface;
}
namespace gpu {
class GLInProcessContext;
}
namespace android_webview {
class AwRenderThreadContextProvider : public cc::ContextProvider {
public:
static scoped_refptr<AwRenderThreadContextProvider> Create(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
private:
AwRenderThreadContextProvider(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service);
~AwRenderThreadContextProvider() override;
// cc::ContextProvider:
bool BindToCurrentThread() override;
Capabilities ContextCapabilities() override;
gpu::gles2::GLES2Interface* ContextGL() override;
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
void SetupLock() override;
base::Lock* GetLock() override;
bool IsContextLost() override;
void VerifyContexts() override;
void DeleteCachedResources() override;
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
void SetMemoryPolicyChangedCallback(
const MemoryPolicyChangedCallback& memory_policy_changed_callback)
override;
void OnLostContext();
base::ThreadChecker main_thread_checker_;
scoped_ptr<gpu::GLInProcessContext> context_;
skia::RefPtr<class GrContext> gr_context_;
cc::ContextProvider::Capabilities capabilities_;
LostContextCallback lost_context_callback_;
bool destroyed_;
base::Lock context_lock_;
DISALLOW_COPY_AND_ASSIGN(AwRenderThreadContextProvider);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_RENDER_THREAD_CONTEXT_PROVIDER_H_
......@@ -5,6 +5,7 @@
#include "android_webview/browser/hardware_renderer.h"
#include "android_webview/browser/aw_gl_surface.h"
#include "android_webview/browser/aw_render_thread_context_provider.h"
#include "android_webview/browser/child_frame.h"
#include "android_webview/browser/deferred_gpu_command_service.h"
#include "android_webview/browser/parent_compositor_draw_constraints.h"
......@@ -22,7 +23,6 @@
#include "cc/scheduler/begin_frame_source.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_settings.h"
#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "ui/gfx/frame_time.h"
......@@ -30,54 +30,9 @@
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/transform.h"
#include "ui/gl/gl_bindings.h"
#include "webkit/common/gpu/context_provider_in_process.h"
namespace android_webview {
namespace {
using gpu_blink::WebGraphicsContext3DImpl;
using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl;
scoped_refptr<cc::ContextProvider> CreateContext(
scoped_refptr<gfx::GLSurface> surface,
scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
const 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;
WebGraphicsContext3DImpl::ConvertAttributes(
attributes, &attribs_for_gles2);
attribs_for_gles2.lose_context_when_out_of_memory = true;
scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
service,
surface,
surface->IsOffscreen(),
gfx::kNullAcceleratedWidget,
surface->GetSize(),
NULL /* share_context */,
false /* share_resources */,
attribs_for_gles2,
gpu_preference,
gpu::GLInProcessContextSharedMemoryLimits(),
nullptr,
nullptr));
DCHECK(context.get());
return webkit::gpu::ContextProviderInProcess::Create(
WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
context.Pass(), attributes),
"Parent-Compositor");
}
} // namespace
HardwareRenderer::HardwareRenderer(SharedRendererState* state)
: shared_renderer_state_(state),
last_egl_context_(eglGetCurrentContext()),
......@@ -240,8 +195,8 @@ void HardwareRenderer::DrawGL(bool stencil_enabled,
void HardwareRenderer::RequestNewOutputSurface() {
scoped_refptr<cc::ContextProvider> context_provider =
CreateContext(gl_surface_,
DeferredGpuCommandService::GetInstance());
AwRenderThreadContextProvider::Create(
gl_surface_, DeferredGpuCommandService::GetInstance());
scoped_ptr<ParentOutputSurface> output_surface_holder(
new ParentOutputSurface(context_provider));
output_surface_ = output_surface_holder.get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment