comparison android-project/src/org/libsdl/app/SDLActivity.java @ 4982:660d3a432102

Added some missing pixel formats and SDL_GetPixelFormatName()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 12 Jan 2011 14:53:23 -0800
parents 55b82067815b
children f9af88a9c823
comparison
equal deleted inserted replaced
4981:55b82067815b 4982:660d3a432102
22 /** 22 /**
23 SDL Activity 23 SDL Activity
24 */ 24 */
25 public class SDLActivity extends Activity { 25 public class SDLActivity extends Activity {
26 26
27 //Main components 27 // Main components
28 private static SDLActivity mSingleton; 28 private static SDLActivity mSingleton;
29 private static SDLSurface mSurface; 29 private static SDLSurface mSurface;
30 30
31 //Audio 31 // Audio
32 private static AudioTrack mAudioTrack; 32 private static AudioTrack mAudioTrack;
33 private static boolean bAudioIsEnabled; 33 private static boolean bAudioIsEnabled;
34 34
35 //Sensors 35 // Sensors
36 private static boolean bAccelIsEnabled; 36 private static boolean bAccelIsEnabled;
37 37
38 //feature IDs. Must match up on the C side as well. 38 // feature IDs. Must match up on the C side as well.
39 private static int FEATURE_AUDIO = 1; 39 private static int FEATURE_AUDIO = 1;
40 private static int FEATURE_ACCEL = 2; 40 private static int FEATURE_ACCEL = 2;
41 41
42 //Load the .so 42 // Load the .so
43 static { 43 static {
44 System.loadLibrary("SDL"); 44 System.loadLibrary("SDL");
45 System.loadLibrary("main"); 45 System.loadLibrary("main");
46 } 46 }
47 47
48 //Setup 48 // Setup
49 protected void onCreate(Bundle savedInstanceState) { 49 protected void onCreate(Bundle savedInstanceState) {
50 super.onCreate(savedInstanceState); 50 super.onCreate(savedInstanceState);
51 51
52 //So we can call stuff from static callbacks 52 // So we can call stuff from static callbacks
53 mSingleton = this; 53 mSingleton = this;
54 54
55 //Set up the surface 55 // Set up the surface
56 mSurface = new SDLSurface(getApplication()); 56 mSurface = new SDLSurface(getApplication());
57 setContentView(mSurface); 57 setContentView(mSurface);
58 SurfaceHolder holder = mSurface.getHolder(); 58 SurfaceHolder holder = mSurface.getHolder();
59 holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); 59 holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
60 60
61 } 61 }
62 62
63 //Audio 63 // Audio
64 public static boolean initAudio(){ 64 public static boolean initAudio(){
65 65
66 //blah. Hardcoded things are bad. FIXME when we have more sound stuff 66 // blah. Hardcoded things are bad. FIXME when we have more sound stuff
67 //working properly. 67 // working properly.
68 mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 68 mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
69 11025, 69 11025,
70 AudioFormat.CHANNEL_CONFIGURATION_MONO, 70 AudioFormat.CHANNEL_CONFIGURATION_MONO,
71 AudioFormat.ENCODING_PCM_8BIT, 71 AudioFormat.ENCODING_PCM_8BIT,
72 2048, 72 2048,
73 AudioTrack.MODE_STREAM); 73 AudioTrack.MODE_STREAM);
74 bAudioIsEnabled = true; 74 bAudioIsEnabled = true;
75 return true; 75 return true;
76 } 76 }
77 77
78 //Accel 78 // Accel
79 public static boolean initAccel(){ 79 public static boolean initAccel(){
80 mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); 80 mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
81 bAccelIsEnabled = true; 81 bAccelIsEnabled = true;
82 return true; 82 return true;
83 } 83 }
108 float y, float p); 108 float y, float p);
109 public static native void onNativeResize(int x, int y, int format); 109 public static native void onNativeResize(int x, int y, int format);
110 public static native void onNativeAccel(float x, float y, float z); 110 public static native void onNativeAccel(float x, float y, float z);
111 111
112 112
113 //Java functions called from C 113 // Java functions called from C
114 private static void createGLContext() { 114 private static void createGLContext() {
115 mSurface.initEGL(); 115 mSurface.initEGL();
116 } 116 }
117 117
118 public static void flipBuffers() { 118 public static void flipBuffers() {
132 } 132 }
133 133
134 public static void enableFeature(int featureid, int enabled) { 134 public static void enableFeature(int featureid, int enabled) {
135 Log.v("SDL","Feature " + featureid + " = " + enabled); 135 Log.v("SDL","Feature " + featureid + " = " + enabled);
136 136
137 //Yuck. This is all horribly inelegent. If it gets to more than a few 137 // Yuck. This is all horribly inelegent. If it gets to more than a few
138 //'features' I'll rip this out and make something nicer, I promise :) 138 // 'features' I'll rip this out and make something nicer, I promise :)
139 if(featureid == FEATURE_AUDIO){ 139 if(featureid == FEATURE_AUDIO){
140 if(enabled == 1){ 140 if(enabled == 1){
141 initAudio(); 141 initAudio();
142 }else{ 142 }else{
143 //We don't have one of these yet... 143 // We don't have one of these yet...
144 //closeAudio(); 144 //closeAudio();
145 } 145 }
146 } 146 }
147 147
148 else if(featureid == FEATURE_ACCEL){ 148 else if(featureid == FEATURE_ACCEL){
239 case PixelFormat.L_8: 239 case PixelFormat.L_8:
240 Log.v("SDL","pixel format L_8"); 240 Log.v("SDL","pixel format L_8");
241 break; 241 break;
242 case PixelFormat.RGBA_4444: 242 case PixelFormat.RGBA_4444:
243 Log.v("SDL","pixel format RGBA_4444"); 243 Log.v("SDL","pixel format RGBA_4444");
244 sdlFormat = 0x85421002; // Doesn't have an SDL constant... 244 sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
245 break; 245 break;
246 case PixelFormat.RGBA_5551: 246 case PixelFormat.RGBA_5551:
247 Log.v("SDL","pixel format RGBA_5551"); 247 Log.v("SDL","pixel format RGBA_5551");
248 sdlFormat = 0x85441002; // Doesn't have an SDL constant... 248 sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
249 break; 249 break;
250 case PixelFormat.RGBA_8888: 250 case PixelFormat.RGBA_8888:
251 Log.v("SDL","pixel format RGBA_8888"); 251 Log.v("SDL","pixel format RGBA_8888");
252 sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 252 sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
253 break; 253 break;
276 mSDLThread = new Thread(new SDLMain(), "SDLThread"); 276 mSDLThread = new Thread(new SDLMain(), "SDLThread");
277 mSDLThread.start(); 277 mSDLThread.start();
278 } 278 }
279 } 279 }
280 280
281 //unused 281 // unused
282 public void onDraw(Canvas canvas) {} 282 public void onDraw(Canvas canvas) {}
283 283
284 284
285 // EGL functions 285 // EGL functions
286 public boolean initEGL() { 286 public boolean initEGL() {
330 EGL10 egl = (EGL10)EGLContext.getEGL(); 330 EGL10 egl = (EGL10)EGLContext.getEGL();
331 GL10 gl = (GL10)mEGLContext.getGL(); 331 GL10 gl = (GL10)mEGLContext.getGL();
332 332
333 egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null); 333 egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
334 334
335 //drawing here 335 // drawing here
336 336
337 egl.eglWaitGL(); 337 egl.eglWaitGL();
338 338
339 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); 339 egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
340 340
368 int action = event.getAction(); 368 int action = event.getAction();
369 float x = event.getX(); 369 float x = event.getX();
370 float y = event.getY(); 370 float y = event.getY();
371 float p = event.getPressure(); 371 float p = event.getPressure();
372 372
373 //TODO: Anything else we need to pass? 373 // TODO: Anything else we need to pass?
374 SDLActivity.onNativeTouch(action, x, y, p); 374 SDLActivity.onNativeTouch(action, x, y, p);
375 return true; 375 return true;
376 } 376 }
377 377
378 // Sensor events 378 // Sensor events
379 public void enableSensor(int sensortype, boolean enabled) { 379 public void enableSensor(int sensortype, boolean enabled) {
380 //TODO: This uses getDefaultSensor - what if we have >1 accels? 380 // TODO: This uses getDefaultSensor - what if we have >1 accels?
381 if (enabled) { 381 if (enabled) {
382 mSensorManager.registerListener(this, 382 mSensorManager.registerListener(this,
383 mSensorManager.getDefaultSensor(sensortype), 383 mSensorManager.getDefaultSensor(sensortype),
384 SensorManager.SENSOR_DELAY_GAME, null); 384 SensorManager.SENSOR_DELAY_GAME, null);
385 } else { 385 } else {
387 mSensorManager.getDefaultSensor(sensortype)); 387 mSensorManager.getDefaultSensor(sensortype));
388 } 388 }
389 } 389 }
390 390
391 public void onAccuracyChanged(Sensor sensor, int accuracy) { 391 public void onAccuracyChanged(Sensor sensor, int accuracy) {
392 //TODO 392 // TODO
393 } 393 }
394 394
395 public void onSensorChanged(SensorEvent event) { 395 public void onSensorChanged(SensorEvent event) {
396 if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 396 if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
397 SDLActivity.onNativeAccel(event.values[0], 397 SDLActivity.onNativeAccel(event.values[0],