Commit 892c566f authored by boliu's avatar boliu Committed by Commit bot

aw: Force auxiliary bitmap on android emulators

Android emulators miss many EGL extensions required for
webview hardware accelerated rendering, so fallback to
a slow software mode when running in emulator.

BUG=490354

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

Cr-Commit-Position: refs/heads/master@{#330811}
parent e66ebca2
......@@ -100,6 +100,9 @@ public class AwContents implements SmartClipProvider,
// produce little visible difference.
private static final float ZOOM_CONTROLS_EPSILON = 0.007f;
private static final boolean FORCE_AUXILIARY_BITMAP_RENDERING =
"goldfish".equals(Build.HARDWARE);
/**
* WebKit hit test related data structure. These are used to implement
* getHitTestResult, requestFocusNodeHref, requestImageRef methods in WebView.
......@@ -1114,6 +1117,8 @@ public class AwContents implements SmartClipProvider,
public static void setAwDrawSWFunctionTable(long functionTablePointer) {
nativeSetAwDrawSWFunctionTable(functionTablePointer);
// Force auxiliary bitmap rendering in emulators.
nativeSetForceAuxiliaryBitmapRendering(FORCE_AUXILIARY_BITMAP_RENDERING);
}
public static void setAwDrawGLFunctionTable(long functionTablePointer) {
......@@ -2714,7 +2719,7 @@ public class AwContents implements SmartClipProvider,
mContainerView.getScrollX(), mContainerView.getScrollY(),
globalVisibleRect.left, globalVisibleRect.top,
globalVisibleRect.right, globalVisibleRect.bottom);
if (did_draw && canvas.isHardwareAccelerated()) {
if (did_draw && canvas.isHardwareAccelerated() && !FORCE_AUXILIARY_BITMAP_RENDERING) {
did_draw = mNativeGLDelegate.requestDrawGL(canvas, false, mContainerView);
}
if (!did_draw) {
......@@ -2990,6 +2995,8 @@ public class AwContents implements SmartClipProvider,
private static native long nativeInit(AwBrowserContext browserContext);
private static native void nativeDestroy(long nativeAwContents);
private static native void nativeSetForceAuxiliaryBitmapRendering(
boolean forceAuxiliaryBitmapRendering);
private static native void nativeSetAwDrawSWFunctionTable(long functionTablePointer);
private static native void nativeSetAwDrawGLFunctionTable(long functionTablePointer);
private static native long nativeGetAwDrawGLFunction();
......
......@@ -108,6 +108,8 @@ namespace {
bool g_should_download_favicons = false;
bool g_force_auxiliary_bitmap_rendering = false;
const void* kAwContentsUserDataKey = &kAwContentsUserDataKey;
class AwContentsUserData : public base::SupportsUserData::Data {
......@@ -310,6 +312,13 @@ static jlong Init(JNIEnv* env, jclass, jobject browser_context) {
return reinterpret_cast<intptr_t>(new AwContents(web_contents.Pass()));
}
static void SetForceAuxiliaryBitmapRendering(
JNIEnv* env,
jclass,
jboolean force_auxiliary_bitmap_rendering) {
g_force_auxiliary_bitmap_rendering = force_auxiliary_bitmap_rendering;
}
static void SetAwDrawSWFunctionTable(JNIEnv* env, jclass,
jlong function_table) {
RasterHelperSetAwDrawSWFunctionTable(
......@@ -876,7 +885,8 @@ bool AwContents::OnDraw(JNIEnv* env,
browser_view_renderer_.PrepareToDraw(
scroll, gfx::Rect(visible_left, visible_top, visible_right - visible_left,
visible_bottom - visible_top));
if (is_hardware_accelerated && browser_view_renderer_.attached_to_window()) {
if (is_hardware_accelerated && browser_view_renderer_.attached_to_window() &&
!g_force_auxiliary_bitmap_rendering) {
return browser_view_renderer_.OnDrawHardware();
}
......@@ -892,8 +902,8 @@ bool AwContents::OnDraw(JNIEnv* env,
// bitmap). For better performance, get global visible rect, transform it
// from screen space to view space, then intersect with the webview in
// viewspace. Use the resulting rect as the auxiliary bitmap.
scoped_ptr<SoftwareCanvasHolder> canvas_holder =
SoftwareCanvasHolder::Create(canvas, scroll, view_size);
scoped_ptr<SoftwareCanvasHolder> canvas_holder = SoftwareCanvasHolder::Create(
canvas, scroll, view_size, g_force_auxiliary_bitmap_rendering);
if (!canvas_holder || !canvas_holder->GetCanvas()) {
TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_EmptySize",
TRACE_EVENT_SCOPE_THREAD);
......
......@@ -33,8 +33,8 @@ jint AwPicture::GetHeight(JNIEnv* env, jobject obj) {
void AwPicture::Draw(JNIEnv* env, jobject obj, jobject canvas) {
const SkIRect bounds = picture_->cullRect().roundOut();
scoped_ptr<SoftwareCanvasHolder> canvas_holder = SoftwareCanvasHolder::Create(
canvas, gfx::Vector2d(),
gfx::Size(bounds.width(), bounds.height()));
canvas, gfx::Vector2d(), gfx::Size(bounds.width(), bounds.height()),
false);
if (!canvas_holder || !canvas_holder->GetCanvas()) {
LOG(ERROR) << "Couldn't draw picture";
return;
......
......@@ -152,11 +152,15 @@ void RasterHelperSetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table) {
scoped_ptr<SoftwareCanvasHolder> SoftwareCanvasHolder::Create(
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Size& auxiliary_bitmap_size) {
const gfx::Size& auxiliary_bitmap_size,
bool force_auxiliary_bitmap) {
JNIEnv* env = base::android::AttachCurrentThread();
scoped_ptr<SoftwareCanvasHolder> holder(
new JavaCanvasHolder(env, java_canvas, scroll_correction));
if (!holder->GetCanvas()) {
scoped_ptr<SoftwareCanvasHolder> holder;
if (!force_auxiliary_bitmap) {
scoped_ptr<SoftwareCanvasHolder> holder(
new JavaCanvasHolder(env, java_canvas, scroll_correction));
}
if (!holder.get() || !holder->GetCanvas()) {
holder.reset();
holder.reset(new AuxiliaryCanvasHolder(env, java_canvas, scroll_correction,
auxiliary_bitmap_size));
......
......@@ -22,7 +22,8 @@ class SoftwareCanvasHolder {
static scoped_ptr<SoftwareCanvasHolder> Create(
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Size& auxiliary_bitmap_size);
const gfx::Size& auxiliary_bitmap_size,
bool force_auxiliary_bitmap);
virtual ~SoftwareCanvasHolder() {}
......
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