Chromium Code Reviews| Index: content/browser/android/jni_helper.h |
| diff --git a/content/browser/android/jni_helper.h b/content/browser/android/jni_helper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1627b01d4ac299b7289ac9780ad24b002990e66d |
| --- /dev/null |
| +++ b/content/browser/android/jni_helper.h |
| @@ -0,0 +1,117 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
Yaron
2012/04/25 17:26:09
See 10035034. The critical parts of this have been
John Knottenbelt
2012/04/26 15:14:51
Nope, I'll get rid of this file.
On 2012/04/25 17
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |
| +#define CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |
| + |
| +#include <jni.h> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/string16.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +struct RegistrationMethod { |
| + const char* name; |
| + bool (*func)(JNIEnv* env); |
| +}; |
| + |
| +class SkBitmap; |
| +namespace gfx { |
| + class Size; |
| +} |
| + |
| +// Auto creator/destructor for a JNI frame for local references. This allows |
| +// safely having more than 16 local references, and avoids calls to |
| +// DeleteLocalRef. |
| +// This should be created on the stack. |
| +class AutoLocalFrame { |
| + public: |
| + AutoLocalFrame(int capacity); |
| + ~AutoLocalFrame(); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AutoLocalFrame); |
| +}; |
| + |
| +// Create this object on the stack to obtain the pixels of a Java Bitmap and |
| +// automatically release them on destruction. |
| +// Similar to SkAutoLockPixels, except that it operates on a Java Bitmap |
| +// object via the Android NDK. |
| +class AutoLockJavaBitmap { |
| + public: |
| + AutoLockJavaBitmap(jobject bitmap); |
| + ~AutoLockJavaBitmap(); |
| + |
| + void* pixels() const { return pixels_; } |
| + gfx::Size size() const; |
| + // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888 */ |
| + int format() const; |
| + uint32_t stride() const; |
| + |
| + private: |
| + jobject bitmap_; |
| + void* pixels_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AutoLockJavaBitmap); |
| +}; |
| + |
| +// Manages WeakGlobalRef lifecycle. |
| +class JavaObjectWeakGlobalRef { |
| + public: |
| + JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj); |
| + virtual ~JavaObjectWeakGlobalRef(); |
| + |
| + base::android::ScopedJavaLocalRef<jobject> get(JNIEnv* env) const; |
| + |
| + private: |
| + jweak obj_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(JavaObjectWeakGlobalRef); |
| +}; |
| + |
| +// Tell Java to write its current stack trace into Android logs. Note that the |
| +// trace will stop at the entry point into C++ code. |
| +void PrintJavaStackTrace(); |
| + |
| +// Get the real object stored in the weak reference returned as a |
| +// ScopedJavaLocalRef. |
| +base::android::ScopedJavaLocalRef<jobject> GetRealObject( |
| + JNIEnv* env, |
| + jobject obj); |
| + |
| +// Fills in the given vector<string> from a java String[]. |
| +void ConvertJavaArrayOfStringsToVectorOfStrings( |
| + JNIEnv* env, |
| + jobjectArray jstrings, |
| + std::vector<std::string>* vec); |
| + |
| +// Helper method to create an Android Java Bitmap object. You can use the |
| +// AutoLockJavaBitmap class to manipulate its pixels, and pass it back up |
| +// to Java code for drawing. Returns a JNI local reference to the bitmap. |
| +// If 'keep' is true, then a reference will be kept in a static Java data |
| +// structure to prevent GC. In that case, you must call DeleteJavaBitmap() to |
| +// garbage collect it. |
| +base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap( |
| + const gfx::Size& size, bool keep); |
| +void DeleteJavaBitmap(jobject bitmap); |
| + |
| +// Paint one java bitmap into another. Scale if needed. |
| +void PaintJavaBitmapToJavaBitmap(jobject sourceBitmap, |
| + const gfx::Rect& sourceRect, |
| + jobject destBitmap, |
| + const gfx::Rect& destRect); |
| + |
| +// Copy the Chromium Skia bitmap into a new Java bitmap. Useful for small UI |
| +// bitmaps originating from WebKit that we want to manipulate in Java (such as |
| +// favicons). Due to the extra copy, should be avoided for large or frequently |
| +// used bitmaps. Returns a local reference to the new bitmap. |
| +base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap( |
| + const SkBitmap* skbitmap); |
| + |
| +// Registers our JNI methods. |
| +bool RegisterJniHelper(JNIEnv* env); |
| + |
| +#endif // CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |