Home | History | Annotate | Download | only in image
      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 
     17 package com.android.rs.image;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.graphics.BitmapFactory;
     23 import android.graphics.Bitmap;
     24 import android.graphics.Canvas;
     25 import android.renderscript.ScriptC;
     26 import android.renderscript.RenderScript;
     27 import android.renderscript.Type;
     28 import android.renderscript.Allocation;
     29 import android.renderscript.Element;
     30 import android.renderscript.Script;
     31 import android.view.SurfaceView;
     32 import android.view.SurfaceHolder;
     33 import android.widget.ImageView;
     34 import android.widget.SeekBar;
     35 import android.widget.TextView;
     36 import android.view.View;
     37 import android.util.Log;
     38 import java.lang.Math;
     39 import android.widget.Spinner;
     40 
     41 public class TestBase  {
     42     protected final String TAG = "Img";
     43 
     44     protected RenderScript mRS;
     45     protected Allocation mInPixelsAllocation;
     46     protected Allocation mInPixelsAllocation2;
     47     protected Allocation mOutPixelsAllocation;
     48     protected ImageProcessingActivity act;
     49 
     50     private class MessageProcessor extends RenderScript.RSMessageHandler {
     51         ImageProcessingActivity mAct;
     52 
     53         MessageProcessor(ImageProcessingActivity act) {
     54             mAct = act;
     55         }
     56 
     57         public void run() {
     58             mAct.updateDisplay();
     59         }
     60     }
     61 
     62     // Override to use UI elements
     63     public void onBar1Changed(int progress) {
     64     }
     65     public void onBar2Changed(int progress) {
     66     }
     67     public void onBar3Changed(int progress) {
     68     }
     69     public void onBar4Changed(int progress) {
     70     }
     71     public void onBar5Changed(int progress) {
     72     }
     73 
     74     // Override to use UI elements
     75     // Unused bars will be hidden.
     76     public boolean onBar1Setup(SeekBar b, TextView t) {
     77         b.setVisibility(View.INVISIBLE);
     78         t.setVisibility(View.INVISIBLE);
     79         return false;
     80     }
     81     public boolean onBar2Setup(SeekBar b, TextView t) {
     82         b.setVisibility(View.INVISIBLE);
     83         t.setVisibility(View.INVISIBLE);
     84         return false;
     85     }
     86     public boolean onBar3Setup(SeekBar b, TextView t) {
     87         b.setVisibility(View.INVISIBLE);
     88         t.setVisibility(View.INVISIBLE);
     89         return false;
     90     }
     91     public boolean onBar4Setup(SeekBar b, TextView t) {
     92         b.setVisibility(View.INVISIBLE);
     93         t.setVisibility(View.INVISIBLE);
     94         return false;
     95     }
     96     public boolean onBar5Setup(SeekBar b, TextView t) {
     97         b.setVisibility(View.INVISIBLE);
     98         t.setVisibility(View.INVISIBLE);
     99         return false;
    100     }
    101 
    102     public boolean onSpinner1Setup(Spinner s) {
    103         s.setVisibility(View.INVISIBLE);
    104         return false;
    105     }
    106 
    107     public final void createBaseTest(ImageProcessingActivity ipact, Bitmap b, Bitmap b2, Bitmap outb) {
    108         act = ipact;
    109         mRS = ipact.mRS;
    110         mRS.setMessageHandler(new MessageProcessor(act));
    111 
    112         mInPixelsAllocation = ipact.mInPixelsAllocation;
    113         mInPixelsAllocation2 = ipact.mInPixelsAllocation2;
    114         mOutPixelsAllocation = ipact.mOutPixelsAllocation;
    115 
    116         createTest(act.getResources());
    117     }
    118 
    119     // Must override
    120     public void createTest(android.content.res.Resources res) {
    121     }
    122 
    123     // Must override
    124     public void runTest() {
    125     }
    126 
    127     final public void runTestSendMessage() {
    128         runTest();
    129         mRS.sendMessage(0, null);
    130     }
    131 
    132     public void finish() {
    133         mRS.finish();
    134     }
    135 
    136     public void destroy() {
    137         mRS.setMessageHandler(null);
    138     }
    139 
    140     public void updateBitmap(Bitmap b) {
    141         mOutPixelsAllocation.copyTo(b);
    142     }
    143 
    144     // Override to configure specific benchmark config.
    145     public void setupBenchmark() {
    146     }
    147 
    148     // Override to reset after benchmark.
    149     public void exitBenchmark() {
    150     }
    151 }
    152