FileDocCategorySizeDatePackage
XLibRenderer.javaAPI DocJMF 2.1.1e7345Mon May 12 12:21:24 BST 2003com.sun.media.renderer.video

XLibRenderer

public class XLibRenderer extends BasicVideoRenderer implements DynamicPlugIn

Fields Summary
private static boolean
available
private static int
jawtAvail
private int
blitter
protected Object
data
private int
defBitsPerPixel
private int
defRedMask
private int
defGreenMask
private int
defBlueMask
private int
offsetX
private int
offsetY
private int
bytesPerPixel
private int
bitsPerPixel
private int
rMask
private int
gMask
private int
bMask
private int
pixelStride
private int
lineStride
private int
lastOutWidth
private int
lastOutHeight
private boolean
firstTime
protected VideoFormat
defaultFormat
Constructors Summary
public XLibRenderer()


      
	super("XLib Renderer");
	try {
	    JMFSecurityManager.loadLibrary("jmutil");
	    JMFSecurityManager.loadLibrary("jmxlib");
	} catch (Exception e) {
	    e.printStackTrace();
	    available = false;
	} catch (UnsatisfiedLinkError ule) {
	    ule.printStackTrace();
	    available = false;
	}
	if (!available)
	    throw new RuntimeException("Could not load jmxlib library");
	xlibSetJAWT(jawtAvail);
	if (xlibInitialize()) {
	    ColorModel cm = Toolkit.getDefaultToolkit().getColorModel();
	    if (!(cm instanceof DirectColorModel))
		throw new RuntimeException("Cannot render to non-TrueColor visuals");

	    DirectColorModel dcm = (DirectColorModel) cm;
	    int pixelStride = 1;
	    defBitsPerPixel = dcm.getPixelSize();
	    Class arrayType = Format.intArray;
	    if (defBitsPerPixel == 16 || defBitsPerPixel == 15) {
		defBitsPerPixel = 16;
		arrayType = Format.shortArray;
		bytesPerPixel = 2;
	    }
	    if (defBitsPerPixel == 24) {
		defBitsPerPixel = 32;
		arrayType = Format.intArray;
	    }

	    defRedMask = dcm.getRedMask();
	    defBlueMask = dcm.getBlueMask();
	    defGreenMask = dcm.getGreenMask();
	    
	    defaultFormat = new RGBFormat(null, Format.NOT_SPECIFIED,
					  arrayType,
					  Format.NOT_SPECIFIED, // frame rate
					  defBitsPerPixel, 
					  defRedMask, defGreenMask, defBlueMask,
					  pixelStride,
					  Format.NOT_SPECIFIED,
					  Format.FALSE, // flipped
					  Format.NOT_SPECIFIED); // endian
	    supportedFormats = new VideoFormat[1];
	    supportedFormats[0] = defaultFormat;
	    close();
	} else {
	    available = false;
	}
    
Methods Summary
public voidclose()

	if (available && blitter != 0) {
	    xlibFree();
	}
    
protected intdoProcess(javax.media.Buffer buffer)

	return doProcess(buffer, false);
    
protected intdoProcess(javax.media.Buffer buffer, boolean repaint)

	boolean resetOutputSize = false;
	if (!available || component == null)
	    return BUFFER_PROCESSED_OK;
	if (!repaint) {
	    if (!buffer.getFormat().equals(inputFormat)) {
		if (setInputFormat(buffer.getFormat()) == null)
		    return BUFFER_PROCESSED_FAILED;
	    }

	    data = getInputData(buffer);
	} else
	    if (data == null)
		return BUFFER_PROCESSED_FAILED;

	synchronized (this) {
	    if (!componentAvailable || data == null)
		return BUFFER_PROCESSED_OK;
	    if (blitter == 0 || firstTime) {
		int handle = 0;
		firstTime = false;
		if (blitter == 0) {
		    handle = com.sun.media.util.WindowUtil.getWindowHandle(component);
		    if (handle == 0)
			return BUFFER_PROCESSED_OK;
		    //System.err.println("handle is " + handle);
		    xlibInitialize();
		    xlibSetComponent(component);
		    xlibSetInputFormat(inWidth, inHeight, lineStride);
		    resetOutputSize = true;
		    // Reset it to force calling setInputFormat
		    inputFormat = new VideoFormat(null);
		}
		if (blitter == 0) {
		    return BUFFER_PROCESSED_FAILED;
		}
	    }
	    
	    if (outWidth > 0 && outHeight > 0) {
		if (outWidth != lastOutWidth || outHeight != lastOutHeight || resetOutputSize) {
		    outWidth &= ~1;
		    lastOutWidth = outWidth;
		    lastOutHeight = outHeight;
		    if (blitter != 0)
			xlibSetOutputSize(outWidth, outHeight);
		}
		long dataBytes = getNativeData(data);
		if (data == null)
		    return BUFFER_PROCESSED_OK;
		return (xlibDraw(data, dataBytes, bytesPerPixel))?
		    BUFFER_PROCESSED_OK : BUFFER_PROCESSED_FAILED;
	    } else
		return BUFFER_PROCESSED_FAILED;
	}
    
public javax.media.Format[]getBaseInputFormats()

	Format [] formats = new Format[1];
	formats[0] = new RGBFormat();
	return formats;
    
public javax.media.Format[]getBaseOutputFormats()

	Format [] formats = new Format[0];
	return formats;
    
public voidopen()


	if (!available)
	    throw new ResourceUnavailableException("XLib not available");
    
protected synchronized voidremovingComponent()

	if (blitter != 0) {
	    xlibFree();
	}
    
protected synchronized voidrepaint()

	if (!isStarted() && data != null)
	    doProcess(null, true);
    
public voidreset()

    
public javax.media.FormatsetInputFormat(javax.media.Format format)
Set the data input format.

return
false if the format is not supported.

	if (!available)
	    return null;
	if (!(format instanceof RGBFormat))
	    return null;
	if (!(Toolkit.getDefaultToolkit().getColorModel() instanceof DirectColorModel))
	    return null;
	if (super.setInputFormat(format) != null) {
	    if (inputFormat instanceof RGBFormat) {
		RGBFormat rgbf = (RGBFormat) inputFormat;
		bitsPerPixel = rgbf.getBitsPerPixel();
		rMask = rgbf.getRedMask();
		gMask = rgbf.getGreenMask();
		bMask = rgbf.getBlueMask();
		lineStride = rgbf.getLineStride();
		pixelStride = rgbf.getPixelStride();
	    } else if (inputFormat instanceof IndexedColorFormat) {
		lineStride = ((IndexedColorFormat)format).getLineStride();
	    } else
		return null;

	    // Inform the native code of the input format change
	    synchronized (this) {
		if (blitter != 0) {
		    xlibSetInputFormat(inWidth, inHeight, lineStride);
		}
	    }
	    
	    if (outWidth == -1 || outHeight == -1) {
		outWidth = inWidth;
		outHeight = inHeight;
	    }

	    if (component != null)
		component.setSize(outWidth, outHeight);
	    // All's well
	    return format;
	} else {
	    // Unsupported format
	    return null;
	}
    
private native synchronized booleanxlibDraw(java.lang.Object data, long dataBytes, int aes)

private native synchronized booleanxlibFree()

private native synchronized booleanxlibInitialize()

private native synchronized booleanxlibSetComponent(java.lang.Object component)

private native synchronized booleanxlibSetInputFormat(int width, int height, int strideX)

private native voidxlibSetJAWT(int jawt)

private native synchronized booleanxlibSetOutputSize(int width, int height)