Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
32 KB
Referenced Files
None
Subscribers
None
diff --git a/util/android/src/org/liballeg/android/AllegroAPKStream.java b/util/android/src/org/liballeg/android/AllegroAPKStream.java
index 64779c39..08efc32b 100644
--- a/util/android/src/org/liballeg/android/AllegroAPKStream.java
+++ b/util/android/src/org/liballeg/android/AllegroAPKStream.java
@@ -1,157 +1,159 @@
package org.liballeg.android;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
class AllegroAPKStream
{
private static final String TAG = "AllegroAPKStream";
private AllegroActivity activity;
private String fn;
private InputStream in;
private long pos = 0;
private long fsize = -1;
private boolean at_eof = false;
AllegroAPKStream(AllegroActivity activity, String filename)
{
this.activity = activity;
fn = Path.simplifyPath(filename);
if (!fn.equals(filename)) {
Log.d(TAG, filename + " simplified to: " + fn);
}
}
boolean open()
{
try {
AssetFileDescriptor fd;
fd = activity.getResources().getAssets().openFd(fn);
fsize = fd.getLength();
fd.close();
}
catch (IOException e) {
Log.w(TAG, "could not get file size: " + e.toString());
fsize = -1;
}
return reopen();
}
boolean reopen()
{
if (in != null) {
close();
in = null;
}
try {
in = activity.getResources().getAssets().open(fn,
AssetManager.ACCESS_RANDOM);
}
catch (IOException e) {
Log.d(TAG, "Got IOException in reopen. fn='" + fn + "'");
return false;
}
in.mark((int)Math.pow(2, 31));
pos = 0;
at_eof = false;
return true;
}
- void close()
+ boolean close()
{
try {
in.close();
in = null;
+ return true;
}
catch (IOException e) {
Log.d(TAG, "IOException in close");
+ return false;
}
}
boolean seek(long seekto)
{
at_eof = false;
if (seekto >= pos) {
long seek_ahead = seekto - pos;
return force_skip(seek_ahead);
}
/* Seek backwards by rewinding to start of file first. */
try {
in.reset();
pos = 0;
}
catch (IOException e) {
if (!reopen()) {
/* Leaves pos wherever it lands! */
return false;
}
}
return force_skip(seekto);
}
private boolean force_skip(long n)
{
if (n <= 0)
return true;
/* NOTE: in.skip doesn't work here! */
byte[] b = new byte[(int)n];
while (n > 0) {
int res;
try {
res = in.read(b, 0, (int)n);
} catch (IOException e) {
Log.d(TAG, "IOException: " + e.toString());
return false;
}
if (res <= 0)
break;
pos += res;
n -= res;
}
return true;
}
long tell()
{
return pos;
}
int read(byte[] b)
{
try {
int ret = in.read(b);
if (ret > 0)
pos += ret;
else if (ret == -1) {
at_eof = true;
}
return ret;
}
catch (IOException e) {
Log.d(TAG, "IOException in read");
return -1;
}
}
long size()
{
return fsize;
}
boolean eof()
{
return at_eof;
}
}
/* vim: set sts=3 sw=3 et: */
diff --git a/util/android/src/org/liballeg/android/AllegroActivity.java b/util/android/src/org/liballeg/android/AllegroActivity.java
index 083303f0..ce9ed656 100644
--- a/util/android/src/org/liballeg/android/AllegroActivity.java
+++ b/util/android/src/org/liballeg/android/AllegroActivity.java
@@ -1,393 +1,393 @@
package org.liballeg.android;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import java.io.File;
import java.lang.Runnable;
import java.lang.String;
public class AllegroActivity extends Activity
{
/* properties */
private String userLibName = "libapp.so";
private Handler handler;
private Sensors sensors;
private Configuration currentConfig;
private AllegroSurface surface;
private ScreenLock screenLock;
private boolean exitedMain = false;
/* native methods we call */
native boolean nativeOnCreate();
native void nativeOnPause();
native void nativeOnResume();
native void nativeOnDestroy();
native void nativeOnOrientationChange(int orientation, boolean init);
/* methods native code calls */
String getUserLibName()
{
ApplicationInfo appInfo = getApplicationInfo();
String libDir = Reflect.getField(appInfo, "nativeLibraryDir");
/* Android < 2.3 doesn't have .nativeLibraryDir */
if (libDir == null) {
libDir = appInfo.dataDir + "/lib";
}
return libDir + "/" + userLibName;
}
String getResourcesDir()
{
//return getApplicationInfo().dataDir + "/assets";
//return getApplicationInfo().sourceDir + "/assets/";
return getFilesDir().getAbsolutePath();
}
String getPubDataDir()
{
return getFilesDir().getAbsolutePath();
}
String getApkPath()
{
return getApplicationInfo().sourceDir;
}
String getModel()
{
return android.os.Build.MODEL;
}
void postRunnable(Runnable runme)
{
try {
Log.d("AllegroActivity", "postRunnable");
handler.post( runme );
} catch (Exception x) {
Log.d("AllegroActivity", "postRunnable exception: " + x.getMessage());
}
}
void createSurface()
{
try {
Log.d("AllegroActivity", "createSurface");
surface = new AllegroSurface(getApplicationContext(),
getWindowManager().getDefaultDisplay());
SurfaceHolder holder = surface.getHolder();
holder.addCallback(surface);
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
//setContentView(surface);
Window win = getWindow();
win.setContentView(surface);
Log.d("AllegroActivity", "createSurface end");
} catch (Exception x) {
Log.d("AllegroActivity", "createSurface exception: " + x.getMessage());
}
}
void postCreateSurface()
{
try {
Log.d("AllegroActivity", "postCreateSurface");
handler.post(new Runnable() {
public void run() {
createSurface();
}
});
} catch (Exception x) {
Log.d("AllegroActivity", "postCreateSurface exception: " + x.getMessage());
}
}
void destroySurface()
{
Log.d("AllegroActivity", "destroySurface");
ViewGroup vg = (ViewGroup)(surface.getParent());
vg.removeView(surface);
surface = null;
}
void postDestroySurface()
{
try {
Log.d("AllegroActivity", "postDestroySurface");
handler.post(new Runnable() {
public void run() {
destroySurface();
}
});
} catch (Exception x) {
Log.d("AllegroActivity", "postDestroySurface exception: " + x.getMessage());
}
}
void postFinish()
{
exitedMain = true;
try {
Log.d("AllegroActivity", "posting finish!");
handler.post(new Runnable() {
public void run() {
try {
AllegroActivity.this.finish();
System.exit(0);
} catch (Exception x) {
Log.d("AllegroActivity", "inner exception: " + x.getMessage());
}
}
});
} catch (Exception x) {
Log.d("AllegroActivity", "exception: " + x.getMessage());
}
}
boolean getMainReturned()
{
return exitedMain;
}
boolean inhibitScreenLock(boolean inhibit)
{
if (screenLock == null) {
screenLock = new ScreenLock(this);
}
return screenLock.inhibitScreenLock(inhibit);
}
/* end of functions native code calls */
public AllegroActivity(String userLibName)
{
super();
this.userLibName = userLibName;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d("AllegroActivity", "onCreate");
Log.d("AllegroActivity", "Files Dir: " + getFilesDir());
File extdir = Environment.getExternalStorageDirectory();
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
// Something else is wrong. It may be one of many other states, but
// all we need to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
}
Log.d("AllegroActivity", "External Storage Dir: " + extdir.getAbsolutePath());
Log.d("AllegroActivity", "External Files Dir: " + getExternalFilesDir(null));
Log.d("AllegroActivity", "external: avail = " + mExternalStorageAvailable +
" writable = " + mExternalStorageWriteable);
Log.d("AllegroActivity", "sourceDir: " + getApplicationInfo().sourceDir);
Log.d("AllegroActivity", "publicSourceDir: " + getApplicationInfo().publicSourceDir);
handler = new Handler();
sensors = new Sensors(getApplicationContext());
currentConfig = new Configuration(getResources().getConfiguration());
Log.d("AllegroActivity", "before nativeOnCreate");
if (!nativeOnCreate()) {
finish();
Log.d("AllegroActivity", "nativeOnCreate failed");
return;
}
nativeOnOrientationChange(0, true);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Log.d("AllegroActivity", "onCreate end");
}
@Override
public void onStart()
{
super.onStart();
Log.d("AllegroActivity", "onStart.");
}
@Override
public void onRestart()
{
super.onRestart();
Log.d("AllegroActivity", "onRestart.");
}
@Override
public void onStop()
{
super.onStop();
Log.d("AllegroActivity", "onStop.");
}
/** Called when the activity is paused. */
@Override
public void onPause()
{
super.onPause();
Log.d("AllegroActivity", "onPause");
sensors.unlisten();
nativeOnPause();
Log.d("AllegroActivity", "onPause end");
}
/** Called when the activity is resumed/unpaused */
@Override
public void onResume()
{
Log.d("AllegroActivity", "onResume");
super.onResume();
sensors.listen();
nativeOnResume();
Log.d("AllegroActivity", "onResume end");
}
/** Called when the activity is destroyed */
@Override
public void onDestroy()
{
super.onDestroy();
Log.d("AllegroActivity", "onDestroy");
nativeOnDestroy();
Log.d("AllegroActivity", "onDestroy end");
}
/** Called when config has changed */
@Override
public void onConfigurationChanged(Configuration conf)
{
super.onConfigurationChanged(conf);
Log.d("AllegroActivity", "onConfigurationChanged");
// compare conf.orientation with some saved value
int changes = currentConfig.diff(conf);
Log.d("AllegroActivity", "changes: " + Integer.toBinaryString(changes));
if ((changes & ActivityInfo.CONFIG_FONT_SCALE) != 0)
Log.d("AllegroActivity", "font scale changed");
if ((changes & ActivityInfo.CONFIG_MCC) != 0)
Log.d("AllegroActivity", "mcc changed");
if ((changes & ActivityInfo.CONFIG_MNC) != 0)
Log.d("AllegroActivity", " changed");
if ((changes & ActivityInfo.CONFIG_LOCALE) != 0)
Log.d("AllegroActivity", "locale changed");
if ((changes & ActivityInfo.CONFIG_TOUCHSCREEN) != 0)
Log.d("AllegroActivity", "touchscreen changed");
if ((changes & ActivityInfo.CONFIG_KEYBOARD) != 0)
Log.d("AllegroActivity", "keyboard changed");
if ((changes & ActivityInfo.CONFIG_NAVIGATION) != 0)
Log.d("AllegroActivity", "navigation changed");
if ((changes & ActivityInfo.CONFIG_ORIENTATION) != 0) {
Log.d("AllegroActivity", "orientation changed");
nativeOnOrientationChange(getAllegroOrientation(), false);
}
if ((changes & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0)
Log.d("AllegroActivity", "screen layout changed");
if ((changes & ActivityInfo.CONFIG_UI_MODE) != 0)
Log.d("AllegroActivity", "ui mode changed");
if (currentConfig.screenLayout != conf.screenLayout) {
Log.d("AllegroActivity", "screenLayout changed!");
}
Log.d("AllegroActivity",
"old orientation: " + currentConfig.orientation
+ ", new orientation: " + conf.orientation);
currentConfig = new Configuration(conf);
}
/** Called when app is frozen **/
@Override
public void onSaveInstanceState(Bundle state)
{
Log.d("AllegroActivity", "onSaveInstanceState");
/* do nothing? */
/* This should get rid of the following warning:
* couldn't save which view has focus because the focused view has no id.
*/
}
- int getAndroidOrientation(int alleg_orientation)
+ void setAllegroOrientation(int alleg_orientation)
{
- return Const.toAndroidOrientation(alleg_orientation);
+ setRequestedOrientation(Const.toAndroidOrientation(alleg_orientation));
}
int getAllegroOrientation()
{
int rotation;
if (Reflect.methodExists(getWindowManager().getDefaultDisplay(),
"getRotation"))
{
/* 2.2+ */
rotation = getWindowManager().getDefaultDisplay().getRotation();
}
else {
rotation = getWindowManager().getDefaultDisplay().getOrientation();
}
return Const.toAllegroOrientation(rotation);
}
String getOsVersion()
{
return android.os.Build.VERSION.RELEASE;
}
}
/* vim: set sts=3 sw=3 et: */
diff --git a/util/android/src/org/liballeg/android/AllegroSurface.java b/util/android/src/org/liballeg/android/AllegroSurface.java
index 93351999..39832cfb 100644
--- a/util/android/src/org/liballeg/android/AllegroSurface.java
+++ b/util/android/src/org/liballeg/android/AllegroSurface.java
@@ -1,391 +1,146 @@
package org.liballeg.android;
import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.view.Display;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
-import java.util.ArrayList;
-import java.util.HashMap;
-import javax.microedition.khronos.egl.*;
class AllegroSurface extends SurfaceView implements SurfaceHolder.Callback
{
- static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
-
/** native functions we call */
public native void nativeOnCreate();
public native boolean nativeOnDestroy();
public native void nativeOnChange(int format, int width, int height);
/** functions that native code calls */
- private int[] egl_Version = { 0, 0 };
- private EGLContext egl_Context;
- private EGLSurface egl_Surface;
- private EGLDisplay egl_Display;
- private int egl_numConfigs = 0;
- private int[] egl_attribs;
- ArrayList<Integer> egl_attribWork = new ArrayList<Integer>();
- EGLConfig[] egl_Config = new EGLConfig[] { null };
- int[] es2_attrib = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL10.EGL_NONE};
-
boolean egl_Init()
{
- Log.d("AllegroSurface", "egl_Init");
- EGL10 egl = (EGL10)EGLContext.getEGL();
-
- EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
-
- if (!egl.eglInitialize(dpy, egl_Version)) {
- Log.d("AllegroSurface", "egl_Init fail");
- return false;
- }
-
- egl_Display = dpy;
-
- Log.d("AllegroSurface", "egl_Init end");
- return true;
+ return egl.egl_Init();
}
- void egl_setConfigAttrib(int attr, int value)
+ void egl_initRequiredAttribs()
{
- EGL10 egl = (EGL10)EGLContext.getEGL();
-
- int egl_attr = attr;
-
- switch (attr) {
- case Const.ALLEGRO_RED_SIZE:
- egl_attr = egl.EGL_RED_SIZE;
- break;
-
- case Const.ALLEGRO_GREEN_SIZE:
- egl_attr = egl.EGL_GREEN_SIZE;
- break;
-
- case Const.ALLEGRO_BLUE_SIZE:
- egl_attr = egl.EGL_BLUE_SIZE;
- break;
-
- case Const.ALLEGRO_ALPHA_SIZE:
- egl_attr = egl.EGL_ALPHA_SIZE;
- break;
-
- case Const.ALLEGRO_DEPTH_SIZE:
- egl_attr = egl.EGL_DEPTH_SIZE;
- break;
-
- case Const.ALLEGRO_STENCIL_SIZE:
- egl_attr = egl.EGL_STENCIL_SIZE;
- break;
-
- case Const.ALLEGRO_SAMPLE_BUFFERS:
- egl_attr = egl.EGL_SAMPLE_BUFFERS;
- break;
-
- case Const.ALLEGRO_SAMPLES:
- egl_attr = egl.EGL_SAMPLES;
- break;
-
- /* Allow others to pass right into the array */
- }
-
- /* Check if it's already in the list, if so change the value */
- for (int i = 0; i < egl_attribWork.size(); i++) {
- if (i % 2 == 0) {
- if (egl_attribWork.get(i) == egl_attr) {
- egl_attribWork.set(i+1, value);
- return;
- }
- }
- }
-
- /* Not in the list, add it */
- egl_attribWork.add(egl_attr);
- egl_attribWork.add(value);
+ egl.egl_initRequiredAttribs();
}
- private final int EGL_OPENGL_ES_BIT = 1;
- private final int EGL_OPENGL_ES2_BIT = 4;
-
- private boolean checkGL20Support(Context context)
+ void egl_setRequiredAttrib(int attr, int value)
{
- EGL10 egl = (EGL10) EGLContext.getEGL();
- //EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
-
- //int[] version = new int[2];
- //egl.eglInitialize(display, version);
-
- int[] configAttribs =
- {
- EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL10.EGL_NONE
- };
-
- EGLConfig[] configs = new EGLConfig[10];
- int[] num_config = new int[1];
- //egl.eglChooseConfig(display, configAttribs, configs, 10, num_config);
- egl.eglChooseConfig(egl_Display, configAttribs, configs, 10, num_config);
- //egl.eglTerminate(display);
- Log.d("AllegroSurface", "" + num_config[0] + " OpenGL ES 2 configurations found.");
- return num_config[0] > 0;
+ egl.egl_setRequiredAttrib(attr, value);
}
- private static HashMap<Integer, String> eglErrors;
- private static void checkEglError(String prompt, EGL10 egl) {
- if (eglErrors == null) {
- eglErrors = new HashMap<Integer, String>();
- eglErrors.put(EGL10.EGL_BAD_DISPLAY, "EGL_BAD_DISPLAY");
- eglErrors.put(EGL10.EGL_NOT_INITIALIZED, "EGL_NOT_INITIALIZED");
- eglErrors.put(EGL10.EGL_BAD_SURFACE, "EGL_BAD_SURFACE");
- eglErrors.put(EGL10.EGL_BAD_CONTEXT, "EGL_BAD_CONTEXT");
- eglErrors.put(EGL10.EGL_BAD_MATCH, "EGL_BAD_MATCH");
- eglErrors.put(EGL10.EGL_BAD_ACCESS, "EGL_BAD_ACCESS");
- eglErrors.put(EGL10.EGL_BAD_NATIVE_PIXMAP, "EGL_BAD_NATIVE_PIXMAP");
- eglErrors.put(EGL10.EGL_BAD_NATIVE_WINDOW, "EGL_BAD_NATIVE_WINDOW");
- eglErrors.put(EGL10.EGL_BAD_CURRENT_SURFACE, "EGL_BAD_CURRENT_SURFACE");
- eglErrors.put(EGL10.EGL_BAD_ALLOC, "EGL_BAD_ALLOC");
- eglErrors.put(EGL10.EGL_BAD_CONFIG, "EGL_BAD_CONFIG");
- eglErrors.put(EGL10.EGL_BAD_ATTRIBUTE, "EGL_BAD_ATTRIBUTE");
- eglErrors.put(EGL11.EGL_CONTEXT_LOST, "EGL_CONTEXT_LOST");
- }
- int error;
- while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {
- Log.e("Allegro", String.format("%s: EGL error: %s", prompt,
- eglErrors.get(error)));
- }
- }
-
- /* Return values:
- * 0 - failure
- * 1 - success
- * 2 - fell back to older ES version
- */
- int egl_createContext(int version)
+ int egl_chooseConfig(boolean programmable_pipeline)
{
- Log.d("AllegroSurface", "egl_createContext");
- EGL10 egl = (EGL10)EGLContext.getEGL();
- int ret = 1;
-
- es2_attrib[1] = version;
-
- egl_setConfigAttrib(EGL10.EGL_RENDERABLE_TYPE,
- (version == 2) ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_ES_BIT);
-
- boolean color_size_specified = false;
- for (int i = 0; i < egl_attribWork.size(); i++) {
- Log.d("AllegroSurface", "egl_attribs[" + i + "] = " + egl_attribWork.get(i));
- if (i % 2 == 0) {
- if (egl_attribWork.get(i) == EGL10.EGL_RED_SIZE ||
- egl_attribWork.get(i) == EGL10.EGL_GREEN_SIZE ||
- egl_attribWork.get(i) == EGL10.EGL_BLUE_SIZE)
- {
- color_size_specified = true;
- }
- }
- }
-
- egl_attribs = new int[egl_attribWork.size()+1];
- for (int i = 0; i < egl_attribWork.size(); i++) {
- egl_attribs[i] = egl_attribWork.get(i);
- }
- egl_attribs[egl_attribWork.size()] = EGL10.EGL_NONE;
-
- int[] num = new int[1];
- boolean retval = egl.eglChooseConfig(egl_Display, egl_attribs,
- egl_Config, 1, num);
- if (retval == false || num[0] < 1) {
- Log.e("AllegroSurface", "No matching config");
- return 0;
- }
-
- EGLContext ctx = egl.eglCreateContext(egl_Display, egl_Config[0],
- EGL10.EGL_NO_CONTEXT, es2_attrib);
- if (ctx == EGL10.EGL_NO_CONTEXT) {
- checkEglError("eglCreateContext", egl);
- Log.d("AllegroSurface", "egl_createContext no context");
- return 0;
- }
-
- Log.d("AllegroSurface", "EGL context created");
-
- egl_Context = ctx;
-
- Log.d("AllegroSurface", "egl_createContext end");
-
- return ret;
+ return egl.egl_chooseConfig(programmable_pipeline);
}
- private void egl_destroyContext()
+ void egl_getConfigAttribs(int index, int ret[])
{
- EGL10 egl = (EGL10)EGLContext.getEGL();
- Log.d("AllegroSurface", "destroying egl_Context");
- egl.eglDestroyContext(egl_Display, egl_Context);
- egl_Context = EGL10.EGL_NO_CONTEXT;
+ egl.egl_getConfigAttribs(index, ret);
}
- boolean egl_createSurface()
+ int egl_createContext(int configIndex, boolean programmable_pipeline)
{
- EGL10 egl = (EGL10)EGLContext.getEGL();
- EGLSurface surface = egl.eglCreateWindowSurface(egl_Display,
- egl_Config[0], this, null);
- if (surface == EGL10.EGL_NO_SURFACE) {
- Log.d("AllegroSurface", "egl_createSurface can't create surface (" + egl.eglGetError() + ")");
- return false;
- }
-
- if (!egl.eglMakeCurrent(egl_Display, surface, surface, egl_Context)) {
- egl.eglDestroySurface(egl_Display, surface);
- Log.d("AllegroSurface", "egl_createSurface can't make current");
- return false;
- }
-
- egl_Surface = surface;
-
- Log.d("AllegroSurface", "created new surface: " + surface);
-
- return true;
+ return egl.egl_createContext(configIndex, programmable_pipeline);
}
- private void egl_destroySurface()
+ boolean egl_createSurface()
{
- EGL10 egl = (EGL10)EGLContext.getEGL();
- if (!egl.eglMakeCurrent(egl_Display, EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT))
- {
- Log.d("AllegroSurface", "could not clear current context");
- }
-
- Log.d("AllegroSurface", "destroying egl_Surface");
- egl.eglDestroySurface(egl_Display, egl_Surface);
- egl_Surface = EGL10.EGL_NO_SURFACE;
+ return egl.egl_createSurface(this);
}
void egl_clearCurrent()
{
- Log.d("AllegroSurface", "egl_clearCurrent");
- EGL10 egl = (EGL10)EGLContext.getEGL();
- if (!egl.eglMakeCurrent(egl_Display, EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT))
- {
- Log.d("AllegroSurface", "could not clear current context");
- }
- Log.d("AllegroSurface", "egl_clearCurrent done");
+ egl.egl_clearCurrent();
}
void egl_makeCurrent()
{
- EGL10 egl = (EGL10)EGLContext.getEGL();
- if (!egl.eglMakeCurrent(egl_Display, egl_Surface, egl_Surface, egl_Context)) {
- // egl.eglDestroySurface(egl_Display, surface);
- // egl.eglTerminate(egl_Display);
- // egl_Display = null;
- Log.d("AllegroSurface", "can't make thread current: ");
- checkEglError("eglMakeCurrent", egl);
- }
+ egl.egl_makeCurrent();
}
void egl_SwapBuffers()
{
- try {
- EGL10 egl = (EGL10)EGLContext.getEGL();
-
- // FIXME: Pretty sure flush is implicit with SwapBuffers
- //egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
- //egl.eglWaitGL();
-
- egl.eglSwapBuffers(egl_Display, egl_Surface);
- checkEglError("eglSwapBuffers", egl);
-
- } catch (Exception x) {
- Log.d("AllegroSurface", "inner exception: " + x.getMessage());
- }
+ egl.egl_SwapBuffers();
}
/** main handlers */
+ private AllegroEGL egl;
private KeyListener key_listener;
private TouchListener touch_listener;
public AllegroSurface(Context context, Display display)
{
super(context);
Log.d("AllegroSurface", "PixelFormat=" + display.getPixelFormat());
getHolder().setFormat(display.getPixelFormat());
getHolder().addCallback(this);
+ this.egl = new AllegroEGL();
this.key_listener = new KeyListener(context);
this.touch_listener = new TouchListener();
}
private void grabFocus()
{
Log.d("AllegroSurface", "Grabbing focus");
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(key_listener);
setOnTouchListener(touch_listener);
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
Log.d("AllegroSurface", "surfaceCreated");
nativeOnCreate();
grabFocus();
Log.d("AllegroSurface", "surfaceCreated end");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.d("AllegroSurface", "surfaceDestroyed");
if (!nativeOnDestroy()) {
Log.d("AllegroSurface", "No surface created, returning early");
return;
}
- egl_makeCurrent();
-
- egl_destroySurface();
- egl_destroyContext();
-
- EGL10 egl = (EGL10)EGLContext.getEGL();
- egl.eglTerminate(egl_Display);
- egl_Display = null;
+ egl.egl_Terminate();
Log.d("AllegroSurface", "surfaceDestroyed end");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
Log.d("AllegroSurface", "surfaceChanged (width=" + width + " height=" + height + ")");
nativeOnChange(0xdeadbeef, width, height);
Log.d("AllegroSurface", "surfaceChanged end");
}
/* unused */
@Override
public void onDraw(Canvas canvas)
{
}
/* Events */
/* XXX not exposed in C API yet */
void setCaptureVolumeKeys(boolean onoff)
{
key_listener.setCaptureVolumeKeys(onoff);
}
}
/* vim: set sts=3 sw=3 et: */
diff --git a/util/android/src/org/liballeg/android/Const.java b/util/android/src/org/liballeg/android/Const.java
index 1ef5c74d..784d8e62 100644
--- a/util/android/src/org/liballeg/android/Const.java
+++ b/util/android/src/org/liballeg/android/Const.java
@@ -1,99 +1,100 @@
package org.liballeg.android;
import android.content.pm.ActivityInfo;
import android.view.Surface;
final class Const
{
/* color.h */
static final int ALLEGRO_PIXEL_FORMAT_ABGR_8888 = 17;
static final int ALLEGRO_PIXEL_FORMAT_BGR_565 = 20;
static final int ALLEGRO_PIXEL_FORMAT_RGBA_4444 = 26;
static final int ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8 = 27;
/* display.h */
static final int ALLEGRO_RED_SIZE = 0;
static final int ALLEGRO_GREEN_SIZE = 1;
static final int ALLEGRO_BLUE_SIZE = 2;
static final int ALLEGRO_ALPHA_SIZE = 3;
+ static final int ALLEGRO_COLOR_SIZE = 14;
static final int ALLEGRO_DEPTH_SIZE = 15;
static final int ALLEGRO_STENCIL_SIZE = 16;
static final int ALLEGRO_SAMPLE_BUFFERS = 17;
static final int ALLEGRO_SAMPLES = 18;
static final int ALLEGRO_DISPLAY_ORIENTATION_UNKNOWN = 0;
static final int ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES = 1;
static final int ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES = 2;
static final int ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES = 4;
static final int ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES = 8;
static final int ALLEGRO_DISPLAY_ORIENTATION_PORTRAIT = 5;
static final int ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE = 10;
static final int ALLEGRO_DISPLAY_ORIENTATION_ALL = 15;
static final int ALLEGRO_DISPLAY_ORIENTATION_FACE_UP = 16;
static final int ALLEGRO_DISPLAY_ORIENTATION_FACE_DOWN = 32;
/* events.h */
static final int ALLEGRO_EVENT_TOUCH_BEGIN = 50;
static final int ALLEGRO_EVENT_TOUCH_END = 51;
static final int ALLEGRO_EVENT_TOUCH_MOVE = 52;
static final int ALLEGRO_EVENT_TOUCH_CANCEL = 53;
static int toAndroidOrientation(int alleg_orientation)
{
switch (alleg_orientation)
{
case ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES:
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
case ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES:
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
case ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES:
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
case ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES:
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
case ALLEGRO_DISPLAY_ORIENTATION_PORTRAIT:
return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
case ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE:
return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
case ALLEGRO_DISPLAY_ORIENTATION_ALL:
return ActivityInfo.SCREEN_ORIENTATION_SENSOR;
}
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}
static int toAllegroOrientation(int rotation)
{
switch (rotation) {
case Surface.ROTATION_0:
return ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES;
case Surface.ROTATION_180:
return ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES;
/* Android device orientations are the opposite of Allegro ones.
* Allegro orientations are the orientation of the device, with 0
* being holding the device at normal orientation, 90 with the device
* rotated 90 degrees clockwise and so on. Android orientations are
* the orientations of the GRAPHICS. By rotating the device by 90
* degrees clockwise, the graphics are actually rotated 270 degrees,
* and that's what Android uses.
*/
case Surface.ROTATION_90:
return ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES;
case Surface.ROTATION_270:
return ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES;
}
return ALLEGRO_DISPLAY_ORIENTATION_UNKNOWN;
}
}
/* vim: set sts=3 sw=3 et: */

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:35 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70531
Default Alt Text
(32 KB)

Event Timeline