Navigation Menu

Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8242920: Gradient Paint doesn't work with metal
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Ushakov committed Aug 26, 2020
1 parent 1e4c6af commit a9a6e4f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/common.h
Expand Up @@ -54,6 +54,7 @@ struct GradFrameUniforms {
vector_float3 params;
vector_float4 color1;
vector_float4 color2;
int isCyclic;
};

struct Vertex {
Expand Down
16 changes: 16 additions & 0 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal
Expand Up @@ -206,6 +206,14 @@ fragment half4 frag_txt_grad(GradShaderInOut in [[stage_in]],

float3 v = float3(in.position.x, in.position.y, 1);
float a = (dot(v,uniforms.params)-0.25)*2.0;
int fa = floor(a);
if (uniforms.isCyclic) {
if (fa%2) {
a = 1.0 + fa - a;
} else {
a = a - fa;
}
}
float4 c = mix(uniforms.color1, uniforms.color2, a);
return half4(c.r*renderColor.a,
c.g*renderColor.a,
Expand Down Expand Up @@ -352,6 +360,14 @@ fragment half4 frag_grad(GradShaderInOut in [[stage_in]],
constant GradFrameUniforms& uniforms [[buffer(0)]]) {
float3 v = float3(in.position.x, in.position.y, 1);
float a = (dot(v,uniforms.params)-0.25)*2.0;
int fa = floor(a);
if (uniforms.isCyclic) {
if (fa%2) {
a = 1.0 + fa - a;
} else {
a = a - fa;
}
}
float4 c = mix(uniforms.color1, uniforms.color2, a);
return half4(c);
}
Expand Down
Expand Up @@ -420,7 +420,8 @@ - (void)setPipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1),
RGBA_TO_V4(_pixel2)};
RGBA_TO_V4(_pixel2),
_cyclic};
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:0];

} else {
Expand Down Expand Up @@ -451,7 +452,9 @@ - (void)setPipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1),
RGBA_TO_V4(_pixel2)};
RGBA_TO_V4(_pixel2),
_cyclic
};
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:0];
} else if (_paintState == sun_java2d_SunGraphics2D_PAINT_TEXTURE) {
vertShader = @"vert_tp";
Expand Down Expand Up @@ -525,7 +528,9 @@ - (void)setXorModePipelineState:(id<MTLRenderCommandEncoder>)encoder
struct GradFrameUniforms uf = {
{_p0, _p1, _p3},
RGBA_TO_V4(_pixel1 ^ xorColor),
RGBA_TO_V4(_pixel2 ^ xorColor)};
RGBA_TO_V4(_pixel2 ^ xorColor),
_cyclic
};

[encoder setFragmentBytes: &uf length:sizeof(uf) atIndex:0];
BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
Expand Down

0 comments on commit a9a6e4f

Please sign in to comment.