Search in sources :

Example 16 with Surface

use of android.view.Surface in project platform_frameworks_base by android.

the class SurfaceHolderTarget method onOpen.

@Override
protected synchronized void onOpen() {
    mSurfaceHolder.addCallback(mSurfaceHolderListener);
    Surface surface = mSurfaceHolder.getSurface();
    mHasSurface = (surface != null) && surface.isValid();
}
Also used : Surface(android.view.Surface)

Example 17 with Surface

use of android.view.Surface in project cameraview by google.

the class Camera2 method startCaptureSession.

/**
     * <p>Starts a capture session for camera preview.</p>
     * <p>This rewrites {@link #mPreviewRequestBuilder}.</p>
     * <p>The result will be continuously processed in {@link #mSessionCallback}.</p>
     */
void startCaptureSession() {
    if (!isCameraOpened() || !mPreview.isReady() || mImageReader == null) {
        return;
    }
    Size previewSize = chooseOptimalSize();
    mPreview.setBufferSize(previewSize.getWidth(), previewSize.getHeight());
    Surface surface = mPreview.getSurface();
    try {
        mPreviewRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);
        mCamera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), mSessionCallback, null);
    } catch (CameraAccessException e) {
        throw new RuntimeException("Failed to start camera session");
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface)

Example 18 with Surface

use of android.view.Surface in project grafika by google.

the class EglCore method createWindowSurface.

/**
     * Creates an EGL surface associated with a Surface.
     * <p>
     * If this is destined for MediaCodec, the EGLConfig should have the "recordable" attribute.
     */
public EGLSurface createWindowSurface(Object surface) {
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture)) {
        throw new RuntimeException("invalid surface: " + surface);
    }
    // Create a window surface, and attach it to the Surface we received.
    int[] surfaceAttribs = { EGL14.EGL_NONE };
    EGLSurface eglSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surface, surfaceAttribs, 0);
    checkEglError("eglCreateWindowSurface");
    if (eglSurface == null) {
        throw new RuntimeException("surface was null");
    }
    return eglSurface;
}
Also used : EGLSurface(android.opengl.EGLSurface) SurfaceTexture(android.graphics.SurfaceTexture) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Example 19 with Surface

use of android.view.Surface in project grafika by google.

the class MultiSurfaceActivity method startBouncing.

private void startBouncing() {
    final Surface surface = mSurfaceView2.getHolder().getSurface();
    if (surface == null || !surface.isValid()) {
        Log.w(TAG, "mSurfaceView2 is not ready");
        return;
    }
    mBounceThread = new Thread() {

        @Override
        public void run() {
            while (true) {
                long startWhen = System.nanoTime();
                for (int i = 0; i < BOUNCE_STEPS; i++) {
                    if (!mBouncing)
                        return;
                    drawBouncingCircle(surface, i);
                }
                for (int i = BOUNCE_STEPS; i > 0; i--) {
                    if (!mBouncing)
                        return;
                    drawBouncingCircle(surface, i);
                }
                long duration = System.nanoTime() - startWhen;
                double framesPerSec = 1000000000.0 / (duration / (BOUNCE_STEPS * 2.0));
                Log.d(TAG, "Bouncing at " + framesPerSec + " fps");
            }
        }
    };
    mBouncing = true;
    mBounceThread.setName("Bouncer");
    mBounceThread.start();
}
Also used : Surface(android.view.Surface) WindowSurface(com.android.grafika.gles.WindowSurface)

Example 20 with Surface

use of android.view.Surface in project grafika by google.

the class MultiSurfaceActivity method surfaceChanged.

/**
     * SurfaceHolder.Callback method
     * <p>
     * Draws when the surface changes.  Since nothing else is touching the surface, and
     * we're not animating, we just draw here and ignore it.
     */
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Log.d(TAG, "surfaceChanged fmt=" + format + " size=" + width + "x" + height + " holder=" + holder);
    int id = getSurfaceId(holder);
    boolean portrait = height > width;
    Surface surface = holder.getSurface();
    switch(id) {
        case 1:
            // default layer: circle on left / top
            if (portrait) {
                drawCircleSurface(surface, width / 2, height / 4, width / 4);
            } else {
                drawCircleSurface(surface, width / 4, height / 2, height / 4);
            }
            break;
        case 2:
            // media overlay layer: circle on right / bottom
            if (portrait) {
                drawCircleSurface(surface, width / 2, height * 3 / 4, width / 4);
            } else {
                drawCircleSurface(surface, width * 3 / 4, height / 2, height / 4);
            }
            break;
        case 3:
            // top layer: alpha stripes
            if (portrait) {
                int halfLine = width / 16 + 1;
                drawRectSurface(surface, width / 2 - halfLine, 0, halfLine * 2, height);
            } else {
                int halfLine = height / 16 + 1;
                drawRectSurface(surface, 0, height / 2 - halfLine, width, halfLine * 2);
            }
            break;
        default:
            throw new RuntimeException("wha?");
    }
}
Also used : Paint(android.graphics.Paint) Surface(android.view.Surface) WindowSurface(com.android.grafika.gles.WindowSurface)

Aggregations

Surface (android.view.Surface)300 ArrayList (java.util.ArrayList)100 SurfaceTexture (android.graphics.SurfaceTexture)49 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)44 Size (android.util.Size)35 CaptureRequest (android.hardware.camera2.CaptureRequest)34 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)30 IOException (java.io.IOException)27 EGLSurface (android.opengl.EGLSurface)19 Paint (android.graphics.Paint)16 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)15 SurfaceHolder (android.view.SurfaceHolder)15 Rect (android.graphics.Rect)13 SurfaceView (android.view.SurfaceView)13 Canvas (android.graphics.Canvas)12 CameraAccessException (android.hardware.camera2.CameraAccessException)12 WifiDisplay (android.hardware.display.WifiDisplay)12 MediaRecorder (android.media.MediaRecorder)11 SurfaceControl (android.view.SurfaceControl)11 Image (android.media.Image)10