blob: 2882b931c5890d057be48ec05f0ad315995e23a6 [file] [log] [blame]
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -08001/*
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
Alex Sakhartchoukc29a4442011-02-22 10:30:32 -080017package com.android.perftest;
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080018
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;
Xia Wang2738fb12011-04-15 17:24:08 -070026import android.renderscript.RenderScript.RSMessageHandler;
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080027
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);
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080047 }
48
49 private RenderScriptGL mRS;
50 private RsBenchRS mRender;
Xia Wang2738fb12011-04-15 17:24:08 -070051 private int mLoops = 0;
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080052
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();
Xia Wang2738fb12011-04-15 17:24:08 -070061 Log.v("RsBenchView", "mLoops = " + mLoops);
62 mRender.init(mRS, getResources(), w, h, mLoops);
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080063 }
64 }
65
66 @Override
67 protected void onDetachedFromWindow() {
68 if (mRS != null) {
69 mRS = null;
70 destroyRenderScriptGL();
71 }
72 }
73
74 @Override
Alex Sakhartchouk08571962010-12-15 09:59:58 -080075 public boolean onKeyDown(int keyCode, KeyEvent event) {
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080076 return super.onKeyDown(keyCode, event);
77 }
78
79
80 @Override
Alex Sakhartchouk08571962010-12-15 09:59:58 -080081 public boolean onTouchEvent(MotionEvent ev) {
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -080082 boolean ret = false;
83 int act = ev.getAction();
84 if (act == ev.ACTION_DOWN) {
85 mRender.onActionDown((int)ev.getX(), (int)ev.getY());
86 ret = true;
87 }
88
89 return ret;
90 }
Xia Wang2738fb12011-04-15 17:24:08 -070091
92 /**
93 * Set the total number of loops the benchmark tests will run
94 * before the test results are collected.
95 */
96 public void setLoops(int iterations) {
97 if (iterations > 0) {
98 mLoops = iterations;
99 }
100 }
101
102 /**
103 * Wait for message from the script
104 */
105 public boolean testIsFinished() {
106 return mRender.testIsFinished();
107 }
Alex Sakhartchouk6b5222d2010-12-13 14:48:21 -0800108}