Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1 | #ifndef _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ |
| 2 | #define _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 4 | #include "Bitmap.h" |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 5 | #include "SkBitmap.h" |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 6 | #include "SkBRDAllocator.h" |
| 7 | #include "SkCodec.h" |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 8 | #include "SkDevice.h" |
| 9 | #include "SkPixelRef.h" |
| 10 | #include "SkMallocPixelRef.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11 | #include "SkPoint.h" |
| 12 | #include "SkRect.h" |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 13 | #include "SkImageDecoder.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | #include <jni.h> |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 15 | #include <hwui/Canvas.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 17 | class SkBitmapRegionDecoder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | class SkCanvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
Raph Levien | 3d528c40 | 2014-06-26 09:04:54 -0700 | [diff] [blame] | 20 | namespace android { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 21 | class Paint; |
sergeyv | bad9918 | 2016-03-17 11:24:22 -0700 | [diff] [blame] | 22 | struct Typeface; |
Raph Levien | 3d528c40 | 2014-06-26 09:04:54 -0700 | [diff] [blame] | 23 | } |
| 24 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | class GraphicsJNI { |
| 26 | public: |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 27 | enum BitmapCreateFlags { |
| 28 | kBitmapCreateFlag_None = 0x0, |
| 29 | kBitmapCreateFlag_Mutable = 0x1, |
| 30 | kBitmapCreateFlag_Premultiplied = 0x2, |
| 31 | }; |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | // returns true if an exception is set (and dumps it out to the Log) |
| 34 | static bool hasException(JNIEnv*); |
| 35 | |
| 36 | static void get_jrect(JNIEnv*, jobject jrect, int* L, int* T, int* R, int* B); |
| 37 | static void set_jrect(JNIEnv*, jobject jrect, int L, int T, int R, int B); |
| 38 | |
| 39 | static SkIRect* jrect_to_irect(JNIEnv*, jobject jrect, SkIRect*); |
| 40 | static void irect_to_jrect(const SkIRect&, JNIEnv*, jobject jrect); |
| 41 | |
| 42 | static SkRect* jrectf_to_rect(JNIEnv*, jobject jrectf, SkRect*); |
| 43 | static SkRect* jrect_to_rect(JNIEnv*, jobject jrect, SkRect*); |
| 44 | static void rect_to_jrectf(const SkRect&, JNIEnv*, jobject jrectf); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | static void set_jpoint(JNIEnv*, jobject jrect, int x, int y); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 47 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | static SkIPoint* jpoint_to_ipoint(JNIEnv*, jobject jpoint, SkIPoint* point); |
| 49 | static void ipoint_to_jpoint(const SkIPoint& point, JNIEnv*, jobject jpoint); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | static SkPoint* jpointf_to_point(JNIEnv*, jobject jpointf, SkPoint* point); |
| 52 | static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 53 | |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 54 | static android::Canvas* getNativeCanvas(JNIEnv*, jobject canvas); |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 55 | static android::Bitmap* getBitmap(JNIEnv*, jobject bitmap); |
John Reck | ed207b9 | 2015-04-10 13:52:57 -0700 | [diff] [blame] | 56 | static void getSkBitmap(JNIEnv*, jobject bitmap, SkBitmap* outBitmap); |
John Reck | ae2e8b4 | 2015-05-06 14:55:05 -0700 | [diff] [blame] | 57 | static SkPixelRef* refSkPixelRef(JNIEnv*, jobject bitmap); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | static SkRegion* getNativeRegion(JNIEnv*, jobject region); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 59 | |
Mike Reed | 4c9355c | 2014-05-07 11:48:37 -0400 | [diff] [blame] | 60 | // Given the 'native' long held by the Rasterizer.java object, return a |
| 61 | // ref to its SkRasterizer* (or NULL). |
| 62 | static SkRasterizer* refNativeRasterizer(jlong rasterizerHandle); |
| 63 | |
Mike Reed | 1103b32 | 2014-07-08 12:36:44 -0400 | [diff] [blame] | 64 | /* |
| 65 | * LegacyBitmapConfig is the old enum in Skia that matched the enum int values |
| 66 | * in Bitmap.Config. Skia no longer supports this config, but has replaced it |
| 67 | * with SkColorType. These routines convert between the two. |
| 68 | */ |
| 69 | static SkColorType legacyBitmapConfigToColorType(jint legacyConfig); |
| 70 | static jint colorTypeToLegacyBitmapConfig(SkColorType colorType); |
| 71 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 72 | /** Return the corresponding native colorType from the java Config enum, |
| 73 | or kUnknown_SkColorType if the java object is null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | */ |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 75 | static SkColorType getNativeBitmapColorType(JNIEnv*, jobject jconfig); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 76 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 77 | /* |
| 78 | * Create a java Bitmap object given the native bitmap |
| 79 | * bitmap's SkAlphaType must already be in sync with bitmapCreateFlags. |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 80 | */ |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 81 | static jobject createBitmap(JNIEnv* env, android::Bitmap* bitmap, |
| 82 | int bitmapCreateFlags, jbyteArray ninePatchChunk = NULL, |
| 83 | jobject ninePatchInsets = NULL, int density = -1); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 84 | |
Leon Scroggins III | 8790be6 | 2013-12-03 16:26:51 -0500 | [diff] [blame] | 85 | /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in |
| 86 | sync with isPremultiplied |
| 87 | */ |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 88 | static void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info, |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 89 | bool isPremultiplied); |
Chris Craik | 9f58361 | 2013-05-20 18:13:47 -0700 | [diff] [blame] | 90 | |
| 91 | static int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap); |
| 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | static jobject createRegion(JNIEnv* env, SkRegion* region); |
| 94 | |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 95 | static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); |
Joseph Wen | f1f48bc | 2010-07-19 16:59:51 +0800 | [diff] [blame] | 96 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 97 | static android::Bitmap* allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap, |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 98 | SkColorTable* ctable); |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 99 | |
Riley Andrews | 39d7f30 | 2014-11-13 17:43:25 -0800 | [diff] [blame] | 100 | static android::Bitmap* allocateAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, |
| 101 | SkColorTable* ctable); |
| 102 | |
| 103 | static android::Bitmap* mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, |
John Reck | aa394dd | 2016-09-12 10:43:35 -0700 | [diff] [blame] | 104 | SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly); |
Riley Andrews | 39d7f30 | 2014-11-13 17:43:25 -0800 | [diff] [blame] | 105 | |
Derek Sollenberger | 3d4eed7 | 2014-12-04 15:20:29 -0500 | [diff] [blame] | 106 | /** |
| 107 | * Given a bitmap we natively allocate a memory block to store the contents |
| 108 | * of that bitmap. The memory is then attached to the bitmap via an |
| 109 | * SkPixelRef, which ensures that upon deletion the appropriate caches |
| 110 | * are notified. |
| 111 | */ |
| 112 | static bool allocatePixels(JNIEnv* env, SkBitmap* bitmap, SkColorTable* ctable); |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | /** Copy the colors in colors[] to the bitmap, convert to the correct |
| 115 | format along the way. |
Leon Scroggins III | 57ee620 | 2014-06-04 18:51:07 -0400 | [diff] [blame] | 116 | Whether to use premultiplied pixels is determined by dstBitmap's alphaType. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | */ |
| 118 | static bool SetPixels(JNIEnv* env, jintArray colors, int srcOffset, |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 119 | int srcStride, int x, int y, int width, int height, |
Leon Scroggins III | 57ee620 | 2014-06-04 18:51:07 -0400 | [diff] [blame] | 120 | const SkBitmap& dstBitmap); |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** Allocator which allocates the backing buffer in the Java heap. |
| 124 | * Instances can only be used to perform a single allocation, which helps |
| 125 | * ensure that the allocated buffer is properly accounted for with a |
| 126 | * reference in the heap (or a JNI global reference). |
| 127 | */ |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 128 | class JavaPixelAllocator : public SkBRDAllocator { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | public: |
Chih-Hung Hsieh | a654328 | 2016-08-29 14:46:35 -0700 | [diff] [blame] | 130 | explicit JavaPixelAllocator(JNIEnv* env); |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 131 | ~JavaPixelAllocator(); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 132 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 133 | virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) override; |
Patrick Dubroy | afde46e | 2010-12-15 11:52:01 -0800 | [diff] [blame] | 134 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 135 | /** |
| 136 | * Fetches the backing allocation object. Must be called! |
Patrick Dubroy | afde46e | 2010-12-15 11:52:01 -0800 | [diff] [blame] | 137 | */ |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 138 | android::Bitmap* getStorageObjAndReset() { |
| 139 | android::Bitmap* result = mStorage; |
| 140 | mStorage = NULL; |
Patrick Dubroy | afde46e | 2010-12-15 11:52:01 -0800 | [diff] [blame] | 141 | return result; |
| 142 | }; |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 143 | |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 144 | /** |
| 145 | * Indicates that this allocator allocates zero initialized |
| 146 | * memory. |
| 147 | */ |
| 148 | SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kYes_ZeroInitialized; } |
| 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | private: |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 151 | JavaVM* mJavaVM; |
| 152 | android::Bitmap* mStorage = nullptr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
Matt Sarett | 1f97963 | 2015-10-27 10:33:20 -0400 | [diff] [blame] | 155 | /** |
| 156 | * Allocator to handle reusing bitmaps for BitmapRegionDecoder. |
| 157 | * |
| 158 | * The BitmapRegionDecoder documentation states that, if it is |
| 159 | * provided, the recycled bitmap will always be reused, clipping |
| 160 | * the decoded output to fit in the recycled bitmap if necessary. |
| 161 | * This allocator implements that behavior. |
| 162 | * |
| 163 | * Skia's SkBitmapRegionDecoder expects the memory that |
| 164 | * is allocated to be large enough to decode the entire region |
| 165 | * that is requested. It will decode directly into the memory |
| 166 | * that is provided. |
| 167 | * |
| 168 | * FIXME: BUG:25465958 |
| 169 | * If the recycled bitmap is not large enough for the decode |
| 170 | * requested, meaning that a clip is required, we will allocate |
| 171 | * enough memory for Skia to perform the decode, and then copy |
| 172 | * from the decoded output into the recycled bitmap. |
| 173 | * |
| 174 | * If the recycled bitmap is large enough for the decode requested, |
| 175 | * we will provide that memory for Skia to decode directly into. |
| 176 | * |
| 177 | * This allocator should only be used for a single allocation. |
| 178 | * After we reuse the recycledBitmap once, it is dangerous to |
| 179 | * reuse it again, given that it still may be in use from our |
| 180 | * first allocation. |
| 181 | */ |
| 182 | class RecyclingClippingPixelAllocator : public SkBRDAllocator { |
| 183 | public: |
| 184 | |
| 185 | RecyclingClippingPixelAllocator(android::Bitmap* recycledBitmap, |
| 186 | size_t recycledBytes); |
| 187 | |
| 188 | ~RecyclingClippingPixelAllocator(); |
| 189 | |
| 190 | virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) override; |
| 191 | |
| 192 | /** |
| 193 | * Must be called! |
| 194 | * |
| 195 | * In the event that the recycled bitmap is not large enough for |
| 196 | * the allocation requested, we will allocate memory on the heap |
| 197 | * instead. As a final step, once we are done using this memory, |
| 198 | * we will copy the contents of the heap memory into the recycled |
| 199 | * bitmap's memory, clipping as necessary. |
| 200 | */ |
| 201 | void copyIfNecessary(); |
| 202 | |
| 203 | /** |
| 204 | * Indicates that this allocator does not allocate zero initialized |
| 205 | * memory. |
| 206 | */ |
| 207 | SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kNo_ZeroInitialized; } |
| 208 | |
| 209 | private: |
| 210 | android::Bitmap* mRecycledBitmap; |
| 211 | const size_t mRecycledBytes; |
| 212 | SkBitmap* mSkiaBitmap; |
| 213 | bool mNeedsCopy; |
| 214 | }; |
| 215 | |
Riley Andrews | 721ae5f | 2015-05-11 16:08:22 -0700 | [diff] [blame] | 216 | class AshmemPixelAllocator : public SkBitmap::Allocator { |
| 217 | public: |
Chih-Hung Hsieh | a654328 | 2016-08-29 14:46:35 -0700 | [diff] [blame] | 218 | explicit AshmemPixelAllocator(JNIEnv* env); |
Riley Andrews | 721ae5f | 2015-05-11 16:08:22 -0700 | [diff] [blame] | 219 | ~AshmemPixelAllocator(); |
| 220 | virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable); |
| 221 | android::Bitmap* getStorageObjAndReset() { |
| 222 | android::Bitmap* result = mStorage; |
| 223 | mStorage = NULL; |
| 224 | return result; |
| 225 | }; |
| 226 | |
| 227 | private: |
| 228 | JavaVM* mJavaVM; |
| 229 | android::Bitmap* mStorage = nullptr; |
| 230 | }; |
| 231 | |
| 232 | |
Mike Reed | c04851f | 2009-10-28 15:09:45 -0400 | [diff] [blame] | 233 | enum JNIAccess { |
| 234 | kRO_JNIAccess, |
| 235 | kRW_JNIAccess |
| 236 | }; |
| 237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | class AutoJavaFloatArray { |
| 239 | public: |
Mike Reed | c04851f | 2009-10-28 15:09:45 -0400 | [diff] [blame] | 240 | AutoJavaFloatArray(JNIEnv* env, jfloatArray array, |
| 241 | int minLength = 0, JNIAccess = kRW_JNIAccess); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | ~AutoJavaFloatArray(); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | float* ptr() const { return fPtr; } |
| 245 | int length() const { return fLen; } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | private: |
| 248 | JNIEnv* fEnv; |
| 249 | jfloatArray fArray; |
| 250 | float* fPtr; |
| 251 | int fLen; |
Mike Reed | c04851f | 2009-10-28 15:09:45 -0400 | [diff] [blame] | 252 | int fReleaseMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | class AutoJavaIntArray { |
| 256 | public: |
| 257 | AutoJavaIntArray(JNIEnv* env, jintArray array, int minLength = 0); |
| 258 | ~AutoJavaIntArray(); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | jint* ptr() const { return fPtr; } |
| 261 | int length() const { return fLen; } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | private: |
| 264 | JNIEnv* fEnv; |
| 265 | jintArray fArray; |
| 266 | jint* fPtr; |
| 267 | int fLen; |
| 268 | }; |
| 269 | |
| 270 | class AutoJavaShortArray { |
| 271 | public: |
Mike Reed | c04851f | 2009-10-28 15:09:45 -0400 | [diff] [blame] | 272 | AutoJavaShortArray(JNIEnv* env, jshortArray array, |
| 273 | int minLength = 0, JNIAccess = kRW_JNIAccess); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | ~AutoJavaShortArray(); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | jshort* ptr() const { return fPtr; } |
| 277 | int length() const { return fLen; } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | private: |
| 280 | JNIEnv* fEnv; |
| 281 | jshortArray fArray; |
| 282 | jshort* fPtr; |
| 283 | int fLen; |
Mike Reed | c04851f | 2009-10-28 15:09:45 -0400 | [diff] [blame] | 284 | int fReleaseMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | class AutoJavaByteArray { |
| 288 | public: |
| 289 | AutoJavaByteArray(JNIEnv* env, jbyteArray array, int minLength = 0); |
| 290 | ~AutoJavaByteArray(); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | jbyte* ptr() const { return fPtr; } |
| 293 | int length() const { return fLen; } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | private: |
| 296 | JNIEnv* fEnv; |
| 297 | jbyteArray fArray; |
| 298 | jbyte* fPtr; |
| 299 | int fLen; |
| 300 | }; |
| 301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | void doThrowNPE(JNIEnv* env); |
| 303 | void doThrowAIOOBE(JNIEnv* env); // Array Index Out Of Bounds Exception |
| 304 | void doThrowIAE(JNIEnv* env, const char* msg = NULL); // Illegal Argument |
| 305 | void doThrowRE(JNIEnv* env, const char* msg = NULL); // Runtime |
| 306 | void doThrowISE(JNIEnv* env, const char* msg = NULL); // Illegal State |
| 307 | void doThrowOOME(JNIEnv* env, const char* msg = NULL); // Out of memory |
Joseph Wen | f1f48bc | 2010-07-19 16:59:51 +0800 | [diff] [blame] | 308 | void doThrowIOE(JNIEnv* env, const char* msg = NULL); // IO Exception |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | |
| 310 | #define NPE_CHECK_RETURN_ZERO(env, object) \ |
| 311 | do { if (NULL == (object)) { doThrowNPE(env); return 0; } } while (0) |
| 312 | |
| 313 | #define NPE_CHECK_RETURN_VOID(env, object) \ |
| 314 | do { if (NULL == (object)) { doThrowNPE(env); return; } } while (0) |
| 315 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 316 | #endif // _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ |