Skip to content

Commit

Permalink
8272392: Lanai: SwingSet2. Black background on expanding tree node
Browse files Browse the repository at this point in the history
Reviewed-by: aghaisas, jdv
  • Loading branch information
Alexey Ushakov committed Dec 8, 2021
1 parent 9b74749 commit 8345453
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ - (id)init;
- (void)dealloc;

- (void)reset:(id<MTLTexture>)destination
isDstOpaque:(jboolean)isDstOpaque
isDstPremultiplied:(jboolean)isDstPremultiplied
isAA:(jboolean)isAA
isText:(jboolean)isText
isLCD:(jboolean)isLCD;
isAA:(jboolean)isAA
isText:(jboolean)isText
isLCD:(jboolean)isLCD;

- (void)updateEncoder:(id<MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
Expand All @@ -64,7 +62,6 @@ @implementation EncoderStates {

// Persistent encoder properties
id<MTLTexture> _destination;
SurfaceRasterFlags _dstFlags;

jboolean _isAA;
jboolean _isText;
Expand Down Expand Up @@ -123,14 +120,10 @@ - (void)setContext:(MTLContext * _Nonnull)mtlc {
}

- (void)reset:(id<MTLTexture>)destination
isDstOpaque:(jboolean)isDstOpaque
isDstPremultiplied:(jboolean)isDstPremultiplied
isAA:(jboolean)isAA
isText:(jboolean)isText
isLCD:(jboolean)isLCD {
isAA:(jboolean)isAA
isText:(jboolean)isText
isLCD:(jboolean)isLCD {
_destination = destination;
_dstFlags.isOpaque = isDstOpaque;
_dstFlags.isPremultiplied = isDstPremultiplied;
_isAA = isAA;
_isText = isText;
_isLCD = isLCD;
Expand Down Expand Up @@ -288,20 +281,20 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {

- (id<MTLRenderCommandEncoder> _Nonnull)getAARenderEncoder:(const BMTLSDOps * _Nonnull)dstOps {
id<MTLTexture> dstTxt = dstOps->pTexture;
RenderOptions roptions = {JNI_FALSE, JNI_TRUE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {dstOps->isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_FALSE, JNI_TRUE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dstTxt renderOptions:&roptions];
}

- (id<MTLRenderCommandEncoder> _Nonnull)getAAShaderRenderEncoder:(const BMTLSDOps * _Nonnull)dstOps
{
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {dstOps->isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_TRUE};
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, JNI_FALSE, JNI_FALSE, JNI_TRUE};
return [self getEncoder:dstOps->pTexture renderOptions:&roptions];
}

- (id<MTLRenderCommandEncoder> _Nonnull)getRenderEncoder:(id<MTLTexture> _Nonnull)dest
isDstOpaque:(bool)isOpaque
{
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

Expand Down Expand Up @@ -329,7 +322,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
isSrcOpaque:(bool)isSrcOpaque
isDstOpaque:(bool)isDstOpaque
{
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, {isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_TRUE, JNI_FALSE};
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, {isSrcOpaque, JNI_TRUE }, JNI_FALSE, JNI_TRUE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

Expand All @@ -339,7 +332,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
interpolation:(int)interpolation
isAA:(jboolean)isAA
{
RenderOptions roptions = {JNI_TRUE, isAA, interpolation, { isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_TRUE, isAA, interpolation, { isSrcOpaque, JNI_TRUE }, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

Expand All @@ -354,7 +347,8 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
- (id<MTLRenderCommandEncoder> _Nonnull) getTextEncoder:(const BMTLSDOps * _Nonnull)dstOps
isSrcOpaque:(bool)isSrcOpaque
{
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, { isSrcOpaque, JNI_TRUE }, {dstOps->isOpaque, JNI_TRUE}, JNI_TRUE, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, { isSrcOpaque, JNI_TRUE },
JNI_TRUE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dstOps->pTexture renderOptions:&roptions];
}

Expand Down Expand Up @@ -437,11 +431,9 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
_encoder = [[cbw getCommandBuffer] renderCommandEncoderWithDescriptor:rpd];

[_encoderStates reset:dest
isDstOpaque:renderOptions->dstFlags.isOpaque
isDstPremultiplied:YES
isAA:renderOptions->isAA
isText:renderOptions->isText
isLCD:renderOptions->isLCD];
isAA:renderOptions->isAA
isText:renderOptions->isText
isLCD:renderOptions->isLCD];
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,9 @@ jboolean clipDestCoords(
}

#ifdef TRACE_BLIT
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_FALSE,
"MTLBlitLoops_Blit [tx=%d, xf=%d, AC=%s]: bdst=%s, src=%p (%dx%d) O=%d premul=%d | (%d, %d, %d, %d)->(%1.2f, %1.2f, %1.2f, %1.2f)",
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE,
"MTLBlitLoops_Blit srctype=%d [tx=%d, xf=%d, AC=%s]: bdst=%s, src=%p (%dx%d) O=%d premul=%d | (%d, "
"%d, %d, %d)->(%1.2f, %1.2f, %1.2f, %1.2f)", srctype,
texture, xform, [mtlc getCompositeDescription].cString,
getSurfaceDescription(dstOps).cString, srcOps,
sx2 - sx1, sy2 - sy1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ @implementation MTLClip {
BMTLSDOps* _dstOps;
BOOL _stencilMaskGenerationInProgress;
BOOL _stencilMaskGenerationStarted;
BOOL _clipReady;
MTLOrigin _clipShapeOrigin;
MTLSize _clipShapeSize;
}
Expand All @@ -73,7 +72,6 @@ - (id)init {
_dstOps = NULL;
_stencilMaskGenerationInProgress = NO;
_stencilMaskGenerationStarted = NO;
_clipReady = NO;
}
return self;
}
Expand Down Expand Up @@ -189,7 +187,6 @@ - (void)endShapeClip:(BMTLSDOps *)dstOps context:(MTLContext *)mtlc {
_stencilMaskGenerationStarted = NO;
_dstOps = dstOps;
_clipType = SHAPE_CLIP;
_clipReady = NO;
}

- (void)setMaskGenerationPipelineState:(id<MTLRenderCommandEncoder>)encoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
static MTLRenderPipelineDescriptor * templateAAPipelineDesc = nil;
static void
setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder, int interpolation, bool repeat,
jfloat extraAlpha, const SurfaceRasterFlags *srcFlags, const SurfaceRasterFlags *dstFlags, int mode);
jfloat extraAlpha, const SurfaceRasterFlags *srcFlags, int mode);

static void initTemplatePipelineDescriptors() {
if (templateRenderPipelineDesc != nil && templateTexturePipelineDesc != nil &&
Expand Down Expand Up @@ -228,8 +228,8 @@ - (void)setPipelineState:(id<MTLRenderCommandEncoder>)encoder
rpDesc = [[templateLCDPipelineDesc copy] autorelease];
}
setTxtUniforms(mtlc, _color, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha], &renderOptions->srcFlags,
&renderOptions->dstFlags, 1);
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
&renderOptions->srcFlags, 1);
} else if (renderOptions->isAAShader) {
vertShader = @"vert_col_aa";
fragShader = @"frag_col_aa";
Expand Down Expand Up @@ -270,7 +270,7 @@ - (void)setXorModePipelineState:(id<MTLRenderCommandEncoder>)encoder

setTxtUniforms(mtlc, col, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
&renderOptions->srcFlags, &renderOptions->dstFlags, 1);
&renderOptions->srcFlags, 1);
[encoder setFragmentBytes:&xorColor length:sizeof(xorColor) atIndex:0];

[encoder setFragmentTexture:dstOps->pTexture atIndex:1];
Expand Down Expand Up @@ -809,9 +809,8 @@ - (void)setPipelineState:(id)encoder
[encoder setFragmentTexture:_paintTexture atIndex:0];
}
const SurfaceRasterFlags srcFlags = {_isOpaque, renderOptions->srcFlags.isPremultiplied};
setTxtUniforms(mtlc, 0, encoder,
renderOptions->interpolation, YES, [mtlc.composite getExtraAlpha],
&srcFlags, &renderOptions->dstFlags, 0);
setTxtUniforms(mtlc, 0, encoder, renderOptions->interpolation, YES, [mtlc.composite getExtraAlpha],
&srcFlags, 0);

id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
vertexShaderId:vertShader
Expand Down Expand Up @@ -893,8 +892,8 @@ - (NSString *)description {

static void
setTxtUniforms(MTLContext *mtlc, int color, id <MTLRenderCommandEncoder> encoder, int interpolation, bool repeat,
jfloat extraAlpha, const SurfaceRasterFlags *srcFlags, const SurfaceRasterFlags *dstFlags, int mode) {
struct TxtFrameUniforms uf = {RGBA_TO_V4(color), mode, srcFlags->isOpaque, dstFlags->isOpaque, extraAlpha};
jfloat extraAlpha, const SurfaceRasterFlags *srcFlags, int mode) {
struct TxtFrameUniforms uf = {RGBA_TO_V4(color), mode, srcFlags->isOpaque, extraAlpha};
[encoder setFragmentBytes:&uf length:sizeof(uf) atIndex:FrameUniformBuffer];
[mtlc.samplerManager setSamplerWithEncoder:encoder interpolation:interpolation repeat:repeat];
}
Expand Down Expand Up @@ -956,8 +955,7 @@ - (void)setPipelineState:(id <MTLRenderCommandEncoder>)encoder
} else {
setTxtUniforms(mtlc, 0, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
&renderOptions->srcFlags,
&renderOptions->dstFlags, 0);
&renderOptions->srcFlags, 0);

}
id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
Expand Down Expand Up @@ -998,16 +996,15 @@ - (void)setXorModePipelineState:(id <MTLRenderCommandEncoder>)encoder
const int col = 0 ^ xorColor;
setTxtUniforms(mtlc, col, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
&renderOptions->srcFlags, &renderOptions->dstFlags, 0);
&renderOptions->srcFlags, 0);
[encoder setFragmentBytes:&xorColor length:sizeof(xorColor) atIndex: 0];

BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
[encoder setFragmentTexture:dstOps->pTexture atIndex:1];

setTxtUniforms(mtlc, 0, encoder,
renderOptions->interpolation, NO, [mtlc.composite getExtraAlpha],
&renderOptions->srcFlags,
&renderOptions->dstFlags, 0);
&renderOptions->srcFlags, 0);

id <MTLRenderPipelineState> pipelineState = [pipelineStateStorage getPipelineState:rpDesc
vertexShaderId:vertShader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
vertexShaderId:(NSString *)vertexShaderId
fragmentShaderId:(NSString *)fragmentShaderId
{
RenderOptions defaultOptions = {JNI_FALSE, JNI_FALSE, 0/*unused*/, {JNI_FALSE, JNI_TRUE}, {JNI_FALSE, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
RenderOptions defaultOptions = {JNI_FALSE, JNI_FALSE, 0/*unused*/, {JNI_FALSE, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getPipelineState:pipelineDescriptor
vertexShaderId:vertexShaderId
fragmentShaderId:fragmentShaderId
Expand All @@ -98,7 +98,7 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
fragmentShaderId:(NSString *)fragmentShaderId
stencilNeeded:(bool)stencilNeeded
{
RenderOptions defaultOptions = {JNI_FALSE, JNI_FALSE, 0/*unused*/, {JNI_FALSE, JNI_TRUE}, {JNI_FALSE, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
RenderOptions defaultOptions = {JNI_FALSE, JNI_FALSE, 0/*unused*/, {JNI_FALSE, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getPipelineState:pipelineDescriptor
vertexShaderId:vertexShaderId
fragmentShaderId:fragmentShaderId
Expand All @@ -107,6 +107,19 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
stencilNeeded:stencilNeeded];
}

// Pipeline state index
union StateIndex {
uint32_t value;
struct {
uint32_t srcPremultiplied : 1,
srcOpaque : 1,
stencil : 1,
aa : 1,
extAlpha : 1,
compositeRule : 27;
} bits;
};

// Base method to obtain MTLRenderPipelineState.
// NOTE: parameters compositeRule, srcFlags, dstFlags are used to set MTLRenderPipelineColorAttachmentDescriptor multipliers
- (id<MTLRenderPipelineState>) getPipelineState:(MTLRenderPipelineDescriptor *) pipelineDescriptor
Expand All @@ -123,45 +136,31 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS

// Calculate index by flags and compositeRule
// TODO: reimplement, use map with convenient key (calculated by all arguments)
int subIndex = 0;
union StateIndex index;
index.value = 0;
if (useXorComposite) {
// compositeRule value is already XOR_COMPOSITE_RULE
}
else {
if (useComposite) {
if (!renderOptions->srcFlags.isPremultiplied)
subIndex |= 1;
if (renderOptions->srcFlags.isOpaque)
subIndex |= 1 << 1;
if (!renderOptions->dstFlags.isPremultiplied)
subIndex |= 1 << 2;
if (renderOptions->dstFlags.isOpaque)
subIndex |= 1 << 3;
index.bits.srcPremultiplied = renderOptions->srcFlags.isPremultiplied;
index.bits.srcOpaque = renderOptions->srcFlags.isOpaque;
} else
compositeRule = RULE_Src;
}

if (stencilNeeded) {
subIndex |= 1 << 4;
}

if (renderOptions->isAA) {
subIndex |= 1 << 5;
}

if ((composite != nil && FLT_LT([composite getExtraAlpha], 1.0f))) {
subIndex |= 1 << 6;
}

int index = compositeRule*128 + subIndex;
index.bits.stencil = stencilNeeded;
index.bits.aa = renderOptions->isAA;
index.bits.extAlpha = composite != nil && FLT_LT([composite getExtraAlpha], 1.0f);
index.bits.compositeRule = compositeRule;

NSPointerArray * subStates = [self getSubStates:vertexShaderId fragmentShader:fragmentShaderId];

if (index >= subStates.count) {
subStates.count = (NSUInteger) (index + 1);
if (index.value >= subStates.count) {
subStates.count = index.value + 1;
}

id<MTLRenderPipelineState> result = [subStates pointerAtIndex:index];
id<MTLRenderPipelineState> result = [subStates pointerAtIndex:index.value];
if (result == nil) {
@autoreleasepool {
id <MTLFunction> vertexShader = [self getShader:vertexShaderId];
Expand Down Expand Up @@ -222,7 +221,7 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
exit(0);
}

[subStates insertPointer:result atIndex:index];
[subStates replacePointerAtIndex:index.value withPointer:result];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ typedef struct {
jboolean isAA;
int interpolation;
SurfaceRasterFlags srcFlags;
SurfaceRasterFlags dstFlags;
jboolean isText;
jboolean isLCD;
jboolean isAAShader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ struct TxtFrameUniforms {
vector_float4 color;
int mode; // NOTE: consider to use bit fields
int isSrcOpaque;
int isDstOpaque;
float extraAlpha;
};

Expand Down

1 comment on commit 8345453

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.