예제 #1
0
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.");
    }
}
예제 #2
0
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", "");
    }
}
예제 #3
0
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.");
    }
}
예제 #4
0
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.");
    }
}
예제 #5
0
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", "");
        }
    }
}
예제 #6
0
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.");
    }
}
예제 #7
0
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.");
    }
}
예제 #8
0
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.");
        }
    }
}
예제 #9
0
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.");
    }
}
예제 #10
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.");
        }
    }
}