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