Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8242920: Gradient Paint doesn't work with metal
  • Loading branch information
Alexey Ushakov committed Aug 26, 2020
1 parent 1e4c6af commit a9a6e4f7cd8c2b5806257f3409b0d463bea4a77a
Showing 3 changed files with 25 additions and 3 deletions.
@@ -54,6 +54,7 @@ struct GradFrameUniforms {
vector_float3 params;
vector_float4 color1;
vector_float4 color2;
int isCyclic;
};

struct Vertex {
@@ -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,
@@ -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);
}
@@ -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 {
@@ -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";
@@ -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();

0 comments on commit a9a6e4f

Please sign in to comment.