Bug 1641064 - Fail screenshot captures immediately if we pause the compositor r=geckoview-reviewers,agi

Differential Revision: https://phabricator.services.mozilla.com/D78373
This commit is contained in:
James Willcox 2020-06-04 23:40:01 +00:00
Родитель c4107df595
Коммит dff6c8722d
2 изменённых файлов: 35 добавлений и 9 удалений

Просмотреть файл

@ -27,6 +27,7 @@ import kotlin.math.max
import android.graphics.BitmapFactory
import android.graphics.Bitmap
import androidx.test.platform.app.InstrumentationRegistry
import java.lang.IllegalStateException
import java.lang.NullPointerException
@ -141,6 +142,18 @@ class ScreenshotTest : BaseSessionTest() {
}
}
@WithDisplay(height = SCREEN_HEIGHT, width = SCREEN_WIDTH)
@Test(expected = IllegalStateException::class)
fun capturePixelsFailsCompositorPaused() {
sessionRule.display?.let {
it.surfaceDestroyed()
val result = it.capturePixels()
it.surfaceDestroyed()
sessionRule.waitForResult(result)
}
}
@WithDisplay(height = SCREEN_HEIGHT, width = SCREEN_WIDTH)
@Test
fun screenshotToBitmap() {

Просмотреть файл

@ -1037,6 +1037,20 @@ class nsWindow::LayerViewSupport final
mCompositorPaused = true;
child->Pause();
}
if (LockedWindowPtr lock{mWindow}) {
while (!mCapturePixelsResults.empty()) {
auto result =
java::GeckoResult::LocalRef(mCapturePixelsResults.front().mResult);
if (result) {
result->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"The compositor has detached from the session")
.Cast<jni::Throwable>());
}
mCapturePixelsResults.pop();
}
}
}
void SyncResumeCompositor() {
@ -1205,22 +1219,21 @@ class nsWindow::LayerViewSupport final
void RecvScreenPixels(Shmem&& aMem, const ScreenIntSize& aSize) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
CaptureRequest aCaptureRequest;
java::GeckoResult::LocalRef aResult = nullptr;
CaptureRequest request;
java::GeckoResult::LocalRef result = nullptr;
if (LockedWindowPtr window{mWindow}) {
aCaptureRequest = mCapturePixelsResults.front();
aResult = java::GeckoResult::LocalRef(aCaptureRequest.mResult);
if (aResult) {
request = mCapturePixelsResults.front();
result = java::GeckoResult::LocalRef(request.mResult);
if (result) {
mCapturePixelsResults.pop();
}
}
if (aResult) {
if (result) {
auto pixels = mozilla::jni::ByteBuffer::New(
FlipScreenPixels(aMem, aSize, aCaptureRequest.mSource,
aCaptureRequest.mOutputSize),
FlipScreenPixels(aMem, aSize, request.mSource, request.mOutputSize),
aMem.Size<int8_t>());
aResult->Complete(pixels);
result->Complete(pixels);
}
// Pixels have been copied, so Dealloc Shmem