Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit aade966

Browse files
dekonoplyovAlexey Ushakov
authored and
Alexey Ushakov
committedJan 14, 2021
8258202: Lanai: Buffered image loses its shape after clicking on Alpha Composite option
8252950: Lanai : sun/java2d/DirectX/OpaqueImageToSurfaceBlitTest/OpaqueImageToSurfaceBlitTest.java fails
1 parent 8e32980 commit aade966

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal

+10
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,16 @@ kernel void stencil2tex(const device uchar *imageBuffer [[buffer(0)]],
617617

618618
// work item deals with 4 byte pixel
619619
// assuming that data is aligned
620+
kernel void rgb_to_rgba(const device uchar *imageBuffer [[buffer(0)]],
621+
device uchar *outputBuffer [[buffer(1)]],
622+
uint gid [[thread_position_in_grid]])
623+
{
624+
outputBuffer[4 * gid] = imageBuffer[4 * gid]; // r
625+
outputBuffer[4 * gid + 1] = imageBuffer[4 * gid + 1]; // g
626+
outputBuffer[4 * gid + 2] = imageBuffer[4 * gid + 2]; // b
627+
outputBuffer[4 * gid + 3] = 255; // a
628+
}
629+
620630
kernel void bgr_to_rgba(const device uchar *imageBuffer [[buffer(0)]],
621631
device uchar *outputBuffer [[buffer(1)]],
622632
uint gid [[thread_position_in_grid]])

‎src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m

+12-42
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
MTLRasterFormatInfo RasterFormatInfos[] = {
6666
{ MTLPixelFormatBGRA8Unorm, 1, 0, nil }, /* 0 - IntArgb */ // Argb (in java notation)
6767
{ MTLPixelFormatBGRA8Unorm, 1, 1, nil }, /* 1 - IntArgbPre */
68-
{ MTLPixelFormatBGRA8Unorm, 0, 1, nil }, /* 2 - IntRgb */
68+
{ MTLPixelFormatBGRA8Unorm, 0, 1, @"rgb_to_rgba" }, /* 2 - IntRgb */
6969
{ MTLPixelFormatBGRA8Unorm, 0, 1, @"xrgb_to_rgba" }, /* 3 - IntRgbx */
7070
{ MTLPixelFormatBGRA8Unorm, 0, 1, @"bgr_to_rgba" }, /* 4 - IntBgr */
7171
{ MTLPixelFormatBGRA8Unorm, 0, 1, @"xbgr_to_rgba" }, /* 5 - IntBgrx */
@@ -163,15 +163,16 @@ void drawTex2Tex(MTLContext *mtlc,
163163
const int sh = srcInfo->bounds.y2 - srcInfo->bounds.y1;
164164
const int dw = dx2 - dx1;
165165
const int dh = dy2 - dy1;
166+
if (dw < sw || dh < sh) {
167+
J2dTraceLn4(J2D_TRACE_WARNING, "replaceTextureRegion: dest size: (%d, %d) less than source size: (%d, %d)", dw, dh, sw, sh);
168+
}
166169

167170
const void *raster = srcInfo->rasBase;
168171
raster += (NSUInteger)srcInfo->bounds.y1 * (NSUInteger)srcInfo->scanStride + (NSUInteger)srcInfo->bounds.x1 * (NSUInteger)srcInfo->pixelStride;
169172

170173
@autoreleasepool {
171174
J2dTraceLn4(J2D_TRACE_VERBOSE, "replaceTextureRegion src (dw, dh) : [%d, %d] dest (dx1, dy1) =[%d, %d]",
172175
dw, dh, dx1, dy1);
173-
// NOTE: we might want to fill alpha channel when !rfi->hasAlpha
174-
175176
id<MTLBuffer> buff = [[mtlc.device newBufferWithLength:(sw * sh * srcInfo->pixelStride) options:MTLResourceStorageModeManaged] autorelease];
176177

177178
// copy src pixels inside src bounds to buff
@@ -226,7 +227,7 @@ void drawTex2Tex(MTLContext *mtlc,
226227
static void
227228
MTLBlitSwToTextureViaPooledTexture(
228229
MTLContext *mtlc, SurfaceDataRasInfo *srcInfo, BMTLSDOps * bmtlsdOps,
229-
MTLRasterFormatInfo * rfi, jboolean useBlitEncoder, jint hint,
230+
MTLRasterFormatInfo *rfi, jint hint,
230231
jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
231232
{
232233
int sw = srcInfo->bounds.x2 - srcInfo->bounds.x1;
@@ -246,23 +247,9 @@ void drawTex2Tex(MTLContext *mtlc,
246247

247248
id<MTLTexture> texBuff = texHandle.texture;
248249
replaceTextureRegion(mtlc, texBuff, srcInfo, rfi, 0, 0, sw, sh);
249-
// TODO: useBlitEncoder is always false, remove dead code
250-
if (useBlitEncoder) {
251-
id <MTLBlitCommandEncoder> blitEncoder = [mtlc.encoderManager createBlitEncoder];
252-
[blitEncoder copyFromTexture:texBuff
253-
sourceSlice:0
254-
sourceLevel:0
255-
sourceOrigin:MTLOriginMake(0, 0, 0)
256-
sourceSize:MTLSizeMake(sw, sh, 1)
257-
toTexture:dest
258-
destinationSlice:0
259-
destinationLevel:0
260-
destinationOrigin:MTLOriginMake(dx1, dy1, 0)];
261-
[blitEncoder endEncoding];
262-
} else {
263-
drawTex2Tex(mtlc, texBuff, dest, !rfi->hasAlpha, bmtlsdOps->isOpaque, hint,
264-
0, 0, sw, sh, dx1, dy1, dx2, dy2);
265-
}
250+
251+
drawTex2Tex(mtlc, texBuff, dest, !rfi->hasAlpha, bmtlsdOps->isOpaque, hint,
252+
0, 0, sw, sh, dx1, dy1, dx2, dy2);
266253
}
267254

268255
static
@@ -582,28 +569,11 @@ jboolean clipDestCoords(
582569
#endif //TRACE_BLIT
583570

584571
MTLRasterFormatInfo rfi = RasterFormatInfos[srctype];
585-
const jboolean useReplaceRegion = texture ||
586-
(!rfi.hasAlpha
587-
&& !xform
588-
&& isIntegerAndUnscaled(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2));
589572

590-
if (useReplaceRegion) {
591-
if (dstOps->isOpaque || rfi.hasAlpha) {
592-
#ifdef TRACE_BLIT
593-
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE," [replaceTextureRegion]");
594-
#endif //TRACE_BLIT
595-
replaceTextureRegion(mtlc, dest, &srcInfo, &rfi, (int) dx1, (int) dy1, (int) dx2, (int) dy2);
596-
} else {
597-
#ifdef TRACE_BLIT
598-
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE," [via pooled + blit]");
599-
#endif //TRACE_BLIT
600-
MTLBlitSwToTextureViaPooledTexture(mtlc, &srcInfo, dstOps, &rfi, false, hint, dx1, dy1, dx2, dy2);
601-
}
602-
} else { // !useReplaceRegion
603-
#ifdef TRACE_BLIT
604-
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE," [via pooled texture]");
605-
#endif //TRACE_BLIT
606-
MTLBlitSwToTextureViaPooledTexture(mtlc, &srcInfo, dstOps, &rfi, false, hint, dx1, dy1, dx2, dy2);
573+
if (texture) {
574+
replaceTextureRegion(mtlc, dest, &srcInfo, &rfi, (int) dx1, (int) dy1, (int) dx2, (int) dy2);
575+
} else {
576+
MTLBlitSwToTextureViaPooledTexture(mtlc, &srcInfo, dstOps, &rfi, hint, dx1, dy1, dx2, dy2);
607577
}
608578
}
609579
SurfaceData_InvokeRelease(env, srcOps, &srcInfo);

0 commit comments

Comments
 (0)