mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 19:13:03 +00:00
Move GLRenderer fetching into PcView to avoid race conditions inside Game activity and cache the result
This commit is contained in:
parent
06156c4d68
commit
777129ca90
@ -20,6 +20,7 @@ import com.limelight.nvstream.http.NvApp;
|
|||||||
import com.limelight.nvstream.input.KeyboardPacket;
|
import com.limelight.nvstream.input.KeyboardPacket;
|
||||||
import com.limelight.nvstream.input.MouseButtonPacket;
|
import com.limelight.nvstream.input.MouseButtonPacket;
|
||||||
import com.limelight.nvstream.jni.MoonBridge;
|
import com.limelight.nvstream.jni.MoonBridge;
|
||||||
|
import com.limelight.preferences.GlPreferences;
|
||||||
import com.limelight.preferences.PreferenceConfiguration;
|
import com.limelight.preferences.PreferenceConfiguration;
|
||||||
import com.limelight.ui.GameGestures;
|
import com.limelight.ui.GameGestures;
|
||||||
import com.limelight.ui.StreamView;
|
import com.limelight.ui.StreamView;
|
||||||
@ -44,7 +45,6 @@ import android.hardware.input.InputManager;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.opengl.GLSurfaceView;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -66,9 +66,6 @@ import android.widget.FrameLayout;
|
|||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
|
||||||
|
|
||||||
|
|
||||||
public class Game extends Activity implements SurfaceHolder.Callback,
|
public class Game extends Activity implements SurfaceHolder.Callback,
|
||||||
OnGenericMotionListener, OnTouchListener, NvConnectionListener, EvdevListener,
|
OnGenericMotionListener, OnTouchListener, NvConnectionListener, EvdevListener,
|
||||||
@ -108,7 +105,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
private ShortcutHelper shortcutHelper;
|
private ShortcutHelper shortcutHelper;
|
||||||
|
|
||||||
private MediaCodecDecoderRenderer decoderRenderer;
|
private MediaCodecDecoderRenderer decoderRenderer;
|
||||||
private String glRenderer;
|
|
||||||
|
|
||||||
private WifiManager.WifiLock wifiLock;
|
private WifiManager.WifiLock wifiLock;
|
||||||
|
|
||||||
@ -167,33 +163,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
// Change volume button behavior
|
// Change volume button behavior
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
|
||||||
// We first construct a GLSurfaceView to probe for GL
|
|
||||||
// properties to pass to MediaCodecHelper. After this completes,
|
|
||||||
// we'll construct the activity like normal.
|
|
||||||
GLSurfaceView surfaceView = new GLSurfaceView(this);
|
|
||||||
surfaceView.setRenderer(new GLSurfaceView.Renderer() {
|
|
||||||
@Override
|
|
||||||
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
|
|
||||||
glRenderer = gl10.glGetString(GL10.GL_RENDERER);
|
|
||||||
LimeLog.info("GL Renderer: "+glRenderer);
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
completeOnCreate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceChanged(GL10 gl10, int i, int i1) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDrawFrame(GL10 gl10) {}
|
|
||||||
});
|
|
||||||
setContentView(surfaceView);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void completeOnCreate() {
|
|
||||||
// Inflate the content
|
// Inflate the content
|
||||||
setContentView(R.layout.activity_game);
|
setContentView(R.layout.activity_game);
|
||||||
|
|
||||||
@ -257,7 +226,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
shortcutHelper.reportShortcutUsed(uuid);
|
shortcutHelper.reportShortcutUsed(uuid);
|
||||||
|
|
||||||
// Initialize the MediaCodec helper before creating the decoder
|
// Initialize the MediaCodec helper before creating the decoder
|
||||||
MediaCodecHelper.initialize(this, glRenderer);
|
MediaCodecHelper.initialize(this, GlPreferences.readPreferences(this).glRenderer);
|
||||||
|
|
||||||
// Check if the user has enabled HDR
|
// Check if the user has enabled HDR
|
||||||
if (prefConfig.enableHdr) {
|
if (prefConfig.enableHdr) {
|
||||||
|
@ -16,6 +16,7 @@ import com.limelight.nvstream.http.PairingManager;
|
|||||||
import com.limelight.nvstream.http.PairingManager.PairState;
|
import com.limelight.nvstream.http.PairingManager.PairState;
|
||||||
import com.limelight.nvstream.wol.WakeOnLanSender;
|
import com.limelight.nvstream.wol.WakeOnLanSender;
|
||||||
import com.limelight.preferences.AddComputerManually;
|
import com.limelight.preferences.AddComputerManually;
|
||||||
|
import com.limelight.preferences.GlPreferences;
|
||||||
import com.limelight.preferences.PreferenceConfiguration;
|
import com.limelight.preferences.PreferenceConfiguration;
|
||||||
import com.limelight.preferences.StreamSettings;
|
import com.limelight.preferences.StreamSettings;
|
||||||
import com.limelight.ui.AdapterFragment;
|
import com.limelight.ui.AdapterFragment;
|
||||||
@ -33,6 +34,8 @@ import android.content.Intent;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.opengl.GLSurfaceView;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -50,6 +53,9 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
|
||||||
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
public class PcView extends Activity implements AdapterFragmentCallbacks {
|
public class PcView extends Activity implements AdapterFragmentCallbacks {
|
||||||
private RelativeLayout noPcFoundLayout;
|
private RelativeLayout noPcFoundLayout;
|
||||||
private PcGridAdapter pcGridAdapter;
|
private PcGridAdapter pcGridAdapter;
|
||||||
@ -151,6 +157,46 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Create a GLSurfaceView to fetch GLRenderer unless we have
|
||||||
|
// a cached result already.
|
||||||
|
final GlPreferences glPrefs = GlPreferences.readPreferences(this);
|
||||||
|
if (!glPrefs.savedFingerprint.equals(Build.FINGERPRINT) || glPrefs.glRenderer.isEmpty()) {
|
||||||
|
GLSurfaceView surfaceView = new GLSurfaceView(this);
|
||||||
|
surfaceView.setRenderer(new GLSurfaceView.Renderer() {
|
||||||
|
@Override
|
||||||
|
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
|
||||||
|
// Save the GLRenderer string so we don't need to do this next time
|
||||||
|
glPrefs.glRenderer = gl10.glGetString(GL10.GL_RENDERER);
|
||||||
|
glPrefs.savedFingerprint = Build.FINGERPRINT;
|
||||||
|
glPrefs.writePreferences();
|
||||||
|
|
||||||
|
LimeLog.info("Fetched GL Renderer: " + glPrefs.glRenderer);
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
completeOnCreate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSurfaceChanged(GL10 gl10, int i, int i1) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawFrame(GL10 gl10) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setContentView(surfaceView);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LimeLog.info("Cached GL Renderer: " + glPrefs.glRenderer);
|
||||||
|
completeOnCreate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void completeOnCreate() {
|
||||||
shortcutHelper = new ShortcutHelper(this);
|
shortcutHelper = new ShortcutHelper(this);
|
||||||
|
|
||||||
UiHelper.setLocale(this);
|
UiHelper.setLocale(this);
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.limelight.preferences;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
public class GlPreferences {
|
||||||
|
private static final String PREF_NAME = "GlPreferences";
|
||||||
|
|
||||||
|
private static final String FINGERPRINT_PREF_STRING = "Fingerprint";
|
||||||
|
private static final String GL_RENDERER_PREF_STRING = "Renderer";
|
||||||
|
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
public String glRenderer;
|
||||||
|
public String savedFingerprint;
|
||||||
|
|
||||||
|
private GlPreferences(SharedPreferences prefs) {
|
||||||
|
this.prefs = prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GlPreferences readPreferences(Context context) {
|
||||||
|
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, 0);
|
||||||
|
GlPreferences glPrefs = new GlPreferences(prefs);
|
||||||
|
|
||||||
|
glPrefs.glRenderer = prefs.getString(GL_RENDERER_PREF_STRING, "");
|
||||||
|
glPrefs.savedFingerprint = prefs.getString(FINGERPRINT_PREF_STRING, "");
|
||||||
|
|
||||||
|
return glPrefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean writePreferences() {
|
||||||
|
return prefs.edit()
|
||||||
|
.putString(GL_RENDERER_PREF_STRING, glRenderer)
|
||||||
|
.putString(FINGERPRINT_PREF_STRING, savedFingerprint)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user