use of android.graphics.SurfaceTexture in project platform_frameworks_base by android.
the class SurfaceTextureRenderer method configureSurfaces.
/**
* Set a collection of output {@link Surface}s that can be drawn to.
*
* @param surfaces a {@link Collection} of surfaces.
*/
public void configureSurfaces(Collection<Pair<Surface, Size>> surfaces) {
releaseEGLContext();
if (surfaces == null || surfaces.size() == 0) {
Log.w(TAG, "No output surfaces configured for GL drawing.");
return;
}
for (Pair<Surface, Size> p : surfaces) {
Surface s = p.first;
Size surfaceSize = p.second;
// If pixel conversions aren't handled by egl, use a pbuffer
try {
EGLSurfaceHolder holder = new EGLSurfaceHolder();
holder.surface = s;
holder.width = surfaceSize.getWidth();
holder.height = surfaceSize.getHeight();
if (LegacyCameraDevice.needsConversion(s)) {
mConversionSurfaces.add(holder);
// LegacyCameraDevice is the producer of surfaces if it's not handled by EGL,
// so LegacyCameraDevice needs to connect to the surfaces.
LegacyCameraDevice.connectSurface(s);
} else {
mSurfaces.add(holder);
}
} catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
Log.w(TAG, "Surface abandoned, skipping configuration... ", e);
}
}
// Set up egl display
configureEGLContext();
// Set up regular egl surfaces if needed
if (mSurfaces.size() > 0) {
configureEGLOutputSurfaces(mSurfaces);
}
// Set up pbuffer surface if needed
if (mConversionSurfaces.size() > 0) {
configureEGLPbufferSurfaces(mConversionSurfaces);
}
makeCurrent((mSurfaces.size() > 0) ? mSurfaces.get(0).eglSurface : mConversionSurfaces.get(0).eglSurface);
initializeGLState();
mSurfaceTexture = new SurfaceTexture(getTextureId());
// Set up performance tracking if enabled
if (SystemProperties.getBoolean(LEGACY_PERF_PROPERTY, false)) {
setupGlTiming();
}
}
use of android.graphics.SurfaceTexture in project android_packages_apps_Torch by CyanogenMod.
the class FlashDevice method setFlashMode.
public synchronized void setFlashMode(int mode) {
Log.d(MSG_TAG, "setFlashMode " + mode);
try {
int value = mode;
switch(mode) {
case STROBE:
value = OFF;
break;
case DEATH_RAY:
if (mValueDeathRay >= 0) {
value = mValueDeathRay;
} else if (mValueHigh >= 0) {
value = mValueHigh;
} else {
value = 0;
Log.d(MSG_TAG, "Broken device configuration");
}
break;
case ON:
if (mValueOn >= 0) {
value = mValueOn;
} else {
value = 0;
Log.d(MSG_TAG, "Broken device configuration");
}
break;
}
if (mUseCameraInterface) {
if (mCamera == null) {
mCamera = Camera.open();
}
if (value == OFF) {
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
if (mode != STROBE) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
if (mSurfaceTexture != null) {
mSurfaceTexture.release();
mSurfaceTexture = null;
}
}
if (mWakeLock.isHeld())
mWakeLock.release();
} else {
if (mSurfaceTexture == null) {
// Create a dummy texture, otherwise setPreview won't work on some devices
mSurfaceTexture = new SurfaceTexture(0);
mCamera.setPreviewTexture(mSurfaceTexture);
mCamera.startPreview();
}
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);
if (!mWakeLock.isHeld()) {
// only get the wakelock if we don't have it already
// we don't want to go to sleep while cam is up
mWakeLock.acquire();
}
}
} else {
// Devices with sysfs toggle and sysfs luminosity
if (mFlashDeviceLuminosity != null && mFlashDeviceLuminosity.length() > 0) {
if (mFlashDeviceWriter == null) {
mFlashDeviceWriter = new FileWriter(mFlashDevice);
}
if (mFlashDeviceLuminosityWriter == null) {
mFlashDeviceLuminosityWriter = new FileWriter(mFlashDeviceLuminosity);
}
mFlashDeviceWriter.write(String.valueOf(mValueOn));
mFlashDeviceWriter.flush();
switch(mode) {
case ON:
mFlashDeviceLuminosityWriter.write(String.valueOf(mValueLow));
mFlashDeviceLuminosityWriter.flush();
break;
case OFF:
mFlashDeviceLuminosityWriter.write(String.valueOf(mValueLow));
mFlashDeviceLuminosityWriter.close();
mFlashDeviceLuminosityWriter = null;
mFlashDeviceWriter.write(String.valueOf(mValueOff));
mFlashDeviceWriter.close();
mFlashDeviceWriter = null;
break;
case STROBE:
mFlashDeviceWriter.write(String.valueOf(OFF));
mFlashDeviceWriter.flush();
break;
case DEATH_RAY:
if (mValueDeathRay >= 0) {
mFlashDeviceLuminosityWriter.write(String.valueOf(mValueDeathRay));
mFlashDeviceLuminosityWriter.flush();
} else if (mValueHigh >= 0) {
mFlashDeviceLuminosityWriter.write(String.valueOf(mValueHigh));
mFlashDeviceLuminosityWriter.flush();
} else {
mFlashDeviceLuminosityWriter.write(String.valueOf(OFF));
mFlashDeviceLuminosityWriter.flush();
Log.d(MSG_TAG, "Broken device configuration");
}
break;
}
} else {
// Devices with just a sysfs toggle
if (mFlashDeviceWriter == null) {
mFlashDeviceWriter = new FileWriter(mFlashDevice);
}
// Write to sysfs only if not already on
if (mode != mFlashMode) {
mFlashDeviceWriter.write(String.valueOf(value));
mFlashDeviceWriter.flush();
}
if (mode == OFF) {
mFlashDeviceWriter.close();
mFlashDeviceWriter = null;
}
}
}
mFlashMode = mode;
} catch (IOException e) {
throw new RuntimeException("Can't open flash device", e);
}
}
use of android.graphics.SurfaceTexture in project Rajawali by Rajawali.
the class StreamingTexture method add.
void add() throws TextureException {
int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
int textureId = textures[0];
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
setTextureId(textureId);
mSurfaceTexture = new SurfaceTexture(textureId);
if (mMediaPlayer != null) {
mSurface = new Surface(mSurfaceTexture);
mMediaPlayer.setSurface(mSurface);
} else if (mCamera != null) {
try {
mSurfaceTexture.setOnFrameAvailableListener(mOnFrameAvailableListener);
mCamera.setPreviewTexture(mSurfaceTexture);
} catch (IOException e) {
throw new TextureException(e);
}
} else if (mSurfaceListener != null) {
mSurfaceListener.setSurface(new Surface(mSurfaceTexture));
}
}
use of android.graphics.SurfaceTexture in project XobotOS by xamarin.
the class CamRenderer method onSurfaceCreated.
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
// Ignore the passed-in GL10 interface, and use the GLES20
// class's static methods instead.
/* Set up alpha blending and an Android background color */
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glClearColor(0.643f, 0.776f, 0.223f, 1.0f);
/* Set up shaders and handles to their variables */
mProgram = createProgram(mVertexShader, mFragmentShader);
if (mProgram == 0) {
return;
}
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
checkGlError("glGetAttribLocation aPosition");
if (maPositionHandle == -1) {
throw new RuntimeException("Could not get attrib location for aPosition");
}
maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
checkGlError("glGetAttribLocation aTextureCoord");
if (maTextureHandle == -1) {
throw new RuntimeException("Could not get attrib location for aTextureCoord");
}
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
checkGlError("glGetUniformLocation uMVPMatrix");
if (muMVPMatrixHandle == -1) {
throw new RuntimeException("Could not get attrib location for uMVPMatrix");
}
muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
checkGlError("glGetUniformLocation uSTMatrix");
if (muMVPMatrixHandle == -1) {
throw new RuntimeException("Could not get attrib location for uSTMatrix");
}
muCRatioHandle = GLES20.glGetUniformLocation(mProgram, "uCRatio");
checkGlError("glGetUniformLocation uCRatio");
if (muMVPMatrixHandle == -1) {
throw new RuntimeException("Could not get attrib location for uCRatio");
}
/*
* Create our texture. This has to be done each time the
* surface is created.
*/
int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
mTextureID = textures[0];
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
checkGlError("glBindTexture mTextureID");
// Can't do mipmapping with camera source
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
// Clamp to edge is the only option
GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
checkGlError("glTexParameteri mTextureID");
/*
* Create the SurfaceTexture that will feed this textureID, and pass it to the camera
*/
mSurface = new SurfaceTexture(mTextureID);
mSurface.setOnFrameAvailableListener(this);
try {
mCamera.setPreviewTexture(mSurface);
} catch (IOException t) {
Log.e(TAG, "Cannot set preview texture target!");
}
/* Start the camera */
mCamera.startPreview();
Matrix.setLookAtM(mVMatrix, 0, 0, 0, 5f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
mLastTime = 0;
synchronized (this) {
updateSurface = false;
}
}
use of android.graphics.SurfaceTexture in project PhotoNoter by yydcdut.
the class Camera2ModelImpl method getSurface.
private Surface getSurface(Size previewSize) {
SurfaceTexture surfaceTexture = mPreviewSurface.getSurfaceTexture();
SurfaceHolder surfaceHolder = mPreviewSurface.getSurfaceHolder();
Surface surface = null;
if (surfaceTexture != null) {
if (previewSize != null) {
surfaceTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
}
surface = new Surface(surfaceTexture);
} else {
if (previewSize != null) {
surfaceHolder.setFixedSize(previewSize.getWidth(), previewSize.getHeight());
}
surface = surfaceHolder.getSurface();
}
return surface;
}
Aggregations