Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h
41159 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef MTLContext_h_Included26#define MTLContext_h_Included2728#include "sun_java2d_pipe_BufferedContext.h"29#include "sun_java2d_metal_MTLContext_MTLContextCaps.h"3031#import <Metal/Metal.h>3233#include "MTLTexturePool.h"34#include "MTLPipelineStatesStorage.h"35#include "MTLTransform.h"36#include "MTLComposite.h"37#include "MTLPaints.h"38#include "MTLClip.h"39#include "EncoderManager.h"40#include "MTLSamplerManager.h"4142@class MTLStencilManager;4344// Constant from45// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf46#define MTL_GPU_FAMILY_MAC_TXT_SIZE 163844748/**49* The MTLCommandBufferWrapper class contains command buffer and50* associated resources that will be released in completion handler51* */52@interface MTLCommandBufferWrapper : NSObject53- (id<MTLCommandBuffer>) getCommandBuffer;54- (void) onComplete; // invoked from completion handler in some pooled thread55- (void) registerPooledTexture:(MTLPooledTextureHandle *)handle;56@end5758/**59* The MTLContext class contains cached state relevant to the native60* MTL context stored within the native ctxInfo field. Each Java-level61* MTLContext object is associated with a native-level MTLContext class.62* */63@interface MTLContext : NSObject64@property (readonly) MTLComposite * composite;65@property (readwrite, retain) MTLPaint * paint;66@property (readonly) MTLTransform * transform;67@property (readonly) MTLClip * clip;6869@property jint textureFunction;70@property jboolean vertexCacheEnabled;71@property jboolean aaEnabled;7273@property (readonly, strong) id<MTLDevice> device;74@property (strong) id<MTLCommandQueue> commandQueue;75@property (strong) id<MTLCommandQueue> blitCommandQueue;76@property (strong) id<MTLBuffer> vertexBuffer;7778@property (readonly) EncoderManager * encoderManager;79@property (readonly) MTLSamplerManager * samplerManager;80@property (readonly) MTLStencilManager * stencilManager;8182@property (strong)MTLPipelineStatesStorage* pipelineStateStorage;83@property (strong)MTLTexturePool* texturePool;8485- (MTLCommandBufferWrapper *) getCommandBufferWrapper; // creates command buffer wrapper (when doesn't exist)86- (MTLCommandBufferWrapper *) pullCommandBufferWrapper; // returns current buffer wrapper with loosing object ownership8788/**89* Fetches the MTLContext associated with the given destination surface,90* makes the context current for those surfaces, updates the destination91* viewport, and then returns a pointer to the MTLContext.92*/93+ (MTLContext*) setSurfacesEnv:(JNIEnv*)env src:(jlong)pSrc dst:(jlong)pDst;9495- (id)initWithDevice:(id<MTLDevice>)d shadersLib:(NSString*)shadersLib;96- (void)dealloc;9798/**99* Resets the current clip state (disables both scissor and depth tests).100*/101- (void)resetClip;102103/**104* Sets the Metal scissor bounds to the provided rectangular clip bounds.105*/106- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2;107108- (const MTLScissorRect *)clipRect;109110/**111* Sets up a complex (shape) clip using the Metal stencil buffer. This112* method prepares the stencil buffer so that the clip Region spans can113* be "rendered" into it. The stencil buffer is first cleared, then the114* stencil func is setup so that when we render the clip spans,115* nothing is rendered into the color buffer, but for each pixel that would116* be rendered, a 0xFF value is placed into that location in the stencil117* buffer. With stencil test enabled, pixels will only be rendered into the118* color buffer if the corresponding value at that (x,y) location in the119* stencil buffer is equal to 0xFF.120*/121- (void)beginShapeClip:(BMTLSDOps *)dstOps;122123/**124* Finishes setting up the shape clip by resetting the stencil func125* so that future rendering operations will once again be encoded for the126* color buffer (while respecting the clip set up in the stencil buffer).127*/128- (void)endShapeClip:(BMTLSDOps *)dstOps;129130/**131* Resets all Metal compositing state (disables blending and logic132* operations).133*/134- (void)resetComposite;135136/**137* Initializes the Metal blending state. XOR mode is disabled and the138* appropriate blend functions are setup based on the AlphaComposite rule139* constant.140*/141- (void)setAlphaCompositeRule:(jint)rule extraAlpha:(jfloat)extraAlpha142flags:(jint)flags;143144/**145* Returns autorelease string with composite description (for debugging only)146*/147- (NSString*)getCompositeDescription;148149/**150* Returns autorelease string with paint description (for debugging only)151*/152- (NSString*)getPaintDescription;153154/**155* Initializes the Metal logic op state to XOR mode. Blending is disabled156* before enabling logic op mode. The XOR pixel value will be applied157* later in the MTLContext_SetColor() method.158*/159- (void)setXorComposite:(jint)xorPixel;160- (jboolean)useXORComposite;161162/**163* Resets the Metal transform state back to the identity matrix.164*/165- (void)resetTransform;166167/**168* Initializes the Metal transform state by setting the modelview transform169* using the given matrix parameters.170*171* REMIND: it may be worthwhile to add serial id to AffineTransform, so we172* could do a quick check to see if the xform has changed since173* last time... a simple object compare won't suffice...174*/175- (void)setTransformM00:(jdouble) m00 M10:(jdouble) m10176M01:(jdouble) m01 M11:(jdouble) m11177M02:(jdouble) m02 M12:(jdouble) m12;178179- (void)reset;180- (void)resetPaint;181- (void)setColorPaint:(int)pixel;182- (void)setGradientPaintUseMask:(jboolean)useMask183cyclic:(jboolean)cyclic184p0:(jdouble)p0185p1:(jdouble)p1186p3:(jdouble)p3187pixel1:(jint)pixel1188pixel2:(jint) pixel2;189- (void)setLinearGradientPaint:(jboolean)useMask190linear:(jboolean)linear191cycleMethod:(jint)cycleMethod192numStops:(jint)numStops193p0:(jfloat)p0194p1:(jfloat)p1195p3:(jfloat)p3196fractions:(jfloat *)fractions197pixels:(jint *)pixels;198- (void)setRadialGradientPaint:(jboolean)useMask199linear:(jboolean)linear200cycleMethod:(jboolean)cycleMethod201numStops:(jint)numStops202m00:(jfloat)m00203m01:(jfloat)m01204m02:(jfloat)m02205m10:(jfloat)m10206m11:(jfloat)m11207m12:(jfloat)m12208focusX:(jfloat)focusX209fractions:(void *)fractions210pixels:(void *)pixels;211- (void)setTexturePaint:(jboolean)useMask212pSrcOps:(jlong)pSrcOps213filter:(jboolean)filter214xp0:(jdouble)xp0215xp1:(jdouble)xp1216xp3:(jdouble)xp3217yp0:(jdouble)yp0218yp1:(jdouble)yp1219yp3:(jdouble)yp3;220221// Sets current image conversion operation (instance of MTLConvolveOp, MTLRescaleOp, MTLLookupOp).222// Used only in MTLIsoBlit (to blit image with some conversion). Pattern of usage: enableOp -> IsoBlit -> disableOp.223// TODO: Need to remove it from MTLContext and pass it as an argument for IsoBlit (because it's more224// simple and clear)225-(void)setBufImgOp:(NSObject*)bufImgOp;226227-(NSObject*)getBufImgOp;228229- (id<MTLCommandBuffer>)createCommandBuffer;230- (id<MTLCommandBuffer>)createBlitCommandBuffer;231@end232233/**234* See BufferedContext.java for more on these flags...235*/236#define MTLC_NO_CONTEXT_FLAGS \237sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS238#define MTLC_SRC_IS_OPAQUE \239sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE240#define MTLC_USE_MASK \241sun_java2d_pipe_BufferedContext_USE_MASK242243#endif /* MTLContext_h_Included */244245246