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