OSDN Git Service

[changed] improved stubs. JNI bridge complete. All that's left is implementing the...
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 17 Dec 2010 16:42:54 +0000 (16:42 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 17 Dec 2010 16:42:54 +0000 (16:42 +0000)
gdx/jni/gdx2d/Gdx2DPixmap.cpp
gdx/jni/gdx2d/Gdx2DPixmap.h
gdx/jni/gdx2d/gdx2d.c
gdx/jni/gdx2d/gdx2d.h
gdx/src/com/badlogic/gdx/graphics/Gdx2DPixmap.java
gdx/windows/gdx.dll

index 14b32d1..c506af9 100644 (file)
@@ -7,8 +7,23 @@
  * Signature: ([J[BII)Ljava/nio/ByteBuffer;\r
  */\r
 JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_load\r
-  (JNIEnv *, jclass, jlongArray, jbyteArray, jint, jint) {\r
-\r
+  (JNIEnv *env, jclass, jlongArray nativeData, jbyteArray buffer, jint len, jint req_format) {\r
+       char* p_buffer = (char*)env->GetPrimitiveArrayCritical(buffer, 0);\r
+       gdx2d_pixmap* pixmap = gdx2d_load(p_buffer, len, req_format);\r
+       env->ReleasePrimitiveArrayCritical(buffer, p_buffer, 0);\r
+\r
+       if(pixmap==0)\r
+               return 0;\r
+\r
+       jobject pixel_buffer = env->NewDirectByteBuffer((void*)pixmap->pixels, pixmap->width * pixmap->height * pixmap->format);\r
+       long* p_native_data = (long*)env->GetPrimitiveArrayCritical(nativeData, 0);\r
+       p_native_data[0] = (long)pixmap;\r
+       p_native_data[1] = pixmap->width;\r
+       p_native_data[2] = pixmap->height;\r
+       p_native_data[3] = pixmap->format;\r
+       env->ReleasePrimitiveArrayCritical(nativeData, p_native_data, 0);\r
+\r
+       return pixel_buffer;\r
 }\r
 \r
 /*\r
@@ -17,8 +32,20 @@ JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_load
  * Signature: ([JIII)Ljava/nio/ByteBuffer;\r
  */\r
 JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_newPixmap\r
-  (JNIEnv *, jclass, jlongArray, jint, jint, jint) {\r
-\r
+  (JNIEnv *env, jclass, jlongArray nativeData, jint width, jint height, jint format) {\r
+       gdx2d_pixmap* pixmap = gdx2d_new(width, height, format);\r
+       if(pixmap==0)\r
+               return 0;\r
+\r
+       jobject pixel_buffer = env->NewDirectByteBuffer((void*)pixmap->pixels, pixmap->width * pixmap->height * pixmap->format);\r
+       long* p_native_data = (long*)env->GetPrimitiveArrayCritical(nativeData, 0);\r
+       p_native_data[0] = (long)pixmap;\r
+       p_native_data[1] = pixmap->width;\r
+       p_native_data[2] = pixmap->height;\r
+       p_native_data[3] = pixmap->format;\r
+       env->ReleasePrimitiveArrayCritical(nativeData, p_native_data, 0);\r
+\r
+       return pixel_buffer;\r
 }\r
 \r
 /*\r
@@ -27,8 +54,8 @@ JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_newPixmap
  * Signature: (J)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_free\r
-  (JNIEnv *, jclass, jlong) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap) {\r
+       gdx2d_free((gdx2d_pixmap*)pixmap);\r
 }\r
 \r
 /*\r
@@ -37,8 +64,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_free
  * Signature: (JI)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_clear\r
-  (JNIEnv *, jclass, jlong, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint color) {\r
+       gdx2d_clear((gdx2d_pixmap*)pixmap, color);\r
 }\r
 \r
 /*\r
@@ -47,8 +74,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_clear
  * Signature: (JIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setPixel\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint color) {\r
+       gdx2d_set_pixel((gdx2d_pixmap*)pixmap, x, y, color);\r
 }\r
 \r
 /*\r
@@ -57,8 +84,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setPixel
  * Signature: (JIIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawLine\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint x2, jint y2, jint color) {\r
+       gdx2d_draw_line((gdx2d_pixmap*)pixmap, x, y, x2, y2, color);\r
 }\r
 \r
 /*\r
@@ -67,8 +94,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawLine
  * Signature: (JIIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawRect\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint width, jint height, jint color) {\r
+       gdx2d_draw_rect((gdx2d_pixmap*)pixmap, x, y, width, height, color);\r
 }\r
 \r
 /*\r
@@ -77,8 +104,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawRect
  * Signature: (JIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawCircle\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint radius, jint color) {\r
+       gdx2d_draw_circle((gdx2d_pixmap*)pixmap, x, y, radius, color);\r
 }\r
 \r
 /*\r
@@ -87,8 +114,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawCircle
  * Signature: (JIIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillRect\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint width, jint height, jint color) {\r
+       gdx2d_fill_rect((gdx2d_pixmap*)pixmap, x, y, width, height, color);\r
 }\r
 \r
 /*\r
@@ -97,8 +124,8 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillRect
  * Signature: (JIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle\r
-  (JNIEnv *, jclass, jlong, jint, jint, jint, jint) {\r
-\r
+  (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint radius, jint color) {\r
+       gdx2d_fill_circle((gdx2d_pixmap*)pixmap, x, y, radius, color);\r
 }\r
 \r
 /*\r
@@ -107,6 +134,26 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle
  * Signature: (JJIIIIIIIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap\r
-  (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint) {\r
+  (JNIEnv *, jclass, jlong src, jlong dst, jint src_x, jint src_y, jint src_width, jint src_height, jint dst_x, jint dst_y, jint dst_width, jint dst_height) {\r
+       gdx2d_draw_pixmap((gdx2d_pixmap*)src, (gdx2d_pixmap*)dst, src_x, src_y, src_width, src_height, dst_x, dst_y, dst_width, dst_height);\r
+}\r
 \r
+/*\r
+ * Class:     com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method:    setBlend\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setBlend\r
+  (JNIEnv *, jclass, jint blend) {\r
+       gdx2d_set_blend(blend);\r
+}\r
+\r
+/*\r
+ * Class:     com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method:    setScale\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setScale\r
+  (JNIEnv *, jclass, jint scale) {\r
+       gdx2d_set_scale(scale);\r
 }\r
index 760f9c4..236de18 100644 (file)
@@ -98,10 +98,26 @@ JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle
 /*\r
  * Class:     com_badlogic_gdx_graphics_Gdx2DPixmap\r
  * Method:    drawPixmap\r
- * Signature: (JJIIIIIIIIII)V\r
+ * Signature: (JJIIIIIIII)V\r
  */\r
 JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap\r
-  (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint);\r
+  (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint);\r
+\r
+/*\r
+ * Class:     com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method:    setBlend\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setBlend\r
+  (JNIEnv *, jclass, jint);\r
+\r
+/*\r
+ * Class:     com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method:    setScale\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setScale\r
+  (JNIEnv *, jclass, jint);\r
 \r
 #ifdef __cplusplus\r
 }\r
index d844f80..0fb015e 100644 (file)
 #include "gdx2d.h"\r
 #define STB_TRUETYPE_IMPLEMENTATION\r
 #define STBI_HEADER_FILE_ONLY\r
+#define STBI_NO_FAILURE_STRINGS\r
 #include "stb_image.c"\r
 #include "stb_truetype.h"\r
+\r
+static int gdx2d_blend = GDX2D_BLEND_NONE;\r
+static int gdx2d_scale = GDX2D_SCALE_NEAREST;\r
+\r
+gdx2d_pixmap* gdx2d_load(const char *buffer, int len, int req_format) {\r
+       int width, height, format;\r
+       const char* pixels = stbi_load_from_memory(buffer, len, &width, &height, &format, req_format);\r
+       if(pixels == NULL)\r
+               return NULL;\r
+\r
+       gdx2d_pixmap* pixmap = (gdx2d_pixmap*)malloc(sizeof(gdx2d_pixmap));\r
+       pixmap->width = width;\r
+       pixmap->height = height;\r
+       pixmap->format = format;\r
+       pixmap->pixels = pixels;\r
+       return pixmap;\r
+}\r
+\r
+gdx2d_pixmap* gdx2d_new(int width, int height, int format) {\r
+       gdx2d_pixmap* pixmap = (gdx2d_pixmap*)malloc(sizeof(gdx2d_pixmap));\r
+       pixmap->width = width;\r
+       pixmap->height = height;\r
+       pixmap->format = format;\r
+       pixmap->pixels = (char*)malloc(width * height * format);\r
+       return pixmap;\r
+}\r
+void gdx2d_free(const gdx2d_pixmap* pixmap) {\r
+       free((void*)pixmap->pixels);\r
+       free((void*)pixmap);\r
+}\r
+\r
+void gdx2d_set_blend (int blend) {\r
+       gdx2d_blend = blend;\r
+}\r
+\r
+void gdx2d_set_scale (int scale) {\r
+       gdx2d_scale = scale;\r
+}\r
+\r
+void gdx2d_clear(const gdx2d_pixmap* pixmap, int col) {\r
+\r
+}\r
+\r
+void gdx2d_set_pixel(const gdx2d_pixmap* pixmap, int x, int y, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) {\r
+\r
+}\r
+\r
+void gdx2d_fill_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) {\r
+\r
+}\r
+\r
+void gdx2d_fill_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_pixmap(const gdx2d_pixmap* src_pixmap, const gdx2d_pixmap* dst_pixmap,\r
+                                          int src_x, int src_y, int src_width, int src_height,\r
+                                          int dst_x, int dst_y, int dst_width, int dst_height) {\r
+\r
+}\r
index 93c2401..5270af5 100644 (file)
@@ -45,32 +45,31 @@ extern "C" {
  * the dimensions and the format of the pixmap.\r
  * the format is one of the GDX2D_FORMAT_XXX constants.\r
  */\r
-struct {\r
+typedef struct {\r
        int width;\r
        int height;\r
        int format;\r
        const char* pixels;\r
-} gdx2d_pixmap_struct;\r
-typedef struct gdx2d_pixmap_struct gdx2d_pixmap;\r
+} gdx2d_pixmap;\r
 \r
+extern gdx2d_pixmap* gdx2d_load (const char *buffer, int len, int req_format);\r
+extern gdx2d_pixmap* gdx2d_new  (int width, int height, int format);\r
+extern void             gdx2d_free (const gdx2d_pixmap* pixmap);\r
 \r
-gdx2d_pixmap*  gdx2d_load_buffer       (const char *buffer, int len, int req_format);\r
-gdx2d_pixmap*  gdx2d_load_file         (const char *filename, int req_format);\r
-gdx2d_pixmap*  gdx2d_new                       (int width, int height, int format);\r
-void                   gdx2d_free                      (const gdx2d_pixmap* pixmap);\r
+extern void gdx2d_set_blend      (int blend);\r
+extern void gdx2d_set_scale      (int scale);\r
 \r
-void gdx2d_clear               (const gdx2d_pixmap* pixmap, int col);\r
-void gdx2d_set_pixel   (const gdx2d_pixmap* pixmap, int x, int y, int col);\r
-void gdx2d_draw_line   (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col);\r
-void gdx2d_draw_rect   (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
-void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_fill_rect   (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap,\r
-                                                const gdx2d_pixmap* dst_pixmap,\r
-                                                int src_x, int src_y, int src_width, int src_height,\r
-                                                int dst_x, int dst_y, int dst_width, int dst_height,\r
-                                                int blend, int scale);\r
+extern void gdx2d_clear                  (const gdx2d_pixmap* pixmap, int col);\r
+extern void gdx2d_set_pixel   (const gdx2d_pixmap* pixmap, int x, int y, int col);\r
+extern void gdx2d_draw_line   (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col);\r
+extern void gdx2d_draw_rect   (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
+extern void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
+extern void gdx2d_fill_rect   (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
+extern void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
+extern void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap,\r
+                                                          const gdx2d_pixmap* dst_pixmap,\r
+                                                          int src_x, int src_y, int src_width, int src_height,\r
+                                                          int dst_x, int dst_y, int dst_width, int dst_height);\r
 \r
 #ifdef __cplusplus\r
 }\r
index 0afad17..fac5451 100644 (file)
@@ -100,9 +100,8 @@ public class Gdx2DPixmap {
        \r
        private void drawPixmap(Gdx2DPixmap src, \r
                                                        int srcX, int srcY, int srcWidth, int srcHeight, \r
-                                                       int dstX, int dstY, int dstWidth, int dstHeight, \r
-                                                       int blend, int scale) {\r
-               drawPixmap(src.basePtr, basePtr, srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight, blend, scale);\r
+                                                       int dstX, int dstY, int dstWidth, int dstHeight) {\r
+               drawPixmap(src.basePtr, basePtr, srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight);\r
        }\r
        \r
        \r
@@ -132,5 +131,8 @@ public class Gdx2DPixmap {
        private static native void drawCircle(long pixmap, int x, int y, int radius, int color);\r
        private static native void fillRect(long pixmap, int x, int y, int width, int height, int color);\r
        private static native void fillCircle(long pixmap, int x, int y, int radius, int color);\r
-       private static native void drawPixmap(long src, long dst, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int blend, int scale);\r
+       private static native void drawPixmap(long src, long dst, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight);\r
+       \r
+       public static native void setBlend(int blend);\r
+       public static native void setScale(int scale);\r
 }\r
index b45725c..973652a 100644 (file)
Binary files a/gdx/windows/gdx.dll and b/gdx/windows/gdx.dll differ