6762511: Translucency is not working on Linux using Metacity
authoranthony
Tue, 05 May 2009 14:45:56 +0400
changeset 11962007e3d9c195
parent 1176 d5a1223e9618
child 1197 ba95c9101e50
6762511: Translucency is not working on Linux using Metacity
Summary: Introduced additional blits and new X11 surface types (ARGB, ABGR)
Reviewed-by: art, avu
src/solaris/classes/sun/awt/X11GraphicsConfig.java
src/solaris/classes/sun/java2d/x11/X11PMBlitBgLoops.java
src/solaris/classes/sun/java2d/x11/X11PMBlitLoops.java
src/solaris/classes/sun/java2d/x11/X11SurfaceData.java
src/solaris/native/sun/awt/X11Color.c
src/solaris/native/sun/awt/awt_GraphicsEnv.c
src/solaris/native/sun/awt/awt_p.h
     1.1 --- a/src/solaris/classes/sun/awt/X11GraphicsConfig.java	Wed Apr 29 00:27:46 2009 -0700
     1.2 +++ b/src/solaris/classes/sun/awt/X11GraphicsConfig.java	Tue May 05 14:45:56 2009 +0400
     1.3 @@ -37,7 +37,10 @@
     1.4  import java.awt.Transparency;
     1.5  import java.awt.image.BufferedImage;
     1.6  import java.awt.image.ColorModel;
     1.7 +import java.awt.color.ColorSpace;
     1.8 +import java.awt.image.ComponentColorModel;
     1.9  import java.awt.image.DirectColorModel;
    1.10 +import java.awt.image.DataBuffer;
    1.11  import java.awt.image.VolatileImage;
    1.12  import java.awt.image.WritableRaster;
    1.13  import java.awt.geom.AffineTransform;
    1.14 @@ -230,6 +233,22 @@
    1.15          }
    1.16      }
    1.17  
    1.18 +    public static DirectColorModel createDCM32(int rMask, int gMask, int bMask,
    1.19 +                                               int aMask, boolean aPre) {
    1.20 +        return new DirectColorModel(
    1.21 +            ColorSpace.getInstance(ColorSpace.CS_sRGB),
    1.22 +            32, rMask, gMask, bMask, aMask, aPre, DataBuffer.TYPE_INT);
    1.23 +    }
    1.24 +
    1.25 +    public static ComponentColorModel createABGRCCM() {
    1.26 +        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    1.27 +        int[] nBits = {8, 8, 8, 8};
    1.28 +        int[] bOffs = {3, 2, 1, 0};
    1.29 +        return new ComponentColorModel(cs, nBits, true, true,
    1.30 +                                       Transparency.TRANSLUCENT,
    1.31 +                                       DataBuffer.TYPE_BYTE);
    1.32 +    }
    1.33 +
    1.34      /**
    1.35       * Returns the default Transform for this configuration.  This
    1.36       * Transform is typically the Identity transform for most normal
     2.1 --- a/src/solaris/classes/sun/java2d/x11/X11PMBlitBgLoops.java	Wed Apr 29 00:27:46 2009 -0700
     2.2 +++ b/src/solaris/classes/sun/java2d/x11/X11PMBlitBgLoops.java	Tue May 05 14:45:56 2009 +0400
     2.3 @@ -70,6 +70,10 @@
     2.4                                   X11SurfaceData.UShort565RgbX11),
     2.5              new X11PMBlitBgLoops(X11SurfaceData.UShortIndexedX11_BM,
     2.6                                   X11SurfaceData.UShortIndexedX11),
     2.7 +            new X11PMBlitBgLoops(X11SurfaceData.IntRgbX11_BM,
     2.8 +                                 X11SurfaceData.IntArgbPreX11),
     2.9 +            new X11PMBlitBgLoops(X11SurfaceData.IntBgrX11_BM,
    2.10 +                                 X11SurfaceData.FourByteAbgrPreX11),
    2.11          };
    2.12          GraphicsPrimitiveMgr.register(primitives);
    2.13      }
     3.1 --- a/src/solaris/classes/sun/java2d/x11/X11PMBlitLoops.java	Wed Apr 29 00:27:46 2009 -0700
     3.2 +++ b/src/solaris/classes/sun/java2d/x11/X11PMBlitLoops.java	Tue May 05 14:45:56 2009 +0400
     3.3 @@ -95,6 +95,22 @@
     3.4              new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11_BM,
     3.5                                 X11SurfaceData.UShortIndexedX11, true),
     3.6  
     3.7 +            new X11PMBlitLoops(X11SurfaceData.IntRgbX11,
     3.8 +                               X11SurfaceData.IntArgbPreX11, true),
     3.9 +            new X11PMBlitLoops(X11SurfaceData.IntRgbX11,
    3.10 +                               X11SurfaceData.IntArgbPreX11, false),
    3.11 +            new X11PMBlitLoops(X11SurfaceData.IntRgbX11_BM,
    3.12 +                               X11SurfaceData.IntArgbPreX11, true),
    3.13 +
    3.14 +            new X11PMBlitLoops(X11SurfaceData.IntBgrX11,
    3.15 +                               X11SurfaceData.FourByteAbgrPreX11, true),
    3.16 +            new X11PMBlitLoops(X11SurfaceData.IntBgrX11,
    3.17 +                               X11SurfaceData.FourByteAbgrPreX11, false),
    3.18 +            new X11PMBlitLoops(X11SurfaceData.IntBgrX11_BM,
    3.19 +                               X11SurfaceData.FourByteAbgrPreX11, true),
    3.20 +
    3.21 +
    3.22 +
    3.23              // delegate loops
    3.24              new DelegateBlitLoop(X11SurfaceData.IntBgrX11_BM,
    3.25                                   X11SurfaceData.IntBgrX11),
     4.1 --- a/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Wed Apr 29 00:27:46 2009 -0700
     4.2 +++ b/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java	Tue May 05 14:45:56 2009 +0400
     4.3 @@ -81,6 +81,13 @@
     4.4          DESC_INT_BGR_X11        = "Integer BGR Pixmap";
     4.5      public static final String
     4.6          DESC_INT_RGB_X11        = "Integer RGB Pixmap";
     4.7 +
     4.8 +    public static final String
     4.9 +        DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
    4.10 +    public static final String
    4.11 +        DESC_INT_ARGB_PRE_X11   = "Integer ARGB Pixmap with pre-multiplied " +
    4.12 +                                  "alpha";
    4.13 +
    4.14      public static final String
    4.15          DESC_BYTE_IND_OPQ_X11   = "Byte Indexed Opaque Pixmap";
    4.16  
    4.17 @@ -133,6 +140,11 @@
    4.18      public static final SurfaceType IntRgbX11 =
    4.19          SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_X11);
    4.20  
    4.21 +    public static final SurfaceType FourByteAbgrPreX11 =
    4.22 +        SurfaceType.FourByteAbgrPre.deriveSubType(DESC_4BYTE_ABGR_PRE_X11);
    4.23 +    public static final SurfaceType IntArgbPreX11 =
    4.24 +        SurfaceType.IntArgbPre.deriveSubType(DESC_INT_ARGB_PRE_X11);
    4.25 +
    4.26      public static final SurfaceType ThreeByteRgbX11 =
    4.27          SurfaceType.ThreeByteRgb.deriveSubType(DESC_3BYTE_RGB_X11);
    4.28      public static final SurfaceType ThreeByteBgrX11 =
    4.29 @@ -413,7 +425,7 @@
    4.30                                                    int transparency)
    4.31      {
    4.32          return new X11PixmapSurfaceData(gc, width, height, image,
    4.33 -                                        getSurfaceType(gc, transparency),
    4.34 +                                        getSurfaceType(gc, transparency, true),
    4.35                                          cm, drawable, transparency);
    4.36      }
    4.37  
    4.38 @@ -498,6 +510,13 @@
    4.39      public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
    4.40                                               int transparency)
    4.41      {
    4.42 +        return getSurfaceType(gc, transparency, false);
    4.43 +    }
    4.44 +
    4.45 +    public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
    4.46 +                                             int transparency,
    4.47 +                                             boolean pixmapSurface)
    4.48 +    {
    4.49          boolean transparent = (transparency == Transparency.BITMASK);
    4.50          SurfaceType sType;
    4.51          ColorModel cm = gc.getColorModel();
    4.52 @@ -524,12 +543,23 @@
    4.53              // Fall through for 32 bit case
    4.54          case 32:
    4.55              if (cm instanceof DirectColorModel) {
    4.56 -                if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
    4.57 -                    sType = transparent ? X11SurfaceData.IntRgbX11_BM : X11SurfaceData.IntRgbX11;
    4.58 +                if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
    4.59 +                     ).isTranslucencyCapable(gc) && !pixmapSurface)
    4.60 +                {
    4.61 +                    sType = X11SurfaceData.IntArgbPreX11;
    4.62                  } else {
    4.63 -                    sType = transparent ? X11SurfaceData.IntBgrX11_BM : X11SurfaceData.IntBgrX11;
    4.64 +                    if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
    4.65 +                        sType = transparent ? X11SurfaceData.IntRgbX11_BM :
    4.66 +                                              X11SurfaceData.IntRgbX11;
    4.67 +                    } else {
    4.68 +                        sType = transparent ? X11SurfaceData.IntBgrX11_BM :
    4.69 +                                              X11SurfaceData.IntBgrX11;
    4.70 +                    }
    4.71                  }
    4.72 +            } else if (cm instanceof ComponentColorModel) {
    4.73 +                   sType = X11SurfaceData.FourByteAbgrPreX11;
    4.74              } else {
    4.75 +
    4.76                  throw new sun.java2d.InvalidPipeException("Unsupported bit " +
    4.77                                                            "depth/cm combo: " +
    4.78                                                            cm.getPixelSize()  +
     5.1 --- a/src/solaris/native/sun/awt/X11Color.c	Wed Apr 29 00:27:46 2009 -0700
     5.2 +++ b/src/solaris/native/sun/awt/X11Color.c	Tue May 05 14:45:56 2009 +0400
     5.3 @@ -886,6 +886,27 @@
     5.4  #define blue(v)         (((v) >>  0) & 0xFF)
     5.5  
     5.6  #ifndef HEADLESS
     5.7 +
     5.8 +jobject getColorSpace(JNIEnv* env, jint csID) {
     5.9 +    jclass clazz;
    5.10 +    jobject cspaceL;
    5.11 +    jmethodID mid;
    5.12 +
    5.13 +    clazz = (*env)->FindClass(env,"java/awt/color/ColorSpace");
    5.14 +    mid = (*env)->GetStaticMethodID(env, clazz, "getInstance",
    5.15 +                                    "(I)Ljava/awt/color/ColorSpace;");
    5.16 +    if (mid == NULL) {
    5.17 +        return NULL;
    5.18 +    }
    5.19 +
    5.20 +    /* SECURITY: This is safe, because static methods cannot
    5.21 +     *           be overridden, and this method does not invoke
    5.22 +     *           client code
    5.23 +     */
    5.24 +
    5.25 +    return (*env)->CallStaticObjectMethod(env, clazz, mid, csID);
    5.26 +}
    5.27 +
    5.28  jobject awtJNI_GetColorModel(JNIEnv *env, AwtGraphicsConfigDataPtr aData)
    5.29  {
    5.30      jobject awt_colormodel = NULL;
    5.31 @@ -899,21 +920,61 @@
    5.32          (aData->awt_depth >= 15))
    5.33      {
    5.34          clazz = (*env)->FindClass(env,"java/awt/image/DirectColorModel");
    5.35 +        if (!aData->isTranslucencySupported) {
    5.36  
    5.37 -        mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
    5.38 +            mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
    5.39  
    5.40 -        if (mid == NULL) {
    5.41 -            (*env)->PopLocalFrame(env, 0);
    5.42 -            return NULL;
    5.43 +            if (mid == NULL) {
    5.44 +                (*env)->PopLocalFrame(env, 0);
    5.45 +                return NULL;
    5.46 +            }
    5.47 +            awt_colormodel = (*env)->NewObject(env,clazz, mid,
    5.48 +                    aData->awt_visInfo.depth,
    5.49 +                    aData->awt_visInfo.red_mask,
    5.50 +                    aData->awt_visInfo.green_mask,
    5.51 +                    aData->awt_visInfo.blue_mask,
    5.52 +                    0);
    5.53 +        } else {
    5.54 +            clazz = (*env)->FindClass(env,"sun/awt/X11GraphicsConfig");
    5.55 +            if (clazz == NULL) {
    5.56 +                (*env)->PopLocalFrame(env, 0);
    5.57 +                return NULL;
    5.58 +            }
    5.59 +
    5.60 +            if (aData->renderPictFormat.direct.red == 16) {
    5.61 +                mid = (*env)->GetStaticMethodID( env,clazz,"createDCM32",
    5.62 +                        "(IIIIZ)Ljava/awt/image/DirectColorModel;");
    5.63 +
    5.64 +                if (mid == NULL) {
    5.65 +                    (*env)->PopLocalFrame(env, 0);
    5.66 +                    return NULL;
    5.67 +                }
    5.68 +
    5.69 +                awt_colormodel = (*env)->CallStaticObjectMethod(
    5.70 +                        env,clazz, mid,
    5.71 +                        aData->renderPictFormat.direct.redMask
    5.72 +                            << aData->renderPictFormat.direct.red,
    5.73 +                        aData->renderPictFormat.direct.greenMask
    5.74 +                            << aData->renderPictFormat.direct.green,
    5.75 +                        aData->renderPictFormat.direct.blueMask
    5.76 +                            << aData->renderPictFormat.direct.blue,
    5.77 +                        aData->renderPictFormat.direct.alphaMask
    5.78 +                            << aData->renderPictFormat.direct.alpha,
    5.79 +                        JNI_TRUE);
    5.80 +            } else {
    5.81 +                mid = (*env)->GetStaticMethodID( env,clazz,"createABGRCCM",
    5.82 +                        "()Ljava/awt/image/ComponentColorModel;");
    5.83 +
    5.84 +                if (mid == NULL) {
    5.85 +                    (*env)->PopLocalFrame(env, 0);
    5.86 +                    return NULL;
    5.87 +                }
    5.88 +
    5.89 +                awt_colormodel = (*env)->CallStaticObjectMethod(
    5.90 +                        env,clazz, mid);
    5.91 +            }
    5.92          }
    5.93  
    5.94 -        awt_colormodel = (*env)->NewObject(env,clazz, mid,
    5.95 -                                           aData->awt_visInfo.depth,
    5.96 -                                           aData->awt_visInfo.red_mask,
    5.97 -                                           aData->awt_visInfo.green_mask,
    5.98 -                                           aData->awt_visInfo.blue_mask,
    5.99 -                                           0);
   5.100 -
   5.101          if(awt_colormodel == NULL)
   5.102          {
   5.103              (*env)->PopLocalFrame(env, 0);
   5.104 @@ -923,25 +984,13 @@
   5.105      }
   5.106      else if (aData->awt_visInfo.class == StaticGray &&
   5.107               aData->awt_num_colors == 256) {
   5.108 -        jclass clazz1;
   5.109          jobject cspace = NULL;
   5.110          jint bits[1];
   5.111          jintArray bitsArray;
   5.112          jboolean falseboolean = JNI_FALSE;
   5.113  
   5.114 -        clazz1 = (*env)->FindClass(env,"java/awt/color/ColorSpace");
   5.115 -        mid = (*env)->GetStaticMethodID(env, clazz1, "getInstance",
   5.116 -              "(I)Ljava/awt/color/ColorSpace;");
   5.117 -        if (mid == NULL) {
   5.118 -            (*env)->PopLocalFrame(env, 0);
   5.119 -            return NULL;
   5.120 -        }
   5.121 -        /* SECURITY: This is safe, because static methods cannot
   5.122 -         *           be overridden, and this method does not invoke
   5.123 -         *           client code
   5.124 -         */
   5.125 -        cspace = (*env)->CallStaticObjectMethod(env, clazz1, mid,
   5.126 -            java_awt_color_ColorSpace_CS_GRAY);
   5.127 +        cspace = getColorSpace(env, java_awt_color_ColorSpace_CS_GRAY);
   5.128 +
   5.129          if (cspace == NULL) {
   5.130              (*env)->PopLocalFrame(env, 0);
   5.131              return NULL;
     6.1 --- a/src/solaris/native/sun/awt/awt_GraphicsEnv.c	Wed Apr 29 00:27:46 2009 -0700
     6.2 +++ b/src/solaris/native/sun/awt/awt_GraphicsEnv.c	Tue May 05 14:45:56 2009 +0400
     6.3 @@ -354,48 +354,6 @@
     6.4      return NULL;
     6.5  }
     6.6  
     6.7 -/* Note: until we include the <X11/extensions/Xrender.h> explicitly
     6.8 - * we have to define a couple of things ourselves.
     6.9 - */
    6.10 -typedef unsigned long   PictFormat;
    6.11 -#define PictTypeIndexed             0
    6.12 -#define PictTypeDirect              1
    6.13 -
    6.14 -typedef struct {
    6.15 -    short   red;
    6.16 -    short   redMask;
    6.17 -    short   green;
    6.18 -    short   greenMask;
    6.19 -    short   blue;
    6.20 -    short   blueMask;
    6.21 -    short   alpha;
    6.22 -    short   alphaMask;
    6.23 -} XRenderDirectFormat;
    6.24 -
    6.25 -typedef struct {
    6.26 -    PictFormat      id;
    6.27 -    int         type;
    6.28 -    int         depth;
    6.29 -    XRenderDirectFormat direct;
    6.30 -    Colormap        colormap;
    6.31 -} XRenderPictFormat;
    6.32 -
    6.33 -#define PictFormatID        (1 << 0)
    6.34 -#define PictFormatType      (1 << 1)
    6.35 -#define PictFormatDepth     (1 << 2)
    6.36 -#define PictFormatRed       (1 << 3)
    6.37 -#define PictFormatRedMask   (1 << 4)
    6.38 -#define PictFormatGreen     (1 << 5)
    6.39 -#define PictFormatGreenMask (1 << 6)
    6.40 -#define PictFormatBlue      (1 << 7)
    6.41 -#define PictFormatBlueMask  (1 << 8)
    6.42 -#define PictFormatAlpha     (1 << 9)
    6.43 -#define PictFormatAlphaMask (1 << 10)
    6.44 -#define PictFormatColormap  (1 << 11)
    6.45 -
    6.46 -typedef XRenderPictFormat *
    6.47 -XRenderFindVisualFormatFunc (Display *dpy, _Xconst Visual *visual);
    6.48 -
    6.49  static void
    6.50  getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) {
    6.51  
    6.52 @@ -535,6 +493,8 @@
    6.53                  format->direct.alphaMask)
    6.54              {
    6.55                  graphicsConfigs [ind]->isTranslucencySupported = 1;
    6.56 +                memcpy(&graphicsConfigs [ind]->renderPictFormat, format,
    6.57 +                        sizeof(*format));
    6.58              }
    6.59          }
    6.60      }
     7.1 --- a/src/solaris/native/sun/awt/awt_p.h	Wed Apr 29 00:27:46 2009 -0700
     7.2 +++ b/src/solaris/native/sun/awt/awt_p.h	Tue May 05 14:45:56 2009 +0400
     7.3 @@ -119,6 +119,50 @@
     7.4  } DamageRect;
     7.5  
     7.6  #ifndef HEADLESS
     7.7 +
     7.8 +/* Note: until we include the <X11/extensions/Xrender.h> explicitly
     7.9 + * we have to define a couple of things ourselves.
    7.10 + */
    7.11 +typedef unsigned long   PictFormat;
    7.12 +#define PictTypeIndexed             0
    7.13 +#define PictTypeDirect              1
    7.14 +
    7.15 +typedef struct {
    7.16 +    short   red;
    7.17 +    short   redMask;
    7.18 +    short   green;
    7.19 +    short   greenMask;
    7.20 +    short   blue;
    7.21 +    short   blueMask;
    7.22 +    short   alpha;
    7.23 +    short   alphaMask;
    7.24 +} XRenderDirectFormat;
    7.25 +
    7.26 +typedef struct {
    7.27 +    PictFormat      id;
    7.28 +    int         type;
    7.29 +    int         depth;
    7.30 +    XRenderDirectFormat direct;
    7.31 +    Colormap        colormap;
    7.32 +} XRenderPictFormat;
    7.33 +
    7.34 +#define PictFormatID        (1 << 0)
    7.35 +#define PictFormatType      (1 << 1)
    7.36 +#define PictFormatDepth     (1 << 2)
    7.37 +#define PictFormatRed       (1 << 3)
    7.38 +#define PictFormatRedMask   (1 << 4)
    7.39 +#define PictFormatGreen     (1 << 5)
    7.40 +#define PictFormatGreenMask (1 << 6)
    7.41 +#define PictFormatBlue      (1 << 7)
    7.42 +#define PictFormatBlueMask  (1 << 8)
    7.43 +#define PictFormatAlpha     (1 << 9)
    7.44 +#define PictFormatAlphaMask (1 << 10)
    7.45 +#define PictFormatColormap  (1 << 11)
    7.46 +
    7.47 +typedef XRenderPictFormat *
    7.48 +XRenderFindVisualFormatFunc (Display *dpy, _Xconst Visual *visual);
    7.49 +/* END OF Xrender.h chunk */
    7.50 +
    7.51  typedef struct _AwtGraphicsConfigData  {
    7.52      int         awt_depth;
    7.53      Colormap    awt_cmap;
    7.54 @@ -136,6 +180,7 @@
    7.55      ColorData      *color_data;
    7.56      struct _GLXGraphicsConfigInfo *glxInfo;
    7.57      int         isTranslucencySupported; /* Uses Xrender to find this out. */
    7.58 +    XRenderPictFormat renderPictFormat; /*Used only if translucency supported*/
    7.59  } AwtGraphicsConfigData;
    7.60  
    7.61  typedef AwtGraphicsConfigData* AwtGraphicsConfigDataPtr;