src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MetalRenderQueue.m
branchmetal-prototype-branch
changeset 57416 e153174dba06
parent 57400 978ffc56771f
child 57417 28582d575a98
equal deleted inserted replaced
57400:978ffc56771f 57416:e153174dba06
     1 /*
       
     2  * Copyright (c) 2019, 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 <stdlib.h>
       
    29 #include <Foundation/NSObjCRuntime.h>
       
    30 #include "sun_java2d_pipe_BufferedOpCodes.h"
       
    31 #include "jlong.h"
       
    32 //#include "OGLBlitLoops.h"
       
    33 //#include "OGLBufImgOps.h"
       
    34 //#include "OGLContext.h"
       
    35 //#include "OGLMaskBlit.h"
       
    36 //#include "OGLMaskFill.h"
       
    37 //#include "OGLPaints.h"
       
    38 //#include "OGLRenderQueue.h"
       
    39 //#include "OGLRenderer.h"
       
    40 //#include "OGLSurfaceData.h"
       
    41 //#include "OGLTextRenderer.h"
       
    42 //#include "OGLVertexCache.h"
       
    43 
       
    44 #include "MetalRenderer.h"
       
    45 #include "MetalRenderQueue.h"
       
    46 #include "Trace.h"
       
    47 #include "MetalSurfaceData.h"
       
    48 
       
    49 /**
       
    50  * Used to track whether we are in a series of a simple primitive operations
       
    51  * or texturing operations.  This variable should be controlled only via
       
    52  * the INIT/CHECK/RESET_PREVIOUS_OP() macros.  See the
       
    53  * OGLRenderQueue_CheckPreviousOp() method below for more information.
       
    54  */
       
    55 //jint previousOp;
       
    56 
       
    57 /**
       
    58  * References to the "current" context and destination surface.
       
    59  */
       
    60 //static MetalContext *mtlc = NULL;
       
    61 static MetalSDOps *dstOps = NULL;
       
    62 static MetalContext *mtlc = NULL;
       
    63 
       
    64 /**
       
    65  * The following methods are implemented in the windowing system (i.e. GLX
       
    66  * and WGL) source files.
       
    67  */
       
    68 //extern OGLContext *OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo);
       
    69 //extern void OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo);
       
    70 //extern void OGLSD_SwapBuffers(JNIEnv *env, jlong window);
       
    71 //extern void OGLSD_Flush(JNIEnv *env);
       
    72 
       
    73 JNIEXPORT jlong JNICALL
       
    74 Java_sun_java2d_metal_MetalRenderQueue_flushBuffer(JNIEnv *env, jobject mtlrq, jlong buf, jint limit)
       
    75 {
       
    76     jboolean sync = JNI_FALSE;
       
    77     unsigned char *b, *end;
       
    78 
       
    79     J2dTraceLn1(J2D_TRACE_INFO,
       
    80                 "MetalRenderQueue_flushBuffer: limit=%d", limit);
       
    81 
       
    82     NSLog(@"Java_sun_java2d_metal_MetalRenderQueue_flushBuffer :");
       
    83 
       
    84     b = (unsigned char *)jlong_to_ptr(buf);
       
    85     if (b == NULL) {
       
    86         /*J2dRlsTraceLn(J2D_TRACE_ERROR,
       
    87             "MetalRenderQueue_flushBuffer: cannot get direct buffer address");*/
       
    88         return 0;
       
    89     }
       
    90 
       
    91     //INIT_PREVIOUS_OP();
       
    92     end = b + limit;
       
    93 
       
    94     while (b < end) {
       
    95         jint opcode = NEXT_INT(b);
       
    96 
       
    97         fprintf(stdout, "MetalRenderQueue_flushBuffer_opcode : %d\n", opcode);fflush(stdout);
       
    98         switch (opcode) {
       
    99 
       
   100         // draw ops
       
   101         case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
       
   102             {
       
   103                 jint x1 = NEXT_INT(b);
       
   104                 jint y1 = NEXT_INT(b);
       
   105                 jint x2 = NEXT_INT(b);
       
   106                 jint y2 = NEXT_INT(b);
       
   107                 MetalRenderer_DrawLine(mtlc, x1, y1, x2, y2);
       
   108             }
       
   109             break;
       
   110         case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:
       
   111             {
       
   112                 jint x = NEXT_INT(b);
       
   113                 jint y = NEXT_INT(b);
       
   114                 jint w = NEXT_INT(b);
       
   115                 jint h = NEXT_INT(b);
       
   116                 MetalRenderer_DrawRect(mtlc, x, y, w, h);
       
   117             }
       
   118             break;
       
   119         case sun_java2d_pipe_BufferedOpCodes_DRAW_POLY:
       
   120             {
       
   121                 jint nPoints      = NEXT_INT(b);
       
   122                 jboolean isClosed = NEXT_BOOLEAN(b);
       
   123                 jint transX       = NEXT_INT(b);
       
   124                 jint transY       = NEXT_INT(b);
       
   125                 /*jint *xPoints = (jint *)b;
       
   126                 jint *yPoints = ((jint *)b) + nPoints;
       
   127                 OGLRenderer_DrawPoly(oglc, nPoints, isClosed,
       
   128                                      transX, transY,
       
   129                                      xPoints, yPoints);*/
       
   130                 SKIP_BYTES(b, nPoints * BYTES_PER_POLY_POINT);
       
   131             }
       
   132             break;
       
   133         case sun_java2d_pipe_BufferedOpCodes_DRAW_PIXEL:
       
   134             {
       
   135                 jint x = NEXT_INT(b);
       
   136                 jint y = NEXT_INT(b);
       
   137                 // Note that we could use GL_POINTS here, but the common
       
   138                 // use case for DRAW_PIXEL is when rendering a Path2D,
       
   139                 // which will consist of a mix of DRAW_PIXEL and DRAW_LINE
       
   140                 // calls.  So to improve batching we use GL_LINES here,
       
   141                 // even though it requires an extra vertex per pixel.
       
   142                 /*CONTINUE_IF_NULL(oglc);
       
   143                 CHECK_PREVIOUS_OP(GL_LINES);
       
   144                 j2d_glVertex2i(x, y);
       
   145                 j2d_glVertex2i(x+1, y+1);*/
       
   146             }
       
   147             break;
       
   148         case sun_java2d_pipe_BufferedOpCodes_DRAW_SCANLINES:
       
   149             {
       
   150                 jint count = NEXT_INT(b);
       
   151                 //OGLRenderer_DrawScanlines(oglc, count, (jint *)b);
       
   152                 SKIP_BYTES(b, count * BYTES_PER_SCANLINE);
       
   153             }
       
   154             break;
       
   155         case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
       
   156             {
       
   157                 jfloat x11 = NEXT_FLOAT(b);
       
   158                 jfloat y11 = NEXT_FLOAT(b);
       
   159                 jfloat dx21 = NEXT_FLOAT(b);
       
   160                 jfloat dy21 = NEXT_FLOAT(b);
       
   161                 jfloat dx12 = NEXT_FLOAT(b);
       
   162                 jfloat dy12 = NEXT_FLOAT(b);
       
   163                 jfloat lwr21 = NEXT_FLOAT(b);
       
   164                 jfloat lwr12 = NEXT_FLOAT(b);
       
   165                 MetalRenderer_DrawParallelogram(mtlc,
       
   166                                               x11, y11,
       
   167                                               dx21, dy21,
       
   168                                               dx12, dy12,
       
   169                                               lwr21, lwr12);
       
   170             }
       
   171             break;
       
   172         case sun_java2d_pipe_BufferedOpCodes_DRAW_AAPARALLELOGRAM:
       
   173             {
       
   174                 jfloat x11 = NEXT_FLOAT(b);
       
   175                 jfloat y11 = NEXT_FLOAT(b);
       
   176                 jfloat dx21 = NEXT_FLOAT(b);
       
   177                 jfloat dy21 = NEXT_FLOAT(b);
       
   178                 jfloat dx12 = NEXT_FLOAT(b);
       
   179                 jfloat dy12 = NEXT_FLOAT(b);
       
   180                 jfloat lwr21 = NEXT_FLOAT(b);
       
   181                 jfloat lwr12 = NEXT_FLOAT(b);
       
   182                 /*OGLRenderer_DrawAAParallelogram(oglc, dstOps,
       
   183                                                 x11, y11,
       
   184                                                 dx21, dy21,
       
   185                                                 dx12, dy12,
       
   186                                                 lwr21, lwr12);*/
       
   187             }
       
   188             break;
       
   189 
       
   190         // fill ops
       
   191         case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:
       
   192             {
       
   193                 jint x = NEXT_INT(b);
       
   194                 jint y = NEXT_INT(b);
       
   195                 jint w = NEXT_INT(b);
       
   196                 jint h = NEXT_INT(b);
       
   197                 MetalRenderer_FillRect(mtlc, x, y, w, h);
       
   198             }
       
   199             break;
       
   200         case sun_java2d_pipe_BufferedOpCodes_FILL_SPANS:
       
   201             {
       
   202                 jint count = NEXT_INT(b);
       
   203                 //OGLRenderer_FillSpans(oglc, count, (jint *)b);
       
   204                 SKIP_BYTES(b, count * BYTES_PER_SPAN);
       
   205             }
       
   206             break;
       
   207         case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
       
   208             {
       
   209                 jfloat x11 = NEXT_FLOAT(b);
       
   210                 jfloat y11 = NEXT_FLOAT(b);
       
   211                 jfloat dx21 = NEXT_FLOAT(b);
       
   212                 jfloat dy21 = NEXT_FLOAT(b);
       
   213                 jfloat dx12 = NEXT_FLOAT(b);
       
   214                 jfloat dy12 = NEXT_FLOAT(b);
       
   215                 MetalRenderer_FillParallelogram(mtlc,
       
   216                                               x11, y11,
       
   217                                               dx21, dy21,
       
   218                                               dx12, dy12);
       
   219             }
       
   220             break;
       
   221         case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:
       
   222             {
       
   223                 jfloat x11 = NEXT_FLOAT(b);
       
   224                 jfloat y11 = NEXT_FLOAT(b);
       
   225                 jfloat dx21 = NEXT_FLOAT(b);
       
   226                 jfloat dy21 = NEXT_FLOAT(b);
       
   227                 jfloat dx12 = NEXT_FLOAT(b);
       
   228                 jfloat dy12 = NEXT_FLOAT(b);
       
   229                 /*OGLRenderer_FillAAParallelogram(oglc, dstOps,
       
   230                                                 x11, y11,
       
   231                                                 dx21, dy21,
       
   232                                                 dx12, dy12);*/
       
   233             }
       
   234             break;
       
   235 
       
   236         // text-related ops
       
   237         case sun_java2d_pipe_BufferedOpCodes_DRAW_GLYPH_LIST:
       
   238             {
       
   239                 jint numGlyphs        = NEXT_INT(b);
       
   240                 jint packedParams     = NEXT_INT(b);
       
   241                 jfloat glyphListOrigX = NEXT_FLOAT(b);
       
   242                 jfloat glyphListOrigY = NEXT_FLOAT(b);
       
   243                 /*jboolean usePositions = EXTRACT_BOOLEAN(packedParams,
       
   244                                                         OFFSET_POSITIONS);
       
   245                 jboolean subPixPos    = EXTRACT_BOOLEAN(packedParams,
       
   246                                                         OFFSET_SUBPIXPOS);
       
   247                 jboolean rgbOrder     = EXTRACT_BOOLEAN(packedParams,
       
   248                                                         OFFSET_RGBORDER);
       
   249                 jint lcdContrast      = EXTRACT_BYTE(packedParams,
       
   250                                                      OFFSET_CONTRAST);
       
   251                 unsigned char *images = b;
       
   252                 unsigned char *positions;
       
   253                 jint bytesPerGlyph;
       
   254                 if (usePositions) {
       
   255                     positions = (b + numGlyphs * BYTES_PER_GLYPH_IMAGE);
       
   256                     bytesPerGlyph = BYTES_PER_POSITIONED_GLYPH;
       
   257                 } else {
       
   258                     positions = NULL;
       
   259                     bytesPerGlyph = BYTES_PER_GLYPH_IMAGE;
       
   260                 }
       
   261                 OGLTR_DrawGlyphList(env, oglc, dstOps,
       
   262                                     numGlyphs, usePositions,
       
   263                                     subPixPos, rgbOrder, lcdContrast,
       
   264                                     glyphListOrigX, glyphListOrigY,
       
   265                                     images, positions);
       
   266                 SKIP_BYTES(b, numGlyphs * bytesPerGlyph);*/
       
   267             }
       
   268             break;
       
   269 
       
   270         // copy-related ops
       
   271         case sun_java2d_pipe_BufferedOpCodes_COPY_AREA:
       
   272             {
       
   273                 jint x  = NEXT_INT(b);
       
   274                 jint y  = NEXT_INT(b);
       
   275                 jint w  = NEXT_INT(b);
       
   276                 jint h  = NEXT_INT(b);
       
   277                 jint dx = NEXT_INT(b);
       
   278                 jint dy = NEXT_INT(b);
       
   279                 /*OGLBlitLoops_CopyArea(env, oglc, dstOps,
       
   280                                       x, y, w, h, dx, dy);*/
       
   281             }
       
   282             break;
       
   283         case sun_java2d_pipe_BufferedOpCodes_BLIT:
       
   284             {
       
   285                 jint packedParams = NEXT_INT(b);
       
   286                 jint sx1          = NEXT_INT(b);
       
   287                 jint sy1          = NEXT_INT(b);
       
   288                 jint sx2          = NEXT_INT(b);
       
   289                 jint sy2          = NEXT_INT(b);
       
   290                 jdouble dx1       = NEXT_DOUBLE(b);
       
   291                 jdouble dy1       = NEXT_DOUBLE(b);
       
   292                 jdouble dx2       = NEXT_DOUBLE(b);
       
   293                 jdouble dy2       = NEXT_DOUBLE(b);
       
   294                 jlong pSrc        = NEXT_LONG(b);
       
   295                 jlong pDst        = NEXT_LONG(b);
       
   296                 /*jint hint         = EXTRACT_BYTE(packedParams, OFFSET_HINT);
       
   297                 jboolean texture  = EXTRACT_BOOLEAN(packedParams,
       
   298                                                     OFFSET_TEXTURE);
       
   299                 jboolean rtt      = EXTRACT_BOOLEAN(packedParams,
       
   300                                                     OFFSET_RTT);
       
   301                 jboolean xform    = EXTRACT_BOOLEAN(packedParams,
       
   302                                                     OFFSET_XFORM);
       
   303                 jboolean isoblit  = EXTRACT_BOOLEAN(packedParams,
       
   304                                                     OFFSET_ISOBLIT);
       
   305                 if (isoblit) {
       
   306                     OGLBlitLoops_IsoBlit(env, oglc, pSrc, pDst,
       
   307                                          xform, hint, texture, rtt,
       
   308                                          sx1, sy1, sx2, sy2,
       
   309                                          dx1, dy1, dx2, dy2);
       
   310                 } else {
       
   311                     jint srctype = EXTRACT_BYTE(packedParams, OFFSET_SRCTYPE);
       
   312                     OGLBlitLoops_Blit(env, oglc, pSrc, pDst,
       
   313                                       xform, hint, srctype, texture,
       
   314                                       sx1, sy1, sx2, sy2,
       
   315                                       dx1, dy1, dx2, dy2);
       
   316                 }*/
       
   317             }
       
   318             break;
       
   319         case sun_java2d_pipe_BufferedOpCodes_SURFACE_TO_SW_BLIT:
       
   320             {
       
   321                 jint sx      = NEXT_INT(b);
       
   322                 jint sy      = NEXT_INT(b);
       
   323                 jint dx      = NEXT_INT(b);
       
   324                 jint dy      = NEXT_INT(b);
       
   325                 jint w       = NEXT_INT(b);
       
   326                 jint h       = NEXT_INT(b);
       
   327                 jint dsttype = NEXT_INT(b);
       
   328                 jlong pSrc   = NEXT_LONG(b);
       
   329                 jlong pDst   = NEXT_LONG(b);
       
   330                 /*OGLBlitLoops_SurfaceToSwBlit(env, oglc,
       
   331                                              pSrc, pDst, dsttype,
       
   332                                              sx, sy, dx, dy, w, h);*/
       
   333             }
       
   334             break;
       
   335         case sun_java2d_pipe_BufferedOpCodes_MASK_FILL:
       
   336             {
       
   337                 jint x        = NEXT_INT(b);
       
   338                 jint y        = NEXT_INT(b);
       
   339                 jint w        = NEXT_INT(b);
       
   340                 jint h        = NEXT_INT(b);
       
   341                 jint maskoff  = NEXT_INT(b);
       
   342                 jint maskscan = NEXT_INT(b);
       
   343                 jint masklen  = NEXT_INT(b);
       
   344                 unsigned char *pMask = (masklen > 0) ? b : NULL;
       
   345                 /*OGLMaskFill_MaskFill(oglc, x, y, w, h,
       
   346                                      maskoff, maskscan, masklen, pMask);*/
       
   347                 SKIP_BYTES(b, masklen);
       
   348             }
       
   349             break;
       
   350         case sun_java2d_pipe_BufferedOpCodes_MASK_BLIT:
       
   351             {
       
   352                 jint dstx     = NEXT_INT(b);
       
   353                 jint dsty     = NEXT_INT(b);
       
   354                 jint width    = NEXT_INT(b);
       
   355                 jint height   = NEXT_INT(b);
       
   356                 jint masklen  = width * height * sizeof(jint);
       
   357                 /*OGLMaskBlit_MaskBlit(env, oglc,
       
   358                                      dstx, dsty, width, height, b);*/
       
   359                 SKIP_BYTES(b, masklen);
       
   360             }
       
   361             break;
       
   362 
       
   363         // state-related ops
       
   364         case sun_java2d_pipe_BufferedOpCodes_SET_RECT_CLIP:
       
   365             {
       
   366                 jint x1 = NEXT_INT(b);
       
   367                 jint y1 = NEXT_INT(b);
       
   368                 jint x2 = NEXT_INT(b);
       
   369                 jint y2 = NEXT_INT(b);
       
   370                 //OGLContext_SetRectClip(oglc, dstOps, x1, y1, x2, y2);
       
   371                 MetalRenderer_SetRectClip(mtlc, x1, y1, x2, y2);
       
   372             }
       
   373             break;
       
   374         case sun_java2d_pipe_BufferedOpCodes_BEGIN_SHAPE_CLIP:
       
   375             {
       
   376                 //OGLContext_BeginShapeClip(oglc);
       
   377             }
       
   378             break;
       
   379         case sun_java2d_pipe_BufferedOpCodes_SET_SHAPE_CLIP_SPANS:
       
   380             {
       
   381                 jint count = NEXT_INT(b);
       
   382                 //OGLRenderer_FillSpans(oglc, count, (jint *)b);
       
   383                 SKIP_BYTES(b, count * BYTES_PER_SPAN);
       
   384             }
       
   385             break;
       
   386         case sun_java2d_pipe_BufferedOpCodes_END_SHAPE_CLIP:
       
   387             {
       
   388                 //OGLContext_EndShapeClip(oglc, dstOps);
       
   389             }
       
   390             break;
       
   391         case sun_java2d_pipe_BufferedOpCodes_RESET_CLIP:
       
   392             {
       
   393                 //OGLContext_ResetClip(oglc);
       
   394             }
       
   395             break;
       
   396         case sun_java2d_pipe_BufferedOpCodes_SET_ALPHA_COMPOSITE:
       
   397             {
       
   398                 jint rule         = NEXT_INT(b);
       
   399                 jfloat extraAlpha = NEXT_FLOAT(b);
       
   400                 jint flags        = NEXT_INT(b);
       
   401                 //OGLContext_SetAlphaComposite(oglc, rule, extraAlpha, flags);
       
   402             }
       
   403             break;
       
   404         case sun_java2d_pipe_BufferedOpCodes_SET_XOR_COMPOSITE:
       
   405             {
       
   406                 jint xorPixel = NEXT_INT(b);
       
   407                 //OGLContext_SetXorComposite(oglc, xorPixel);
       
   408             }
       
   409             break;
       
   410         case sun_java2d_pipe_BufferedOpCodes_RESET_COMPOSITE:
       
   411             {
       
   412                 //OGLContext_ResetComposite(oglc);
       
   413             }
       
   414             break;
       
   415         case sun_java2d_pipe_BufferedOpCodes_SET_TRANSFORM:
       
   416             {
       
   417                 jdouble m00 = NEXT_DOUBLE(b);
       
   418                 jdouble m10 = NEXT_DOUBLE(b);
       
   419                 jdouble m01 = NEXT_DOUBLE(b);
       
   420                 jdouble m11 = NEXT_DOUBLE(b);
       
   421                 jdouble m02 = NEXT_DOUBLE(b);
       
   422                 jdouble m12 = NEXT_DOUBLE(b);
       
   423                 //OGLContext_SetTransform(oglc, m00, m10, m01, m11, m02, m12);
       
   424             }
       
   425             break;
       
   426         case sun_java2d_pipe_BufferedOpCodes_RESET_TRANSFORM:
       
   427             {
       
   428                 //OGLContext_ResetTransform(oglc);
       
   429             }
       
   430             break;
       
   431 
       
   432         // context-related ops
       
   433         case sun_java2d_pipe_BufferedOpCodes_SET_SURFACES:
       
   434             {
       
   435                 //fprintf(stdout, "MetalRenderQueue_flushBuffer_SetSurfaces\n");fflush(stdout);
       
   436                 jlong pSrc = NEXT_LONG(b);
       
   437                 jlong pDst = NEXT_LONG(b);
       
   438                 /*if (oglc != NULL) {
       
   439                     RESET_PREVIOUS_OP();
       
   440                 }
       
   441                 oglc = OGLContext_SetSurfaces(env, pSrc, pDst);*/
       
   442                 dstOps = (MetalSDOps *)jlong_to_ptr(pDst);
       
   443             }
       
   444             break;
       
   445         case sun_java2d_pipe_BufferedOpCodes_SET_SCRATCH_SURFACE:
       
   446             {
       
   447                 jlong pConfigInfo = NEXT_LONG(b);
       
   448                 /*if (oglc != NULL) {
       
   449                     RESET_PREVIOUS_OP();
       
   450                 }
       
   451                 oglc = OGLSD_SetScratchSurface(env, pConfigInfo);
       
   452                 dstOps = NULL;*/
       
   453             }
       
   454             break;
       
   455         case sun_java2d_pipe_BufferedOpCodes_FLUSH_SURFACE:
       
   456             {
       
   457                 jlong pData = NEXT_LONG(b);
       
   458                 /*OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
       
   459                 if (oglsdo != NULL) {
       
   460                     CONTINUE_IF_NULL(oglc);
       
   461                     RESET_PREVIOUS_OP();
       
   462                     OGLSD_Delete(env, oglsdo);
       
   463                 }*/
       
   464             }
       
   465             break;
       
   466         case sun_java2d_pipe_BufferedOpCodes_DISPOSE_SURFACE:
       
   467             {
       
   468                 jlong pData = NEXT_LONG(b);
       
   469                 /*OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
       
   470                 if (oglsdo != NULL) {
       
   471                     CONTINUE_IF_NULL(oglc);
       
   472                     RESET_PREVIOUS_OP();
       
   473                     OGLSD_Delete(env, oglsdo);
       
   474                     if (oglsdo->privOps != NULL) {
       
   475                         free(oglsdo->privOps);
       
   476                     }
       
   477                 }*/
       
   478             }
       
   479             break;
       
   480         case sun_java2d_pipe_BufferedOpCodes_DISPOSE_CONFIG:
       
   481             {
       
   482                 jlong pConfigInfo = NEXT_LONG(b);
       
   483                 /*CONTINUE_IF_NULL(oglc);
       
   484                 RESET_PREVIOUS_OP();
       
   485                 OGLGC_DestroyOGLGraphicsConfig(pConfigInfo);
       
   486 
       
   487                 // the previous method will call glX/wglMakeCurrent(None),
       
   488                 // so we should nullify the current oglc and dstOps to avoid
       
   489                 // calling glFlush() (or similar) while no context is current
       
   490                 oglc = NULL;
       
   491                 dstOps = NULL;*/
       
   492             }
       
   493             break;
       
   494         case sun_java2d_pipe_BufferedOpCodes_INVALIDATE_CONTEXT:
       
   495             {
       
   496                 // flush just in case there are any pending operations in
       
   497                 // the hardware pipe
       
   498                 /*if (oglc != NULL) {
       
   499                     RESET_PREVIOUS_OP();
       
   500                     j2d_glFlush();
       
   501                 }
       
   502 
       
   503                 // invalidate the references to the current context and
       
   504                 // destination surface that are maintained at the native level
       
   505                 oglc = NULL;
       
   506                 dstOps = NULL;*/
       
   507             }
       
   508             break;
       
   509         case sun_java2d_pipe_BufferedOpCodes_SAVE_STATE:
       
   510             {
       
   511                 /*j2d_glPushAttrib(GL_ALL_ATTRIB_BITS);
       
   512                 j2d_glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
       
   513                 j2d_glMatrixMode(GL_MODELVIEW);
       
   514                 j2d_glPushMatrix();
       
   515                 j2d_glMatrixMode(GL_PROJECTION);
       
   516                 j2d_glPushMatrix();
       
   517                 j2d_glMatrixMode(GL_TEXTURE);
       
   518                 j2d_glPushMatrix();*/
       
   519             }
       
   520             break;
       
   521 
       
   522         case sun_java2d_pipe_BufferedOpCodes_RESTORE_STATE:
       
   523             {
       
   524                 /*j2d_glPopAttrib();
       
   525                 j2d_glPopClientAttrib();
       
   526                 j2d_glMatrixMode(GL_MODELVIEW);
       
   527                 j2d_glPopMatrix();
       
   528                 j2d_glMatrixMode(GL_PROJECTION);
       
   529                 j2d_glPopMatrix();
       
   530                 j2d_glMatrixMode(GL_TEXTURE);
       
   531                 j2d_glPopMatrix();*/
       
   532             }
       
   533             break;
       
   534         case sun_java2d_pipe_BufferedOpCodes_SYNC:
       
   535             {
       
   536                 //sync = JNI_TRUE;
       
   537             }
       
   538             break;
       
   539 
       
   540         // multibuffering ops
       
   541         case sun_java2d_pipe_BufferedOpCodes_SWAP_BUFFERS:
       
   542             {
       
   543                 jlong window = NEXT_LONG(b);
       
   544                 /*if (oglc != NULL) {
       
   545                     RESET_PREVIOUS_OP();
       
   546                 }
       
   547                 OGLSD_SwapBuffers(env, window);*/
       
   548             }
       
   549             break;
       
   550 
       
   551         // special no-op (mainly used for achieving 8-byte alignment)
       
   552         case sun_java2d_pipe_BufferedOpCodes_NOOP:
       
   553             break;
       
   554 
       
   555         // paint-related ops
       
   556         case sun_java2d_pipe_BufferedOpCodes_RESET_PAINT:
       
   557             {
       
   558                 //OGLPaints_ResetPaint(oglc);
       
   559             }
       
   560             break;
       
   561         case sun_java2d_pipe_BufferedOpCodes_SET_COLOR:
       
   562             {
       
   563                 fprintf(stdout, "MetalRenderQueue_flushBuffer_SetColor\n");fflush(stdout);
       
   564                 jint color = NEXT_INT(b);       
       
   565                 MetalRenderer_SetColor(mtlc, color);
       
   566             }
       
   567             break;
       
   568         case sun_java2d_pipe_BufferedOpCodes_SET_GRADIENT_PAINT:
       
   569             {
       
   570                 jboolean useMask= NEXT_BOOLEAN(b);
       
   571                 jboolean cyclic = NEXT_BOOLEAN(b);
       
   572                 jdouble p0      = NEXT_DOUBLE(b);
       
   573                 jdouble p1      = NEXT_DOUBLE(b);
       
   574                 jdouble p3      = NEXT_DOUBLE(b);
       
   575                 jint pixel1     = NEXT_INT(b);
       
   576                 jint pixel2     = NEXT_INT(b);
       
   577                 /*OGLPaints_SetGradientPaint(oglc, useMask, cyclic,
       
   578                                            p0, p1, p3,
       
   579                                            pixel1, pixel2);*/
       
   580             }
       
   581             break;
       
   582         case sun_java2d_pipe_BufferedOpCodes_SET_LINEAR_GRADIENT_PAINT:
       
   583             {
       
   584                 jboolean useMask = NEXT_BOOLEAN(b);
       
   585                 jboolean linear  = NEXT_BOOLEAN(b);
       
   586                 jint cycleMethod = NEXT_INT(b);
       
   587                 jint numStops    = NEXT_INT(b);
       
   588                 jfloat p0        = NEXT_FLOAT(b);
       
   589                 jfloat p1        = NEXT_FLOAT(b);
       
   590                 jfloat p3        = NEXT_FLOAT(b);
       
   591                 void *fractions, *pixels;
       
   592                 fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
       
   593                 pixels    = b; SKIP_BYTES(b, numStops * sizeof(jint));
       
   594                 /*OGLPaints_SetLinearGradientPaint(oglc, dstOps,
       
   595                                                  useMask, linear,
       
   596                                                  cycleMethod, numStops,
       
   597                                                  p0, p1, p3,
       
   598                                                  fractions, pixels);*/
       
   599             }
       
   600             break;
       
   601         case sun_java2d_pipe_BufferedOpCodes_SET_RADIAL_GRADIENT_PAINT:
       
   602             {
       
   603                 jboolean useMask = NEXT_BOOLEAN(b);
       
   604                 jboolean linear  = NEXT_BOOLEAN(b);
       
   605                 jint numStops    = NEXT_INT(b);
       
   606                 jint cycleMethod = NEXT_INT(b);
       
   607                 jfloat m00       = NEXT_FLOAT(b);
       
   608                 jfloat m01       = NEXT_FLOAT(b);
       
   609                 jfloat m02       = NEXT_FLOAT(b);
       
   610                 jfloat m10       = NEXT_FLOAT(b);
       
   611                 jfloat m11       = NEXT_FLOAT(b);
       
   612                 jfloat m12       = NEXT_FLOAT(b);
       
   613                 jfloat focusX    = NEXT_FLOAT(b);
       
   614                 void *fractions, *pixels;
       
   615                 fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
       
   616                 pixels    = b; SKIP_BYTES(b, numStops * sizeof(jint));
       
   617                 /*OGLPaints_SetRadialGradientPaint(oglc, dstOps,
       
   618                                                  useMask, linear,
       
   619                                                  cycleMethod, numStops,
       
   620                                                  m00, m01, m02,
       
   621                                                  m10, m11, m12,
       
   622                                                  focusX,
       
   623                                                  fractions, pixels);*/
       
   624             }
       
   625             break;
       
   626         case sun_java2d_pipe_BufferedOpCodes_SET_TEXTURE_PAINT:
       
   627             {
       
   628                 jboolean useMask= NEXT_BOOLEAN(b);
       
   629                 jboolean filter = NEXT_BOOLEAN(b);
       
   630                 jlong pSrc      = NEXT_LONG(b);
       
   631                 jdouble xp0     = NEXT_DOUBLE(b);
       
   632                 jdouble xp1     = NEXT_DOUBLE(b);
       
   633                 jdouble xp3     = NEXT_DOUBLE(b);
       
   634                 jdouble yp0     = NEXT_DOUBLE(b);
       
   635                 jdouble yp1     = NEXT_DOUBLE(b);
       
   636                 jdouble yp3     = NEXT_DOUBLE(b);
       
   637                 /*OGLPaints_SetTexturePaint(oglc, useMask, pSrc, filter,
       
   638                                           xp0, xp1, xp3,
       
   639                                           yp0, yp1, yp3);*/
       
   640             }
       
   641             break;
       
   642 
       
   643         // BufferedImageOp-related ops
       
   644         case sun_java2d_pipe_BufferedOpCodes_ENABLE_CONVOLVE_OP:
       
   645             {
       
   646                 jlong pSrc        = NEXT_LONG(b);
       
   647                 jboolean edgeZero = NEXT_BOOLEAN(b);
       
   648                 jint kernelWidth  = NEXT_INT(b);
       
   649                 jint kernelHeight = NEXT_INT(b);
       
   650                 /*OGLBufImgOps_EnableConvolveOp(oglc, pSrc, edgeZero,
       
   651                                               kernelWidth, kernelHeight, b);*/
       
   652                 SKIP_BYTES(b, kernelWidth * kernelHeight * sizeof(jfloat));
       
   653             }
       
   654             break;
       
   655         case sun_java2d_pipe_BufferedOpCodes_DISABLE_CONVOLVE_OP:
       
   656             {
       
   657                 //OGLBufImgOps_DisableConvolveOp(oglc);
       
   658             }
       
   659             break;
       
   660         case sun_java2d_pipe_BufferedOpCodes_ENABLE_RESCALE_OP:
       
   661             {
       
   662                 jlong pSrc          = NEXT_LONG(b);
       
   663                 jboolean nonPremult = NEXT_BOOLEAN(b);
       
   664                 jint numFactors     = 4;
       
   665                 unsigned char *scaleFactors = b;
       
   666                 unsigned char *offsets = (b + numFactors * sizeof(jfloat));
       
   667                 /*OGLBufImgOps_EnableRescaleOp(oglc, pSrc, nonPremult,
       
   668                                              scaleFactors, offsets);*/
       
   669                 SKIP_BYTES(b, numFactors * sizeof(jfloat) * 2);
       
   670             }
       
   671             break;
       
   672         case sun_java2d_pipe_BufferedOpCodes_DISABLE_RESCALE_OP:
       
   673             {
       
   674                 //OGLBufImgOps_DisableRescaleOp(oglc);
       
   675             }
       
   676             break;
       
   677         case sun_java2d_pipe_BufferedOpCodes_ENABLE_LOOKUP_OP:
       
   678             {
       
   679                 jlong pSrc          = NEXT_LONG(b);
       
   680                 jboolean nonPremult = NEXT_BOOLEAN(b);
       
   681                 jboolean shortData  = NEXT_BOOLEAN(b);
       
   682                 jint numBands       = NEXT_INT(b);
       
   683                 jint bandLength     = NEXT_INT(b);
       
   684                 jint offset         = NEXT_INT(b);
       
   685                 jint bytesPerElem = shortData ? sizeof(jshort):sizeof(jbyte);
       
   686                 void *tableValues = b;
       
   687                 /*OGLBufImgOps_EnableLookupOp(oglc, pSrc, nonPremult, shortData,
       
   688                                             numBands, bandLength, offset,
       
   689                                             tableValues);*/
       
   690                 SKIP_BYTES(b, numBands * bandLength * bytesPerElem);
       
   691             }
       
   692             break;
       
   693         case sun_java2d_pipe_BufferedOpCodes_DISABLE_LOOKUP_OP:
       
   694             {
       
   695                 //OGLBufImgOps_DisableLookupOp(oglc);
       
   696             }
       
   697             break;
       
   698 
       
   699         default:
       
   700             J2dRlsTraceLn1(J2D_TRACE_ERROR,
       
   701                 "OGLRenderQueue_flushBuffer: invalid opcode=%d", opcode);
       
   702             /*if (oglc != NULL) {
       
   703                 RESET_PREVIOUS_OP();
       
   704             }*/
       
   705             return 0;
       
   706         }
       
   707         // TODO : Below logic need to be refined more if any more opcodes
       
   708         // we need to consider
       
   709         /*if ((opcode != sun_java2d_pipe_BufferedOpCodes_DRAW_LINE) && 
       
   710             (opcode != sun_java2d_pipe_BufferedOpCodes_SET_COLOR) &&
       
   711             //(opcode != sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM) &&
       
   712             //(opcode != sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM) &&
       
   713             (opcode != sun_java2d_pipe_BufferedOpCodes_SET_SURFACES)) {
       
   714             // We should not read int as it can cause under/overflow if
       
   715             // coming data is not int
       
   716             //jint x = NEXT_INT(b);
       
   717             continue;
       
   718         }*/
       
   719 
       
   720         /*J2dTraceLn2(J2D_TRACE_VERBOSE,
       
   721                     "MetalRenderQueue_flushBuffer: opcode=%d, rem=%d",
       
   722                     opcode, (end-b));*/
       
   723 
       
   724         /*switch (opcode) {
       
   725 
       
   726         // draw ops
       
   727         case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
       
   728             {
       
   729                 //fprintf(stdout, "MetalRenderQueue_flushBuffer_DrawLine\n");fflush(stdout);
       
   730                 jint x1 = NEXT_INT(b);
       
   731                 jint y1 = NEXT_INT(b);
       
   732                 jint x2 = NEXT_INT(b);
       
   733                 jint y2 = NEXT_INT(b);
       
   734                 MetalRenderer_DrawLine(mtlc, x1, y1, x2, y2);
       
   735             }
       
   736             break;
       
   737 
       
   738         case sun_java2d_pipe_BufferedOpCodes_SET_COLOR:
       
   739             {
       
   740                 //fprintf(stdout, "MetalRenderQueue_flushBuffer_SetColor\n");fflush(stdout);
       
   741                 jint color = NEXT_INT(b);       
       
   742                 MetalRenderer_SetColor(mtlc, color);
       
   743             }
       
   744             break;
       
   745 
       
   746 
       
   747         case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
       
   748             {
       
   749                 jfloat x11 = NEXT_FLOAT(b);
       
   750                 jfloat y11 = NEXT_FLOAT(b);
       
   751                 jfloat dx21 = NEXT_FLOAT(b);
       
   752                 jfloat dy21 = NEXT_FLOAT(b);
       
   753                 jfloat dx12 = NEXT_FLOAT(b);
       
   754                 jfloat dy12 = NEXT_FLOAT(b);
       
   755                 jfloat lwr21 = NEXT_FLOAT(b);
       
   756                 jfloat lwr12 = NEXT_FLOAT(b);
       
   757                 MetalRenderer_DrawParallelogram(mtlc,
       
   758                                               x11, y11,
       
   759                                               dx21, dy21,
       
   760                                               dx12, dy12,
       
   761                                               lwr21, lwr12);
       
   762             }
       
   763             break;
       
   764 
       
   765         case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
       
   766             {
       
   767                 jfloat x11 = NEXT_FLOAT(b);
       
   768                 jfloat y11 = NEXT_FLOAT(b);
       
   769                 jfloat dx21 = NEXT_FLOAT(b);
       
   770                 jfloat dy21 = NEXT_FLOAT(b);
       
   771                 jfloat dx12 = NEXT_FLOAT(b);
       
   772                 jfloat dy12 = NEXT_FLOAT(b);
       
   773                 MetalRenderer_FillParallelogram(mtlc,
       
   774                                               x11, y11,
       
   775                                               dx21, dy21,
       
   776                                               dx12, dy12);
       
   777             }
       
   778             break;
       
   779 
       
   780         case sun_java2d_pipe_BufferedOpCodes_SET_SURFACES:
       
   781             {
       
   782                 //fprintf(stdout, "MetalRenderQueue_flushBuffer_SetSurfaces\n");fflush(stdout);
       
   783                 jlong pSrc = NEXT_LONG(b);
       
   784                 jlong pDst = NEXT_LONG(b);
       
   785                 if (oglc != NULL) {
       
   786                     RESET_PREVIOUS_OP();
       
   787                 }
       
   788                 oglc = OGLContext_SetSurfaces(env, pSrc, pDst);
       
   789                 dstOps = (MetalSDOps *)jlong_to_ptr(pDst);
       
   790             }
       
   791             break;
       
   792         
       
   793         default:
       
   794             J2dRlsTraceLn1(J2D_TRACE_ERROR,
       
   795                 "MetalRenderQueue_flushBuffer: invalid opcode=%d", opcode);
       
   796             if (oglc != NULL) {
       
   797                 RESET_PREVIOUS_OP();
       
   798             }
       
   799             return 0;
       
   800         }*/
       
   801     }
       
   802 
       
   803     // Render everything to offscreen surface data
       
   804     MetalRenderer_Flush();
       
   805 
       
   806     // Render to on-screen
       
   807     MetalRenderer_blitToScreenDrawable();
       
   808 
       
   809     return 1;
       
   810 }
       
   811 
       
   812 /**
       
   813  * Returns a pointer to the "current" context, as set by the last SET_SURFACES
       
   814  * or SET_SCRATCH_SURFACE operation.
       
   815  */
       
   816 /*MetalContext *
       
   817 MetalRenderQueue_GetCurrentContext()
       
   818 {
       
   819     return mtlc;
       
   820 }*/
       
   821 
       
   822 /**
       
   823  * Returns a pointer to the "current" destination surface, as set by the last
       
   824  * SET_SURFACES operation.
       
   825  */
       
   826 MetalSDOps*
       
   827 MetalRenderQueue_GetCurrentDestination()
       
   828 {
       
   829     return dstOps;
       
   830 }
       
   831 
       
   832 #endif /* !HEADLESS */