Skip to content

Commit

Permalink
Engine::unprotected() drops the command queue back to unprotected mode
Browse files Browse the repository at this point in the history
FIXES=[344021154]
  • Loading branch information
pixelflinger committed Jun 4, 2024
1 parent 749b063 commit b5d7de0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions android/filament-android/src/main/cpp/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ Java_com_google_android_filament_Engine_nSetPaused(JNIEnv*, jclass,
engine->setPaused(paused);
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Engine_nUnprotected(JNIEnv*, jclass,
jlong nativeEngine, jboolean paused) {
Engine* engine = (Engine*) nativeEngine;
engine->unprotected();
}

// Managers...

extern "C" JNIEXPORT jlong JNICALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,18 @@ public void setPaused(boolean paused) {
nSetPaused(getNativeObject(), paused);
}

/**
* Switch the command queue to unprotected mode. Protected mode can be activated via
* Renderer::beginFrame() using a protected SwapChain.
* @see Renderer
* @see SwapChain
*/
public void unprotected() {
nUnprotected(getNativeObject());
}


@UsedByReflection("TextureHelper.java")
public long getNativeObject() {
if (mNativeObject == 0) {
Expand Down Expand Up @@ -1366,6 +1378,7 @@ private static void assertDestroy(boolean success) {
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 void nUnprotected(long nativeEngine);
private static native long nGetTransformManager(long nativeEngine);
private static native long nGetLightManager(long nativeEngine);
private static native long nGetRenderableManager(long nativeEngine);
Expand Down
8 changes: 8 additions & 0 deletions filament/include/filament/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@ class UTILS_PUBLIC Engine {
*/
void pumpMessageQueues();

/**
* Switch the command queue to unprotected mode. Protected mode can be activated via
* Renderer::beginFrame() using a protected SwapChain.
* @see Renderer
* @see SwapChain
*/
void unprotected() noexcept;

/**
* Returns the default Material.
*
Expand Down
4 changes: 4 additions & 0 deletions filament/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ void Engine::pumpMessageQueues() {
downcast(this)->pumpMessageQueues();
}

void Engine::unprotected() noexcept {
downcast(this)->unprotected();
}

void Engine::setAutomaticInstancingEnabled(bool enable) noexcept {
downcast(this)->setAutomaticInstancingEnabled(enable);
}
Expand Down
9 changes: 9 additions & 0 deletions filament/src/details/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ void FEngine::shutdown() {

destroy(mDefaultMaterial);

destroy(mUnprotectedDummySwapchain);

/*
* clean-up after the user -- we call terminate on each "leaked" object and clear each list.
*
Expand Down Expand Up @@ -1253,6 +1255,13 @@ void FEngine::resetBackendState() noexcept {
}
#endif

void FEngine::unprotected() noexcept {
if (UTILS_UNLIKELY(!mUnprotectedDummySwapchain)) {
mUnprotectedDummySwapchain = createSwapChain(1, 1, 0);
}
mUnprotectedDummySwapchain->makeCurrent(getDriverApi());
}

// ------------------------------------------------------------------------------------------------

Engine::Builder::Builder() noexcept = default;
Expand Down
3 changes: 3 additions & 0 deletions filament/src/details/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ class FEngine : public Engine {
getDriver().purge();
}

void unprotected() noexcept;

void setAutomaticInstancingEnabled(bool enable) noexcept {
// instancing is not allowed at feature level 0
if (hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1)) {
Expand Down Expand Up @@ -539,6 +541,7 @@ class FEngine : public Engine {

mutable FMaterial const* mDefaultMaterial = nullptr;
mutable FMaterial const* mSkyboxMaterial = nullptr;
mutable FSwapChain* mUnprotectedDummySwapchain = nullptr;

mutable FTexture* mDefaultIblTexture = nullptr;
mutable FIndirectLight* mDefaultIbl = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions web/filament-js/jsbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ class_<Engine>("Engine")
return Engine::create();
}, allow_raw_pointers())

.function("unprotected", &Engine::unprotected)

.function("enableAccurateTranslations", &Engine::enableAccurateTranslations)

.function("setAutomaticInstancingEnabled", &Engine::setAutomaticInstancingEnabled)
Expand Down

0 comments on commit b5d7de0

Please sign in to comment.