Skip to content

Commit

Permalink
updateDisplayMetrics was a poorly defined method, removed it.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 7, 2017
1 parent ae64519 commit 43de028
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 33 deletions.
89 changes: 56 additions & 33 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.database.Cursor;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -93,14 +94,17 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
private boolean shuttingDown;
private static int RESULT_LOAD_IMAGE = 1;

// Allow for multiple connected gamepads but just consider them the same for now.
// Actually this is not entirely true, see the code.
InputDeviceState inputPlayerA;
InputDeviceState inputPlayerB;
InputDeviceState inputPlayerC;
String inputPlayerADesc;
// Allow for multiple connected gamepads but just consider them the same for now.
// Actually this is not entirely true, see the code.
InputDeviceState inputPlayerA;
InputDeviceState inputPlayerB;
InputDeviceState inputPlayerC;
String inputPlayerADesc;

// Functions for the app activity to override to change behaviour.
float densityDpi;
float refreshRate;

// Functions for the app activity to override to change behaviour.

public native void registerCallbacks();
public native void unregisterCallbacks();
Expand Down Expand Up @@ -155,25 +159,46 @@ void GetScreenSizeJB(Point size, boolean real) {

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
void GetScreenSizeHC(Point size, boolean real) {
WindowManager w = getWindowManager();
WindowManager w = getWindowManager();
if (real && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
GetScreenSizeJB(size, real);
} else {
w.getDefaultDisplay().getSize(size);
}
}

private View GetSurfaceView() {
if (mGLSurfaceView != null)
return mGLSurfaceView;
if (mSurfaceView != null)
return mSurfaceView;
return null;
}

@SuppressWarnings("deprecation")
public void GetScreenSize(Point size) {
boolean real = useImmersive();
Rect rc = new Rect();

boolean real = useImmersive();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
GetScreenSizeHC(size, real);
} else {
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
size.x = d.getWidth();
size.y = d.getHeight();
}

Log.i(TAG, "Size old way: " + size.x + "x" + size.y);

View surface = GetSurfaceView();
if (surface != null) {
surface.getWindowVisibleDisplayFrame(rc);
size.x = rc.width();
size.y = rc.height();

Log.i(TAG, "Size new way: " + size.x + "x" + size.y);
}
}

public static final int REQUEST_CODE_STORAGE_PERMISSION = 1337;
Expand Down Expand Up @@ -384,19 +409,6 @@ public void run() {
// Tells the render loop thread to exit, so we can restart it.
public native void exitEGLRenderLoop();

void updateDisplayMetrics(Point outSize) {
DisplayMetrics metrics = new DisplayMetrics();
Display display = getWindowManager().getDefaultDisplay();
display.getMetrics(metrics);

float refreshRate = display.getRefreshRate();
if (outSize == null) {
outSize = new Point();
}
GetScreenSize(outSize);
NativeApp.setDisplayParameters(outSize.x, outSize.y, metrics.densityDpi, refreshRate);
}

public void getDesiredBackbufferSize(Point sz) {
NativeApp.computeDesiredBackbufferDimensions();
sz.x = NativeApp.getDesiredBackbufferWidth();
Expand All @@ -410,13 +422,17 @@ public void onCreate(Bundle savedInstanceState) {
shuttingDown = false;
registerCallbacks();

updateDisplayMetrics(null);

if (!initialized) {
Initialize();
initialized = true;
}

Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
densityDpi = metrics.densityDpi;
refreshRate = display.getRefreshRate();

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

Expand All @@ -428,7 +444,9 @@ public void onCreate(Bundle savedInstanceState) {
gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
NativeApp.audioInit();

updateDisplayMetrics(null);
Point outSize = new Point();
GetScreenSize(outSize);
NativeApp.setDisplayParameters(outSize.x, outSize.y, (int)densityDpi, refreshRate);
if (javaGL) {
mGLSurfaceView = new NativeGLView(this);
nativeRenderer = new NativeRenderer(this);
Expand Down Expand Up @@ -489,6 +507,8 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public void surfaceCreated(SurfaceHolder holder) {


Log.d(TAG, "Surface created.");
}

Expand All @@ -501,10 +521,10 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
}

Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format);
// Make sure we have fresh display metrics so the computations go right.
// This is needed on some very old devices, I guess event order is different or something...
Point sz = new Point();
updateDisplayMetrics(sz);

Point outSize = new Point();
GetScreenSize(outSize);
NativeApp.setDisplayParameters(outSize.x, outSize.y, (int)densityDpi, refreshRate);
NativeApp.backbufferResize(width, height, format);

mSurface = holder.getSurface();
Expand Down Expand Up @@ -676,8 +696,11 @@ public void onConfigurationChanged(Configuration newConfig) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
updateSystemUiVisibility();
}
updateDisplayMetrics(null);
if (javaGL) {
densityDpi = (float)newConfig.densityDpi;
Point outSize = new Point();
GetScreenSize(outSize);
NativeApp.setDisplayParameters(outSize.x, outSize.y, (int)densityDpi, refreshRate);
if (javaGL) {
Point sz = new Point();
getDesiredBackbufferSize(sz);
if (sz.x > 0) {
Expand Down
2 changes: 2 additions & 0 deletions android/src/org/ppsspp/ppsspp/NativeGLView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.bda.controller.*;

public class NativeGLView extends GLSurfaceView implements SensorEventListener, ControllerListener {
Expand Down

0 comments on commit 43de028

Please sign in to comment.