Home | History | Annotate | Download | only in sgtest
      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.sgtest;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.graphics.Bitmap;
     23 import android.renderscript.ScriptC;
     24 import android.renderscript.RenderScript;
     25 import android.renderscript.Type;
     26 import android.renderscript.Allocation;
     27 import android.renderscript.Element;
     28 import android.renderscript.Script;
     29 import android.view.SurfaceView;
     30 import android.view.SurfaceHolder;
     31 import android.widget.ImageView;
     32 import android.widget.SeekBar;
     33 import android.widget.TextView;
     34 import android.view.View;
     35 import android.util.Log;
     36 import java.lang.Math;
     37 import android.widget.Spinner;
     38 
     39 public 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