1 #ifndef GraphicsJNI_DEFINED
2 #define GraphicsJNI_DEFINED
7 #include "../images/SkLargeBitmap.h"
8 #include "../images/SkImageDecoder.h"
17 // returns true if an exception is set (and dumps it out to the Log)
18 static bool hasException(JNIEnv*);
20 static void get_jrect(JNIEnv*, jobject jrect, int* L, int* T, int* R, int* B);
21 static void set_jrect(JNIEnv*, jobject jrect, int L, int T, int R, int B);
23 static SkIRect* jrect_to_irect(JNIEnv*, jobject jrect, SkIRect*);
24 static void irect_to_jrect(const SkIRect&, JNIEnv*, jobject jrect);
26 static SkRect* jrectf_to_rect(JNIEnv*, jobject jrectf, SkRect*);
27 static SkRect* jrect_to_rect(JNIEnv*, jobject jrect, SkRect*);
28 static void rect_to_jrectf(const SkRect&, JNIEnv*, jobject jrectf);
30 static void set_jpoint(JNIEnv*, jobject jrect, int x, int y);
32 static SkIPoint* jpoint_to_ipoint(JNIEnv*, jobject jpoint, SkIPoint* point);
33 static void ipoint_to_jpoint(const SkIPoint& point, JNIEnv*, jobject jpoint);
35 static SkPoint* jpointf_to_point(JNIEnv*, jobject jpointf, SkPoint* point);
36 static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf);
38 static SkCanvas* getNativeCanvas(JNIEnv*, jobject canvas);
39 static SkPaint* getNativePaint(JNIEnv*, jobject paint);
40 static SkBitmap* getNativeBitmap(JNIEnv*, jobject bitmap);
41 static SkPicture* getNativePicture(JNIEnv*, jobject picture);
42 static SkRegion* getNativeRegion(JNIEnv*, jobject region);
44 /** Return the corresponding native config from the java Config enum,
45 or kNo_Config if the java object is null.
47 static SkBitmap::Config getNativeBitmapConfig(JNIEnv*, jobject jconfig);
49 /** Create a java Bitmap object given the native bitmap (required) and optional
50 storage array (may be null). If storage is specified, then it must already be
51 locked, and its native address set as the bitmap's pixels. If storage is null,
52 then the bitmap must be an owner of its natively allocated pixels (via allocPixels).
54 static jobject createBitmap(JNIEnv* env, SkBitmap* bitmap, bool isMutable,
55 jbyteArray ninePatch, int density = -1);
57 static jobject createRegion(JNIEnv* env, SkRegion* region);
59 static jobject createLargeBitmap(JNIEnv* env, SkLargeBitmap* bitmap);
61 /** Set a pixelref for the bitmap (needs setConfig to already be called)
62 Returns true on success. If it returns false, then it failed, and the
63 appropriate exception will have been raised.
65 static bool setJavaPixelRef(JNIEnv*, SkBitmap*, SkColorTable* ctable,
68 /** Copy the colors in colors[] to the bitmap, convert to the correct
71 static bool SetPixels(JNIEnv* env, jintArray colors, int srcOffset,
72 int srcStride, int x, int y, int width, int height,
73 const SkBitmap& dstBitmap);
76 class JavaPixelAllocator : public SkBitmap::Allocator {
78 JavaPixelAllocator(JNIEnv* env, bool reportSizeToVM);
80 virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
87 class JavaMemoryUsageReporter : public SkVMMemoryReporter {
89 JavaMemoryUsageReporter(JNIEnv* env);
90 virtual ~JavaMemoryUsageReporter();
92 virtual bool reportMemory(size_t memorySize);
104 class AutoJavaFloatArray {
106 AutoJavaFloatArray(JNIEnv* env, jfloatArray array,
107 int minLength = 0, JNIAccess = kRW_JNIAccess);
108 ~AutoJavaFloatArray();
110 float* ptr() const { return fPtr; }
111 int length() const { return fLen; }
121 class AutoJavaIntArray {
123 AutoJavaIntArray(JNIEnv* env, jintArray array, int minLength = 0);
126 jint* ptr() const { return fPtr; }
127 int length() const { return fLen; }
136 class AutoJavaShortArray {
138 AutoJavaShortArray(JNIEnv* env, jshortArray array,
139 int minLength = 0, JNIAccess = kRW_JNIAccess);
140 ~AutoJavaShortArray();
142 jshort* ptr() const { return fPtr; }
143 int length() const { return fLen; }
153 class AutoJavaByteArray {
155 AutoJavaByteArray(JNIEnv* env, jbyteArray array, int minLength = 0);
156 ~AutoJavaByteArray();
158 jbyte* ptr() const { return fPtr; }
159 int length() const { return fLen; }
168 void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL);
169 void doThrowNPE(JNIEnv* env);
170 void doThrowAIOOBE(JNIEnv* env); // Array Index Out Of Bounds Exception
171 void doThrowIAE(JNIEnv* env, const char* msg = NULL); // Illegal Argument
172 void doThrowRE(JNIEnv* env, const char* msg = NULL); // Runtime
173 void doThrowISE(JNIEnv* env, const char* msg = NULL); // Illegal State
174 void doThrowOOME(JNIEnv* env, const char* msg = NULL); // Out of memory
175 void doThrowIOE(JNIEnv* env, const char* msg = NULL); // IO Exception
177 #define NPE_CHECK_RETURN_ZERO(env, object) \
178 do { if (NULL == (object)) { doThrowNPE(env); return 0; } } while (0)
180 #define NPE_CHECK_RETURN_VOID(env, object) \
181 do { if (NULL == (object)) { doThrowNPE(env); return; } } while (0)