src/share/native/sun/java2d/loops/TransformHelper.c

Print this page




 367     srcInfo.bounds.y2 = sy2;
 368     dstInfo.bounds.x1 = dx1;
 369     dstInfo.bounds.y1 = dy1;
 370     dstInfo.bounds.x2 = dx2;
 371     dstInfo.bounds.y2 = dy2;
 372     SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
 373     if (srcOps->Lock(env, srcOps, &srcInfo, pHelperPrim->srcflags)
 374         != SD_SUCCESS)
 375     {
 376         /* edgeArray should already contain zeros for min/maxy */
 377         return;
 378     }
 379     if (dstOps->Lock(env, dstOps, &dstInfo, pMaskBlitPrim->dstflags)
 380         != SD_SUCCESS)
 381     {
 382         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 383         /* edgeArray should already contain zeros for min/maxy */
 384         return;
 385     }
 386     Region_IntersectBounds(&clipInfo, &dstInfo.bounds);


 387 
 388     numedges = (((jlong) dstInfo.bounds.y2) - ((jlong) dstInfo.bounds.y1));
 389     if (numedges <= 0) {
 390         pEdges = NULL;
 391     } else if (!JNU_IsNull(env, edgeArray)) {
 392         /*
 393          * Ideally Java should allocate an array large enough, but if
 394          * we ever have a miscommunication about the number of edge
 395          * lines, or if the Java array calculation should overflow to
 396          * a positive number and succeed in allocating an array that
 397          * is too small, we need to verify that it can still hold the
 398          * number of integers that we plan to store to be safe.
 399          */
 400         jsize edgesize = (*env)->GetArrayLength(env, edgeArray);
 401         /* (edgesize/2 - 1) should avoid any overflow or underflow. */
 402         pEdges = (((edgesize / 2) - 1) >= numedges)
 403             ? (*env)->GetPrimitiveArrayCritical(env, edgeArray, NULL)
 404             : NULL;
 405     } else if (numedges > MAXEDGES) {
 406         /* numedges variable (jlong) can be at most ((1<<32)-1) */
 407         /* memsize can overflow a jint, but not a jlong */
 408         jlong memsize = ((numedges * 2) + 2) * sizeof(*pEdges);
 409         pEdges = (memsize == ((size_t) memsize))
 410             ? malloc((size_t) memsize)
 411             : NULL;
 412     } else {
 413         pEdges = edgebuf;
 414     }
 415 
 416     if (pEdges == NULL) {
 417         if (!(*env)->ExceptionCheck(env) && numedges > 0) {
 418             JNU_ThrowInternalError(env, "Unable to allocate edge list");
 419         }
 420         SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
 421         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 422         /* edgeArray should already contain zeros for min/maxy */
 423         return;
 424     }
 425 
 426     Transform_GetInfo(env, itxform, &itxInfo);
 427 
 428     if (!Region_IsEmpty(&clipInfo)) {
 429         srcOps->GetRasInfo(env, srcOps, &srcInfo);
 430         dstOps->GetRasInfo(env, dstOps, &dstInfo);
 431         if (srcInfo.rasBase == NULL || dstInfo.rasBase == NULL) {
 432             pEdges[0] = pEdges[1] = 0;
 433         } else if (checkOverflow(dxoff, dyoff, &dstInfo.bounds,
 434                                  &itxInfo, &xorig, &yorig))
 435         {
 436             Transform_SafeHelper(env, srcOps, dstOps,
 437                                  &srcInfo, &dstInfo,
 438                                  pMaskBlitPrim, &compInfo,
 439                                  pHelperFunc, pInterpFunc,
 440                                  &clipInfo, &itxInfo, rgb.data, pEdges,
 441                                  dxoff, dyoff, sx2-sx1, sy2-sy1);
 442         } else {
 443             SurfaceDataBounds span;
 444             jlong dxdxlong, dydxlong;
 445             jlong dxdylong, dydylong;
 446             jlong xbase, ybase;




 367     srcInfo.bounds.y2 = sy2;
 368     dstInfo.bounds.x1 = dx1;
 369     dstInfo.bounds.y1 = dy1;
 370     dstInfo.bounds.x2 = dx2;
 371     dstInfo.bounds.y2 = dy2;
 372     SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
 373     if (srcOps->Lock(env, srcOps, &srcInfo, pHelperPrim->srcflags)
 374         != SD_SUCCESS)
 375     {
 376         /* edgeArray should already contain zeros for min/maxy */
 377         return;
 378     }
 379     if (dstOps->Lock(env, dstOps, &dstInfo, pMaskBlitPrim->dstflags)
 380         != SD_SUCCESS)
 381     {
 382         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 383         /* edgeArray should already contain zeros for min/maxy */
 384         return;
 385     }
 386     Region_IntersectBounds(&clipInfo, &dstInfo.bounds);
 387     Transform_GetInfo(env, itxform, &itxInfo);
 388 
 389 
 390     numedges = (((jlong) dstInfo.bounds.y2) - ((jlong) dstInfo.bounds.y1));
 391     if (numedges <= 0) {
 392         pEdges = NULL;
 393     } else if (!JNU_IsNull(env, edgeArray)) {
 394         /*
 395          * Ideally Java should allocate an array large enough, but if
 396          * we ever have a miscommunication about the number of edge
 397          * lines, or if the Java array calculation should overflow to
 398          * a positive number and succeed in allocating an array that
 399          * is too small, we need to verify that it can still hold the
 400          * number of integers that we plan to store to be safe.
 401          */
 402         jsize edgesize = (*env)->GetArrayLength(env, edgeArray);
 403         /* (edgesize/2 - 1) should avoid any overflow or underflow. */
 404         pEdges = (((edgesize / 2) - 1) >= numedges)
 405             ? (*env)->GetPrimitiveArrayCritical(env, edgeArray, NULL)
 406             : NULL;
 407     } else if (numedges > MAXEDGES) {
 408         /* numedges variable (jlong) can be at most ((1<<32)-1) */
 409         /* memsize can overflow a jint, but not a jlong */
 410         jlong memsize = ((numedges * 2) + 2) * sizeof(*pEdges);
 411         pEdges = (memsize == ((size_t) memsize))
 412             ? malloc((size_t) memsize)
 413             : NULL;
 414     } else {
 415         pEdges = edgebuf;
 416     }
 417 
 418     if (pEdges == NULL) {
 419         if (!(*env)->ExceptionCheck(env) && numedges > 0) {
 420             JNU_ThrowInternalError(env, "Unable to allocate edge list");
 421         }
 422         SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
 423         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 424         /* edgeArray should already contain zeros for min/maxy */
 425         return;
 426     }
 427 

 428 
 429     if (!Region_IsEmpty(&clipInfo)) {
 430         srcOps->GetRasInfo(env, srcOps, &srcInfo);
 431         dstOps->GetRasInfo(env, dstOps, &dstInfo);
 432         if (srcInfo.rasBase == NULL || dstInfo.rasBase == NULL) {
 433             pEdges[0] = pEdges[1] = 0;
 434         } else if (checkOverflow(dxoff, dyoff, &dstInfo.bounds,
 435                                  &itxInfo, &xorig, &yorig))
 436         {
 437             Transform_SafeHelper(env, srcOps, dstOps,
 438                                  &srcInfo, &dstInfo,
 439                                  pMaskBlitPrim, &compInfo,
 440                                  pHelperFunc, pInterpFunc,
 441                                  &clipInfo, &itxInfo, rgb.data, pEdges,
 442                                  dxoff, dyoff, sx2-sx1, sy2-sy1);
 443         } else {
 444             SurfaceDataBounds span;
 445             jlong dxdxlong, dydxlong;
 446             jlong dxdylong, dydylong;
 447             jlong xbase, ybase;