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

Surface

public abstract class Surface extends Object implements Transparency
This class is super class for others types of Surfaces. Surface is storing data and data format description, that are using in blitting operations

Fields Summary
public static final int
sRGB_CS
public static final int
Linear_RGB_CS
public static final int
Linear_Gray_CS
public static final int
Custom_CS
public static final int
DCM
public static final int
ICM
public static final int
CCM
public static final int
SPPSM
public static final int
MPPSM
public static final int
CSM
public static final int
PISM
public static final int
BSM
private static final int
ALPHA_MASK
private static final int
RED_MASK
private static final int
GREEN_MASK
private static final int
BLUE_MASK
private static final int
RED_BGR_MASK
private static final int
GREEN_BGR_MASK
private static final int
BLUE_BGR_MASK
private static final int
RED_565_MASK
private static final int
GREEN_565_MASK
private static final int
BLUE_565_MASK
private static final int
RED_555_MASK
private static final int
GREEN_555_MASK
private static final int
BLUE_555_MASK
protected long
surfaceDataPtr
protected int
transparency
protected int
width
protected int
height
private final ArrayList
validCaches
This list contains caches with the data of this surface that are valid at the moment. Surface should clear this list when its data is updated. Caches may check if they are still valid using isCacheValid method. When cache gets data from the surface, it should call addValidCache method of the surface.
Constructors Summary
Methods Summary
public final voidaddValidCache(java.lang.Object cache)

        validCaches.add(cache);
    
protected final voidclearValidCaches()

        validCaches.clear();
    
public abstract voiddispose()
Dispose Native Surface data

protected voidfinalize()

        dispose();
    
public abstract java.awt.image.ColorModelgetColorModel()

public java.lang.ObjectgetData()
If Surface has Raster, this method returns data array of Raster's DataBuffer

return
- data array

        return null;
    
public intgetHeight()

        return height;
    
public static org.apache.harmony.awt.gl.SurfacegetImageSurface(java.awt.Image image)

        return AwtImageBackdoorAccessor.getInstance().getImageSurface(image);
    
public abstract org.apache.harmony.awt.gl.SurfacegetImageSurface()

public abstract java.awt.image.WritableRastergetRaster()

public longgetSurfaceDataPtr()


       
       
        // Syrface type. It is equal 
                                          // BufferedImge type
             
            
    
              
       
    
             
       
       

      
        return surfaceDataPtr;
    
public abstract intgetSurfaceType()

public intgetTransparency()

        return transparency;
    
public static intgetType(java.awt.image.ColorModel cm, java.awt.image.WritableRaster raster)
Computation type of BufferedImage or Surface

param
cm - ColorModel
param
raster - WritableRaste
return
- type of BufferedImage

        int transferType = cm.getTransferType();
        boolean hasAlpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        int csType = cs.getType();
        SampleModel sm = raster.getSampleModel();

        if(csType == ColorSpace.TYPE_RGB){
            if(cm instanceof DirectColorModel){
                DirectColorModel dcm = (DirectColorModel) cm;
                switch (transferType) {
                case DataBuffer.TYPE_INT:
                    if (dcm.getRedMask() == RED_MASK &&
                            dcm.getGreenMask() == GREEN_MASK &&
                            dcm.getBlueMask() == BLUE_MASK) {
                        if (!hasAlpha) {
                            return BufferedImage.TYPE_INT_RGB;
                        }
                        if (dcm.getAlphaMask() == ALPHA_MASK) {
                            if (dcm.isAlphaPremultiplied()) {
                                return BufferedImage.TYPE_INT_ARGB_PRE;
                            }
                            return BufferedImage.TYPE_INT_ARGB;
                        }
                        return BufferedImage.TYPE_CUSTOM;
                    } else if (dcm.getRedMask() == RED_BGR_MASK &&
                            dcm.getGreenMask() == GREEN_BGR_MASK &&
                            dcm.getBlueMask() == BLUE_BGR_MASK) {
                        if (!hasAlpha) {
                            return BufferedImage.TYPE_INT_BGR;
                        }
                    } else {
                        return BufferedImage.TYPE_CUSTOM;
                    }
                case DataBuffer.TYPE_USHORT:
                    if (dcm.getRedMask() == RED_555_MASK &&
                            dcm.getGreenMask() == GREEN_555_MASK &&
                            dcm.getBlueMask() == BLUE_555_MASK && !hasAlpha) {
                        return BufferedImage.TYPE_USHORT_555_RGB;
                    } else if (dcm.getRedMask() == RED_565_MASK &&
                            dcm.getGreenMask() == GREEN_565_MASK &&
                            dcm.getBlueMask() == BLUE_565_MASK) {
                        return BufferedImage.TYPE_USHORT_565_RGB;
                    }
                default:
                    return BufferedImage.TYPE_CUSTOM;
                }
            }else if(cm instanceof IndexColorModel){
                IndexColorModel icm = (IndexColorModel) cm;
                int pixelBits = icm.getPixelSize();
                if(transferType == DataBuffer.TYPE_BYTE){
                    if(sm instanceof MultiPixelPackedSampleModel && !hasAlpha &&
                        pixelBits < 5){
                            return BufferedImage.TYPE_BYTE_BINARY;
                    }else if(pixelBits == 8){
                        return BufferedImage.TYPE_BYTE_INDEXED;
                    }
                }
                return BufferedImage.TYPE_CUSTOM;
            }else if(cm instanceof ComponentColorModel){
                ComponentColorModel ccm = (ComponentColorModel) cm;
                if(transferType == DataBuffer.TYPE_BYTE &&
                        sm instanceof ComponentSampleModel){
                    ComponentSampleModel csm =
                        (ComponentSampleModel) sm;
                    int[] offsets = csm.getBandOffsets();
                    int[] bits = ccm.getComponentSize();
                    boolean isCustom = false;
                    for (int i = 0; i < bits.length; i++) {
                        if (bits[i] != 8 ||
                               offsets[i] != offsets.length - 1 - i) {
                            isCustom = true;
                            break;
                        }
                    }
                    if (!isCustom) {
                        if (!ccm.hasAlpha()) {
                            return BufferedImage.TYPE_3BYTE_BGR;
                        } else if (ccm.isAlphaPremultiplied()) {
                            return BufferedImage.TYPE_4BYTE_ABGR_PRE;
                        } else {
                            return BufferedImage.TYPE_4BYTE_ABGR;
                        }
                    }
                }
                return BufferedImage.TYPE_CUSTOM;
            }
            return BufferedImage.TYPE_CUSTOM;
        }else if(cs == LUTColorConverter.LINEAR_GRAY_CS){
            if(cm instanceof ComponentColorModel &&
                    cm.getNumComponents() == 1){
                int bits[] = cm.getComponentSize();
                if(transferType == DataBuffer.TYPE_BYTE &&
                        bits[0] == 8){
                    return BufferedImage.TYPE_BYTE_GRAY;
                }else if(transferType == DataBuffer.TYPE_USHORT &&
                        bits[0] == 16){
                    return BufferedImage.TYPE_USHORT_GRAY;
                }else{
                    return BufferedImage.TYPE_CUSTOM;
                }
            }
            return BufferedImage.TYPE_CUSTOM;
        }
        return BufferedImage.TYPE_CUSTOM;
    
public intgetWidth()

        return width;
    
public voidinvalidate()

public booleaninvalidated()

        return true;
    
public final booleanisCaheValid(java.lang.Object cache)

        return validCaches.contains(cache);
    
public static booleanisGrayPallete(java.awt.image.IndexColorModel icm)

        return AwtImageBackdoorAccessor.getInstance().isGrayPallete(icm);
    
public booleanisNativeDrawable()
Returns could or coldn't the Surface be blit by Native blitter

return
- true if the Surface could be blit by Native blitter, false in other case

        return true;
    
public abstract longlock()
Lock Native Surface data

public abstract voidunlock()
Unlock Native Surface data

public voidvalidate()