OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
jam
2012/06/15 22:59:31
if these helper files stuff is used outside of con
| |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_ANDROID_BITMAP_HOLDER_H_ |
6 #define CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_ANDROID_BITMAP_HOLDER_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 | 15 |
16 class SkBitmap; | 16 class SkBitmap; |
17 namespace gfx { | 17 namespace gfx { |
18 class Size; | 18 class Size; |
19 } | 19 } |
20 | 20 |
21 namespace content { | |
22 | |
23 // TODO(sievers): Remove this and use ScopedJavaLocalRef instead. | |
21 // Auto creator/destructor for a JNI frame for local references. This allows | 24 // Auto creator/destructor for a JNI frame for local references. This allows |
22 // safely having more than 16 local references, and avoids calls to | 25 // safely having more than 16 local references, and avoids calls to |
23 // DeleteLocalRef. | 26 // DeleteLocalRef. |
24 // This should be created on the stack. | 27 // This should be created on the stack. |
25 class AutoLocalFrame { | 28 class AutoLocalFrame { |
26 public: | 29 public: |
27 AutoLocalFrame(int capacity); | 30 AutoLocalFrame(int capacity); |
28 ~AutoLocalFrame(); | 31 ~AutoLocalFrame(); |
29 | 32 |
30 private: | 33 private: |
(...skipping 15 matching lines...) Expand all Loading... | |
46 int format() const; | 49 int format() const; |
47 uint32_t stride() const; | 50 uint32_t stride() const; |
48 | 51 |
49 private: | 52 private: |
50 jobject bitmap_; | 53 jobject bitmap_; |
51 void* pixels_; | 54 void* pixels_; |
52 | 55 |
53 DISALLOW_COPY_AND_ASSIGN(AutoLockJavaBitmap); | 56 DISALLOW_COPY_AND_ASSIGN(AutoLockJavaBitmap); |
54 }; | 57 }; |
55 | 58 |
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 | 59 // 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 | 60 // 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. | 61 // 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 | 62 // 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 | 63 // structure to prevent GC. In that case, you must call DeleteJavaBitmap() to |
71 // garbage collect it. | 64 // garbage collect it. |
72 base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap( | 65 base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap( |
73 const gfx::Size& size, bool keep); | 66 const gfx::Size& size, bool keep); |
74 void DeleteJavaBitmap(jobject bitmap); | 67 void DeleteJavaBitmap(jobject bitmap); |
75 | 68 |
76 // Paint one java bitmap into another. Scale if needed. | 69 // Paint one java bitmap into another. Scale if needed. |
77 void PaintJavaBitmapToJavaBitmap(jobject sourceBitmap, | 70 void PaintJavaBitmapToJavaBitmap(jobject sourceBitmap, |
78 const gfx::Rect& sourceRect, | 71 const gfx::Rect& sourceRect, |
Ted C
2012/06/15 20:52:17
indent of this looks messed up.
| |
79 jobject destBitmap, | 72 jobject destBitmap, |
80 const gfx::Rect& destRect); | 73 const gfx::Rect& destRect); |
81 | 74 |
82 // Copy the Chromium Skia bitmap into a new Java bitmap. Useful for small UI | 75 // 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 | 76 // 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 | 77 // favicons). Due to the extra copy, should be avoided for large or frequently |
85 // used bitmaps. Returns a local reference to the new bitmap. | 78 // used bitmaps. Returns a local reference to the new bitmap. |
86 base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap( | 79 base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap( |
87 const SkBitmap* skbitmap); | 80 const SkBitmap* skbitmap); |
88 | 81 |
89 // Registers our JNI methods. | 82 } // namespace content |
90 bool RegisterJniHelper(JNIEnv* env); | |
91 | 83 |
92 #endif // CONTENT_BROWSER_ANDROID_JNI_HELPER_H_ | 84 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_BITMAP_HOLDER_H_ |
OLD | NEW |