1 /*
   2  * Copyright (c) 2010, 2020, 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 #ifdef HEADLESS
  27     #error This file should not be included in headless library
  28 #endif
  29 
  30 #include "GraphicsPrimitiveMgr.h"
  31 #include "Region.h"
  32 #include "Trace.h"
  33 #include "X11SurfaceData.h"
  34 
  35 /*#include <xcb/xcb.h>*/
  36 #include <X11/extensions/Xrender.h>
  37 
  38 #ifndef RepeatNone  /* added in 0.10 */
  39 #define RepeatNone    0
  40 #define RepeatNormal  1
  41 #define RepeatPad     2
  42 #define RepeatReflect 3
  43 #endif
  44 
  45 
  46 #include <sys/uio.h>
  47 #include <dlfcn.h>
  48 #include <setjmp.h>
  49 
  50 jfieldID pictID;
  51 jfieldID xidID;
  52 jfieldID blitMaskPMID;
  53 jfieldID blitMaskPictID;
  54 
  55 JNIEXPORT void JNICALL
  56    Java_sun_java2d_xr_XRSurfaceData_initXRPicture(JNIEnv *env, jobject xsd,
  57                                                   jlong pXSData,
  58                                                   jint pictFormat)
  59 {
  60   X11SDOps *xsdo;
  61   XRenderPictFormat *fmt;
  62 
  63   J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initXRender");
  64 
  65   xsdo = (X11SDOps *) jlong_to_ptr(pXSData);
  66   if (xsdo == NULL) {
  67       return;
  68   }
  69 
  70   if (xsdo->xrPic == None) {
  71       XRenderPictureAttributes pict_attr;
  72       pict_attr.repeat = RepeatNone;
  73       fmt = XRenderFindStandardFormat(awt_display, pictFormat);
  74       xsdo->xrPic =
  75          XRenderCreatePicture(awt_display, xsdo->drawable, fmt,
  76                               CPRepeat, &pict_attr);
  77   }
  78 
  79   (*env)->SetIntField (env, xsd, pictID, xsdo->xrPic);
  80   (*env)->SetIntField (env, xsd, xidID, xsdo->drawable);
  81 }
  82 
  83 JNIEXPORT void JNICALL
  84 Java_sun_java2d_xr_XRSurfaceData_initIDs(JNIEnv *env, jclass xsd)
  85 {
  86   J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initIDs");
  87 
  88   pictID = (*env)->GetFieldID(env, xsd, "picture", "I");
  89   if (pictID == NULL) {
  90       return;
  91   }
  92   xidID = (*env)->GetFieldID(env, xsd, "xid", "I");
  93   if (xidID == NULL) {
  94       return;
  95   }
  96 
  97   XShared_initIDs(env, JNI_FALSE);
  98 }
  99 
 100 JNIEXPORT void JNICALL
 101 Java_sun_java2d_xr_XRSurfaceData_XRInitSurface(JNIEnv *env, jclass xsd,
 102                                                jint depth,
 103                                                jint width, jint height,
 104                                                jlong drawable, jint pictFormat)
 105 {
 106     X11SDOps *xsdo;
 107 
 108     J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initSurface");
 109 
 110     xsdo = X11SurfaceData_GetOps(env, xsd);
 111     if (xsdo == NULL) {
 112         return;
 113     }
 114 
 115     XShared_initSurface(env, xsdo, depth, width, height, drawable);
 116 }
 117 
 118 JNIEXPORT void JNICALL
 119 Java_sun_java2d_xr_XRSurfaceData_freeXSDOPicture(JNIEnv *env, jobject xsd,
 120                                                   jlong pXSData)
 121 {
 122     X11SDOps *xsdo;
 123 
 124     J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_freeXSDOPicture");
 125 
 126     xsdo = X11SurfaceData_GetOps(env, xsd);
 127     if (xsdo == NULL) {
 128         return;
 129     }
 130 
 131     if(xsdo->xrPic != None) {
 132        XRenderFreePicture(awt_display, xsdo->xrPic);
 133        xsdo->xrPic = None;
 134     }
 135 }