JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_beginRenderingIIIII(JNIEnv* env, jobject objectHandle, jint minX, jint minY, jint width, jint height, jint windingRule) { Renderer* rdr; Surface* surface; jobject surfaceHandle; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); SURFACE_FROM_RENDERER(surface, env, surfaceHandle, objectHandle); ACQUIRE_SURFACE(surface, env, surfaceHandle); INVALIDATE_RENDERER_SURFACE(rdr); renderer_beginRendering5(rdr, minX, minY, width, height, windingRule); RELEASE_SURFACE(surface, env, surfaceHandle); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setRadialGradientImpl(JNIEnv* env, jobject objectHandle, jint cx, jint cy, jint fx, jint fy, jint radius, jintArray rampHandle, jint cycleMethod, jobject transformHandle) { Renderer* rdr; Transform6 gradientTransform; jint *ramp; ramp = (jint*)(*env)->GetPrimitiveArrayCritical(env, rampHandle, NULL); if (ramp != NULL) { transform_get6(&gradientTransform, env, transformHandle); rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); rdr->_gradient_cycleMethod = cycleMethod; renderer_setRadialGradient(rdr, cx, cy, fx, fy, radius, ramp, &gradientTransform); (*env)->ReleasePrimitiveArrayCritical(env, rampHandle, ramp, 0); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } else { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of renderer memory for gradient failed."); } }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_AbstractSurface_drawSurfaceImpl() { KNI_StartHandles(2); KNI_DeclareHandle(objectHandle); KNI_DeclareHandle(surfaceHandle); jint srcX = KNI_GetParameterAsInt(2); jint srcY = KNI_GetParameterAsInt(3); jint dstX = KNI_GetParameterAsInt(4); jint dstY = KNI_GetParameterAsInt(5); jint width = KNI_GetParameterAsInt(6); jint height = KNI_GetParameterAsInt(7); jfloat opacity = KNI_GetParameterAsFloat(8); Surface* dstSurface; Surface* srcSurface; KNI_GetThisPointer(objectHandle); dstSurface = (Surface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); KNI_GetParameterAsObject(1, surfaceHandle); srcSurface = (Surface*)JLongToPointer( KNI_GetLongField(surfaceHandle, fieldIds[SURFACE_NATIVE_PTR])); CORRECT_DIMS(dstSurface, dstX, dstY, width, height, srcX, srcY); CORRECT_DIMS(srcSurface, srcX, srcY, width, height, dstX, dstY); if ((width > 0) && (height > 0) && (opacity > 0)) { ACQUIRE_SURFACE(dstSurface, objectHandle); ACQUIRE_SURFACE(srcSurface, surfaceHandle); surface_drawSurface(dstSurface, dstX, dstY, width, height, srcSurface, srcX, srcY, opacity); RELEASE_SURFACE(srcSurface, surfaceHandle); RELEASE_SURFACE(dstSurface, objectHandle); } KNI_EndHandles(); KNI_ReturnVoid(); }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_end(JNIEnv* env, jobject objectHandle) { Renderer* rdr; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); renderer_end(rdr); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_getBoundingBox(JNIEnv* env, jobject objectHandle, jintArray bbox) { Renderer* rdr; jint bb[4]; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); bb[0] = rdr->_bboxX0; bb[1] = rdr->_bboxY0; bb[2] = rdr->_bboxX1 - rdr->_bboxX0; bb[3] = rdr->_bboxY1 - rdr->_bboxY0; (*env)->SetIntArrayRegion(env, bbox, 0, 4, bb); }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_AbstractSurface_drawRGBImpl() { KNI_StartHandles(2); KNI_DeclareHandle(objectHandle); KNI_DeclareHandle(arrayHandle); jint offset = KNI_GetParameterAsInt(2); jint scanLength = KNI_GetParameterAsInt(3); jint x = KNI_GetParameterAsInt(4); jint y = KNI_GetParameterAsInt(5); jint width = KNI_GetParameterAsInt(6); jint height = KNI_GetParameterAsInt(7); jfloat opacity = KNI_GetParameterAsFloat(8); jint srcX = 0; jint srcY = 0; Surface* surface; KNI_GetParameterAsObject(1, arrayHandle); KNI_GetThisPointer(objectHandle); surface = (Surface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); CORRECT_DIMS(surface, x, y, width, height, srcX, srcY); if ((width > 0) && (height > 0)) { jint* tempArray; offset += srcY * scanLength + srcX; SNI_BEGIN_RAW_POINTERS; tempArray = &JavaIntArray(arrayHandle)[offset]; ACQUIRE_SURFACE(surface, objectHandle); surface_drawRGB(surface, x, y, width, height, tempArray, scanLength, opacity); RELEASE_SURFACE(surface, objectHandle); SNI_END_RAW_POINTERS; } KNI_EndHandles(); KNI_ReturnVoid(); }
static void disposeNativeImpl(JNIEnv* env, jobject objectHandle) { Renderer* rdr; if (!fieldIdsInitialized) { return; } rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); if (rdr != NULL) { renderer_dispose(rdr); (*env)->SetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR], (jlong)0); } }
KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_pisces_AbstractSurface_getHeight() { jint height; KNI_StartHandles(1); KNI_DeclareHandle(objectHandle); Surface* surface; KNI_GetThisPointer(objectHandle); surface = (Surface*)JLongToPointer(KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); height = surface->height; KNI_EndHandles(); KNI_ReturnInt(height); }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_drawLine(JNIEnv* env, jobject objectHandle, jint x0, jint y0, jint x1, jint y1) { Renderer* rdr; Surface* surface; jobject surfaceHandle; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); SURFACE_FROM_RENDERER(surface, env, surfaceHandle, objectHandle); ACQUIRE_SURFACE(surface, env, surfaceHandle); INVALIDATE_RENDERER_SURFACE(rdr); renderer_drawLine(rdr, x0, y0, x1, y1); RELEASE_SURFACE(surface, env, surfaceHandle); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } }
void surface_finalize(jobject objectHandle) { AbstractSurface* surface; if (!fieldIdsInitialized) { return; } surface = (AbstractSurface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); if (surface != NULL) { surface->cleanup(surface); surface_dispose(&surface->super); KNI_SetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR], (jlong)0); if (KNI_TRUE == readAndClearMemErrorFlag()) { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setStrokeImpl(JNIEnv* env, jobject objectHandle, jint lineWidth, jint capStyle, jint joinStyle, jint miterLimit, jintArray arrayHandle, jint dashPhase) { jint* dashArray = NULL; jint dashArray_length = 0; Renderer* rdr; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); if (arrayHandle != NULL) { jsize length = (*env)->GetArrayLength(env, arrayHandle); dashArray = (jint*)PISCESmalloc(length * sizeof(jint)); //NOTE : dashArray is freed at finalization time by renderer_dispose() if (NULL == dashArray) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of renderer memory for stroke data failed."); } else { (*env)->GetIntArrayRegion(env, arrayHandle, 0, length, dashArray); dashArray_length = length; } } renderer_setStroke6(rdr, lineWidth, capStyle, joinStyle, miterLimit, dashArray, dashArray_length, dashPhase); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } }
Renderer* renderer_get(JNIEnv* env, jobject objectHandle) { return (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setPathData(JNIEnv* env, jobject objectHandle, jfloatArray dataHandle, jbyteArray commandsHandle, jint nCommands) { jint idx; Renderer* rdr; jfloat* data = NULL; jbyte* commands = NULL; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); data = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, dataHandle, NULL); commands = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, commandsHandle, NULL); if ((data != NULL) && (commands != NULL)) { jint offset = 0; for (idx = 0; idx < nCommands; ++idx) { switch (commands[idx]) { case CMD_MOVE_TO: renderer_moveTo(rdr, (jint)(data[offset] * 65536.0f), (jint)(data[offset + 1] * 65536.0f)); offset += 2; break; case CMD_LINE_TO: renderer_lineTo(rdr, (jint)(data[offset] * 65536.0f), (jint)(data[offset + 1] * 65536.0f)); offset += 2; break; case CMD_QUAD_TO: renderer_quadTo(rdr, (jint)(data[offset] * 65536.0f), (jint)(data[offset + 1] * 65536.0f), (jint)(data[offset + 2] * 65536.0f), (jint)(data[offset + 3] * 65536.0f)); offset += 4; break; case CMD_CURVE_TO: renderer_cubicTo(rdr, (jint)(data[offset] * 65536.0f), (jint)(data[offset + 1] * 65536.0f), (jint)(data[offset + 2] * 65536.0f), (jint)(data[offset + 3] * 65536.0f), (jint)(data[offset + 4] * 65536.0f), (jint)(data[offset + 5] * 65536.0f)); offset += 6; break; case CMD_CLOSE: default: renderer_close(rdr); break; } } } else { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", ""); } if (data != NULL) { (*env)->ReleasePrimitiveArrayCritical(env, dataHandle, data, 0); } if (commands != NULL) { (*env)->ReleasePrimitiveArrayCritical(env, commandsHandle, commands, 0); } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setTextureImpl(JNIEnv* env, jobject objectHandle, jint imageType, jintArray arrayHandle, jint width, jint height, jint offset, jint stride, jobject transformHandle, jboolean repeat) { Renderer* rdr; jint* data; Transform6 textureTransform; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); data = (jint*)PISCESmalloc((width + 2) * (height + 2) * sizeof(jint)); //NOTE : data is freed at finalization time by renderer_dispose() if (NULL == data) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of renderer memory for texture failed."); } else { jint size = width * sizeof(jint); jint dadd = width + 2; jint* dest = data + dadd; jint h2 = height; jint copyToFirstCol; jint copyToLastCol; jint copyToFirstRow; jint copyToLastRow; /* prepare additional pixels for interpolation */ if (repeat) { copyToFirstCol = width - 1; copyToLastCol = 0; copyToFirstRow = height - 1; copyToLastRow = 0; } else { copyToFirstCol = 0; copyToLastCol = width - 1; copyToFirstRow = 0; copyToLastRow = height - 1; } for (; h2 > 0; --h2) { (*env)->GetIntArrayRegion(env, arrayHandle, offset, width, dest + 1); dest[0] = dest[copyToFirstCol + 1]; dest[width + 1] = dest[copyToLastCol + 1]; dest += dadd; offset += stride; } memcpy(data, data + (copyToFirstRow + 1) * (width + 2), size + 2 * sizeof(jint)); memcpy(dest, data + (copyToLastRow + 1) * (width + 2), size + 2 * sizeof(jint)); transform_get6(&textureTransform, env, transformHandle); renderer_setTexture(rdr, data, width, height, repeat, &textureTransform); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_AbstractSurface_getRGB() { KNI_StartHandles(2); KNI_DeclareHandle(objectHandle); KNI_DeclareHandle(arrayHandle); jint offset = KNI_GetParameterAsInt(2); jint scanLength = KNI_GetParameterAsInt(3); jint x = KNI_GetParameterAsInt(4); jint y = KNI_GetParameterAsInt(5); jint width = KNI_GetParameterAsInt(6); jint height = KNI_GetParameterAsInt(7); jint dstX = 0; jint dstY = 0; Surface* surface; KNI_GetParameterAsObject(1, arrayHandle); KNI_GetThisPointer(objectHandle); surface = (Surface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); CORRECT_DIMS(surface, x, y, width, height, dstX, dstY); if ((width > 0) && (height > 0)) { jint size = ((height - 1) * scanLength + width) * sizeof(jint); jint* tempArray = (jint*)PISCESmalloc(size); if (NULL == tempArray) { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of temporary renderer memory buffer failed."); } else { jint* src; jint* dst; jint srcScanRest = surface->width - width; jint dstScanRest = scanLength - width; ACQUIRE_SURFACE(surface, objectHandle); src = (jint*)surface->data + y * surface->width + x; dst = tempArray; for (; height > 0; --height) { jint w2 = width; for (; w2 > 0; --w2) { *dst++ = *src++; } src += srcScanRest; dst += dstScanRest; } offset += dstY * scanLength + dstX; KNI_SetRawArrayRegion(arrayHandle, offset * sizeof(jint), size, (const jbyte*)tempArray); RELEASE_SURFACE(surface, objectHandle); PISCESfree(tempArray); } } KNI_EndHandles(); KNI_ReturnVoid(); }
AbstractSurface* surface_get(jobject surfaceHandle) { return (AbstractSurface*)JLongToPointer( KNI_GetLongField(surfaceHandle, fieldIds[SURFACE_NATIVE_PTR])); }