src/solaris/classes/sun/java2d/xr/XRCompositeManager.java

Print this page

        

@@ -46,11 +46,16 @@
 
 public class XRCompositeManager {
     private static boolean enableGradCache = true;
     private static XRCompositeManager instance;
 
-    XRSurfaceData src;
+    private final static int SOLID = 0;
+    private final static int TEXTURE = 1;
+    private final static int GRADIENT = 2;
+
+    int srcType;
+    XRSolidSrcPict solidSrc32;
     XRSurfaceData texture;
     XRSurfaceData gradient;
     int alphaMask = XRUtils.None;
 
     XRColor solidColor = new XRColor();

@@ -82,11 +87,10 @@
         return instance;
     }
 
     private XRCompositeManager(XRSurfaceData surface) {
         con = new XRBackendNative();
-        // con = XRBackendJava.getInstance();
 
         String gradProp =
             AccessController.doPrivileged(new PrivilegedAction<String>() {
                 public String run() {
                     return System.getProperty("sun.java2d.xrgradcache");

@@ -107,18 +111,11 @@
     }
 
     public void initResources(XRSurfaceData surface) {
         int parentXid = surface.getXid();
 
-        int solidPixmap = con.createPixmap(parentXid, 32, 1, 1);
-        int solidSrcPictXID = con.createPicture(solidPixmap,
-                XRUtils.PictStandardARGB32);
-        con.setPictureRepeat(solidSrcPictXID, XRUtils.RepeatNormal);
-        con.renderRectangle(solidSrcPictXID, XRUtils.PictOpSrc,
-                XRColor.FULL_ALPHA, 0, 0, 1, 1);
-        solidSrcPict = new XRSurfaceData.XRInternalSurfaceData(con,
-                solidSrcPictXID, null);
+        solidSrc32 = new XRSolidSrcPict(con, parentXid);
         setForeground(0);
 
         int extraAlphaMask = con.createPixmap(parentXid, 8, 1, 1);
         alphaMaskPict = con.createPicture(extraAlphaMask,
                 XRUtils.PictStandardA8);

@@ -133,30 +130,28 @@
                     XRUtils.PictStandardARGB32);
         }
     }
 
     public void setForeground(int pixel) {
-        solidColor.setColorValues(pixel, false);
-        con.renderRectangle(solidSrcPict.picture, XRUtils.PictOpSrc,
-                solidColor, 0, 0, 1, 1);
+        solidColor.setColorValues(pixel, true);
     }
 
     public void setGradientPaint(XRSurfaceData gradient) {
         if (this.gradient != null) {
             con.freePicture(this.gradient.picture);
         }
         this.gradient = gradient;
-        src = gradient;
+        srcType = GRADIENT;
     }
 
     public void setTexturePaint(XRSurfaceData texture) {
         this.texture = texture;
-        src = texture;
+        this.srcType = TEXTURE;
     }
 
     public void XRResetPaint() {
-        src = solidSrcPict;
+        srcType = SOLID;
     }
 
     public void validateCompositeState(Composite comp, AffineTransform xform,
             Paint paint, SunGraphics2D sg2d) {
         boolean updatePaint = (paint != validatedPaint) || paint == null;

@@ -173,11 +168,11 @@
             // sure we update the color below
             updatePaint = true;
             validatedComp = comp;
         }
 
-        if (sg2d != null && validatedPixel != sg2d.pixel) {
+        if (sg2d != null && (validatedPixel != sg2d.pixel  || updatePaint)) {
             validatedPixel = sg2d.pixel;
             setForeground(validatedPixel);
         }
 
         // validate paint

@@ -189,18 +184,18 @@
                 XRResetPaint();
             }
             validatedPaint = paint;
         }
 
-        if (src != solidSrcPict) {
+        if (srcType != SOLID) {
             AffineTransform at = (AffineTransform) xform.clone();
             try {
                 at.invert();
             } catch (NoninvertibleTransformException e) {
                 at.setToIdentity();
             }
-            src.validateAsSource(at, -1, -1);
+            getCurrentSource().validateAsSource(at, -1, -1);
         }
     }
 
     private void setComposite(Composite comp) {
         if (comp instanceof AlphaComposite) {

@@ -232,17 +227,17 @@
         }
     }
 
     public boolean maskRequired() {
         return (!xorEnabled)
-                && ((src != solidSrcPict)
-                        || (src == solidSrcPict && solidColor.alpha != 0xffff) || (extraAlpha != 1.0f));
+                && ((srcType != SOLID)
+                        || (srcType == SOLID && (solidColor.alpha != 0xffff) || (extraAlpha != 1.0f)));
     }
 
     public void XRComposite(int src, int mask, int dst, int srcX, int srcY,
             int maskX, int maskY, int dstX, int dstY, int width, int height) {
-        int cachedSrc = (src == XRUtils.None) ? this.src.picture : src;
+        int cachedSrc = (src == XRUtils.None) ? getCurrentSource().picture : src;
         int cachedX = srcX;
         int cachedY = srcY;
 
         if (enableGradCache && gradient != null
                 && cachedSrc == gradient.picture) {

@@ -274,11 +269,11 @@
         renderReferenceX = (int) Math.floor(XRUtils
                 .XFixedToDouble(renderReferenceX));
         renderReferenceY = (int) Math.floor(XRUtils
                 .XFixedToDouble(renderReferenceY));
 
-        con.renderCompositeTrapezoids(compRule, src.picture,
+        con.renderCompositeTrapezoids(compRule, getCurrentSource().picture,
                 XRUtils.PictStandardA8, dst, renderReferenceX,
                 renderReferenceY, trapList);
     }
 
     public void XRRenderRectangles(XRSurfaceData dst, GrowableRectArray rects) {

@@ -292,19 +287,50 @@
                 con.renderRectangles(dst.getPicture(), compRule, solidColor, rects);
             }
         }
     }
 
+    public void XRCompositeRectangles(XRSurfaceData dst, GrowableRectArray rects) {
+        int srcPict = getCurrentSource().picture;
+        
+        for(int i=0; i < rects.getSize(); i++) {
+            int x = rects.getX(i);
+            int y = rects.getY(i);
+            int width = rects.getWidth(i);
+            int height = rects.getHeight(i);
+            
+            con.renderComposite(compRule, srcPict, XRUtils.None, dst.picture, x, y, 0, 0, x, y, width, height);
+        }
+    }
+    
+    protected XRSurfaceData getCurrentSource() {
+        switch(srcType) {
+        case SOLID:
+            return solidSrc32.prepareSrcPict(validatedPixel);
+        case TEXTURE:
+            return texture;
+        case GRADIENT:
+            return gradient;
+        }
+        
+        return null;
+    }
+
     public void compositeBlit(XRSurfaceData src, XRSurfaceData dst, int sx,
             int sy, int dx, int dy, int w, int h) {
         con.renderComposite(compRule, src.picture, alphaMask, dst.picture, sx,
                 sy, 0, 0, dx, dy, w, h);
     }
 
-    public void compositeText(XRSurfaceData dst, int sx, int sy,
-            int glyphSet, int maskFormat, GrowableEltArray elts) {
-        con.XRenderCompositeText(compRule, src.picture, dst.picture,
+    public void compositeText(XRSurfaceData dst, int sx, int sy, int glyphSet,
+            int maskFormat, GrowableEltArray elts) {
+        /*
+         * Try to emulate the SRC blend mode with SRC_OVER.
+         * We bail out during pipe validation for cases where this is not possible.
+         */
+        byte textCompRule = (compRule != XRUtils.PictOpSrc) ? compRule : XRUtils.PictOpOver;
+        con.XRenderCompositeText(textCompRule, getCurrentSource().picture, dst.picture,
                 maskFormat, sx, sy, 0, 0, glyphSet, elts);
     }
 
     public XRColor getMaskColor() {
         return !isTexturePaintActive() ? XRColor.FULL_ALPHA : getAlphaColor();

@@ -313,11 +339,15 @@
     public int getExtraAlphaMask() {
         return alphaMask;
     }
 
     public boolean isTexturePaintActive() {
-        return src == texture;
+        return srcType == TEXTURE;
+    }
+    
+    public boolean isSolidPaintActive() {
+        return srcType == SOLID;
     }
 
     public XRColor getAlphaColor() {
         return alphaColor;
     }