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();
}
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");
}
}
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;
}
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();
}
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?");
}
}
Aggregations