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 HEADLESS
  27 
  28 #include <jni.h>
  29 #include <jlong.h>
  30 
  31 #include "SurfaceData.h"
  32 #include "MTLBlitLoops.h"
  33 #include "MTLRenderQueue.h"
  34 #include "MTLSurfaceDataBase.h"
  35 #include "GraphicsPrimitiveMgr.h"
  36 
  37 #include <stdlib.h> // malloc
  38 #include <string.h> // memcpy
  39 #include "IntArgbPre.h"
  40 
  41 extern MTLPixelFormat PixelFormats[];
  42 
  43 /**
  44  * Inner loop used for copying a source MTL "Surface" (window, pbuffer,
  45  * etc.) to a destination OpenGL "Surface".  Note that the same surface can
  46  * be used as both the source and destination, as is the case in a copyArea()
  47  * operation.  This method is invoked from MTLBlitLoops_IsoBlit() as well as
  48  * MTLBlitLoops_CopyArea().
  49  *
  50  * The standard glCopyPixels() mechanism is used to copy the source region
  51  * into the destination region.  If the regions have different dimensions,
  52  * the source will be scaled into the destination as appropriate (only
  53  * nearest neighbor filtering will be applied for simple scale operations).
  54  */
  55 static void
  56 MTLBlitSurfaceToSurface(MTLContext *mtlc, BMTLSDOps *srcOps, BMTLSDOps *dstOps,
  57                         jint sx1, jint sy1, jint sx2, jint sy2,
  58                         jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
  59 {
  60     //TODO
  61     J2dTraceNotImplPrimitive("MTLBlitSurfaceToSurface");
  62 }
  63 
  64 /**
  65  * Inner loop used for copying a source MTL "Texture" to a destination
  66  * OpenGL "Surface".  This method is invoked from MTLBlitLoops_IsoBlit().
  67  *
  68  * This method will copy, scale, or transform the source texture into the
  69  * destination depending on the transform state, as established in
  70  * and MTLContext_SetTransform().  If the source texture is
  71  * transformed in any way when rendered into the destination, the filtering
  72  * method applied is determined by the hint parameter (can be GL_NEAREST or
  73  * GL_LINEAR).
  74  */
  75 static void
  76 MTLBlitTextureToSurface(MTLContext *mtlc,
  77                         MTLSDOps *srcOps, MTLSDOps *dstOps,
  78                         jboolean rtt, jint hint,
  79                         jint sx1, jint sy1, jint sx2, jint sy2,
  80                         jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
  81 {
  82     //TODO
  83     J2dTraceNotImplPrimitive("MTLBlitTextureToSurface");
  84 }
  85 
  86 /**
  87  * Inner loop used for copying a source system memory ("Sw") surface to a
  88  * destination MTL "Surface".  This method is invoked from
  89  * MTLBlitLoops_Blit().
  90  *
  91  * The standard glDrawPixels() mechanism is used to copy the source region
  92  * into the destination region.  If the regions have different
  93  * dimensions, the source will be scaled into the destination
  94  * as appropriate (only nearest neighbor filtering will be applied for simple
  95  * scale operations).
  96  */
  97 static void
  98 MTLBlitSwToSurface(MTLContext *mtlc, SurfaceDataRasInfo *srcInfo,
  99                    MTPixelFormat *pf,
 100                    jint sx1, jint sy1, jint sx2, jint sy2,
 101                    jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
 102 {
 103     //TODO
 104     J2dTraceNotImplPrimitive("MTLBlitSwToSurface");
 105 }
 106 
 107 /**
 108  * Inner loop used for copying a source system memory ("Sw") surface or
 109  * MTL "Surface" to a destination OpenGL "Surface", using an MTL texture
 110  * tile as an intermediate surface.  This method is invoked from
 111  * MTLBlitLoops_Blit() for "Sw" surfaces and MTLBlitLoops_IsoBlit() for
 112  * "Surface" surfaces.
 113  *
 114  * This method is used to transform the source surface into the destination.
 115  * Pixel rectangles cannot be arbitrarily transformed (without the
 116  * GL_EXT_pixel_transform extension, which is not supported on most modern
 117  * hardware).  However, texture mapped quads do respect the GL_MODELVIEW
 118  * transform matrix, so we use textures here to perform the transform
 119  * operation.  This method uses a tile-based approach in which a small
 120  * subregion of the source surface is copied into a cached texture tile.  The
 121  * texture tile is then mapped into the appropriate location in the
 122  * destination surface.
 123  *
 124  * REMIND: this only works well using GL_NEAREST for the filtering mode
 125  *         (GL_LINEAR causes visible stitching problems between tiles,
 126  *         but this can be fixed by making use of texture borders)
 127  */
 128 static void
 129 MTLBlitToSurfaceViaTexture(MTLContext *mtlc, SurfaceDataRasInfo *srcInfo,
 130                            MTPixelFormat *pf, MTLSDOps *srcOps,
 131                            jboolean swsurface, jint hint,
 132                            jint sx1, jint sy1, jint sx2, jint sy2,
 133                            jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
 134 {
 135     //TODO
 136     J2dTraceNotImplPrimitive("MTLBlitToSurfaceViaTexture");
 137 }
 138 
 139 /**
 140  * Inner loop used for copying a source system memory ("Sw") surface to a
 141  * destination OpenGL "Texture".  This method is invoked from
 142  * MTLBlitLoops_Blit().
 143  *
 144  * The source surface is effectively loaded into the MTL texture object,
 145  * which must have already been initialized by MTLSD_initTexture().  Note
 146  * that this method is only capable of copying the source surface into the
 147  * destination surface (i.e. no scaling or general transform is allowed).
 148  * This restriction should not be an issue as this method is only used
 149  * currently to cache a static system memory image into an MTL texture in
 150  * a hidden-acceleration situation.
 151  */
 152 static void
 153 MTLBlitSwToTexture(SurfaceDataRasInfo *srcInfo, MTPixelFormat *pf,
 154                    MTLSDOps *dstOps,
 155                    jint dx1, jint dy1, jint dx2, jint dy2)
 156 {
 157     //TODO
 158     J2dTraceNotImplPrimitive("MTLBlitSwToTexture");
 159 }
 160 
 161 /**
 162  * General blit method for copying a native MTL surface (of type "Surface"
 163  * or "Texture") to another MTL "Surface".  If texture is JNI_TRUE, this
 164  * method will invoke the Texture->Surface inner loop; otherwise, one of the
 165  * Surface->Surface inner loops will be invoked, depending on the transform
 166  * state.
 167  *
 168  * REMIND: we can trick these blit methods into doing XOR simply by passing
 169  *         in the (pixel ^ xorpixel) as the pixel value and preceding the
 170  *         blit with a fillrect...
 171  */
 172 void
 173 MTLBlitLoops_IsoBlit(JNIEnv *env,
 174                      MTLContext *mtlc, jlong pSrcOps, jlong pDstOps,
 175                      jboolean xform, jint hint,
 176                      jboolean texture, jboolean rtt,
 177                      jint sx1, jint sy1, jint sx2, jint sy2,
 178                      jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
 179 {
 180     //TODO
 181     J2dTraceNotImplPrimitive("MTLBlitLoops_IsoBlit");
 182 }
 183 
 184 /**
 185  * General blit method for copying a system memory ("Sw") surface to a native
 186  * MTL surface (of type "Surface" or "Texture").  If texture is JNI_TRUE,
 187  * this method will invoke the Sw->Texture inner loop; otherwise, one of the
 188  * Sw->Surface inner loops will be invoked, depending on the transform state.
 189  */
 190 void
 191 MTLBlitLoops_Blit(JNIEnv *env,
 192                   MTLContext *mtlc, jlong pSrcOps, jlong pDstOps,
 193                   jboolean xform, jint hint,
 194                   jint srctype, jboolean texture,
 195                   jint sx1, jint sy1, jint sx2, jint sy2,
 196                   jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
 197 {
 198     //TODO
 199     J2dTraceNotImplPrimitive("MTLBlitLoops_Blit");
 200 }
 201 
 202 /**
 203  * Specialized blit method for copying a native MTL "Surface" (pbuffer,
 204  * window, etc.) to a system memory ("Sw") surface.
 205  */
 206 void
 207 MTLBlitLoops_SurfaceToSwBlit(JNIEnv *env, MTLContext *mtlc,
 208                              jlong pSrcOps, jlong pDstOps, jint dsttype,
 209                              jint srcx, jint srcy, jint dstx, jint dsty,
 210                              jint width, jint height)
 211 {
 212     //TODO
 213     J2dTraceNotImplPrimitive("MTLBlitLoops_SurfaceToSwBlit");
 214 }
 215 
 216 void
 217 MTLBlitLoops_CopyArea(JNIEnv *env,
 218                       MTLContext *mtlc, BMTLSDOps *dstOps,
 219                       jint x, jint y, jint width, jint height,
 220                       jint dx, jint dy)
 221 {
 222     //TODO
 223     J2dTraceNotImplPrimitive("MTLBlitLoops_CopyArea");
 224 }
 225 
 226 #endif /* !HEADLESS */