8264475: CopyArea ignores clip state in metal rendering pipeline

8251036: SwingSet2 - Dragging internal frame inside jframe leaves artifacts with MetalLookAndFeel

Reviewed-by: aghaisas, psadhukhan
This commit is contained in:
Jayathirth D V 2021-04-05 05:28:21 +00:00
parent f084bd2f61
commit 0039c18e08
2 changed files with 37 additions and 13 deletions

View File

@ -800,23 +800,45 @@ MTLBlitLoops_CopyArea(JNIEnv *env,
(dstBounds.x1 < dstBounds.x2 && dstBounds.y1 < dstBounds.y2))
{
@autoreleasepool {
id<MTLCommandBuffer> cb = [mtlc createCommandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [cb blitCommandEncoder];
struct TxtVertex quadTxVerticesBuffer[6];
MTLPooledTextureHandle * interHandle =
[mtlc.texturePool getTexture:texWidth
height:texHeight
format:MTLPixelFormatBGRA8Unorm];
if (interHandle == nil) {
J2dTraceLn(J2D_TRACE_ERROR,
"MTLBlitLoops_CopyArea: texture handle is null");
return;
}
[[mtlc getCommandBufferWrapper] registerPooledTexture:interHandle];
// Create an intrermediate buffer
int totalBuffsize = srcWidth * srcHeight * 4;
id <MTLBuffer> buff = [[mtlc.device newBufferWithLength:totalBuffsize options:MTLResourceStorageModePrivate] autorelease];
id<MTLTexture> interTexture = interHandle.texture;
[blitEncoder copyFromTexture:dstOps->pTexture
sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(srcBounds.x1, srcBounds.y1, 0) sourceSize:MTLSizeMake(srcWidth, srcHeight, 1)
toBuffer:buff destinationOffset:0 destinationBytesPerRow:(srcWidth * 4) destinationBytesPerImage:totalBuffsize];
/*
* We need to consider common states like clipping while
* performing copyArea, thats why we use drawTex2Tex and
* get encoder with appropriate state from EncoderManager
* and not directly use MTLBlitCommandEncoder for texture copy.
*/
[blitEncoder copyFromBuffer:buff
sourceOffset:0 sourceBytesPerRow:srcWidth*4 sourceBytesPerImage:totalBuffsize sourceSize:MTLSizeMake(srcWidth, srcHeight, 1)
toTexture:dstOps->pTexture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(dstBounds.x1, dstBounds.y1, 0)];
[blitEncoder endEncoding];
// copy content to intermediate texture
drawTex2Tex(mtlc, dstOps->pTexture, interTexture, dstOps->isOpaque,
JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR,
0, 0, texWidth, texHeight, 0, 0, texWidth, texHeight);
[cb commit];
// copy content with appropriate bounds to destination texture
drawTex2Tex(mtlc, interTexture, dstOps->pTexture, JNI_FALSE,
dstOps->isOpaque, INTERPOLATION_NEAREST_NEIGHBOR,
srcBounds.x1, srcBounds.y1, srcBounds.x2, srcBounds.y2,
dstBounds.x1, dstBounds.y1, dstBounds.x2, dstBounds.y2);
[mtlc.encoderManager endEncoder];
MTLCommandBufferWrapper * cbwrapper =
[mtlc pullCommandBufferWrapper];
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
[cbwrapper release];
}];
[commandbuf commit];
}
}
}

View File

@ -202,6 +202,8 @@
width:(NSUInteger) width
height:(NSUInteger) height
mipmapped:NO];
textureDescriptor.usage = MTLTextureUsageRenderTarget |
MTLTextureUsageShaderRead;
if (isMultiSample) {
textureDescriptor.textureType = MTLTextureType2DMultisample;
textureDescriptor.sampleCount = MTLAASampleCount;