diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m index 46fc9c70641..97444da4c6b 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m @@ -599,11 +599,11 @@ jboolean clipDestCoords( SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); } -void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, BOOL convertFromArgbPre) { +void copyFromMTLBuffer(void *pDst, id srcBuf, NSUInteger offset, NSUInteger len, BOOL convertFromArgbPre) { char *pSrc = (char*)srcBuf.contents + offset; if (convertFromArgbPre) { - jint pixelLen = len>>2; - for (int i = 0; i < pixelLen; i++) { + NSUInteger pixelLen = len >> 2; + for (NSUInteger i = 0; i < pixelLen; i++) { LoadIntArgbPreTo1IntArgb((jint*)pSrc, 0, i, ((jint*)pDst)[i]); } } else { @@ -640,6 +640,10 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, RETURN_IF_NULL(srcOps); RETURN_IF_NULL(dstOps); RETURN_IF_NULL(mtlc); + RETURN_IF_TRUE(width < 0); + RETURN_IF_TRUE(height < 0); + NSUInteger w = (NSUInteger)width; + NSUInteger h = (NSUInteger)height; srcInfo.bounds.x1 = srcx; srcInfo.bounds.y1 = srcy; @@ -675,13 +679,13 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, width = srcInfo.bounds.x2 - srcInfo.bounds.x1; height = srcInfo.bounds.y2 - srcInfo.bounds.y1; - pDst = PtrAddBytes(pDst, dstx * dstInfo.pixelStride); + pDst = PtrPixelsRow(pDst, dstx, dstInfo.pixelStride); pDst = PtrPixelsRow(pDst, dsty, dstInfo.scanStride); // Metal texture is (0,0) at left-top srcx = srcOps->xOffset + srcx; srcy = srcOps->yOffset + srcy; - const int byteLength = width * height * 4; // NOTE: assume that src format is MTLPixelFormatBGRA8Unorm + NSUInteger byteLength = w * h * 4; // NOTE: assume that src format is MTLPixelFormatBGRA8Unorm // Create MTLBuffer (or use static) id mtlbuf; @@ -708,7 +712,7 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, } mtlbuf = mtlIntermediateBuffer; #else // USE_STATIC_BUFFER - mtlbuf = [mtlc.device newBufferWithLength:width*height*4 options:MTLResourceStorageModeShared]; + mtlbuf = [mtlc.device newBufferWithLength:byteLength options:MTLResourceStorageModeShared]; #endif // USE_STATIC_BUFFER // Read from surface into MTLBuffer @@ -723,10 +727,10 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(srcx, srcy, 0) - sourceSize:MTLSizeMake(width, height, 1) + sourceSize:MTLSizeMake(w, h, 1) toBuffer:mtlbuf - destinationOffset:0 /*offset already taken in: pDst = PtrAddBytes(pDst, dstx * dstInfo.pixelStride)*/ - destinationBytesPerRow:width*4 + destinationOffset:0 /*offset already taken in: pDst = PtrPixelsRow(pDst, dstx, dstInfo.pixelStride)*/ + destinationBytesPerRow:w*4 destinationBytesPerImage:byteLength]; [blitEncoder endEncoding]; @@ -737,7 +741,7 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, // Perform conversion if necessary BOOL convertFromPre = !RasterFormatInfos[dsttype].isPremult && !srcOps->isOpaque; - if ((dstInfo.scanStride == width * dstInfo.pixelStride) && + if ((dstInfo.scanStride == w * dstInfo.pixelStride) && (height == (dstInfo.bounds.y2 - dstInfo.bounds.y1))) { // mtlbuf.contents have same dimensions as of pDst copyFromMTLBuffer(pDst, mtlbuf, 0, byteLength, convertFromPre); @@ -746,7 +750,7 @@ void copyFromMTLBuffer(void *pDst, id srcBuf, jint offset, jint len, // copy each row from mtlbuf.contents at appropriate position in pDst // Note : pDst is already addjusted for offsets using PtrAddBytes above - int rowSize = width * dstInfo.pixelStride; + NSUInteger rowSize = w * dstInfo.pixelStride; for (int y = 0; y < height; y++) { copyFromMTLBuffer(pDst, mtlbuf, y * rowSize, rowSize, convertFromPre); pDst = PtrAddBytes(pDst, dstInfo.scanStride); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.m index 3c756b53273..a36e211f748 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.m @@ -175,13 +175,13 @@ - (id)init:(jboolean)nonPremult shortData:(jboolean)shortData } else if (numBands == 3) { // user supplied band for each of R/G/B; alpha band is unused for (int i = 0; i < 3; i++) { - bands[i] = PtrAddBytes(tableValues, i*bandLength*bytesPerElem); + bands[i] = PtrPixelsBand(tableValues, i, bandLength, bytesPerElem); } bands[3] = NULL; } else if (numBands == 4) { // user supplied band for each of R/G/B/A for (int i = 0; i < 4; i++) { - bands[i] = PtrAddBytes(tableValues, i*bandLength*bytesPerElem); + bands[i] = PtrPixelsBand(tableValues, i, bandLength, bytesPerElem); } } diff --git a/src/java.desktop/share/native/libawt/java2d/loops/GraphicsPrimitiveMgr.h b/src/java.desktop/share/native/libawt/java2d/loops/GraphicsPrimitiveMgr.h index b9158ce99f6..2a3353aded8 100644 --- a/src/java.desktop/share/native/libawt/java2d/loops/GraphicsPrimitiveMgr.h +++ b/src/java.desktop/share/native/libawt/java2d/loops/GraphicsPrimitiveMgr.h @@ -485,6 +485,9 @@ extern struct _CompositeTypes { #define PtrPixelsRow(p, y, scanStride) PtrAddBytes(p, \ ((intptr_t) (y)) * (scanStride)) +#define PtrPixelsBand(p, y, length, elemSize) PtrAddBytes(p, \ + ((intptr_t) (y)) * (length) * (elemSize)) + /* * The function to call with an array of NativePrimitive structures * to register them with the Java GraphicsPrimitiveMgr.