Remove oval experiment

v2
Mattia Iavarone 6 years ago
parent bc5c9a41b4
commit c4baa7cacd
  1. 10
      MIGRATION.md
  2. 38
      cameraview/src/main/gles/com/otaliastudios/cameraview/EglViewport.java
  3. 3
      cameraview/src/main/res/layout/cameraview_gl_view.xml
  4. 26
      cameraview/src/main/views/com/otaliastudios/cameraview/GlCameraPreview.java

@ -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?

@ -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");

@ -6,8 +6,7 @@
android:layout_gravity="center"
android:gravity="center">
<view
class="com.otaliastudios.cameraview.GlCameraPreview$ClippingSurfaceView"
<android.opengl.GLSurfaceView
android:id="@+id/gl_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

@ -75,32 +75,6 @@ class GlCameraPreview extends CameraPreview<GLSurfaceView, SurfaceTexture> 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) {

Loading…
Cancel
Save