Skip to content
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

Initial work on supporting sustained perf mode #9901

Merged
merged 3 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ static ConfigSetting graphicsSettings[] = {
ConfigSetting("FullScreenMulti", &g_Config.bFullScreenMulti, false),
#endif

// TODO: Replace these settings with a list of options
ConfigSetting("SmallDisplayZoomType", &g_Config.iSmallDisplayZoomType, &DefaultZoomType, true, true),
ConfigSetting("SmallDisplayOffsetX", &g_Config.fSmallDisplayOffsetX, 0.5f, true, true),
ConfigSetting("SmallDisplayOffsetY", &g_Config.fSmallDisplayOffsetY, 0.5f, true, true),
ConfigSetting("SmallDisplayZoomLevel", &g_Config.fSmallDisplayZoomLevel, 1.0f, true, true),
ConfigSetting("ImmersiveMode", &g_Config.bImmersiveMode, false, true, true),
ConfigSetting("SustainedPerformanceMode", &g_Config.bSustainedPerformanceMode, false, true, true),

ReportedConfigSetting("TrueColor", &g_Config.bTrueColor, true, true, true),
ReportedConfigSetting("ReplaceTextures", &g_Config.bReplaceTextures, true, true, true),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct Config {
float fSmallDisplayOffsetY;
float fSmallDisplayZoomLevel; //This is used for zoom values, both in and out.
bool bImmersiveMode; // Mode on Android Kitkat 4.4 that hides the back button etc.
bool bSustainedPerformanceMode; // Android: Slows clocks down to avoid overheating/speed fluctuations.
bool bVSync;
int iFrameSkip;
bool bAutoFrameSkip;
Expand Down
1 change: 1 addition & 0 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void SystemInfoScreen::CreateViews() {
deviceSpecs->Add(new ItemHeader("OS Information"));
deviceSpecs->Add(new InfoItem("Memory Page Size", StringFromFormat("%d bytes", GetMemoryProtectPageSize())));
deviceSpecs->Add(new InfoItem("RW/RX exclusive: ", PlatformIsWXExclusive() ? "Yes" : "No"));
deviceSpecs->Add(new InfoItem("Sustained perf mode: ", System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE) ? "Yes" : "No"));

const char *build = "Release";
#ifdef _DEBUG
Expand Down
11 changes: 9 additions & 2 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ void GameSettingsScreen::CreateViews() {
static const char *screenRotation[] = {"Auto", "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed"};
PopupMultiChoice *rot = systemSettings->Add(new PopupMultiChoice(&g_Config.iScreenRotation, co->T("Screen Rotation"), screenRotation, 0, ARRAY_SIZE(screenRotation), co->GetName(), screenManager()));
rot->OnChoice.Handle(this, &GameSettingsScreen::OnScreenRotation);

if (System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE)) {
systemSettings->Add(new CheckBox(&g_Config.bSustainedPerformanceMode, sy->T("Sustained performance mode")))->OnClick.Handle(this, &GameSettingsScreen::OnSustainedPerformanceModeChange);
}
}
#endif

Expand Down Expand Up @@ -845,14 +849,17 @@ UI::EventReturn GameSettingsScreen::OnAdhocGuides(UI::EventParams &e) {

UI::EventReturn GameSettingsScreen::OnImmersiveModeChange(UI::EventParams &e) {
System_SendMessage("immersive", "");
const int SYSTEM_JELLYBEAN = 16;
// recreate doesn't seem reliable on earlier versions.
if (g_Config.iAndroidHwScale != 0) {
RecreateActivity();
}
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnSustainedPerformanceModeChange(UI::EventParams &e) {
System_SendMessage("sustainedPerfMode", "");
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnRenderingMode(UI::EventParams &e) {
// We do not want to report when rendering mode is Framebuffer to memory - so many issues
// are caused by that (framebuffer copies overwriting display lists, etc).
Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {

UI::EventReturn OnScreenRotation(UI::EventParams &e);
UI::EventReturn OnImmersiveModeChange(UI::EventParams &e);
UI::EventReturn OnSustainedPerformanceModeChange(UI::EventParams &e);

UI::EventReturn OnAdhocGuides(UI::EventParams &e);

Expand Down
2 changes: 2 additions & 0 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ std::string NativeQueryConfig(std::string query) {
}
// Otherwise, some devices prefer the Java init so play it safe.
return "true";
} else if (query == "sustainedPerformanceMode") {
return std::string(g_Config.bSustainedPerformanceMode ? "1" : "0");
} else {
return "";
}
Expand Down
6 changes: 6 additions & 0 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ static float dp_yscale = 1.0f;

static bool renderer_inited = false;
static bool renderer_ever_inited = false;
static bool sustainedPerfSupported = false;

// See NativeQueryConfig("androidJavaGL") to change this value.
static bool javaGL = true;

Expand Down Expand Up @@ -471,6 +473,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_SUPPORTS_PERMISSIONS:
return androidVersion >= 23; // 6.0 Marshmallow introduced run time permissions.
case SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE:
return sustainedPerfSupported; // 7.0 introduced sustained performance mode as an optional feature.
case SYSPROP_HAS_BACK_BUTTON:
return true;
case SYSPROP_HAS_IMAGE_BROWSER:
Expand Down Expand Up @@ -908,6 +912,8 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessage(JNIEnv *env
} else if (msg == "permission_granted") {
permissions[SYSTEM_PERMISSION_STORAGE] = PERMISSION_STATUS_GRANTED;
NativePermissionStatus(SYSTEM_PERMISSION_STORAGE, PERMISSION_STATUS_PENDING);
} else if (msg == "sustained_perf_supported") {
sustainedPerfSupported = true;
}

NativeMessageReceived(msg.c_str(), prm.c_str());
Expand Down
48 changes: 38 additions & 10 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.text.InputType;
Expand Down Expand Up @@ -84,9 +85,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
private int optimalFramesPerBuffer;
private int optimalSampleRate;

private boolean sustainedPerfSupported;

// audioFocusChangeListener to listen to changes in audio state
private AudioFocusChangeListener audioFocusChangeListener;
private AudioManager audioManager;
private PowerManager powerManager;

private Vibrator vibrator;

Expand Down Expand Up @@ -202,6 +206,13 @@ public void Initialize() {
// Get the optimal buffer sz
detectOptimalAudioSettings();
}
powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= 24) {
if (powerManager.isSustainedPerformanceModeSupported()) {
sustainedPerfSupported = true;
NativeApp.sendMessage("sustained_perf_supported", "1");
}
}

// isLandscape is used to trigger GetAppInfo currently, we
boolean landscape = NativeApp.isLandscape();
Expand Down Expand Up @@ -279,6 +290,20 @@ public void Initialize() {
}
}

@TargetApi(24)
private void updateSustainedPerformanceMode() {
// Query the native application on the desired rotation.
int enable = 0;
String str = NativeApp.queryConfig("sustainedPerformanceMode");
try {
enable = Integer.parseInt(str);
} catch (NumberFormatException e) {
Log.e(TAG, "Invalid perf mode: " + str);
return;
}
getWindow().setSustainedPerformanceMode(enable != 0);
}

@TargetApi(9)
private void updateScreenRotation() {
// Query the native application on the desired rotation.
Expand Down Expand Up @@ -388,6 +413,7 @@ public void onCreate(Bundle savedInstanceState) {

// OK, config should be initialized, we can query for screen rotation.
updateScreenRotation();
updateSustainedPerformanceMode();

// Keep the screen bright - very annoying if it goes dark when tilting away
Window window = this.getWindow();
Expand Down Expand Up @@ -1098,16 +1124,18 @@ public boolean processCommand(String command, String params) {
shuttingDown = true;
finish();
} else if (command.equals("rotate")) {
if (javaGL) {
updateScreenRotation();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Log.i(TAG, "Must recreate activity on rotation");
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
updateScreenRotation();
}
}
if (javaGL) {
updateScreenRotation();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Log.i(TAG, "Must recreate activity on rotation");
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
updateScreenRotation();
}
}
} else if (command.equals("sustainedPerfMode")) {
updateSustainedPerformanceMode();
} else if (command.equals("immersive")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
updateSystemUiVisibility();
Expand Down
1 change: 1 addition & 0 deletions ext/native/base/NativeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ enum SystemProperty {
SYSPROP_AUDIO_OPTIMAL_FRAMES_PER_BUFFER,

SYSPROP_SUPPORTS_PERMISSIONS,
SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE,
};

std::string System_GetProperty(SystemProperty prop);
Expand Down