1 /*
   2  * Copyright (c) 2000, 2011, 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 #include "SurfaceData.h"
  27 
  28 #include "awt_p.h"
  29 #include "awt_GraphicsEnv.h"
  30 
  31 #include <jdga.h>
  32 
  33 #ifdef HEADLESS
  34 #include "GLXGraphicsConfig.h"
  35 #endif
  36 
  37 #include <X11/extensions/Xrender.h>
  38 
  39 /**
  40  * This include file contains support declarations for loops using the
  41  * X11 extended SurfaceData interface to talk to an X11 drawable from
  42  * native code.
  43  */
  44 
  45 #ifdef HEADLESS
  46 #define X11SDOps void
  47 #else /* HEADLESS */
  48 typedef struct _X11SDOps X11SDOps;
  49 
  50 /*
  51  * This function returns an X11 Drawable which transparent pixels
  52  * (if there are any) were set to the specified color.
  53  *
  54  * The env parameter should be the JNIEnv of the surrounding JNI context.
  55  *
  56  * The xsdo parameter should be a pointer to the ops object upon which
  57  * this function is being invoked.
  58  *
  59  * The pixel parameter should be a color to which the transparent
  60  * pixels of the image should be se set to.
  61  */
  62 typedef Drawable GetPixmapBgFunc(JNIEnv *env,
  63                                  X11SDOps *xsdo,
  64                                  jint pixel);
  65 
  66 /*
  67  * This function releases the lock set by GetPixmapBg
  68  * function of the indicated X11SDOps structure.
  69  *
  70  * The env parameter should be the JNIEnv of the surrounding JNI context.
  71  *
  72  * The ops parameter should be a pointer to the ops object upon which
  73  * this function is being invoked.
  74  */
  75 typedef void ReleasePixmapBgFunc(JNIEnv *env,
  76                                  X11SDOps *xsdo);
  77 
  78 
  79 #ifdef MITSHM
  80 typedef struct {
  81     XShmSegmentInfo     *shmSegInfo;    /* Shared Memory Segment Info */
  82     jint                bytesPerLine;   /* needed for ShMem lock */
  83     jboolean            xRequestSent;   /* true if x request is sent w/o XSync */
  84     jint                pmSize;
  85 
  86     jboolean            usingShmPixmap;
  87     Drawable            pixmap;
  88     Drawable            shmPixmap;
  89     jint                numBltsSinceRead;
  90     jint                pixelsReadSinceBlt;
  91     jint                pixelsReadThreshold;
  92     jint                numBltsThreshold;
  93 } ShmPixmapData;
  94 #endif /* MITSHM */
  95 
  96 struct _X11SDOps {
  97     SurfaceDataOps      sdOps;
  98     GetPixmapBgFunc     *GetPixmapWithBg;
  99     ReleasePixmapBgFunc *ReleasePixmapWithBg;
 100     jboolean            invalid;
 101     jboolean            isPixmap;
 102     jobject             peer;
 103     Drawable            drawable;

 104     GC                  javaGC;        /* used for Java-level GC validation */
 105     GC                  cachedGC;      /* cached for use in X11SD_Unlock() */
 106     jint                depth;
 107     jint                pixelmask;
 108     JDgaSurfaceInfo     surfInfo;
 109     AwtGraphicsConfigData *configData;
 110     ColorData           *cData;
 111     jboolean            dgaAvailable;
 112     void                *dgaDev;
 113     Pixmap              bitmask;
 114     jint                bgPixel;       /* bg pixel for the pixmap */
 115     jboolean            isBgInitialized; /* whether the bg pixel is valid */
 116     jint                pmWidth;       /* width, height of the */
 117     jint                pmHeight;      /* pixmap */
 118     Picture             xrPic;
 119 #ifdef MITSHM
 120     ShmPixmapData       shmPMData;     /* data for switching between shm/nonshm pixmaps*/
 121 #endif /* MITSHM */
 122 };
 123 
 124 #define X11SD_LOCK_UNLOCKED     0       /* surface is not locked */
 125 #define X11SD_LOCK_BY_NULL      1       /* surface locked for NOP */
 126 #define X11SD_LOCK_BY_XIMAGE    2       /* surface locked by Get/PutImage */
 127 #define X11SD_LOCK_BY_DGA       3       /* surface locked by DGA */
 128 #define X11SD_LOCK_BY_SHMEM     4       /* surface locked by ShMemExt */
 129 
 130 #ifdef MITSHM
 131 XImage * X11SD_GetSharedImage       (X11SDOps *xsdo,
 132                                      jint width, jint height,
 133                                      jint maxWidth, jint maxHeight,
 134                                      jboolean readBits);
 135 XImage * X11SD_CreateSharedImage    (X11SDOps *xsdo, jint width, jint height);
 136 Drawable X11SD_CreateSharedPixmap   (X11SDOps *xsdo);
 137 void     X11SD_DropSharedSegment    (XShmSegmentInfo *shminfo);
 138 void     X11SD_PuntPixmap           (X11SDOps *xsdo, jint width, jint height);
 139 void     X11SD_UnPuntPixmap         (X11SDOps *xsdo);
 140 jboolean X11SD_CachedXImageFits     (jint width, jint height,
 141                                      jint maxWidth, jint maxHeight,
 142                                      jint depth, jboolean readBits);
 143 XImage * X11SD_GetCachedXImage      (jint width, jint height, jboolean readBits);
 144 #endif /* MITSHM */
 145 jint     X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo);
 146 void     X11SD_DisposeOrCacheXImage (XImage * image);
 147 void     X11SD_DisposeXImage(XImage * image);
 148 void     X11SD_DirectRenderNotify(JNIEnv *env, X11SDOps *xsdo);
 149 #endif /* !HEADLESS */
 150 
 151 jboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps);
 152 jboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable);
 153 
 154 /*
 155  * This function returns a pointer to a native X11SDOps structure
 156  * for accessing the indicated X11 SurfaceData Java object.  It
 157  * verifies that the indicated SurfaceData object is an instance
 158  * of X11SurfaceData before returning and will return NULL if the
 159  * wrong SurfaceData object is being accessed.  This function will
 160  * throw the appropriate Java exception if it returns NULL so that
 161  * the caller can simply return.
 162  *
 163  * Note to callers:
 164  *      This function uses JNI methods so it is important that the
 165  *      caller not have any outstanding GetPrimitiveArrayCritical or
 166  *      GetStringCritical locks which have not been released.
 167  *
 168  *      The caller may continue to use JNI methods after this method
 169  *      is called since this function will not leave any outstanding
 170  *      JNI Critical locks unreleased.
 171  */
 172 JNIEXPORT X11SDOps * JNICALL
 173 X11SurfaceData_GetOps(JNIEnv *env, jobject sData);
--- EOF ---