blob: e70d740158c32396b6c53f622ca557a95f60799c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#ifndef OGLRenderQueue_h_Included
27#define OGLRenderQueue_h_Included
28
29#include "OGLContext.h"
30#include "OGLSurfaceData.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 OGL_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 OGL_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 OGLMaskFill and OGLTR_DrawGrayscaleGlyphNoCache().
82 */
83#define OGL_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 OGLTR_DrawGrayscaleGlyphViaCache().
89 */
90#define OGL_STATE_GLYPH_OP -4
91
92/*
93 * Initializes the "previous operation" state to its default value.
94 */
95#define INIT_PREVIOUS_OP() previousOp = OGL_STATE_RESET
96
97/*
98 * These macros now simply delegate to the CheckPreviousOp() method.
99 */
100#define CHECK_PREVIOUS_OP(op) OGLRenderQueue_CheckPreviousOp(op)
101#define RESET_PREVIOUS_OP() CHECK_PREVIOUS_OP(OGL_STATE_RESET)
102
103/*
104 * The following macros allow the caller to return (or continue) if the
105 * provided value is NULL. (The strange else clause is included below to
106 * allow for a trailing ';' after RETURN/CONTINUE_IF_NULL() invocations.)
107 */
108#define ACT_IF_NULL(ACTION, value) \
109 if ((value) == NULL) { \
110 J2dTraceLn1(J2D_TRACE_ERROR, \
111 "%s is null", #value); \
112 ACTION; \
113 } else do { } while (0)
114#define RETURN_IF_NULL(value) ACT_IF_NULL(return, value)
115#define CONTINUE_IF_NULL(value) ACT_IF_NULL(continue, value)
116
117/*
118 * Exports.
119 */
120extern jint previousOp;
121
122OGLContext *OGLRenderQueue_GetCurrentContext();
123OGLSDOps *OGLRenderQueue_GetCurrentDestination();
124void OGLRenderQueue_CheckPreviousOp(jint op);
125
126#endif /* OGLRenderQueue_h_Included */