1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.android.exoplayer2.transformer; 17 18 import android.util.Size; 19 import java.io.IOException; 20 21 /** 22 * Manages a GLSL shader program for processing a frame. 23 * 24 * <p>Methods must be called in the following order: 25 * 26 * <ol> 27 * <li>The constructor, for implementation-specific arguments. 28 * <li>{@link #initialize(int,int,int)}, to set up graphics initialization. 29 * <li>{@link #updateProgramAndDraw(long)}, to process one frame. 30 * <li>{@link #release()}, upon conclusion of processing. 31 * </ol> 32 */ 33 public interface GlFrameProcessor { 34 35 /** 36 * Performs all initialization that requires OpenGL, such as, loading and compiling a GLSL shader 37 * program. 38 * 39 * <p>This method may only be called if there is a current OpenGL context. 40 * 41 * @param inputTexId Identifier of a 2D OpenGL texture. 42 * @param inputWidth The input width, in pixels. 43 * @param inputHeight The input height, in pixels. 44 */ initialize(int inputTexId, int inputWidth, int inputHeight)45 void initialize(int inputTexId, int inputWidth, int inputHeight) throws IOException; 46 47 /** 48 * Returns the output {@link Size} of frames processed through {@link 49 * #updateProgramAndDraw(long)}. 50 * 51 * <p>This method may only be called after the frame processor has been {@link 52 * #initialize(int,int,int) initialized}. 53 */ getOutputSize()54 Size getOutputSize(); 55 56 /** 57 * Updates the shader program's vertex attributes and uniforms, binds them, and draws. 58 * 59 * <p>This method may only be called after the frame processor has been {@link 60 * #initialize(int,int,int) initialized}. The caller is responsible for focussing the correct 61 * render target before calling this method. 62 * 63 * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds. 64 */ updateProgramAndDraw(long presentationTimeUs)65 void updateProgramAndDraw(long presentationTimeUs); 66 67 /** Releases all resources. */ release()68 void release(); 69 } 70