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 MTLRenderQueue_h_Included 27 #define MTLRenderQueue_h_Included 28 29 #include "MTLContext.h" 30 #include "MTLSurfaceData.h" 31 32 /* 33 * The following macros are used to pick values (of the specified type) off 34 * the queue. 35 */ 36 #define NEXT_VAL(buf, type) (((type *)((buf) += sizeof(type)))[-1]) 37 #define NEXT_BYTE(buf) NEXT_VAL(buf, unsigned char) 38 #define NEXT_INT(buf) NEXT_VAL(buf, jint) 39 #define NEXT_FLOAT(buf) NEXT_VAL(buf, jfloat) 40 #define NEXT_BOOLEAN(buf) (jboolean)NEXT_INT(buf) 41 #define NEXT_LONG(buf) NEXT_VAL(buf, jlong) 42 #define NEXT_DOUBLE(buf) NEXT_VAL(buf, jdouble) 43 44 /* 45 * Increments a pointer (buf) by the given number of bytes. 46 */ 47 #define SKIP_BYTES(buf, numbytes) buf += (numbytes) 48 49 /* 50 * Extracts a value at the given offset from the provided packed value. 51 */ 52 #define EXTRACT_VAL(packedval, offset, mask) \ 53 (((packedval) >> (offset)) & (mask)) 54 #define EXTRACT_BYTE(packedval, offset) \ 55 (unsigned char)EXTRACT_VAL(packedval, offset, 0xff) 56 #define EXTRACT_BOOLEAN(packedval, offset) \ 57 (jboolean)EXTRACT_VAL(packedval, offset, 0x1) 58 59 /* 60 * Parameter used by the RESET_PREVIOUS_OP() convenience macro, which 61 * indicates that any "open" state (such as an unmatched glBegin() or 62 * glEnable(GL_TEXTURE_2D)) should be completed before the following operation 63 * is performed. SET_SURFACES is an example of an operation that needs to 64 * call RESET_PREVIOUS_OP() before completing the surface change operation. 65 */ 66 #define MTL_STATE_RESET -1 67 68 /* 69 * Parameter passed to the CHECK_PREVIOUS_OP() macro to indicate that the 70 * following operation represents a "simple" state change. A simple state 71 * change is one that is allowed to occur within a series of texturing 72 * operations; in other words, this type of state change can occur without 73 * first calling glDisable(GL_TEXTURE_2D). An example of such an operation 74 * is SET_RECT_CLIP. 75 */ 76 #define MTL_STATE_CHANGE -2 77 78 /* 79 * Parameter passed to the CHECK_PREVIOUS_OP() macro to indicate that the 80 * following operation represents an operation that uses an alpha mask, 81 * such as MTLMaskFill and MTLTR_DrawGrayscaleGlyphNoCache(). 82 */ 83 #define MTL_STATE_MASK_OP -3 84 85 /* 86 * Parameter passed to the CHECK_PREVIOUS_OP() macro to indicate that the 87 * following operation represents an operation that uses the glyph cache, 88 * such as MTLTR_DrawGrayscaleGlyphViaCache(). 89 */ 90 #define MTL_STATE_GLYPH_OP -4 91 92 /* 93 * Parameter passed to the CHECK_PREVIOUS_OP() macro to indicate that the 94 * following operation represents an operation that renders a 95 * parallelogram via a fragment program (see MTLRenderer). 96 */ 97 #define MTL_STATE_PGRAM_OP -5 98 99 /* 100 * Initializes the "previous operation" state to its default value. 101 */ 102 #define INIT_PREVIOUS_OP() previousOp = MTL_STATE_RESET 103 104 /* 105 * These macros now simply delegate to the CheckPreviousOp() method. 106 */ 107 #define CHECK_PREVIOUS_OP(op) MTLRenderQueue_CheckPreviousOp(op) 108 #define RESET_PREVIOUS_OP() CHECK_PREVIOUS_OP(MTL_STATE_RESET) 109 110 /* 111 * The following macros allow the caller to return (or continue) if the 112 * provided value is NULL. (The strange else clause is included below to 113 * allow for a trailing ';' after RETURN/CONTINUE_IF_NULL() invocations.) 114 */ 115 #define ACT_IF_NULL(ACTION, value) \ 116 if ((value) == NULL) { \ 117 J2dTraceLn1(J2D_TRACE_ERROR, \ 118 "%s is null", #value); \ 119 ACTION; \ 120 } else do { } while (0) 121 #define RETURN_IF_NULL(value) ACT_IF_NULL(return, value) 122 #define CONTINUE_IF_NULL(value) ACT_IF_NULL(continue, value) 123 124 /* 125 * Exports. 126 */ 127 extern jint previousOp; 128 129 MTLContext *MTLRenderQueue_GetCurrentContext(); 130 BMTLSDOps *MTLRenderQueue_GetCurrentDestination(); 131 void MTLRenderQueue_CheckPreviousOp(jint op); 132 void MTLTR_DisableGlyphModeState(); 133 134 #endif /* MTLRenderQueue_h_Included */