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

Commit ced2058

Browse files
committed
8248129: Swingmark numbers are not good for Nimbus LAF
8255212: J2DDemo : Rectangle in Texture paint disappears if we enable AA
1 parent fea7abd commit ced2058

File tree

6 files changed

+405
-79
lines changed

6 files changed

+405
-79
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ enum GradCycleMethod {
3939
};
4040
enum VertexAttributes {
4141
VertexAttributePosition = 0,
42-
VertexAttributeTexPos = 1
42+
VertexAttributeTexPos = 1,
43+
VertexAttributeITexPos = 2
4344
};
4445

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

94+
struct AAVertex {
95+
float position[2];
96+
float otxtpos[2];
97+
float itxtpos[2];
98+
};
99+
93100
// These values are mapped from AffineTransformOp
94101
#define INTERPOLATION_NEAREST_NEIGHBOR 1
95102
#define INTERPOLATION_BILINEAR 2

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,24 @@ struct TxtVertexInput {
3838
float2 texCoords [[attribute(VertexAttributeTexPos)]];
3939
};
4040

41+
struct AAVertexInput {
42+
float2 position [[attribute(VertexAttributePosition)]];
43+
float2 oTexCoords [[attribute(VertexAttributeTexPos)]];
44+
float2 iTexCoords [[attribute(VertexAttributeITexPos)]];
45+
};
46+
4147
struct ColShaderInOut {
4248
float4 position [[position]];
4349
half4 color;
4450
};
4551

52+
struct AAShaderInOut {
53+
float4 position [[position]];
54+
float2 outerTexCoords;
55+
float2 innerTexCoords;
56+
half4 color;
57+
};
58+
4659
struct StencilShaderInOut {
4760
float4 position [[position]];
4861
char color;
@@ -89,6 +102,18 @@ vertex ColShaderInOut vert_col(VertexInput in [[stage_in]],
89102
return out;
90103
}
91104

105+
vertex AAShaderInOut vert_col_aa(AAVertexInput in [[stage_in]],
106+
constant FrameUniforms& uniforms [[buffer(FrameUniformBuffer)]],
107+
constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
108+
AAShaderInOut out;
109+
float4 pos4 = float4(in.position, 0.0, 1.0);
110+
out.position = transform.transformMatrix*pos4;
111+
out.color = half4(uniforms.color.r, uniforms.color.g, uniforms.color.b, uniforms.color.a);
112+
out.outerTexCoords = in.oTexCoords;
113+
out.innerTexCoords = in.iTexCoords;
114+
return out;
115+
}
116+
92117
vertex StencilShaderInOut vert_stencil(VertexInput in [[stage_in]],
93118
constant FrameUniforms& uniforms [[buffer(FrameUniformBuffer)]],
94119
constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
@@ -154,6 +179,48 @@ fragment half4 frag_col(ColShaderInOut in [[stage_in]]) {
154179
return in.color;
155180
}
156181

182+
fragment half4 frag_col_aa(AAShaderInOut in [[stage_in]]) {
183+
float2 oleg1 = dfdx(in.outerTexCoords);
184+
float2 oleg2 = dfdy(in.outerTexCoords);
185+
// Calculate the bounds of the distorted pixel parallelogram.
186+
float2 corner = in.outerTexCoords - (oleg1+oleg2)/2.0;
187+
float2 omin = min(corner, corner+oleg1);
188+
omin = min(omin, corner+oleg2);
189+
omin = min(omin, corner+oleg1+oleg2);
190+
float2 omax = max(corner, corner+oleg1);
191+
omax = max(omax, corner+oleg2);
192+
omax = max(omax, corner+oleg1+oleg2);
193+
// Calculate the vectors for the "legs" of the pixel parallelogram
194+
// for the inner parallelogram.
195+
float2 ileg1 = dfdx(in.innerTexCoords);
196+
float2 ileg2 = dfdy(in.innerTexCoords);
197+
// Calculate the bounds of the distorted pixel parallelogram.
198+
corner = in.innerTexCoords - (ileg1+ileg2)/2.0;
199+
float2 imin = min(corner, corner+ileg1);
200+
imin = min(imin, corner+ileg2);
201+
imin = min(imin, corner+ileg1+ileg2);
202+
float2 imax = max(corner, corner+ileg1);
203+
imax = max(imax, corner+ileg2);
204+
imax = max(imax, corner+ileg1+ileg2);
205+
// Clamp the bounds of the parallelograms to the unit square to
206+
// estimate the intersection of the pixel parallelogram with
207+
// the unit square. The ratio of the 2 rectangle areas is a
208+
// reasonable estimate of the proportion of coverage.
209+
float2 o1 = clamp(omin, 0.0, 1.0);
210+
float2 o2 = clamp(omax, 0.0, 1.0);
211+
float oint = (o2.y-o1.y)*(o2.x-o1.x);
212+
float oarea = (omax.y-omin.y)*(omax.x-omin.x);
213+
float2 i1 = clamp(imin, 0.0, 1.0);
214+
float2 i2 = clamp(imax, 0.0, 1.0);
215+
float iint = (i2.y-i1.y)*(i2.x-i1.x);
216+
float iarea = (imax.y-imin.y)*(imax.x-imin.x);
217+
// Proportion of pixel in outer shape minus the proportion
218+
// of pixel in the inner shape == the coverage of the pixel
219+
// in the area between the two.
220+
float coverage = oint/oarea - iint / iarea;
221+
return (in.color * coverage);
222+
}
223+
157224
fragment unsigned int frag_stencil(StencilShaderInOut in [[stage_in]]) {
158225
return in.color;
159226
}

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/EncoderManager.m

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -339,28 +339,9 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
339339
MTLRenderPassDescriptor *rpd =
340340
[MTLRenderPassDescriptor renderPassDescriptor];
341341
MTLRenderPassColorAttachmentDescriptor *ca = rpd.colorAttachments[0];
342-
if (renderOptions->isAA && !renderOptions->isTexture) {
343-
MTLTexturePoolItem *tiBuf = [_mtlc.texturePool getTexture:dest.width
344-
height:dest.height
345-
format:MTLPixelFormatBGRA8Unorm];
346-
[cbw registerPooledTexture:tiBuf];
347-
_aaDestination = tiBuf.texture;
348-
349-
MTLTexturePoolItem *ti = [_mtlc.texturePool getTexture:dest.width
350-
height:dest.height
351-
format:_aaDestination.pixelFormat
352-
isMultiSample:YES];
353-
[cbw registerPooledTexture:ti];
354-
ca.texture = ti.texture;
355-
ca.resolveTexture = _aaDestination;
356-
ca.clearColor = MTLClearColorMake(0.0f, 0.0f, 0.0f, 0.0f);
357-
ca.loadAction = MTLLoadActionClear;
358-
ca.storeAction = MTLStoreActionMultisampleResolve;
359-
} else {
360-
ca.texture = dest;
361-
ca.loadAction = MTLLoadActionLoad;
362-
ca.storeAction = MTLStoreActionStore;
363-
}
342+
ca.texture = dest;
343+
ca.loadAction = MTLLoadActionLoad;
344+
ca.storeAction = MTLStoreActionStore;
364345

365346
if (_useStencil && !renderOptions->isAA) {
366347
// If you enable stencil testing or stencil writing, the
@@ -400,35 +381,7 @@ - (void) endEncoder {
400381
if (_encoder != nil) {
401382
[_encoder endEncoding];
402383
_encoder = nil;
403-
if (_aaDestination != nil) {
404-
id<MTLTexture> aaDest = _aaDestination;
405-
_aaDestination = nil;
406-
NSUInteger _w = _destination.width;
407-
NSUInteger _h = _destination.height;
408-
_encoder = [self getTextureEncoder:_destination
409-
isSrcOpaque:JNI_FALSE
410-
isDstOpaque:JNI_TRUE
411-
interpolation:INTERPOLATION_NEAREST_NEIGHBOR
412-
isAA:JNI_TRUE];
413-
[_encoder setFragmentTexture:_mtlc.clip.stencilAADataRef atIndex: 1];
414-
415-
struct TxtVertex quadTxVerticesBuffer[] = {
416-
{{0, 0}, {0, 0}},
417-
{{0,_h}, {0, 1}},
418-
{{_w, 0},{1, 0}},
419-
{{0, _h},{0, 1}},
420-
{{_w, _h}, {1, 1}},
421-
{{_w, 0}, {1, 0}}
422-
};
423-
424-
[_encoder setVertexBytes:quadTxVerticesBuffer length:sizeof(quadTxVerticesBuffer) atIndex:MeshVertexBuffer];
425-
[_encoder setFragmentTexture:aaDest atIndex: 0];
426-
[_encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:6];
427-
[_encoder endEncoding];
428-
}
429-
430-
_encoder = nil;
431-
_destination = nil;
384+
_destination = nil;
432385
}
433386
}
434387

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
511511
jfloat lwr21 = NEXT_FLOAT(b);
512512
jfloat lwr12 = NEXT_FLOAT(b);
513513

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

533-
MTLRenderer_DrawParallelogram(mtlc, dstOps, JNI_TRUE,
533+
MTLRenderer_DrawAAParallelogram(mtlc, dstOps,
534534
x11, y11,
535535
dx21, dy21,
536536
dx12, dy12,
@@ -588,22 +588,22 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
588588
jfloat dy21 = NEXT_FLOAT(b);
589589
jfloat dx12 = NEXT_FLOAT(b);
590590
jfloat dy12 = NEXT_FLOAT(b);
591-
MTLRenderer_FillParallelogram(mtlc, dstOps, JNI_FALSE,
591+
MTLRenderer_FillParallelogram(mtlc, dstOps,
592592
x11, y11,
593593
dx21, dy21,
594594
dx12, dy12);
595595
break;
596596
}
597597
case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:
598598
{
599-
CHECK_PREVIOUS_OP(MTL_OP_AA);
599+
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
600600
jfloat x11 = NEXT_FLOAT(b);
601601
jfloat y11 = NEXT_FLOAT(b);
602602
jfloat dx21 = NEXT_FLOAT(b);
603603
jfloat dy21 = NEXT_FLOAT(b);
604604
jfloat dx12 = NEXT_FLOAT(b);
605605
jfloat dy12 = NEXT_FLOAT(b);
606-
MTLRenderer_FillParallelogram(mtlc, dstOps, JNI_TRUE,
606+
MTLRenderer_FillAAParallelogram(mtlc, dstOps,
607607
x11, y11,
608608
dx21, dy21,
609609
dx12, dy12);

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@ void MTLRenderer_DrawPoly(MTLContext *mtlc, BMTLSDOps * dstOps,
5050
jint *xPoints, jint *yPoints);
5151
void MTLRenderer_DrawScanlines(MTLContext *mtlc, BMTLSDOps * dstOps,
5252
jint count, jint *scanlines);
53-
void MTLRenderer_DrawParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps, jboolean isAA,
53+
void MTLRenderer_DrawParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
54+
jfloat fx11, jfloat fy11,
55+
jfloat dx21, jfloat dy21,
56+
jfloat dx12, jfloat dy12,
57+
jfloat lw21, jfloat lw12);
58+
void MTLRenderer_DrawAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
5459
jfloat fx11, jfloat fy11,
5560
jfloat dx21, jfloat dy21,
5661
jfloat dx12, jfloat dy12,
5762
jfloat lw21, jfloat lw12);
58-
5963
void MTLRenderer_FillRect(MTLContext *mtlc, BMTLSDOps * dstOps,
6064
jint x, jint y, jint w, jint h);
6165
void MTLRenderer_FillSpans(MTLContext *mtlc, BMTLSDOps * dstOps,
6266
jint count, jint *spans);
63-
void MTLRenderer_FillParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps, jboolean isAA,
67+
void MTLRenderer_FillParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
68+
jfloat fx11, jfloat fy11,
69+
jfloat dx21, jfloat dy21,
70+
jfloat dx12, jfloat dy12);
71+
void MTLRenderer_FillAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
6472
jfloat fx11, jfloat fy11,
6573
jfloat dx21, jfloat dy21,
6674
jfloat dx12, jfloat dy12);

0 commit comments

Comments
 (0)