diff --git a/NEW_RELEASE_NOTES.md b/NEW_RELEASE_NOTES.md index 4a1a9c7fa7..494e8046aa 100644 --- a/NEW_RELEASE_NOTES.md +++ b/NEW_RELEASE_NOTES.md @@ -7,3 +7,5 @@ for next branch cut* header. appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md). ## Release notes for next branch cut + +- engine: Add `isPaused()` diff --git a/android/filament-android/src/main/cpp/Engine.cpp b/android/filament-android/src/main/cpp/Engine.cpp index 713baa53ed..ef67358079 100644 --- a/android/filament-android/src/main/cpp/Engine.cpp +++ b/android/filament-android/src/main/cpp/Engine.cpp @@ -406,6 +406,13 @@ Java_com_google_android_filament_Engine_nFlush(JNIEnv*, jclass, engine->flush(); } +extern "C" JNIEXPORT jboolean JNICALL +Java_com_google_android_filament_Engine_nIsPaused(JNIEnv*, jclass, + jlong nativeEngine) { + Engine* engine = (Engine*) nativeEngine; + return (jboolean)engine->isPaused(); +} + extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetPaused(JNIEnv*, jclass, jlong nativeEngine, jboolean paused) { diff --git a/android/filament-android/src/main/java/com/google/android/filament/Engine.java b/android/filament-android/src/main/java/com/google/android/filament/Engine.java index a7ec77a71c..9f8f478009 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/Engine.java +++ b/android/filament-android/src/main/java/com/google/android/filament/Engine.java @@ -1227,6 +1227,17 @@ public class Engine { nFlush(getNativeObject()); } + /** + * Get paused state of rendering thread. + * + *
Warning: This is an experimental API.
+ *
+ * @see #setPaused
+ */
+ public boolean isPaused() {
+ return nIsPaused(getNativeObject());
+ }
+
/**
* Pause or resume the rendering thread.
*
@@ -1319,6 +1330,7 @@ public class Engine {
private static native void nDestroyEntity(long nativeEngine, int entity);
private static native void nFlushAndWait(long nativeEngine);
private static native void nFlush(long nativeEngine);
+ private static native boolean nIsPaused(long nativeEngine);
private static native void nSetPaused(long nativeEngine, boolean paused);
private static native long nGetTransformManager(long nativeEngine);
private static native long nGetLightManager(long nativeEngine);
diff --git a/filament/backend/include/private/backend/CommandBufferQueue.h b/filament/backend/include/private/backend/CommandBufferQueue.h
index 92bf7e1488..e8ff9aa896 100644
--- a/filament/backend/include/private/backend/CommandBufferQueue.h
+++ b/filament/backend/include/private/backend/CommandBufferQueue.h
@@ -82,6 +82,7 @@ public:
void requestExit();
// suspend or unsuspend the queue.
+ bool isPaused() const noexcept;
void setPaused(bool paused);
bool isExitRequested() const;
diff --git a/filament/backend/src/CommandBufferQueue.cpp b/filament/backend/src/CommandBufferQueue.cpp
index b721ce0c50..62af649980 100644
--- a/filament/backend/src/CommandBufferQueue.cpp
+++ b/filament/backend/src/CommandBufferQueue.cpp
@@ -57,6 +57,11 @@ void CommandBufferQueue::requestExit() {
mCondition.notify_one();
}
+bool CommandBufferQueue::isPaused() const noexcept {
+ std::lock_guard Warning: This is an experimental API.
+ *
+ * @see setPaused
+ */
+ bool isPaused() const noexcept;
+
/**
* Pause or resume rendering thread.
*
diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp
index d0042f6332..ca370bc85c 100644
--- a/filament/src/Engine.cpp
+++ b/filament/src/Engine.cpp
@@ -308,6 +308,11 @@ utils::JobSystem& Engine::getJobSystem() noexcept {
return downcast(this)->getJobSystem();
}
+bool Engine::isPaused() const noexcept {
+ ASSERT_PRECONDITION(UTILS_HAS_THREADING, "Pause is meant for multi-threaded platforms.");
+ return downcast(this)->isPaused();
+}
+
void Engine::setPaused(bool paused) {
ASSERT_PRECONDITION(UTILS_HAS_THREADING, "Pause is meant for multi-threaded platforms.");
downcast(this)->setPaused(paused);
diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp
index 7a97aedd7e..d57df19550 100644
--- a/filament/src/details/Engine.cpp
+++ b/filament/src/details/Engine.cpp
@@ -581,6 +581,8 @@ void FEngine::flush() {
}
void FEngine::flushAndWait() {
+ ASSERT_PRECONDITION(!mCommandBufferQueue.isPaused(),
+ "Cannot call flushAndWait() when rendering thread is paused!");
#if defined(__ANDROID__)
@@ -1218,6 +1220,10 @@ void FEngine::destroy(FEngine* engine) {
}
}
+bool FEngine::isPaused() const noexcept {
+ return mCommandBufferQueue.isPaused();
+}
+
void FEngine::setPaused(bool paused) {
mCommandBufferQueue.setPaused(paused);
}
diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h
index c31549e9da..88434071a5 100644
--- a/filament/src/details/Engine.h
+++ b/filament/src/details/Engine.h
@@ -344,6 +344,7 @@ public:
void destroy(utils::Entity e);
+ bool isPaused() const noexcept;
void setPaused(bool paused);
void flushAndWait();