Merge pull request #21345 from hrydgard/more-regression-fixes

Fix image picker on Android, plus smoother fullscreen startup on Windows
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-03-05 01:52:22 +01:00
commit c3dbb7f608
9 files changed
+196 -31

No files matched your search

+24 -10
View File
@@ -851,8 +851,15 @@ bool BitCheckBox::Toggled() const {
}
void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
if (imageID_.isValid()) {
dc.Draw()->GetAtlas()->measureImage(imageID_, &w, &h);
ImageID imageId;
if (imageFunc_) {
imageId = imageFunc_();
} else {
imageId = imageID_;
}
if (imageId.isValid()) {
dc.Draw()->GetAtlas()->measureImage(imageId, &w, &h);
} else {
w = 0.0f;
h = 0.0f;
@@ -864,7 +871,7 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
dc.MeasureText(dc.GetTheme().uiFont, 1.0f, 1.0f, text_, &width, &height);
w += width;
if (imageID_.isValid()) {
if (imageId.isValid()) {
w += paddingW_;
}
h = std::max(h, height);
@@ -902,19 +909,26 @@ void Button::Draw(UIContext &dc) {
tw *= scale_;
th *= scale_;
if (tw > bounds_.w || imageID_.isValid()) {
ImageID imageId;
if (imageFunc_) {
imageId = imageFunc_();
} else {
imageId = imageID_;
}
if (tw > bounds_.w || imageId.isValid()) {
dc.PushScissor(bounds_);
}
dc.SetFontStyle(dc.GetTheme().uiFont);
dc.SetFontScale(scale_, scale_);
if (imageID_.isValid() && (ignoreText_ || text_.empty())) {
dc.Draw()->DrawImage(imageID_, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER);
if (imageId.isValid() && (ignoreText_ || text_.empty())) {
dc.Draw()->DrawImage(imageId, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER);
} else if (!text_.empty()) {
float textX = bounds_.centerX();
if (imageID_.isValid()) {
const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageID_);
if (imageId.isValid()) {
const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageId);
if (img) {
dc.Draw()->DrawImage(imageID_, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
dc.Draw()->DrawImage(imageId, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
textX += img->w / 2.0f;
}
}
@@ -922,7 +936,7 @@ void Button::Draw(UIContext &dc) {
}
dc.SetFontScale(1.0f, 1.0f);
if (tw > bounds_.w || imageID_.isValid()) {
if (tw > bounds_.w || imageId.isValid()) {
dc.PopScissor();
}
}
+4
View File
@@ -562,6 +562,9 @@ public:
void SetImageID(ImageID imageID) {
imageID_ = imageID;
}
void SetImageIDFunc(std::function<ImageID()> func) {
imageFunc_ = func;
}
void SetIgnoreText(bool ignore) {
ignoreText_ = ignore;
}
@@ -574,6 +577,7 @@ private:
Style style_;
std::string text_;
ImageID imageID_;
std::function<ImageID()> imageFunc_;
int paddingW_ = 16;
int paddingH_ = 8;
float scale_ = 1.0f;
+5 -6
View File
@@ -1456,16 +1456,15 @@ void MainScreen::CreateViews() {
ViewGroup *logo = new LogoView(false, new LinearLayoutParams(FILL_PARENT, 80.0f));
#if !defined(MOBILE_DEVICE)
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
ImageID icon(g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN");
UI::Button *fullscreenButton = logo->Add(new Button("", icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None)));
Button *fullscreenButton = logo->Add(new Button("", ImageID(), new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None)));
fullscreenButton->SetIgnoreText(true);
fullscreenButton->OnClick.Add([fullscreenButton](UI::EventParams &e) {
if (fullscreenButton) {
fullscreenButton->SetImageID(ImageID(!g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"));
}
fullscreenButton->OnClick.Add([this](UI::EventParams &e) {
g_Config.bFullScreen = !g_Config.bFullScreen;
System_ApplyFullscreenState();
});
fullscreenButton->SetImageIDFunc([this]() {
return g_Config.bFullScreen ? ImageID("I_RESTORE") : ImageID("I_FULLSCREEN");
});
#endif
rightColumnItems->Add(logo);
+6 -5
View File
@@ -335,7 +335,6 @@ namespace MainWindow {
g_Config.iWindowY = wp.rcNormalPosition.top;
g_Config.iWindowWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
g_Config.iWindowHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
wp.showCmd = SW_SHOW;
}
if (g_Config.bFullScreenMulti) {
@@ -352,6 +351,7 @@ namespace MainWindow {
totalX, totalY,
totalWidth, totalHeight,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
ShowWindow(hWnd, SW_SHOW);
} else {
MONITORINFO mi = {sizeof(mi)};
if (GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &mi)) {
@@ -365,6 +365,7 @@ namespace MainWindow {
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
ShowWindow(hWnd, SW_SHOW);
}
} else if (!goFullscreen && isCurrentlyFullscreen) {
INFO_LOG(Log::System, "ApplyFullscreenState: Exiting fullscreen to %s mode at %dx%d+%d+%d",
@@ -502,7 +503,7 @@ namespace MainWindow {
g_hMenu = GetMenu(hwndMain);
WINDOWPLACEMENT placement = {sizeof(WINDOWPLACEMENT)};
WINDOWPLACEMENT placement{sizeof(WINDOWPLACEMENT)};
if ((g_Config.iWindowX == -1 && g_Config.iWindowY == -1) || g_Config.iWindowWidth < 20 || g_Config.iWindowHeight < 20) {
RECT rc = DetermineDefaultWindowRectangle();
// Should be a first boot, or just bad parameters. Reset.
@@ -513,7 +514,8 @@ namespace MainWindow {
g_Config.iWindowHeight = rc.bottom - rc.top;
}
placement.showCmd = WindowSizeStateToShowCmd((WindowSizeState)g_Config.iWindowSizeState);
// Start as hidden in fullscreen mode. Makes for a nicer transition.
placement.showCmd = g_Config.bFullScreen ? SW_HIDE : WindowSizeStateToShowCmd((WindowSizeState)g_Config.iWindowSizeState);
placement.rcNormalPosition.left = g_Config.iWindowX;
placement.rcNormalPosition.top = g_Config.iWindowY;
placement.rcNormalPosition.right = g_Config.iWindowX + g_Config.iWindowWidth;
@@ -525,6 +527,7 @@ namespace MainWindow {
const DWM_WINDOW_CORNER_PREFERENCE pref = DWMWCP_DONOTROUND;
DwmSetWindowAttribute(hwndMain, DWMWA_WINDOW_CORNER_PREFERENCE, &pref, sizeof(pref));
ApplyFullscreenState(hwndMain, g_Config.bFullScreen);
MainMenuInit(hwndMain, g_hMenu);
@@ -534,8 +537,6 @@ namespace MainWindow {
hideCursor = true;
SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);
ApplyFullscreenState(hwndMain, g_Config.bFullScreen);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
touchHandler.registerTouchWindow(hwndMain);
+10
View File
@@ -1093,6 +1093,15 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
break;
}
// NOTE: We need to parse --fullscreen early, before we create the window.
if (!wcscmp(wideArgs[i].c_str(), L"--fullscreen")) {
g_Config.bFullScreen = true;
g_Config.DoNotSaveSetting(&g_Config.bFullScreen);
} else if (!wcscmp(wideArgs[i].c_str(), L"--windowed")) {
g_Config.bFullScreen = false;
g_Config.DoNotSaveSetting(&g_Config.bFullScreen);
}
if (wideArgs[i].find(gpuBackend) != std::wstring::npos && wideArgs[i].size() > gpuBackend.size()) {
const std::wstring restOfOption = wideArgs[i].substr(gpuBackend.size());
@@ -1115,6 +1124,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
}
}
}
}
#ifdef _DEBUG
g_Config.bEnableLogging = true;
+3 -1
View File
@@ -110,7 +110,9 @@
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>
<activity android:name=".ImageResultProxyActivity"
android:theme="@style/Theme.ProxyTransparent"
android:launchMode="standard" />
<profileable android:shell="true" android:enabled="true" />
</application>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.ProxyTransparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
@@ -0,0 +1,79 @@
package org.ppsspp.ppsspp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ImageResultProxyActivity extends AppCompatActivity {
public static final String TAG = "PPSSPP";
private String copyToCache(Uri selectedImage) {
Log.i(TAG, "Selected image: " + selectedImage);
File tempFile = new File(getExternalCacheDir(), "temp_import.jpg");
try (InputStream in = getContentResolver().openInputStream(selectedImage);
OutputStream out = new FileOutputStream(tempFile)) {
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Pass the local path back instead of the content:// URI
String returnPath = tempFile.getAbsolutePath();
Log.i(TAG, "Return path: " + returnPath);
return returnPath;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the Intent that was meant for the picker
Intent pickerIntent = getIntent().getParcelableExtra("picker_intent");
int requestId = getIntent().getIntExtra("request_id", -1);
Log.i(TAG, "Setting up activity launch, requestId = " + requestId);
ActivityResultLauncher<Intent> launcher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
Log.i(TAG, "Packing return intent, requestId = " + requestId);
Intent returnIntent = new Intent(this, PpssppActivity.class);
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
String localPath = copyToCache(result.getData().getData());
Log.i(TAG, "Putting extra: " + localPath);
// Pass the result back to the SingleInstance activity.
returnIntent.putExtra("result_path", localPath);
}
returnIntent.putExtra("result_code", result.getResultCode());
returnIntent.putExtra("request_id", requestId);
// This flag is key: it finds the existing instance of your main activity
returnIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(returnIntent);
finish();
}
);
launcher.launch(pickerIntent);
}
}
@@ -1643,9 +1643,13 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
try {
int requestId = Integer.parseInt(params);
int packedResultCode = packResultCode(RESULT_LOAD_IMAGE, requestId);
// 1. To Launch the picker:
Intent picker = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent proxy = new Intent(this, ImageResultProxyActivity.class);
proxy.putExtra("picker_intent", picker);
proxy.putExtra("request_id", requestId);
Log.i(TAG, "image request ID: " + requestId + " packed: " + packedResultCode);
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, packedResultCode);
startActivity(proxy);
return true;
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
NativeApp.reportException(e, params);
@@ -1945,16 +1949,57 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
}
}
public static void logIntentExtras(Intent intent) {
if (intent == null) {
Log.i(TAG, "Intent is null");
return;
}
Bundle bundle = intent.getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
String type = (value != null) ? value.getClass().getSimpleName() : "null";
Log.i(TAG, String.format("Extra Key: %s | Value: %s | Type: %s", key, value, type));
}
} else {
Log.i(TAG, "Intent has no extras.");
}
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
String value = parseIntent(intent);
if (value != null) {
// TODO: Actually send a command to the native code to launch the new game.
Log.i(TAG, "NEW INTENT AT RUNTIME: " + value);
Log.i(TAG, "Posting a 'shortcutParam' message to the C++ code.");
NativeApp.sendMessageFromJava("shortcutParam", value);
Log.i(TAG, "onNewIntent: " + intent.toString());
if (intent.hasExtra("request_id")) {
logIntentExtras(intent);
// This was a proxied image request.
int requestId = intent.getIntExtra("request_id", -1);
int resultCode = intent.getIntExtra("result_code", RESULT_CANCELED);
String path = intent.getStringExtra("result_path");
if (path != null) {
Log.i(TAG, "Received valid intent: " + path);
Log.i(TAG, "requestId: " + requestId + " resultCode: " + resultCode);
// Now you can call your native method
NativeApp.sendRequestResult(requestId, (resultCode == RESULT_OK), path, resultCode);
} else {
Log.i(TAG, "Received failed intent");
Log.i(TAG, "requestId: " + requestId + " resultCode: " + resultCode);
NativeApp.sendRequestResult(requestId, false,"", resultCode);
}
} else {
// Someone launched a shortcut while we were running....
setIntent(intent);
String value = parseIntent(intent);
if (value != null) {
// TODO: Actually send a command to the native code to launch the new game.
Log.i(TAG, "NEW INTENT AT RUNTIME: " + value);
Log.i(TAG, "Posting a 'shortcutParam' message to the C++ code.");
NativeApp.sendMessageFromJava("shortcutParam", value);
}
}
}