use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.
the class ColorFade method captureScreenshotTextureAndSetViewport.
private boolean captureScreenshotTextureAndSetViewport() {
if (!attachEglContext()) {
return false;
}
try {
if (!mTexNamesGenerated) {
GLES20.glGenTextures(1, mTexNames, 0);
if (checkGlErrors("glGenTextures")) {
return false;
}
mTexNamesGenerated = true;
}
final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
final Surface s = new Surface(st);
try {
SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
st.updateTexImage();
st.getTransformMatrix(mTexMatrix);
} finally {
s.release();
st.release();
}
// Set up texture coordinates for a quad.
// We might need to change this if the texture ends up being
// a different size from the display for some reason.
mTexCoordBuffer.put(0, 0f);
mTexCoordBuffer.put(1, 0f);
mTexCoordBuffer.put(2, 0f);
mTexCoordBuffer.put(3, 1f);
mTexCoordBuffer.put(4, 1f);
mTexCoordBuffer.put(5, 1f);
mTexCoordBuffer.put(6, 1f);
mTexCoordBuffer.put(7, 0f);
// Set up our viewport.
GLES20.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
ortho(0, mDisplayWidth, 0, mDisplayHeight, -1, 1);
} finally {
detachEglContext();
}
return true;
}
use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.
the class TextureView method getHardwareLayer.
HardwareLayer getHardwareLayer() {
if (mLayer == null) {
if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) {
return null;
}
mLayer = mAttachInfo.mHardwareRenderer.createTextureLayer();
boolean createNewSurface = (mSurface == null);
if (createNewSurface) {
// Create a new SurfaceTexture for the layer.
mSurface = new SurfaceTexture(false);
nCreateNativeWindow(mSurface);
}
mLayer.setSurfaceTexture(mSurface);
mSurface.setDefaultBufferSize(getWidth(), getHeight());
mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
if (mListener != null && createNewSurface) {
mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
}
mLayer.setLayerPaint(mLayerPaint);
}
if (mUpdateSurface) {
// Someone has requested that we use a specific SurfaceTexture, so
// tell mLayer about it and set the SurfaceTexture to use the
// current view size.
mUpdateSurface = false;
// Since we are updating the layer, force an update to ensure its
// parameters are correct (width, height, transform, etc.)
updateLayer();
mMatrixChanged = true;
mLayer.setSurfaceTexture(mSurface);
mSurface.setDefaultBufferSize(getWidth(), getHeight());
}
return mLayer;
}
use of android.graphics.SurfaceTexture in project android_frameworks_base by DirtyUnicorns.
the class MediaSource method open.
@Override
public void open(FilterContext context) {
if (mLogVerbose) {
Log.v(TAG, "Opening MediaSource");
if (mSelectedIsUrl) {
Log.v(TAG, "Current URL is " + mSourceUrl);
} else {
Log.v(TAG, "Current source is Asset!");
}
}
mMediaFrame = (GLFrame) context.getFrameManager().newBoundFrame(mOutputFormat, GLFrame.EXTERNAL_TEXTURE, 0);
mSurfaceTexture = new SurfaceTexture(mMediaFrame.getTextureId());
if (!setupMediaPlayer(mSelectedIsUrl)) {
throw new RuntimeException("Error setting up MediaPlayer!");
}
}
use of android.graphics.SurfaceTexture in project android_packages_apps_Camera by CyanogenMod.
the class CameraScreenNail method draw.
@Override
public void draw(GLCanvas canvas, int x, int y, int width, int height) {
synchronized (mLock) {
if (!mVisible)
mVisible = true;
SurfaceTexture surfaceTexture = getSurfaceTexture();
if (surfaceTexture == null || !mFirstFrameArrived)
return;
if (mOnFrameDrawnListener != null) {
mOnFrameDrawnListener.run();
mOnFrameDrawnListener = null;
}
float oldAlpha = canvas.getAlpha();
canvas.setAlpha(mAlpha);
switch(mAnimState) {
case ANIM_NONE:
super.draw(canvas, x, y, width, height);
break;
case ANIM_SWITCH_COPY_TEXTURE:
copyPreviewTexture(canvas);
mSwitchAnimManager.setReviewDrawingSize(width, height);
mListener.onPreviewTextureCopied();
mAnimState = ANIM_SWITCH_DARK_PREVIEW;
// preview.
case ANIM_SWITCH_DARK_PREVIEW:
case ANIM_SWITCH_WAITING_FIRST_FRAME:
// Consume the frame. If the buffers are full,
// onFrameAvailable will not be called. Animation state
// relies on onFrameAvailable.
surfaceTexture.updateTexImage();
mSwitchAnimManager.drawDarkPreview(canvas, x, y, width, height, mAnimTexture);
break;
case ANIM_SWITCH_START:
mSwitchAnimManager.startAnimation();
mAnimState = ANIM_SWITCH_RUNNING;
break;
case ANIM_CAPTURE_START:
copyPreviewTexture(canvas);
mListener.onCaptureTextureCopied();
mCaptureAnimManager.startAnimation(x, y, width, height);
mAnimState = ANIM_CAPTURE_RUNNING;
break;
}
if (mAnimState == ANIM_CAPTURE_RUNNING || mAnimState == ANIM_SWITCH_RUNNING) {
boolean drawn;
if (mAnimState == ANIM_CAPTURE_RUNNING) {
if (!mFullScreen) {
// Skip the animation if no longer in full screen mode
drawn = false;
} else {
drawn = mCaptureAnimManager.drawAnimation(canvas, this, mAnimTexture);
}
} else {
drawn = mSwitchAnimManager.drawAnimation(canvas, x, y, width, height, this, mAnimTexture);
}
if (drawn) {
mListener.requestRender();
} else {
// Continue to the normal draw procedure if the animation is
// not drawn.
mAnimState = ANIM_NONE;
super.draw(canvas, x, y, width, height);
}
}
canvas.setAlpha(oldAlpha);
callbackIfNeeded();
}
// mLock
}
use of android.graphics.SurfaceTexture in project android_frameworks_base by crdroidandroid.
the class OnTheGoService method setupViews.
private void setupViews(final boolean isRestarting) {
logDebug("Setup Views, restarting: " + (isRestarting ? "true" : "false"));
final int cameraType = Settings.System.getInt(getContentResolver(), Settings.System.ON_THE_GO_CAMERA, 0);
try {
getCameraInstance(cameraType);
} catch (Exception exc) {
// Well, you cant have all in this life..
logDebug("Exception: " + exc.getMessage());
createNotification(NOTIFICATION_ERROR);
stopOnTheGo(true);
}
final TextureView mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
try {
if (mCamera != null) {
mCamera.setDisplayOrientation(90);
mCamera.setPreviewTexture(surfaceTexture);
mCamera.startPreview();
}
} catch (IOException io) {
logDebug("IOException: " + io.getMessage());
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
releaseCamera();
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
});
mOverlay = new FrameLayout(this);
mOverlay.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mOverlay.addView(mTextureView);
final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, PixelFormat.TRANSLUCENT);
wm.addView(mOverlay, params);
toggleOnTheGoAlpha();
}
Aggregations