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 MTLSurfaceDataBase_h_Included 27 #define MTLSurfaceDataBase_h_Included 28 29 #include "java_awt_image_AffineTransformOp.h" 30 #include "sun_java2d_metal_MTLSurfaceData.h" 31 #include "sun_java2d_pipe_hw_AccelSurface.h" 32 33 #include "SurfaceData.h" 34 #include "Trace.h" 35 #include "MTLFuncs.h" 36 37 38 /** 39 * The MTLPixelFormat structure contains all the information OpenGL needs to 40 * know when copying from or into a particular system memory image buffer (via 41 * glDrawPixels(), glReadPixels, glTexSubImage2D(), etc). 42 * 43 * GLenum format; 44 * The pixel format parameter used in glDrawPixels() and other similar calls. 45 * Indicates the component ordering for each pixel (e.g. GL_BGRA). 46 * 47 * GLenum type; 48 * The pixel data type parameter used in glDrawPixels() and other similar 49 * calls. Indicates the data type for an entire pixel or for each component 50 * in a pixel (e.g. GL_UNSIGNED_BYTE with GL_BGR means a pixel consists of 51 * 3 unsigned byte components, blue first, then green, then red; 52 * GL_UNSIGNED_INT_8_8_8_8_REV with GL_BGRA means a pixel consists of 1 53 * unsigned integer comprised of four byte components, alpha first, then red, 54 * then green, then blue). 55 * 56 * jint alignment; 57 * The byte alignment parameter used in glPixelStorei(GL_UNPACK_ALIGNMENT). A 58 * value of 4 indicates that each pixel starts on a 4-byte aligned region in 59 * memory, and so on. This alignment parameter helps OpenGL speed up pixel 60 * transfer operations by transferring memory in aligned blocks. 61 * 62 * jboolean hasAlpha; 63 * If true, indicates that this pixel format contains an alpha component. 64 * 65 * jboolean isPremult; 66 * If true, indicates that this pixel format contains color components that 67 * have been pre-multiplied by their corresponding alpha component. 68 */ 69 typedef struct { 70 //GLenum format; 71 //GLenum type; 72 jint format; 73 jint type; 74 jint alignment; 75 jboolean hasAlpha; 76 jboolean isPremult; 77 } MTPixelFormat; 78 79 /** 80 * The MTLSDOps structure describes a native OpenGL surface and contains all 81 * information pertaining to the native surface. Some information about 82 * the more important/different fields: 83 * 84 * void *privOps; 85 * Pointer to native-specific (GLX, WGL, etc.) SurfaceData info, such as the 86 * native Drawable handle and GraphicsConfig data. 87 * 88 * jint drawableType; 89 * The surface type; can be any one of the surface type constants defined 90 * below (MTLSD_WINDOW, MTLSD_TEXTURE, etc). 91 * 92 * GLenum activeBuffer; 93 * Can be either GL_FRONT if this is the front buffer surface of an onscreen 94 * window or a pbuffer surface, or GL_BACK if this is the backbuffer surface 95 * of an onscreen window. 96 * 97 * jboolean isOpaque; 98 * If true, the surface should be treated as being fully opaque. If 99 * the underlying surface (e.g. pbuffer) has an alpha channel and isOpaque 100 * is true, then we should take appropriate action (i.e. call glColorMask() 101 * to disable writes into the alpha channel) to ensure that the surface 102 * remains fully opaque. 103 * 104 * jboolean needsInit; 105 * If true, the surface requires some one-time initialization, which should 106 * be performed after a context has been made current to the surface for 107 * the first time. 108 * 109 * jint x/yOffset 110 * The offset in pixels of the OpenGL viewport origin from the lower-left 111 * corner of the heavyweight drawable. For example, a top-level frame on 112 * Windows XP has lower-left insets of (4,4). The OpenGL viewport origin 113 * would typically begin at the lower-left corner of the client region (inside 114 * the frame decorations), but AWT/Swing will take the insets into account 115 * when rendering into that window. So in order to account for this, we 116 * need to adjust the OpenGL viewport origin by an x/yOffset of (-4,-4). On 117 * X11, top-level frames typically don't have this insets issue, so their 118 * x/yOffset would be (0,0) (the same applies to pbuffers). 119 * 120 * jint width/height; 121 * The cached surface bounds. For offscreen surface types (MTLSD_FBOBJECT, 122 * MTLSD_TEXTURE, etc.) these values must remain constant. Onscreen window 123 * surfaces (MTLSD_WINDOW, MTLSD_FLIP_BACKBUFFER, etc.) may have their 124 * bounds changed in response to a programmatic or user-initiated event, so 125 * these values represent the last known dimensions. To determine the true 126 * current bounds of this surface, query the native Drawable through the 127 * privOps field. 128 * 129 * GLuint textureID; 130 * The texture object handle, as generated by glGenTextures(). If this value 131 * is zero, the texture has not yet been initialized. 132 * 133 * jint textureWidth/Height; 134 * The actual bounds of the texture object for this surface. If the 135 * GL_ARB_texture_non_power_of_two extension is not present, the dimensions 136 * of an OpenGL texture object must be a power-of-two (e.g. 64x32 or 128x512). 137 * The texture image that we care about has dimensions specified by the width 138 * and height fields in this MTLSDOps structure. For example, if the image 139 * to be stored in the texture has dimensions 115x47, the actual OpenGL 140 * texture we allocate will have dimensions 128x64 to meet the pow2 141 * restriction. The image bounds within the texture can be accessed using 142 * floating point texture coordinates in the range [0.0,1.0]. 143 * 144 * GLenum textureTarget; 145 * The texture target of the texture object for this surface. If this 146 * surface is not backed by a texture, this value is set to zero. Otherwise, 147 * this value is GL_TEXTURE_RECTANGLE_ARB when the GL_ARB_texture_rectangle 148 * extension is in use; if not, it is set to GL_TEXTURE_2D. 149 * 150 * GLint textureFilter; 151 * The current filter state for this texture object (can be either GL_NEAREST 152 * or GL_LINEAR). We cache this value here and check it before updating 153 * the filter state to avoid redundant calls to glTexParameteri() when the 154 * filter state remains constant (see the MTLSD_UPDATE_TEXTURE_FILTER() 155 * macro below). 156 * 157 * GLuint fbobjectID, depthID; 158 * The object handles for the framebuffer object and depth renderbuffer 159 * associated with this surface. These fields are only used when 160 * drawableType is MTLSD_FBOBJECT, otherwise they are zero. 161 */ 162 typedef struct { 163 SurfaceDataOps sdOps; 164 void *privOps; 165 jint drawableType; 166 jint activeBuffer; 167 jboolean isOpaque; 168 jboolean needsInit; 169 jint xOffset; 170 jint yOffset; 171 jint width; 172 jint height; 173 void* pTexture; 174 jint textureWidth; 175 jint textureHeight; 176 /* GLenum */ jint textureTarget; 177 /* GLint */ jint textureFilter; 178 /* GLuint */ jint fbobjectID; 179 /* GLuint */ jint depthID; 180 } BMTLSDOps; 181 182 #define MTLSD_UNDEFINED sun_java2d_pipe_hw_AccelSurface_UNDEFINED 183 #define MTLSD_WINDOW sun_java2d_pipe_hw_AccelSurface_WINDOW 184 #define MTLSD_TEXTURE sun_java2d_pipe_hw_AccelSurface_TEXTURE 185 #define MTLSD_FLIP_BACKBUFFER sun_java2d_pipe_hw_AccelSurface_FLIP_BACKBUFFER 186 #define MTLSD_RT_TEXTURE sun_java2d_pipe_hw_AccelSurface_RT_TEXTURE 187 188 /** 189 * These are shorthand names for the filtering method constants used by 190 * image transform methods. 191 */ 192 #define MTLSD_XFORM_DEFAULT 0 193 #define MTLSD_XFORM_NEAREST_NEIGHBOR \ 194 java_awt_image_AffineTransformOp_TYPE_NEAREST_NEIGHBOR 195 #define MTLSD_XFORM_BILINEAR \ 196 java_awt_image_AffineTransformOp_TYPE_BILINEAR 197 198 /** 199 * Exported methods. 200 */ 201 jint MTLSD_Lock(JNIEnv *env, 202 SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo, 203 jint lockflags); 204 void MTLSD_GetRasInfo(JNIEnv *env, 205 SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo); 206 void MTLSD_Unlock(JNIEnv *env, 207 SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo); 208 void MTLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops); 209 void MTLSD_Delete(JNIEnv *env, BMTLSDOps *mtlsdo); 210 jint MTLSD_NextPowerOfTwo(jint val, jint max); 211 212 #endif /* MTLSurfaceDataBase_h_Included */