FileDocCategorySizeDatePackage
PiscesGCISurface.javaAPI DocphoneME MR2 API (J2ME)8132Wed May 02 18:00:36 BST 2007com.sun.pisces

PiscesGCISurface

public final class PiscesGCISurface extends AbstractSurface
Wrapper for GCIDrawingSurface for Pisces rendering.
see
PiscesShapeRenderer

Fields Summary
private long
nativeArray
Pointer to native image data. Accessed from native code. This field is used when GCISurface stores image data in a buffer allocated by native code.
private int[]
javaArrayInt
Java image data arrays for different image-types. GCIDrawingSurface uses different Java arrays to store data. The real data-type used depends on image-type. Accessed from native code.
private short[]
javaArrayShort
private byte[]
javaArrayByte
private int
typeOfArray
This property says which of previously declared data arrays (nativeArray, javaArrayInt, javaArrayShort, javaArrayByte) is currently used to store image-data. This is set in acquireSurface() accordingly to underlying GCIDrawingSurface properties. The value is also used in native code for acquirement of appropriate image memory from java. Values must be one of the following TYPE_OF_ARRAY_. Another value is errorneous.
public static final int
TYPE_OF_ARRAY_NATIVE
Field's @typeOfArray possible values. Corresponding #defines are used in native code. If you modify them here, please, make relevant changes to JPiscesGCISurface.c also.
public static final int
TYPE_OF_ARRAY_JAVA_INT
public static final int
TYPE_OF_ARRAY_JAVA_SHORT
public static final int
TYPE_OF_ARRAY_JAVA_BYTE
private final com.sun.me.gci.surface.GCIDrawingSurface
gciSurface
Underlying GCIDrawingSurface. This is destination of our rendering.
private com.sun.me.gci.surface.GCISurfaceInfo
gciSurfaceInfo
The GCISurfaceInfo of gciSurface held between calls to acquireSurface and releaseSurface.
private final int
imageType
private final int
bitsToPixelsShift
How much to right-shift value in bits to get value in pixels.
private int
offset
private int
scanlineStride
private int
pixelStride
Constructors Summary
public PiscesGCISurface(com.sun.me.gci.surface.GCIDrawingSurface surface)
Instantiates wrapper class of GCIDrawingSurface for Pisces rendering. It acquires all needed information from surface and ensures initialization of native pisces surface structures.

param
surface
see
GCIDrawingSurface

    
                                                             
       
        gciSurface = surface;
        
        switch (surface.getFormat()) {
            case GCIDrawingSurface.FORMAT_RGB_888:
            case GCIDrawingSurface.FORMAT_XRGB_8888:
            case GCIDrawingSurface.FORMAT_ARGB_8888:
                imageType = RendererBase.TYPE_INT_RGB;
                bitsToPixelsShift = 5;  // 2 ^ 5 = 32
                break;
            case GCIDrawingSurface.FORMAT_RGB_565:
                imageType = RendererBase.TYPE_USHORT_565_RGB;
                bitsToPixelsShift = 4; // 2 ^ 4 = 16
                break;
            case GCIDrawingSurface.FORMAT_GRAY_8:
                imageType = RendererBase.TYPE_BYTE_GRAY;
                bitsToPixelsShift = 3; // 2 ^ 3 = 8
                break;
            case GCIDrawingSurface.FORMAT_ARGB_8888_PRE:
                imageType = RendererBase.TYPE_INT_ARGB_PRE;
                bitsToPixelsShift = 5; // 2 ^ 5 = 32
                break;
            default:
                throw new IllegalArgumentException("Pisces does not support"
                        + " " + surface.getFormat() + " yet") ;
        }

        int width = surface.getWidth();
        int height = surface.getHeight();

        if (surface.isSurfaceInfoDynamic()) {
            initialize(imageType, width, height, true);
        } else {
            // acquire surface once
            acquireSurface();
            initialize(imageType, width, height, false);
        }
    
Methods Summary
public voidacquireSurface()
Gets all neccessary information from GCIDrawingSurface. Anytime surface changes at runtime. This method must be called to ensure pisces and GCI surfaces synchronization.

        if (gciSurfaceInfo != null) {
            // we have already acquired the surface
            return;
        }
        gciSurfaceInfo = gciSurface.getSurfaceInfo();    
        if (gciSurfaceInfo == null) {
            throw new RuntimeException("Unable to get surface information");
        }

        offset = gciSurfaceInfo.getBitOffset() >> bitsToPixelsShift;
        scanlineStride = 
                gciSurfaceInfo.getYBitStride() >> bitsToPixelsShift;
        pixelStride =
                gciSurfaceInfo.getXBitStride() >> bitsToPixelsShift; 
        
        if (gciSurface.isNativeSurface()) {
            typeOfArray = TYPE_OF_ARRAY_NATIVE;
            nativeArray = gciSurfaceInfo.getBasePointer();
        } else {            
            switch (gciSurfaceInfo.getPixelArrayType()) {
                case GCISurfaceInfo.TYPE_JAVA_ARRAY_INT:
                    javaArrayInt = (int[])gciSurfaceInfo.getPixelArray();
                    typeOfArray = TYPE_OF_ARRAY_JAVA_INT;
                    break;
                case GCISurfaceInfo.TYPE_JAVA_ARRAY_SHORT:
                    javaArrayShort = (short[])gciSurfaceInfo.getPixelArray();
                    typeOfArray = TYPE_OF_ARRAY_JAVA_SHORT;
                    break;    
                case GCISurfaceInfo.TYPE_JAVA_ARRAY_BYTE:
                    javaArrayByte = (byte[])gciSurfaceInfo.getPixelArray();
                    typeOfArray = TYPE_OF_ARRAY_JAVA_BYTE;
                    break;    
                default:
                    break;    
            }
        }
    
private native voidinitialize(int imageType, int width, int height, boolean isDynamic)
This method initializes (C-native-code) underlying pisces surface/renderer structures.

see
JPiscesGCISurface.c source on details.

public voidreleaseSurface()
Detaches (releases) underlying GCIDrawing surface and resets Pisces native surface structures. No rendering is possible after releaseSurface().

        if (gciSurfaceInfo != null) {
            // allow garbage collection
            javaArrayByte = null;
            javaArrayInt = null;
            javaArrayShort = null;

            nativeArray = 0;

            gciSurfaceInfo.release();
            gciSurfaceInfo = null;
        }