diff options
4 files changed, 16 insertions, 10 deletions
diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal b/src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal index b944c74cb15..99d36c5bca0 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal @@ -532,17 +532,13 @@ vertex TxtShaderInOut vert_tp(VertexInput in [[stage_in]], fragment half4 frag_tp( TxtShaderInOut vert [[stage_in]], - texture2d<float, access::sample> renderTexture [[texture(0)]]) + texture2d<float, access::sample> renderTexture [[texture(0)]], + constant TxtFrameUniforms& uniforms [[buffer(1)]], + sampler textureSampler [[sampler(0)]]) { - constexpr sampler textureSampler (address::repeat, - mag_filter::nearest, - min_filter::nearest); - float4 pixelColor = renderTexture.sample(textureSampler, vert.texCoords); - return half4(pixelColor.r, pixelColor.g, pixelColor.b, 1.0); - - // This implementation defaults alpha to 1.0 as if source is opaque - //TODO : implement alpha component value if source is transparent + const float srcA = uniforms.isSrcOpaque ? 1 : pixelColor.a; + return half4(pixelColor.r, pixelColor.g, pixelColor.b, srcA) * uniforms.extraAlpha; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m index 676d5f20dd2..0d0f3a494db 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m @@ -435,6 +435,7 @@ extern void initSamplers(id<MTLDevice> device); self.paint = [[[MTLTexturePaint alloc] initWithUseMask:useMask textureID:srcOps->pTexture + isOpaque:srcOps->isOpaque filter:filter xp0:xp0 xp1:xp1 diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.h index 933588f4170..b74bdf39785 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.h @@ -133,6 +133,7 @@ - (id)initWithUseMask:(jboolean)useMask textureID:(id <MTLTexture>)textureID + isOpaque:(jboolean)isOpaque filter:(jboolean)filter xp0:(jdouble)xp0 xp1:(jdouble)xp1 diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m index 49dad8b9b65..b1ed0b7c127 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m @@ -657,10 +657,12 @@ jint _color; @implementation MTLTexturePaint { struct AnchorData _anchor; id <MTLTexture> _paintTexture; + jboolean _isOpaque; } - (id)initWithUseMask:(jboolean)useMask textureID:(id)textureId + isOpaque:(jboolean)isOpaque filter:(jboolean)filter xp0:(jdouble)xp0 xp1:(jdouble)xp1 @@ -680,6 +682,7 @@ jint _color; _anchor.yParams[0] = yp0; _anchor.yParams[1] = yp1; _anchor.yParams[2] = yp3; + _isOpaque = isOpaque; } return self; @@ -701,7 +704,7 @@ jint _color; } - (NSString *)description { - return [NSString stringWithFormat:@"radial_gradient"]; + return [NSString stringWithFormat:@"texture_paint"]; } - (void)setPipelineState:(id)encoder @@ -727,6 +730,11 @@ jint _color; } else { rpDesc = [[templateRenderPipelineDesc copy] autorelease]; [encoder setFragmentTexture:_paintTexture atIndex:0]; + const SurfaceRasterFlags srcFlags = {_isOpaque, renderOptions->srcFlags.isPremultiplied}; + setTxtUniforms(encoder, 0, 0, + renderOptions->interpolation, YES, [mtlc.composite getExtraAlpha], + &srcFlags, + &renderOptions->dstFlags); } id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc |