OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/string16.h" |
| 14 #include "ui/gfx/rect.h" |
| 15 |
| 16 class SkBitmap; |
| 17 namespace gfx { |
| 18 class Size; |
| 19 } |
| 20 |
| 21 // Auto creator/destructor for a JNI frame for local references. This allows |
| 22 // safely having more than 16 local references, and avoids calls to |
| 23 // DeleteLocalRef. |
| 24 // This should be created on the stack. |
| 25 class AutoLocalFrame { |
| 26 public: |
| 27 AutoLocalFrame(int capacity); |
| 28 ~AutoLocalFrame(); |
| 29 |
| 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(AutoLocalFrame); |
| 32 }; |
| 33 |
| 34 // Create this object on the stack to obtain the pixels of a Java Bitmap and |
| 35 // automatically release them on destruction. |
| 36 // Similar to SkAutoLockPixels, except that it operates on a Java Bitmap |
| 37 // object via the Android NDK. |
| 38 class AutoLockJavaBitmap { |
| 39 public: |
| 40 AutoLockJavaBitmap(jobject bitmap); |
| 41 ~AutoLockJavaBitmap(); |
| 42 |
| 43 void* pixels() const { return pixels_; } |
| 44 gfx::Size size() const; |
| 45 // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888 */ |
| 46 int format() const; |
| 47 uint32_t stride() const; |
| 48 |
| 49 private: |
| 50 jobject bitmap_; |
| 51 void* pixels_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(AutoLockJavaBitmap); |
| 54 }; |
| 55 |
| 56 // Tell Java to write its current stack trace into Android logs. Note that the |
| 57 // trace will stop at the entry point into C++ code. |
| 58 void PrintJavaStackTrace(); |
| 59 |
| 60 // Fills in the given vector<string> from a java String[]. |
| 61 void ConvertJavaArrayOfStringsToVectorOfStrings( |
| 62 JNIEnv* env, |
| 63 jobjectArray jstrings, |
| 64 std::vector<std::string>* vec); |
| 65 |
| 66 // Helper method to create an Android Java Bitmap object. You can use the |
| 67 // AutoLockJavaBitmap class to manipulate its pixels, and pass it back up |
| 68 // to Java code for drawing. Returns a JNI local reference to the bitmap. |
| 69 // If 'keep' is true, then a reference will be kept in a static Java data |
| 70 // structure to prevent GC. In that case, you must call DeleteJavaBitmap() to |
| 71 // garbage collect it. |
| 72 base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap( |
| 73 const gfx::Size& size, bool keep); |
| 74 void DeleteJavaBitmap(jobject bitmap); |
| 75 |
| 76 // Paint one java bitmap into another. Scale if needed. |
| 77 void PaintJavaBitmapToJavaBitmap(jobject sourceBitmap, |
| 78 const gfx::Rect& sourceRect, |
| 79 jobject destBitmap, |
| 80 const gfx::Rect& destRect); |
| 81 |
| 82 // Copy the Chromium Skia bitmap into a new Java bitmap. Useful for small UI |
| 83 // bitmaps originating from WebKit that we want to manipulate in Java (such as |
| 84 // favicons). Due to the extra copy, should be avoided for large or frequently |
| 85 // used bitmaps. Returns a local reference to the new bitmap. |
| 86 base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap( |
| 87 const SkBitmap* skbitmap); |
| 88 |
| 89 // Registers our JNI methods. |
| 90 bool RegisterJniHelper(JNIEnv* env); |
| 91 |
| 92 #endif // CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ |
OLD | NEW |