Debian Codegraph @

build-system/integration-test/test-projects/ndkSanAngeles/src/main/java/com/example/SanAngeles/DemoActivity.java

raw
1 /*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * This is a small port of the "San Angeles Observation" demo
17 * program for OpenGL ES 1.x. For more details, see:
18 *
19 * http://jet.ro/visuals/san-angeles-observation/
20 *
21 * This program demonstrates how to use a GLSurfaceView from Java
22 * along with native OpenGL calls to perform frame rendering.
23 *
24 * Touching the screen will start/stop the animation.
25 *
26 * Note that the demo runs much faster on the emulator than on
27 * real devices, this is mainly due to the following facts:
28 *
29 * - the demo sends bazillions of polygons to OpenGL without
30 * even trying to do culling. Most of them are clearly out
31 * of view.
32 *
33 * - on a real device, the GPU bus is the real bottleneck
34 * that prevent the demo from getting acceptable performance.
35 *
36 * - the software OpenGL engine used in the emulator uses
37 * the system bus instead, and its code rocks :-)
38 *
39 * Fixing the program to send less polygons to the GPU is left
40 * as an exercise to the reader. As always, patches welcomed :-)
41 */
42 package com.example.SanAngeles;
43
44 import android.app.Activity;
45 import android.content.Context;
46 import android.opengl.GLSurfaceView;
47 import android.os.Bundle;
48 import android.view.MotionEvent;
49
50 import javax.microedition.khronos.egl.EGLConfig;
51 import javax.microedition.khronos.opengles.GL10;
52
53 public class DemoActivity extends Activity {
54 @Override
55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
57 mGLView = new DemoGLSurfaceView(this);
58 setContentView(mGLView);
59 }
60
61 @Override
62 protected void onPause() {
63 super.onPause();
64 mGLView.onPause();
65 }
66
67 @Override
68 protected void onResume() {
69 super.onResume();
70 mGLView.onResume();
71 }
72
73 // visible for testing
74 GLSurfaceView mGLView;
75
76 static {
77 System.loadLibrary("sanangeles");
78 }
79 }
80
81 class DemoGLSurfaceView extends GLSurfaceView {
82 public DemoGLSurfaceView(Context context) {
83 super(context);
84 mRenderer = new DemoRenderer();
85 setRenderer(mRenderer);
86 }
87
88 public boolean onTouchEvent(final MotionEvent event) {
89 if (event.getAction() == MotionEvent.ACTION_DOWN) {
90 nativeTogglePauseResume();
91 }
92 return true;
93 }
94
95 @Override
96 public void onPause() {
97 super.onPause();
98 nativePause();
99 }
100
101 @Override
102 public void onResume() {
103 super.onResume();
104 nativeResume();
105 }
106
107
108 DemoRenderer mRenderer;
109
110 private static native void nativePause();
111 private static native void nativeResume();
112 private static native void nativeTogglePauseResume();
113 }
114
115 class DemoRenderer implements GLSurfaceView.Renderer {
116 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
117 nativeInit();
118 }
119
120 public void onSurfaceChanged(GL10 gl, int w, int h) {
121 //gl.glViewport(0, 0, w, h);
122 nativeResize(w, h);
123 }
124
125 public void onDrawFrame(GL10 gl) {
126 nativeRender();
127 }
128
129 private static native void nativeInit();
130 private static native void nativeResize(int w, int h);
131 private static native void nativeRender();
132 private static native void nativeDone();
133 }