1/*
2 * Copyright (C) 2011 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.perftest;
18
19import android.os.Environment;
20import android.content.res.Resources;
21import android.renderscript.*;
22import android.util.DisplayMetrics;
23
24import android.util.Log;
25
26
27public class TextTest implements RsBenchBaseTest{
28
29    private static final String TAG = "TextTest";
30    private RenderScriptGL mRS;
31    private Resources mRes;
32
33    private ScriptC_text_test mTextScript;
34    ScriptField_TestScripts_s.Item[] mTests;
35
36    private final String[] mNames = {
37        "Fill screen with text 1 time",
38        "Fill screen with text 3 times",
39        "Fill screen with text 5 times"
40    };
41
42    public TextTest() {
43    }
44
45    void addTest(int index, int fillNum) {
46        mTests[index] = new ScriptField_TestScripts_s.Item();
47        mTests[index].testScript = mTextScript;
48        mTests[index].testName = Allocation.createFromString(mRS,
49                                                             mNames[index],
50                                                             Allocation.USAGE_SCRIPT);
51        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
52                                                                     mNames[index],
53                                                                     Allocation.USAGE_SCRIPT);
54
55        ScriptField_TextTestData_s.Item dataItem = new ScriptField_TextTestData_s.Item();
56        dataItem.fillNum = fillNum;
57        ScriptField_TextTestData_s testData = new ScriptField_TextTestData_s(mRS, 1);
58        testData.set(dataItem, 0, true);
59        mTests[index].testData = testData.getAllocation();
60    }
61
62    public boolean init(RenderScriptGL rs, Resources res) {
63        mRS = rs;
64        mRes = res;
65        initTextScript();
66        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
67
68        int index = 0;
69        addTest(index++, 1 /*fillNum*/);
70        addTest(index++, 3 /*fillNum*/);
71        addTest(index++, 5 /*fillNum*/);
72
73        return true;
74    }
75
76    public ScriptField_TestScripts_s.Item[] getTests() {
77        return mTests;
78    }
79
80    public String[] getTestNames() {
81        return mNames;
82    }
83
84    void initTextScript() {
85        DisplayMetrics metrics = mRes.getDisplayMetrics();
86
87        mTextScript = new ScriptC_text_test(mRS, mRes, R.raw.text_test);
88        mTextScript.set_gFontSans(Font.create(mRS, mRes, "sans-serif",
89                                              Font.Style.NORMAL, 8.0f / metrics.density));
90        mTextScript.set_gFontSerif(Font.create(mRS, mRes, "serif",
91                                               Font.Style.NORMAL, 8.0f / metrics.density));
92    }
93}
94