FileDocCategorySizeDatePackage
DisplayEventReceiver.javaAPI DocAndroid 5.1 API4730Thu Mar 12 22:22:10 GMT 2015android.view

DisplayEventReceiver

public abstract class DisplayEventReceiver extends Object
Provides a low-level mechanism for an application to receive display events such as vertical sync. The display event receive is NOT thread safe. Moreover, its methods must only be called on the Looper thread to which it is attached.
hide

Fields Summary
private static final String
TAG
private final dalvik.system.CloseGuard
mCloseGuard
private long
mReceiverPtr
private android.os.MessageQueue
mMessageQueue
Constructors Summary
public DisplayEventReceiver(android.os.Looper looper)
Creates a display event receiver.

param
looper The looper to use when invoking callbacks.


         
             
         
         

                       
       
        if (looper == null) {
            throw new IllegalArgumentException("looper must not be null");
        }

        mMessageQueue = looper.getQueue();
        mReceiverPtr = nativeInit(this, mMessageQueue);

        mCloseGuard.open("dispose");
    
Methods Summary
private voiddispatchHotplug(long timestampNanos, int builtInDisplayId, boolean connected)

        onHotplug(timestampNanos, builtInDisplayId, connected);
    
private voiddispatchVsync(long timestampNanos, int builtInDisplayId, int frame)

        onVsync(timestampNanos, builtInDisplayId, frame);
    
public voiddispose()
Disposes the receiver.

        dispose(false);
    
private voiddispose(boolean finalized)

        if (mCloseGuard != null) {
            if (finalized) {
                mCloseGuard.warnIfOpen();
            }
            mCloseGuard.close();
        }

        if (mReceiverPtr != 0) {
            nativeDispose(mReceiverPtr);
            mReceiverPtr = 0;
        }
        mMessageQueue = null;
    
protected voidfinalize()

        try {
            dispose(true);
        } finally {
            super.finalize();
        }
    
private static native voidnativeDispose(long receiverPtr)

private static native longnativeInit(android.view.DisplayEventReceiver receiver, android.os.MessageQueue messageQueue)

private static native voidnativeScheduleVsync(long receiverPtr)

public voidonHotplug(long timestampNanos, int builtInDisplayId, boolean connected)
Called when a display hotplug event is received.

param
timestampNanos The timestamp of the event, in the {@link System#nanoTime()} timebase.
param
builtInDisplayId The surface flinger built-in display id such as {@link SurfaceControl#BUILT_IN_DISPLAY_ID_HDMI}.
param
connected True if the display is connected, false if it disconnected.

    
public voidonVsync(long timestampNanos, int builtInDisplayId, int frame)
Called when a vertical sync pulse is received. The recipient should render a frame and then call {@link #scheduleVsync} to schedule the next vertical sync pulse.

param
timestampNanos The timestamp of the pulse, in the {@link System#nanoTime()} timebase.
param
builtInDisplayId The surface flinger built-in display id such as {@link SurfaceControl#BUILT_IN_DISPLAY_ID_MAIN}.
param
frame The frame number. Increases by one for each vertical sync interval.

    
public voidscheduleVsync()
Schedules a single vertical sync pulse to be delivered when the next display frame begins.

        if (mReceiverPtr == 0) {
            Log.w(TAG, "Attempted to schedule a vertical sync pulse but the display event "
                    + "receiver has already been disposed.");
        } else {
            nativeScheduleVsync(mReceiverPtr);
        }