Search in sources :

Example 96 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)

Example 97 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_frameworks_base by crdroidandroid.

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)

Aggregations

SurfaceTexture (android.graphics.SurfaceTexture)97 Surface (android.view.Surface)49 IOException (java.io.IOException)16 SurfaceView (android.view.SurfaceView)15 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 TextureView (android.view.TextureView)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 Camera (android.hardware.Camera)2 RequiresPermission (android.support.annotation.RequiresPermission)2 WindowManager (android.view.WindowManager)2 FrameLayout (android.widget.FrameLayout)2 FullFrameRect (com.android.grafika.gles.FullFrameRect)2 ByteBuffer (java.nio.ByteBuffer)2 CalledByNative (org.chromium.base.CalledByNative)2