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