@@ -696,6 +696,7 @@ jboolean clipDestCoords(
696
696
697
697
SurfaceData_IntersectBoundsXYXY (&srcInfo.bounds ,
698
698
0 , 0 , srcOps->width , srcOps->height );
699
+
699
700
SurfaceData_IntersectBlitBounds (&dstInfo.bounds , &srcInfo.bounds ,
700
701
srcx - dstx, srcy - dsty);
701
702
@@ -721,15 +722,6 @@ jboolean clipDestCoords(
721
722
srcy = srcOps->yOffset + srcy;
722
723
const int srcLength = width * height * 4 ; // NOTE: assume that src format is MTLPixelFormatBGRA8Unorm
723
724
724
- #ifdef DEBUG
725
- void *pDstEnd = dstInfo.rasBase + (height - 1 )*dstInfo.scanStride + width*dstInfo.pixelStride ;
726
- if (pDst + srcLength > pDstEnd) {
727
- J2dTraceLn6 (J2D_TRACE_ERROR, " MTLBlitLoops_SurfaceToSwBlit: length mismatch: dstx=%d , dsty=%d , w=%d , h=%d , pixStride=%d , scanStride=%d " ,
728
- dstx, dsty, width, height, dstInfo.pixelStride , dstInfo.scanStride );
729
- return ;
730
- }
731
- #endif // DEBUG
732
-
733
725
// Create MTLBuffer (or use static)
734
726
MTLRasterFormatInfo rfi = RasterFormatInfos[dsttype];
735
727
const jboolean directCopy = rfi.permuteMap == NULL ;
@@ -789,7 +781,21 @@ jboolean clipDestCoords(
789
781
790
782
// Perform conversion if necessary
791
783
if (directCopy) {
792
- memcpy (pDst, mtlbuf.contents , srcLength);
784
+ if ((dstInfo.scanStride == width * dstInfo.pixelStride ) &&
785
+ (height == (dstInfo.bounds .y2 - dstInfo.bounds .y1 ))) {
786
+ // mtlbuf.contents have same dimensions as of pDst
787
+ memcpy (pDst, mtlbuf.contents , srcLength);
788
+ } else {
789
+ // mtlbuf.contents have smaller dimensions than pDst
790
+ // copy each row from mtlbuf.contents at appropriate position in pDst
791
+ // Note : pDst is already addjusted for offsets using PtrAddBytes above
792
+
793
+ int rowSize = width * dstInfo.pixelStride ;
794
+ for (int y = 0 ; y < height; y++) {
795
+ memcpy (pDst, mtlbuf.contents + (y * rowSize), rowSize);
796
+ pDst = PtrAddBytes (pDst, dstInfo.scanStride );
797
+ }
798
+ }
793
799
} else {
794
800
J2dTraceLn6 (J2D_TRACE_VERBOSE," MTLBlitLoops_SurfaceToSwBlit: dsttype=%d , raster conversion will be performed, dest rfi: %d , %d , %d , %d , hasA=%d " ,
795
801
dsttype, rfi.permuteMap [0 ], rfi.permuteMap [1 ], rfi.permuteMap [2 ], rfi.permuteMap [3 ], rfi.hasAlpha );
0 commit comments