TestBase.java revision 572a5031a5d8602db0bec0b253428a034bd4dd59
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.imagejb;
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;
39import android.widget.Spinner;
40
41public 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 ScriptC_msg mMessageScript;
49
50    protected ImageProcessingActivityJB act;
51
52    private class MessageProcessor extends RenderScript.RSMessageHandler {
53        ImageProcessingActivityJB mAct;
54
55        MessageProcessor(ImageProcessingActivityJB act) {
56            mAct = act;
57        }
58
59        public void run() {
60            mAct.updateDisplay();
61        }
62    }
63
64    // Override to use UI elements
65    public void onBar1Changed(int progress) {
66    }
67    public void onBar2Changed(int progress) {
68    }
69    public void onBar3Changed(int progress) {
70    }
71    public void onBar4Changed(int progress) {
72    }
73    public void onBar5Changed(int progress) {
74    }
75
76    // Override to use UI elements
77    // Unused bars will be hidden.
78    public boolean onBar1Setup(SeekBar b, TextView t) {
79        b.setVisibility(View.INVISIBLE);
80        t.setVisibility(View.INVISIBLE);
81        return false;
82    }
83    public boolean onBar2Setup(SeekBar b, TextView t) {
84        b.setVisibility(View.INVISIBLE);
85        t.setVisibility(View.INVISIBLE);
86        return false;
87    }
88    public boolean onBar3Setup(SeekBar b, TextView t) {
89        b.setVisibility(View.INVISIBLE);
90        t.setVisibility(View.INVISIBLE);
91        return false;
92    }
93    public boolean onBar4Setup(SeekBar b, TextView t) {
94        b.setVisibility(View.INVISIBLE);
95        t.setVisibility(View.INVISIBLE);
96        return false;
97    }
98    public boolean onBar5Setup(SeekBar b, TextView t) {
99        b.setVisibility(View.INVISIBLE);
100        t.setVisibility(View.INVISIBLE);
101        return false;
102    }
103
104    public boolean onSpinner1Setup(Spinner s) {
105        s.setVisibility(View.INVISIBLE);
106        return false;
107    }
108
109    public final void createBaseTest(ImageProcessingActivityJB ipact, Bitmap b, Bitmap b2, Bitmap outb) {
110        act = ipact;
111        mRS = ipact.mRS;
112        mRS.setMessageHandler(new MessageProcessor(act));
113
114        mInPixelsAllocation = ipact.mInPixelsAllocation;
115        mInPixelsAllocation2 = ipact.mInPixelsAllocation2;
116        mOutPixelsAllocation = ipact.mOutPixelsAllocation;
117
118        createTest(act.getResources());
119    }
120
121    // Must override
122    public void createTest(android.content.res.Resources res) {
123    }
124
125    // Must override
126    public void runTest() {
127    }
128
129    final public void runTestSendMessage() {
130        runTest();
131        mMessageScript.invoke_sendMsg();
132    }
133
134    public void finish() {
135        mRS.finish();
136    }
137
138    public void destroy() {
139        mRS.setMessageHandler(null);
140    }
141
142    public void updateBitmap(Bitmap b) {
143        mOutPixelsAllocation.copyTo(b);
144    }
145
146    // Override to configure specific benchmark config.
147    public void setupBenchmark() {
148    }
149
150    // Override to reset after benchmark.
151    public void exitBenchmark() {
152    }
153}
154