1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef MTLContext_h_Included
  27 #define MTLContext_h_Included
  28 
  29 #include "sun_java2d_pipe_BufferedContext.h"
  30 #include "sun_java2d_metal_MTLContext.h"
  31 #include "sun_java2d_metal_MTLContext_MTLContextCaps.h"
  32 
  33 #import <Metal/Metal.h>
  34 #include "j2d_md.h"
  35 #include "MTLSurfaceDataBase.h"
  36 
  37 /**
  38  * The MTLBlendRule structure encapsulates the two enumerated values that
  39  * comprise a given Porter-Duff blending (compositing) rule.  For example,
  40  * the "SrcOver" rule can be represented by:
  41  *     rule.src = GL_ONE;
  42  *     rule.dst = GL_ONE_MINUS_SRC_ALPHA;
  43  *
  44  *     GLenum src;
  45  * The constant representing the source factor in this Porter-Duff rule.
  46  *
  47  *     GLenum dst;
  48  * The constant representing the destination factor in this Porter-Duff rule.
  49  */
  50 typedef struct {
  51     jint src;
  52     jint dst;
  53 } MTLBlendRule;
  54 
  55 /**
  56  * The MTLContext structure contains cached state relevant to the native
  57  * OpenGL context stored within the native ctxInfo field.  Each Java-level
  58  * MTLContext object is associated with a native-level MTLContext structure.
  59  * The caps field is a bitfield that expresses the capabilities of the
  60  * GraphicsConfig associated with this context (see MTLContext.java for
  61  * the definitions of each capability bit).  The other fields are
  62  * simply cached values of various elements of the context state, typically
  63  * used in the MTLContext.set*() methods.
  64  *
  65  * Note that the textureFunction field is implicitly set to zero when the
  66  * MTLContext is created.  The acceptable values (e.g. GL_MODULATE,
  67  * GL_REPLACE) for this field are never zero, which means we will always
  68  * validate the texture function state upon the first call to the
  69  * MTLC_UPDATE_TEXTURE_FUNCTION() macro.
  70  */
  71 typedef struct {
  72     jint       compState;
  73     jfloat     extraAlpha;
  74     jint       xorPixel;
  75     jint       pixel;
  76     jubyte     r;
  77     jubyte     g;
  78     jubyte     b;
  79     jubyte     a;
  80     jint       paintState;
  81     jboolean   useMask;
  82     jdouble   *xformMatrix;
  83     jint     blitTextureID;
  84     jint      textureFunction;
  85     jboolean   vertexCacheEnabled;
  86 
  87     id<MTLDevice>               mtlDevice;
  88     id<MTLLibrary>              mtlLibrary;
  89     id<MTLRenderPipelineState>  mtlPipelineState;
  90     id<MTLRenderPipelineState>  mtlBlitPipelineState;
  91     id<MTLCommandQueue>         mtlCommandQueue;
  92     id<MTLCommandBuffer>        mtlCommandBuffer;
  93     id<MTLTexture>              mtlFrameBuffer;
  94     BOOL                        mtlEmptyCommandBuffer;
  95     id<MTLBuffer>               mtlVertexBuffer;
  96     jint                        mtlColor;
  97     MTLRenderPassDescriptor*    mtlRenderPassDesc;
  98 } MTLContext;
  99 
 100 /**
 101  * See BufferedContext.java for more on these flags...
 102  */
 103 #define MTLC_NO_CONTEXT_FLAGS \
 104     sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS
 105 #define MTLC_SRC_IS_OPAQUE    \
 106     sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE
 107 #define MTLC_USE_MASK         \
 108     sun_java2d_pipe_BufferedContext_USE_MASK
 109 
 110 /**
 111  * See MTLContext.java for more on these flags.
 112  */
 113 
 114 /**
 115  * Exported methods.
 116  */
 117 MTLContext *MTLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst);
 118 void MTLContext_ResetClip(MTLContext *mtlc);
 119 void MTLContext_SetRectClip(MTLContext *mtlc, BMTLSDOps *dstOps,
 120                             jint x1, jint y1, jint x2, jint y2);
 121 void MTLContext_BeginShapeClip(MTLContext *mtlc);
 122 void MTLContext_EndShapeClip(MTLContext *mtlc, BMTLSDOps *dstOps);
 123 void MTLContext_SetExtraAlpha(jfloat ea);
 124 void MTLContext_ResetComposite(MTLContext *mtlc);
 125 void MTLContext_SetAlphaComposite(MTLContext *mtlc,
 126                                   jint rule, jfloat extraAlpha, jint flags);
 127 void MTLContext_SetXorComposite(MTLContext *mtlc, jint xorPixel);
 128 void MTLContext_ResetTransform(MTLContext *mtlc);
 129 void MTLContext_SetTransform(MTLContext *mtlc,
 130                              jdouble m00, jdouble m10,
 131                              jdouble m01, jdouble m11,
 132                              jdouble m02, jdouble m12);
 133 
 134 jboolean MTLContext_InitBlitTileTexture(MTLContext *mtlc);
 135 jint MTLContext_CreateBlitTexture(jint internalFormat, jint pixelFormat,
 136                                     jint width, jint height);
 137 
 138 void MTLContext_DestroyContextResources(MTLContext *mtlc);
 139 
 140 #endif /* MTLContext_h_Included */