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 java.io.Writer;
20 import java.util.ArrayList;
21 import java.util.concurrent.Semaphore;
22 
23 import android.renderscript.RSSurfaceView;
24 import android.renderscript.RenderScript;
25 import android.renderscript.RenderScriptGL;
26 import android.renderscript.RenderScript.RSMessageHandler;
27 
28 import android.content.Context;
29 import android.content.res.Resources;
30 import android.graphics.Bitmap;
31 import android.graphics.drawable.BitmapDrawable;
32 import android.graphics.drawable.Drawable;
33 import android.os.Handler;
34 import android.os.Message;
35 import android.util.AttributeSet;
36 import android.util.Log;
37 import android.view.Surface;
38 import android.view.SurfaceHolder;
39 import android.view.SurfaceView;
40 import android.view.KeyEvent;
41 import android.view.MotionEvent;
42 
43 public class RsBenchView extends RSSurfaceView {
44 
RsBenchView(Context context)45     public RsBenchView(Context context) {
46         super(context);
47     }
48 
49     private RenderScriptGL mRS;
50     private RsBenchRS mRender;
51     private int mLoops = 0;
52 
surfaceChanged(SurfaceHolder holder, int format, int w, int h)53     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
54         super.surfaceChanged(holder, format, w, h);
55         if (mRS == null) {
56             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
57             sc.setDepth(16, 24);
58             mRS = createRenderScriptGL(sc);
59             mRS.setSurface(holder, w, h);
60             mRender = new RsBenchRS();
61             Log.v("RsBenchView", "mLoops = " + mLoops);
62             mRender.init(mRS, getResources(), w, h, mLoops);
63         }
64     }
65 
66     @Override
onDetachedFromWindow()67     protected void onDetachedFromWindow() {
68         if (mRS != null) {
69             mRS = null;
70             destroyRenderScriptGL();
71         }
72     }
73 
74     /**
75      * Set the total number of loops the benchmark tests will run
76      * before the test results are collected.
77      */
setLoops(int iterations)78     public void setLoops(int iterations) {
79         if (iterations > 0) {
80             mLoops = iterations;
81         }
82     }
83 
84     /**
85      * Wait for message from the script
86      */
testIsFinished()87     public boolean testIsFinished() {
88         return mRender.testIsFinished();
89     }
90 
setBenchmarkMode(int benchNum)91     void setBenchmarkMode(int benchNum) {
92         mRender.setBenchmarkMode(benchNum);
93     }
94 
suspendRendering(boolean pause)95     void suspendRendering(boolean pause) {
96         mRender.pause(pause);
97     }
98 
setDebugMode(int num)99     void setDebugMode(int num) {
100         mRender.setDebugMode(num);
101     }
102 
getTestNames()103     String[] getTestNames() {
104         return mRender.mTestNames;
105     }
106 }
107