2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #ifndef SAMPLE_UTIL_SIMPLE_BENCHMARK_H
8 #define SAMPLE_UTIL_SIMPLE_BENCHMARK_H
13 #include <EGL/eglext.h>
16 #include "shared_utils.h"
19 #include "EGLWindow.h"
25 struct BenchmarkParams
27 EGLint requestedRenderer;
29 virtual std::string suffix() const;
35 SimpleBenchmark(const std::string &name, size_t width, size_t height,
36 EGLint glesMajorVersion, const BenchmarkParams ¶ms);
38 virtual ~SimpleBenchmark() { };
40 virtual bool initializeBenchmark() { return true; }
41 virtual void destroyBenchmark() { }
43 virtual void stepBenchmark(float dt, double totalTime) { }
45 virtual void beginDrawBenchmark() { }
46 virtual void drawBenchmark() = 0;
47 virtual void endDrawBenchmark() { }
50 bool popEvent(Event *event);
52 OSWindow *getWindow();
55 void printResult(const std::string &trace, double value, const std::string &units, bool important) const;
56 void printResult(const std::string &trace, size_t value, const std::string &units, bool important) const;
58 unsigned int mDrawIterations;
59 double mRunTimeSeconds;
63 DISALLOW_COPY_AND_ASSIGN(SimpleBenchmark);
68 void step(float dt, double totalTime);
75 std::unique_ptr<EGLWindow> mEGLWindow;
76 std::unique_ptr<OSWindow> mOSWindow;
77 std::unique_ptr<Timer> mTimer;
80 template <typename BenchmarkT, typename ParamsT>
81 inline int RunBenchmarks(const std::vector<ParamsT> &benchmarks)
85 for (size_t benchIndex = 0; benchIndex < benchmarks.size(); benchIndex++)
87 BenchmarkT benchmark(benchmarks[benchIndex]);
88 result = benchmark.run();
89 if (result != 0) { return result; }
95 #endif // SAMPLE_UTIL_SIMPLE_BENCHMARK_H