Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XSurface.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XSurface.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XSurface.java (working copy) @@ -32,255 +32,55 @@ import org.apache.harmony.awt.gl.*; public class XSurface extends Surface { - private static final X11 x11 = X11.getInstance(); - //int width, height; // XXX - todo - use from superclass - - XGraphics2D g2d; - - private BufferedImage lastSnapshot = null; - boolean needServerData = true; - - private Rectangle2D roi; // Rectangle of interest - - private ImageSurface imageSurface; - - // Cached parameters for XCreateImage - boolean cachedXCIParams = false; - int depthXCI; - int offsetXCI; - int formatXCI; - int bitmapPadXCI; - int bytesPerLineXCI; - - XSurface(XGraphics2D g2d, int width, int height) { - this.g2d = g2d; + surfaceDataPtr = createSurfData(g2d.display, g2d.drawable, g2d.imageGC, g2d.xConfig.info.lock(), width, height); + g2d.xConfig.info.unlock(); this.width = width; this.height = height; - roi = new Rectangle2D.Float(0, 0, width, height); } - - void setRoi(Rectangle2D roi) { - this.roi = roi; - } - - public ColorModel getColorModel() { - return g2d.xConfig.getColorModel(); - } - - public WritableRaster getRaster() { - if (needServerData) { - long pixmap = x11.XCreatePixmap( - g2d.display, - x11.XRootWindow(g2d.display, g2d.xConfig.dev.screen), - (int) roi.getWidth(), (int) roi.getHeight(), - g2d.xConfig.info.get_depth() - ); - - x11.XCopyArea( - g2d.display, - g2d.drawable, - pixmap, - g2d.imageGC, - (int) roi.getX(), - (int) roi.getY(), - (int) roi.getWidth(), (int) roi.getHeight(), - 0, 0 - ); - - if (!cachedXCIParams) { - long xImagePtr = x11.XGetImage( - g2d.display, - pixmap, - 0, 0, - 1, 1, - ~(0L), // All bits set to 1, should be same as XAllPlanes() result - X11Defs.ZPixmap - ); - - if (xImagePtr == 0) // Check obtained XImage pointer - return null; - - X11.XImage xTmpImage = x11.createXImage(xImagePtr); - depthXCI = xTmpImage.get_depth(); - formatXCI = xTmpImage.get_format(); - offsetXCI = xTmpImage.get_xoffset(); - bitmapPadXCI = xTmpImage.get_bitmap_pad(); - bytesPerLineXCI = xTmpImage.get_bytes_per_line(); - xTmpImage.get_f().destroy_image(xTmpImage); - - cachedXCIParams = true; - } - - X11.Visual visual = g2d.xConfig.info.get_visual(); - - long xImagePtr = x11.XCreateImage( - g2d.display, - visual.lock(), - depthXCI, - formatXCI, - offsetXCI, - Utils.memaccess.malloc(height*width*bytesPerLineXCI), - width, height, - bitmapPadXCI, - 0 - ); - visual.unlock(); - - X11.XImage xImage = x11.createXImage(xImagePtr); - xImage.set_byte_order(X11Defs.LSBFirst); - - xImage = x11.XGetSubImage( - g2d.display, - pixmap, - 0, 0, - (int) roi.getWidth(), (int) roi.getHeight(), - ~(0L), // All bits set to 1, should be same as XAllPlanes() result - X11Defs.ZPixmap, - xImage, 0, 0 - ); - x11.XFreePixmap(g2d.display, pixmap); - lastSnapshot = XVolatileImage.biFromXImage(xImage, g2d.xConfig); - - // Cleanup - xImage.get_f().destroy_image(xImage); - } else { - lastSnapshot = g2d.xConfig.createCompatibleImage(width, height); - } - - return lastSnapshot.getRaster(); - } - - void putImage(MultiRectArea clip, int x, int y, int width, int height) { - putImage( - clip, - lastSnapshot.getRaster(), - x, y, width, height - ); - } - - void putImage( - MultiRectArea clip, Raster r, - int dstX, int dstY, - int dstWidth, int dstHeight - ) { - if (r == null) // Just blit last snapshot - r = lastSnapshot.getRaster(); - - Object data; - AwtImageBackdoorAccessor dbAccess = AwtImageBackdoorAccessor.getInstance(); - data = dbAccess.getData(r.getDataBuffer()); - LockedArray lockedData = Utils.arraccess.lockArrayShort(data); - - SampleModel sm = r.getSampleModel(); - int scanlineStride; - if (sm instanceof ComponentSampleModel) { - scanlineStride = ((ComponentSampleModel) sm).getScanlineStride(); - } else if (sm instanceof SinglePixelPackedSampleModel) { - scanlineStride = ((SinglePixelPackedSampleModel) sm).getScanlineStride(); - } else if (sm instanceof MultiPixelPackedSampleModel) { - scanlineStride = ((MultiPixelPackedSampleModel) sm).getScanlineStride(); - } else { + @Override + public void dispose() { + if (surfaceDataPtr == 0) { return; } - - int pad; - if (data instanceof byte[]) { - pad = 8; - } else if (data instanceof short[]) { - pad = 16; - scanlineStride *= 2; - } else if (data instanceof int[]) { - pad = 32; - scanlineStride *= 4; - } else { - return; - } - - X11.Visual visual = g2d.xConfig.info.get_visual(); - - long xImagePtr = x11.XCreateImage( - g2d.display, - visual.lock(), - g2d.xConfig.info.get_depth(), - X11Defs.ZPixmap, - 0, - lockedData.getAddress(), - r.getWidth(), - r.getHeight(), - pad, - scanlineStride - ); - visual.unlock(); - - g2d.setXClip(clip, g2d.imageGC); - - X11.XImage xImage = x11.createXImage(xImagePtr); - xImage.set_byte_order(X11Defs.LSBFirst); // Set byte order explicitly - - x11.XPutImage( - g2d.display, - g2d.drawable, - g2d.imageGC, - xImagePtr, - 0, 0, - dstX, dstY, - dstWidth, dstHeight - ); - - g2d.resetXClip(g2d.imageGC); - - lockedData.release(); - - xImage.set_data(NativeBridge.getInstance().createInt8Pointer(0, true)); - xImage.get_f().destroy_image(xImage); + + dispose(surfaceDataPtr); + surfaceDataPtr = 0; } - public void dispose() { - return; - } - - public XGraphics2D getGraphics() { - return g2d; - } - - /* - public int getWidth() { // XXX - todo - use from superclass - return this.width; - } - - public int getHeight() { // XXX - todo - use from superclass - return this.height; - } - */ - + @Override public long lock() { return 0; } + @Override public void unlock() { + } - public boolean isNativeDrawable() { - return true; + @Override + public ColorModel getColorModel() { + return null; } + @Override + public WritableRaster getRaster() { + return null; + } + + @Override public int getSurfaceType() { - return BufferedImage.TYPE_CUSTOM; + return 0; } + @Override public Surface getImageSurface() { - if (imageSurface == null) { - imageSurface = new ImageSurface(getColorModel(), getRaster()); - } else { - imageSurface.setRaster(getRaster()); - } - - return imageSurface; + return this; } - protected void finalize() throws Throwable { - imageSurface.dispose(); - } + private native long createSurfData(long display, long drawable, long gc, long visual_info, int width, int height); + + private native void dispose(long structPtr); + } Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/PixmapSurface.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/PixmapSurface.java (revision 0) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/PixmapSurface.java (revision 0) @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + * + */ +package org.apache.harmony.awt.gl.linux; + +import java.awt.image.ColorModel; +import java.awt.image.WritableRaster; + +import org.apache.harmony.awt.gl.Surface; + + +public class PixmapSurface extends Surface { + + public PixmapSurface(long display, long drawable, long visual_info, int width, int height){ + surfaceDataPtr = createSurfData(display, drawable, visual_info, width, height); + this.width = width; + this.height = height; + } + + @Override + public synchronized void dispose() { + dispose(surfaceDataPtr); + surfaceDataPtr = 0L; + } + + private native long createSurfData(long display, long drawable, long visual_info, int width, int height); + + private native void dispose(long structPtr); + + @Override + public long lock() { + return 0; + } + + @Override + public void unlock() { + } + + @Override + public ColorModel getColorModel() { + return null; + } + + @Override + public WritableRaster getRaster() { + return null; + } + + @Override + public int getSurfaceType() { + return 0; + } + + @Override + public Surface getImageSurface() { + return this; + } + +} Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XVolatileImage.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XVolatileImage.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XVolatileImage.java (working copy) @@ -39,7 +39,7 @@ private long pixmap; private XGraphicsConfiguration xconf; - private XGraphics2D lastGraphics = null; + Surface surface; int width, height; @@ -54,6 +54,9 @@ w, h, xconf.info.get_depth() ); + + surface = new PixmapSurface(display, pixmap, xconf.info.lock(), w, h); + xconf.info.unlock(); } public long getPixmap() { @@ -73,8 +76,7 @@ } public Graphics2D createGraphics() { - lastGraphics = new XGraphics2D(pixmap, 0, 0, width, height); - return lastGraphics; + return new XGraphics2D(this, 0, 0, width, height); } public int validate(GraphicsConfiguration graphicsConfiguration) { @@ -278,13 +280,11 @@ } public void finalize() { + surface.dispose(); x11.XFreePixmap(xconf.dev.display, pixmap); } public Surface getImageSurface() { - if (lastGraphics == null) - createGraphics(); - - return lastGraphics.getSurface(); + return surface; } } Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XBlitter.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XBlitter.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XBlitter.java (working copy) @@ -36,375 +36,188 @@ import org.apache.harmony.awt.nativebridge.linux.X11; import org.apache.harmony.awt.nativebridge.linux.X11Defs; +import org.apache.harmony.awt.internal.nls.Messages; + public class XBlitter implements Blitter { + static final XBlitter inst = new XBlitter(); public static XBlitter getInstance(){ return inst; } + public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY, + Surface dstSurf, int width, int height, AffineTransform sysxform, + AffineTransform xform, Composite comp, Color bgcolor, + MultiRectArea clip) { - public void blit( - int srcX, int srcY, Surface srcSurf, - int dstX, int dstY, Surface dstSurf, - int width, int height, - AffineTransform sysxform, AffineTransform xform, - Composite comp, Color bgcolor, MultiRectArea clip - ) { - int type = xform.getType(); - switch (type) { - case AffineTransform.TYPE_TRANSLATION: - dstX += xform.getTranslateX(); - dstY += xform.getTranslateY(); - case AffineTransform.TYPE_IDENTITY: - blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, - width, height, sysxform, comp, bgcolor, clip); - break; - default: - XSurface xDstSurf = (XSurface) dstSurf; + if(xform == null){ + blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height, + sysxform, comp, bgcolor, clip); + }else{ + double scaleX = xform.getScaleX(); + double scaleY = xform.getScaleY(); + double scaledX = dstX / scaleX; + double scaledY = dstY / scaleY; + AffineTransform at = new AffineTransform(); + at.setToTranslation(scaledX, scaledY); + xform.concatenate(at); + sysxform.concatenate(xform); + blit(srcX, srcY, srcSurf, 0, 0, dstSurf, width, height, + sysxform, comp, bgcolor, clip); + } + } - BufferedImage compIm; - int w = srcSurf.getWidth(); - int h = srcSurf.getHeight(); + public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY, + Surface dstSurf, int width, int height, AffineTransform sysxform, Composite comp, + Color bgcolor, MultiRectArea clip) { - if (!(srcSurf instanceof ImageSurface)) { - compIm = xDstSurf.g2d.xConfig.createCompatibleImage(w, h); - NativeImageBlitter.getInstance().blit( - srcX, srcY, srcSurf, - srcX, srcY, - AwtImageBackdoorAccessor.getInstance().getImageSurface(compIm), - w, h, - AlphaComposite.Src, null, null - ); - } else { - ColorModel cm = srcSurf.getColorModel(); - compIm = new BufferedImage( - cm, - srcSurf.getRaster(), - cm.isAlphaPremultiplied(), - null - ); - } + if(srcSurf.isNativeDrawable()){ + double matrix[] = null; + if(sysxform != null){ + int type = sysxform.getType(); + switch (type) { - WritableRaster compRaster = compIm.getRaster(); + case AffineTransform.TYPE_TRANSLATION: + dstX += sysxform.getTranslateX(); + dstY += sysxform.getTranslateY(); + case AffineTransform.TYPE_IDENTITY: + break; - AffineTransform at = (AffineTransform) sysxform.clone(); - at.concatenate(xform); + default: + matrix = new double[6]; + sysxform.getMatrix(matrix); + Rectangle transDstBounds = JavaBlitter.getBounds2D(sysxform, new Rectangle(dstX, dstY, width, height)).getBounds(); + dstX = transDstBounds.x; + dstY = transDstBounds.y; + + Rectangle transSrcBounds = JavaBlitter.getBounds2D(sysxform, new Rectangle(srcX, srcY, width, height)).getBounds(); + srcX = transSrcBounds.x; + srcY = transSrcBounds.y; + width = transSrcBounds.width; + height = transSrcBounds.height; - // Want to transform without translation to fit into destination image - // Translation will be added then when blitting to final dest surface - dstX += at.getTranslateX(); - dstY += at.getTranslateY(); - AffineTransform untranslated = - AffineTransform.getTranslateInstance( - -at.getTranslateX(), - -at.getTranslateY() - ); - untranslated.concatenate(at); - - AffineTransformOp atop = - new AffineTransformOp(untranslated, xDstSurf.g2d.getRenderingHints()); - - Rectangle r = atop.getBounds2D(compRaster).getBounds(); - int tWidth = r.width; - int tHeight = r.height; - - BufferedImage transformed; - if (compIm.getColorModel().getTransparency() == Transparency.OPAQUE) { - transformed = xDstSurf.g2d.xConfig.createCompatibleImage(tWidth, tHeight); - } else { - ColorModel cm = compIm.getColorModel(); - transformed = - new BufferedImage( - cm, - compIm.getRaster().createCompatibleWritableRaster( - tWidth, - tHeight - ), - cm.isAlphaPremultiplied(), - null - ); } - atop.filter(compIm, transformed); - if (dstX < 0){ - tWidth += dstX; - dstX = 0; - } + } - if (dstY < 0){ - tHeight += dstY; - dstY = 0; - } + long dstSurfStruct = dstSurf.getSurfaceDataPtr(); + long srcSurfStruct = srcSurf.getSurfaceDataPtr(); + int clipRects[] = null; + int numVertex = 0; + if(clip != null){ + clipRects = clip.rect; + numVertex = clipRects[0] - 1; + } - blit( - 0, 0, AwtImageBackdoorAccessor.getInstance().getImageSurface(transformed), - dstX, dstY, dstSurf, - tWidth, tHeight, - comp, bgcolor, clip - ); - } - } + if(comp instanceof AlphaComposite){ + AlphaComposite ac = (AlphaComposite) comp; + int compType = ac.getRule(); + float alpha = ac.getAlpha(); - public void blit( - int srcX, int srcY, Surface srcSurf, - int dstX, int dstY, Surface dstSurf, - int width, int height, - AffineTransform sysxform, - Composite comp, Color bgcolor, MultiRectArea clip - ) { - int type = sysxform.getType(); - switch (type) { - case AffineTransform.TYPE_TRANSLATION: - case AffineTransform.TYPE_IDENTITY: - blit( - srcX, srcY, srcSurf, - dstX + (int) sysxform.getTranslateX(), - dstY + (int) sysxform.getTranslateY(), - dstSurf, - width, height, - comp, bgcolor, clip - ); - break; - default: - ColorModel cm = srcSurf.getColorModel(); - WritableRaster compRaster = srcSurf.getRaster(); - BufferedImage compIm = new BufferedImage( - cm, - compRaster, - cm.isAlphaPremultiplied(), - null - ); + if(srcSurf instanceof ImageSurface){ + Object data = srcSurf.getData(); - Rectangle transDstBounds = JavaBlitter.getBounds2D(sysxform, new Rectangle(dstX, dstY, width, height)).getBounds(); - int tWidth = transDstBounds.width; - int tHeight = transDstBounds.height; - int tX = transDstBounds.x; - int tY = transDstBounds.y; + int dirtyRegions[] = ((ImageSurface) srcSurf).getDirtyRegions(); + int regCount = 0; + if(dirtyRegions != null) regCount = dirtyRegions[0] - 1; + + boolean hasBackground = false; + int bgc = 0; - if(tWidth <= 0 || tHeight <= 0) return; - BufferedImage transformed = new BufferedImage(dstSurf.getWidth(), dstSurf.getHeight(), BufferedImage.TYPE_INT_ARGB); + if(bgcolor != null && srcSurf.getTransparency() != Transparency.OPAQUE){ + hasBackground = true; + bgc = bgcolor.getRGB(); + } - Surface transfSurf = Surface.getImageSurface(transformed); - JavaBlitter.getInstance().blit(srcX, srcY, Surface.getImageSurface(compIm), - dstX, dstY, transfSurf, width, height, sysxform, AlphaComposite.Src, null, null); - blit( - tX, tY, transfSurf, - tX, tY, dstSurf, - tWidth, tHeight, - comp, bgcolor, clip - ); - - } - } - - public void blit( - int srcX, int srcY, Surface srcSurf, - int dstX, int dstY, Surface dstSurf, - int width, int height, - Composite comp, Color bgcolor, MultiRectArea clip - ) { - - if (clip == null) { - clip = new MultiRectArea(new Rectangle(dstX, dstY, width, height)); - } else { - clip = new MultiRectArea(clip); - } - // XXX - todo - need to do smth with bgcolor - ColorModel srcCM = srcSurf.getColorModel(); - XSurface xDstSurf = (XSurface) dstSurf; - - if (srcSurf.isNativeDrawable() && srcCM.equals(dstSurf.getColorModel())) { - if (srcSurf instanceof XSurface) { // Blit from native to native - XSurface xSrcSurf = (XSurface) srcSurf; - - XGraphics2D g2d = xDstSurf.g2d; - - if (comp instanceof AlphaComposite) { - switch (((AlphaComposite) comp).getRule()) { - case AlphaComposite.SRC: - case AlphaComposite.SRC_ATOP: - case AlphaComposite.SRC_IN: - case AlphaComposite.SRC_OVER: - break; // GXCopy - is default - case AlphaComposite.DST: - case AlphaComposite.DST_ATOP: - case AlphaComposite.DST_IN: - case AlphaComposite.DST_OVER: - g2d.setImageGCFunction(X11Defs.GXnoop); - break; - case AlphaComposite.SRC_OUT: // Clear - case AlphaComposite.DST_OUT: // Clear - case AlphaComposite.CLEAR: - case AlphaComposite.XOR: // Clear - g2d.setImageGCFunction(X11Defs.GXclear); - break; - default: // Do nothing + synchronized(data){ + bltImage(srcX, srcY, srcSurfStruct, srcSurf.getData(), + dstX, dstY, dstSurfStruct, width, height, + hasBackground, bgc, compType, alpha, matrix, + clipRects, numVertex, srcSurf.invalidated(), + dirtyRegions, regCount); } - } else { - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); - return; + srcSurf.validate(); + }else{ + bltPixmap(srcX, srcY, srcSurfStruct, + dstX, dstY, dstSurfStruct, + width, height, compType, alpha, matrix, + clipRects, numVertex); } + }else if(comp instanceof XORComposite){ + XORComposite xcomp = (XORComposite) comp; + if(srcSurf instanceof ImageSurface){ + Object data = srcSurf.getData(); - // Get translated clip - makeClip(dstX, dstY, width, height, clip); + int dirtyRegions[] = ((ImageSurface) srcSurf).getDirtyRegions(); + int regCount = 0; + if(dirtyRegions != null) regCount = dirtyRegions[0] - 1; - g2d.setXClip(clip, g2d.imageGC); - X11 x11 = X11.getInstance(); - x11.XCopyArea( - g2d.display, - xSrcSurf.g2d.drawable, g2d.drawable, - g2d.imageGC, - srcX, srcY, - width, height, - dstX, dstY - ); - x11.XFlush(g2d.display); - g2d.resetXClip(g2d.imageGC); - - g2d.setImageGCFunction(X11Defs.GXcopy); - } else if (srcSurf.getSurfaceType() == BufferedImage.TYPE_CUSTOM) { - // source is custom image, slow blit - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); - } else { // source could be compatible image - int srcTransp = srcCM.getTransparency(); - if (srcTransp == Transparency.OPAQUE) { - if (comp instanceof AlphaComposite) { - AlphaComposite acomp = (AlphaComposite) comp; - if ( - acomp.getRule() == AlphaComposite.SRC || - (acomp.getAlpha() == 1 && - (acomp.getRule() == AlphaComposite.SRC_OVER || - acomp.getRule() == AlphaComposite.SRC_ATOP || - acomp.getRule() == AlphaComposite.SRC_IN) - ) - ) { - // Get translated clip - makeClip(dstX, dstY, width, height, clip); - xDstSurf.putImage( - clip, - srcSurf.getRaster(), - dstX, dstY, - width, height - ); - } else { - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); - } + synchronized(data){ + xorImage(srcX, srcY, srcSurfStruct, data, + dstX, dstY, dstSurfStruct, + width, height, xcomp.getXORColor().getRGB(), matrix, + clipRects, numVertex, + srcSurf.invalidated(), dirtyRegions, regCount); } - - } else if (srcTransp == Transparency.BITMASK) { - // todo - XXX - optimize here - use native clip mask - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); - } else { // have to compose in java - no native alpha composite - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); + srcSurf.validate(); + }else{ + xorPixmap(srcX, srcY, srcSurfStruct, + dstX, dstY, dstSurfStruct, + width, height, xcomp.getXORColor().getRGB(), matrix, + clipRects, numVertex); } + }else{ + // awt.17=Unknown Composite type : {0} + throw new IllegalArgumentException(Messages.getString("awt.17", //$NON-NLS-1$ + comp.getClass())); } - } else { - imBlit( - srcX, srcY, srcSurf, - dstX, dstY, dstSurf, - width, height, - comp, bgcolor, clip - ); + }else{ + BufferedImage bi; + if(srcSurf.getTransparency() == Transparency.OPAQUE){ + bi = new BufferedImage(srcSurf.getWidth(), srcSurf.getHeight(), BufferedImage.TYPE_INT_RGB); + }else{ + bi = new BufferedImage(srcSurf.getWidth(), srcSurf.getHeight(), BufferedImage.TYPE_INT_ARGB); + } + Surface tmpSurf = AwtImageBackdoorAccessor.getInstance().getImageSurface(bi); + JavaBlitter.getInstance().blit(0, 0, srcSurf, 0, 0, tmpSurf, + srcSurf.getWidth(), srcSurf.getHeight(), + AlphaComposite.Src, null, null); + blit(srcX, srcY, tmpSurf, dstX, dstY, dstSurf, + width, height, comp, bgcolor, clip); } } - private static void imBlit( - int srcX, int srcY, Surface srcSurf, - int dstX, int dstY, Surface dstSurf, - int width, int height, - Composite comp, - Color bgcolor, - MultiRectArea clip - ) { + // Native methods - if(dstX < 0){ - width += dstX; - dstX = 0; - } + public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY, + Surface dstSurf, int width, int height, + Composite comp, Color bgcolor, MultiRectArea clip) { - if(dstY < 0){ - height += dstY; - dstY = 0; - } + blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height, + null, comp, bgcolor, clip); + } - if(width <= 0 || height <= 0) return; + private native void bltImage(int srcX, int srcY, long srsSurfDataPtr, + Object srcData, int dstX, int dstY, long dstSurfDataPtr, + int width, int height, boolean hasBackground, int bgcolor, int compType, + float alpha, double matrix[], int clip[], int numVertex, + boolean invalidated, int[] dirtyRegions, int regCount); - XSurface xDstSurf = ((XSurface) dstSurf); + private native void bltPixmap(int srcX, int srcY, long srsSurfDataPtr, + int dstX, int dstY, long dstSurfDataPtr, + int width, int height, int compType, + float alpha, double matrix[], int clip[], int numVertex); - boolean srcNoAlpha = - srcSurf.getColorModel().getTransparency() == Transparency.OPAQUE; + private native void xorImage(int srcX, int srcY, long srsSurfDataPtr, + Object srcData, int dstX, int dstY, long dstSurfDataPtr, + int width, int height, int xorcolor, double matrix[], int clip[], + int numVertex, boolean invalidated, int[] dirtyRegions, int regCount); - if (comp instanceof AlphaComposite) { - AlphaComposite acomp = (AlphaComposite) comp; - if ( - acomp.getRule() == AlphaComposite.SRC || - (srcNoAlpha && acomp.getAlpha() == 1 && - (acomp.getRule() == AlphaComposite.SRC_OVER || - acomp.getRule() == AlphaComposite.SRC_ATOP || - acomp.getRule() == AlphaComposite.SRC_IN) - ) - ) { - xDstSurf.needServerData = false; - } - } - - Rectangle2D roi = new Rectangle2D.Float(dstX, dstY, width, height); - xDstSurf.setRoi(roi); - NativeImageBlitter.getInstance().blit( - srcX, srcY, srcSurf, - 0, 0, xDstSurf.getImageSurface(), - width, height, - comp, bgcolor, null - ); - - if (xDstSurf.needServerData) { - xDstSurf.putImage(clip, - (int) (roi.getX()), - (int) (roi.getY()), - (int) roi.getWidth(), - (int) roi.getHeight() - ); - - } else { - xDstSurf.putImage(clip, dstX, dstY, width, height); - } - - xDstSurf.needServerData = true; - } - - private static void makeClip( - int dstX, int dstY, - int width, int height, - MultiRectArea clip - ) { - Rectangle destRect = new Rectangle(dstX, dstY, width, height); - clip.intersect(destRect); - } + private native void xorPixmap(int srcX, int srcY, long srsSurfDataPtr, + int dstX, int dstY, long dstSurfDataPtr, + int width, int height, int xorcolor, double matrix[], + int clip[], int numVertex); } + Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java (working copy) @@ -66,10 +66,6 @@ boolean xor_mode = false; boolean indexModel = false; - - static{ - System.loadLibrary("gl"); - } public XGraphics2D(long drawable, int tx, int ty, MultiRectArea clip) { super(tx, ty, clip); @@ -101,6 +97,41 @@ } } + public XGraphics2D(XVolatileImage image, int tx, int ty, int width, int height) { + this(image, tx, ty, new MultiRectArea(new Rectangle(width, height))); + } + + public XGraphics2D(XVolatileImage image, int tx, int ty, MultiRectArea clip) { + super(tx, ty, clip); + drawable = image.getPixmap(); + xConfig = (XGraphicsConfiguration) getDeviceConfiguration(); + display = xConfig.dev.display; + gc = createGC(display, drawable); + + X11.Visual visual = xConfig.info.get_visual(); + xftDraw = createXftDraw(display, drawable, visual.lock()); + visual.unlock(); + + imageGC = createGC(display, drawable); + + //xSetForeground(argb); // Set default foregroung to black + + blitter = XBlitter.getInstance(); + Rectangle bounds = clip.getBounds(); + dstSurf = image.getImageSurface(); + + if (!FontManager.IS_FONTLIB) { + jtr = DrawableTextRenderer.inst; + } + + //setTransformedClip(clip); + setClip(clip); + + if (xConfig.getColorModel() instanceof IndexColorModel) { + indexModel = true; + } + } + public XGraphics2D(long drawable, int tx, int ty, int width, int height) { this(drawable, tx, ty, new MultiRectArea(new Rectangle(width, height))); } @@ -215,6 +246,9 @@ xftDraw = 0; } + if(dstSurf instanceof XSurface) + dstSurf.dispose(); + if (gc != 0) { freeGC(display, gc); gc = 0; Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/XServerConnection.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/XServerConnection.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/XServerConnection.java (working copy) @@ -31,8 +31,10 @@ private final X11 x11; - public XServerConnection(X11 x11) { - this.x11 = x11; + private static XServerConnection instance = new XServerConnection(); + + private XServerConnection() { + this.x11 = X11.getInstance();; display = x11.XOpenDisplay(0); //0 - we use default display only if (display == 0) { String name = System.getProperty("DISPLAY"); //$NON-NLS-1$ @@ -40,9 +42,17 @@ throw new InternalError(Messages.getString("awt.0F", //$NON-NLS-1$ (name != null ? name : ""))); //$NON-NLS-1$ } + screen = x11.XDefaultScreen(display); + + System.loadLibrary("gl"); + init(display, screen); } + public static XServerConnection getInstance(){ + return instance; + } + public void close() { x11.XCloseDisplay(display); } @@ -54,4 +64,6 @@ public int getScreen() { return screen; } + + private native void init(long display, int screen); } Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java (revision 612414) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWindowFactory.java (working copy) @@ -43,7 +43,7 @@ private static final X11 x11 = X11.getInstance(); private static final NativeBridge bridge = NativeBridge.getInstance(); - private final XServerConnection xConnection = new XServerConnection(x11); + private final XServerConnection xConnection = XServerConnection.getInstance(); private final long display = xConnection.getDisplay(); private final int screen = xConnection.getScreen(); final WindowManager wm; Index: modules/awt/src/main/java/common/org/apache/harmony/awt/gl/render/JavaBlitter.java =================================================================== --- modules/awt/src/main/java/common/org/apache/harmony/awt/gl/render/JavaBlitter.java (revision 612414) +++ modules/awt/src/main/java/common/org/apache/harmony/awt/gl/render/JavaBlitter.java (working copy) @@ -489,9 +489,9 @@ float[] corners = { x, y, - x + width, y, - x + width, y + height, - x, y + height + x + width + 1, y, + x + width + 1, y + height + 1, + x, y + height + 1 }; at.transform(corners, 0, corners, 0, 4); Index: modules/awt/src/main/native/gl/unix/XGraphics2D.cpp =================================================================== --- modules/awt/src/main/native/gl/unix/XGraphics2D.cpp (revision 612414) +++ modules/awt/src/main/native/gl/unix/XGraphics2D.cpp (working copy) @@ -26,6 +26,7 @@ #include #include +#include "XSurfaceInfo.h" #include "org_apache_harmony_awt_gl_linux_XGraphics2D.h" JNIEXPORT jlong JNICALL Index: modules/awt/src/main/native/gl/unix/exports.txt =================================================================== --- modules/awt/src/main/native/gl/unix/exports.txt (revision 612414) +++ modules/awt/src/main/native/gl/unix/exports.txt (working copy) @@ -32,3 +32,12 @@ Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setForeground Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setFunction Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setStroke +Java_org_apache_harmony_awt_gl_linux_XSurface_createSurfData +Java_org_apache_harmony_awt_gl_linux_XSurface_dispose +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_createSurfData +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_dispose +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltImage +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltPixmap +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorImage +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorPixmap +Java_org_apache_harmony_awt_wtk_linux_XServerConnection_init Index: modules/awt/src/main/native/gl/unix/include/XSurfaceInfo.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/XSurfaceInfo.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/XSurfaceInfo.h (revision 0) @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +#ifndef __XSURFACE_H__ +#define __XSURFACE_H__ + +#include +#include + +#ifdef _XSHM_H_ +#include +#include +#endif + +#include +#include + +#include +#include +#include + +extern Bool hasXRender; +extern Bool hasXShm; +extern Bool hasXShmPixmap; + +extern Visual *true_color_visual; + +int error_handler(Display *, XErrorEvent *); + +#endif Index: modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XBlitter.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XBlitter.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XBlitter.h (revision 0) @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +/* + * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL. + * Please be aware that all changes made to this file manually + * will be overwritten by the tool if it runs again. + */ + +#include + + +/* Header for class org.apache.harmony.awt.gl.linux.XBlitter */ + +#ifndef _ORG_APACHE_HARMONY_AWT_GL_LINUX_XBLITTER +#define _ORG_APACHE_HARMONY_AWT_GL_LINUX_XBLITTER + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Native methods */ + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.bltImage(IIJLjava/lang/Object;IIJIIZIIF[D[IIZ[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltImage(JNIEnv *, jobject, + jint, jint, jlong, jobject, jint, jint, jlong, jint, jint, jboolean, jint, jint, + jfloat, jdoubleArray, jintArray, jint, jboolean, jintArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.bltPixmap(IIJIIJIIIF[D[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltPixmap(JNIEnv *, jobject, + jint, jint, jlong, jint, jint, jlong, jint, jint, jint, jfloat, jdoubleArray, jintArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.xorImage(IIJLjava/lang/Object;IIJIII[D[IIZ[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorImage(JNIEnv *, jobject, + jint, jint, jlong, jobject, jint, jint, jlong, jint, jint, jint, jdoubleArray, + jintArray, jint, jboolean, jintArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.xorPixmap(IIJIIJIII[D[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorPixmap(JNIEnv *, jobject, + jint, jint, jlong, jint, jint, jlong, jint, jint, jint, jdoubleArray, jintArray, jint); + +#ifdef __cplusplus +} +#endif + +#endif /*_ORG_APACHE_HARMONY_AWT_GL_LINUX_XBLITTER*/ Index: modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XSurface.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XSurface.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XSurface.h (revision 0) @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +/* + * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL. + * Please be aware that all changes made to this file manually + * will be overwritten by the tool if it runs again. + */ + +#include + + +/* Header for class org.apache.harmony.awt.gl.linux.XSurface */ + +#ifndef _ORG_APACHE_HARMONY_AWT_GL_LINUX_XSURFACE +#define _ORG_APACHE_HARMONY_AWT_GL_LINUX_XSURFACE + +#ifdef __cplusplus +extern "C" { +#endif + +/* Native methods */ + + +/* + * Method: org.apache.harmony.awt.gl.linux.XSurface.createSurfData(JJJJII)J + */ +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_XSurface_createSurfData(JNIEnv *, jobject, + jlong, jlong, jlong, jlong, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XSurface.dispose(J)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XSurface_dispose(JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif + +#endif /* _ORG_APACHE_HARMONY_AWT_GL_LINUX_XSURFACE */ Index: modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_wtk_linux_XServerConnection.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_wtk_linux_XServerConnection.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_wtk_linux_XServerConnection.h (revision 0) @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +/* + * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL. + * Please be aware that all changes made to this file manually + * will be overwritten by the tool if it runs again. + */ + +#include + + +/* Header for class org.apache.harmony.awt.wtk.linux.XServerConnection */ + +#ifndef _ORG_APACHE_HARMONY_AWT_WTK_LINUX_XSERVERCONNECTION +#define _ORG_APACHE_HARMONY_AWT_WTK_LINUX_XSERVERCONNECTION + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Native methods */ + +/* + * Method: org.apache.harmony.awt.wtk.linux.XServerConnection.init(JI)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_wtk_linux_XServerConnection_init(JNIEnv *, jobject, jlong, jint); + +#ifdef __cplusplus +} +#endif + +#endif /* _ORG_APACHE_HARMONY_AWT_WTK_LINUX_XSERVERCONNECTION */ Index: modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_PixmapSurface.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_PixmapSurface.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_PixmapSurface.h (revision 0) @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +/* + * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL. + * Please be aware that all changes made to this file manually + * will be overwritten by the tool if it runs again. + */ + +#include + + +/* Header for class org.apache.harmony.awt.gl.linux.XSurface */ + +#ifndef _ORG_APACHE_HARMONY_AWT_GL_LINUX_PIXMAPSURFACE +#define _ORG_APACHE_HARMONY_AWT_GL_LINUX_PIXMAPSURFACE + +#ifdef __cplusplus +extern "C" { +#endif + +/* Native methods */ + + +/* + * Method: org.apache.harmony.awt.gl.linux.PixmapSurface.createSurfData(JJJII)J + */ +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_createSurfData(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.PixmapSurface.dispose(J)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_dispose(JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif + +#endif /* _ORG_APACHE_HARMONY_AWT_GL_LINUX_PIXMAPSURFACE */ Index: modules/awt/src/main/native/gl/unix/gl.cpp =================================================================== --- modules/awt/src/main/native/gl/unix/gl.cpp (revision 0) +++ modules/awt/src/main/native/gl/unix/gl.cpp (revision 0) @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +#include +#include + +#include "XSurfaceInfo.h" +#include "org_apache_harmony_awt_wtk_linux_XServerConnection.h" + +Bool hasXRender; +Bool hasXShm; +Bool hasXShmPixmap; + +Visual *true_color_visual; +/* + * Method: org.apache.harmony.awt.wtk.linux.XServerConnection.init(JI)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_wtk_linux_XServerConnection_init + (JNIEnv *env, jobject obj, jlong display, jint screen) +{ + int minor, major, num_visuals = 0; + + XVisualInfo templ; + + templ.screen = screen; + templ.depth = 32; + templ.red_mask = 0xff0000; + templ.green_mask = 0xff00; + templ.blue_mask = 0xff; + + XVisualInfo *info = XGetVisualInfo((Display *)display, VisualScreenMask | VisualDepthMask | + VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask, &templ, &num_visuals); + + if(num_visuals) true_color_visual = info[0].visual; + else true_color_visual = NULL; + + hasXRender = false; + hasXShm = false; + + int num; + char **ext_list = XListExtensions((Display *)display, &num); + +#ifdef _XRENDER_H_ + + Bool renderExists = False; + + for(int i = 0; i < num; i++){ + if(strstr(ext_list[i], "RENDER")){ + renderExists = True; + break; + } + } + + if(renderExists){ + XRenderQueryVersion((Display *)display, &major, &minor); + + if(major == 0 && minor > 7){ + hasXRender = true; + } + } +#endif + +#ifdef _XSHM_H_ + + Bool shmExists = False; + + for(int i = 0; i < num; i++){ + if(strstr(ext_list[i], "MIT-SHM")){ + shmExists = True; + break; + } + } + + if(shmExists){ + if(XShmQueryVersion((Display *)display, &major, &minor, &hasXShmPixmap)){ + hasXShm = true; + } + } +#endif + +} + Index: modules/awt/src/main/native/gl/unix/makefile =================================================================== --- modules/awt/src/main/native/gl/unix/makefile (revision 612414) +++ modules/awt/src/main/native/gl/unix/makefile (working copy) @@ -25,6 +25,8 @@ $(SHAREDSUB)/LUTTables.o \ $(SHAREDSUB)/pngdecoder.o \ $(SHAREDSUB)/SurfaceDataStructure.o \ + gl.o \ + XBlitter.o \ XGraphics2D.o \ libpng.a Index: modules/awt/src/main/native/gl/unix/XBlitter.cpp =================================================================== --- modules/awt/src/main/native/gl/unix/XBlitter.cpp (revision 0) +++ modules/awt/src/main/native/gl/unix/XBlitter.cpp (revision 0) @@ -0,0 +1,616 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +#include + +#include "XSurfaceInfo.h" +#include "SurfaceDataStructure.h" + +#include "org_apache_harmony_awt_gl_linux_XBlitter.h" +#include "org_apache_harmony_awt_gl_linux_XSurface.h" +#include "org_apache_harmony_awt_gl_linux_PixmapSurface.h" + +#define ZERO 1E-10 + +int error_handler(Display *display, XErrorEvent *myerr){ + char msg[1024]; + XGetErrorText(display, myerr->error_code, msg, 1024); + fprintf(stderr, "Error code: %d, Error message: %s\n", myerr->error_code, msg); +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XSurface.createSurfData(JJJJII)J + */ +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_XSurface_createSurfData + (JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jlong visual_info, jint width, jint height) +{ + SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1); + surf->display = (Display *)display; + surf->drawable = (Drawable)drawable; + surf->gc = (GC)gc; + surf->visual_info = (XVisualInfo *)visual_info; + surf->width = width; + surf->height = height; + return (jlong)surf; +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XSurface.dispose(J)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XSurface_dispose + (JNIEnv *env, jobject obj, jlong surfPtr) +{ + if(surfPtr) free((void *)surfPtr); +} + +/* + * Method: org.apache.harmony.awt.gl.linux.PixmapSurface.createSurfData(JJJII)J + */ +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_createSurfData + (JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong visual_info, jint width, jint height) +{ + SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)calloc(sizeof(SURFACE_STRUCTURE), 1); + surf->display = (Display *)display; + surf->drawable = (Drawable)drawable; + surf->gc = XCreateGC(surf->display, surf->drawable, 0, NULL); + surf->visual_info = (XVisualInfo *)visual_info; + surf->width = width; + surf->height = height; + return (jlong)surf; +} + +/* + * Method: org.apache.harmony.awt.gl.linux.PixmapSurface.dispose(J)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_PixmapSurface_dispose + (JNIEnv *env, jobject obj, jlong surfPtr) +{ + SURFACE_STRUCTURE *surf = (SURFACE_STRUCTURE *)surfPtr; + if(surf){ + if(surf->gc) XFreeGC(surf->display, surf->gc); + if(surf->ximage) XDestroyImage(surf->ximage); + + free(surf); + } +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.bltImage(IIJLjava/lang/Object;IIJIIZIIF[D[IIZ[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltImage + (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, jobject srcData, + jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, jboolean hasBackground, jint bgcolor, + jint compType, jfloat alpha, jdoubleArray matrix, jintArray clip, jint numVertex, jboolean invalidated, + jintArray dirtyRegions, jint regCount) +{ + XSetErrorHandler(error_handler); + + jdouble *mtrx = NULL, *inv = NULL; + + if(matrix != 0){ + mtrx = (jdouble *)malloc(6 * sizeof(jdouble)); + env->GetDoubleArrayRegion(matrix, 0, 6, mtrx); + + jdouble det = mtrx[0] * mtrx[3] - mtrx[1] * mtrx[2]; + + if(fabs(det) < ZERO){ + free(mtrx); + return; + } + + inv = (jdouble *)malloc(6 * sizeof(jdouble)); + inv[0] = mtrx[3] / det; + inv[1] = -mtrx[1] / det; + inv[2] = -mtrx[2] / det; + inv[3] = mtrx[0] / det; + inv[4] = (mtrx[2] * mtrx[5] - mtrx[3] * mtrx[4] ) / det; + inv[5] = (mtrx[1] * mtrx[4] - mtrx[0] * mtrx[5] ) / det; + } + + SURFACE_STRUCTURE *srcSurf = (SURFACE_STRUCTURE *)srcSurfStruct; + SURFACE_STRUCTURE *dstSurf = (SURFACE_STRUCTURE *)dstSurfStruct; + + Display *display = dstSurf->display; + Window root = XRootWindow(display, dstSurf->visual_info->screen); + + jint *verts = NULL; + XRectangle *rects = NULL; + int num_rects = 0; + + if(numVertex > 0){ + verts = (jint *)malloc(sizeof(jint)*numVertex); + env->GetIntArrayRegion(clip, 1, numVertex, verts); + + num_rects = numVertex >> 2; + rects = (XRectangle *)malloc(sizeof(XRectangle) * num_rects); + + for (int i = 0, j = 0; i < numVertex; i += 4, j++) { + rects[j].x = (short)verts[i]; + rects[j].y = (short)verts[i + 1]; + rects[j].width = (unsigned short)(verts[i+2]-verts[i]+1); + rects[j].height = (unsigned short)(verts[i+3]-verts[i+1]+1); + } + + free(verts); + } + + srcSurf->invalidated = invalidated != 0; + + if(srcSurf->invalidated){ + int *regions = NULL; + if(dirtyRegions == 0){ + regCount = 4; + regions = (int *)malloc(4 * sizeof(int)); + regions[0] = 0; + regions[1] = 0; + regions[2] = srcSurf->width - 1; + regions[3] = srcSurf->height - 1; + } else { + regions = (int *)malloc(regCount * sizeof(int)); + env->GetIntArrayRegion(dirtyRegions, 1, regCount, regions); + } + + for(int i = 0; i < regCount;){ + int x = regions[i++]; + int y = regions[i++]; + int w = regions[i++] - x + 1; + int h = regions[i++] - y + 1; + updateCache(srcSurf, env, srcData, true, x, y, w, h); + } + + if(regions) free(regions); + } + + int depth; + + if(srcSurf->has_alpha || matrix) { + depth = 32; + } else { + depth = 24; + } + + XImage ximage; + + ximage.width = srcSurf->width; + ximage.height = srcSurf->height; + ximage.xoffset = 0; + ximage.format = ZPixmap; + ximage.data = (char *)srcSurf->bmpData; + ximage.byte_order = LSBFirst; + ximage.bitmap_unit = depth; + ximage.bitmap_bit_order = MSBFirst; + ximage.bitmap_pad = 32; + ximage.depth = depth; + ximage.bytes_per_line = srcSurf->bmp_byte_stride; + ximage.bits_per_pixel = 32; + ximage.red_mask = 0xff0000; + ximage.green_mask = 0xff00; + ximage.blue_mask = 0xff; + + if(dstSurf->visual_info->depth == depth && + depth == 24 && (((compType == 2 || compType == 5) && alpha != 0) || + ((compType == 3 || compType == 10) && alpha == 1.0))){ + + XSetClipRectangles(display, dstSurf->gc, 0, 0, rects, num_rects, Unsorted); + XPutImage(display, dstSurf->drawable, dstSurf->gc, &ximage, srcX, srcY, dstX, dstY, width, height); + + if(rects) free(rects); + + return; + } +#ifdef _XRENDER_H_ + + if(hasXRender){ + + XRenderPictFormat *srcFormat; + + if(depth == 32) { + srcFormat = XRenderFindStandardFormat(display, PictStandardARGB32); + } else { + srcFormat = XRenderFindStandardFormat(display, PictStandardRGB24); + } + + Pixmap pixmap = XCreatePixmap(display, root, srcSurf->width, srcSurf->height, depth); + + GC gc = XCreateGC(display, pixmap, 0, 0); + XPutImage(display, pixmap, gc, &ximage, 0, 0, 0, 0, srcSurf->width, srcSurf->height); + XFreeGC(display, gc); + + Picture srcPict = XRenderCreatePicture(display, pixmap, srcFormat, 0, NULL); + + int op; + + switch(compType){ + case 1: + op = PictOpClear; + alpha = 1.0; + break; + case 2: + op = PictOpSrc; + if(alpha != 0) alpha = 1.0; + break; + case 3: + op = PictOpOver; + break; + case 4: + op = PictOpOverReverse; + alpha = 1.0; + break; + case 5: + op = PictOpIn; + if(alpha != 0) alpha = 1.0; + break; + case 6: + op = PictOpInReverse; + if(alpha != 0) alpha = 1.0; + break; + case 7: + op = PictOpOut; + alpha = 1.0; + break; + case 8: + op = PictOpOutReverse; + if(alpha != 1.0) alpha = 0; + break; + case 9: + op = PictOpDst; + alpha = 1.0; + break; + case 10: + op = PictOpAtop; + break; + case 11: + op = PictOpAtopReverse; + if(alpha != 0) alpha = 1.0; + break; + case 12: + op = PictOpXor; + if(alpha != 1.0) alpha = 0; + } + + if(matrix != NULL){ + int _one = XDoubleToFixed( 1 ); + XTransform xform = {{ + { _one, 0, 0 }, + { 0, _one, 0 }, + { 0, 0, _one } + }}; + + xform.matrix[0][0] = XDoubleToFixed(inv[0]); + xform.matrix[1][1] = XDoubleToFixed(inv[3]); + xform.matrix[1][0] = XDoubleToFixed(inv[1]); + xform.matrix[0][1] = XDoubleToFixed(inv[2]); + + xform.matrix[0][2] = (int)(mtrx[4] + 0.5); + xform.matrix[1][2] = (int)(mtrx[5] + 0.5); + + free(mtrx); + free(inv); + + XRenderSetPictureTransform( display, srcPict, &xform ); + XRenderSetPictureFilter(display, srcPict, FilterNearest, 0, 0); + + srcX -= xform.matrix[0][2]; + srcY -= xform.matrix[1][2]; + + } + + XRenderPictFormat *dstFormat = XRenderFindVisualFormat (dstSurf->display, dstSurf->visual_info->visual); + Picture dstPict = XRenderCreatePicture(dstSurf->display, dstSurf->drawable, dstFormat, 0, NULL); + + if(rects) XRenderSetPictureClipRectangles(display, dstPict, 0, 0, rects, num_rects); + + if(hasBackground){ + XRenderColor bgc; + bgc.red = (unsigned short)((bgcolor & 0xff0000) >> 8); + bgc.green = (unsigned short)(bgcolor & 0xff00); + bgc.blue = (unsigned short)((bgcolor & 0xff) << 8);; + bgc.alpha = (unsigned short)((bgcolor & 0xff000000) >> 16); + + Pixmap tmpPix = XCreatePixmap(display, root, srcSurf->width, srcSurf->height, depth); + + XRenderPictFormat *tmpFormat = XRenderFindStandardFormat(display, PictStandardARGB32); + + Picture tmpPict = XRenderCreatePicture(display, tmpPix, tmpFormat, 0, NULL); + + XRenderFillRectangle(display, PictOpSrc, tmpPict, &bgc, 0, 0, srcSurf->width, srcSurf->height); + + XRenderComposite(display, PictOpOver, srcPict, 0, tmpPict, + 0, 0, 0, 0, 0, 0, srcSurf->width, srcSurf->height); + + XRenderFreePicture(display, srcPict); + XFreePixmap(display, tmpPix); + + srcPict = tmpPict; + } + + Picture alphaMask = 0; + if(alpha != 1.0){ + XRenderColor c; + c.red = c.green = c.blue = 0; + c.alpha = (unsigned short)(((long)(alpha * 255 + 0.5)) << 8); + Pixmap am = XCreatePixmap(display, root, width, height, 8); + XRenderPictFormat *aformat = XRenderFindStandardFormat(display, PictStandardA8); + alphaMask = XRenderCreatePicture(display, am, aformat, 0, NULL); + XRenderFillRectangle(display, PictOpSrc, alphaMask, &c, 0, 0, width, height); + } + + XRenderComposite(display, op, srcPict, alphaMask, dstPict, + srcX, srcY, 0, 0, dstX, dstY, width, height); + + XFlush(display); + + if(alphaMask) XRenderFreePicture(display, alphaMask); + XRenderFreePicture(display, srcPict); + XRenderFreePicture(display, dstPict); + + if(pixmap) XFreePixmap(display, pixmap); + if(rects) free(rects); + + } else { + +#endif + +#ifdef _XRENDER_H_ + + } + +#endif + +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.bltPixmap(IIJIIJIIIF[D[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_bltPixmap + (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, + jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, + jint compType, jfloat alpha, jdoubleArray matrix, jintArray clip, jint numVertex) +{ + XSetErrorHandler(error_handler); + + jdouble *mtrx = NULL, *inv = NULL; + + if(matrix != 0){ + mtrx = (jdouble *)malloc(6 * sizeof(jdouble)); + env->GetDoubleArrayRegion(matrix, 0, 6, mtrx); + + jdouble det = mtrx[0] * mtrx[3] - mtrx[1] * mtrx[2]; + + if(fabs(det) < ZERO){ + free(mtrx); + return; + } + + inv = (jdouble *)malloc(6 * sizeof(jdouble)); + inv[0] = mtrx[3] / det; + inv[1] = -mtrx[1] / det; + inv[2] = -mtrx[2] / det; + inv[3] = mtrx[0] / det; + inv[4] = (mtrx[2] * mtrx[5] - mtrx[3] * mtrx[4] ) / det; + inv[5] = (mtrx[1] * mtrx[4] - mtrx[0] * mtrx[5] ) / det; + } + + SURFACE_STRUCTURE *srcSurf = (SURFACE_STRUCTURE *)srcSurfStruct; + SURFACE_STRUCTURE *dstSurf = (SURFACE_STRUCTURE *)dstSurfStruct; + + Display *display = dstSurf->display; + Window root = XRootWindow(display, dstSurf->visual_info->screen); + + jint *verts = NULL; + XRectangle *rects = NULL; + int num_rects = 0; + + if(numVertex > 0){ + verts = (jint *)malloc(sizeof(jint)*numVertex); + env->GetIntArrayRegion(clip, 1, numVertex, verts); + + num_rects = numVertex >> 2; + rects = (XRectangle *)malloc(sizeof(XRectangle) * num_rects); + + for (int i = 0, j = 0; i < numVertex; i += 4, j++) { + rects[j].x = (short)verts[i]; + rects[j].y = (short)verts[i + 1]; + rects[j].width = (unsigned short)(verts[i+2]-verts[i]+1); + rects[j].height = (unsigned short)(verts[i+3]-verts[i+1]+1); + } + + free(verts); + } + + if(!matrix && (((compType == 2 || compType == 5) && alpha != 0) || + ((compType == 3 || compType == 10) && alpha == 1.0))){ + + XSetClipRectangles(display, dstSurf->gc, 0, 0, rects, num_rects, Unsorted); + XCopyArea(display, srcSurf->drawable, dstSurf->drawable, dstSurf->gc, srcX, srcY, width, height, dstX, dstY); + XFlush(display); + + if(rects) free(rects); + return; + } + +#ifdef _XRENDER_H_ + + if(hasXRender){ + + int op; + + switch(compType){ + case 1: + op = PictOpClear; + alpha = 1.0; + break; + case 2: + op = PictOpSrc; + if(alpha != 0) alpha = 1.0; + break; + case 3: + op = PictOpOver; + break; + case 4: + op = PictOpOverReverse; + alpha = 1.0; + break; + case 5: + op = PictOpIn; + if(alpha != 0) alpha = 1.0; + break; + case 6: + op = PictOpInReverse; + if(alpha != 0) alpha = 1.0; + break; + case 7: + op = PictOpOut; + alpha = 1.0; + break; + case 8: + op = PictOpOutReverse; + if(alpha != 1.0) alpha = 0; + break; + case 9: + op = PictOpDst; + alpha = 1.0; + break; + case 10: + op = PictOpAtop; + break; + case 11: + op = PictOpAtopReverse; + if(alpha != 0) alpha = 1.0; + break; + case 12: + op = PictOpXor; + if(alpha != 1.0) alpha = 0; + } + + XRenderPictFormat *srcFormat = XRenderFindVisualFormat (srcSurf->display, srcSurf->visual_info->visual); + Picture srcPict = XRenderCreatePicture(srcSurf->display, srcSurf->drawable, srcFormat, 0, NULL); + + XRenderPictFormat *dstFormat = XRenderFindVisualFormat (dstSurf->display, dstSurf->visual_info->visual); + Picture dstPict = XRenderCreatePicture(dstSurf->display, dstSurf->drawable, dstFormat, 0, NULL); + + Pixmap pixmap = 0; + + if(matrix != NULL){ + int _one = XDoubleToFixed( 1 ); + XTransform xform = {{ + { _one, 0, 0 }, + { 0, _one, 0 }, + { 0, 0, _one } + }}; + + xform.matrix[0][0] = XDoubleToFixed(inv[0]); + xform.matrix[1][1] = XDoubleToFixed(inv[3]); + xform.matrix[1][0] = XDoubleToFixed(inv[1]); + xform.matrix[0][1] = XDoubleToFixed(inv[2]); + + xform.matrix[0][2] = (int)(mtrx[4] + 0.5); + xform.matrix[1][2] = (int)(mtrx[5] + 0.5); + + free(mtrx); + free(inv); + + srcX -= xform.matrix[0][2]; + srcY -= xform.matrix[1][2]; + + pixmap = XCreatePixmap(display, root, srcSurf->width, srcSurf->height, 32); + + XRenderPictFormat *format = XRenderFindStandardFormat(display, PictStandardARGB32); + Picture picture = XRenderCreatePicture(display, pixmap, format, 0, NULL); + + XRenderComposite(display, PictOpSrc, srcPict, 0, picture, + 0, 0, 0, 0, 0, 0, srcSurf->width, srcSurf->height); + + XRenderFreePicture(display, srcPict); + srcPict = picture; + + XRenderSetPictureTransform( display, srcPict, &xform ); + XRenderSetPictureFilter(display, srcPict, FilterNearest, 0, 0); + } + + if(rects) XRenderSetPictureClipRectangles(display, dstPict, 0, 0, rects, num_rects); + + Picture alphaMask = 0; + + if(alpha != 1.0){ + XRenderColor c; + c.red = c.green = c.blue = 0; + c.alpha = (unsigned short)(((long)(alpha * 255 + 0.5)) << 8); + Pixmap am = XCreatePixmap(display, root, width, height, 8); + XRenderPictFormat *aformat = XRenderFindStandardFormat(display, PictStandardA8); + alphaMask = XRenderCreatePicture(display, am, aformat, 0, NULL); + XRenderFillRectangle(display, PictOpSrc, alphaMask, &c, 0, 0, width, height); + } + + XRenderComposite(display, op, srcPict, alphaMask, dstPict, + srcX, srcY, 0, 0, dstX, dstY, width, height); + + XFlush(display); + + if(alphaMask) XRenderFreePicture(display, alphaMask); + XRenderFreePicture(display, srcPict); + XRenderFreePicture(display, dstPict); + + if(pixmap) XFreePixmap(display, pixmap); + + if(rects) free(rects); + + } else { + +#endif + +#ifdef _XRENDER_H_ + + } + +#endif + +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.xorImage(IIJLjava/lang/Object;IIJIII[D[IIZ[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorImage + (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, jobject srcData, + jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, jint xorcolor, + jdoubleArray matrix, jintArray clip, jint numVertex, jboolean invalidated, + jintArray dirtyRegions, jint regCount) +{ +} + +/* + * Method: org.apache.harmony.awt.gl.linux.XBlitter.xorPixmap(IIJIIJIII[D[II)V + */ +JNIEXPORT void JNICALL +Java_org_apache_harmony_awt_gl_linux_XBlitter_xorPixmap + (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, + jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, jint xorcolor, + jdoubleArray matrix, jintArray clip, jint numVertex) +{ +} + Index: modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp =================================================================== --- modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp (revision 612414) +++ modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp (working copy) @@ -83,6 +83,10 @@ { unsigned int *src, *dst; +#ifdef unix + unsigned int *s, *d; +#endif + src_stride = srcSurf->scanline_stride; dst_stride = srcSurf->width; @@ -92,7 +96,16 @@ dst = (unsigned int *)bmpDataPtr + dst_offset; for(int _y = 0; _y < h; _y++, src += src_stride, dst += dst_stride){ +#ifdef _WIN32 memcpy(dst, src, w * sizeof(int)); +#endif + +#ifdef unix + s = src, d = dst; + for(int _x = 0; _x < w; _x++, s++, d++){ + *d = 0xff000000 | *s; + } +#endif } } break; @@ -668,10 +681,11 @@ env->ReleasePrimitiveArrayCritical(bandOffsets, p, 0); break; } + surf->invalidated = true; surf->bmp_byte_stride = surf->width << 2; - surf->invalidated = true; #ifdef _WIN32 + surf->bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); surf->bmpInfo.bmiHeader.biWidth = surf->width; surf->bmpInfo.bmiHeader.biHeight = -surf->height; Index: modules/awt/src/main/native/gl/shared/blitter.cpp =================================================================== --- modules/awt/src/main/native/gl/shared/blitter.cpp (revision 612414) +++ modules/awt/src/main/native/gl/shared/blitter.cpp (working copy) @@ -1489,6 +1489,94 @@ #endif +#ifdef unix + if(!srcSurf->ximage){ + if(XImageByteOrder(srcSurf->display) == LSBFirst){ + srcSurf->ximage = XGetImage(srcSurf->display, srcSurf->drawable, 0, 0, + srcSurf->width, srcSurf->height, ~(0L), ZPixmap); + }else{ + XImage *tmp = XGetImage(srcSurf->display, srcSurf->drawable, 0, 0, + 1, 1, ~(0L), ZPixmap); + + srcSurf->ximage = XCreateImage(srcSurf->display, srcSurf->visual_info->visual, + tmp->depth, tmp->format, tmp->xoffset, (char *)malloc(tmp->width * tmp->height * tmp->bytes_per_line), + srcSurf->width, srcSurf->height, tmp->bitmap_pad, 0); + + XDestroyImage(tmp); + + srcSurf->ximage->byte_order = LSBFirst; + + XGetSubImage(srcSurf->display, srcSurf->drawable, 0, 0, + srcSurf->width, srcSurf->height, ~(0L), ZPixmap, srcSurf->ximage, 0, 0); + } + srcSurf->scanline_stride_byte = srcSurf->ximage->bytes_per_line; + + char *info = (char *)srcSurf->visual_info; + int visual_class = (int)*((int *)(info + sizeof(Visual *) + sizeof(VisualID) + sizeof(int) + sizeof(unsigned int))); + int bpp = srcSurf->ximage->bits_per_pixel; + + switch(visual_class){ + case TrueColor: + case DirectColor: + if(bpp == 32){ + srcSurf->scanline_stride = srcSurf->scanline_stride_byte >> 2; + if(srcSurf->visual_info->red_mask == 0xff0000 && srcSurf->visual_info->green_mask == 0xff00 && + srcSurf->visual_info->blue_mask == 0xff){ + + srcSurf->ss_type = INT_RGB; + srcSurf->red_mask = 0xff0000; + srcSurf->green_mask = 0xff00; + srcSurf->blue_mask = 0xff; + } else if (srcSurf->visual_info->red_mask == 0xff && srcSurf->visual_info->green_mask == 0xff00 && + srcSurf->visual_info->blue_mask == 0xff0000){ + + srcSurf->ss_type = INT_BGR; + srcSurf->red_mask = 0xff; + srcSurf->green_mask = 0xff00; + srcSurf->blue_mask = 0xff0000; + } else { + srcSurf->ss_type = -1; + } + }else if(bpp == 16){ + srcSurf->scanline_stride = srcSurf->scanline_stride_byte >> 1; + if(srcSurf->visual_info->red_mask == 0x7c00 && srcSurf->visual_info->green_mask == 0x03e0 && + srcSurf->visual_info->blue_mask == 0x1f){ + + srcSurf->ss_type = USHORT_555; + srcSurf->red_mask = 0x7c00; + srcSurf->green_mask = 0x03e0; + srcSurf->blue_mask = 0x1f; + } else if (srcSurf->visual_info->red_mask == 0xf800 && srcSurf->visual_info->green_mask == 0x07e0 && + srcSurf->visual_info->blue_mask == 0x1f){ + + srcSurf->ss_type = USHORT_565; + srcSurf->red_mask = 0xf800; + srcSurf->green_mask = 0x07e0; + srcSurf->blue_mask = 0x1f; + } else { + srcSurf->ss_type = -1; + } + }else{ + srcSurf->ss_type = -1; + } + break; + case StaticGray: + case PseudoColor: + case GrayScale: + case StaticColor: + // TODO: Need to implement parsing of others visual types + srcSurf->ss_type = -1; + break; + default: + srcSurf->ss_type = -1; + } + } else { + XGetSubImage(srcSurf->display, srcSurf->drawable, 0, 0, + srcSurf->width, srcSurf->height, ~(0L), ZPixmap, srcSurf->ximage, 0, 0); + } + srcDataPtr = srcSurf->ximage->data; +#endif + srcType = srcSurf->ss_type; }else{ srcDataPtr = env->GetPrimitiveArrayCritical((jarray)srcData, 0); } Index: modules/awt/src/main/native/gl/shared/SurfaceDataStructure.h =================================================================== --- modules/awt/src/main/native/gl/shared/SurfaceDataStructure.h (revision 612414) +++ modules/awt/src/main/native/gl/shared/SurfaceDataStructure.h (working copy) @@ -27,9 +27,11 @@ #include #ifdef _WIN32 - #include "gl_GDIPlus.h" +#endif +#ifdef unix +#include "XSurfaceInfo.h" #endif // Color Space constants @@ -146,7 +148,7 @@ bool isAlphaPre; #ifdef _WIN32 - // VolataileImage + // WinVolataileImage GraphicsInfo *gi; GLBITMAPINFO bmpInfo; @@ -156,7 +158,17 @@ BOOL isTrueColor; #endif +#ifdef unix + // XVolatileImage + XImage *ximage; + Display *display; + Drawable drawable; + GC gc; + XVisualInfo *visual_info; +#endif + + }SURFACE_STRUCTURE; int parseMask(unsigned int, int *, int *);