FileDocCategorySizeDatePackage
GLThreadManager.javaAPI DocAndroid 5.1 API9677Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.legacy

GLThreadManager

public class GLThreadManager extends Object
GLThreadManager handles the thread used for rendering into the configured output surfaces.

Fields Summary
private final String
TAG
private static final boolean
DEBUG
private static final int
MSG_NEW_CONFIGURATION
private static final int
MSG_NEW_FRAME
private static final int
MSG_CLEANUP
private static final int
MSG_DROP_FRAMES
private static final int
MSG_ALLOW_FRAMES
private CaptureCollector
mCaptureCollector
private final CameraDeviceState
mDeviceState
private final SurfaceTextureRenderer
mTextureRenderer
private final RequestHandlerThread
mGLHandlerThread
private final RequestThreadManager.FpsCounter
mPrevCounter
private final Handler.Callback
mGLHandlerCb
Constructors Summary
public GLThreadManager(int cameraId, int facing, CameraDeviceState state)
Create a new GL thread and renderer.

param
cameraId the camera id for this thread.
param
facing direction the camera is facing.
param
state {@link CameraDeviceState} to use for error handling.


                                        
           
        mTextureRenderer = new SurfaceTextureRenderer(facing);
        TAG = String.format("CameraDeviceGLThread-%d", cameraId);
        mGLHandlerThread = new RequestHandlerThread(TAG, mGLHandlerCb);
        mDeviceState = state;
    
Methods Summary
public voidallowNewFrames()
Re-enable drawing new frames after a call to {@link #ignoreNewFrames()}.

        mGLHandlerThread.getHandler().sendEmptyMessage(MSG_ALLOW_FRAMES);
    
public android.graphics.SurfaceTexturegetCurrentSurfaceTexture()
Get the underlying surface to produce frames from.

This returns the surface that is drawn into the set of surfaces passed in for each frame. This method should only be called after a call to {@link #setConfigurationAndWait(java.util.Collection)}. Calling this before the first call to {@link #setConfigurationAndWait(java.util.Collection)}, after {@link #quit()}, or concurrently to one of these calls may result in an invalid {@link android.graphics.SurfaceTexture} being returned.

return
an {@link android.graphics.SurfaceTexture} to draw to.

        return mTextureRenderer.getSurfaceTexture();
    
public voidignoreNewFrames()
Ignore any subsequent calls to {@link #queueNewFrame(java.util.Collection)}.

        mGLHandlerThread.getHandler().sendEmptyMessage(MSG_DROP_FRAMES);
    
public voidqueueNewFrame()
Queue a new call to draw into the surfaces specified in the next available preview request from the {@link CaptureCollector} passed to {@link #setConfigurationAndWait(java.util.Collection, CaptureCollector)};

        Handler handler = mGLHandlerThread.getHandler();

        /**
         * Avoid queuing more than one new frame.  If we are not consuming faster than frames
         * are produced, drop frames rather than allowing the queue to back up.
         */
        if (!handler.hasMessages(MSG_NEW_FRAME)) {
            handler.sendMessage(handler.obtainMessage(MSG_NEW_FRAME));
        } else {
            Log.e(TAG, "GLThread dropping frame.  Not consuming frames quickly enough!");
        }
    
public voidquit()
Quit the thread.

No further methods can be called after this.

        Handler handler = mGLHandlerThread.getHandler();
        handler.sendMessageAtFrontOfQueue(handler.obtainMessage(MSG_CLEANUP));
        mGLHandlerThread.quitSafely();
        try {
            mGLHandlerThread.join();
        } catch (InterruptedException e) {
            Log.e(TAG, String.format("Thread %s (%d) interrupted while quitting.",
                    mGLHandlerThread.getName(), mGLHandlerThread.getId()));
        }
    
public voidsetConfigurationAndWait(java.util.Collection surfaces, CaptureCollector collector)
Configure the GL renderer for the given set of output surfaces, and block until this configuration has been applied.

param
surfaces a collection of pairs of {@link android.view.Surface}s and their corresponding sizes to configure.
param
collector a {@link CaptureCollector} to retrieve requests from.

        checkNotNull(collector, "collector must not be null");
        Handler handler = mGLHandlerThread.getHandler();

        final ConditionVariable condition = new ConditionVariable(/*closed*/false);
        ConfigureHolder configure = new ConfigureHolder(condition, surfaces, collector);

        Message m = handler.obtainMessage(MSG_NEW_CONFIGURATION, /*arg1*/0, /*arg2*/0, configure);
        handler.sendMessage(m);

        // Block until configuration applied.
        condition.block();
    
public voidstart()
Start the thread.

This must be called before queueing new frames.

        mGLHandlerThread.start();
    
public voidwaitUntilIdle()
Wait until no messages are queued.

        mGLHandlerThread.waitUntilIdle();
    
public voidwaitUntilStarted()
Wait until the thread has started.

        mGLHandlerThread.waitUntilStarted();