diff options
author | Jonathan Dixon <joth@google.com> | 2012-12-21 22:10:09 -0800 |
---|---|---|
committer | Jonathan Dixon <joth@google.com> | 2012-12-24 16:28:57 -0800 |
commit | 8a8a1f9b5ea238437196790b89f4dbec78fda4e9 (patch) | |
tree | 6950cf08d709f60d2109d4d82feb186b6197ced5 /chromium/plat_support | |
parent | 037e86f2095d1ca3fc1dff8e4ee82457257e8ea0 (diff) | |
download | webview-8a8a1f9b5ea238437196790b89f4dbec78fda4e9.tar.gz |
Connect up DrawSW interface
Depends on https://codereview.chromium.org/11665020
Provides the underlying code with direct access to native bitmap
pixels that back the java Canvas.
Change-Id: Ie9e6a28213167e0e7eaf9d91668466935d14fe38
Diffstat (limited to 'chromium/plat_support')
-rw-r--r-- | chromium/plat_support/draw_gl_functor.cpp | 6 | ||||
-rw-r--r-- | chromium/plat_support/graphics_utils.cpp | 111 | ||||
-rw-r--r-- | chromium/plat_support/jni_entry_point.cpp | 2 |
3 files changed, 116 insertions, 3 deletions
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; } |