< prev index next >

src/java.desktop/unix/native/libawt_xawt/java2d/x11/XRBackendNative.c

Print this page
rev 59106 : imported patch client


  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 "X11SurfaceData.h"
  27 #include <jni.h>
  28 #include <math.h>
  29 #include "Region.h"
  30 #include "fontscalerdefs.h"
  31 
  32 #include <X11/extensions/Xrender.h>
  33 
  34 #ifdef __linux__
  35     #include <sys/utsname.h>
  36 #endif
  37 
  38 /* On Solaris 10 updates 8, 9, the render.h file defines these
  39  * protocol values but does not define the structs in Xrender.h.
  40  * Thus in order to get these always defined on Solaris 10
  41  * we will undefine the symbols if we have determined via the
  42  * makefiles that Xrender.h is lacking the structs. This will
  43  * trigger providing our own definitions as on earlier updates.
  44  * We could assume that *all* Solaris 10 update versions will lack the updated
  45  * Xrender.h and do this based solely on O/S being any 5.10 version, but this
  46  * could still change and we'd be broken again as we'd be re-defining them.
  47  */
  48 #ifdef SOLARIS10_NO_XRENDER_STRUCTS
  49 #undef X_RenderCreateLinearGradient
  50 #undef X_RenderCreateRadialGradient
  51 #endif
  52 
  53 #ifndef X_RenderCreateLinearGradient
  54 typedef struct _XLinearGradient {
  55     XPointFixed p1;
  56     XPointFixed p2;
  57 } XLinearGradient;
  58 #endif
  59 
  60 #ifndef X_RenderCreateRadialGradient
  61 typedef struct _XCircle {
  62     XFixed x;
  63     XFixed y;
  64     XFixed radius;
  65 } XCircle;
  66 
  67 typedef struct _XRadialGradient {
  68     XCircle inner;
  69     XCircle outer;
  70 } XRadialGradient;
  71 #endif
  72 
  73 #include <dlfcn.h>
  74 
  75 #if defined(__solaris__)
  76 /* Solaris 10 will not have these symbols at compile time */
  77 
  78 typedef Picture (*XRenderCreateLinearGradientFuncType)
  79                                      (Display *dpy,
  80                                      const XLinearGradient *gradient,
  81                                      const XFixed *stops,
  82                                      const XRenderColor *colors,
  83                                      int nstops);
  84 
  85 typedef Picture (*XRenderCreateRadialGradientFuncType)
  86                                      (Display *dpy,
  87                                      const XRadialGradient *gradient,
  88                                      const XFixed *stops,
  89                                      const XRenderColor *colors,
  90                                      int nstops);
  91 
  92 static
  93 XRenderCreateLinearGradientFuncType XRenderCreateLinearGradientFunc = NULL;
  94 static
  95  XRenderCreateRadialGradientFuncType XRenderCreateRadialGradientFunc = NULL;
  96 #endif
  97 
  98 #define BUILD_TRANSFORM_MATRIX(TRANSFORM, M00, M01, M02, M10, M11, M12)                        \
  99     {                                                                                          \
 100       TRANSFORM.matrix[0][0] = M00;                                                            \
 101       TRANSFORM.matrix[0][1] = M01;                                                            \
 102       TRANSFORM.matrix[0][2] = M02;                                                            \
 103       TRANSFORM.matrix[1][0] = M10;                                                            \
 104       TRANSFORM.matrix[1][1] = M11;                                                            \
 105       TRANSFORM.matrix[1][2] = M12;                                                            \
 106       TRANSFORM.matrix[2][0] = 0;                                                              \
 107       TRANSFORM.matrix[2][1] = 0;                                                              \
 108       TRANSFORM.matrix[2][2] = 1<<16;                                                          \
 109     }
 110 
 111 /* The xrender pipleine requires libXrender.so version 0.9.3 or later. */
 112 #define REQUIRED_XRENDER_VER1 0
 113 #define REQUIRED_XRENDER_VER2 9
 114 #define REQUIRED_XRENDER_VER3 3
 115 
 116 #define PKGINFO_LINE_LEN_MAX 256
 117 #define PKGINFO_LINE_CNT_MAX 50


 145     if (!XQueryExtension(awt_display, "RENDER",
 146                          &major_opcode, &first_event, &first_error)) {
 147         return JNI_FALSE;
 148     }
 149 
 150 #if defined(_AIX)
 151     // On AIX we have to use a special syntax because the shared libraries are packed in
 152     // multi-architecture archives. We first try to load the system default libXrender
 153     // which is contained in the 'X11.base.lib' fileset starting with AIX 6.1
 154     xrenderlib = dlopen("libXrender.a(shr_64.o)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER);
 155     if (xrenderlib == NULL) {
 156       // If the latter wasn't successful, we also try to load the version under /opt/freeware
 157       // This may be downloaded from the "AIX Toolbox for Linux Applications" even for AIX 5.3
 158       xrenderlib = dlopen("libXrender.a(libXrender.so.0)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER);
 159     }
 160     if (xrenderlib != NULL) {
 161       dlclose(xrenderlib);
 162     } else {
 163       available = JNI_FALSE;
 164     }
 165 #elif defined(__solaris__)
 166     xrenderlib = dlopen("libXrender.so",RTLD_GLOBAL|RTLD_LAZY);
 167     if (xrenderlib != NULL) {
 168 
 169       XRenderCreateLinearGradientFunc =
 170         (XRenderCreateLinearGradientFuncType)
 171         dlsym(xrenderlib, "XRenderCreateLinearGradient");
 172 
 173       XRenderCreateRadialGradientFunc =
 174         (XRenderCreateRadialGradientFuncType)
 175         dlsym(xrenderlib, "XRenderCreateRadialGradient");
 176 
 177       if (XRenderCreateLinearGradientFunc == NULL ||
 178           XRenderCreateRadialGradientFunc == NULL)
 179       {
 180         available = JNI_FALSE;
 181       }
 182       dlclose(xrenderlib);
 183     } else {
 184       available = JNI_FALSE;
 185     }
 186 #else
 187     Dl_info info;
 188     jboolean versionInfoIsFound = JNI_FALSE;
 189 
 190     memset(&info, 0, sizeof(Dl_info));
 191     if (dladdr(&XRenderChangePicture, &info) && info.dli_fname != NULL) {
 192       char pkgInfoPath[FILENAME_MAX];
 193       char *pkgFileName = "/pkgconfig/xrender.pc";
 194       size_t pkgFileNameLen = strlen(pkgFileName);
 195       size_t pos, len = strlen(info.dli_fname);
 196 
 197       pos = len;
 198       while (pos > 0 && info.dli_fname[pos] != '/') {
 199         pos -= 1;
 200       }
 201 
 202       if (pos > 0 && pos < (FILENAME_MAX - pkgFileNameLen - 1)) {
 203         struct stat stat_info;
 204 
 205         // compose absolute filename to package config


 576 
 577     if (colors == NULL || stops == NULL) {
 578         if (colors != NULL) {
 579             free(colors);
 580         }
 581         if (stops != NULL) {
 582             free(stops);
 583         }
 584         (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 585         (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 586         return -1;
 587     }
 588 
 589     for (i=0; i < numStops; i++) {
 590       stops[i] = XDoubleToFixed(fractions[i]);
 591       colors[i].alpha = pixels[i*4 + 0];
 592       colors[i].red = pixels[i*4 + 1];
 593       colors[i].green = pixels[i*4 + 2];
 594       colors[i].blue = pixels[i*4 + 3];
 595     }
 596 #ifdef __solaris__
 597     if (XRenderCreateLinearGradientFunc!=NULL) {
 598       gradient = (*XRenderCreateLinearGradientFunc)(awt_display, &grad, stops, colors, numStops);
 599     }
 600 #else
 601     gradient = XRenderCreateLinearGradient(awt_display, &grad, stops, colors, numStops);
 602 #endif
 603     free(colors);
 604     free(stops);
 605 
 606    (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 607    (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 608 
 609     if (gradient != 0) {
 610         pict_attr.repeat = repeat;
 611         XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr);
 612     }
 613 
 614    return (jint) gradient;
 615 }
 616 
 617 
 618 JNIEXPORT jint JNICALL
 619 Java_sun_java2d_xr_XRBackendNative_XRCreateRadialGradientPaintNative
 620     (JNIEnv *env, jclass xsd, jfloatArray fractionsArray,
 621      jshortArray pixelsArray, jint numStops,
 622      jint centerX, jint centerY,


 660 
 661     if (colors == NULL || stops == NULL) {
 662         if (colors != NULL) {
 663             free(colors);
 664         }
 665         if (stops != NULL) {
 666             free(stops);
 667         }
 668         (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 669         (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 670         return -1;
 671     }
 672 
 673     for (i=0; i < numStops; i++) {
 674       stops[i] = XDoubleToFixed(fractions[i]);
 675       colors[i].alpha = pixels[i*4 + 0];
 676       colors[i].red = pixels[i*4 + 1];
 677       colors[i].green = pixels[i*4 + 2];
 678       colors[i].blue = pixels[i*4 + 3];
 679     }
 680 #ifdef __solaris__
 681     if (XRenderCreateRadialGradientFunc != NULL) {
 682         gradient = (jint) (*XRenderCreateRadialGradientFunc)(awt_display, &grad, stops, colors, numStops);
 683     }
 684 #else
 685     gradient = (jint) XRenderCreateRadialGradient(awt_display, &grad, stops, colors, numStops);
 686 #endif
 687     free(colors);
 688     free(stops);
 689 
 690    (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 691    (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 692 
 693 
 694     if (gradient != 0) {
 695         pict_attr.repeat = repeat;
 696         XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr);
 697     }
 698 
 699    return (jint) gradient;
 700 }
 701 
 702 JNIEXPORT void JNICALL
 703 Java_sun_java2d_xr_XRBackendNative_setFilter
 704  (JNIEnv *env, jobject this, jint picture, jint filter) {
 705 
 706   char * filterName = "fast";




  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 "X11SurfaceData.h"
  27 #include <jni.h>
  28 #include <math.h>
  29 #include "Region.h"
  30 #include "fontscalerdefs.h"
  31 
  32 #include <X11/extensions/Xrender.h>
  33 
  34 #ifdef __linux__
  35     #include <sys/utsname.h>
  36 #endif
  37 















  38 #ifndef X_RenderCreateLinearGradient
  39 typedef struct _XLinearGradient {
  40     XPointFixed p1;
  41     XPointFixed p2;
  42 } XLinearGradient;
  43 #endif
  44 
  45 #ifndef X_RenderCreateRadialGradient
  46 typedef struct _XCircle {
  47     XFixed x;
  48     XFixed y;
  49     XFixed radius;
  50 } XCircle;
  51 
  52 typedef struct _XRadialGradient {
  53     XCircle inner;
  54     XCircle outer;
  55 } XRadialGradient;
  56 #endif
  57 
  58 #include <dlfcn.h>
  59 























  60 #define BUILD_TRANSFORM_MATRIX(TRANSFORM, M00, M01, M02, M10, M11, M12)                        \
  61     {                                                                                          \
  62       TRANSFORM.matrix[0][0] = M00;                                                            \
  63       TRANSFORM.matrix[0][1] = M01;                                                            \
  64       TRANSFORM.matrix[0][2] = M02;                                                            \
  65       TRANSFORM.matrix[1][0] = M10;                                                            \
  66       TRANSFORM.matrix[1][1] = M11;                                                            \
  67       TRANSFORM.matrix[1][2] = M12;                                                            \
  68       TRANSFORM.matrix[2][0] = 0;                                                              \
  69       TRANSFORM.matrix[2][1] = 0;                                                              \
  70       TRANSFORM.matrix[2][2] = 1<<16;                                                          \
  71     }
  72 
  73 /* The xrender pipleine requires libXrender.so version 0.9.3 or later. */
  74 #define REQUIRED_XRENDER_VER1 0
  75 #define REQUIRED_XRENDER_VER2 9
  76 #define REQUIRED_XRENDER_VER3 3
  77 
  78 #define PKGINFO_LINE_LEN_MAX 256
  79 #define PKGINFO_LINE_CNT_MAX 50


 107     if (!XQueryExtension(awt_display, "RENDER",
 108                          &major_opcode, &first_event, &first_error)) {
 109         return JNI_FALSE;
 110     }
 111 
 112 #if defined(_AIX)
 113     // On AIX we have to use a special syntax because the shared libraries are packed in
 114     // multi-architecture archives. We first try to load the system default libXrender
 115     // which is contained in the 'X11.base.lib' fileset starting with AIX 6.1
 116     xrenderlib = dlopen("libXrender.a(shr_64.o)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER);
 117     if (xrenderlib == NULL) {
 118       // If the latter wasn't successful, we also try to load the version under /opt/freeware
 119       // This may be downloaded from the "AIX Toolbox for Linux Applications" even for AIX 5.3
 120       xrenderlib = dlopen("libXrender.a(libXrender.so.0)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER);
 121     }
 122     if (xrenderlib != NULL) {
 123       dlclose(xrenderlib);
 124     } else {
 125       available = JNI_FALSE;
 126     }





















 127 #else
 128     Dl_info info;
 129     jboolean versionInfoIsFound = JNI_FALSE;
 130 
 131     memset(&info, 0, sizeof(Dl_info));
 132     if (dladdr(&XRenderChangePicture, &info) && info.dli_fname != NULL) {
 133       char pkgInfoPath[FILENAME_MAX];
 134       char *pkgFileName = "/pkgconfig/xrender.pc";
 135       size_t pkgFileNameLen = strlen(pkgFileName);
 136       size_t pos, len = strlen(info.dli_fname);
 137 
 138       pos = len;
 139       while (pos > 0 && info.dli_fname[pos] != '/') {
 140         pos -= 1;
 141       }
 142 
 143       if (pos > 0 && pos < (FILENAME_MAX - pkgFileNameLen - 1)) {
 144         struct stat stat_info;
 145 
 146         // compose absolute filename to package config


 517 
 518     if (colors == NULL || stops == NULL) {
 519         if (colors != NULL) {
 520             free(colors);
 521         }
 522         if (stops != NULL) {
 523             free(stops);
 524         }
 525         (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 526         (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 527         return -1;
 528     }
 529 
 530     for (i=0; i < numStops; i++) {
 531       stops[i] = XDoubleToFixed(fractions[i]);
 532       colors[i].alpha = pixels[i*4 + 0];
 533       colors[i].red = pixels[i*4 + 1];
 534       colors[i].green = pixels[i*4 + 2];
 535       colors[i].blue = pixels[i*4 + 3];
 536     }





 537     gradient = XRenderCreateLinearGradient(awt_display, &grad, stops, colors, numStops);

 538     free(colors);
 539     free(stops);
 540 
 541    (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 542    (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 543 
 544     if (gradient != 0) {
 545         pict_attr.repeat = repeat;
 546         XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr);
 547     }
 548 
 549    return (jint) gradient;
 550 }
 551 
 552 
 553 JNIEXPORT jint JNICALL
 554 Java_sun_java2d_xr_XRBackendNative_XRCreateRadialGradientPaintNative
 555     (JNIEnv *env, jclass xsd, jfloatArray fractionsArray,
 556      jshortArray pixelsArray, jint numStops,
 557      jint centerX, jint centerY,


 595 
 596     if (colors == NULL || stops == NULL) {
 597         if (colors != NULL) {
 598             free(colors);
 599         }
 600         if (stops != NULL) {
 601             free(stops);
 602         }
 603         (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 604         (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 605         return -1;
 606     }
 607 
 608     for (i=0; i < numStops; i++) {
 609       stops[i] = XDoubleToFixed(fractions[i]);
 610       colors[i].alpha = pixels[i*4 + 0];
 611       colors[i].red = pixels[i*4 + 1];
 612       colors[i].green = pixels[i*4 + 2];
 613       colors[i].blue = pixels[i*4 + 3];
 614     }





 615     gradient = (jint) XRenderCreateRadialGradient(awt_display, &grad, stops, colors, numStops);

 616     free(colors);
 617     free(stops);
 618 
 619    (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT);
 620    (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT);
 621 
 622 
 623     if (gradient != 0) {
 624         pict_attr.repeat = repeat;
 625         XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr);
 626     }
 627 
 628    return (jint) gradient;
 629 }
 630 
 631 JNIEXPORT void JNICALL
 632 Java_sun_java2d_xr_XRBackendNative_setFilter
 633  (JNIEnv *env, jobject this, jint picture, jint filter) {
 634 
 635   char * filterName = "fast";


< prev index next >