summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Dixon <joth@google.com>2012-12-26 15:44:20 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-12-26 15:44:20 -0800
commit991b0c63bb8c0b0d8577a255b026117e9f37cece (patch)
tree6950cf08d709f60d2109d4d82feb186b6197ced5
parentd72ea1e90563e7d3056eef86c3c7dd0c526b718f (diff)
downloadwebview-991b0c63bb8c0b0d8577a255b026117e9f37cece.tar.gz
Revert "Revert "Connect up DrawSW interface""
This re-lands Ie9e6a28213167e0e7eaf9d91668466935d14fe38 as the dependent change has now rolled into android tree. Change-Id: I121d7de9c1428e773fde54653d7e60fa898c7acd
-rw-r--r--chromium/Android.mk15
-rw-r--r--chromium/java/com/android/webview/chromium/GraphicsUtils.java26
-rw-r--r--chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java1
-rw-r--r--chromium/plat_support/draw_gl_functor.cpp6
-rw-r--r--chromium/plat_support/graphics_utils.cpp111
-rw-r--r--chromium/plat_support/jni_entry_point.cpp2
6 files changed, 153 insertions, 8 deletions
diff --git a/chromium/Android.mk b/chromium/Android.mk
index 1830803..afa3cb7 100644
--- a/chromium/Android.mk
+++ b/chromium/Android.mk
@@ -27,7 +27,7 @@ LOCAL_MODULE := webviewchromium
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES += google-common \
- android_webview_java
+ android_webview_java \
LOCAL_SRC_FILES := $(call all-java-files-under, java)
@@ -35,7 +35,7 @@ LOCAL_REQUIRED_MODULES := \
libwebviewchromium \
libwebviewchromium_plat_support \
webviewchromium_pak \
- webviewchromium_strings_pak
+ webviewchromium_strings_pak \
LOCAL_PROGUARD_ENABLED := disabled
@@ -49,14 +49,19 @@ LOCAL_MODULE:= libwebviewchromium_plat_support
LOCAL_SRC_FILES:= \
plat_support/draw_gl_functor.cpp \
- plat_support/jni_entry_point.cpp
+ plat_support/jni_entry_point.cpp \
+ plat_support/graphics_utils.cpp \
LOCAL_C_INCLUDES:= \
- $(CHROMIUM_PATH)
+ $(CHROMIUM_PATH) \
+ external/skia/include/core \
+ frameworks/base/core/jni/android/graphics \
LOCAL_SHARED_LIBRARIES += \
+ libandroid_runtime \
+ libcutils \
+ libskia \
libutils \
- libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/chromium/java/com/android/webview/chromium/GraphicsUtils.java b/chromium/java/com/android/webview/chromium/GraphicsUtils.java
new file mode 100644
index 0000000..d5e9c4a
--- /dev/null
+++ b/chromium/java/com/android/webview/chromium/GraphicsUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.webview.chromium;
+
+abstract class GraphicsUtils {
+ public static int getDrawSWFunctionTable() {
+ return nativeGetDrawSWFunctionTable();
+ }
+
+ private static native int nativeGetDrawSWFunctionTable();
+
+}
diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
index a1a0d3b..ad45d75 100644
--- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
+++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
@@ -66,6 +66,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
// Load glue-layer support library.
System.loadLibrary("webviewchromium_plat_support");
DrawGLFunctor.setChromiumAwDrawGLFunction(AwContents.getAwDrawGLFunction());
+ AwContents.setAwDrawSWFunctionTable(GraphicsUtils.getDrawSWFunctionTable());
}
// TODO(joth): Much of this initialization logic could be moved into the chromium tree.
diff --git a/chromium/plat_support/draw_gl_functor.cpp b/chromium/plat_support/draw_gl_functor.cpp
index e9474bd..c07e2db 100644
--- a/chromium/plat_support/draw_gl_functor.cpp
+++ b/chromium/plat_support/draw_gl_functor.cpp
@@ -112,11 +112,11 @@ void SetChromiumAwDrawGLFunction(JNIEnv*, jclass, jint draw_function) {
const char kClassName[] = "com/android/webview/chromium/DrawGLFunctor";
const JNINativeMethod kJniMethods[] = {
{ "nativeCreateGLFunctor", "(I)I",
- reinterpret_cast<void*>(CreateGLFunctor), },
+ reinterpret_cast<void*>(CreateGLFunctor) },
{ "nativeDestroyGLFunctor", "(I)V",
- reinterpret_cast<void*>(DestroyGLFunctor), },
+ reinterpret_cast<void*>(DestroyGLFunctor) },
{ "nativeSetChromiumAwDrawGLFunction", "(I)V",
- reinterpret_cast<void*>(SetChromiumAwDrawGLFunction), },
+ reinterpret_cast<void*>(SetChromiumAwDrawGLFunction) },
};
} // namespace
diff --git a/chromium/plat_support/graphics_utils.cpp b/chromium/plat_support/graphics_utils.cpp
new file mode 100644
index 0000000..c9e519b
--- /dev/null
+++ b/chromium/plat_support/graphics_utils.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Provides a webviewchromium glue layer adapter from the internal Android
+// graphics types into the types the chromium stack expects, and back.
+
+#define LOG_TAG "webviewchromium_plat_support"
+
+#include "android_webview/public/browser/draw_sw.h"
+
+#include <cstdlib>
+#include <jni.h>
+#include <utils/Log.h>
+#include "GraphicsJNI.h"
+
+#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
+
+namespace android {
+namespace {
+
+struct PixelInfo : public AwPixelInfo {
+ PixelInfo(const SkBitmap* bitmap)
+ : bitmap_(bitmap) {
+ this->bitmap_->lockPixels();
+ }
+ ~PixelInfo() {
+ this->bitmap_->unlockPixels();
+ free(clip_region);
+ };
+ const SkBitmap* bitmap_;
+};
+
+AwPixelInfo* GetPixels(JNIEnv* env, jobject java_canvas) {
+ SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, java_canvas);
+ if (!canvas) return NULL;
+ SkDevice* device = canvas->getDevice();
+ if (!device) return NULL;
+ const SkBitmap* bitmap = &device->accessBitmap(true);
+ if (!bitmap->lockPixelsAreWritable()) return NULL;
+
+ PixelInfo* pixels = new PixelInfo(bitmap);
+ pixels->config = bitmap->config();
+ pixels->width = bitmap->width();
+ pixels->height = bitmap->height();
+ pixels->row_bytes = bitmap->rowBytes();
+ pixels->pixels = bitmap->getPixels();
+ const SkMatrix& matrix = canvas->getTotalMatrix();
+ for (int i = 0; i < 9; i++) {
+ pixels->matrix[i] = matrix.get(i);
+ }
+ // TODO: getTotalClip() is now marked as deprecated, but the replacement,
+ // getClipDeviceBounds, does not return the exact region, just the bounds.
+ // Work out what we should use instead.
+ const SkRegion& region = canvas->getTotalClip();
+ pixels->clip_region = NULL;
+ pixels->clip_region_size = region.writeToMemory(NULL);
+ if (pixels->clip_region_size) {
+ pixels->clip_region = malloc(pixels->clip_region_size);
+ size_t written = region.writeToMemory(pixels->clip_region);
+ ALOG_ASSERT(written == pixels->clip_region_size);
+ }
+ // WebViewClassic used the DrawFilter for its own purposes (e.g. disabling
+ // dithering when zooming/scrolling) so for now at least, just ignore any
+ // client supplied DrawFilter.
+ ALOGW_IF(canvas->getDrawFilter(),
+ "DrawFilter not supported in webviewchromium, will be ignored");
+ return pixels;
+}
+
+void ReleasePixels(AwPixelInfo* pixels) {
+ delete static_cast<PixelInfo*>(pixels);
+}
+
+jint GetDrawSWFunctionTable(JNIEnv* env, jclass) {
+ static const AwDrawSWFunctionTable function_table = {
+ &GetPixels,
+ &ReleasePixels,
+ };
+ return reinterpret_cast<jint>(&function_table);
+}
+
+const char kClassName[] = "com/android/webview/chromium/GraphicsUtils";
+const JNINativeMethod kJniMethods[] = {
+ { "nativeGetDrawSWFunctionTable", "()I",
+ reinterpret_cast<void*>(GetDrawSWFunctionTable) },
+};
+
+} // namespace
+
+void RegisterGraphicsUtils(JNIEnv* env) {
+ jclass clazz = env->FindClass(kClassName);
+ LOG_ALWAYS_FATAL_IF(!clazz, "Unable to find class '%s'", kClassName);
+
+ int res = env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods));
+ LOG_ALWAYS_FATAL_IF(res < 0, "register native methods failed: res=%d", res);
+}
+
+} // namespace android
diff --git a/chromium/plat_support/jni_entry_point.cpp b/chromium/plat_support/jni_entry_point.cpp
index 6293fa5..4771be1 100644
--- a/chromium/plat_support/jni_entry_point.cpp
+++ b/chromium/plat_support/jni_entry_point.cpp
@@ -22,6 +22,7 @@
namespace android {
void RegisterDrawGLFunctor(JNIEnv* env);
+void RegisterGraphicsUtils(JNIEnv* env);
} // namespace android
@@ -30,6 +31,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
jint ret = vm->AttachCurrentThread(&env, NULL);
LOG_ALWAYS_FATAL_IF(ret != JNI_OK, "AttachCurrentThread failed");
android::RegisterDrawGLFunctor(env);
+ android::RegisterGraphicsUtils(env);
return JNI_VERSION_1_4;
}