mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Take DPI into account. Fix some memory leaks in JNI code.
This commit is contained in:
parent
fad6a869d9
commit
b041bd474b
8 changed files with 75 additions and 39 deletions
|
@ -52,29 +52,24 @@ void Vibrate(int length_ms) {
|
|||
frameCommandParam = "100";
|
||||
}
|
||||
|
||||
void LaunchBrowser(const char *url)
|
||||
{
|
||||
void LaunchBrowser(const char *url) {
|
||||
frameCommand = "launchBrowser";
|
||||
frameCommandParam = url;
|
||||
}
|
||||
|
||||
void LaunchMarket(const char *url)
|
||||
{
|
||||
void LaunchMarket(const char *url) {
|
||||
frameCommand = "launchMarket";
|
||||
frameCommandParam = url;
|
||||
}
|
||||
|
||||
void LaunchEmail(const char *email_address)
|
||||
{
|
||||
void LaunchEmail(const char *email_address) {
|
||||
frameCommand = "launchEmail";
|
||||
frameCommandParam = email_address;
|
||||
}
|
||||
|
||||
|
||||
// Remember that all of these need initialization on init! The process
|
||||
// may be reused when restarting the game. Globals are DANGEROUS.
|
||||
|
||||
// Used for touch. (TODO)
|
||||
float xscale = 1;
|
||||
float yscale = 1;
|
||||
|
||||
|
@ -84,6 +79,14 @@ static bool renderer_inited = false;
|
|||
static bool first_lost = true;
|
||||
static bool use_native_audio = false;
|
||||
|
||||
std::string GetJavaString(JNIEnv *env, jstring jstr)
|
||||
{
|
||||
const char *str = env->GetStringUTFChars(jstr, 0);
|
||||
std::string cpp_string = std::string(str);
|
||||
env->ReleaseStringUTFChars(jstr, str);
|
||||
return cpp_string;
|
||||
}
|
||||
|
||||
extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isLandscape(JNIEnv *env, jclass) {
|
||||
std::string app_name, app_nice_name;
|
||||
bool landscape;
|
||||
|
@ -92,13 +95,19 @@ extern "C" jboolean Java_com_turboviking_libnative_NativeApp_isLandscape(JNIEnv
|
|||
}
|
||||
|
||||
extern "C" void Java_com_turboviking_libnative_NativeApp_init
|
||||
(JNIEnv *env, jclass, jint xxres, jint yyres, jstring apkpath,
|
||||
jstring dataDir, jstring externalDir, jstring libraryDir, jstring jinstallID, jboolean juseNativeAudio) {
|
||||
(JNIEnv *env, jclass, jint xxres, jint yyres, jint dpi, jstring japkpath,
|
||||
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jinstallID, jboolean juseNativeAudio) {
|
||||
jniEnvUI = env;
|
||||
|
||||
pixel_xres = xxres;
|
||||
pixel_yres = yyres;
|
||||
g_xres = xxres;
|
||||
g_yres = yyres;
|
||||
|
||||
g_dpi = dpi;
|
||||
|
||||
// We default to 160 dpi and all our UI code is written to assume it. (DENSITY_MEDIUM).
|
||||
g_xres = xxres * 160 / dpi;
|
||||
g_yres = yyres * 160 / dpi;
|
||||
|
||||
use_native_audio = juseNativeAudio;
|
||||
if (g_xres < g_yres)
|
||||
{
|
||||
|
@ -112,22 +121,16 @@ extern "C" void Java_com_turboviking_libnative_NativeApp_init
|
|||
renderer_inited = false;
|
||||
first_lost = true;
|
||||
|
||||
jboolean isCopy;
|
||||
const char *str = env->GetStringUTFChars(apkpath, &isCopy);
|
||||
ILOG("APK path: %s", str);
|
||||
VFSRegister("", new ZipAssetReader(str, "assets/"));
|
||||
std::string apkPath = GetJavaString(env, japkpath);
|
||||
ILOG("APK path: %s", apkPath.c_str());
|
||||
VFSRegister("", new ZipAssetReader(apkPath.c_str(), "assets/"));
|
||||
|
||||
str = env->GetStringUTFChars(externalDir, &isCopy);
|
||||
ILOG("External storage path: %s", str);
|
||||
std::string externalDir = GetJavaString(env, jexternalDir);
|
||||
std::string user_data_path = GetJavaString(env, jdataDir); + "/";
|
||||
std::string library_path = GetJavaString(env, jlibraryDir) + "/";
|
||||
std::string installID = GetJavaString(env, jinstallID);
|
||||
|
||||
str = env->GetStringUTFChars(dataDir, &isCopy);
|
||||
std::string user_data_path = std::string(str) + "/";
|
||||
|
||||
str = env->GetStringUTFChars(libraryDir, &isCopy);
|
||||
std::string library_path = std::string(str) + "/";
|
||||
|
||||
str = env->GetStringUTFChars(jinstallID, &isCopy);
|
||||
std::string installID = std::string(str);
|
||||
ILOG("External storage path: %s", externalDir.c_str());
|
||||
|
||||
std::string app_name;
|
||||
std::string app_nice_name;
|
||||
|
@ -213,9 +216,9 @@ extern "C" void Java_com_turboviking_libnative_NativeRenderer_displayRender
|
|||
|
||||
if (!frameCommand.empty()) {
|
||||
ILOG("frameCommand %s %s", frameCommand.c_str(), frameCommandParam.c_str());
|
||||
|
||||
jstring cmd = env->NewStringUTF(frameCommand.c_str());
|
||||
jstring param = env->NewStringUTF(frameCommandParam.c_str());
|
||||
|
||||
env->CallVoidMethod(obj, postCommand, cmd, param);
|
||||
|
||||
frameCommand = "";
|
||||
|
@ -239,8 +242,8 @@ extern "C" void Java_com_turboviking_libnative_NativeApp_audioRender(JNIEnv* en
|
|||
extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch
|
||||
(JNIEnv *, jclass, float x, float y, int code, int pointerId) {
|
||||
lock_guard guard(input_state.lock);
|
||||
if (pointerId >= MAX_POINTERS)
|
||||
{
|
||||
|
||||
if (pointerId >= MAX_POINTERS) {
|
||||
ELOG("Too many pointers: %i", pointerId);
|
||||
return; // We ignore 8+ pointers entirely.
|
||||
}
|
||||
|
@ -248,11 +251,9 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch
|
|||
input_state.mouse_x[pointerId] = (int)(x * xscale);
|
||||
input_state.mouse_y[pointerId] = (int)(y * yscale);
|
||||
if (code == 1) {
|
||||
//ILOG("Down: %i %f %f", pointerId, x, y);
|
||||
input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId];
|
||||
input_state.mouse_down[pointerId] = true;
|
||||
} else if (code == 2) {
|
||||
//ILOG("Up: %i %f %f", pointerId, x, y);
|
||||
input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId];
|
||||
input_state.mouse_down[pointerId] = false;
|
||||
}
|
||||
|
@ -307,8 +308,8 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_accelerometer
|
|||
extern "C" void Java_com_turboviking_libnative_NativeApp_sendMessage
|
||||
(JNIEnv *env, jclass, jstring message, jstring param) {
|
||||
jboolean isCopy;
|
||||
std::string msg(env->GetStringUTFChars(message, &isCopy));
|
||||
std::string prm(env->GetStringUTFChars(param, &isCopy));
|
||||
std::string msg = GetJavaString(env, message);
|
||||
std::string prm = GetJavaString(env, param);
|
||||
ILOG("Message received: %s %s", msg.c_str(), prm.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.opengl.GLSurfaceView;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -148,7 +149,11 @@ public class NativeActivity extends Activity {
|
|||
String dataDir = this.getFilesDir().getAbsolutePath();
|
||||
String apkFilePath = appInfo.sourceDir;
|
||||
NativeApp.sendMessage("Message from Java", "Hot Coffee");
|
||||
NativeApp.init(scrWidth, scrHeight, apkFilePath, dataDir, externalStorageDir, libraryDir, installID, useOpenSL);
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int dpi = metrics.densityDpi;
|
||||
// INIT!
|
||||
NativeApp.init(scrWidth, scrHeight, dpi, apkFilePath, dataDir, externalStorageDir, libraryDir, installID, useOpenSL);
|
||||
|
||||
// Keep the screen bright - very annoying if it goes dark when tilting away
|
||||
Window window = this.getWindow();
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.turboviking.libnative;
|
|||
public class NativeApp {
|
||||
public static native boolean isLandscape();
|
||||
public static native void init(
|
||||
int xxres, int yyres, String apkPath,
|
||||
int xxres, int yyres, int dpi, String apkPath,
|
||||
String dataDir, String externalDir, String libraryDir, String installID, boolean useOpenSL);
|
||||
|
||||
// These have Android semantics: Resume is always called on bootup, after init
|
||||
|
|
|
@ -128,7 +128,7 @@ int main(int argc, char *argv[]) {
|
|||
bool landscape;
|
||||
NativeGetAppInfo(&app_name, &app_name_nice, &landscape);
|
||||
|
||||
float zoom = 0.7f;
|
||||
float zoom = 1.0f;
|
||||
const char *zoomenv = getenv("ZOOM");
|
||||
if (zoomenv) {
|
||||
zoom = atof(zoomenv);
|
||||
|
@ -137,6 +137,7 @@ int main(int argc, char *argv[]) {
|
|||
pixel_xres = 800 * zoom;
|
||||
pixel_yres = 480 * zoom;
|
||||
} else {
|
||||
// PC development hack
|
||||
pixel_xres = 1580 * zoom;
|
||||
pixel_yres = 1000 * zoom;
|
||||
}
|
||||
|
|
|
@ -4,3 +4,5 @@ int g_xres;
|
|||
int g_yres;
|
||||
int pixel_xres;
|
||||
int pixel_yres;
|
||||
|
||||
int g_dpi;
|
|
@ -7,3 +7,5 @@ extern int g_xres;
|
|||
extern int g_yres;
|
||||
extern int pixel_xres;
|
||||
extern int pixel_yres;
|
||||
|
||||
extern int g_dpi;
|
|
@ -92,6 +92,8 @@
|
|||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="android\native-audio-so.h" />
|
||||
<ClInclude Include="android\native_audio.h" />
|
||||
<ClInclude Include="audio\mixer.h" />
|
||||
<ClInclude Include="audio\wav_read.h" />
|
||||
<ClInclude Include="base\basictypes.h" />
|
||||
|
@ -154,6 +156,14 @@
|
|||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\native-audio-so.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\native_audio.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="audio\mixer.cpp" />
|
||||
<ClCompile Include="audio\wav_read.cpp" />
|
||||
<ClCompile Include="base\buffer.cpp" />
|
||||
|
|
|
@ -175,6 +175,12 @@
|
|||
<ClInclude Include="net\resolve.h">
|
||||
<Filter>net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="android\native_audio.h">
|
||||
<Filter>android</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="android\native-audio-so.h">
|
||||
<Filter>android</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="gfx\gl_debug_log.cpp">
|
||||
|
@ -294,9 +300,6 @@
|
|||
<ClCompile Include="file\dialog.cpp">
|
||||
<Filter>file</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\app-android.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="util\bits\bits.cpp">
|
||||
<Filter>util</Filter>
|
||||
</ClCompile>
|
||||
|
@ -318,6 +321,15 @@
|
|||
<ClCompile Include="net\resolve.cpp">
|
||||
<Filter>net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\app-android.cpp">
|
||||
<Filter>android</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\native_audio.cpp">
|
||||
<Filter>android</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="android\native-audio-so.cpp">
|
||||
<Filter>android</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="gfx">
|
||||
|
@ -371,5 +383,8 @@
|
|||
<Filter Include="net">
|
||||
<UniqueIdentifier>{6a548b3d-3a4c-4114-aa2f-0b42bf7bf2ce}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="android">
|
||||
<UniqueIdentifier>{b7bc9a09-29c1-447b-9255-fe0709d10689}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Reference in a new issue