-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Android: decouple JNI setup from unused subsystems #15895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -467,22 +467,28 @@ public void onClick(DialogInterface dialog,int id) { | |
| mSingleton = this; | ||
| SDL.setContext(this); | ||
|
|
||
| SDLControllerManager.initializeDeviceListener(); | ||
| if (SDL.isControllerManagerReady()) { | ||
| SDLControllerManager.initializeDeviceListener(); | ||
| } | ||
|
|
||
| mClipboardHandler = new SDLClipboardHandler(); | ||
| if (SDL.isSubsystemInitialized(SDL.SDL_INIT_VIDEO)) { | ||
| mClipboardHandler = new SDLClipboardHandler(); | ||
| } | ||
|
|
||
| mHIDDeviceManager = HIDDeviceManager.acquire(this); | ||
|
|
||
| // Set up the surface | ||
| mSurface = createSDLSurface(this); | ||
| if (SDL.isSubsystemInitialized(SDL.SDL_INIT_VIDEO)) { | ||
| mSurface = createSDLSurface(this); | ||
|
|
||
| mLayout = new RelativeLayout(this); | ||
| mLayout.addView(mSurface); | ||
| mLayout = new RelativeLayout(this); | ||
| mLayout.addView(mSurface); | ||
|
|
||
| // Get our current screen orientation and pass it down. | ||
| SDLActivity.nativeSetNaturalOrientation(SDLActivity.getNaturalOrientation()); | ||
| mCurrentRotation = SDLActivity.getCurrentRotation(); | ||
| SDLActivity.onNativeRotationChanged(mCurrentRotation); | ||
| // Get our current screen orientation and pass it down. | ||
| SDLActivity.nativeSetNaturalOrientation(SDLActivity.getNaturalOrientation()); | ||
| mCurrentRotation = SDLActivity.getCurrentRotation(); | ||
| SDLActivity.onNativeRotationChanged(mCurrentRotation); | ||
| } | ||
|
|
||
| try { | ||
| if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) { | ||
|
|
@@ -502,19 +508,22 @@ public void onClick(DialogInterface dialog,int id) { | |
| break; | ||
| } | ||
|
|
||
| setContentView(mLayout); | ||
|
|
||
| setWindowStyle(false); | ||
| if (mLayout != null) { | ||
| setContentView(mLayout); | ||
| setWindowStyle(false); | ||
| } | ||
|
|
||
| getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this); | ||
|
|
||
| // Get filename from "Open with" of another application | ||
| Intent intent = getIntent(); | ||
| if (intent != null && intent.getData() != null) { | ||
| String filename = intent.getData().getPath(); | ||
| if (filename != null) { | ||
| Log.v(TAG, "Got filename: " + filename); | ||
| SDLActivity.onNativeDropFile(filename); | ||
| if (SDL.isSubsystemInitialized(SDL.SDL_INIT_VIDEO)) { | ||
| Intent intent = getIntent(); | ||
| if (intent != null && intent.getData() != null) { | ||
| String filename = intent.getData().getPath(); | ||
| if (filename != null) { | ||
| Log.v(TAG, "Got filename: " + filename); | ||
| SDLActivity.onNativeDropFile(filename); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -886,21 +895,27 @@ public static void handleNativeState() { | |
|
|
||
| // Try a transition to resumed state | ||
| if (mNextNativeState == NativeState.RESUMED) { | ||
| if (mSurface.mIsSurfaceReady && (mHasFocus || mHasMultiWindow) && mIsResumedCalled) { | ||
| boolean readyToRun = (mSurface == null) ? mIsResumedCalled | ||
| : (mSurface.mIsSurfaceReady && (mHasFocus || mHasMultiWindow) && mIsResumedCalled); | ||
| if (readyToRun) { | ||
| if (mSDLThread == null) { | ||
| // This is the entry point to the C app. | ||
| // Start up the C app thread and enable sensor input for the first time | ||
| // FIXME: Why aren't we enabling sensor input at start? | ||
|
|
||
| mSDLThread = new Thread(new SDLMain(), "SDLThread"); | ||
| mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); | ||
| if (mSurface != null) { | ||
| mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); | ||
| } | ||
| mSDLThread.start(); | ||
|
|
||
| // No nativeResume(), don't signal Android_ResumeSem | ||
| } else { | ||
| nativeResume(); | ||
| } | ||
| mSurface.handleResume(); | ||
| if (mSurface != null) { | ||
| mSurface.handleResume(); | ||
| } | ||
|
|
||
| mCurrentNativeState = mNextNativeState; | ||
| } | ||
|
|
@@ -1058,7 +1073,8 @@ protected boolean sendCommand(int command, Object data) { | |
| DisplayMetrics realMetrics = new DisplayMetrics(); | ||
| display.getRealMetrics(realMetrics); | ||
|
|
||
| boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) && | ||
| boolean bFullscreenLayout = (mSurface != null) && | ||
| ((realMetrics.widthPixels == mSurface.getWidth()) && | ||
| (realMetrics.heightPixels == mSurface.getHeight())); | ||
|
|
||
| if ((Integer) data == 1) { | ||
|
|
@@ -1102,6 +1118,7 @@ protected boolean sendCommand(int command, Object data) { | |
| // C functions we call | ||
| public static native String nativeGetVersion(); | ||
| public static native void nativeSetupJNI(); | ||
| public static native int nativeGetCompiledSubsystems(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HTRamsey, @AntTheAlchemist, do we need to do something with proguard here? |
||
| public static native void nativeInitMainThread(); | ||
| public static native void nativeCleanupMainThread(); | ||
| public static native int nativeRunMain(String library, String function, Object arguments); | ||
|
|
@@ -1553,7 +1570,7 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC | |
| // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and | ||
| // SOURCE_JOYSTICK, while its key events arrive from the keyboard source | ||
| // So, retrieve the device itself and check all of its sources | ||
| if (SDLControllerManager.isDeviceSDLJoystick(device)) { | ||
| if (SDL.isControllerManagerReady() && SDLControllerManager.isDeviceSDLJoystick(device)) { | ||
| // Note that we process events with specific key codes here | ||
| if (event.getAction() == KeyEvent.ACTION_DOWN) { | ||
| if (SDLControllerManager.onNativePadDown(deviceId, keyCode, event.getScanCode())) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ static void initialize() { | |
| mJoystickHandler = new SDLJoystickHandler(); | ||
| } | ||
|
|
||
| if (mHapticHandler == null) { | ||
| if (mHapticHandler == null && SDL.isSubsystemInitialized(SDL.SDL_INIT_HAPTIC)) { | ||
| if (Build.VERSION.SDK_INT >= 31 /* Android 12.0 (S) */) { | ||
| mHapticHandler = new SDLHapticHandler_API31(); | ||
| } else if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) { | ||
|
|
@@ -977,10 +977,12 @@ boolean setRelativeMouseEnabled(boolean enabled) { | |
| } | ||
|
|
||
| if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) { | ||
| if (enabled) { | ||
| SDLActivity.getContentView().requestPointerCapture(); | ||
| } else { | ||
| SDLActivity.getContentView().releasePointerCapture(); | ||
| if (SDLActivity.getContentView() != null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put this into a temporary variable. |
||
| if (enabled) { | ||
| SDLActivity.getContentView().requestPointerCapture(); | ||
| } else { | ||
| SDLActivity.getContentView().releasePointerCapture(); | ||
| } | ||
| } | ||
| mRelativeModeEnabled = enabled; | ||
| return true; | ||
|
|
@@ -997,7 +999,7 @@ void reclaimRelativeMouseModeIfNeeded() { | |
| return; | ||
| } | ||
|
|
||
| if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) { | ||
| if (mRelativeModeEnabled && !SDLActivity.isDeXMode() && SDLActivity.getContentView() != null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, please put this into a temporary variable. |
||
| SDLActivity.getContentView().requestPointerCapture(); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.