FileDocCategorySizeDatePackage
EffectContext.javaAPI DocAndroid 5.1 API4925Thu Mar 12 22:22:30 GMT 2015android.media.effect

EffectContext

public class EffectContext extends Object

An EffectContext keeps all necessary state information to run Effects within a Open GL ES 2.0 context.

Every EffectContext is bound to one GL context. The application is responsible for creating this EGL context, and making it current before applying any effect. If your EGL context is destroyed, the EffectContext becomes invalid and any effects bound to this context can no longer be used. If you switch to another EGL context, you must create a new EffectContext. Each Effect is bound to a single EffectContext, and can only be executed in that context.

Fields Summary
private final int
GL_STATE_FBO
private final int
GL_STATE_PROGRAM
private final int
GL_STATE_ARRAYBUFFER
private final int
GL_STATE_COUNT
android.filterfw.core.FilterContext
mFilterContext
private EffectFactory
mFactory
private int[]
mOldState
Constructors Summary
private EffectContext()

        mFilterContext = new FilterContext();
        mFilterContext.setFrameManager(new CachedFrameManager());
        mFactory = new EffectFactory(this);
    
Methods Summary
final voidassertValidGLState()

        GLEnvironment glEnv = mFilterContext.getGLEnvironment();
        if (glEnv == null || !glEnv.isContextActive()) {
            if (GLEnvironment.isAnyContextActive()) {
                throw new RuntimeException("Applying effect in wrong GL context!");
            } else {
                throw new RuntimeException("Attempting to apply effect without valid GL context!");
            }
        }
    
public static android.media.effect.EffectContextcreateWithCurrentGlContext()
Creates a context within the current GL context.

Binds the EffectContext to the current OpenGL context. All subsequent calls to the EffectContext must be made in the GL context that was active during creation. When you have finished using a context, you must call {@link #release()}. to dispose of all resources associated with this context.


                                                                
        
        EffectContext result = new EffectContext();
        result.initInCurrentGlContext();
        return result;
    
public EffectFactorygetFactory()
Returns the EffectFactory for this context.

The EffectFactory returned from this method allows instantiating new effects within this context.

return
The EffectFactory instance for this context.

        return mFactory;
    
private voidinitInCurrentGlContext()

        if (!GLEnvironment.isAnyContextActive()) {
            throw new RuntimeException("Attempting to initialize EffectContext with no active "
                + "GL context!");
        }
        GLEnvironment glEnvironment = new GLEnvironment();
        glEnvironment.initWithCurrentContext();
        mFilterContext.initGLEnvironment(glEnvironment);
    
public voidrelease()
Releases the context.

Releases all the resources and effects associated with the EffectContext. This renders the context and all the effects bound to this context invalid. You must no longer use the context or any of its bound effects after calling release().

Note that this method must be called with the proper EGL context made current, as the EffectContext and its effects may release internal GL resources.

        mFilterContext.tearDown();
        mFilterContext = null;
    
final voidrestoreGLState()

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mOldState[GL_STATE_FBO]);
        GLES20.glUseProgram(mOldState[GL_STATE_PROGRAM]);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mOldState[GL_STATE_ARRAYBUFFER]);
    
final voidsaveGLState()

        GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, mOldState, GL_STATE_FBO);
        GLES20.glGetIntegerv(GLES20.GL_CURRENT_PROGRAM, mOldState, GL_STATE_PROGRAM);
        GLES20.glGetIntegerv(GLES20.GL_ARRAY_BUFFER_BINDING, mOldState, GL_STATE_ARRAYBUFFER);