Skip to content
This repository has been archived by the owner. It is now read-only.

8248129: Swingmark numbers are not good for Nimbus LAF #124

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -39,7 +39,8 @@ enum GradCycleMethod {
};
enum VertexAttributes {
VertexAttributePosition = 0,
VertexAttributeTexPos = 1
VertexAttributeTexPos = 1,
VertexAttributeITexPos = 2
};

enum BufferIndex {
@@ -90,6 +91,12 @@ struct TxtVertex {
float txtpos[2];
};

struct AAVertex {
float position[2];
float otxtpos[2];
float itxtpos[2];
};

// These values are mapped from AffineTransformOp
#define INTERPOLATION_NEAREST_NEIGHBOR 1
#define INTERPOLATION_BILINEAR 2
@@ -38,11 +38,24 @@ struct TxtVertexInput {
float2 texCoords [[attribute(VertexAttributeTexPos)]];
};

struct AAVertexInput {
float2 position [[attribute(VertexAttributePosition)]];
float2 oTexCoords [[attribute(VertexAttributeTexPos)]];
float2 iTexCoords [[attribute(VertexAttributeITexPos)]];
};

struct ColShaderInOut {
float4 position [[position]];
half4 color;
};

struct AAShaderInOut {
float4 position [[position]];
float2 outerTexCoords;
float2 innerTexCoords;
half4 color;
};

struct StencilShaderInOut {
float4 position [[position]];
char color;
@@ -89,6 +102,18 @@ vertex ColShaderInOut vert_col(VertexInput in [[stage_in]],
return out;
}

vertex AAShaderInOut vert_col_aa(AAVertexInput in [[stage_in]],
constant FrameUniforms& uniforms [[buffer(FrameUniformBuffer)]],
constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
AAShaderInOut out;
float4 pos4 = float4(in.position, 0.0, 1.0);
out.position = transform.transformMatrix*pos4;
out.color = half4(uniforms.color.r, uniforms.color.g, uniforms.color.b, uniforms.color.a);
out.outerTexCoords = in.oTexCoords;
out.innerTexCoords = in.iTexCoords;
return out;
}

vertex StencilShaderInOut vert_stencil(VertexInput in [[stage_in]],
constant FrameUniforms& uniforms [[buffer(FrameUniformBuffer)]],
constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
@@ -154,6 +179,48 @@ fragment half4 frag_col(ColShaderInOut in [[stage_in]]) {
return in.color;
}

fragment half4 frag_col_aa(AAShaderInOut in [[stage_in]]) {
float2 oleg1 = dfdx(in.outerTexCoords);
float2 oleg2 = dfdy(in.outerTexCoords);
// Calculate the bounds of the distorted pixel parallelogram.
float2 corner = in.outerTexCoords - (oleg1+oleg2)/2.0;
float2 omin = min(corner, corner+oleg1);
omin = min(omin, corner+oleg2);
omin = min(omin, corner+oleg1+oleg2);
float2 omax = max(corner, corner+oleg1);
omax = max(omax, corner+oleg2);
omax = max(omax, corner+oleg1+oleg2);
// Calculate the vectors for the "legs" of the pixel parallelogram
// for the inner parallelogram.
float2 ileg1 = dfdx(in.innerTexCoords);
float2 ileg2 = dfdy(in.innerTexCoords);
// Calculate the bounds of the distorted pixel parallelogram.
corner = in.innerTexCoords - (ileg1+ileg2)/2.0;
float2 imin = min(corner, corner+ileg1);
imin = min(imin, corner+ileg2);
imin = min(imin, corner+ileg1+ileg2);
float2 imax = max(corner, corner+ileg1);
imax = max(imax, corner+ileg2);
imax = max(imax, corner+ileg1+ileg2);
// Clamp the bounds of the parallelograms to the unit square to
// estimate the intersection of the pixel parallelogram with
// the unit square. The ratio of the 2 rectangle areas is a
// reasonable estimate of the proportion of coverage.
float2 o1 = clamp(omin, 0.0, 1.0);
float2 o2 = clamp(omax, 0.0, 1.0);
float oint = (o2.y-o1.y)*(o2.x-o1.x);
float oarea = (omax.y-omin.y)*(omax.x-omin.x);
float2 i1 = clamp(imin, 0.0, 1.0);
float2 i2 = clamp(imax, 0.0, 1.0);
float iint = (i2.y-i1.y)*(i2.x-i1.x);
float iarea = (imax.y-imin.y)*(imax.x-imin.x);
// Proportion of pixel in outer shape minus the proportion
// of pixel in the inner shape == the coverage of the pixel
// in the area between the two.
float coverage = oint/oarea - iint / iarea;
return (in.color * coverage);
}

fragment unsigned int frag_stencil(StencilShaderInOut in [[stage_in]]) {
return in.color;
}
@@ -339,28 +339,9 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
MTLRenderPassDescriptor *rpd =
[MTLRenderPassDescriptor renderPassDescriptor];
MTLRenderPassColorAttachmentDescriptor *ca = rpd.colorAttachments[0];
if (renderOptions->isAA && !renderOptions->isTexture) {
MTLTexturePoolItem *tiBuf = [_mtlc.texturePool getTexture:dest.width
height:dest.height
format:MTLPixelFormatBGRA8Unorm];
[cbw registerPooledTexture:tiBuf];
_aaDestination = tiBuf.texture;

MTLTexturePoolItem *ti = [_mtlc.texturePool getTexture:dest.width
height:dest.height
format:_aaDestination.pixelFormat
isMultiSample:YES];
[cbw registerPooledTexture:ti];
ca.texture = ti.texture;
ca.resolveTexture = _aaDestination;
ca.clearColor = MTLClearColorMake(0.0f, 0.0f, 0.0f, 0.0f);
ca.loadAction = MTLLoadActionClear;
ca.storeAction = MTLStoreActionMultisampleResolve;
} else {
ca.texture = dest;
ca.loadAction = MTLLoadActionLoad;
ca.storeAction = MTLStoreActionStore;
}
ca.texture = dest;
ca.loadAction = MTLLoadActionLoad;
ca.storeAction = MTLStoreActionStore;

if (_useStencil && !renderOptions->isAA) {
// If you enable stencil testing or stencil writing, the
@@ -400,35 +381,7 @@ - (void) endEncoder {
if (_encoder != nil) {
[_encoder endEncoding];
_encoder = nil;
if (_aaDestination != nil) {
id<MTLTexture> aaDest = _aaDestination;
_aaDestination = nil;
NSUInteger _w = _destination.width;
NSUInteger _h = _destination.height;
_encoder = [self getTextureEncoder:_destination
isSrcOpaque:JNI_FALSE
isDstOpaque:JNI_TRUE
interpolation:INTERPOLATION_NEAREST_NEIGHBOR
isAA:JNI_TRUE];
[_encoder setFragmentTexture:_mtlc.clip.stencilAADataRef atIndex: 1];

struct TxtVertex quadTxVerticesBuffer[] = {
{{0, 0}, {0, 0}},
{{0,_h}, {0, 1}},
{{_w, 0},{1, 0}},
{{0, _h},{0, 1}},
{{_w, _h}, {1, 1}},
{{_w, 0}, {1, 0}}
};

[_encoder setVertexBytes:quadTxVerticesBuffer length:sizeof(quadTxVerticesBuffer) atIndex:MeshVertexBuffer];
[_encoder setFragmentTexture:aaDest atIndex: 0];
[_encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:6];
[_encoder endEncoding];
}

_encoder = nil;
_destination = nil;
_destination = nil;
}
}

@@ -511,7 +511,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
jfloat lwr21 = NEXT_FLOAT(b);
jfloat lwr12 = NEXT_FLOAT(b);

MTLRenderer_DrawParallelogram(mtlc, dstOps, JNI_FALSE,
MTLRenderer_DrawParallelogram(mtlc, dstOps,
x11, y11,
dx21, dy21,
dx12, dy12,
@@ -530,7 +530,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
jfloat lwr21 = NEXT_FLOAT(b);
jfloat lwr12 = NEXT_FLOAT(b);

MTLRenderer_DrawParallelogram(mtlc, dstOps, JNI_TRUE,
MTLRenderer_DrawAAParallelogram(mtlc, dstOps,
x11, y11,
dx21, dy21,
dx12, dy12,
@@ -588,22 +588,22 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
jfloat dy21 = NEXT_FLOAT(b);
jfloat dx12 = NEXT_FLOAT(b);
jfloat dy12 = NEXT_FLOAT(b);
MTLRenderer_FillParallelogram(mtlc, dstOps, JNI_FALSE,
MTLRenderer_FillParallelogram(mtlc, dstOps,
x11, y11,
dx21, dy21,
dx12, dy12);
break;
}
case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:
{
CHECK_PREVIOUS_OP(MTL_OP_AA);
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
jfloat x11 = NEXT_FLOAT(b);
jfloat y11 = NEXT_FLOAT(b);
jfloat dx21 = NEXT_FLOAT(b);
jfloat dy21 = NEXT_FLOAT(b);
jfloat dx12 = NEXT_FLOAT(b);
jfloat dy12 = NEXT_FLOAT(b);
MTLRenderer_FillParallelogram(mtlc, dstOps, JNI_TRUE,
MTLRenderer_FillAAParallelogram(mtlc, dstOps,
x11, y11,
dx21, dy21,
dx12, dy12);
@@ -50,17 +50,25 @@ void MTLRenderer_DrawPoly(MTLContext *mtlc, BMTLSDOps * dstOps,
jint *xPoints, jint *yPoints);
void MTLRenderer_DrawScanlines(MTLContext *mtlc, BMTLSDOps * dstOps,
jint count, jint *scanlines);
void MTLRenderer_DrawParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps, jboolean isAA,
void MTLRenderer_DrawParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
jfloat fx11, jfloat fy11,
jfloat dx21, jfloat dy21,
jfloat dx12, jfloat dy12,
jfloat lw21, jfloat lw12);
void MTLRenderer_DrawAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
jfloat fx11, jfloat fy11,
jfloat dx21, jfloat dy21,
jfloat dx12, jfloat dy12,
jfloat lw21, jfloat lw12);

void MTLRenderer_FillRect(MTLContext *mtlc, BMTLSDOps * dstOps,
jint x, jint y, jint w, jint h);
void MTLRenderer_FillSpans(MTLContext *mtlc, BMTLSDOps * dstOps,
jint count, jint *spans);
void MTLRenderer_FillParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps, jboolean isAA,
void MTLRenderer_FillParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
jfloat fx11, jfloat fy11,
jfloat dx21, jfloat dy21,
jfloat dx12, jfloat dy12);
void MTLRenderer_FillAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
jfloat fx11, jfloat fy11,
jfloat dx21, jfloat dy21,
jfloat dx12, jfloat dy12);