TestBase.java revision 52541816fb308fcac31e86eb3293c2b28b0999de
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.image; 18 19import android.app.Activity; 20import android.content.Context; 21import android.os.Bundle; 22import android.graphics.BitmapFactory; 23import android.graphics.Bitmap; 24import android.graphics.Canvas; 25import android.renderscript.ScriptC; 26import android.renderscript.RenderScript; 27import android.renderscript.Type; 28import android.renderscript.Allocation; 29import android.renderscript.Element; 30import android.renderscript.Script; 31import android.view.SurfaceView; 32import android.view.SurfaceHolder; 33import android.widget.ImageView; 34import android.widget.SeekBar; 35import android.widget.TextView; 36import android.view.View; 37import android.util.Log; 38import java.lang.Math; 39 40public class TestBase { 41 protected final String TAG = "Img"; 42 43 protected RenderScript mRS; 44 protected Allocation mInPixelsAllocation; 45 protected Allocation mOutPixelsAllocation; 46 47 // Override to use UI elements 48 public void onBar1Changed(int progress) { 49 } 50 public void onBar2Changed(int progress) { 51 } 52 public void onBar3Changed(int progress) { 53 } 54 public void onBar4Changed(int progress) { 55 } 56 public void onBar5Changed(int progress) { 57 } 58 59 // Override to use UI elements 60 // Unused bars will be hidden. 61 public boolean onBar1Setup(SeekBar b, TextView t) { 62 b.setVisibility(View.INVISIBLE); 63 t.setVisibility(View.INVISIBLE); 64 return false; 65 } 66 public boolean onBar2Setup(SeekBar b, TextView t) { 67 b.setVisibility(View.INVISIBLE); 68 t.setVisibility(View.INVISIBLE); 69 return false; 70 } 71 public boolean onBar3Setup(SeekBar b, TextView t) { 72 b.setVisibility(View.INVISIBLE); 73 t.setVisibility(View.INVISIBLE); 74 return false; 75 } 76 public boolean onBar4Setup(SeekBar b, TextView t) { 77 b.setVisibility(View.INVISIBLE); 78 t.setVisibility(View.INVISIBLE); 79 return false; 80 } 81 public boolean onBar5Setup(SeekBar b, TextView t) { 82 b.setVisibility(View.INVISIBLE); 83 t.setVisibility(View.INVISIBLE); 84 return false; 85 } 86 87 public final void createBaseTest(ImageProcessingActivity act, Bitmap b) { 88 mRS = RenderScript.create(act); 89 mInPixelsAllocation = Allocation.createFromBitmap(mRS, b, 90 Allocation.MipmapControl.MIPMAP_NONE, 91 Allocation.USAGE_SCRIPT); 92 mOutPixelsAllocation = Allocation.createFromBitmap(mRS, b, 93 Allocation.MipmapControl.MIPMAP_NONE, 94 Allocation.USAGE_SCRIPT); 95 createTest(act.getResources()); 96 } 97 98 // Must override 99 public void createTest(android.content.res.Resources res) { 100 android.util.Log.e("img", "implement createTest"); 101 } 102 103 // Must override 104 public void runTest() { 105 } 106 107 public void finish() { 108 mRS.finish(); 109 } 110 111 public void updateBitmap(Bitmap b) { 112 mOutPixelsAllocation.copyTo(b); 113 } 114 115 // Override to configure specific benchmark config. 116 public void setupBenchmark() { 117 } 118 119 // Override to reset after benchmark. 120 public void exitBenchmark() { 121 } 122} 123