1 /*
   2  * Copyright (c) 2000, 2005, 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 #include <X11/extensions/Xrender.h>
  34 
  35 /**
  36  * This include file contains support declarations for loops using the
  37  * X11 extended SurfaceData interface to talk to an X11 drawable from
  38  * native code.
  39  */
  40 
  41 #ifdef HEADLESS
  42 #define X11SDOps void
  43 #else /* HEADLESS */
  44 typedef struct _X11SDOps X11SDOps;
  45 
  46 /*
  47  * This function returns an X11 Drawable which transparent pixels
  48  * (if there are any) were set to the specified color.
  49  *
  50  * The env parameter should be the JNIEnv of the surrounding JNI context.
  51  *
  52  * The xsdo parameter should be a pointer to the ops object upon which
  53  * this function is being invoked.
  54  *
  55  * The pixel parameter should be a color to which the transparent
  56  * pixels of the image should be se set to.
  57  */
  58 typedef Drawable GetPixmapBgFunc(JNIEnv *env,
  59                                  X11SDOps *xsdo,
  60                                  jint pixel);
  61 
  62 /*
  63  * This function releases the lock set by GetPixmapBg
  64  * function of the indicated X11SDOps structure.
  65  *
  66  * The env parameter should be the JNIEnv of the surrounding JNI context.
  67  *
  68  * The ops parameter should be a pointer to the ops object upon which
  69  * this function is being invoked.
  70  */
  71 typedef void ReleasePixmapBgFunc(JNIEnv *env,
  72                                  X11SDOps *xsdo);
  73 
  74 
  75 #ifdef MITSHM
  76 typedef struct {
  77     XShmSegmentInfo     *shmSegInfo;    /* Shared Memory Segment Info */
  78     jint                bytesPerLine;   /* needed for ShMem lock */
  79     jboolean            xRequestSent;   /* true if x request is sent w/o XSync */
  80     jint                pmSize;
  81 
  82     jboolean            usingShmPixmap;
  83     Drawable            pixmap;
  84     Drawable            shmPixmap;
  85     jint                numBltsSinceRead;
  86     jint                pixelsReadSinceBlt;
  87     jint                pixelsReadThreshold;
  88     jint                numBltsThreshold;
  89 } ShmPixmapData;
  90 #endif /* MITSHM */
  91 
  92 struct _X11SDOps {
  93     SurfaceDataOps      sdOps;
  94     GetPixmapBgFunc     *GetPixmapWithBg;
  95     ReleasePixmapBgFunc *ReleasePixmapWithBg;
  96     jboolean            invalid;
  97     jboolean            isPixmap;
  98     jobject             peer;
  99     Drawable            drawable;
 100     Widget              widget;
 101     GC                  javaGC;        /* used for Java-level GC validation */
 102     GC                  cachedGC;      /* cached for use in X11SD_Unlock() */
 103     jint                depth;
 104     jint                pixelmask;
 105     JDgaSurfaceInfo     surfInfo;
 106     AwtGraphicsConfigData *configData;
 107     ColorData           *cData;
 108     jboolean            dgaAvailable;
 109     void                *dgaDev;
 110     Pixmap              bitmask;
 111     jint                bgPixel;       /* bg pixel for the pixmap */
 112     jboolean            isBgInitialized; /* whether the bg pixel is valid */
 113     jint                pmWidth;       /* width, height of the */
 114     jint                pmHeight;      /* pixmap */
 115     Picture             xrPic;
 116 #ifdef MITSHM
 117     ShmPixmapData       shmPMData;     /* data for switching between shm/nonshm pixmaps*/
 118 #endif /* MITSHM */
 119 };
 120 
 121 #define X11SD_LOCK_UNLOCKED     0       /* surface is not locked */
 122 #define X11SD_LOCK_BY_NULL      1       /* surface locked for NOP */
 123 #define X11SD_LOCK_BY_XIMAGE    2       /* surface locked by Get/PutImage */
 124 #define X11SD_LOCK_BY_DGA       3       /* surface locked by DGA */
 125 #define X11SD_LOCK_BY_SHMEM     4       /* surface locked by ShMemExt */
 126 
 127 #ifdef MITSHM
 128 XImage * X11SD_GetSharedImage       (X11SDOps *xsdo, jint width, jint height, jboolean readBits);
 129 XImage * X11SD_CreateSharedImage    (X11SDOps *xsdo, jint width, jint height);
 130 Drawable X11SD_CreateSharedPixmap   (X11SDOps *xsdo);
 131 void     X11SD_DropSharedSegment    (XShmSegmentInfo *shminfo);
 132 void     X11SD_PuntPixmap           (X11SDOps *xsdo, jint width, jint height);
 133 void     X11SD_UnPuntPixmap         (X11SDOps *xsdo);
 134 jboolean X11SD_CachedXImageFits     (jint width, jint height, jint depth, jboolean readBits);
 135 XImage * X11SD_GetCachedXImage      (jint width, jint height, jboolean readBits);
 136 #endif /* MITSHM */
 137 void     X11SD_DisposeOrCacheXImage (XImage * image);
 138 void     X11SD_DisposeXImage(XImage * image);
 139 void     X11SD_DirectRenderNotify(JNIEnv *env, X11SDOps *xsdo);
 140 #endif /* !HEADLESS */
 141 
 142 jboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps);
 143 jboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable);
 144 
 145 /*
 146  * This function returns a pointer to a native X11SDOps structure
 147  * for accessing the indicated X11 SurfaceData Java object.  It
 148  * verifies that the indicated SurfaceData object is an instance
 149  * of X11SurfaceData before returning and will return NULL if the
 150  * wrong SurfaceData object is being accessed.  This function will
 151  * throw the appropriate Java exception if it returns NULL so that
 152  * the caller can simply return.
 153  *
 154  * Note to callers:
 155  *      This function uses JNI methods so it is important that the
 156  *      caller not have any outstanding GetPrimitiveArrayCritical or
 157  *      GetStringCritical locks which have not been released.
 158  *
 159  *      The caller may continue to use JNI methods after this method
 160  *      is called since this function will not leave any outstanding
 161  *      JNI Critical locks unreleased.
 162  */
 163 JNIEXPORT X11SDOps * JNICALL
 164 X11SurfaceData_GetOps(JNIEnv *env, jobject sData);