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
17package com.android.perftest;
18
19import java.io.Writer;
20import java.util.ArrayList;
21import java.util.concurrent.Semaphore;
22
23import android.renderscript.RSSurfaceView;
24import android.renderscript.RenderScript;
25import android.renderscript.RenderScriptGL;
26import android.renderscript.RenderScript.RSMessageHandler;
27
28import android.content.Context;
29import android.content.res.Resources;
30import android.graphics.Bitmap;
31import android.graphics.drawable.BitmapDrawable;
32import android.graphics.drawable.Drawable;
33import android.os.Handler;
34import android.os.Message;
35import android.util.AttributeSet;
36import android.util.Log;
37import android.view.Surface;
38import android.view.SurfaceHolder;
39import android.view.SurfaceView;
40import android.view.KeyEvent;
41import android.view.MotionEvent;
42
43public class RsBenchView extends RSSurfaceView {
44
45    public RsBenchView(Context context) {
46        super(context);
47    }
48
49    private RenderScriptGL mRS;
50    private RsBenchRS mRender;
51    private int mLoops = 0;
52
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
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     */
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     */
87    public boolean testIsFinished() {
88        return mRender.testIsFinished();
89    }
90
91    void setBenchmarkMode(int benchNum) {
92        mRender.setBenchmarkMode(benchNum);
93    }
94
95    void suspendRendering(boolean pause) {
96        mRender.pause(pause);
97    }
98
99    void setDebugMode(int num) {
100        mRender.setDebugMode(num);
101    }
102
103    String[] getTestNames() {
104        return mRender.mTestNames;
105    }
106}
107