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

8260706: Minor cleanup - CGLGraphicsConfig.java and MTLBlitLoops.m

  • Loading branch information
aghaisas committed Feb 1, 2021
1 parent b64eb4e commit 6a4d69512bb4fa1ab91e1b9ce8a669c9c3e0090c
@@ -63,7 +63,7 @@
import static sun.java2d.opengl.OGLSurfaceData.TEXTURE;

public final class CGLGraphicsConfig extends CGraphicsConfig
implements OGLGraphicsConfig
implements OGLGraphicsConfig
{
private static boolean cglAvailable;
private static ImageCapabilities imageCaps = new CGLImageCaps();
@@ -102,7 +102,7 @@ private CGLGraphicsConfig(CGraphicsDevice device, long configInfo,
// add a record to the Disposer so that we destroy the native
// CGLGraphicsConfigInfo data when this object goes away
Disposer.addRecord(disposerReferent,
new CGLGCDisposerRecord(pConfigInfo));
new CGLGCDisposerRecord(pConfigInfo));
}

@Override
@@ -113,9 +113,9 @@ public Object getProxyKey() {
@Override
public SurfaceData createManagedSurface(int w, int h, int transparency) {
return CGLSurfaceData.createData(this, w, h,
getColorModel(transparency),
null,
OGLSurfaceData.TEXTURE);
getColorModel(transparency),
null,
OGLSurfaceData.TEXTURE);
}

public static CGLGraphicsConfig getConfig(CGraphicsDevice device)
@@ -185,27 +185,27 @@ public OGLContext getContext() {
public BufferedImage createCompatibleImage(int width, int height) {
ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
WritableRaster
raster = model.createCompatibleWritableRaster(width, height);
raster = model.createCompatibleWritableRaster(width, height);
return new BufferedImage(model, raster, model.isAlphaPremultiplied(),
null);
null);
}

@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}

@@ -260,7 +260,7 @@ public Image createAcceleratedImage(Component target,
ColorModel model = getColorModel(Transparency.OPAQUE);
WritableRaster wr = model.createCompatibleWritableRaster(width, height);
return new OffScreenImage(target, model, wr,
model.isAlphaPremultiplied());
model.isAlphaPremultiplied());
}

@Override
@@ -291,7 +291,7 @@ public Image createBackBuffer(final LWComponentPeer<?, ?> peer) {
final int w = Math.max(1, r.width);
final int h = Math.max(1, r.height);
final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT
: Transparency.OPAQUE;
: Transparency.OPAQUE;
return new SunVolatileImage(this, w, h, transparency, null);
}

@@ -317,7 +317,7 @@ public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
try {
bg.setBackground(peer.getBackground());
bg.clearRect(0, 0, backBuffer.getWidth(null),
backBuffer.getHeight(null));
backBuffer.getHeight(null));
} finally {
bg.dispose();
}
@@ -327,7 +327,7 @@ public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
private static class CGLBufferCaps extends BufferCapabilities {
public CGLBufferCaps(boolean dblBuf) {
super(imageCaps, imageCaps,
dblBuf ? FlipContents.UNDEFINED : null);
dblBuf ? FlipContents.UNDEFINED : null);
}
}

@@ -363,10 +363,10 @@ public VolatileImage createCompatibleVolatileImage(int width, int height,
return null;
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
@@ -383,12 +383,12 @@ public ContextCapabilities getContextCapabilities() {
@Override
public int getMaxTextureWidth() {
return Math.max(maxTextureSize / getDevice().getScaleFactor(),
getBounds().width);
getBounds().width);
}

@Override
public int getMaxTextureHeight() {
return Math.max(maxTextureSize / getDevice().getScaleFactor(),
getBounds().height);
getBounds().height);
}
}
@@ -757,35 +757,27 @@ void copyFromMTLBuffer(void *pDst, id<MTLBuffer> srcBuf, jint offset, jint len,
#endif //DEBUG

@autoreleasepool {
id<MTLCommandBuffer> cb = [mtlc createCommandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [cb blitCommandEncoder];
id<MTLCommandBuffer> cb = [mtlc createCommandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [cb blitCommandEncoder];

// Create an intrermediate buffer
int totalBuffsize = width * height * 4;
id <MTLBuffer> buff = [[mtlc.device newBufferWithLength:totalBuffsize options:MTLResourceStorageModePrivate] autorelease];
// Create an intrermediate buffer
int totalBuffsize = width * height * 4;
id <MTLBuffer> buff = [[mtlc.device newBufferWithLength:totalBuffsize options:MTLResourceStorageModePrivate] autorelease];

[blitEncoder copyFromTexture:dstOps->pTexture
sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(x, y, 0) sourceSize:MTLSizeMake(width, height, 1)
toBuffer:buff destinationOffset:0 destinationBytesPerRow:(width * 4) destinationBytesPerImage:totalBuffsize];
[blitEncoder copyFromTexture:dstOps->pTexture
sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(x, y, 0) sourceSize:MTLSizeMake(width, height, 1)
toBuffer:buff destinationOffset:0 destinationBytesPerRow:(width * 4) destinationBytesPerImage:totalBuffsize];

[blitEncoder copyFromBuffer:buff
sourceOffset:0 sourceBytesPerRow:width*4 sourceBytesPerImage:totalBuffsize sourceSize:MTLSizeMake(width, height, 1)
toTexture:dstOps->pTexture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(x + dx, y + dy, 0)];
[blitEncoder endEncoding];

[cb commit];
//[cb waitUntilCompleted];

/*[blitEncoder
copyFromTexture:dstOps->pTexture
sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(x, y, 0) sourceSize:MTLSizeMake(width, height, 1)
toTexture:dstOps->pTexture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(x + dx, y + dy, 0)];
[blitEncoder endEncoding];*/
[blitEncoder copyFromBuffer:buff
sourceOffset:0 sourceBytesPerRow:width*4 sourceBytesPerImage:totalBuffsize sourceSize:MTLSizeMake(width, height, 1)
toTexture:dstOps->pTexture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(x + dx, y + dy, 0)];
[blitEncoder endEncoding];

[cb commit];
}

// TODO:
// 1. check rect bounds
// 2. support CopyArea with extra-alpha (and with custom Composite if necessary)
}

#endif /* !HEADLESS */

0 comments on commit 6a4d695

Please sign in to comment.