Search in sources :

Example 86 with SurfaceTexture

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;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Example 87 with SurfaceTexture

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;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 88 with SurfaceTexture

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!");
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 89 with SurfaceTexture

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
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 90 with SurfaceTexture

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();
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) FrameLayout(android.widget.FrameLayout) TextureView(android.view.TextureView) IOException(java.io.IOException) IOException(java.io.IOException) WindowManager(android.view.WindowManager)

Aggregations

SurfaceTexture (android.graphics.SurfaceTexture)99 Surface (android.view.Surface)49 SurfaceView (android.view.SurfaceView)16 IOException (java.io.IOException)16 SurfaceHolder (android.view.SurfaceHolder)14 EGLSurface (android.opengl.EGLSurface)13 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Size (android.util.Size)5 RequiresPermission (android.support.annotation.RequiresPermission)4 TextureView (android.view.TextureView)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 Camera (android.hardware.Camera)2 WindowManager (android.view.WindowManager)2 FrameLayout (android.widget.FrameLayout)2 ByteBuffer (java.nio.ByteBuffer)2 CalledByNative (org.chromium.base.CalledByNative)2 Size (android.hardware.Camera.Size)1