Beispiel #1
0
/*
 * Class:     sun_java2d_x11_X11Renderer
 * Method:    XDrawPoly
 * Signature: (IJII[I[IIZ)V
 */
JNIEXPORT void JNICALL Java_sun_java2d_x11_X11Renderer_XDrawPoly
    (JNIEnv *env, jobject xr,
     jlong pXSData, jlong xgc,
     jint transx, jint transy,
     jintArray xcoordsArray, jintArray ycoordsArray, jint npoints,
     jboolean isclosed)
{
#ifndef HEADLESS
    XPoint pTmp[POLYTEMPSIZE], *points;
    X11SDOps *xsdo = (X11SDOps *) pXSData;

    if (xsdo == NULL) {
        return;
    }

    if (JNU_IsNull(env, xcoordsArray) || JNU_IsNull(env, ycoordsArray)) {
        JNU_ThrowNullPointerException(env, "coordinate array");
        return;
    }
    if ((*env)->GetArrayLength(env, ycoordsArray) < npoints ||
        (*env)->GetArrayLength(env, xcoordsArray) < npoints)
    {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "coordinate array");
        return;
    }

    if (npoints < 2) {
        return;
    }

    points = transformPoints(env, xcoordsArray, ycoordsArray, transx, transy,
                             pTmp, (int *)&npoints, isclosed);
    if (points == 0) {
        JNU_ThrowOutOfMemoryError(env, "translated coordinate array");
    } else {
        if (npoints == 2) {
            /*
             * Some X11 implementations fail to draw anything for
             * simple 2 point polygons where the vertices are the
             * same point even though this violates the X11
             * specification.  For simplicity we will dispatch all
             * 2 point polygons through XDrawLine even if they are
             * non-degenerate as this may invoke less processing
             * down the line than a Poly primitive anyway.
             */
            XDrawLine(awt_display, xsdo->drawable, (GC) xgc,
                      points[0].x, points[0].y,
                      points[1].x, points[1].y);
        } else {
            XDrawLines(awt_display, xsdo->drawable, (GC) xgc,
                       points, npoints, CoordModeOrigin);
        }
        if (points != pTmp) {
            free(points);
        }
        X11SD_DirectRenderNotify(env, xsdo);
    }
#endif /* !HEADLESS */
}
int putGV(JNIEnv* env, jint gmask, jint baseIndex, jobject gvdata, const LayoutEngine* engine, int glyphCount) {
    int count = env->GetIntField(gvdata, gvdCountFID);

    jarray glyphArray = (jarray)env->GetObjectField(gvdata, gvdGlyphsFID);
    if (IS_NULL(glyphArray)) {
      JNU_ThrowInternalError(env, "glypharray null");
      return 0;
    }
    jint capacity = env->GetArrayLength(glyphArray);
    if (count + glyphCount > capacity) {
      JNU_ThrowArrayIndexOutOfBoundsException(env, "");
      return 0;
    }

    jarray posArray = (jarray)env->GetObjectField(gvdata, gvdPositionsFID);
    if (IS_NULL(glyphArray)) {
      JNU_ThrowInternalError(env, "positions array null");
      return 0;
    }
    jarray inxArray = (jarray)env->GetObjectField(gvdata, gvdIndicesFID);
    if (IS_NULL(inxArray)) {
      JNU_ThrowInternalError(env, "indices array null");
      return 0;
    }

    int countDelta = 0;

    // le_uint32 is the same size as jint... forever, we hope
    le_uint32* glyphs = (le_uint32*)env->GetPrimitiveArrayCritical(glyphArray, NULL);
    if (glyphs) {
      jfloat* positions = (jfloat*)env->GetPrimitiveArrayCritical(posArray, NULL);
      if (positions) {
        jint* indices = (jint*)env->GetPrimitiveArrayCritical(inxArray, NULL);
        if (indices) {
          LEErrorCode status = (LEErrorCode)0;
          engine->getGlyphs(glyphs + count, gmask, status);
          engine->getGlyphPositions(positions + (count * 2), status);
          engine->getCharIndices((le_int32*)(indices + count), baseIndex, status);

          countDelta = glyphCount;

          // !!! need engine->getFlags to signal positions, indices data
          /* "0" arg used instead of JNI_COMMIT as we want the carray
           * to be freed by any VM that actually passes us a copy.
           */
          env->ReleasePrimitiveArrayCritical(inxArray, indices, 0);
        }
        env->ReleasePrimitiveArrayCritical(posArray, positions, 0);
      }
      env->ReleasePrimitiveArrayCritical(glyphArray, glyphs, 0);
    }

    if (countDelta) {
      count += countDelta;
      env->SetIntField(gvdata, gvdCountFID, count);
    }

  return 1;
}
Beispiel #3
0
/*
 * Class:     sun_java2d_windows_GDIRenderer
 * Method:    doFillPoly
 * Signature: (Lsun/java2d/windows/GDIWindowSurfaceData;Lsun/java2d/pipe/Region;Ljava/awt/Composite;III[I[II)V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_windows_GDIRenderer_doFillPoly
    (JNIEnv *env, jobject wr,
     jobject sData,
     jobject clip, jobject comp, jint color,
     jint transx, jint transy,
     jintArray xpointsarray, jintArray ypointsarray,
     jint npoints)
{
    J2dTraceLn(J2D_TRACE_INFO, "GDIRenderer_doFillPoly");
    J2dTraceLn4(J2D_TRACE_VERBOSE,
                "  color=0x%x transx=%-4d transy=%-4d npoints=%-4d",
                color, transx, transy, npoints);
    if (JNU_IsNull(env, xpointsarray) || JNU_IsNull(env, ypointsarray)) {
        JNU_ThrowNullPointerException(env, "coordinate array");
        return;
    }
    if (env->GetArrayLength(xpointsarray) < npoints ||
        env->GetArrayLength(ypointsarray) < npoints)
    {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "coordinate array");
        return;
    }
    if (npoints < 3) {
        // Fix for 4067534 - assertion failure in 1.3.1 for degenerate polys
        // Not enough points for a triangle.
        // Note that this would be ignored later anyway, but returning
        // here saves us from mistakes in TransformPoly and seeing bad
        // return values from the Windows Polyline function.
        return;
    }

    GDIWinSDOps *wsdo = GDIWindowSurfaceData_GetOps(env, sData);
    if (wsdo == NULL) {
        return;
    }

    POINT tmpPts[POLYTEMPSIZE], *pPoints;
    jint *xpoints = (jint *) env->GetPrimitiveArrayCritical(xpointsarray, NULL);
    jint *ypoints = (jint *) env->GetPrimitiveArrayCritical(ypointsarray, NULL);
    pPoints = TransformPoly(xpoints, ypoints, transx, transy,
                            tmpPts, &npoints, FALSE, FALSE);
    env->ReleasePrimitiveArrayCritical(xpointsarray, xpoints, JNI_ABORT);
    env->ReleasePrimitiveArrayCritical(ypointsarray, ypoints, JNI_ABORT);
    if (pPoints == NULL) {
        return;
    }

    HDC hdc = wsdo->GetDC(env, wsdo, BRUSHONLY, NULL, clip, comp, color);
    if (hdc == NULL) {
        return;
    }
    ::SetPolyFillMode(hdc, ALTERNATE);
    ::Polygon(hdc, pPoints, npoints);
    wsdo->ReleaseDC(env, wsdo, hdc);
    if (pPoints != tmpPts) {
        free(pPoints);
    }
}
Beispiel #4
0
JNIEXPORT void JNICALL
Java_sun_java2d_pipe_SpanClipRenderer_fillTile
    (JNIEnv *env, jobject sr, jobject ri,
     jbyteArray alphaTile, jint offset, jint tsize, jintArray boxArray)
{
    jbyte *alpha;
    jint *box;
    jint w, h;
    jsize alphalen;

    if ((*env)->GetArrayLength(env, boxArray) < 4) {
	JNU_ThrowArrayIndexOutOfBoundsException(env, "band array");
    }
    alphalen = (*env)->GetArrayLength(env, alphaTile);

    box = (*env)->GetPrimitiveArrayCritical(env, boxArray, 0);

    w = box[2] - box[0];
    h = box[3] - box[1];

    if (alphalen < offset || (alphalen - offset) / tsize < h) {
	(*env)->ReleasePrimitiveArrayCritical(env, boxArray, box, 0);
	JNU_ThrowArrayIndexOutOfBoundsException(env, "alpha tile array");
    }

    alpha = (*env)->GetPrimitiveArrayCritical(env, alphaTile, 0);

    fill(alpha, offset, tsize, 0, 0, w, h, (jbyte) 0xff);

    (*env)->ReleasePrimitiveArrayCritical(env, alphaTile, alpha, 0);
    (*env)->ReleasePrimitiveArrayCritical(env, boxArray, box, 0);

    Java_sun_java2d_pipe_SpanClipRenderer_eraseTile(env, sr, ri,
						    alphaTile, offset, tsize,
						    boxArray);
}
Beispiel #5
0
/*
 * Class:     sun_java2d_x11_X11Renderer
 * Method:    XFillPoly
 * Signature: (IJII[I[II)V
 */
JNIEXPORT void JNICALL Java_sun_java2d_x11_X11Renderer_XFillPoly
    (JNIEnv *env, jobject xr,
     jlong pXSData, jlong xgc,
     jint transx, jint transy,
     jintArray xcoordsArray, jintArray ycoordsArray, jint npoints)
{
#ifndef HEADLESS
    XPoint pTmp[POLYTEMPSIZE], *points;
    X11SDOps *xsdo = (X11SDOps *) pXSData;

    if (xsdo == NULL) {
        return;
    }

    if (JNU_IsNull(env, xcoordsArray) || JNU_IsNull(env, ycoordsArray)) {
        JNU_ThrowNullPointerException(env, "coordinate array");
        return;
    }
    if ((*env)->GetArrayLength(env, ycoordsArray) < npoints ||
        (*env)->GetArrayLength(env, xcoordsArray) < npoints)
    {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "coordinate array");
        return;
    }

    if (npoints < 3) {
        return;
    }

    points = transformPoints(env, xcoordsArray, ycoordsArray, transx, transy,
                             pTmp, (int *)&npoints, JNI_FALSE);
    if (points == 0) {
        JNU_ThrowOutOfMemoryError(env, "translated coordinate array");
    } else {
        if (npoints > 2) {
            XFillPolygon(awt_display, xsdo->drawable, (GC) xgc,
                         points, npoints, Complex, CoordModeOrigin);
            X11SD_DirectRenderNotify(env, xsdo);
        }
        if (points != pTmp) {
            free(points);
        }
    }
#endif /* !HEADLESS */
}
Beispiel #6
0
/*
 * Class:     java_lang_reflect_Proxy
 * Method:    defineClass0
 * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;
 *
 * The implementation of this native static method is a copy of that of
 * the native instance method Java_java_lang_ClassLoader_defineClass0()
 * with the implicit "this" parameter becoming the "loader" parameter.
 */
JNIEXPORT jclass JNICALL
Java_java_lang_reflect_Proxy_defineClass0(JNIEnv *env,
                                          jclass ignore,
                                          jobject loader,
                                          jstring name,
                                          jbyteArray data,
                                          jint offset,
                                          jint length)
{
    jbyte *body;
    char *utfName;
    jclass result = 0;
    char buf[128];

    if (data == NULL) {
        JNU_ThrowNullPointerException(env, 0);
        return 0;
    }

    /* Work around 4153825. malloc crashes on Solaris when passed a
     * negative size.
     */
    if (length < 0) {
        JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
        return 0;
    }

    body = (jbyte *)malloc(length);

    if (body == 0) {
        JNU_ThrowOutOfMemoryError(env, 0);
        return 0;
    }

    (*env)->GetByteArrayRegion(env, data, offset, length, body);

    if ((*env)->ExceptionOccurred(env))
        goto free_body;

    if (name != NULL) {
        jsize len = (*env)->GetStringUTFLength(env, name);
        jsize unicode_len = (*env)->GetStringLength(env, name);
        if (len >= (jsize)sizeof(buf)) {
            utfName = malloc(len + 1);
            if (utfName == NULL) {
                JNU_ThrowOutOfMemoryError(env, NULL);
                goto free_body;
            }
        } else {
            utfName = buf;
        }
        (*env)->GetStringUTFRegion(env, name, 0, unicode_len, utfName);
        VerifyFixClassname(utfName);
    } else {
        utfName = NULL;
    }

    result = (*env)->DefineClass(env, utfName, loader, body, length);

    if (utfName && utfName != buf)
        free(utfName);

 free_body:
    free(body);
    return result;
}
Beispiel #7
0
/*
 * Class:     sun_java2d_loops_FillPath
 * Method:    FillPath
 * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IILjava/awt/geom/Path2D.Float;)V
 */
JNIEXPORT void JNICALL Java_sun_java2d_loops_FillPath_FillPath
    (JNIEnv *env, jobject self,
     jobject sg2d, jobject sData,
     jint transX, jint transY, jobject p2df)
{
    jarray typesArray;
    jarray coordsArray;
    jint numTypes;
    jint fillRule;
    jboolean ok = JNI_TRUE;
    jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);
    jint maxCoords;
    jfloat *coords;
    SurfaceDataOps *sdOps;
    SurfaceDataRasInfo rasInfo;
    CompositeInfo compInfo;
    jint ret;
    NativePrimitive *pPrim = GetNativePrim(env, self);
    jint stroke = (*env)->GetIntField(env, sg2d, sg2dStrokeHintID);

    if (pPrim == NULL) {
        return;
    }
    if (pPrim->pCompType->getCompInfo != NULL) {
        GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
    }

    sdOps = SurfaceData_GetOps(env, sData);
    if (sdOps == 0) {
        return;
    }

    typesArray = (jarray)(*env)->GetObjectField(env, p2df, path2DTypesID);
    coordsArray = (jarray)(*env)->GetObjectField(env, p2df,
                                                 path2DFloatCoordsID);
    if (coordsArray == NULL) {
        JNU_ThrowNullPointerException(env, "coordinates array");
        return;
    }
    numTypes = (*env)->GetIntField(env, p2df, path2DNumTypesID);
    fillRule = (*env)->GetIntField(env, p2df, path2DWindingRuleID);
    if ((*env)->GetArrayLength(env, typesArray) < numTypes) {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");
        return;
    }

    GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);

    ret = sdOps->Lock(env, sdOps, &rasInfo, SD_LOCK_FASTEST | pPrim->dstflags);
    if (ret == SD_FAILURE) {
        return;
    }

    maxCoords = (*env)->GetArrayLength(env, coordsArray);
    coords = (jfloat*)(*env)->GetPrimitiveArrayCritical(
            env, coordsArray, NULL);

    if (ret == SD_SLOWLOCK) {
        GrPrim_RefineBounds(&rasInfo.bounds, transX, transY,
                     coords, maxCoords);
        ok = (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
              rasInfo.bounds.y2 > rasInfo.bounds.y1);
    }

    if (ok) {
        sdOps->GetRasInfo(env, sdOps, &rasInfo);
        if (rasInfo.rasBase) {
            if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
                rasInfo.bounds.y2 > rasInfo.bounds.y1)
            {
                DrawHandlerData dHData;
                DrawHandler drawHandler = {
                    NULL,
                    NULL,
                    &drawScanline,
                    0, 0, 0, 0,
                    0, 0, 0, 0,
                    NULL
                };

                jbyte *types = (jbyte*)(*env)->GetPrimitiveArrayCritical(
                    env, typesArray, NULL);

                /* Initialization of the following fields in the declaration of
                 * the dHData and drawHandler above causes warnings on sun
                 * studio compiler with
                 * -xc99=%none option applied (this option means compliance
                 *  with C90 standard instead of C99)
                 */
                dHData.pRasInfo = &rasInfo;
                dHData.pixel = pixel;
                dHData.pPrim = pPrim;
                dHData.pCompInfo = &compInfo;

                drawHandler.xMin = rasInfo.bounds.x1;
                drawHandler.yMin = rasInfo.bounds.y1;
                drawHandler.xMax = rasInfo.bounds.x2;
                drawHandler.yMax = rasInfo.bounds.y2;
                drawHandler.pData = &dHData;

                if (!doFillPath(&drawHandler,
                                transX, transY, coords,
                                maxCoords, types, numTypes,
                                (stroke == sunHints_INTVAL_STROKE_PURE)?
                                     PH_STROKE_PURE : PH_STROKE_DEFAULT,
                                fillRule))
                {
                    JNU_ThrowArrayIndexOutOfBoundsException(env,
                                                            "coords array");
                }

                (*env)->ReleasePrimitiveArrayCritical(env, typesArray, types,
                                                      JNI_ABORT);
            }
        }
        SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
    }
    (*env)->ReleasePrimitiveArrayCritical(env, coordsArray, coords,
                                          JNI_ABORT);
    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
}
/*
 * Class:     sun_java2d_loops_DrawPolygons
 * Method:    DrawPolygons
 * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;[I[I[IIIIZ)V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_loops_DrawPolygons_DrawPolygons
    (JNIEnv *env, jobject self,
     jobject sg2d, jobject sData,
     jintArray xPointsArray, jintArray yPointsArray,
     jintArray nPointsArray, jint numPolys,
     jint transX, jint transY, jboolean close)
{
    SurfaceDataOps *sdOps;
    SurfaceDataRasInfo rasInfo;
    NativePrimitive *pPrim;
    CompositeInfo compInfo;
    jsize nPointsLen, xPointsLen, yPointsLen;
    jint *nPointsPtr = NULL;
    jint *xPointsPtr = NULL;
    jint *yPointsPtr = NULL;
    jint pointsNeeded;
    jint i, ret;
    jboolean ok = JNI_TRUE;
    jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);

    if (JNU_IsNull(env, xPointsArray) || JNU_IsNull(env, yPointsArray)) {
	JNU_ThrowNullPointerException(env, "coordinate array");
	return;
    }
    if (JNU_IsNull(env, nPointsArray)) {
	JNU_ThrowNullPointerException(env, "polygon length array");
	return;
    }

    nPointsLen = (*env)->GetArrayLength(env, nPointsArray);
    xPointsLen = (*env)->GetArrayLength(env, xPointsArray);
    yPointsLen = (*env)->GetArrayLength(env, yPointsArray);
    if (nPointsLen < numPolys) {
	JNU_ThrowArrayIndexOutOfBoundsException(env,
						"polygon length array size");
	return;
    }

    pPrim = GetNativePrim(env, self);
    if (pPrim == NULL) {
	return;
    }
    if (pPrim->pCompType->getCompInfo != NULL) { 
        GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo); 
    }

    sdOps = SurfaceData_GetOps(env, sData);
    if (sdOps == 0) {
	return;
    }

    GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);

    ret = sdOps->Lock(env, sdOps, &rasInfo, SD_LOCK_FASTEST | pPrim->dstflags);
    if (ret == SD_FAILURE) {
	return;
    }

    nPointsPtr = (*env)->GetPrimitiveArrayCritical(env, nPointsArray, NULL);
    if (!nPointsPtr) {
	ok = JNI_FALSE;
    }

    if (ok) {
	pointsNeeded = 0;
	for (i = 0; i < numPolys; i++) {
	    if (nPointsPtr[i] > 0) {
		pointsNeeded += nPointsPtr[i];
	    }
	}

	if (yPointsLen < pointsNeeded || xPointsLen < pointsNeeded) {
	    (*env)->ReleasePrimitiveArrayCritical(env, nPointsArray,
						  nPointsPtr, JNI_ABORT);
	    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
	    JNU_ThrowArrayIndexOutOfBoundsException(env,
						    "coordinate array length");
	    return;
	}

	xPointsPtr = (*env)->GetPrimitiveArrayCritical(env, xPointsArray, NULL);
	yPointsPtr = (*env)->GetPrimitiveArrayCritical(env, yPointsArray, NULL);
	if (!xPointsPtr || !yPointsPtr) {
	    ok = JNI_FALSE;
	}
    }

    if (ok) {
	if (ret == SD_SLOWLOCK) {
	    RefineBounds(&rasInfo.bounds, transX, transY,
			 xPointsPtr, yPointsPtr, pointsNeeded);
	    ok = (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
		  rasInfo.bounds.y2 > rasInfo.bounds.y1);
	}
    }

    if (ok) {
	sdOps->GetRasInfo(env, sdOps, &rasInfo);
	if (rasInfo.rasBase &&
	    rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
	    rasInfo.bounds.y2 > rasInfo.bounds.y1)
	{
	    ProcessPoly(&rasInfo, pPrim->funcs.drawline, pPrim, &compInfo, 
                        pixel, transX, transY,
			xPointsPtr, yPointsPtr,
			nPointsPtr, numPolys,
			close);
	}
	SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
    }

    if (nPointsPtr) {
	(*env)->ReleasePrimitiveArrayCritical(env, nPointsArray,
					      nPointsPtr, JNI_ABORT);
    }
    if (xPointsPtr) {
	(*env)->ReleasePrimitiveArrayCritical(env, xPointsArray,
					      xPointsPtr, JNI_ABORT);
    }
    if (yPointsPtr) {
	(*env)->ReleasePrimitiveArrayCritical(env, yPointsArray,
					      yPointsPtr, JNI_ABORT);
    }
    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
}
Beispiel #9
0
JNIEXPORT void JNICALL
Java_sun_awt_windows_WCustomCursor_createCursorIndirect(
    JNIEnv *env, jobject self, jintArray intRasterData, jbyteArray andMask,
    jint nSS, jint nW, jint nH, jint xHotSpot, jint yHotSpot)
{
    TRY;

    JNI_CHECK_NULL_RETURN(intRasterData, "intRasterData argument");

    if (nW != ::GetSystemMetrics(SM_CXCURSOR) ||
        nH != ::GetSystemMetrics(SM_CYCURSOR)) {
        JNU_ThrowArrayIndexOutOfBoundsException(env,
                                                "bad width and/or height");
        return;
    }

    jsize length = env->GetArrayLength(andMask);
    jbyte *andMaskPtr = new jbyte[length]; // safe because sizeof(jbyte)==1
    env->GetByteArrayRegion(andMask, 0, length, andMaskPtr);

    HBITMAP hMask = ::CreateBitmap(nW, nH, 1, 1, (BYTE *)andMaskPtr);
    ::GdiFlush();

    int *cols = SAFE_SIZE_NEW_ARRAY2(int, nW, nH);

    jint *intRasterDataPtr = NULL;
    HBITMAP hColor = NULL;
    try {
        intRasterDataPtr =
            (jint *)env->GetPrimitiveArrayCritical(intRasterData, 0);
        hColor = create_BMP(NULL, (int *)intRasterDataPtr, nSS, nW, nH);
        memcpy(cols, intRasterDataPtr, nW*nH*sizeof(int));
    } catch (...) {
        if (intRasterDataPtr != NULL) {
            env->ReleasePrimitiveArrayCritical(intRasterData,
                                               intRasterDataPtr, 0);
        }
        throw;
    }

    env->ReleasePrimitiveArrayCritical(intRasterData, intRasterDataPtr, 0);
    intRasterDataPtr = NULL;

    HCURSOR hCursor = NULL;

    if (hMask && hColor) {
        ICONINFO icnInfo;
        memset(&icnInfo, 0, sizeof(ICONINFO));
        icnInfo.hbmMask = hMask;
        icnInfo.hbmColor = hColor;
        icnInfo.fIcon = FALSE;
        icnInfo.xHotspot = xHotSpot;
        icnInfo.yHotspot = yHotSpot;

        hCursor = ::CreateIconIndirect(&icnInfo);

        destroy_BMP(hColor);
        destroy_BMP(hMask);
    }

    DASSERT(hCursor);

    AwtCursor::setPData(self, ptr_to_jlong(new AwtCursor(env, hCursor, self, xHotSpot,
                                              yHotSpot, nW, nH, nSS, cols,
                                              (BYTE *)andMaskPtr)));
    CATCH_BAD_ALLOC;
}
Beispiel #10
0
// gmask is the composite font slot mask
// baseindex is to be added to the character (code point) index.
jboolean storeGVData(JNIEnv* env,
                     jobject gvdata, jint slot,
                     jint baseIndex, int offset, jobject startPt,
                     int charCount, int glyphCount, hb_glyph_info_t *glyphInfo,
                     hb_glyph_position_t *glyphPos, float devScale) {

    int i, needToGrow;
    float x=0, y=0;
    float startX, startY, advX, advY;
    float scale = 1.0f / HBFloatToFixedScale / devScale;
    unsigned int* glyphs;
    float* positions;
    int initialCount, glyphArrayLen, posArrayLen, maxGlyphs, storeadv, maxStore;
    unsigned int* indices;
    jarray glyphArray, posArray, inxArray;

    if (!init_JNI_IDs(env)) {
        return JNI_FALSE;
    }

    initialCount = (*env)->GetIntField(env, gvdata, gvdCountFID);
    do {
        glyphArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdGlyphsFID);
        posArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdPositionsFID);
        inxArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdIndicesFID);
        if (glyphArray == NULL || posArray == NULL || inxArray == NULL) {
            JNU_ThrowArrayIndexOutOfBoundsException(env, "");
            return JNI_FALSE;
        }
        glyphArrayLen = (*env)->GetArrayLength(env, glyphArray);
        posArrayLen = (*env)->GetArrayLength(env, posArray);
        maxGlyphs = (charCount > glyphCount) ? charCount : glyphCount;
        maxStore = maxGlyphs + initialCount;
        needToGrow = (maxStore > glyphArrayLen) ||
                     (maxStore * 2 + 2 >  posArrayLen);
        if (needToGrow) {
            (*env)->CallVoidMethod(env, gvdata, gvdGrowMID);
            if ((*env)->ExceptionCheck(env)) {
                return JNI_FALSE;
            }
        }
    } while (needToGrow);

    getFloat(env, startPt, &startX, &startY);

    glyphs =
        (unsigned int*)(*env)->GetPrimitiveArrayCritical(env, glyphArray, NULL);
    if (glyphs == NULL) {
        return JNI_FALSE;
    }
    positions = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
    if (positions == NULL) {
        (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
        return JNI_FALSE;
    }
    indices =
        (unsigned int*)(*env)->GetPrimitiveArrayCritical(env, inxArray, NULL);
    if (indices == NULL) {
        (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
        (*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, 0);
        return JNI_FALSE;
    }

    for (i = 0; i < glyphCount; i++) {
        int storei = i + initialCount;
        int cluster = glyphInfo[i].cluster - offset;
        indices[storei] = baseIndex + cluster;
        glyphs[storei] = (unsigned int)(glyphInfo[i].codepoint | slot);
        positions[storei*2] = startX + x + glyphPos[i].x_offset * scale;
        positions[(storei*2)+1] = startY + y - glyphPos[i].y_offset * scale;
        x += glyphPos[i].x_advance * scale;
        y -= glyphPos[i].y_advance * scale;
        storei++;
    }
    storeadv = initialCount + glyphCount;
    // The final slot in the positions array is important
    // because when the GlyphVector is created from this
    // data it determines the overall advance of the glyphvector
    // and this is used in positioning the next glyphvector
    // during rendering where text is broken into runs.
    // We also need to report it back into "pt", so layout can
    // pass it back down for that next run in this code.
    advX = startX + x;
    advY = startY + y;
    positions[(storeadv*2)] = advX;
    positions[(storeadv*2)+1] = advY;
    (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
    (*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, 0);
    (*env)->ReleasePrimitiveArrayCritical(env, inxArray, indices, 0);
    putFloat(env, startPt, advX, advY);
    (*env)->SetIntField(env, gvdata, gvdCountFID, storeadv);

    return JNI_TRUE;
}
Beispiel #11
0
/*
 * Class:     sun_java2d_windows_GDIRenderer
 * Method:    doShape
 * Signature:  (Lsun/java2d/windows/GDIWindowSurfaceData;Lsun/java2d/pipe/Region;
 *              Ljava/awt/Composite;IIILjava/awt/geom/Path2D.Float;Z)V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_windows_GDIRenderer_doShape
    (JNIEnv *env, jobject wr,
     jobject sData,
     jobject clip, jobject comp, jint color,
     jint transX, jint transY,
     jobject p2df, jboolean isfill)
{
    J2dTraceLn(J2D_TRACE_INFO, "GDIRenderer_doShape");
    J2dTraceLn4(J2D_TRACE_VERBOSE,
                "  color=0x%x transx=%-4d transy=%-4d isfill=%-4d",
                color, transX, transY, isfill);
    GDIWinSDOps *wsdo = GDIWindowSurfaceData_GetOps(env, sData);
    if (wsdo == NULL) {
        return;
    }

    jarray typesarray = (jarray) env->GetObjectField(p2df, path2DTypesID);
    jarray coordsarray = (jarray) env->GetObjectField(p2df,
                                                      path2DFloatCoordsID);
    if (coordsarray == NULL) {
        JNU_ThrowNullPointerException(env, "coordinates array");
        return;
    }
    jint numtypes = env->GetIntField(p2df, path2DNumTypesID);
    if (env->GetArrayLength(typesarray) < numtypes) {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");
        return;
    }
    jint maxcoords = env->GetArrayLength(coordsarray);
    jint rule = env->GetIntField(p2df, path2DWindingRuleID);

    HDC hdc = wsdo->GetDC(env, wsdo, (isfill ? BRUSH : PEN), NULL,
                          clip, comp, color);
    if (hdc == NULL) {
        return;
    }
    ::SetPolyFillMode(hdc, (rule == java_awt_geom_PathIterator_WIND_NON_ZERO
                            ? WINDING : ALTERNATE));
    ::BeginPath(hdc);
    jbyte *types = (jbyte *) env->GetPrimitiveArrayCritical(typesarray,
                                                            NULL);
    jfloat *coords = (jfloat *) env->GetPrimitiveArrayCritical(coordsarray,
                                                               NULL);
    int index = 0;
    BOOL ok = TRUE;
    BOOL isempty = TRUE;
    BOOL isapoint = TRUE;
    int mx = 0, my = 0, x1 = 0, y1 = 0;
    POINT ctrlpts[3];
    for (int i = 0; ok && i < numtypes; i++) {
        switch (types[i]) {
        case java_awt_geom_PathIterator_SEG_MOVETO:
            if (!isfill && !isempty) {
                // Fix for 4298688 - draw(Line) omits last pixel
                // Windows omits the last pixel of a path when stroking.
                // Fix up the last segment of the previous subpath by
                // adding another segment after it that is only 1 pixel
                // long.  The first pixel of that segment will be drawn,
                // but the second pixel is the one that Windows omits.
                ::LineTo(hdc, x1+1, y1);
            }
            if (index + 2 <= maxcoords) {
                mx = x1 = transX + (int) floor(coords[index++]);
                my = y1 = transY + (int) floor(coords[index++]);
                ::MoveToEx(hdc, x1, y1, NULL);
                isempty = TRUE;
                isapoint = TRUE;
            } else {
                ok = FALSE;
            }
            break;
        case java_awt_geom_PathIterator_SEG_LINETO:
            if (index + 2 <= maxcoords) {
                x1 = transX + (int) floor(coords[index++]);
                y1 = transY + (int) floor(coords[index++]);
                ::LineTo(hdc, x1, y1);
                isapoint = isapoint && (x1 == mx && y1 == my);
                isempty = FALSE;
            } else {
                ok = FALSE;
            }
            break;
        case java_awt_geom_PathIterator_SEG_QUADTO:
            if (index + 4 <= maxcoords) {
                ctrlpts[0].x = transX + (int) floor(coords[index++]);
                ctrlpts[0].y = transY + (int) floor(coords[index++]);
                ctrlpts[2].x = transX + (int) floor(coords[index++]);
                ctrlpts[2].y = transY + (int) floor(coords[index++]);
                ctrlpts[1].x = (ctrlpts[0].x * 2 + ctrlpts[2].x) / 3;
                ctrlpts[1].y = (ctrlpts[0].y * 2 + ctrlpts[2].y) / 3;
                ctrlpts[0].x = (ctrlpts[0].x * 2 + x1) / 3;
                ctrlpts[0].y = (ctrlpts[0].y * 2 + y1) / 3;
                x1 = ctrlpts[2].x;
                y1 = ctrlpts[2].y;
                ::PolyBezierTo(hdc, ctrlpts, 3);
                isapoint = isapoint && (x1 == mx && y1 == my);
                isempty = FALSE;
            } else {
                ok = FALSE;
            }
            break;
        case java_awt_geom_PathIterator_SEG_CUBICTO:
            if (index + 6 <= maxcoords) {
                ctrlpts[0].x = transX + (int) floor(coords[index++]);
                ctrlpts[0].y = transY + (int) floor(coords[index++]);
                ctrlpts[1].x = transX + (int) floor(coords[index++]);
                ctrlpts[1].y = transY + (int) floor(coords[index++]);
                ctrlpts[2].x = transX + (int) floor(coords[index++]);
                ctrlpts[2].y = transY + (int) floor(coords[index++]);
                x1 = ctrlpts[2].x;
                y1 = ctrlpts[2].y;
                ::PolyBezierTo(hdc, ctrlpts, 3);
                isapoint = isapoint && (x1 == mx && y1 == my);
                isempty = FALSE;
            } else {
                ok = FALSE;
            }
            break;
        case java_awt_geom_PathIterator_SEG_CLOSE:
            ::CloseFigure(hdc);
            if (x1 != mx || y1 != my) {
                x1 = mx;
                y1 = my;
                ::MoveToEx(hdc, x1, y1, NULL);
                isempty = TRUE;
                isapoint = TRUE;
            } else if (!isfill && !isempty && isapoint) {
                ::LineTo(hdc, x1+1, y1);
                ::MoveToEx(hdc, x1, y1, NULL);
                isempty = TRUE;
                isapoint = TRUE;
            }
            break;
        }
    }
    env->ReleasePrimitiveArrayCritical(typesarray, types, JNI_ABORT);
    env->ReleasePrimitiveArrayCritical(coordsarray, coords, JNI_ABORT);
    if (ok) {
        if (!isfill && !isempty) {
            // Fix for 4298688 - draw(Line) omits last pixel
            // Windows omits the last pixel of a path when stroking.
            // Fix up the last segment of the previous subpath by
            // adding another segment after it that is only 1 pixel
            // long.  The first pixel of that segment will be drawn,
            // but the second pixel is the one that Windows omits.
            ::LineTo(hdc, x1+1, y1);
        }
        ::EndPath(hdc);
        if (isfill) {
            ::FillPath(hdc);
        } else {
            ::StrokePath(hdc);
        }
    } else {
        ::AbortPath(hdc);
        JNU_ThrowArrayIndexOutOfBoundsException(env, "coords array");
    }
    wsdo->ReleaseDC(env, wsdo, hdc);
}
GlyphLayout::GlyphLayout(JNIEnv *env, jcharArray unicodes, jint offset, jint count,
            jint flags, jdoubleArray fontTX, jdoubleArray devTX, jboolean isAntiAliased,
            jboolean usesFractionalMetrics, fontObject *fo)
  : fNumGlyphs(0), fScriptCount(0), fScriptMax(eDefaultStorage), fRightToLeft(false), fDevTX(env, devTX)
{
    if (JNU_IsNull(env, unicodes) ) {
        JNU_ThrowIllegalArgumentException(env,"Unicode array is NULL!");
        return;
    }

    jint max = env->GetArrayLength(unicodes);

    if (offset + count > max) {
        JNU_ThrowArrayIndexOutOfBoundsException(env,
                                        "chars [offset + count]");
        return;
    }

    // !!! check to see how layout should adapt to devTX.  Should it ignore devTX
    // and then adjust the information by devTX afterwards?  Then it would perhaps
    // get incorrectly hinted advance information by the strike.  But if it uses
    // devTX then the advance and position information needs to be normalized
    // before returning it to native.

    TX gtx(fDevTX);
    TX ftx(env, fontTX);
    gtx.concat(ftx);
    FontTransform tx(gtx.m00, gtx.m10, gtx.m01, gtx.m11);

    jfloat x = (jfloat)gtx.m02;
    jfloat y = (jfloat)gtx.m12;

	const jchar *theChars = (const jchar *) env->GetPrimitiveArrayCritical(unicodes, NULL);

	if (theChars != NULL) {
	    const jchar *oldChars = theChars; // theChars can get changed, save original
        if (flags != 0) {
            if ((flags & 0x0001) != 0) {
                fRightToLeft = true;
            }

            if ((flags & 0x0002) != 0) {
                theChars += offset;
                max -= offset;
                offset = 0;
            }

            if ((flags & 0x0004) != 0) {
                max = offset + count;
            }
        }

        if (fo->GetFormat() == kCompositeFontFormat) {
            Strike *strike = &fo->getStrike(tx, isAntiAliased, usesFractionalMetrics);
            UInt32 *glyphs = new UInt32[count];
            ScriptRun scriptRun(theChars, offset, count);
            le_uint32 slot;

            charsToGlyphs(&theChars[offset], count, strike, glyphs);

            fScriptInfo = fScriptInfoBase;
            slot = glyphs[0] >> 24;

            while (scriptRun.next()) {
                le_int32 scriptStart = scriptRun.getScriptStart();
                le_int32 scriptEnd   = scriptRun.getScriptEnd();
                le_int32 scriptCode  = scriptRun.getScriptCode();

                le_int32 ch = scriptStart;
                while (ch < scriptEnd) {
                    while (ch < scriptEnd && slot == glyphs[ch - offset] >> 24) {
                        ch += 1;
                    }

                    if (fScriptCount >= fScriptMax) {
                        growScriptInfo();
                    }

                    fScriptInfo[fScriptCount].scriptStart = scriptStart;
                    fScriptInfo[fScriptCount].scriptCode  = scriptCode;
                    fScriptInfo[fScriptCount].scriptSlot  = slot;

                    fScriptCount += 1;

                    if (ch < scriptEnd) {
                        slot = glyphs[ch - offset] >> 24;
                        scriptStart = ch;
                    }
                }
            }

            delete[] glyphs;
            fScriptInfo[fScriptCount].scriptStart = scriptRun.getScriptEnd();
        } else {
Beispiel #13
0
JNIEXPORT void JNICALL
Java_sun_java2d_pipe_SpanClipRenderer_eraseTile
    (JNIEnv *env, jobject sr, jobject ri,
     jbyteArray alphaTile, jint offset, jint tsize, jintArray boxArray)
{
    jobject region;
    jintArray bandsArray;
    jint *bands;
    jbyte *alpha;
    jint *box;
    jint endIndex;
    jint curIndex;
    jint saveCurIndex;
    jint numXbands;
    jint saveNumXbands;
    jint lox;
    jint loy;
    jint hix;
    jint hiy;
    jint firstx;
    jint firsty;
    jint lastx;
    jint lasty;
    jint curx;
    jsize alphalen;

    if ((*env)->GetArrayLength(env, boxArray) < 4) {
	JNU_ThrowArrayIndexOutOfBoundsException(env, "band array");
    }
    alphalen = (*env)->GetArrayLength(env, alphaTile);

    saveCurIndex = (*env)->GetIntField(env, ri, pCurIndexID);
    saveNumXbands = (*env)->GetIntField(env, ri, pNumXbandsID);
    region = (*env)->GetObjectField(env, ri, pRegionID);
    bandsArray = (*env)->GetObjectField(env, region, pBandsArrayID);
    endIndex = (*env)->GetIntField(env, region, pEndIndexID);

    if (endIndex > (*env)->GetArrayLength(env, bandsArray)) {
	endIndex = (*env)->GetArrayLength(env, bandsArray);
    }

    box = (*env)->GetPrimitiveArrayCritical(env, boxArray, 0);

    lox = box[0];
    loy = box[1];
    hix = box[2];
    hiy = box[3];

    if (alphalen < offset ||
	alphalen < offset + (hix-lox) ||
	(alphalen - offset - (hix-lox)) / tsize < (hiy - loy - 1)) {
	(*env)->ReleasePrimitiveArrayCritical(env, boxArray, box, 0);
	JNU_ThrowArrayIndexOutOfBoundsException(env, "alpha tile array");
    }

    bands = (*env)->GetPrimitiveArrayCritical(env, bandsArray, 0);
    alpha = (*env)->GetPrimitiveArrayCritical(env, alphaTile, 0);

    curIndex = saveCurIndex;
    numXbands = saveNumXbands;
    firsty = hiy;
    lasty = hiy;
    firstx = hix;
    lastx = lox;

    while (nextYRange(box, bands, endIndex, &curIndex, &numXbands)) {
	if (box[3] <= loy) {
	    saveNumXbands = numXbands;
	    saveCurIndex = curIndex;
	    continue;
	}
	if (box[1] >= hiy) {
	    break;
	}
	if (box[1] < loy) {
	    box[1] = loy;
	}
	if (box[3] > hiy) {
	    box[3] = hiy;
	}
	curx = lox;
	while (nextXBand(box, bands, endIndex, &curIndex, &numXbands)) {
	    if (box[2] <= lox) {
		continue;
	    }
	    if (box[0] >= hix) {
		break;
	    }
	    if (box[0] < lox) {
		box[0] = lox;
	    }
	    if (lasty < box[1]) {
		fill(alpha, offset, tsize,
		     0, lasty - loy,
		     hix - lox, box[1] - lasty, 0);
	    }
	    lasty = box[3];
	    if (firstx > box[0]) {
		firstx = box[0];
	    }
	    if (curx < box[0]) {
		fill(alpha, offset, tsize,
		     curx - lox, box[1] - loy,
		     box[0] - curx, box[3] - box[1], 0);
	    }
	    curx = box[2];
	    if (curx >= hix) {
		curx = hix;
		break;
	    }
	}
	if (curx > lox) {
	    if (curx < hix) {
		fill(alpha, offset, tsize,
		     curx - lox, box[1] - loy,
		     hix - curx, box[3] - box[1], 0);
	    }
	    if (firsty > box[1]) {
		firsty = box[1];
	    }
	}
	if (lastx < curx) {
	    lastx = curx;
	}
    }

    box[0] = firstx;
    box[1] = firsty;
    box[2] = lastx;
    box[3] = lasty;

    (*env)->ReleasePrimitiveArrayCritical(env, alphaTile, alpha, 0);
    (*env)->ReleasePrimitiveArrayCritical(env, bandsArray, bands, 0);
    (*env)->ReleasePrimitiveArrayCritical(env, boxArray, box, 0);

    (*env)->SetIntField(env, ri, pCurIndexID, saveCurIndex);
    (*env)->SetIntField(env, ri, pNumXbandsID, saveNumXbands);
}
/*
 * Class:     java_io_ObjectInputStream
 * Method:    setPrimitiveFieldValues
 * Signature: (Ljava/lang/Object;[J[C[B)V
 * 
 * Sets the values of the primitive fields of object obj.  fieldIDs is an array
 * of field IDs (the primFieldsID field of the appropriate ObjectStreamClass)
 * identifying which fields to set.  typecodes is an array of characters
 * designating the primitive type of each field (e.g., 'C' for char, 'Z' for
 * boolean, etc.)  data is the byte buffer from which the primitive field values
 * are read, in the order of their field IDs.
 * 
 * For efficiency, this method does not check all of its arguments for safety.
 * Specifically, it assumes that obj's type is compatible with the given field
 * IDs, and that the data array is long enough to contain all of the byte values
 * that will be read out of it.
 */
JNIEXPORT void JNICALL 
Java_java_io_ObjectInputStream_setPrimitiveFieldValues(JNIEnv *env, 
						       jclass thisObj, 
						       jobject obj, 
						       jlongArray fieldIDs, 
						       jcharArray typecodes, 
						       jbyteArray data)
{
    jchar *tcodes = NULL;
    jbyte *dbuf = NULL;
    jlong *fids = NULL;
    jsize nfids, off, i;

    /* check object */
    if (obj == NULL) {
	JNU_ThrowNullPointerException(env, NULL);
	goto end;
    }

    /* get field ids */
    if (fieldIDs == NULL) {
	JNU_ThrowNullPointerException(env, NULL);
	goto end;
    }
    nfids = (*env)->GetArrayLength(env, fieldIDs);
    if (nfids == 0)
	goto end;
    fids = (*env)->GetLongArrayElements(env, fieldIDs, NULL);
    if (fids == NULL)	/* exception thrown */
	goto end;
    
    /* get typecodes */
    if (typecodes == NULL) {
	JNU_ThrowNullPointerException(env, NULL);
	goto end;
    }
    if ((*env)->GetArrayLength(env, typecodes) < nfids) {
	JNU_ThrowArrayIndexOutOfBoundsException(env, NULL);
	goto end;
    }
    tcodes = (*env)->GetCharArrayElements(env, typecodes, NULL);
    if (tcodes == NULL)	/* exception thrown */
	goto end;
    
    /* get data buffer */
    if (data == NULL) {
	JNU_ThrowNullPointerException(env, NULL);
	goto end;
    }
    dbuf = (*env)->GetByteArrayElements(env, data, NULL);
    if (dbuf == NULL)	/* exception thrown */
	goto end;
    
    /* loop through fields, setting values */
    for (i = 0, off = 0; i < nfids; i++) {
	jfieldID fid = (jfieldID) jlong_to_ptr(fids[i]);
	switch (tcodes[i]) {
	    case 'Z':
		if (fid != NULL) {
		    jboolean val = (dbuf[off] != 0) ? JNI_TRUE : JNI_FALSE;
		    (*env)->SetBooleanField(env, obj, fid, val);
		}
		off++;
		break;
		
	    case 'B':
		if (fid != NULL) {
		    (*env)->SetByteField(env, obj, fid, dbuf[off]);
		}
		off++;
		break;
		
	    case 'C':
		if (fid != NULL) {
		    jchar val = ((dbuf[off + 0] & 0xFF) << 8) +
				((dbuf[off + 1] & 0xFF) << 0);
		    (*env)->SetCharField(env, obj, fid, val);
		}
		off += 2;
		break;

	    case 'S':
		if (fid != NULL) {
		    jshort val = ((dbuf[off + 0] & 0xFF) << 8) +
				 ((dbuf[off + 1] & 0xFF) << 0);
		    (*env)->SetShortField(env, obj, fid, val);
		}
		off += 2;
		break;
		
	    case 'I':
		if (fid != NULL) {
		    jint val = ((dbuf[off + 0] & 0xFF) << 24) +
			       ((dbuf[off + 1] & 0xFF) << 16) +
			       ((dbuf[off + 2] & 0xFF) << 8) +
			       ((dbuf[off + 3] & 0xFF) << 0);
		    (*env)->SetIntField(env, obj, fid, val);
		}
		off += 4;
		break;
		
	    case 'F':
		if (fid != NULL) {
		    jint ival = ((dbuf[off + 0] & 0xFF) << 24) +
				((dbuf[off + 1] & 0xFF) << 16) +
				((dbuf[off + 2] & 0xFF) << 8) +
				((dbuf[off + 3] & 0xFF) << 0);
		    jfloat fval = Java_java_lang_Float_intBitsToFloat(env,
			    NULL, ival);
		    (*env)->SetFloatField(env, obj, fid, fval);
		}
		off += 4;
		break;

	    case 'J':
		if (fid != NULL) {
		    jlong val = READ_JLONG_FROM_BUF(dbuf, off);
		    (*env)->SetLongField(env, obj, fid, val);
		}
		off += 8;
		break;
		
	    case 'D':
		if (fid != NULL) {
		    jlong lval = READ_JLONG_FROM_BUF(dbuf, off);
		    jdouble dval = Java_java_lang_Double_longBitsToDouble(env,
			    NULL, lval);
		    (*env)->SetDoubleField(env, obj, fid, dval);
		}
		off += 8;
		break;
		
	    default:
		/* Illegal typecode */
		JNU_ThrowIllegalArgumentException(env, "illegal typecode");
		goto end;
	}
    }
    
    
end:
    /* cleanup */
    if (fids != NULL)
	(*env)->ReleaseLongArrayElements(env, fieldIDs, fids, JNI_ABORT);
    if (tcodes != NULL)
	(*env)->ReleaseCharArrayElements(env, typecodes, tcodes, JNI_ABORT);
    if (dbuf != NULL)
	(*env)->ReleaseByteArrayElements(env, data, dbuf, JNI_ABORT);
}
Beispiel #15
0
/*
 * Class:     sun_java2d_x11_X11Renderer
 * Method:    XDoPath
 * Signature: (Lsun/java2d/SunGraphics2D;JJIILjava/awt/geom/Path2D/Float;Z)V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_x11_X11Renderer_XDoPath
    (JNIEnv *env, jobject self, jobject sg2d, jlong pXSData, jlong xgc,
     jint transX, jint transY, jobject p2df, jboolean isFill)
{
#ifndef HEADLESS
    X11SDOps *xsdo = (X11SDOps *) pXSData;
    jarray typesArray;
    jobject pointArray;
    jarray coordsArray;
    jint numTypes;
    jint fillRule;
    jint maxCoords;
    jbyte *types;
    jfloat *coords;
    XDrawHandlerData dHData;
    DrawHandler drawHandler = {
        NULL, NULL, NULL,
        MIN_SHORT, MIN_SHORT, MAX_SHORT, MAX_SHORT,
        0, 0, 0, 0,
        NULL
    };
    PHStroke stroke;

    if (xsdo == NULL) {
        return;
    }

    if (isFill) {
        fillRule = (*env)->GetIntField(env, p2df, path2DWindingRuleID);
    }

    typesArray = (jarray)(*env)->GetObjectField(env, p2df, path2DTypesID);
    coordsArray = (jarray)(*env)->GetObjectField(env, p2df,
                                                 path2DFloatCoordsID);
    if (coordsArray == NULL) {
        JNU_ThrowNullPointerException(env, "coordinates array");
        return;
    }
    numTypes = (*env)->GetIntField(env, p2df, path2DNumTypesID);
    if ((*env)->GetArrayLength(env, typesArray) < numTypes) {
        JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");
        return;
    }

    XDHD_INIT(&dHData, (GC)xgc, xsdo->drawable);
    drawHandler.pData = &dHData;

    stroke = (((*env)->GetIntField(env, sg2d, sg2dStrokeHintID) ==
               sunHints_INTVAL_STROKE_PURE)
              ? PH_STROKE_PURE
              : PH_STROKE_DEFAULT);

    maxCoords = (*env)->GetArrayLength(env, coordsArray);
    coords = (jfloat*)
        (*env)->GetPrimitiveArrayCritical(env, coordsArray, NULL);
    if (coords != NULL) {
        types = (jbyte*)
            (*env)->GetPrimitiveArrayCritical(env, typesArray, NULL);
        if (types != NULL) {
            jboolean ok;

            if (isFill) {
                drawHandler.pDrawScanline = &drawScanline;
                ok = doFillPath(&drawHandler,
                                transX, transY,
                                coords, maxCoords,
                                types, numTypes,
                                stroke, fillRule);
            } else {
                drawHandler.pDrawLine = &storeLine;
                drawHandler.pDrawPixel = &storePoint;
                ok = doDrawPath(&drawHandler, &drawSubPath,
                                transX, transY,
                                coords, maxCoords,
                                types, numTypes,
                                stroke);
            }
            if (!ok) {
                JNU_ThrowArrayIndexOutOfBoundsException(env, "coords array");
            }
            (*env)->ReleasePrimitiveArrayCritical(env, typesArray, types,
                                                  JNI_ABORT);
        }
        (*env)->ReleasePrimitiveArrayCritical(env, coordsArray, coords,
                                              JNI_ABORT);
    }

    XDHD_FREE_POINTS(&dHData);
    X11SD_DirectRenderNotify(env, xsdo);
#endif /* !HEADLESS */
}
Beispiel #16
0
JNIEXPORT jclass JNICALL
Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
					jobject loader,
					jstring name,
					jbyteArray data,
					jint offset,
					jint length,
					jobject pd,
                                        jstring source,
                                        jboolean verify)
{
    jbyte *body;
    char *utfName;
    jclass result = 0;
    char buf[128];
    char* utfSource;
    char sourceBuf[1024];

    if (data == NULL) {
	JNU_ThrowNullPointerException(env, 0);
	return 0;
    }

    /* Work around 4153825. malloc crashes on Solaris when passed a
     * negative size.
     */
    if (length < 0) {
        JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
	return 0;
    }

    body = (jbyte *)malloc(length);

    if (body == 0) {
        JNU_ThrowOutOfMemoryError(env, 0);
	return 0;
    }

    (*env)->GetByteArrayRegion(env, data, offset, length, body);

    if ((*env)->ExceptionOccurred(env))
        goto free_body;

    if (name != NULL) {
	utfName = getUTF(env, name, buf, sizeof(buf));
	if (utfName == NULL) {
	    JNU_ThrowOutOfMemoryError(env, NULL);
	    goto free_body;
	}
	VerifyFixClassname(utfName);
    } else {
	utfName = NULL;
    }

    if (source != NULL) {
        utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
	if (utfSource == NULL) {
	    JNU_ThrowOutOfMemoryError(env, NULL);
	    goto free_utfName;
	}
    } else {
	utfSource = NULL;
    }
    result = JVM_DefineClassWithSourceCond(env, utfName, loader, body, length, pd, utfSource, verify); 

    if (utfSource && utfSource != sourceBuf) 
        free(utfSource);

 free_utfName:
    if (utfName && utfName != buf) 
        free(utfName);

 free_body:
    free(body);
    return result;
}