From e6857388c746e76614c7cebf2b53736453bddd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 10 Oct 2021 11:49:53 +0200 Subject: [PATCH] Add input device debug info to touchscreen test screen (yeah maybe there's a better place but it's fine). Also make a slight tweak to the detection order which I don't think matters much. --- Common/GPU/Vulkan/VulkanLoader.cpp | 2 - Common/GPU/Vulkan/VulkanLoader.h | 1 - UI/ControlMappingScreen.cpp | 25 ++++-- android/jni/app-android.cpp | 21 +++++ android/jni/app-android.h | 7 +- .../org/ppsspp/ppsspp/InputDeviceState.java | 80 +++++++++++++++++-- .../src/org/ppsspp/ppsspp/NativeActivity.java | 15 ++++ .../src/org/ppsspp/ppsspp/PpssppActivity.java | 8 ++ 8 files changed, 142 insertions(+), 17 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanLoader.cpp b/Common/GPU/Vulkan/VulkanLoader.cpp index 3666fc72e7..351668f0f8 100644 --- a/Common/GPU/Vulkan/VulkanLoader.cpp +++ b/Common/GPU/Vulkan/VulkanLoader.cpp @@ -62,7 +62,6 @@ PFN_vkBindImageMemory vkBindImageMemory; PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements; PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements; -PFN_vkGetPhysicalDeviceSparseImageFormatProperties vkGetPhysicalDeviceSparseImageFormatProperties; PFN_vkQueueBindSparse vkQueueBindSparse; PFN_vkCreateFence vkCreateFence; PFN_vkDestroyFence vkDestroyFence; @@ -586,7 +585,6 @@ void VulkanLoadDeviceFunctions(VkDevice device, const VulkanExtensions &enabledE LOAD_DEVICE_FUNC(device, vkGetBufferMemoryRequirements); LOAD_DEVICE_FUNC(device, vkGetImageMemoryRequirements); LOAD_DEVICE_FUNC(device, vkGetImageSparseMemoryRequirements); - LOAD_DEVICE_FUNC(device, vkGetPhysicalDeviceSparseImageFormatProperties); LOAD_DEVICE_FUNC(device, vkQueueBindSparse); LOAD_DEVICE_FUNC(device, vkCreateFence); LOAD_DEVICE_FUNC(device, vkDestroyFence); diff --git a/Common/GPU/Vulkan/VulkanLoader.h b/Common/GPU/Vulkan/VulkanLoader.h index 5808ae8076..c91c896a82 100644 --- a/Common/GPU/Vulkan/VulkanLoader.h +++ b/Common/GPU/Vulkan/VulkanLoader.h @@ -68,7 +68,6 @@ extern PFN_vkBindImageMemory vkBindImageMemory; extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements; extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements; extern PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements; -extern PFN_vkGetPhysicalDeviceSparseImageFormatProperties vkGetPhysicalDeviceSparseImageFormatProperties; extern PFN_vkQueueBindSparse vkQueueBindSparse; extern PFN_vkCreateFence vkCreateFence; extern PFN_vkDestroyFence vkDestroyFence; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index a4ec6e6657..2120435efc 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -45,6 +45,10 @@ #include "UI/ControlMappingScreen.h" #include "UI/GameSettingsScreen.h" +#if PPSSPP_PLATFORM(ANDROID) +#include "android/jni/app-android.h" +#endif + class SingleControlMapper : public UI::LinearLayout { public: SingleControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = nullptr); @@ -805,7 +809,7 @@ void TouchTestScreen::render() { ui_context->Begin(); - char buffer[1024]; + char buffer[2048]; for (int i = 0; i < MAX_TOUCH_POINTS; i++) { if (touches_[i].id != -1) { ui_context->Draw()->Circle(touches_[i].x, touches_[i].y, 100.0, 3.0, 80, 0.0f, 0xFFFFFFFF, 1.0); @@ -814,15 +818,19 @@ void TouchTestScreen::render() { } } + char extra_debug[2048]{}; + +#if PPSSPP_PLATFORM(ANDROID) + truncate_cpy(extra_debug, Android_GetInputDeviceDebugString().c_str()); +#endif + snprintf(buffer, sizeof(buffer), #if PPSSPP_PLATFORM(ANDROID) "display_res: %dx%d\n" #endif - "dp_res: %dx%d\n" - "pixel_res: %dx%d\n" - "g_dpi: %f\n" - "g_dpi_scale: %0.3fx%0.3f\n" - "g_dpi_scale_real: %0.3fx%0.3f\n", + "dp_res: %dx%d pixel_res: %dx%d\n" + "g_dpi: %0.3f g_dpi_scale: %0.3fx%0.3f\n" + "g_dpi_scale_real: %0.3fx%0.3f\n%s", #if PPSSPP_PLATFORM(ANDROID) display_xres, display_yres, #endif @@ -830,7 +838,10 @@ void TouchTestScreen::render() { pixel_xres, pixel_yres, g_dpi, g_dpi_scale_x, g_dpi_scale_y, - g_dpi_scale_real_x, g_dpi_scale_real_y); + g_dpi_scale_real_x, g_dpi_scale_real_y, extra_debug); + + // On Android, also add joystick debug data. + ui_context->DrawTextShadow(buffer, bounds.centerX(), bounds.y + 20.0f, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII); ui_context->Flush(); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 7b2f2079f2..df395e3048 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -170,6 +170,7 @@ static float g_safeInsetTop = 0.0; static float g_safeInsetBottom = 0.0; static jmethodID postCommand; +static jmethodID getDebugString; static jobject nativeActivity; static volatile bool exitRenderLoop; @@ -489,6 +490,24 @@ bool System_GetPropertyBool(SystemProperty prop) { } } +std::string Android_GetInputDeviceDebugString() { + if (!nativeActivity) { + return "(N/A)"; + } + auto env = getEnv(); + jstring param = env->NewStringUTF("InputDevice"); + + jstring str = (jstring)env->CallObjectMethod(nativeActivity, getDebugString, param); + if (!str) { + return "(N/A)"; + } + + const char *charArray = env->GetStringUTFChars(str, 0); + std::string retVal = charArray; + env->DeleteLocalRef(str); + return retVal; +} + std::string GetJavaString(JNIEnv *env, jstring jstr) { if (!jstr) return ""; @@ -501,7 +520,9 @@ std::string GetJavaString(JNIEnv *env, jstring jstr) { extern "C" void Java_org_ppsspp_ppsspp_NativeActivity_registerCallbacks(JNIEnv *env, jobject obj) { nativeActivity = env->NewGlobalRef(obj); postCommand = env->GetMethodID(env->GetObjectClass(obj), "postCommand", "(Ljava/lang/String;Ljava/lang/String;)V"); + getDebugString = env->GetMethodID(env->GetObjectClass(obj), "getDebugString", "(Ljava/lang/String;)Ljava/lang/String;"); _dbg_assert_(postCommand); + _dbg_assert_(getDebugString); Android_RegisterStorageCallbacks(env, obj); Android_StorageSetNativeActivity(nativeActivity); diff --git a/android/jni/app-android.h b/android/jni/app-android.h index d4cb8d2fee..9c78672561 100644 --- a/android/jni/app-android.h +++ b/android/jni/app-android.h @@ -11,7 +11,11 @@ #include "Common/File/Path.h" #include "Common/File/AndroidStorage.h" -#if PPSSPP_PLATFORM(ANDROID) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(ANDROID) + +std::string Android_GetInputDeviceDebugString(); + +#if !defined(__LIBRETRO__) #include @@ -22,5 +26,6 @@ class AndroidLogger : public LogListener { public: void Log(const LogMessage &message) override; }; +#endif #endif diff --git a/android/src/org/ppsspp/ppsspp/InputDeviceState.java b/android/src/org/ppsspp/ppsspp/InputDeviceState.java index c7dd18d7f0..d117b53167 100644 --- a/android/src/org/ppsspp/ppsspp/InputDeviceState.java +++ b/android/src/org/ppsspp/ppsspp/InputDeviceState.java @@ -8,6 +8,8 @@ import android.view.InputDevice.MotionRange; import android.view.KeyEvent; import android.view.MotionEvent; +import java.lang.annotation.Target; + @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) public class InputDeviceState { private static final String TAG = "InputDeviceState"; @@ -17,29 +19,95 @@ public class InputDeviceState { private InputDevice mDevice; private int[] mAxes; + private int sources; + InputDevice getDevice() { return mDevice; } @TargetApi(19) - void logAdvanced(InputDevice device) { - Log.i(TAG, "Vendor ID:" + device.getVendorId() + " productId: " + device.getProductId()); + static void logAdvanced(InputDevice device) { + Log.i(TAG, "Vendor ID:" + device.getVendorId() + " productId: " + device.getProductId() + " sources: " + String.format("%08x", device.getSources())); + } + + @TargetApi(19) + public String getDebugString() { + String str = mDevice.getName() + " sources: " + String.format("%08x", sources) + "\n classes: "; + + String[] classes = { "BUTTON ", "POINTER ", "TRACKBALL ", "POSITION ", "JOYSTICK " }; + for (int i = 0; i < 5; i++) { + if ((sources & (1 << i)) != 0) { + str += classes[i]; + } + } + str += "\n "; + + // Check the full identifications. + if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { + str += "GAMEPAD "; + } + + if ((sources & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) { + str += "KEYBOARD"; + if (mDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { + str += "(alpha) "; + } else { + str += " "; + } + } + + if ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) { + str += "JOYSTICK "; + } + if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) { + str += "DPAD "; + } + if ((sources & InputDevice.SOURCE_HDMI) == InputDevice.SOURCE_HDMI) { + // what? + str += "HDMI "; + } + if ((sources & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { + str += "MOUSE "; + } + if ((sources & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE) { + str += "MOUSE_RELATIVE "; + } + if ((sources & InputDevice.SOURCE_ROTARY_ENCODER) == InputDevice.SOURCE_ROTARY_ENCODER) { + str += "ROTARY_ENCODER "; + } + if ((sources & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) { + str += "STYLUS "; + } + if ((sources & InputDevice.SOURCE_TOUCHPAD) == InputDevice.SOURCE_TOUCHPAD) { + str += "TOUCHPAD "; + } + if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { + str += "TOUCHSCREEN "; + } + if ((sources & InputDevice.SOURCE_TOUCH_NAVIGATION) == InputDevice.SOURCE_TOUCH_NAVIGATION) { + str += "TOUCH_NAVIGATION "; + } + if ((sources & InputDevice.SOURCE_BLUETOOTH_STYLUS) == InputDevice.SOURCE_BLUETOOTH_STYLUS) { + str += "BLUETOOTH_STYLUS "; + } + str += "\n"; + return str; } public InputDeviceState(InputDevice device) { - int sources = device.getSources(); + sources = device.getSources(); // First, anything that's a gamepad is a gamepad, even if it has a keyboard or pointer. if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { this.deviceId = NativeApp.DEVICE_ID_PAD_0; } else if ((sources & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD && device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { this.deviceId = NativeApp.DEVICE_ID_KEYBOARD; - } else if ((sources & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) { - this.deviceId = NativeApp.DEVICE_ID_MOUSE; } else if ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK || (sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) { this.deviceId = NativeApp.DEVICE_ID_PAD_0; + } else if ((sources & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) { + this.deviceId = NativeApp.DEVICE_ID_MOUSE; } else { - // Built-in buttons like Back etc. + // Built-in device buttons like Back etc. this.deviceId = NativeApp.DEVICE_ID_DEFAULT; } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index fe7cba3de8..87a6ddf4be 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -930,6 +930,21 @@ public abstract class NativeActivity extends Activity { return state; } + protected String getInputDeviceDebugString() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + String buffer = ""; + for (InputDeviceState input : inputPlayers) { + buffer += input.getDebugString(); + } + if (buffer.length() == 0) { + buffer = "(no devices)"; + } + return buffer; + } else { + return "(input device debug not available before Android Kitkat)"; + } + } + public boolean IsXperiaPlay() { return android.os.Build.MODEL.equals("R800a") || android.os.Build.MODEL.equals("R800i") || android.os.Build.MODEL.equals("R800x") || android.os.Build.MODEL.equals("R800at") || android.os.Build.MODEL.equals("SO-01D") || android.os.Build.MODEL.equals("zeus"); } diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index 95e684659b..3142995042 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -135,6 +135,14 @@ public class PpssppActivity extends NativeActivity { }); } + public String getDebugString(String str) { + if (str.equals("InputDevice")) { + return getInputDeviceDebugString(); + } else { + return "bad debug string: " + str; + } + } + public int openContentUri(String uriString, String mode) { try { Uri uri = Uri.parse(uriString);