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