1/* 2 * Copyright (C) 2012 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.rs.sgtest; 18 19import android.app.Activity; 20import android.content.Context; 21import android.os.Bundle; 22import android.graphics.Bitmap; 23import android.renderscript.ScriptC; 24import android.renderscript.RenderScript; 25import android.renderscript.Type; 26import android.renderscript.Allocation; 27import android.renderscript.Element; 28import android.renderscript.Script; 29import android.view.SurfaceView; 30import android.view.SurfaceHolder; 31import android.widget.ImageView; 32import android.widget.SeekBar; 33import android.widget.TextView; 34import android.view.View; 35import android.util.Log; 36import java.lang.Math; 37import android.widget.Spinner; 38 39public class TestBase { 40 protected final String TAG = "Img"; 41 42 protected RenderScript mRS; 43 protected Allocation mInPixelsAllocation; 44 // protected Allocation mInPixelsAllocation2; 45 protected Allocation mOutPixelsAllocation; 46 protected ScriptGroupTestActivity act; 47 48 private class MessageProcessor extends RenderScript.RSMessageHandler { 49 ScriptGroupTestActivity mAct; 50 51 MessageProcessor(ScriptGroupTestActivity act) { 52 mAct = act; 53 } 54 55 public void run() { 56 mAct.updateDisplay(); 57 } 58 } 59 60 public boolean onSpinnerSetup(Spinner s) { 61 s.setVisibility(View.INVISIBLE); 62 return false; 63 } 64 65 public final void createBaseTest(ScriptGroupTestActivity ipact) { 66 act = ipact; 67 mRS = ipact.mRS; 68 mRS.setMessageHandler(new MessageProcessor(act)); 69 70 mInPixelsAllocation = ipact.mInPixelsAllocation; 71 // mInPixelsAllocation2 = ipact.mInPixelsAllocation2; 72 mOutPixelsAllocation = ipact.mOutPixelsAllocation; 73 74 createTest(act.getResources()); 75 } 76 77 // Must override 78 public void createTest(android.content.res.Resources res) { 79 } 80 81 // Must override 82 public void runTest() { 83 } 84 85 final public void runTestSendMessage() { 86 runTest(); 87 mRS.sendMessage(0, null); 88 } 89 90 public void finish() { 91 mRS.finish(); 92 } 93 94 public void destroy() { 95 mRS.setMessageHandler(null); 96 } 97 98 public void updateBitmap(Bitmap b) { 99 mOutPixelsAllocation.copyTo(b); 100 } 101 102 // Override to configure specific benchmark config. 103 public void setupBenchmark() { 104 } 105 106 // Override to reset after benchmark. 107 public void exitBenchmark() { 108 } 109} 110