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 #include <fstream> 23 #include "benchmark-collection.h" 24 #include "default-benchmarks.h" 25 #include "options.h" 26 #include "log.h" 27 #include "util.h" 28 ~BenchmarkCollection()29BenchmarkCollection::~BenchmarkCollection() 30 { 31 Util::dispose_pointer_vector(benchmarks_); 32 } 33 34 void add(const std::vector<std::string> & benchmarks)35BenchmarkCollection::add(const std::vector<std::string> &benchmarks) 36 { 37 for (std::vector<std::string>::const_iterator iter = benchmarks.begin(); 38 iter != benchmarks.end(); 39 iter++) 40 { 41 benchmarks_.push_back(new Benchmark(*iter)); 42 } 43 } 44 45 void populate_from_options()46BenchmarkCollection::populate_from_options() 47 { 48 if (Options::annotate) { 49 std::vector<std::string> annotate; 50 annotate.push_back(":show-fps=true:title=#info#"); 51 add(annotate); 52 } 53 54 if (!Options::benchmarks.empty()) 55 add(Options::benchmarks); 56 57 if (!Options::benchmark_files.empty()) 58 add_benchmarks_from_files(); 59 60 if (!benchmarks_contain_normal_scenes()) 61 add(DefaultBenchmarks::get()); 62 } 63 64 bool needs_decoration()65BenchmarkCollection::needs_decoration() 66 { 67 for (std::vector<Benchmark *>::const_iterator bench_iter = benchmarks_.begin(); 68 bench_iter != benchmarks_.end(); 69 bench_iter++) 70 { 71 const Benchmark *bench = *bench_iter; 72 if (bench->needs_decoration()) 73 return true; 74 } 75 76 return false; 77 } 78 79 80 void add_benchmarks_from_files()81BenchmarkCollection::add_benchmarks_from_files() 82 { 83 for (std::vector<std::string>::const_iterator iter = Options::benchmark_files.begin(); 84 iter != Options::benchmark_files.end(); 85 iter++) 86 { 87 std::ifstream ifs(iter->c_str()); 88 89 if (!ifs.fail()) { 90 std::string line; 91 92 while (getline(ifs, line)) { 93 if (!line.empty()) 94 benchmarks_.push_back(new Benchmark(line)); 95 } 96 } 97 else { 98 Log::error("Cannot open benchmark file %s\n", 99 iter->c_str()); 100 } 101 102 } 103 } 104 105 bool benchmarks_contain_normal_scenes()106BenchmarkCollection::benchmarks_contain_normal_scenes() 107 { 108 for (std::vector<Benchmark *>::const_iterator bench_iter = benchmarks_.begin(); 109 bench_iter != benchmarks_.end(); 110 bench_iter++) 111 { 112 const Benchmark *bench = *bench_iter; 113 if (!bench->scene().name().empty()) 114 return true; 115 } 116 117 return false; 118 } 119 120