Skip to content

Commit

Permalink
AndroidJniProvider now has acquire and release calls instead of get
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Apr 12, 2024
1 parent dc925ad commit a188ce0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ namespace Ogre
public:
/** User must override this function.
@param env [out]
The JNI class that is assumed to be from AttachCurrentThread.
The JNI class that is assumed to be from AttachCurrentThread().
@param activity [out]
NativeActivity object handle, used for JNI.
*/
virtual void get( JNIEnv **env, jobject *activity ) = 0;
virtual void acquire( JNIEnv **env, jobject *activity ) = 0;

/** Notifies the implementation that we're done using the env object.
In case the implementation wants to call DetachCurrentThread().
@param env
The JNI class that was retrieved via acquire().
*/
virtual void release( JNIEnv *env ) = 0;
};

class _OgreVulkanExport VulkanAndroidWindow final : public VulkanWindowSwapChainBased
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,14 @@ namespace Ogre
"VulkanAndroidWindow::createSwapchain" );
}

JNIEnv *jni = 0;
jobject nativeActivityClass = 0;
mJniProvider->get( &jni, &nativeActivityClass );
SwappyVk_initAndGetRefreshCycleDuration( jni, nativeActivityClass, mDevice->mPhysicalDevice,
mDevice->mDevice, mSwapchain, &mRefreshDuration );
{
JNIEnv *jni = 0;
jobject nativeActivityClass = 0;
mJniProvider->acquire( &jni, &nativeActivityClass );
SwappyVk_initAndGetRefreshCycleDuration( jni, nativeActivityClass, mDevice->mPhysicalDevice,
mDevice->mDevice, mSwapchain, &mRefreshDuration );
mJniProvider->release( jni );
}

// Swappy wants to know the mNativeWindow every time the Swapchain changes.
// If we try to set mNativeWindow without a valid mSwapchain yet, it won't work correctly.
Expand Down

0 comments on commit a188ce0

Please sign in to comment.