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.");
    }
}
JNIEXPORT void JNICALL
Java_com_sun_pisces_PiscesRenderer_initialize(JNIEnv* env,
                                              jobject objectHandle) {
    Renderer* rdr;
    Surface* surface;
    jboolean sfieldsOK;

    sfieldsOK = initializeRendererFieldIds(env, objectHandle);
    if (sfieldsOK) {
        jobject surfaceHandle = (*env)->GetObjectField(env, objectHandle,
                                fieldIds[RENDERER_SURFACE]);
        surface = &surface_get(env, surfaceHandle)->super;

        rdr = renderer_create(surface);

        (*env)->SetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR],
                             PointerToJLong(rdr));
        if (JNI_TRUE == readAndClearMemErrorFlag()) {
            JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                         "Allocation of internal renderer buffer failed!!!");
        }

    } else {
        JNI_ThrowNew(env, "java/lang/IllegalStateException", "");
    }
}
JNIEXPORT void JNICALL
Java_com_sun_pisces_PiscesRenderer_staticInitialize(JNIEnv* env,
        jclass classHandle, jint xbias, jint ybias) {
    piscesutil_setStrokeBias(xbias, ybias);
    if (JNI_TRUE == readAndClearMemErrorFlag()) {
        JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                     "Allocation of internal renderer buffer failed.");
    } else {
        if (!pisces_moduleInitialize()) {
            JNI_ThrowNew(env, "java/lang/IllegalStateException", "");
        }
    }
}
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.");
    }
}
Exemple #5
0
static void
surface_acquire(AbstractSurface* surface, JNIEnv* env, jobject surfaceHandle) {
    jint width = 0;
    jint height = 0;
    jint dataArrayLength = 0;

    ((JavaSurface *) surface)->dataHandle = (*env)->GetObjectField(env, surfaceHandle,
                                ((JavaSurface *) surface)->javaArrayFieldID);

    dataArrayLength = (*env)->GetArrayLength(env, ((JavaSurface *) surface)->dataHandle);

    width = surface->super.width;
    height = surface->super.height;
    if (width < 0 || height < 0 || dataArrayLength / width < height) {
        // Set data to NULL indicating invalid width and height
        surface->super.data = NULL;
        ((JavaSurface *) surface)->dataHandle = NULL;
        JNI_ThrowNew(env, "java/lang/IllegalArgumentException", "Out of range access of buffer");
        return;
    }

    surface->super.data =
        (void *)(*env)->GetPrimitiveArrayCritical(env, ((JavaSurface *) surface)->dataHandle, NULL);
    if (surface->super.data == NULL) {
        ((JavaSurface *) surface)->dataHandle = NULL;
        setMemErrorFlag();
    }
}
JNIEXPORT void JNICALL
Java_com_sun_pisces_NativeSurface_initialize(JNIEnv* env, jobject objectHandle, 
        jint dataType, jint width, jint height) {

    AbstractSurface* surface;

    if (surface_initialize(env, objectHandle)
            && initializeSurfaceFieldIds(env, objectHandle)) {
        surface = my_malloc(AbstractSurface, 1);
        if (surface != NULL) {
            jint size = width * height * sizeof(jint);
            jint* data = (jint*)PISCESmalloc(size);
            if (data != NULL) {
                memset(data, 0, size);

                surface->super.width = width;
                surface->super.height = height;
                surface->super.offset = 0;
                surface->super.scanlineStride = width;
                surface->super.pixelStride = 1;
                surface->super.imageType = dataType;
                surface->super.data = data;
                
                surface->acquire = surface_acquire;
                surface->release = surface_release;
                surface->cleanup = surface_cleanup;

                (*env)->SetLongField(env, objectHandle, fieldIds[SURFACE_NATIVE_PTR],
                                 PointerToJLong(surface));
                //    KNI_registerCleanup(objectHandle, disposeNativeImpl);

            } else {
                JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                             "Allocation of internal renderer buffer failed.");
            }
        } else {
            JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                         "Allocation of internal renderer buffer failed.");
        }
    } else {
        JNI_ThrowNew(env, "java/lang/IllegalStateException", "");
    }

}
JNIEXPORT void JNICALL
Java_com_sun_pisces_PiscesRenderer_nativeFinalize(JNIEnv* env,
        jobject objectHandle) {
    disposeNativeImpl(env, objectHandle);

    if (JNI_TRUE == readAndClearMemErrorFlag()) {
        JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                     "Allocation of internal renderer buffer failed.");
    }
}
Exemple #8
0
/*
 * Class:     com_sun_pisces_JavaSurface
 * Method:    initialize
 * Signature: (III)V
 */
JNIEXPORT void JNICALL
Java_com_sun_pisces_JavaSurface_initialize
  (JNIEnv *env, jobject objectHandle, jint dataType, jint width, jint height)
{
    if (surface_initialize(env, objectHandle)
            && initializeSurfaceFieldIds(env, objectHandle))
    {
        // NOTE: when is this freed?
        JavaSurface* jSurface = my_malloc(JavaSurface, 1);
        AbstractSurface* surface = &jSurface->super;
        if (surface != NULL) {
            surface->super.width = width;
            surface->super.height = height;
            surface->super.offset = 0;
            surface->super.scanlineStride = width;
            surface->super.pixelStride = 1;
            surface->super.imageType = dataType;

            surface->acquire = surface_acquire;
            surface->release = surface_release;
            surface->cleanup = surface_cleanup;

            switch(surface->super.imageType){
                case TYPE_INT_ARGB_PRE:
                    jSurface->javaArrayFieldID = fieldIds[SURFACE_DATA_INT];
                    break;
                default: //errorneous - should never happen
                    jSurface->javaArrayFieldID = NULL;
            }

            (*env)->SetLongField(env, objectHandle, fieldIds[SURFACE_NATIVE_PTR],
                                PointerToJLong(jSurface));
            //    JNI_registerCleanup(objectHandle, disposeNativeImpl);
        } else {
            JNI_ThrowNew(env, "java/lang/OutOfMemoryError",
                         "Allocation of internal renderer buffer failed.");
        }
    } else {
        JNI_ThrowNew(env, "java/lang/IllegalStateException", "");
    }
}
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_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.");
    }
}
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.");
    }
}
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.");
        }
    }
}