Revert "Avoid recreating VirtualDisplay on format changes."

This reverts commit fcd1dfad1f855346a1fb6741322ff48c61601df7.

Reason for revert: Breaks downstream test.

Original change's description:
> Avoid recreating VirtualDisplay on format changes.
>
> Recreating the VirtualDisplay will require new user permission dialog,
> so resize instead when possible.
>
> Bug: b/281978124
> Change-Id: I3b6939720897c038c9e598433372342cf72e001e
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305560
> Reviewed-by: Xavier Lepaul‎ <xalep@webrtc.org>
> Commit-Queue: Linus Nilsson <lnilsson@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#40084}

Bug: b/281978124, b/283063961
Change-Id: I8ec2ba3321be225a673af2a6192819a8a1b79b2c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305641
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#40085}
This commit is contained in:
Mirko Bonadei 2023-05-17 11:15:37 +00:00 committed by WebRTC LUCI CQ
parent fcd1dfad1f
commit 510890ba19

View File

@ -17,8 +17,6 @@ import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.Surface;
import androidx.annotation.Nullable;
@ -115,7 +113,7 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
// Let MediaProjection callback use the SurfaceTextureHelper thread.
mediaProjection.registerCallback(mediaProjectionCallback, surfaceTextureHelper.getHandler());
updateVirtualDisplay();
createVirtualDisplay();
capturerObserver.onCapturerStarted(true);
surfaceTextureHelper.startListening(ScreenCapturerAndroid.this);
}
@ -173,33 +171,24 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
this.height = height;
if (virtualDisplay == null) {
// Capturer is stopped, the virtual display will be created in startCapture().
// Capturer is stopped, the virtual display will be created in startCaptuer().
return;
}
// Create a new virtual display on the surfaceTextureHelper thread to avoid interference
// with frame processing, which happens on the same thread (we serialize events by running
// them on the same thread).
ThreadUtils.invokeAtFrontUninterruptibly(
surfaceTextureHelper.getHandler(), this::updateVirtualDisplay);
ThreadUtils.invokeAtFrontUninterruptibly(surfaceTextureHelper.getHandler(), new Runnable() {
@Override
public void run() {
virtualDisplay.release();
createVirtualDisplay();
}
});
}
private void updateVirtualDisplay() {
surfaceTextureHelper.setTextureSize(width, height);
// Before Android S (12), resizing the virtual display can cause the captured screen to be
// scaled incorrectly (b/260606562), so keep the behavior of recreating the virtual display
// prior to Android S.
if (virtualDisplay == null || VERSION.SDK_INT < VERSION_CODES.S) {
createVirtualDisplay();
} else {
virtualDisplay.resize(width, height, VIRTUAL_DISPLAY_DPI);
virtualDisplay.setSurface(new Surface(surfaceTextureHelper.getSurfaceTexture()));
}
}
private void createVirtualDisplay() {
if (virtualDisplay != null) {
virtualDisplay.release();
}
surfaceTextureHelper.setTextureSize(width, height);
virtualDisplay = mediaProjection.createVirtualDisplay("WebRTC_ScreenCapture", width, height,
VIRTUAL_DISPLAY_DPI, DISPLAY_FLAGS, new Surface(surfaceTextureHelper.getSurfaceTexture()),
null /* callback */, null /* callback handler */);