Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: content/browser/android/jni_helper.h

Issue 10209003: Upstream Android Geolocation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add OWNERS Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // 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
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 struct RegistrationMethod {
17 const char* name;
18 bool (*func)(JNIEnv* env);
19 };
20
21 class SkBitmap;
22 namespace gfx {
23 class Size;
24 }
25
26 // Auto creator/destructor for a JNI frame for local references. This allows
27 // safely having more than 16 local references, and avoids calls to
28 // DeleteLocalRef.
29 // This should be created on the stack.
30 class AutoLocalFrame {
31 public:
32 AutoLocalFrame(int capacity);
33 ~AutoLocalFrame();
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(AutoLocalFrame);
37 };
38
39 // Create this object on the stack to obtain the pixels of a Java Bitmap and
40 // automatically release them on destruction.
41 // Similar to SkAutoLockPixels, except that it operates on a Java Bitmap
42 // object via the Android NDK.
43 class AutoLockJavaBitmap {
44 public:
45 AutoLockJavaBitmap(jobject bitmap);
46 ~AutoLockJavaBitmap();
47
48 void* pixels() const { return pixels_; }
49 gfx::Size size() const;
50 // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888 */
51 int format() const;
52 uint32_t stride() const;
53
54 private:
55 jobject bitmap_;
56 void* pixels_;
57
58 DISALLOW_COPY_AND_ASSIGN(AutoLockJavaBitmap);
59 };
60
61 // Manages WeakGlobalRef lifecycle.
62 class JavaObjectWeakGlobalRef {
63 public:
64 JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj);
65 virtual ~JavaObjectWeakGlobalRef();
66
67 base::android::ScopedJavaLocalRef<jobject> get(JNIEnv* env) const;
68
69 private:
70 jweak obj_;
71
72 DISALLOW_COPY_AND_ASSIGN(JavaObjectWeakGlobalRef);
73 };
74
75 // Tell Java to write its current stack trace into Android logs. Note that the
76 // trace will stop at the entry point into C++ code.
77 void PrintJavaStackTrace();
78
79 // Get the real object stored in the weak reference returned as a
80 // ScopedJavaLocalRef.
81 base::android::ScopedJavaLocalRef<jobject> GetRealObject(
82 JNIEnv* env,
83 jobject obj);
84
85 // Fills in the given vector<string> from a java String[].
86 void ConvertJavaArrayOfStringsToVectorOfStrings(
87 JNIEnv* env,
88 jobjectArray jstrings,
89 std::vector<std::string>* vec);
90
91 // Helper method to create an Android Java Bitmap object. You can use the
92 // AutoLockJavaBitmap class to manipulate its pixels, and pass it back up
93 // to Java code for drawing. Returns a JNI local reference to the bitmap.
94 // If 'keep' is true, then a reference will be kept in a static Java data
95 // structure to prevent GC. In that case, you must call DeleteJavaBitmap() to
96 // garbage collect it.
97 base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap(
98 const gfx::Size& size, bool keep);
99 void DeleteJavaBitmap(jobject bitmap);
100
101 // Paint one java bitmap into another. Scale if needed.
102 void PaintJavaBitmapToJavaBitmap(jobject sourceBitmap,
103 const gfx::Rect& sourceRect,
104 jobject destBitmap,
105 const gfx::Rect& destRect);
106
107 // Copy the Chromium Skia bitmap into a new Java bitmap. Useful for small UI
108 // bitmaps originating from WebKit that we want to manipulate in Java (such as
109 // favicons). Due to the extra copy, should be avoided for large or frequently
110 // used bitmaps. Returns a local reference to the new bitmap.
111 base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(
112 const SkBitmap* skbitmap);
113
114 // Registers our JNI methods.
115 bool RegisterJniHelper(JNIEnv* env);
116
117 #endif // CONTENT_BROWSER_ANDROID_JNI_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698