From e0c5b3efdeb44751ba35e8abdd3ed9e41ea21ff1 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Wed, 19 Dec 2018 18:16:59 +0100 Subject: [PATCH] Remove oval experiment --- MIGRATION.md | 10 +++-- .../otaliastudios/cameraview/EglViewport.java | 38 ++++++++++--------- .../main/res/layout/cameraview_gl_view.xml | 3 +- .../cameraview/GlCameraPreview.java | 26 ------------- 4 files changed, 28 insertions(+), 49 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index c486df89..4fbcc68f 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -134,16 +134,18 @@ Might be used in the future to speed up development. - Default `Facing` value is not `BACK` anymore but rather a value that guarantees that you have cameras (if possible). If device has no `BACK` cameras, defaults to `FRONT`. + +TODO: think bout getPreviewSize() being removed, and think about adding a setPreviewSize(). + If adding getPreviewSize() back, update this doc. +TODO: fix video recording rotation: with front camera, it does not work. +TODO: opencollective + TODO: document cameraGridColor TODO: document setVideoBitRate TODO: document setAudioBitRate TODO: document takeVideoSnapshot TODO: document that takePictureSnaphot works while taking videos, if GL_SURFACE TODO: document the camera previews -TODO: think bout getPreviewSize() being removed, and think about adding a setPreviewSize(). - If adding getPreviewSize() back, update this doc. -TODO: fix video recording rotation: with front camera, it does not work. -TODO: opencollective TODO: new docs? diff --git a/cameraview/src/main/gles/com/otaliastudios/cameraview/EglViewport.java b/cameraview/src/main/gles/com/otaliastudios/cameraview/EglViewport.java index 7f437ed6..20556e99 100644 --- a/cameraview/src/main/gles/com/otaliastudios/cameraview/EglViewport.java +++ b/cameraview/src/main/gles/com/otaliastudios/cameraview/EglViewport.java @@ -29,12 +29,26 @@ class EglViewport extends EglElement { " vTextureScale = uTextureScale.xy;\n" + "}\n"; - // Circle fragment shader for use with external 2D textures - // We draw as transparent all the pixels outside the circle of center (0.5, 0.5) - // and radius 0.5. Works well! But we have: - // - black in the preview. Solved with canvas.clipPath and a custom GlSurfaceView. - // - black in picture snapshots, UNLESS we use PNG which is super slow - // - black in videos because they have no alpha channel + // Simple fragment shader for use with external 2D textures + private static final String SIMPLE_FRAGMENT_SHADER = + "#extension GL_OES_EGL_image_external : require\n" + + "precision mediump float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform samplerExternalOES sTexture;\n" + + "void main() {\n" + + " gl_FragColor = texture2D(sTexture, vTextureCoord);\n" + + "}\n"; + + /** + * EXPERIMENT: + * An oval fragment shader. We draw all the pixels outside the circle of center (0.5, 0.5) + * and radius 0.5 as transparent. Works well, but we have: + * + * 1. black in the preview: This can be solved with a custom GlSurfaceView that overrides + * dispatchDraw, and, before calling super, clips the canvas with an oval path (canvas.clipPath). + * 2. black in picture snapshot: This can be solved by using PNG, but it is suepr slow. + * 3. black in videos: No way to solve this AFAIK. + */ private static final String CIRCLE_FRAGMENT_SHADER = "#extension GL_OES_EGL_image_external : require\n" + "precision mediump float;\n" + @@ -52,16 +66,6 @@ class EglViewport extends EglElement { " }\n" + "}\n"; - // Simple fragment shader for use with external 2D textures - private static final String SIMPLE_FRAGMENT_SHADER = - "#extension GL_OES_EGL_image_external : require\n" + - "precision mediump float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform samplerExternalOES sTexture;\n" + - "void main() {\n" + - " gl_FragColor = texture2D(sTexture, vTextureCoord);\n" + - "}\n"; - // Stuff from Drawable2d.FULL_RECTANGLE // A full square, extending from -1 to +1 in both dimensions. // When the model/view/projection matrix is identity, this will exactly cover the viewport. @@ -102,7 +106,7 @@ class EglViewport extends EglElement { EglViewport() { mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; - mProgramHandle = createProgram(SIMPLE_VERTEX_SHADER, CIRCLE_FRAGMENT_SHADER); + mProgramHandle = createProgram(SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER); maPositionLocation = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); checkLocation(maPositionLocation, "aPosition"); maTextureCoordLocation = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); diff --git a/cameraview/src/main/res/layout/cameraview_gl_view.xml b/cameraview/src/main/res/layout/cameraview_gl_view.xml index 88b19411..0525ee6e 100644 --- a/cameraview/src/main/res/layout/cameraview_gl_view.xml +++ b/cameraview/src/main/res/layout/cameraview_gl_view.xml @@ -6,8 +6,7 @@ android:layout_gravity="center" android:gravity="center"> - diff --git a/cameraview/src/main/views/com/otaliastudios/cameraview/GlCameraPreview.java b/cameraview/src/main/views/com/otaliastudios/cameraview/GlCameraPreview.java index 65c3c3af..9672f90b 100644 --- a/cameraview/src/main/views/com/otaliastudios/cameraview/GlCameraPreview.java +++ b/cameraview/src/main/views/com/otaliastudios/cameraview/GlCameraPreview.java @@ -75,32 +75,6 @@ class GlCameraPreview extends CameraPreview imple super(context, parent, callback); } - static class ClippingSurfaceView extends GLSurfaceView { - - private Path path = new Path(); - private RectF rect = new RectF(); - - public ClippingSurfaceView(Context context) { - super(context); - } - public ClippingSurfaceView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void dispatchDraw(Canvas canvas) { - if (false) { - if (getWidth() != rect.width() || getHeight() != rect.height()) { - rect.set(0, 0, getWidth(), getHeight()); - path.rewind(); - path.addOval(rect, Path.Direction.CW); - } - canvas.clipPath(path); - } - super.dispatchDraw(canvas); - } - } - @NonNull @Override protected GLSurfaceView onCreateView(@NonNull Context context, @NonNull ViewGroup parent) {