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 @Override onKeyDown(int keyCode, KeyEvent event)75 public boolean onKeyDown(int keyCode, KeyEvent event) { 76 return super.onKeyDown(keyCode, event); 77 } 78 79 80 @Override onTouchEvent(MotionEvent ev)81 public boolean onTouchEvent(MotionEvent ev) { 82 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 } 91 92 /** 93 * Set the total number of loops the benchmark tests will run 94 * before the test results are collected. 95 */ setLoops(int iterations)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 */ testIsFinished()105 public boolean testIsFinished() { 106 return mRender.testIsFinished(); 107 } 108 setBenchmarkMode()109 void setBenchmarkMode() { 110 mRender.setBenchmarkMode(); 111 } 112 setDebugMode(int num)113 void setDebugMode(int num) { 114 mRender.setDebugMode(num); 115 } 116 getTestNames()117 String[] getTestNames() { 118 return mRender.mTestNames; 119 } 120 } 121