jdk/src/windows/native/sun/java2d/windows/Win32SurfaceData.h
changeset 1024 2253d6d6cf2c
parent 1023 9a1c25552b10
parent 945 6838c1a3296a
child 1025 a9ba5ea0f1f7
equal deleted inserted replaced
1023:9a1c25552b10 1024:2253d6d6cf2c
     1 /*
       
     2  * Copyright 1999-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 _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 #include <ddraw.h>
       
    39 
       
    40 
       
    41 #define TEST_SURFACE_BITS(a,f) (((a)&(f)) == (f))
       
    42 
       
    43 /**
       
    44  * This include file contains support definitions for loops using the
       
    45  * SurfaceData interface to talk to a Win32 drawable from native code.
       
    46  */
       
    47 
       
    48 typedef struct _Win32SDOps Win32SDOps;
       
    49 
       
    50 /* These defined in ddrawObject.h */
       
    51 class DDraw;
       
    52 class DDrawSurface;
       
    53 class DDrawClipper;
       
    54 class DDrawDisplayMode;
       
    55 
       
    56 /*
       
    57  * Typedef for the structure which contains the ddObject reference, as
       
    58  * well as a refCount so that we know when we can delete the ddObject
       
    59  * and this structure.  We have to keep around the old ddObject even
       
    60  * after creating a new one because there may be multiple other surfaces
       
    61  * that still reference the old ddObject.  When all of those surfaces
       
    62  * have been recreated with the new ddObject, the old one can be
       
    63  * released.
       
    64  */
       
    65 typedef struct  {
       
    66     DDraw                   *ddObject;
       
    67     int                     refCount;
       
    68     DDrawSurface            *primary;
       
    69     DDrawSurface            *syncSurface;
       
    70     DDrawClipper            *clipper;
       
    71     CriticalSection         *primaryLock;
       
    72     BOOL                    valid;
       
    73     HMONITOR                hMonitor;
       
    74     BOOL                    capsSet;
       
    75     BOOL                    canBlt;
       
    76     HWND                    hwndFullScreen;
       
    77     int                     backBufferCount;
       
    78     int                     context;
       
    79     BOOL                    accelerated;
       
    80 } DDrawObjectStruct;
       
    81 
       
    82 #define CONTEXT_NORMAL 0
       
    83 #define CONTEXT_DISPLAY_CHANGE 1
       
    84 #define CONTEXT_ENTER_FULL_SCREEN 2
       
    85 #define CONTEXT_CHANGE_BUFFER_COUNT 3
       
    86 #define CONTEXT_EXIT_FULL_SCREEN 4
       
    87 
       
    88 /*
       
    89  * The definitions of the various attribute flags for requesting
       
    90  * which rendering objects should be selected into the HDC returned
       
    91  * from GetDC().
       
    92  */
       
    93 #define PEN             1
       
    94 #define NOPEN           2
       
    95 #define BRUSH           4
       
    96 #define NOBRUSH         8
       
    97 #define CLIP            16              /* For tracking purposes only */
       
    98 #define PENBRUSH        (PEN | BRUSH)
       
    99 #define PENONLY         (PEN | NOBRUSH)
       
   100 #define BRUSHONLY       (BRUSH | NOPEN)
       
   101 
       
   102 /*
       
   103  * This function retrieves an HDC for rendering to the destination
       
   104  * managed by the indicated Win32SDOps structure.
       
   105  *
       
   106  * The env parameter should be the JNIEnv of the surrounding JNI context.
       
   107  *
       
   108  * The ops parameter should be a pointer to the ops object upon which
       
   109  * this function is being invoked.
       
   110  *
       
   111  * The flags parameter should be an inclusive OR of any of the attribute
       
   112  * flags defined above.
       
   113  *
       
   114  * The patrop parameter should be a pointer to a jint that will receive
       
   115  * the appropriate ROP code (PATCOPY or PATINVERT) based on the current
       
   116  * composite, or NULL if the ROP code will be ignored by the caller.
       
   117  *
       
   118  * The clip parameter should be a pointer to a rectangle indicating the
       
   119  * desired clip.
       
   120  *
       
   121  * The comp parameter should be a pointer to a Composite object, or NULL
       
   122  * which means the Src (default) compositing rule will be used.
       
   123  *
       
   124  * The pixel parameter should be a 24-bit XRGB value indicating the
       
   125  * color that will be used for rendering.  The upper 8 bits are allowed
       
   126  * to be any value.
       
   127  *
       
   128  * The ReleaseDC function should be called to release the lock on the DC
       
   129  * after a given atomic set of rendering operations is complete.
       
   130  *
       
   131  * Note to callers:
       
   132  *      This function may use JNI methods so it is important that the
       
   133  *      caller not have any outstanding GetPrimitiveArrayCritical or
       
   134  *      GetStringCritical locks which have not been released.
       
   135  */
       
   136 typedef HDC GetDCFunc(JNIEnv *env,
       
   137                       Win32SDOps *wsdo,
       
   138                       jint flags,
       
   139                       jint *patrop,
       
   140                       jobject clip,
       
   141                       jobject comp,
       
   142                       jint color);
       
   143 
       
   144 /*
       
   145  * This function releases an HDC that was retrieved from the GetDC
       
   146  * function of the indicated Win32SDOps structure.
       
   147  *
       
   148  * The env parameter should be the JNIEnv of the surrounding JNI context.
       
   149  *
       
   150  * The ops parameter should be a pointer to the ops object upon which
       
   151  * this function is being invoked.
       
   152  *
       
   153  * The hdc parameter should be the handle to the HDC object that was
       
   154  * returned from the GetDC function.
       
   155  *
       
   156  * Note to callers:
       
   157  *      This function may use JNI methods so it is important that the
       
   158  *      caller not have any outstanding GetPrimitiveArrayCritical or
       
   159  *      GetStringCritical locks which have not been released.
       
   160  */
       
   161 typedef void ReleaseDCFunc(JNIEnv *env,
       
   162                            Win32SDOps *wsdo,
       
   163                            HDC hdc);
       
   164 
       
   165 
       
   166 typedef void InvalidateSDFunc(JNIEnv *env,
       
   167                               Win32SDOps *wsdo);
       
   168 
       
   169 typedef void RestoreSurfaceFunc(JNIEnv *env, Win32SDOps *wsdo);
       
   170 
       
   171 #define READS_PUNT_THRESHOLD 2
       
   172 #define BLTS_UNPUNT_THRESHOLD  4
       
   173 typedef struct {
       
   174     jboolean            disablePunts;
       
   175     jint                pixelsReadThreshold;
       
   176     jint                numBltsThreshold;
       
   177     jboolean            usingDDSystem;
       
   178     DDrawSurface        *lpSurfaceSystem;
       
   179     DDrawSurface        *lpSurfaceVram;
       
   180     jint                numBltsSinceRead;
       
   181     jint                pixelsReadSinceBlt;
       
   182 } SurfacePuntData;
       
   183 /*
       
   184  * A structure that holds all state global to the native surfaceData
       
   185  * object.
       
   186  *
       
   187  * Note:
       
   188  * This structure will be shared between different threads that
       
   189  * operate on the same surfaceData, so it should not contain any
       
   190  * variables that could be changed by one thread thus placing other
       
   191  * threads in a state of confusion.  For example, the hDC field was
       
   192  * removed because each thread now has its own shared DC.  But the
       
   193  * window field remains because once it is set for a given wsdo
       
   194  * structure it stays the same until that structure is destroyed.
       
   195  */
       
   196 struct _Win32SDOps {
       
   197     SurfaceDataOps      sdOps;
       
   198     jboolean            invalid;
       
   199     GetDCFunc           *GetDC;
       
   200     ReleaseDCFunc       *ReleaseDC;
       
   201     InvalidateSDFunc    *InvalidateSD;
       
   202     jint                lockType;       // REMIND: store in TLS
       
   203     jint                lockFlags;      // REMIND: store in TLS
       
   204     jobject             peer;
       
   205     HWND                window;
       
   206     RECT                insets;
       
   207     jint                depth;
       
   208     jint                pixelStride;    // Bytes per pixel
       
   209     DWORD               pixelMasks[3];  // RGB Masks for Windows DIB creation
       
   210     HBITMAP             bitmap;         // REMIND: store in TLS
       
   211     HBITMAP             oldmap;         // REMIND: store in TLS
       
   212     HDC                 bmdc;           // REMIND: store in TLS
       
   213     int                 bmScanStride;   // REMIND: store in TLS
       
   214     int                 bmWidth;        // REMIND: store in TLS
       
   215     int                 bmHeight;       // REMIND: store in TLS
       
   216     void                *bmBuffer;      // REMIND: store in TLS
       
   217     jboolean            bmCopyToScreen; // Used to track whether we
       
   218                                         // actually should copy the bitmap
       
   219                                         // to the screen
       
   220     AwtBrush            *brush;         // used for offscreen surfaces only
       
   221     jint                brushclr;
       
   222     AwtPen              *pen;           // used for offscreen surfaces only
       
   223     jint                penclr;
       
   224 
       
   225     int                 x, y, w, h;     // REMIND: store in TLS
       
   226     RestoreSurfaceFunc  *RestoreSurface;
       
   227     DDrawSurface        *lpSurface;
       
   228     int                 backBufferCount;
       
   229     DDrawObjectStruct   *ddInstance;
       
   230     CriticalSection     *surfaceLock;   // REMIND: try to remove
       
   231     jboolean            surfaceLost;
       
   232     jboolean            gdiOpPending;   // whether a GDI operation is pending for this
       
   233                                         // surface (Get/ReleaseDC were called)
       
   234     jint                transparency;
       
   235     AwtWin32GraphicsDevice *device;
       
   236     SurfacePuntData     surfacePuntData;
       
   237 };
       
   238 
       
   239 #define WIN32SD_LOCK_UNLOCKED   0       /* surface is not locked */
       
   240 #define WIN32SD_LOCK_BY_NULL    1       /* surface locked for NOP */
       
   241 #define WIN32SD_LOCK_BY_DDRAW   2       /* surface locked by DirectDraw */
       
   242 #define WIN32SD_LOCK_BY_DIB     3       /* surface locked by BitBlt */
       
   243 
       
   244 extern "C" {
       
   245 
       
   246 /*
       
   247  * Structure for holding the graphics state of a thread.
       
   248  */
       
   249 typedef struct {
       
   250     HDC         hDC;
       
   251     Win32SDOps  *wsdo;
       
   252     RECT        bounds;
       
   253     jobject     clip;
       
   254     jobject     comp;
       
   255     jint        xorcolor;
       
   256     jint        patrop;
       
   257     jint        type;
       
   258     AwtBrush    *brush;
       
   259     jint        brushclr;
       
   260     AwtPen      *pen;
       
   261     jint        penclr;
       
   262 } ThreadGraphicsInfo;
       
   263 
       
   264 
       
   265 /*
       
   266  * This function returns a pointer to a native Win32SDOps structure
       
   267  * for accessing the indicated Win32 SurfaceData Java object.  It
       
   268  * verifies that the indicated SurfaceData object is an instance
       
   269  * of Win32SurfaceData before returning and will return NULL if the
       
   270  * wrong SurfaceData object is being accessed.  This function will
       
   271  * throw the appropriate Java exception if it returns NULL so that
       
   272  * the caller can simply return.
       
   273  *
       
   274  * Note to callers:
       
   275  *      This function uses JNI methods so it is important that the
       
   276  *      caller not have any outstanding GetPrimitiveArrayCritical or
       
   277  *      GetStringCritical locks which have not been released.
       
   278  *
       
   279  *      The caller may continue to use JNI methods after this method
       
   280  *      is called since this function will not leave any outstanding
       
   281  *      JNI Critical locks unreleased.
       
   282  */
       
   283 JNIEXPORT Win32SDOps * JNICALL
       
   284 Win32SurfaceData_GetOps(JNIEnv *env, jobject sData);
       
   285 
       
   286 JNIEXPORT Win32SDOps * JNICALL
       
   287 Win32SurfaceData_GetOpsNoSetup(JNIEnv *env, jobject sData);
       
   288 
       
   289 JNIEXPORT HWND JNICALL
       
   290 Win32SurfaceData_GetWindow(JNIEnv *env, Win32SDOps *wsdo);
       
   291 
       
   292 JNIEXPORT void JNICALL
       
   293 Win32SD_InitDC(JNIEnv *env, Win32SDOps *wsdo, ThreadGraphicsInfo *info,
       
   294                jint type, jint *patrop,
       
   295                jobject clip, jobject comp, jint color);
       
   296 
       
   297 JNIEXPORT AwtComponent * JNICALL
       
   298 Win32SurfaceData_GetComp(JNIEnv *env, Win32SDOps *wsdo);
       
   299 
       
   300 } /* extern "C" */
       
   301 
       
   302 
       
   303 #endif _WIN32SURFACEDATA_H_