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

Commit cf94b38

Browse files
author
Alexey Ushakov
committedNov 17, 2020
8256331: Lanai: DrawImage/IncorrectAlphaSurface2SW fails
1 parent 501ace0 commit cf94b38

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/awt/common.h

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ struct TxtFrameUniforms {
112112
vector_float4 color;
113113
int mode; // NOTE: consider to use bit fields
114114
int isSrcOpaque;
115-
int isSrcPremult;
116115
int isDstOpaque;
117116
float extraAlpha;
118117
};

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

-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ fragment half4 frag_txt(
244244
return half4(c.r, c.g, c.b , c.a);
245245
}
246246

247-
if (uniforms.isSrcPremult) {
248-
pixelColor.rgb /= srcA;
249-
}
250-
251247
return half4(pixelColor.r,
252248
pixelColor.g,
253249
pixelColor.b, srcA)*uniforms.extraAlpha;

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,18 @@ jboolean clipDestCoords(
649649
SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
650650
}
651651

652+
void copyFromMTLBuffer(void *pDst, id<MTLBuffer> srcBuf, jint offset, jint len, BOOL convertFromArgbPre) {
653+
char *pSrc = (char*)srcBuf.contents + offset;
654+
if (convertFromArgbPre) {
655+
jint pixelLen = len>>2;
656+
for (int i = 0; i < pixelLen; i++) {
657+
LoadIntArgbPreTo1IntArgb((jint*)pSrc, 0, i, ((jint*)pDst)[i]);
658+
}
659+
} else {
660+
memcpy(pDst, pSrc, len);
661+
}
662+
}
663+
652664
/**
653665
* Specialized blit method for copying a native MTL "Surface" (pbuffer,
654666
* window, etc.) to a system memory ("Sw") surface.
@@ -719,7 +731,7 @@ jboolean clipDestCoords(
719731
// Metal texture is (0,0) at left-top
720732
srcx = srcOps->xOffset + srcx;
721733
srcy = srcOps->yOffset + srcy;
722-
const int srcLength = width * height * 4; // NOTE: assume that src format is MTLPixelFormatBGRA8Unorm
734+
const int byteLength = width * height * 4; // NOTE: assume that src format is MTLPixelFormatBGRA8Unorm
723735

724736
// Create MTLBuffer (or use static)
725737
MTLRasterFormatInfo rfi = RasterFormatInfos[dsttype];
@@ -771,27 +783,28 @@ jboolean clipDestCoords(
771783
toBuffer:mtlbuf
772784
destinationOffset:0 /*offset already taken in: pDst = PtrAddBytes(pDst, dstx * dstInfo.pixelStride)*/
773785
destinationBytesPerRow:width*4
774-
destinationBytesPerImage:width * height*4];
786+
destinationBytesPerImage:byteLength];
775787
[blitEncoder endEncoding];
776788

777789
// Commit and wait for reading complete
778790
[cb commit];
779791
[cb waitUntilCompleted];
780792

781793
// Perform conversion if necessary
794+
BOOL convertFromPre = !RasterFormatInfos[dsttype].isPremult && !srcOps->isOpaque;
782795
if (directCopy) {
783796
if ((dstInfo.scanStride == width * dstInfo.pixelStride) &&
784797
(height == (dstInfo.bounds.y2 - dstInfo.bounds.y1))) {
785798
// mtlbuf.contents have same dimensions as of pDst
786-
memcpy(pDst, mtlbuf.contents, srcLength);
799+
copyFromMTLBuffer(pDst, mtlbuf, 0, byteLength, convertFromPre);
787800
} else {
788801
// mtlbuf.contents have smaller dimensions than pDst
789802
// copy each row from mtlbuf.contents at appropriate position in pDst
790803
// Note : pDst is already addjusted for offsets using PtrAddBytes above
791804

792805
int rowSize = width * dstInfo.pixelStride;
793806
for (int y = 0; y < height; y++) {
794-
memcpy(pDst, mtlbuf.contents + (y * rowSize), rowSize);
807+
copyFromMTLBuffer(pDst, mtlbuf, y * rowSize, rowSize, convertFromPre);
795808
pDst = PtrAddBytes(pDst, dstInfo.scanStride);
796809
}
797810
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,7 @@ static void setTxtUniforms(
867867
id<MTLRenderCommandEncoder> encoder, int color, int mode, int interpolation, bool repeat, jfloat extraAlpha,
868868
const SurfaceRasterFlags * srcFlags, const SurfaceRasterFlags * dstFlags
869869
) {
870-
struct TxtFrameUniforms uf = {
871-
RGBA_TO_V4(color), mode, srcFlags->isOpaque, srcFlags->isPremultiplied,
872-
dstFlags->isOpaque, extraAlpha};
870+
struct TxtFrameUniforms uf = {RGBA_TO_V4(color), mode, srcFlags->isOpaque, dstFlags->isOpaque, extraAlpha};
873871
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:FrameUniformBuffer];
874872

875873
setSampler(encoder, interpolation, repeat);

0 commit comments

Comments
 (0)