~ubuntu-branches/ubuntu/raring/glmark2/raring

« back to all changes in this revision

Viewing changes to android/src/org/linaro/glmark2/BenchmarkListManager.java

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2012-08-21 15:38:09 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120821153809-bwux72bat8qp2n5v
Tags: 2012.08-0ubuntu1
* New upstream release 2012.08 (LP: #1039736)
  - Avoid crashing if gl used is not >= 2.0 (LP: #842279)
* Bumping dh compatibility level to v9
* debian/control:
  - Update Standards-Version to 3.9.3.
  - Add libjpeg-dev build dependency.
  - Use libegl1-x11-dev as an build-dep alternative instead of libegl1-dev.
  - Update description of glmark2-data binary package.
* debian/copyright:
  - Refresh copyright based on the current upstrem version
* debian/rules:
  - Clean compiled python code from unpacked waflib/ directory, as
    described in http://wiki.debian.org/UnpackWaf

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Linaro Limited
 
3
 *
 
4
 * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
 
5
 *
 
6
 * glmark2 is free software: you can redistribute it and/or modify it under the
 
7
 * terms of the GNU General Public License as published by the Free Software
 
8
 * Foundation, either version 3 of the License, or (at your option) any later
 
9
 * version.
 
10
 *
 
11
 * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
 
12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
 * details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along with
 
17
 * glmark2.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * Authors:
 
20
 *  Alexandros Frantzis
 
21
 */
 
22
package org.linaro.glmark2;
 
23
 
 
24
import java.util.ArrayList;
 
25
import java.util.Collections;
 
26
import java.io.*;
 
27
 
 
28
import android.app.Activity;
 
29
import android.os.Environment;
 
30
 
 
31
class BenchmarkListManager {
 
32
 
 
33
    private ArrayList<String> benchmarks;
 
34
    private Activity activity;
 
35
 
 
36
    BenchmarkListManager(Activity activity, ArrayList<String> benchmarks)
 
37
    {
 
38
        this.activity = activity;
 
39
        if (benchmarks == null) {
 
40
            this.benchmarks = new ArrayList<String>();
 
41
            this.benchmarks.add("Add benchmark...");
 
42
        }
 
43
        else {
 
44
            this.benchmarks = benchmarks;
 
45
        }
 
46
    }
 
47
 
 
48
    /** 
 
49
     * Gets the list holding the benchmarks.
 
50
     *
 
51
     * The reference to this list is constant for the life of
 
52
     * the BenchmarkListManager,
 
53
     * 
 
54
     * @return the operation error code
 
55
     */
 
56
    ArrayList<String> getBenchmarkList() {
 
57
        return benchmarks;
 
58
    }
 
59
 
 
60
    /** 
 
61
     * Gets the saved benchmark lists.
 
62
     * 
 
63
     * Each list name is prefixed with either "internal/" or "external/"
 
64
     * to denote in which storage area it is saved in.
 
65
     * 
 
66
     * @return an array containing the saved list names
 
67
     */
 
68
     String[] getSavedLists() {
 
69
        File externalPath = getSavedListPath(true);
 
70
        File internalPath = getSavedListPath(false);
 
71
        ArrayList<String> lists = new ArrayList<String>();
 
72
 
 
73
        if (externalPath != null && externalPath.isDirectory()) {
 
74
            for (File f: externalPath.listFiles())
 
75
                lists.add("external/" + f.getName());
 
76
        }
 
77
 
 
78
        if (internalPath != null && internalPath.isDirectory()) {
 
79
            for (File f: internalPath.listFiles())
 
80
                lists.add("internal/" + f.getName());
 
81
        }
 
82
 
 
83
        Collections.sort(lists);
 
84
 
 
85
        String[] a = new String[0];
 
86
        return lists.toArray(a);
 
87
    }
 
88
 
 
89
    /** 
 
90
     * Saves the current benchmark list to a file.
 
91
     * 
 
92
     * @param listName the list filename
 
93
     * @param external whether the file is to be stored in external storage
 
94
     */
 
95
    void saveBenchmarkList(String listName, boolean external) throws Exception {
 
96
        File listPath = getSavedListPath(external);
 
97
        if (listPath == null)
 
98
            throw new Exception("External storage not present");
 
99
 
 
100
        listPath.mkdirs();
 
101
 
 
102
        File f = new File(listPath, listName);
 
103
 
 
104
        BufferedWriter out = new BufferedWriter(new FileWriter(f));
 
105
        try {
 
106
            for (int i = 0; i < benchmarks.size() - 1; i++) {
 
107
                out.write(benchmarks.get(i));
 
108
                out.newLine();
 
109
            }
 
110
        }
 
111
        catch (Exception ex) {
 
112
            throw ex;
 
113
        }
 
114
        finally {
 
115
            out.close();
 
116
        }
 
117
    }
 
118
 
 
119
    /** 
 
120
     * Loads a benchmark list from a file.
 
121
     * 
 
122
     * @param listName the list filename
 
123
     * @param external whether the file is stored in external storage
 
124
     */
 
125
    void loadBenchmarkList(String listName, boolean external) throws Exception {
 
126
        /* Get the list file path */
 
127
        File listPath = getSavedListPath(external);
 
128
        if (listPath == null)
 
129
            throw new Exception("External storage not present");
 
130
 
 
131
        File f = new File(listPath, listName);
 
132
 
 
133
        ArrayList<String> newBenchmarks = new ArrayList<String>();
 
134
 
 
135
        /* Read benchmarks from file */
 
136
        BufferedReader reader = new BufferedReader(new FileReader(f));
 
137
        String line = null;
 
138
 
 
139
        while ((line = reader.readLine()) != null)
 
140
            newBenchmarks.add(line);
 
141
 
 
142
        /* If everything went well, replace current benchmarks */
 
143
        benchmarks.clear();
 
144
        benchmarks.addAll(newBenchmarks);
 
145
        benchmarks.add("Add benchmark...");
 
146
    }
 
147
 
 
148
    /** 
 
149
     * Delete a benchmark list file.
 
150
     * 
 
151
     * @param listName the list filename
 
152
     * @param external whether the file is stored in external storage
 
153
     */
 
154
    void deleteBenchmarkList(String listName, boolean external) throws Exception {
 
155
        /* Get the list file path */
 
156
        File listPath = getSavedListPath(external);
 
157
        if (listPath == null)
 
158
            throw new Exception("External storage not present");
 
159
 
 
160
        File f = new File(listPath, listName);
 
161
        f.delete();
 
162
    }
 
163
 
 
164
    /** 
 
165
     * Gets the path where benchmark lists are saved in.
 
166
     * 
 
167
     * @param external whether to get the path for external storage
 
168
     * 
 
169
     * @return the saved list path
 
170
     */
 
171
    private File getSavedListPath(boolean external) {
 
172
        File f = null;
 
173
 
 
174
        if (external) {
 
175
            String state = Environment.getExternalStorageState();
 
176
            if (!Environment.MEDIA_MOUNTED.equals(state))
 
177
                return null;
 
178
            f = activity.getExternalFilesDir(null);
 
179
        }
 
180
        else {
 
181
            f = activity.getFilesDir();
 
182
        }
 
183
 
 
184
        if (f != null)
 
185
            f = new File(f, "lists");
 
186
 
 
187
        return f;
 
188
    }
 
189
}