FileDocCategorySizeDatePackage
ImageSurface.javaAPI DocAndroid 1.5 API10474Wed May 06 22:41:54 BST 2009org.apache.harmony.awt.gl

ImageSurface

public class ImageSurface extends Surface implements org.apache.harmony.awt.gl.image.DataBufferListener
This class represent Surface for different types of Images (BufferedImage, OffscreenImage and so on)

Fields Summary
boolean
nativeDrawable
int
surfaceType
int
csType
ColorModel
cm
WritableRaster
raster
Object
data
boolean
needToRefresh
boolean
dataTaken
private long
cachedDataPtr
private boolean
alphaPre
Constructors Summary
public ImageSurface(ColorModel cm, WritableRaster raster)

         // Cached Image Data alpha premultiplied 

        
        this(cm, raster, Surface.getType(cm, raster));
    
public ImageSurface(ColorModel cm, WritableRaster raster, int type)

        if (!cm.isCompatibleRaster(raster)) {
            // awt.4D=The raster is incompatible with this ColorModel
            throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
        }
        this.cm = cm;
        this.raster = raster;
        surfaceType = type;

        data = AwtImageBackdoorAccessor.getInstance().
        getData(raster.getDataBuffer());
        ColorSpace cs = cm.getColorSpace();
        transparency = cm.getTransparency();
        width = raster.getWidth();
        height = raster.getHeight();

        // For the moment we can build natively only images which have 
        // sRGB, Linear_RGB, Linear_Gray Color Space and type different
        // from BufferedImage.TYPE_CUSTOM
        if(cs == LUTColorConverter.sRGB_CS){
            csType = sRGB_CS;
        }else if(cs == LUTColorConverter.LINEAR_RGB_CS){
            csType = Linear_RGB_CS;
        }else if(cs == LUTColorConverter.LINEAR_GRAY_CS){
            csType = Linear_Gray_CS;
        }else{
            csType = Custom_CS;
            nativeDrawable = false;
        }

        if(type == BufferedImage.TYPE_CUSTOM){
            nativeDrawable = false;
        }
    
Methods Summary
private voidcreateSufaceStructure()
Creates native Surface structure which used for native blitting

        int cmType = 0;
        int numComponents = cm.getNumComponents();
        boolean hasAlpha = cm.hasAlpha();
        boolean isAlphaPre = cm.isAlphaPremultiplied();
        int transparency = cm.getTransparency();
        int bits[] = cm.getComponentSize();
        int pixelStride = cm.getPixelSize();
        int masks[] = null;
        int colorMap[] = null;
        int colorMapSize = 0;
        int transpPixel = -1;
        boolean isGrayPallete = false;
        SampleModel sm = raster.getSampleModel();
        int smType = 0;
        int dataType = sm.getDataType();
        int scanlineStride = 0;
        int bankIndeces[] = null;
        int bandOffsets[] = null;
        int offset = raster.getDataBuffer().getOffset();

        if(cm instanceof DirectColorModel){
            cmType = DCM;
            DirectColorModel dcm = (DirectColorModel) cm;
            masks = dcm.getMasks();
            smType = SPPSM;
            SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
            scanlineStride = sppsm.getScanlineStride();

        }else if(cm instanceof IndexColorModel){
            cmType = ICM;
            IndexColorModel icm = (IndexColorModel) cm;
            colorMapSize = icm.getMapSize();
            colorMap = new int[colorMapSize];
            icm.getRGBs(colorMap);
            transpPixel = icm.getTransparentPixel();
            isGrayPallete = Surface.isGrayPallete(icm);

            if(sm instanceof MultiPixelPackedSampleModel){
                smType = MPPSM;
                MultiPixelPackedSampleModel mppsm =
                    (MultiPixelPackedSampleModel) sm;
                scanlineStride = mppsm.getScanlineStride();
            }else if(sm instanceof ComponentSampleModel){
                smType = CSM;
                ComponentSampleModel csm =
                    (ComponentSampleModel) sm;
                scanlineStride = csm.getScanlineStride();
            }else{
                // awt.4D=The raster is incompatible with this ColorModel
                throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
            }

        }else if(cm instanceof ComponentColorModel){
            cmType = CCM;
            if(sm instanceof ComponentSampleModel){
                ComponentSampleModel csm = (ComponentSampleModel) sm;
                scanlineStride = csm.getScanlineStride();
                bankIndeces = csm.getBankIndices();
                bandOffsets = csm.getBandOffsets();
                if(sm instanceof PixelInterleavedSampleModel){
                    smType = PISM;
                }else if(sm instanceof BandedSampleModel){
                    smType = BSM;
                }else{
                    smType = CSM;
                }
            }else{
                // awt.4D=The raster is incompatible with this ColorModel
                throw new IllegalArgumentException(Messages.getString("awt.4D")); //$NON-NLS-1$
            }

        }else{
            surfaceDataPtr = 0L;
            return;
        }
        surfaceDataPtr = createSurfStruct(surfaceType, width, height, cmType, csType, smType, dataType,
                numComponents, pixelStride, scanlineStride, bits, masks, colorMapSize,
                colorMap, transpPixel, isGrayPallete, bankIndeces, bandOffsets,
                offset, hasAlpha, isAlphaPre, transparency);
    
private native longcreateSurfStruct(int surfaceType, int width, int height, int cmType, int csType, int smType, int dataType, int numComponents, int pixelStride, int scanlineStride, int[] bits, int[] masks, int colorMapSize, int[] colorMap, int transpPixel, boolean isGrayPalette, int[] bankIndeces, int[] bandOffsets, int offset, boolean hasAlpha, boolean isAlphaPre, int transparency)

public voiddataChanged()

        needToRefresh = true;
        clearValidCaches();
    
public voiddataReleased()

        dataTaken = false;
        needToRefresh = true;
        clearValidCaches();
    
public voiddataTaken()

        dataTaken = true;
        needToRefresh = true;
        clearValidCaches();
    
public voiddispose()

        if(surfaceDataPtr != 0L){
            dispose(surfaceDataPtr);
            surfaceDataPtr = 0L;
        }
    
private native voiddispose(long structPtr)

public longgetCachedData(boolean alphaPre)

        if(nativeDrawable){
            if(cachedDataPtr == 0L || needToRefresh || this.alphaPre != alphaPre){
                cachedDataPtr = updateCache(getSurfaceDataPtr(), data, alphaPre);
                this.alphaPre = alphaPre;
                validate(); 
            }
        }
        return cachedDataPtr;
    
public java.awt.image.ColorModelgetColorModel()

        return cm;
    
public java.lang.ObjectgetData()

        return data;
    
public SurfacegetImageSurface()

        return this;
    
public java.awt.image.WritableRastergetRaster()

        return raster;
    
public longgetSurfaceDataPtr()

        if(surfaceDataPtr == 0L && nativeDrawable){
            createSufaceStructure();
        }
        return surfaceDataPtr;
    
public intgetSurfaceType()

        return surfaceType;
    
public voidinvalidate()

        needToRefresh = true;
        clearValidCaches();
    
public booleaninvalidated()

        return needToRefresh;
    
public booleanisNativeDrawable()

        return nativeDrawable;
    
public longlock()

        // TODO
        return 0;
    
private native voidsetImageSize(long structPtr, int width, int height)

public voidsetRaster(java.awt.image.WritableRaster r)
Supposes that new raster is compatible with an old one

param
r

        raster = r;
        data = AwtImageBackdoorAccessor.getInstance().getData(r.getDataBuffer());
        if (surfaceDataPtr != 0) {
            setImageSize(surfaceDataPtr, r.getWidth(), r.getHeight());
        }
        this.width = r.getWidth();
        this.height = r.getHeight();
    
public voidunlock()

        //TODO
    
private native longupdateCache(long structPtr, java.lang.Object data, boolean alphaPre)

public voidvalidate()

        if(!needToRefresh) {
            return;
        }
        if(!dataTaken){
            needToRefresh = false;
            AwtImageBackdoorAccessor ba = AwtImageBackdoorAccessor.getInstance();
            ba.validate(raster.getDataBuffer());
        }