1 /*
2  * Copyright (C) 2008 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 
17 package com.android.perftest;
18 
19 import android.renderscript.RSSurfaceView;
20 import android.renderscript.RenderScript;
21 
22 import android.app.Activity;
23 import android.content.res.Configuration;
24 import android.content.Intent;
25 import android.net.Uri;
26 import android.os.Bundle;
27 import android.os.Handler;
28 import android.os.Looper;
29 import android.os.Message;
30 import android.provider.Settings.System;
31 import android.util.Log;
32 import android.view.Menu;
33 import android.view.MenuItem;
34 import android.view.MenuInflater;
35 import android.view.View;
36 import android.view.Window;
37 import android.widget.Button;
38 import android.widget.ListView;
39 import android.app.AlertDialog;
40 import android.content.DialogInterface;
41 import android.widget.Toast;
42 
43 import java.lang.Runtime;
44 
45 public class RsBench extends Activity {
46     private final String TAG = "RsBench";
47     public RsBenchView mView;
48 
49     @Override
onCreate(Bundle icicle)50     public void onCreate(Bundle icicle) {
51         super.onCreate(icicle);
52         int iterations = 0;
53         Intent intent = getIntent();
54         Uri uri = intent.getData();
55         if (uri != null) {
56             // when lauched from instrumentation
57             String scheme = uri.getScheme();
58             if ("iterations".equals(scheme)) {
59                 iterations = Integer.parseInt(uri.getSchemeSpecificPart());
60             }
61         }
62         // Create our Preview view and set it as the content of our
63         // Activity
64         mView = new RsBenchView(this);
65         setContentView(mView);
66         mView.setLoops(iterations);
67     }
68 
69     @Override
onResume()70     protected void onResume() {
71         // Ideally a game should implement onResume() and onPause()
72         // to take appropriate action when the activity loses focus
73         super.onResume();
74         mView.resume();
75     }
76 
77     @Override
onPause()78     protected void onPause() {
79         // Ideally a game should implement onResume() and onPause()
80         // to take appropriate action when the activity loses focus
81         super.onPause();
82         mView.pause();
83     }
84 
85     @Override
onCreateOptionsMenu(Menu menu)86     public boolean onCreateOptionsMenu(Menu menu) {
87         MenuInflater inflater = getMenuInflater();
88         inflater.inflate(R.menu.loader_menu, menu);
89         return true;
90     }
91 
92     @Override
onOptionsItemSelected(MenuItem item)93     public boolean onOptionsItemSelected(MenuItem item) {
94         // Handle item selection
95         switch (item.getItemId()) {
96             case R.id.benchmark_all:
97                 mView.setBenchmarkMode(-1);
98                 mView.suspendRendering(false);
99                 return true;
100             case R.id.benchmark_one:
101                 mView.suspendRendering(true);
102                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
103                 builder.setTitle("Pick a Test");
104                 builder.setItems(mView.getTestNames(),
105                                  new DialogInterface.OnClickListener() {
106                     public void onClick(DialogInterface dialog, int item) {
107                         Toast.makeText(getApplicationContext(),
108                                        "Starting to benchmark: " + mView.getTestNames()[item],
109                                        Toast.LENGTH_SHORT).show();
110                         mView.setBenchmarkMode(item);
111                         mView.suspendRendering(false);
112                     }
113                 });
114                 builder.show();
115                 return true;
116             case R.id.debug_mode:
117                 mView.suspendRendering(true);
118                 AlertDialog.Builder debugBuilder = new AlertDialog.Builder(this);
119                 debugBuilder.setTitle("Pick a Test");
120                 debugBuilder.setItems(mView.getTestNames(),
121                                  new DialogInterface.OnClickListener() {
122                     public void onClick(DialogInterface dialog, int item) {
123                         Toast.makeText(getApplicationContext(),
124                                        "Switching to: " + mView.getTestNames()[item],
125                                        Toast.LENGTH_SHORT).show();
126                         mView.setDebugMode(item);
127                         mView.suspendRendering(false);
128                     }
129                 });
130                 debugBuilder.show();
131                 return true;
132             default:
133                 return super.onOptionsItemSelected(item);
134         }
135     }
136 }
137