aboutsummaryrefslogtreecommitdiff
path: root/src/windows/native/sun/java2d/windows/Win32SurfaceData.h
blob: 425a5b48f5ae3d24b74333cb898869f5e7160687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

#ifndef _WIN32SURFACEDATA_H_
#define _WIN32SURFACEDATA_H_


#include "SurfaceData.h"

#include "colordata.h"
#include "awt_Brush.h"
#include "awt_Pen.h"
#include "awt_Win32GraphicsDevice.h"

#include "stdhdrs.h"
#include <ddraw.h>


#define TEST_SURFACE_BITS(a,f) (((a)&(f)) == (f))

/**
 * This include file contains support definitions for loops using the
 * SurfaceData interface to talk to a Win32 drawable from native code.
 */

typedef struct _Win32SDOps Win32SDOps;

/* These defined in ddrawObject.h */
class DDraw;
class DDrawSurface;
class DDrawClipper;
class DDrawDisplayMode;

/*
 * Typedef for the structure which contains the ddObject reference, as
 * well as a refCount so that we know when we can delete the ddObject
 * and this structure.  We have to keep around the old ddObject even
 * after creating a new one because there may be multiple other surfaces
 * that still reference the old ddObject.  When all of those surfaces
 * have been recreated with the new ddObject, the old one can be
 * released.
 */
typedef struct  {
    DDraw                   *ddObject;
    int                     refCount;
    DDrawSurface            *primary;
    DDrawSurface            *syncSurface;
    DDrawClipper            *clipper;
    CriticalSection         *primaryLock;
    BOOL                    valid;
    HMONITOR                hMonitor;
    BOOL                    capsSet;
    BOOL                    canBlt;
    HWND                    hwndFullScreen;
    int                     backBufferCount;
    int                     context;
    BOOL                    accelerated;
} DDrawObjectStruct;

#define CONTEXT_NORMAL 0
#define CONTEXT_DISPLAY_CHANGE 1
#define CONTEXT_ENTER_FULL_SCREEN 2
#define CONTEXT_CHANGE_BUFFER_COUNT 3
#define CONTEXT_EXIT_FULL_SCREEN 4

/*
 * The definitions of the various attribute flags for requesting
 * which rendering objects should be selected into the HDC returned
 * from GetDC().
 */
#define PEN             1
#define NOPEN           2
#define BRUSH           4
#define NOBRUSH         8
#define CLIP            16              /* For tracking purposes only */
#define PENBRUSH        (PEN | BRUSH)
#define PENONLY         (PEN | NOBRUSH)
#define BRUSHONLY       (BRUSH | NOPEN)

/*
 * This function retrieves an HDC for rendering to the destination
 * managed by the indicated Win32SDOps structure.
 *
 * The env parameter should be the JNIEnv of the surrounding JNI context.
 *
 * The ops parameter should be a pointer to the ops object upon which
 * this function is being invoked.
 *
 * The flags parameter should be an inclusive OR of any of the attribute
 * flags defined above.
 *
 * The patrop parameter should be a pointer to a jint that will receive
 * the appropriate ROP code (PATCOPY or PATINVERT) based on the current
 * composite, or NULL if the ROP code will be ignored by the caller.
 *
 * The clip parameter should be a pointer to a rectangle indicating the
 * desired clip.
 *
 * The comp parameter should be a pointer to a Composite object, or NULL
 * which means the Src (default) compositing rule will be used.
 *
 * The pixel parameter should be a 24-bit XRGB value indicating the
 * color that will be used for rendering.  The upper 8 bits are allowed
 * to be any value.
 *
 * The ReleaseDC function should be called to release the lock on the DC
 * after a given atomic set of rendering operations is complete.
 *
 * Note to callers:
 *      This function may use JNI methods so it is important that the
 *      caller not have any outstanding GetPrimitiveArrayCritical or
 *      GetStringCritical locks which have not been released.
 */
typedef HDC GetDCFunc(JNIEnv *env,
                      Win32SDOps *wsdo,
                      jint flags,
                      jint *patrop,
                      jobject clip,
                      jobject comp,
                      jint color);

/*
 * This function releases an HDC that was retrieved from the GetDC
 * function of the indicated Win32SDOps structure.
 *
 * The env parameter should be the JNIEnv of the surrounding JNI context.
 *
 * The ops parameter should be a pointer to the ops object upon which
 * this function is being invoked.
 *
 * The hdc parameter should be the handle to the HDC object that was
 * returned from the GetDC function.
 *
 * Note to callers:
 *      This function may use JNI methods so it is important that the
 *      caller not have any outstanding GetPrimitiveArrayCritical or
 *      GetStringCritical locks which have not been released.
 */
typedef void ReleaseDCFunc(JNIEnv *env,
                           Win32SDOps *wsdo,
                           HDC hdc);


typedef void InvalidateSDFunc(JNIEnv *env,
                              Win32SDOps *wsdo);

typedef void RestoreSurfaceFunc(JNIEnv *env, Win32SDOps *wsdo);

#define READS_PUNT_THRESHOLD 2
#define BLTS_UNPUNT_THRESHOLD  4
typedef struct {
    jboolean            disablePunts;
    jint                pixelsReadThreshold;
    jint                numBltsThreshold;
    jboolean            usingDDSystem;
    DDrawSurface        *lpSurfaceSystem;
    DDrawSurface        *lpSurfaceVram;
    jint                numBltsSinceRead;
    jint                pixelsReadSinceBlt;
} SurfacePuntData;
/*
 * A structure that holds all state global to the native surfaceData
 * object.
 *
 * Note:
 * This structure will be shared between different threads that
 * operate on the same surfaceData, so it should not contain any
 * variables that could be changed by one thread thus placing other
 * threads in a state of confusion.  For example, the hDC field was
 * removed because each thread now has its own shared DC.  But the
 * window field remains because once it is set for a given wsdo
 * structure it stays the same until that structure is destroyed.
 */
struct _Win32SDOps {
    SurfaceDataOps      sdOps;
    jboolean            invalid;
    GetDCFunc           *GetDC;
    ReleaseDCFunc       *ReleaseDC;
    InvalidateSDFunc    *InvalidateSD;
    jint                lockType;       // REMIND: store in TLS
    jint                lockFlags;      // REMIND: store in TLS
    jobject             peer;
    HWND                window;
    RECT                insets;
    jint                depth;
    jint                pixelStride;    // Bytes per pixel
    DWORD               pixelMasks[3];  // RGB Masks for Windows DIB creation
    HBITMAP             bitmap;         // REMIND: store in TLS
    HBITMAP             oldmap;         // REMIND: store in TLS
    HDC                 bmdc;           // REMIND: store in TLS
    int                 bmScanStride;   // REMIND: store in TLS
    int                 bmWidth;        // REMIND: store in TLS
    int                 bmHeight;       // REMIND: store in TLS
    void                *bmBuffer;      // REMIND: store in TLS
    jboolean            bmCopyToScreen; // Used to track whether we
                                        // actually should copy the bitmap
                                        // to the screen
    AwtBrush            *brush;         // used for offscreen surfaces only
    jint                brushclr;
    AwtPen              *pen;           // used for offscreen surfaces only
    jint                penclr;

    int                 x, y, w, h;     // REMIND: store in TLS
    RestoreSurfaceFunc  *RestoreSurface;
    DDrawSurface        *lpSurface;
    int                 backBufferCount;
    DDrawObjectStruct   *ddInstance;
    CriticalSection     *surfaceLock;   // REMIND: try to remove
    jboolean            surfaceLost;
    jboolean            gdiOpPending;   // whether a GDI operation is pending for this
                                        // surface (Get/ReleaseDC were called)
    jint                transparency;
    AwtWin32GraphicsDevice *device;
    SurfacePuntData     surfacePuntData;
};

#define WIN32SD_LOCK_UNLOCKED   0       /* surface is not locked */
#define WIN32SD_LOCK_BY_NULL    1       /* surface locked for NOP */
#define WIN32SD_LOCK_BY_DDRAW   2       /* surface locked by DirectDraw */
#define WIN32SD_LOCK_BY_DIB     3       /* surface locked by BitBlt */

extern "C" {

/*
 * Structure for holding the graphics state of a thread.
 */
typedef struct {
    HDC         hDC;
    Win32SDOps  *wsdo;
    RECT        bounds;
    jobject     clip;
    jobject     comp;
    jint        xorcolor;
    jint        patrop;
    jint        type;
    AwtBrush    *brush;
    jint        brushclr;
    AwtPen      *pen;
    jint        penclr;
} ThreadGraphicsInfo;


/*
 * This function returns a pointer to a native Win32SDOps structure
 * for accessing the indicated Win32 SurfaceData Java object.  It
 * verifies that the indicated SurfaceData object is an instance
 * of Win32SurfaceData before returning and will return NULL if the
 * wrong SurfaceData object is being accessed.  This function will
 * throw the appropriate Java exception if it returns NULL so that
 * the caller can simply return.
 *
 * Note to callers:
 *      This function uses JNI methods so it is important that the
 *      caller not have any outstanding GetPrimitiveArrayCritical or
 *      GetStringCritical locks which have not been released.
 *
 *      The caller may continue to use JNI methods after this method
 *      is called since this function will not leave any outstanding
 *      JNI Critical locks unreleased.
 */
JNIEXPORT Win32SDOps * JNICALL
Win32SurfaceData_GetOps(JNIEnv *env, jobject sData);

JNIEXPORT Win32SDOps * JNICALL
Win32SurfaceData_GetOpsNoSetup(JNIEnv *env, jobject sData);

JNIEXPORT HWND JNICALL
Win32SurfaceData_GetWindow(JNIEnv *env, Win32SDOps *wsdo);

JNIEXPORT void JNICALL
Win32SD_InitDC(JNIEnv *env, Win32SDOps *wsdo, ThreadGraphicsInfo *info,
               jint type, jint *patrop,
               jobject clip, jobject comp, jint color);

JNIEXPORT AwtComponent * JNICALL
Win32SurfaceData_GetComp(JNIEnv *env, Win32SDOps *wsdo);

} /* extern "C" */


#endif _WIN32SURFACEDATA_H_