|
|
@ -12,16 +12,14 @@ import com.otaliastudios.cameraview.preview.RendererThread; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Fixes an issue for some devices with snapshot picture and video recording. |
|
|
|
* Fixes an issue for some devices with snapshot picture and video recording. |
|
|
|
* This is so dirty and totally unclear that I wanted to have a separate class. |
|
|
|
* This is so unclear that I wanted to have a separate class holding code and comments. |
|
|
|
* |
|
|
|
* |
|
|
|
* WHY IT FIXES THAT ISSUE |
|
|
|
* WHEN TO USE THIS CLASS |
|
|
|
* I have no answer, this is pure magic to me. |
|
|
|
|
|
|
|
* There is actually no need of this class in some cases: |
|
|
|
* There is actually no need of this class in some cases: |
|
|
|
* - when we don't have overlays, everything works |
|
|
|
* - when we don't have overlays, everything works |
|
|
|
* - on the majority of devices, everything works |
|
|
|
* - on the majority of devices, everything works |
|
|
|
* But some devices will show the issue #514 and so they need this class to fix it. |
|
|
|
* But some devices will show the issue #514 and so they need this class to fix it. |
|
|
|
* I believe that this has no performance impact but it could be measured and the use of this |
|
|
|
* We will use this always since it should have close to none performance impact. |
|
|
|
* class could be restricted to those specific devices that need it. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* SNAPSHOT PROCEDURE |
|
|
|
* SNAPSHOT PROCEDURE |
|
|
|
* The issue is about picture and video snapshots with overlays. In both cases, we: |
|
|
|
* The issue is about picture and video snapshots with overlays. In both cases, we: |
|
|
@ -75,12 +73,15 @@ import com.otaliastudios.cameraview.preview.RendererThread; |
|
|
|
* THE MAGIC |
|
|
|
* THE MAGIC |
|
|
|
* Hard to say why, but using this class fixes the described issue. |
|
|
|
* Hard to say why, but using this class fixes the described issue. |
|
|
|
* It seems that when the {@link SurfaceTexture#updateTexImage()} method for the overlay surface |
|
|
|
* It seems that when the {@link SurfaceTexture#updateTexImage()} method for the overlay surface |
|
|
|
* is called - the one that updates the overlayTextureId - we must ensure that the currently |
|
|
|
* is called - the one that updates the overlayTextureId - we must ensure that the CURRENTLY |
|
|
|
* bound texture is the cameraTextureId. |
|
|
|
* BOUND TEXTURE ID IS NOT 0. The id we choose to apply might be cameraTextureId, or overlayTextureId, |
|
|
|
|
|
|
|
* or probably whatever other valid id, and should be passed to {@link #Issue514Workaround(int)}. |
|
|
|
|
|
|
|
* [Tested with cameraTextureId and overlayTextureId: both do work.] |
|
|
|
|
|
|
|
* [Tested with invalid id like 9999. This won't work.] |
|
|
|
* |
|
|
|
* |
|
|
|
* This makes no sense, since overlaySurfaceTexture.updateTexImage() is setting it to overlayTextureId, |
|
|
|
* This makes no sense, since overlaySurfaceTexture.updateTexImage() is setting it to overlayTextureId |
|
|
|
* but it fixes the issue. Specifically, after any draw operation with {@link EglViewport}, the bound |
|
|
|
* anyway, but it fixes the issue. Specifically, after any draw operation with {@link EglViewport}, |
|
|
|
* texture is reset to 0 so this must be undone here. We offer: |
|
|
|
* the bound texture is reset to 0 so this must be undone here. We offer: |
|
|
|
* |
|
|
|
* |
|
|
|
* - {@link #beforeOverlayUpdateTexImage()} to be called before the {@link SurfaceTexture#updateTexImage()} call |
|
|
|
* - {@link #beforeOverlayUpdateTexImage()} to be called before the {@link SurfaceTexture#updateTexImage()} call |
|
|
|
* - {@link #end()} to release and bring things back to normal state |
|
|
|
* - {@link #end()} to release and bring things back to normal state |
|
|
@ -90,22 +91,22 @@ import com.otaliastudios.cameraview.preview.RendererThread; |
|
|
|
* finally the {@link EglViewport} drawing operations should be synchronized with a lock. |
|
|
|
* finally the {@link EglViewport} drawing operations should be synchronized with a lock. |
|
|
|
* |
|
|
|
* |
|
|
|
* REFERENCES |
|
|
|
* REFERENCES |
|
|
|
|
|
|
|
* https://github.com/natario1/CameraView/issues/514
|
|
|
|
* https://android.googlesource.com/platform/frameworks/native/+/5c1139f/libs/gui/SurfaceTexture.cpp
|
|
|
|
* https://android.googlesource.com/platform/frameworks/native/+/5c1139f/libs/gui/SurfaceTexture.cpp
|
|
|
|
|
|
|
|
* I can see here that SurfaceTexture does indeed call glBindTexture with the same parameters whenever |
|
|
|
|
|
|
|
* updateTexImage is called, but it also does other gl stuff first. This other gl stuff might be |
|
|
|
|
|
|
|
* breaking when we don't have a bound texture on some specific hardware implementation. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Issue514Workaround { |
|
|
|
public class Issue514Workaround { |
|
|
|
|
|
|
|
|
|
|
|
private final int cameraTextureId; |
|
|
|
private final int textureId; |
|
|
|
|
|
|
|
|
|
|
|
public Issue514Workaround(int cameraTextureId) { |
|
|
|
public Issue514Workaround(int textureId) { |
|
|
|
this.cameraTextureId = cameraTextureId; |
|
|
|
this.textureId = textureId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void beforeOverlayUpdateTexImage() { |
|
|
|
public void beforeOverlayUpdateTexImage() { |
|
|
|
bindTexture(cameraTextureId); |
|
|
|
bindTexture(textureId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void afterOverlayGlDrawn() { |
|
|
|
|
|
|
|
bindTexture(cameraTextureId); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void end() { |
|
|
|
public void end() { |
|
|
|