use of com.android.grafika.gles.Texture2dProgram in project grafika by google.
the class TextureMovieEncoder method prepareEncoder.
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, File outputFile) {
try {
mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
mInputWindowSurface.makeCurrent();
mFullScreen = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
use of com.android.grafika.gles.Texture2dProgram in project grafika by google.
the class CameraSurfaceRenderer method onSurfaceCreated.
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
Log.d(TAG, "onSurfaceCreated");
// We're starting up or coming back. Either way we've got a new EGLContext that will
// need to be shared with the video encoder, so figure out if a recording is already
// in progress.
mRecordingEnabled = mVideoEncoder.isRecording();
if (mRecordingEnabled) {
mRecordingStatus = RECORDING_RESUMED;
} else {
mRecordingStatus = RECORDING_OFF;
}
// Set up the texture blitter that will be used for on-screen display. This
// is *not* applied to the recording, because that uses a separate shader.
mFullScreen = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
mTextureId = mFullScreen.createTextureObject();
// Create a SurfaceTexture, with an external texture, in this EGL context. We don't
// have a Looper in this thread -- GLSurfaceView doesn't create one -- so the frame
// available messages will arrive on the main thread.
mSurfaceTexture = new SurfaceTexture(mTextureId);
// Tell the UI thread to enable the camera preview.
mCameraHandler.sendMessage(mCameraHandler.obtainMessage(CameraCaptureActivity.CameraHandler.MSG_SET_SURFACE_TEXTURE, mSurfaceTexture));
}
use of com.android.grafika.gles.Texture2dProgram in project grafika by google.
the class TextureMovieEncoder method handleUpdateSharedContext.
/**
* Tears down the EGL surface and context we've been using to feed the MediaCodec input
* surface, and replaces it with a new one that shares with the new context.
* <p>
* This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
* that got torn down) and we need to hook up with the new one.
*/
private void handleUpdateSharedContext(EGLContext newSharedContext) {
Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);
// Release the EGLSurface and EGLContext.
mInputWindowSurface.releaseEglSurface();
mFullScreen.release(false);
mEglCore.release();
// Create a new EGLContext and recreate the window surface.
mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
mInputWindowSurface.recreate(mEglCore);
mInputWindowSurface.makeCurrent();
// Create new programs and such for the new context.
mFullScreen = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
use of com.android.grafika.gles.Texture2dProgram in project grafika by google.
the class ContinuousCaptureActivity method surfaceCreated.
// SurfaceHolder.Callback
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated holder=" + holder);
// Set up everything that requires an EGL context.
//
// We had to wait until we had a surface because you can't make an EGL context current
// without one, and creating a temporary 1x1 pbuffer is a waste of time.
//
// The display surface that we use for the SurfaceView, and the encoder surface we
// use for video, use the same EGL context.
mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
mDisplaySurface = new WindowSurface(mEglCore, holder.getSurface(), false);
mDisplaySurface.makeCurrent();
mFullFrameBlit = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
mTextureId = mFullFrameBlit.createTextureObject();
mCameraTexture = new SurfaceTexture(mTextureId);
mCameraTexture.setOnFrameAvailableListener(this);
Log.d(TAG, "starting camera preview");
try {
mCamera.setPreviewTexture(mCameraTexture);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mCamera.startPreview();
// (can we guarantee that camera preview size is compatible with AVC video encoder?)
try {
mCircEncoder = new CircularEncoder(VIDEO_WIDTH, VIDEO_HEIGHT, 6000000, mCameraPreviewThousandFps / 1000, 7, mHandler);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
mEncoderSurface = new WindowSurface(mEglCore, mCircEncoder.getInputSurface(), true);
updateControls();
}
use of com.android.grafika.gles.Texture2dProgram in project grafika by google.
the class CameraSurfaceRenderer method updateFilter.
/**
* Updates the filter program.
*/
public void updateFilter() {
Texture2dProgram.ProgramType programType;
float[] kernel = null;
float colorAdj = 0.0f;
Log.d(TAG, "Updating filter to " + mNewFilter);
switch(mNewFilter) {
case CameraCaptureActivity.FILTER_NONE:
programType = Texture2dProgram.ProgramType.TEXTURE_EXT;
break;
case CameraCaptureActivity.FILTER_BLACK_WHITE:
// (In a previous version the TEXTURE_EXT_BW variant was enabled by a flag called
// ROSE_COLORED_GLASSES, because the shader set the red channel to the B&W color
// and green/blue to zero.)
programType = Texture2dProgram.ProgramType.TEXTURE_EXT_BW;
break;
case CameraCaptureActivity.FILTER_BLUR:
programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
kernel = new float[] { 1f / 16f, 2f / 16f, 1f / 16f, 2f / 16f, 4f / 16f, 2f / 16f, 1f / 16f, 2f / 16f, 1f / 16f };
break;
case CameraCaptureActivity.FILTER_SHARPEN:
programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
kernel = new float[] { 0f, -1f, 0f, -1f, 5f, -1f, 0f, -1f, 0f };
break;
case CameraCaptureActivity.FILTER_EDGE_DETECT:
programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
kernel = new float[] { -1f, -1f, -1f, -1f, 8f, -1f, -1f, -1f, -1f };
break;
case CameraCaptureActivity.FILTER_EMBOSS:
programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
kernel = new float[] { 2f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, -1f };
colorAdj = 0.5f;
break;
default:
throw new RuntimeException("Unknown filter mode " + mNewFilter);
}
// too -- compiling a program could be expensive.)
if (programType != mFullScreen.getProgram().getProgramType()) {
mFullScreen.changeProgram(new Texture2dProgram(programType));
// If we created a new program, we need to initialize the texture width/height.
mIncomingSizeUpdated = true;
}
// Update the filter kernel (if any).
if (kernel != null) {
mFullScreen.getProgram().setKernel(kernel, colorAdj);
}
mCurrentFilter = mNewFilter;
}
Aggregations