1/* 2 * Copyright (c) 1999, 2015, 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 _WIN32SURFACEDATA_H_ 27#define _WIN32SURFACEDATA_H_ 28 29 30#include "SurfaceData.h" 31 32#include "colordata.h" 33#include "awt_Brush.h" 34#include "awt_Pen.h" 35#include "awt_Win32GraphicsDevice.h" 36 37#include "stdhdrs.h" 38 39 40#define TEST_SURFACE_BITS(a,f) (((a)&(f)) == (f)) 41 42/** 43 * This include file contains support definitions for loops using the 44 * SurfaceData interface to talk to a Win32 drawable from native code. 45 */ 46 47typedef struct _GDIWinSDOps GDIWinSDOps; 48 49#define CONTEXT_NORMAL 0 50#define CONTEXT_DISPLAY_CHANGE 1 51#define CONTEXT_ENTER_FULL_SCREEN 2 52#define CONTEXT_CHANGE_BUFFER_COUNT 3 53#define CONTEXT_EXIT_FULL_SCREEN 4 54 55/* 56 * The definitions of the various attribute flags for requesting 57 * which rendering objects should be selected into the HDC returned 58 * from GetDC(). 59 */ 60#define PEN 1 61#define NOPEN 2 62#define BRUSH 4 63#define NOBRUSH 8 64#define CLIP 16 /* For tracking purposes only */ 65#define PENBRUSH (PEN | BRUSH) 66#define PENONLY (PEN | NOBRUSH) 67#define BRUSHONLY (BRUSH | NOPEN) 68 69/* 70 * This function retrieves an HDC for rendering to the destination 71 * managed by the indicated GDIWinSDOps structure. 72 * 73 * The env parameter should be the JNIEnv of the surrounding JNI context. 74 * 75 * The ops parameter should be a pointer to the ops object upon which 76 * this function is being invoked. 77 * 78 * The flags parameter should be an inclusive OR of any of the attribute 79 * flags defined above. 80 * 81 * The patrop parameter should be a pointer to a jint that will receive 82 * the appropriate ROP code (PATCOPY or PATINVERT) based on the current 83 * composite, or NULL if the ROP code will be ignored by the caller. 84 * 85 * The clip parameter should be a pointer to a rectangle indicating the 86 * desired clip. 87 * 88 * The comp parameter should be a pointer to a Composite object, or NULL 89 * which means the Src (default) compositing rule will be used. 90 * 91 * The pixel parameter should be a 24-bit XRGB value indicating the 92 * color that will be used for rendering. The upper 8 bits are allowed 93 * to be any value. 94 * 95 * The ReleaseDC function should be called to release the lock on the DC 96 * after a given atomic set of rendering operations is complete. 97 * 98 * Note to callers: 99 * This function may use JNI methods so it is important that the 100 * caller not have any outstanding GetPrimitiveArrayCritical or 101 * GetStringCritical locks which have not been released. 102 */ 103typedef HDC GetDCFunc(JNIEnv *env, 104 GDIWinSDOps *wsdo, 105 jint flags, 106 jint *patrop, 107 jobject clip, 108 jobject comp, 109 jint color); 110 111/* 112 * This function releases an HDC that was retrieved from the GetDC 113 * function of the indicated GDIWinSDOps structure. 114 * 115 * The env parameter should be the JNIEnv of the surrounding JNI context. 116 * 117 * The ops parameter should be a pointer to the ops object upon which 118 * this function is being invoked. 119 * 120 * The hdc parameter should be the handle to the HDC object that was 121 * returned from the GetDC function. 122 * 123 * Note to callers: 124 * This function may use JNI methods so it is important that the 125 * caller not have any outstanding GetPrimitiveArrayCritical or 126 * GetStringCritical locks which have not been released. 127 */ 128typedef void ReleaseDCFunc(JNIEnv *env, 129 GDIWinSDOps *wsdo, 130 HDC hdc); 131 132 133typedef void InvalidateSDFunc(JNIEnv *env, 134 GDIWinSDOps *wsdo); 135 136/* 137 * A structure that holds all state global to the native surfaceData 138 * object. 139 * 140 * Note: 141 * This structure will be shared between different threads that 142 * operate on the same surfaceData, so it should not contain any 143 * variables that could be changed by one thread thus placing other 144 * threads in a state of confusion. For example, the hDC field was 145 * removed because each thread now has its own shared DC. But the 146 * window field remains because once it is set for a given wsdo 147 * structure it stays the same until that structure is destroyed. 148 */ 149struct _GDIWinSDOps { 150 SurfaceDataOps sdOps; 151 LONG timeStamp; // creation time stamp. 152 // Doesn't store a real time - 153 // just counts creation events of this structure 154 // made by GDIWindowSurfaceData_initOps() 155 // see bug# 6859086 156 jboolean invalid; 157 GetDCFunc *GetDC; 158 ReleaseDCFunc *ReleaseDC; 159 InvalidateSDFunc *InvalidateSD; 160 jint lockType; // REMIND: store in TLS 161 jint lockFlags; // REMIND: store in TLS 162 jobject peer; 163 HWND window; 164 RECT insets; 165 jint depth; 166 jint pixelStride; // Bytes per pixel 167 DWORD pixelMasks[3]; // RGB Masks for Windows DIB creation 168 HBITMAP bitmap; // REMIND: store in TLS 169 HBITMAP oldmap; // REMIND: store in TLS 170 HDC bmdc; // REMIND: store in TLS 171 int bmScanStride; // REMIND: store in TLS 172 int bmWidth; // REMIND: store in TLS 173 int bmHeight; // REMIND: store in TLS 174 void *bmBuffer; // REMIND: store in TLS 175 jboolean bmCopyToScreen; // Used to track whether we 176 // actually should copy the bitmap 177 // to the screen 178 AwtBrush *brush; // used for offscreen surfaces only 179 jint brushclr; 180 AwtPen *pen; // used for offscreen surfaces only 181 jint penclr; 182 183 int x, y, w, h; // REMIND: store in TLS 184 CriticalSection *surfaceLock; // REMIND: try to remove 185 AwtWin32GraphicsDevice *device; 186}; 187 188#define WIN32SD_LOCK_UNLOCKED 0 /* surface is not locked */ 189#define WIN32SD_LOCK_BY_NULL 1 /* surface locked for NOP */ 190#define WIN32SD_LOCK_BY_DIB 2 /* surface locked by BitBlt */ 191 192extern "C" { 193 194/* 195 * Structure for holding the graphics state of a thread. 196 */ 197typedef struct { 198 HDC hDC; 199 HWND hWnd; 200 GDIWinSDOps *wsdo; 201 LONG wsdoTimeStamp; // wsdo creation time stamp. 202 // Other threads may deallocate wsdo 203 // and then allocate a new GDIWinSDOps 204 // structure at the same memory location. 205 // Time stamp is the only way to detect if 206 // wsdo got changed. 207 // see bug# 6859086 208 RECT bounds; 209 jobject clip; 210 jobject comp; 211 jint xorcolor; 212 jint patrop; 213 jint type; 214 AwtBrush *brush; 215 jint brushclr; 216 AwtPen *pen; 217 jint penclr; 218} ThreadGraphicsInfo; 219 220 221/* 222 * This function returns a pointer to a native GDIWinSDOps structure 223 * for accessing the indicated Win32 SurfaceData Java object. It 224 * verifies that the indicated SurfaceData object is an instance 225 * of GDIWindowSurfaceData before returning and will return NULL if the 226 * wrong SurfaceData object is being accessed. This function will 227 * throw the appropriate Java exception if it returns NULL so that 228 * the caller can simply return. 229 * 230 * Note to callers: 231 * This function uses JNI methods so it is important that the 232 * caller not have any outstanding GetPrimitiveArrayCritical or 233 * GetStringCritical locks which have not been released. 234 * 235 * The caller may continue to use JNI methods after this method 236 * is called since this function will not leave any outstanding 237 * JNI Critical locks unreleased. 238 */ 239JNIEXPORT GDIWinSDOps * JNICALL 240GDIWindowSurfaceData_GetOps(JNIEnv *env, jobject sData); 241 242JNIEXPORT GDIWinSDOps * JNICALL 243GDIWindowSurfaceData_GetOpsNoSetup(JNIEnv *env, jobject sData); 244 245JNIEXPORT HWND JNICALL 246GDIWindowSurfaceData_GetWindow(JNIEnv *env, GDIWinSDOps *wsdo); 247 248JNIEXPORT void JNICALL 249GDIWinSD_InitDC(JNIEnv *env, GDIWinSDOps *wsdo, ThreadGraphicsInfo *info, 250 jint type, jint *patrop, 251 jobject clip, jobject comp, jint color); 252 253JNIEXPORT AwtComponent * JNICALL 254GDIWindowSurfaceData_GetComp(JNIEnv *env, GDIWinSDOps *wsdo); 255 256} /* extern "C" */ 257 258 259#endif _WIN32SURFACEDATA_H_ 260