From 5a0ccbd732f17dc79ee2358e51ad7ddf2d262ffa Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Thu, 7 Jan 2021 14:09:58 +0000 Subject: [PATCH] 8245256: Cleanup OpenGL references in Metal documentation --- .../java2d/MacosxSurfaceManagerFactory.java | 2 +- .../sun/java2d/metal/MTLBlitLoops.java | 34 +- .../sun/java2d/metal/MTLGraphicsConfig.java | 10 +- .../classes/sun/java2d/metal/MTLLayer.java | 2 +- .../classes/sun/java2d/metal/MTLMaskBlit.java | 4 +- .../classes/sun/java2d/metal/MTLPaints.java | 11 +- .../sun/java2d/metal/MTLRenderQueue.java | 8 +- .../sun/java2d/metal/MTLSurfaceData.java | 12 +- .../sun/java2d/metal/MTLSurfaceDataProxy.java | 2 +- .../sun/java2d/metal/MTLTextRenderer.java | 4 +- .../sun/java2d/metal/MTLUtilities.java | 10 +- .../classes/sun/lwawt/macosx/LWCToolkit.java | 2 +- .../libawt_lwawt/java2d/metal/MTLContext.h | 42 +- .../libawt_lwawt/java2d/metal/MTLContext.m | 19 +- .../java2d/metal/MTLGraphicsConfig.h | 31 +- .../java2d/metal/MTLGraphicsConfig.m | 10 +- .../libawt_lwawt/java2d/metal/MTLLayer.h | 2 +- .../libawt_lwawt/java2d/metal/MTLMaskFill.m | 44 +-- .../libawt_lwawt/java2d/metal/MTLPaints.m | 367 ------------------ .../libawt_lwawt/java2d/metal/MTLRenderer.m | 11 +- .../java2d/metal/MTLSurfaceData.h | 2 +- .../java2d/metal/MTLSurfaceData.m | 19 +- .../java2d/metal/MTLSurfaceDataBase.h | 81 +--- .../java2d/metal/MTLTextRenderer.m | 5 +- .../java2d/metal/MTLVertexCache.h | 1 - .../java2d/metal/MTLVertexCache.m | 51 +-- 26 files changed, 89 insertions(+), 697 deletions(-) diff --git a/src/java.desktop/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java b/src/java.desktop/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java index cef692c3ab0..f6365dbbfc8 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java +++ b/src/java.desktop/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java @@ -44,7 +44,7 @@ public class MacosxSurfaceManagerFactory extends SurfaceManagerFactory { * as a way for the caller to pass pipeline-specific context data to * the VolatileSurfaceManager (such as a backbuffer handle, for example). * - * For Mac OS X, this method returns either an CGL-specific + * For Mac OS X, this method returns either an CGL/MTL-specific * VolatileSurfaceManager based on the GraphicsConfiguration * under which the SunVolatileImage was created. */ diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBlitLoops.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBlitLoops.java index 3b19e37f1e3..c58f58f9b10 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBlitLoops.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBlitLoops.java @@ -273,14 +273,14 @@ static void Blit(SurfaceData srcData, SurfaceData dstData, // disposed while the operation is processed on the QFT rq.addReference(srcData); - MTLSurfaceData oglDst = (MTLSurfaceData)dstData; + MTLSurfaceData mtlDst = (MTLSurfaceData)dstData; if (texture) { // make sure we have a current context before uploading // the sysmem data to the texture object - MTLGraphicsConfig gc = oglDst.getMTLGraphicsConfig(); + MTLGraphicsConfig gc = mtlDst.getMTLGraphicsConfig(); MTLContext.setScratchSurface(gc); } else { - MTLContext.validateContext(oglDst, oglDst, + MTLContext.validateContext(mtlDst, mtlDst, clip, comp, xform, null, null, ctxflags); } @@ -325,9 +325,9 @@ static void IsoBlit(SurfaceData srcData, SurfaceData dstData, MTLRenderQueue rq = MTLRenderQueue.getInstance(); rq.lock(); try { - MTLSurfaceData oglSrc = (MTLSurfaceData)srcData; - MTLSurfaceData oglDst = (MTLSurfaceData)dstData; - int srctype = oglSrc.getType(); + MTLSurfaceData mtlSrc = (MTLSurfaceData)srcData; + MTLSurfaceData mtlDst = (MTLSurfaceData)dstData; + int srctype = mtlSrc.getType(); boolean rtt; MTLSurfaceData srcCtxData; if (srctype == MTLSurfaceData.TEXTURE) { @@ -335,25 +335,25 @@ static void IsoBlit(SurfaceData srcData, SurfaceData dstData, // the destination surface for the purposes of making a // context current rtt = false; - srcCtxData = oglDst; + srcCtxData = mtlDst; } else { // the source is a pbuffer, backbuffer, or render-to-texture // surface; we set rtt to true to differentiate this kind // of surface from a regular texture object rtt = true; if (srctype == AccelSurface.RT_TEXTURE) { - srcCtxData = oglDst; + srcCtxData = mtlDst; } else { - srcCtxData = oglSrc; + srcCtxData = mtlSrc; } } - MTLContext.validateContext(srcCtxData, oglDst, + MTLContext.validateContext(srcCtxData, mtlDst, clip, comp, xform, null, null, ctxflags); if (biop != null) { - MTLBufImgOps.enableBufImgOp(rq, oglSrc, srcImg, biop); + MTLBufImgOps.enableBufImgOp(rq, mtlSrc, srcImg, biop); } int packedParams = createPackedParams(true, texture, @@ -368,7 +368,7 @@ static void IsoBlit(SurfaceData srcData, SurfaceData dstData, MTLBufImgOps.disableBufImgOp(rq, biop); } - if (rtt && oglDst.isOnScreen()) { + if (rtt && mtlDst.isOnScreen()) { // we only have to flush immediately when copying from a // (non-texture) surface to the screen; otherwise Swing apps // might appear unresponsive until the auto-flush completes @@ -793,7 +793,7 @@ public void Transform(SurfaceData src, SurfaceData dst, * This general Blit implementation converts any source surface to an * intermediate IntArgbPre surface, and then uses the more specific * IntArgbPre->MTLSurface/Texture loop to get the intermediate - * (premultiplied) surface down to OpenGL using simple blit. + * (premultiplied) surface down to Metal using simple blit. */ class MTLGeneralBlit extends Blit { @@ -827,7 +827,7 @@ public synchronized void Blit(SurfaceData src, SurfaceData dst, src = convertFrom(convertsrc, src, sx, sy, w, h, cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE); - // copy IntArgbPre intermediate surface to OpenGL surface + // copy IntArgbPre intermediate surface to Metal surface performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h); @@ -842,7 +842,7 @@ public synchronized void Blit(SurfaceData src, SurfaceData dst, * This general TransformedBlit implementation converts any source surface to an * intermediate IntArgbPre surface, and then uses the more specific * IntArgbPre->MTLSurface/Texture loop to get the intermediate - * (premultiplied) surface down to OpenGL using simple transformBlit. + * (premultiplied) surface down to Metal using simple transformBlit. */ final class MTLGeneralTransformedBlit extends TransformBlit { @@ -870,7 +870,7 @@ public synchronized void Transform(SurfaceData src, SurfaceData dst, src = convertFrom(convertsrc, src, srcx, srcy, width, height, cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE); - // transform IntArgbPre intermediate surface to OpenGL surface + // transform IntArgbPre intermediate surface to Metal surface performop.Transform(src, dst, comp, clip, at, hint, 0, 0, dstx, dsty, width, height); @@ -885,7 +885,7 @@ public synchronized void Transform(SurfaceData src, SurfaceData dst, * This general MTLAnyCompositeBlit implementation can convert any source/target * surface to an intermediate surface using convertsrc/convertdst loops, applies * necessary composite operation, and then uses convertresult loop to get the - * intermediate surface down to OpenGL. + * intermediate surface down to Metal. */ final class MTLAnyCompositeBlit extends Blit { diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java index 3e715ef9587..5cb4cd4d749 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java @@ -60,7 +60,7 @@ public final class MTLGraphicsConfig extends CGraphicsConfig { //private static final int kOpenGLSwapInterval = // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; - private static final int kOpenGLSwapInterval = 0; // TODO + private static final int kMetalSwapInterval = 0; // TODO private static boolean mtlAvailable; private static ImageCapabilities imageCaps = new MTLImageCaps(); @@ -82,10 +82,8 @@ public final class MTLGraphicsConfig extends CGraphicsConfig private static native long getMTLConfigInfo(int displayID, String mtlShadersLib); /** - * Returns GL_MAX_TEXTURE_SIZE from the shared opengl context. Must be - * called under OGLRQ lock, because this method change current context. - * - * @return GL_MAX_TEXTURE_SIZE + * Returns maximum texture size supported by Metal. Must be + * called under MTLRQ lock. */ private static native int nativeGetMaxTextureSize(); @@ -134,7 +132,7 @@ public static MTLGraphicsConfig getConfig(CGraphicsDevice device, MTLRenderQueue rq = MTLRenderQueue.getInstance(); rq.lock(); try { - // getCGLConfigInfo() creates and destroys temporary + // getMTLConfigInfo() creates and destroys temporary // surfaces/contexts, so we should first invalidate the current // Java-level context and flush the queue... MTLContext.invalidateCurrentContext(); diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java index 7cfd77b2208..ba38f391350 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java @@ -83,7 +83,7 @@ public SurfaceData replaceSurfaceData() { } // the layer redirects all painting to the buffer's graphics - // and blits the buffer to the layer surface (in drawInCGLContext callback) + // and blits the buffer to the layer surface (in display callback) MTLGraphicsConfig gc = (MTLGraphicsConfig)getGraphicsConfiguration(); surfaceData = gc.createSurfaceData(this); setScale(gc.getDevice().getScaleFactor()); diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskBlit.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskBlit.java index cf3945346bb..ca41ed71469 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskBlit.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskBlit.java @@ -64,8 +64,8 @@ private MTLMaskBlit(SurfaceType srcType, protected void validateContext(SurfaceData dstData, Composite comp, Region clip) { - MTLSurfaceData oglDst = (MTLSurfaceData)dstData; - MTLContext.validateContext(oglDst, oglDst, + MTLSurfaceData mtlDst = (MTLSurfaceData)dstData; + MTLContext.validateContext(mtlDst, mtlDst, clip, comp, null, null, null, MTLContext.NO_CONTEXT_FLAGS); } diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLPaints.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLPaints.java index 5e22758671e..08ddb8d9072 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLPaints.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLPaints.java @@ -97,9 +97,8 @@ private Texture() {} * Returns true if the given TexturePaint instance can be used by the * accelerated MTLPaints.Texture implementation. A TexturePaint is * considered valid if the following conditions are met: - * - the texture image dimensions are power-of-two (or the - * GL_ARB_texture_non_power_of_two extension is present) - * - the texture image can be (or is already) cached in an OpenGL + * - the texture image dimensions are power-of-two + * - the texture image can be (or is already) cached in an Metal * texture object */ @Override @@ -115,7 +114,7 @@ boolean isPaintValid(SunGraphics2D sg2d) { if (!(srcData instanceof MTLSurfaceData)) { // REMIND: this is a hack that attempts to cache the system // memory image from the TexturePaint instance into an - // OpenGL texture... + // Metal texture... srcData = dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT, @@ -126,8 +125,8 @@ boolean isPaintValid(SunGraphics2D sg2d) { } // verify that the source surface is actually a texture - MTLSurfaceData oglData = (MTLSurfaceData)srcData; - if (oglData.getType() != MTLSurfaceData.TEXTURE) { + MTLSurfaceData mtlData = (MTLSurfaceData)srcData; + if (mtlData.getType() != MTLSurfaceData.TEXTURE) { return false; } diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java index b902c33ac34..bdfe96cc6dc 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java @@ -36,7 +36,7 @@ import static sun.java2d.pipe.BufferedOpCodes.SYNC; /** - * OGL-specific implementation of RenderQueue. This class provides a + * MTL-specific implementation of RenderQueue. This class provides a * single (daemon) thread that is responsible for periodically flushing * the queue, thus ensuring that only one thread communicates with the native * OpenGL libraries for the entire process. @@ -70,10 +70,10 @@ public static synchronized MTLRenderQueue getInstance() { * Flushes the single MTLRenderQueue instance synchronously. If an * MTLRenderQueue has not yet been instantiated, this method is a no-op. * This method is useful in the case of Toolkit.sync(), in which we want - * to flush the OGL pipeline, but only if the OGL pipeline is currently + * to flush the MTL pipeline, but only if the MTL pipeline is currently * enabled. Since this class has few external dependencies, callers need * not be concerned that calling this method will trigger initialization - * of the OGL pipeline and related classes. + * of the MTL pipeline and related classes. */ public static void sync() { if (theInstance != null) { @@ -113,7 +113,7 @@ public static void disposeGraphicsConfig(long pConfigInfo) { } /** - * Returns true if the current thread is the OGL QueueFlusher thread. + * Returns true if the current thread is the MTL QueueFlusher thread. */ public static boolean isQueueFlusherThread() { return (Thread.currentThread() == getInstance().flusher.thread); diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceData.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceData.java index 996b9153a74..f1f0a3205ec 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceData.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceData.java @@ -157,11 +157,11 @@ public abstract class MTLSurfaceData extends SurfaceData private int nativeHeight; /** - * Returns the appropriate SurfaceType corresponding to the given OpenGL + * Returns the appropriate SurfaceType corresponding to the given Metal * surface type constant (e.g. TEXTURE -> MTLTexture). */ - private static SurfaceType getCustomSurfaceType(int oglType) { - switch (oglType) { + private static SurfaceType getCustomSurfaceType(int mtlType) { + switch (mtlType) { case TEXTURE: return MTLTexture; case RT_TEXTURE: @@ -296,7 +296,7 @@ private void initSurfaceNow(int width, int height) { } /** - * Initializes the appropriate OpenGL offscreen surface based on the value + * Initializes the appropriate Metal offscreen surface based on the value * of the type parameter. If the surface creation fails for any reason, * an OutOfMemoryError will be thrown. */ @@ -353,7 +353,7 @@ public final int getType() { * - blending is SrcOverNoEa or disabled * - and the destination is opaque * - * Eventually, we could enhance the native OGL text rendering code + * Eventually, we could enhance the native MTL text rendering code * and remove the above restrictions, but that would require significantly * more code just to support a few uncommon cases. */ @@ -476,7 +476,7 @@ public void validatePipe(SunGraphics2D sg2d) { // install the text pipe based on our earlier decision sg2d.textpipe = textpipe; - // always override the image pipe with the specialized OGL pipe + // always override the image pipe with the specialized MTL pipe sg2d.imagepipe = mtlImagePipe; } diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java index 4d50bb8808c..4aae72697bf 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java @@ -33,7 +33,7 @@ /** * The proxy class contains the logic for when to replace a - * SurfaceData with a cached OGL Texture and the code to create + * SurfaceData with a cached MTL Texture and the code to create * the accelerated surfaces. */ public class MTLSurfaceDataProxy extends SurfaceDataProxy { diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLTextRenderer.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLTextRenderer.java index 12a6ca76583..9acab6f450b 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLTextRenderer.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLTextRenderer.java @@ -49,8 +49,8 @@ protected native void drawGlyphList(int numGlyphs, boolean usePositions, @Override protected void validateContext(SunGraphics2D sg2d, Composite comp) { // assert rq.lock.isHeldByCurrentThread(); - MTLSurfaceData oglDst = (MTLSurfaceData)sg2d.surfaceData; - MTLContext.validateContext(oglDst, oglDst, + MTLSurfaceData mtlDst = (MTLSurfaceData)sg2d.surfaceData; + MTLContext.validateContext(mtlDst, mtlDst, sg2d.getCompClip(), comp, null, sg2d.paint, sg2d, MTLContext.NO_CONTEXT_FLAGS); diff --git a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLUtilities.java b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLUtilities.java index 8d6262e7883..dbdce516dd9 100644 --- a/src/java.desktop/macosx/classes/sun/java2d/metal/MTLUtilities.java +++ b/src/java.desktop/macosx/classes/sun/java2d/metal/MTLUtilities.java @@ -40,7 +40,7 @@ class MTLUtilities { /** - * These OGL-specific surface type constants are the same as those + * These MTL-specific surface type constants are the same as those * defined in the MTLSurfaceData class and are duplicated here so that * clients of this API can access them more easily via reflection. */ @@ -54,7 +54,7 @@ private MTLUtilities() { } /** - * Returns true if the current thread is the OGL QueueFlusher thread. + * Returns true if the current thread is the MTL QueueFlusher thread. */ public static boolean isQueueFlusherThread() { return MTLRenderQueue.isQueueFlusherThread(); @@ -117,7 +117,7 @@ public static boolean invokeWithMTLContextCurrent(Graphics g, Runnable r) { * used when the Runnable needs a current context to complete its * operation, but does not require that the context be made current to * a particular surface. For example, an application may call this - * method so that the given Runnable can query the OpenGL capabilities + * method so that the given Runnable can query the Metal capabilities * of the given GraphicsConfiguration, without making a context current * to a dummy surface (or similar hacky techniques). * @@ -199,7 +199,7 @@ public static Rectangle getMTLViewport(Graphics g, // this is the lower-left origin of the region to be painted, // relative to the lower-left origin of the surface - // (in OpenGL coordinates) + // (in Metal coordinates) Rectangle surfaceBounds = sData.getBounds(); int x1 = x0; int y1 = surfaceBounds.height - (y0 + componentHeight); @@ -249,7 +249,7 @@ public static Rectangle getOGLScissorBox(Graphics g) { int h = r.getHeight(); // this is the lower-left origin of the scissor box relative to the - // lower-left origin of the surface (in OpenGL coordinates) + // lower-left origin of the surface (in Metal coordinates) Rectangle surfaceBounds = sData.getBounds(); int x1 = x0; int y1 = surfaceBounds.height - (y0 + h); diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index e33d752b23c..20e5b8e915e 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -502,7 +502,7 @@ public Insets getScreenInsets(final GraphicsConfiguration gc) { @Override public void sync() { - // flush the OGL pipeline (this is a no-op if OGL is not enabled) + // flush the OGL/MTL pipeline (this is a no-op if OGL/MTL is not enabled) if (MacOSFlags.isMetalEnabled()) { MTLRenderQueue.sync(); } else { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h index 8d1c6c85a6d..c9059b0ea2c 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h @@ -126,22 +126,13 @@ - (void)endShapeClip:(BMTLSDOps *)dstOps; /** - * Initializes the OpenGL state responsible for applying extra alpha. This - * step is only necessary for any operation that uses glDrawPixels() or - * glCopyPixels() with a non-1.0f extra alpha value. Since the source is - * always premultiplied, we apply the extra alpha value to both alpha and - * color components using GL_*_SCALE. - */ -- (void)setExtraAlpha:(jfloat)ea; - -/** - * Resets all OpenGL compositing state (disables blending and logic + * Resets all Metal compositing state (disables blending and logic * operations). */ - (void)resetComposite; /** - * Initializes the OpenGL blending state. XOR mode is disabled and the + * Initializes the Metal blending state. XOR mode is disabled and the * appropriate blend functions are setup based on the AlphaComposite rule * constant. */ @@ -159,7 +150,7 @@ - (NSString*)getPaintDescription; /** - * Initializes the OpenGL logic op state to XOR mode. Blending is disabled + * Initializes the Metal logic op state to XOR mode. Blending is disabled * before enabling logic op mode. The XOR pixel value will be applied * later in the MTLContext_SetColor() method. */ @@ -167,12 +158,12 @@ - (jboolean)useXORComposite; /** - * Resets the OpenGL transform state back to the identity matrix. + * Resets the Metal transform state back to the identity matrix. */ - (void)resetTransform; /** - * Initializes the OpenGL transform state by setting the modelview transform + * Initializes the Metal transform state by setting the modelview transform * using the given matrix parameters. * * REMIND: it may be worthwhile to add serial id to AffineTransform, so we @@ -183,29 +174,6 @@ M01:(jdouble) m01 M11:(jdouble) m11 M02:(jdouble) m02 M12:(jdouble) m12; -/** - * Initializes a small texture tile for use with tiled blit operations (see - * MTLBlitLoops.c and MTLMaskBlit.c for usage examples). The texture ID for - * the tile is stored in the given MTLContext. The tile is initially filled - * with garbage values, but the tile is updated as needed (via - * glTexSubImage2D()) with real RGBA values used in tiled blit situations. - * The internal format for the texture is GL_RGBA8, which should be sufficient - * for storing system memory surfaces of any known format (see PixelFormats - * for a list of compatible surface formats). - */ -- (jboolean)initBlitTileTexture; - - -/** - * Creates a 2D texture of the given format and dimensions and returns the - * texture object identifier. This method is typically used to create a - * temporary texture for intermediate work, such as in the - * MTLContext_InitBlitTileTexture() method below. - */ -- (jint)createBlitTextureFormat:(jint)internalFormat pixelFormat:(jint)pixelFormat - width:(jint)width height:(jint)height; - -- (void)destroyContextResources; - (void)resetPaint; - (void)setColorPaint:(int)pixel; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m index 94ea249ad0b..80db243723d 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m @@ -221,8 +221,8 @@ + (MTLContext*) setSurfacesEnv:(JNIEnv*)env src:(jlong)pSrc dst:(jlong)pDst { } // make the context current - MTLSDOps *dstCGLOps = (MTLSDOps *)dstOps->privOps; - mtlc = dstCGLOps->configInfo->context; + MTLSDOps *dstMTLOps = (MTLSDOps *)dstOps->privOps; + mtlc = dstMTLOps->configInfo->context; if (mtlc == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, @@ -314,21 +314,6 @@ - (void)setTransformM00:(jdouble) m00 M10:(jdouble) m10 [_transform setTransformM00:m00 M10:m10 M01:m01 M11:m11 M02:m02 M12:m12]; } -- (jboolean)initBlitTileTexture { - //TODO - J2dTraceLn(J2D_TRACE_INFO, "MTLContext_InitBlitTileTexture -- :TODO"); - - return JNI_TRUE; -} - -- (jint)createBlitTextureFormat:(jint)internalFormat pixelFormat:(jint)pixelFormat - width:(jint)width height:(jint)height { - J2dTraceLn(J2D_TRACE_INFO, "MTLContext_InitBlitTileTexture -- :TODO"); - - //TODO - return 0; -} - - (void)resetPaint { J2dTraceLn(J2D_TRACE_INFO, "MTLContext.resetPaint"); self.paint = [[[MTLPaint alloc] init] autorelease]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.h index 77b585c15c8..79695e09378 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.h @@ -37,43 +37,18 @@ + (void) _getMTLConfigInfo: (NSMutableArray *)argValue; @end -// REMIND: Using an NSOpenGLPixelBuffer as the scratch surface has been -// problematic thus far (seeing garbage and flickering when switching -// between an NSView and the scratch surface), so the following enables -// an alternate codepath that uses a hidden NSWindow/NSView as the scratch -// surface, for the purposes of making a context current in certain -// situations. It appears that calling [NSOpenGLContext setView] too -// frequently contributes to the bad behavior, so we should try to avoid -// switching to the scratch surface whenever possible. - -/* Do we need this if we are using all off-screen drawing ? */ -#define USE_NSVIEW_FOR_SCRATCH 1 - -/* Uncomment to have an additional CAOGLLayer instance tied to - * each instance, which can be used to test remoting the layer - * to an out of process window. The additional layer is needed - * because a layer can only be attached to one context (view/window). - * This is only for testing purposes and can be removed if/when no - * longer needed. - */ - - /** * The MTLGraphicsConfigInfo structure contains information specific to a - * given CGLGraphicsConfig (pixel format). + * given MTLGraphicsConfig (pixel format). * * jint screen; - * The screen and PixelFormat for the associated CGLGraphicsConfig. - * - * NSOpenGLPixelFormat *pixfmt; - * The pixel format of the native NSOpenGL context. + * The screen for the associated MTLGraphicsConfig. * * MTLContext *context; - * The context associated with this CGLGraphicsConfig. + * The context associated with this MTLGraphicsConfig. */ typedef struct _MTLGraphicsConfigInfo { jint screen; - NSOpenGLPixelFormat *pixfmt; MTLContext *context; } MTLGraphicsConfigInfo; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m index 2450d76798c..504cd858782 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m @@ -43,7 +43,7 @@ /** * Disposes all memory and resources associated with the given - * CGLGraphicsConfigInfo (including its native MTLContext data). + * MTLGraphicsConfigInfo (including its native MTLContext data). */ void MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo) @@ -71,7 +71,7 @@ /** - * Attempts to initialize CGL and the core OpenGL library. + * Attempts to initialize MTL and the core Metal library. */ JNIEXPORT jboolean JNICALL Java_sun_java2d_metal_MTLGraphicsConfig_initMTL @@ -121,12 +121,12 @@ /** - * Determines whether the CGL pipeline can be used for a given GraphicsConfig + * Determines whether the MTL pipeline can be used for a given GraphicsConfig * provided its screen number and visual ID. If the minimum requirements are - * met, the native CGLGraphicsConfigInfo structure is initialized for this + * met, the native MTLGraphicsConfigInfo structure is initialized for this * GraphicsConfig with the necessary information (pixel format, etc.) * and a pointer to this structure is returned as a jlong. If - * initialization fails at any point, zero is returned, indicating that CGL + * initialization fails at any point, zero is returned, indicating that MTL * cannot be used for this GraphicsConfig (we should fallback on an existing * 2D pipeline). */ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h index 955c2a629ef..885fe44c98a 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h @@ -74,4 +74,4 @@ - (void) stopDisplayLink; @end -#endif /* CGLLayer_h_Included */ +#endif /* MTLLayer_h_Included */ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m index 78e2d45420f..dcda23bff67 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m @@ -32,49 +32,9 @@ #include "MTLVertexCache.h" /** - * This implementation first copies the alpha tile into a texture and then - * maps that texture to the destination surface. This approach appears to - * offer the best performance despite being a two-step process. + * In case of Metal we use shader for texture mapping. * - * When the source paint is a Color, we can simply use the GL_MODULATE - * function to multiply the current color (already premultiplied with the - * extra alpha value from the AlphaComposite) with the alpha value from - * the mask texture tile. In picture form, this process looks like: - * - * A R G B - * primary color Pa Pr Pg Pb (modulated with...) - * texture unit 0 Ca Ca Ca Ca - * --------------------------------------- - * resulting color Ra Rr Rg Rb - * - * where: - * Px = current color (already premultiplied by extra alpha) - * Cx = coverage value from mask tile - * Rx = resulting color/alpha component - * - * When the source paint is not a Color, it means that we are rendering with - * a complex paint (e.g. GradientPaint, TexturePaint). In this case, we - * rely on the GL_ARB_multitexture extension to effectively multiply the - * paint fragments (autogenerated on texture unit 1, see the - * MTLPaints_Set{Gradient,Texture,etc}Paint() methods for more details) - * with the coverage values from the mask texture tile (provided on texture - * unit 0), all of which is multiplied with the current color value (which - * contains the extra alpha value). In picture form: - * - * A R G B - * primary color Ea Ea Ea Ea (modulated with...) - * texture unit 0 Ca Ca Ca Ca (modulated with...) - * texture unit 1 Pa Pr Pg Pb - * --------------------------------------- - * resulting color Ra Rr Rg Rb - * - * where: - * Ea = extra alpha - * Cx = coverage value from mask tile - * Px = gradient/texture paint color (generated for each fragment) - * Rx = resulting color/alpha component - * - * Here are some descriptions of the many variables used in this method: + * Descriptions of the many variables used in this method: * x,y - upper left corner of the tile destination * w,h - width/height of the mask tile * x0 - placekeeper for the original destination x location diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m index c063efc0431..d94887a6f99 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m @@ -991,371 +991,4 @@ - (void)setXorModePipelineState:(id )encoder } @end - - -/************************* GradientPaint support ****************************/ - -static void -MTLPaints_InitGradientTexture() -{ - //TODO - J2dTraceLn(J2D_TRACE_INFO, "MTLPaints_InitGradientTexture -- :TODO"); -} - -/****************** Shared MultipleGradientPaint support ********************/ - -/** - * These constants are identical to those defined in the - * MultipleGradientPaint.CycleMethod enum; they are copied here for - * convenience (ideally we would pull them directly from the Java level, - * but that entails more hassle than it is worth). - */ -#define CYCLE_NONE 0 -#define CYCLE_REFLECT 1 -#define CYCLE_REPEAT 2 - -/** - * The following constants are flags that can be bitwise-or'ed together - * to control how the MultipleGradientPaint shader source code is generated: - * - * MULTI_CYCLE_METHOD - * Placeholder for the CycleMethod enum constant. - * - * MULTI_LARGE - * If set, use the (slower) shader that supports a larger number of - * gradient colors; otherwise, use the optimized codepath. See - * the MAX_FRACTIONS_SMALL/LARGE constants below for more details. - * - * MULTI_USE_MASK - * If set, apply the alpha mask value from texture unit 0 to the - * final color result (only used in the MaskFill case). - * - * MULTI_LINEAR_RGB - * If set, convert the linear RGB result back into the sRGB color space. - */ -#define MULTI_CYCLE_METHOD (3 << 0) -#define MULTI_LARGE (1 << 2) -#define MULTI_USE_MASK (1 << 3) -#define MULTI_LINEAR_RGB (1 << 4) - -/** - * This value determines the size of the array of programs for each - * MultipleGradientPaint type. This value reflects the maximum value that - * can be represented by performing a bitwise-or of all the MULTI_* - * constants defined above. - */ -#define MAX_PROGRAMS 32 - -/** Evaluates to true if the given bit is set on the local flags variable. */ -#define IS_SET(flagbit) \ - (((flags) & (flagbit)) != 0) - -/** Composes the given parameters as flags into the given flags variable.*/ -#define COMPOSE_FLAGS(flags, cycleMethod, large, useMask, linear) \ - do { \ - flags |= ((cycleMethod) & MULTI_CYCLE_METHOD); \ - if (large) flags |= MULTI_LARGE; \ - if (useMask) flags |= MULTI_USE_MASK; \ - if (linear) flags |= MULTI_LINEAR_RGB; \ - } while (0) - -/** Extracts the CycleMethod enum value from the given flags variable. */ -#define EXTRACT_CYCLE_METHOD(flags) \ - ((flags) & MULTI_CYCLE_METHOD) - -/** - * The maximum number of gradient "stops" supported by the fragment shader - * and related code. When the MULTI_LARGE flag is set, we will use - * MAX_FRACTIONS_LARGE; otherwise, we use MAX_FRACTIONS_SMALL. By having - * two separate values, we can have one highly optimized shader (SMALL) that - * supports only a few fractions/colors, and then another, less optimal - * shader that supports more stops. - */ -#define MAX_FRACTIONS sun_java2d_pipe_BufferedPaints_MULTI_MAX_FRACTIONS -#define MAX_FRACTIONS_LARGE MAX_FRACTIONS -#define MAX_FRACTIONS_SMALL 4 - -/** - * The maximum number of gradient colors supported by all of the gradient - * fragment shaders. Note that this value must be a power of two, as it - * determines the size of the 1D texture created below. It also must be - * greater than or equal to MAX_FRACTIONS (there is no strict requirement - * that the two values be equal). - */ -#define MAX_COLORS 16 - -/** - * The handle to the gradient color table texture object used by the shaders. - */ -static jint multiGradientTexID = 0; - -/** - * This is essentially a template of the shader source code that can be used - * for either LinearGradientPaint or RadialGradientPaint. It includes the - * structure and some variables that are common to each; the remaining - * code snippets (for CycleMethod, ColorSpaceType, and mask modulation) - * are filled in prior to compiling the shader at runtime depending on the - * paint parameters. See MTLPaints_CreateMultiGradProgram() for more details. - */ -static const char *multiGradientShaderSource = - // gradient texture size (in texels) - "const int TEXTURE_SIZE = %d;" - // maximum number of fractions/colors supported by this shader - "const int MAX_FRACTIONS = %d;" - // size of a single texel - "const float FULL_TEXEL = (1.0 / float(TEXTURE_SIZE));" - // size of half of a single texel - "const float HALF_TEXEL = (FULL_TEXEL / 2.0);" - // texture containing the gradient colors - "uniform sampler1D colors;" - // array of gradient stops/fractions - "uniform float fractions[MAX_FRACTIONS];" - // array of scale factors (one for each interval) - "uniform float scaleFactors[MAX_FRACTIONS-1];" - // (placeholder for mask variable) - "%s" - // (placeholder for Linear/RadialGP-specific variables) - "%s" - "" - "void main(void)" - "{" - " float dist;" - // (placeholder for Linear/RadialGradientPaint-specific code) - " %s" - "" - " float tc;" - // (placeholder for CycleMethod-specific code) - " %s" - "" - // calculate interpolated color - " vec4 result = texture1D(colors, tc);" - "" - // (placeholder for ColorSpace conversion code) - " %s" - "" - // (placeholder for mask modulation code) - " %s" - "" - // modulate with gl_Color in order to apply extra alpha - " gl_FragColor = result * gl_Color;" - "}"; - -/** - * This code takes a "dist" value as input (as calculated earlier by the - * LGP/RGP-specific code) in the range [0,1] and produces a texture - * coordinate value "tc" that represents the position of the chosen color - * in the one-dimensional gradient texture (also in the range [0,1]). - * - * One naive way to implement this would be to iterate through the fractions - * to figure out in which interval "dist" falls, and then compute the - * relative distance between the two nearest stops. This approach would - * require an "if" check on every iteration, and it is best to avoid - * conditionals in fragment shaders for performance reasons. Also, one might - * be tempted to use a break statement to jump out of the loop once the - * interval was found, but break statements (and non-constant loop bounds) - * are not natively available on most graphics hardware today, so that is - * a non-starter. - * - * The more optimal approach used here avoids these issues entirely by using - * an accumulation function that is equivalent to the process described above. - * The scaleFactors array is pre-initialized at enable time as follows: - * scaleFactors[i] = 1.0 / (fractions[i+1] - fractions[i]); - * - * For each iteration, we subtract fractions[i] from dist and then multiply - * that value by scaleFactors[i]. If we are within the target interval, - * this value will be a fraction in the range [0,1] indicating the relative - * distance between fraction[i] and fraction[i+1]. If we are below the - * target interval, this value will be negative, so we clamp it to zero - * to avoid accumulating any value. If we are above the target interval, - * the value will be greater than one, so we clamp it to one. Upon exiting - * the loop, we will have accumulated zero or more 1.0's and a single - * fractional value. This accumulated value tells us the position of the - * fragment color in the one-dimensional gradient texture, i.e., the - * texcoord called "tc". - */ -static const char *texCoordCalcCode = - "int i;" - "float relFraction = 0.0;" - "for (i = 0; i < MAX_FRACTIONS-1; i++) {" - " relFraction +=" - " clamp((dist - fractions[i]) * scaleFactors[i], 0.0, 1.0);" - "}" - // we offset by half a texel so that we find the linearly interpolated - // color between the two texel centers of interest - "tc = HALF_TEXEL + (FULL_TEXEL * relFraction);"; - -/** Code for NO_CYCLE that gets plugged into the CycleMethod placeholder. */ -static const char *noCycleCode = - "if (dist <= 0.0) {" - " tc = 0.0;" - "} else if (dist >= 1.0) {" - " tc = 1.0;" - "} else {" - // (placeholder for texcoord calculation) - " %s" - "}"; - -/** Code for REFLECT that gets plugged into the CycleMethod placeholder. */ -static const char *reflectCode = - "dist = 1.0 - (abs(fract(dist * 0.5) - 0.5) * 2.0);" - // (placeholder for texcoord calculation) - "%s"; - -/** Code for REPEAT that gets plugged into the CycleMethod placeholder. */ -static const char *repeatCode = - "dist = fract(dist);" - // (placeholder for texcoord calculation) - "%s"; - -static void -MTLPaints_InitMultiGradientTexture() -{ - J2dTraceLn(J2D_TRACE_INFO, "MTLPaints_InitMultiGradientTexture -- :TODO"); -} - -/** - * Compiles and links the MultipleGradientPaint shader program. If - * successful, this function returns a handle to the newly created - * shader program; otherwise returns 0. - */ -static void* -MTLPaints_CreateMultiGradProgram(jint flags, - char *paintVars, char *distCode) -{ - - //TODO - J2dTraceLn(J2D_TRACE_INFO, "MTLPaints_CreateMultiGradProgram -- :TODO"); - - return NULL; -} - -/** - * Called from the MTLPaints_SetLinear/RadialGradientPaint() methods - * in order to setup the fraction/color values that are common to both. - */ -static void -MTLPaints_SetMultiGradientPaint(void* multiGradProgram, - jint numStops, - void *pFractions, void *pPixels) -{ - //TODO - J2dTraceLn(J2D_TRACE_INFO, "MTLPaints_SetMultiGradientPaint -- :TODO"); - -} - -/********************** LinearGradientPaint support *************************/ - -/** - * The handles to the LinearGradientPaint fragment program objects. The - * index to the array should be a bitwise-or'ing of the MULTI_* flags defined - * above. Note that most applications will likely need to initialize one - * or two of these elements, so the array is usually sparsely populated. - */ -static void* linearGradPrograms[MAX_PROGRAMS]; - -/** - * Compiles and links the LinearGradientPaint shader program. If successful, - * this function returns a handle to the newly created shader program; - * otherwise returns 0. - */ -static void* -MTLPaints_CreateLinearGradProgram(jint flags) -{ - char *paintVars; - char *distCode; - - J2dTraceLn1(J2D_TRACE_INFO, - "MTLPaints_CreateLinearGradProgram", - flags); - - /* - * To simplify the code and to make it easier to upload a number of - * uniform values at once, we pack a bunch of scalar (float) values - * into vec3 values below. Here's how the values are related: - * - * params.x = p0 - * params.y = p1 - * params.z = p3 - * - * yoff = dstOps->yOffset + dstOps->height - */ - paintVars = - "uniform vec3 params;" - "uniform float yoff;"; - distCode = - // note that gl_FragCoord is in window space relative to the - // lower-left corner, so we have to flip the y-coordinate here - "vec3 fragCoord = vec3(gl_FragCoord.x, yoff-gl_FragCoord.y, 1.0);" - "dist = dot(params, fragCoord);"; - - return MTLPaints_CreateMultiGradProgram(flags, paintVars, distCode); -} - -/********************** RadialGradientPaint support *************************/ - -/** - * The handles to the RadialGradientPaint fragment program objects. The - * index to the array should be a bitwise-or'ing of the MULTI_* flags defined - * above. Note that most applications will likely need to initialize one - * or two of these elements, so the array is usually sparsely populated. - */ -static void* radialGradPrograms[MAX_PROGRAMS]; - -/** - * Compiles and links the RadialGradientPaint shader program. If successful, - * this function returns a handle to the newly created shader program; - * otherwise returns 0. - */ -static void* -MTLPaints_CreateRadialGradProgram(jint flags) -{ - char *paintVars; - char *distCode; - - J2dTraceLn1(J2D_TRACE_INFO, - "MTLPaints_CreateRadialGradProgram", - flags); - - /* - * To simplify the code and to make it easier to upload a number of - * uniform values at once, we pack a bunch of scalar (float) values - * into vec3 and vec4 values below. Here's how the values are related: - * - * m0.x = m00 - * m0.y = m01 - * m0.z = m02 - * - * m1.x = m10 - * m1.y = m11 - * m1.z = m12 - * - * precalc.x = focusX - * precalc.y = yoff = dstOps->yOffset + dstOps->height - * precalc.z = 1.0 - (focusX * focusX) - * precalc.w = 1.0 / precalc.z - */ - paintVars = - "uniform vec3 m0;" - "uniform vec3 m1;" - "uniform vec4 precalc;"; - - /* - * The following code is derived from Daniel Rice's whitepaper on - * radial gradient performance (attached to the bug report for 6521533). - * Refer to that document as well as the setup code in the Java-level - * BufferedPaints.setRadialGradientPaint() method for more details. - */ - distCode = - // note that gl_FragCoord is in window space relative to the - // lower-left corner, so we have to flip the y-coordinate here - "vec3 fragCoord =" - " vec3(gl_FragCoord.x, precalc.y - gl_FragCoord.y, 1.0);" - "float x = dot(fragCoord, m0);" - "float y = dot(fragCoord, m1);" - "float xfx = x - precalc.x;" - "dist = (precalc.x*xfx + sqrt(xfx*xfx + y*y*precalc.z))*precalc.w;"; - - return MTLPaints_CreateMultiGradProgram(flags, paintVars, distCode); -} - #endif /* !HEADLESS */ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m index 3545b99afda..487cafbc58f 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m @@ -39,15 +39,10 @@ /** * Note: Some of the methods in this file apply a "magic number" - * translation to line segments. The OpenGL specification lays out the - * "diamond exit rule" for line rasterization, but it is loose enough to - * allow for a wide range of line rendering hardware. (It appears that - * some hardware, such as the Nvidia GeForce2 series, does not even meet - * the spec in all cases.) As such it is difficult to find a mapping - * between the Java2D and OpenGL line specs that works consistently across - * all hardware combinations. + * translation to line segments. It is same as what we have in + * OGLrenderer. * - * Therefore the "magic numbers" you see here have been empirically derived + * The "magic numbers" you see here have been empirically derived * after testing on a variety of graphics hardware in order to find some * reasonable middle ground between the two specifications. The general * approach is to apply a fractional translation to vertices so that they diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.h index f05bf64fc8a..ab2ca28ea15 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.h @@ -32,7 +32,7 @@ #import "MTLLayer.h" /** - * The CGLSDOps structure contains the CGL-specific information for a given + * The MTLSDOps structure contains the MTL-specific information for a given * MTLSurfaceData. It is referenced by the native MTLSDOps structure. */ typedef struct _MTLSDOps { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m index bfb7fc5f013..d63f4d2f628 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m @@ -109,7 +109,6 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque bmtlsdo->height = height; bmtlsdo->textureWidth = width; bmtlsdo->textureHeight = height; - bmtlsdo->textureTarget = -1; bmtlsdo->drawableType = rtt ? MTLSD_RT_TEXTURE : MTLSD_TEXTURE; J2dTraceLn6(J2D_TRACE_VERBOSE, "MTLSurfaceData_initTexture: w=%d h=%d bp=%p [tex=%p] opaque=%d rtt=%d", width, height, bmtlsdo, bmtlsdo->pTexture, isOpaque, rtt); @@ -199,7 +198,7 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque } /** - * Deletes native OpenGL resources associated with this surface. + * Deletes native Metal resources associated with this surface. */ void MTLSD_Delete(JNIEnv *env, BMTLSDOps *bmtlsdo) @@ -226,7 +225,7 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque /** * This is the implementation of the general DisposeFunc defined in * SurfaceData.h and used by the Disposer mechanism. It first flushes all - * native OpenGL resources and then frees any memory allocated within the + * native Metal resources and then frees any memory allocated within the * native MTLSDOps structure. */ void @@ -338,11 +337,11 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque void MTLSD_SwapBuffers(JNIEnv *env, jlong pPeerData) { - J2dTraceLn(J2D_TRACE_ERROR, "OGLSD_SwapBuffers -- :TODO"); + J2dTraceLn(J2D_TRACE_ERROR, "MTLSD_SwapBuffers -- :TODO"); } #pragma mark - -#pragma mark "--- CGLSurfaceData methods ---" +#pragma mark "--- MTLSurfaceData methods ---" extern LockFunc MTLSD_Lock; extern GetRasInfoFunc MTLSD_GetRasInfo; @@ -404,13 +403,13 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque Java_sun_java2d_metal_MTLSurfaceData_clearWindow (JNIEnv *env, jobject cglsd) { - J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_clearWindow"); + J2dTraceLn(J2D_TRACE_INFO, "MTLSurfaceData_clearWindow"); - BMTLSDOps *mtlsdo = (MTLSDOps*) SurfaceData_GetOps(env, cglsd); - MTLSDOps *cglsdo = (MTLSDOps*) mtlsdo->privOps; + BMTLSDOps *bmtlsdo = (MTLSDOps*) SurfaceData_GetOps(env, cglsd); + MTLSDOps *mtlsdo = (MTLSDOps*) bmtlsdo->privOps; - cglsdo->peerData = NULL; - cglsdo->layer = NULL; + mtlsdo->peerData = NULL; + mtlsdo->layer = NULL; } NSString * getSurfaceDescription(const BMTLSDOps * bmtlsdOps) { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceDataBase.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceDataBase.h index feb99a11778..c2b0fd23ff1 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceDataBase.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceDataBase.h @@ -34,48 +34,6 @@ #include "Trace.h" #include "MTLFuncs.h" - -/** - * The MTLPixelFormat structure contains all the information OpenGL needs to - * know when copying from or into a particular system memory image buffer (via - * glDrawPixels(), glReadPixels, glTexSubImage2D(), etc). - * - * GLenum format; - * The pixel format parameter used in glDrawPixels() and other similar calls. - * Indicates the component ordering for each pixel (e.g. GL_BGRA). - * - * GLenum type; - * The pixel data type parameter used in glDrawPixels() and other similar - * calls. Indicates the data type for an entire pixel or for each component - * in a pixel (e.g. GL_UNSIGNED_BYTE with GL_BGR means a pixel consists of - * 3 unsigned byte components, blue first, then green, then red; - * GL_UNSIGNED_INT_8_8_8_8_REV with GL_BGRA means a pixel consists of 1 - * unsigned integer comprised of four byte components, alpha first, then red, - * then green, then blue). - * - * jint alignment; - * The byte alignment parameter used in glPixelStorei(GL_UNPACK_ALIGNMENT). A - * value of 4 indicates that each pixel starts on a 4-byte aligned region in - * memory, and so on. This alignment parameter helps OpenGL speed up pixel - * transfer operations by transferring memory in aligned blocks. - * - * jboolean hasAlpha; - * If true, indicates that this pixel format contains an alpha component. - * - * jboolean isPremult; - * If true, indicates that this pixel format contains color components that - * have been pre-multiplied by their corresponding alpha component. - */ -typedef struct { - //GLenum format; - //GLenum type; - jint format; - jint type; - jint alignment; - jboolean hasAlpha; - jboolean isPremult; -} MTPixelFormat; - /** * The MTLSDOps structure describes a native OpenGL surface and contains all * information pertaining to the native surface. Some information about @@ -89,11 +47,6 @@ typedef struct { * The surface type; can be any one of the surface type constants defined * below (MTLSD_WINDOW, MTLSD_TEXTURE, etc). * - * GLenum activeBuffer; - * Can be either GL_FRONT if this is the front buffer surface of an onscreen - * window or a pbuffer surface, or GL_BACK if this is the backbuffer surface - * of an onscreen window. - * * jboolean isOpaque; * If true, the surface should be treated as being fully opaque. If * the underlying surface (e.g. pbuffer) has an alpha channel and isOpaque @@ -107,13 +60,13 @@ typedef struct { * the first time. * * jint x/yOffset - * The offset in pixels of the OpenGL viewport origin from the lower-left + * The offset in pixels of the Metal viewport origin from the lower-left * corner of the heavyweight drawable. For example, a top-level frame on - * Windows XP has lower-left insets of (4,4). The OpenGL viewport origin + * Windows XP has lower-left insets of (4,4). The Metal viewport origin * would typically begin at the lower-left corner of the client region (inside * the frame decorations), but AWT/Swing will take the insets into account * when rendering into that window. So in order to account for this, we - * need to adjust the OpenGL viewport origin by an x/yOffset of (-4,-4). On + * need to adjust the Metal viewport origin by an x/yOffset of (-4,-4). On * X11, top-level frames typically don't have this insets issue, so their * x/yOffset would be (0,0) (the same applies to pbuffers). * @@ -126,9 +79,9 @@ typedef struct { * current bounds of this surface, query the native Drawable through the * privOps field. * - * GLuint textureID; - * The texture object handle, as generated by glGenTextures(). If this value - * is zero, the texture has not yet been initialized. + * void* pTexture; + * The texture object handle, as generated by MTLTextureDescriptor(). If this + * value is null, the texture has not yet been initialized. * * jint textureWidth/Height; * The actual bounds of the texture object for this surface. If the @@ -140,24 +93,6 @@ typedef struct { * texture we allocate will have dimensions 128x64 to meet the pow2 * restriction. The image bounds within the texture can be accessed using * floating point texture coordinates in the range [0.0,1.0]. - * - * GLenum textureTarget; - * The texture target of the texture object for this surface. If this - * surface is not backed by a texture, this value is set to zero. Otherwise, - * this value is GL_TEXTURE_RECTANGLE_ARB when the GL_ARB_texture_rectangle - * extension is in use; if not, it is set to GL_TEXTURE_2D. - * - * GLint textureFilter; - * The current filter state for this texture object (can be either GL_NEAREST - * or GL_LINEAR). We cache this value here and check it before updating - * the filter state to avoid redundant calls to glTexParameteri() when the - * filter state remains constant (see the MTLSD_UPDATE_TEXTURE_FILTER() - * macro below). - * - * GLuint fbobjectID, depthID; - * The object handles for the framebuffer object and depth renderbuffer - * associated with this surface. These fields are only used when - * drawableType is MTLSD_FBOBJECT, otherwise they are zero. */ typedef struct { SurfaceDataOps sdOps; @@ -179,10 +114,6 @@ typedef struct { void* pAAStencilDataBuf; // MTLBuffer with AA stencil data jint textureWidth; jint textureHeight; - /* GLenum */ jint textureTarget; - /* GLint */ jint textureFilter; - /* GLuint */ jint fbobjectID; - /* GLuint */ jint depthID; } BMTLSDOps; #define MTLSD_UNDEFINED sun_java2d_pipe_hw_AccelSurface_UNDEFINED diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m index 5d91f0cc574..db9f847f475 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m @@ -125,13 +125,13 @@ * Initializes the one glyph cache (texture and data structure). * If lcdCache is JNI_TRUE, the texture will contain RGB data, * otherwise we will simply store the grayscale/monochrome glyph images - * as intensity values (which work well with the GL_MODULATE function). + * as intensity values. */ static jboolean MTLTR_InitGlyphCache(MTLContext *mtlc, jboolean lcdCache) { J2dTraceLn(J2D_TRACE_INFO, "MTLTR_InitGlyphCache"); - // TODO : Need to fix RGB order in case of LCD + // TODO : Need to verify RGB order in case of LCD MTLPixelFormat pixelFormat = lcdCache ? MTLPixelFormatBGRA8Unorm : MTLPixelFormatA8Unorm; @@ -420,7 +420,6 @@ { J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DisableGlyphVertexCache"); MTLVertexCache_FlushGlyphVertexCache(); - MTLVertexCache_RestoreColorState(mtlc); MTLVertexCache_FreeVertexCache(); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.h index 52fd6be30b5..35b3edd2576 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.h @@ -69,7 +69,6 @@ jboolean MTLVertexCache_InitVertexCache(); void MTLVertexCache_FlushVertexCache(MTLContext *mtlc); void MTLVertexCache_FlushGlyphVertexCache(); void MTLVertexCache_FreeVertexCache(); -void MTLVertexCache_RestoreColorState(MTLContext *mtlc); void MTLVertexCache_EnableMaskCache(MTLContext *mtlc, BMTLSDOps *dstOps); void MTLVertexCache_DisableMaskCache(MTLContext *mtlc); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m index a64ff1dd2b6..08b407d736b 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m @@ -130,52 +130,9 @@ void MTLVertexCache_FreeVertexCache() vertexCache = NULL; } -/** - * This method is somewhat hacky, but necessary for the foreseeable future. - * The problem is the way OpenGL handles color values in vertex arrays. When - * a vertex in a vertex array contains a color, and then the vertex array - * is rendered via glDrawArrays(), the global OpenGL color state is actually - * modified each time a vertex is rendered. This means that after all - * vertices have been flushed, the global OpenGL color state will be set to - * the color of the most recently rendered element in the vertex array. - * - * The reason this is a problem for us is that we do not want to flush the - * vertex array (in the case of mask/glyph operations) or issue a glEnd() - * (in the case of non-antialiased primitives) everytime the current color - * changes, which would defeat any benefit from batching in the first place. - * We handle this in practice by not calling CHECK/RESET_PREVIOUS_OP() when - * the simple color state is changing in MTLPaints_SetColor(). This is - * problematic for vertex caching because we may end up with the following - * situation, for example: - * SET_COLOR (orange) - * MASK_FILL - * MASK_FILL - * SET_COLOR (blue; remember, this won't cause a flush) - * FILL_RECT (this will cause the vertex array to be flushed) - * - * In this case, we would actually end up rendering an orange FILL_RECT, - * not a blue one as intended, because flushing the vertex cache flush would - * override the color state from the most recent SET_COLOR call. - * - * Long story short, the easiest way to resolve this problem is to call - * this method just after disabling the mask/glyph cache, which will ensure - * that the appropriate color state is restored. - */ -void -MTLVertexCache_RestoreColorState(MTLContext *mtlc) -{ -// TODO -// if (mtlc.paint.paintState == sun_java2d_SunGraphics2D_PAINT_ALPHACOLOR) { -// //mtlc.paint.color = mtlc.paint.pixel; -// } -} - static jboolean MTLVertexCache_InitMaskCache(MTLContext *mtlc) { J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_InitMaskCache"); - // TODO : We are creating mask cache only of type MTLPixelFormatA8Unorm - // when we need more than 1 byte to store a pixel(LCD) we need to update - // below code. if (maskCacheTex == NULL) { maskCacheTex = [mtlc.texturePool getTexture:MTLVC_MASK_CACHE_WIDTH_IN_TEXELS height:MTLVC_MASK_CACHE_HEIGHT_IN_TEXELS @@ -235,10 +192,9 @@ void MTLVertexCache_FreeVertexCache() { // TODO : Once we enable check_previous_op // we will start using DisableMaskCache until then - // we are force flusging vertexcache. + // we are force flushing vertexcache. J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_DisableMaskCache"); MTLVertexCache_FlushVertexCache(mtlc); - MTLVertexCache_RestoreColorState(mtlc); maskCacheIndex = 0; free(vertexCache); vertexCache = NULL; @@ -247,7 +203,6 @@ void MTLVertexCache_FreeVertexCache() void MTLVertexCache_CreateSamplingEncoder(MTLContext *mtlc, BMTLSDOps *dstOps) { J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_CreateSamplingEncoder"); - //encoder = [mtlc.encoderManager getTextureEncoder:dstOps isSrcOpaque:NO]; encoder = [mtlc.encoderManager getTextEncoder:dstOps isSrcOpaque:NO]; } @@ -270,10 +225,6 @@ void MTLVertexCache_FreeVertexCache() { J2dTraceLn2(J2D_TRACE_INFO, "maskCacheIndex = %d, vertexCacheIndex = %d", maskCacheIndex, vertexCacheIndex); MTLVertexCache_FlushVertexCache(mtlc); - // TODO : Since we are not committing command buffer - // in FlushVertexCache we need to create new maskcache - // after present cache is full. Check whether we can - // avoid multiple cache creation. MTLVertexCache_EnableMaskCache(mtlc, dstOps); maskCacheIndex = 0; }