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"
27 SimpleBenchmark(const std::string &name, size_t width, size_t height,
28 EGLint glesMajorVersion = 2,
29 EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE);
31 virtual ~SimpleBenchmark() { };
33 virtual bool initializeBenchmark() { return true; }
34 virtual void destroyBenchmark() { }
36 virtual void stepBenchmark(float dt, double totalTime) { }
38 virtual void beginDrawBenchmark() { }
39 virtual void drawBenchmark() = 0;
40 virtual void endDrawBenchmark() { }
43 bool popEvent(Event *event);
45 OSWindow *getWindow();
48 unsigned int mDrawIterations;
49 double mRunTimeSeconds;
53 DISALLOW_COPY_AND_ASSIGN(SimpleBenchmark);
58 void step(float dt, double totalTime);
64 std::unique_ptr<EGLWindow> mEGLWindow;
65 std::unique_ptr<OSWindow> mOSWindow;
66 std::unique_ptr<Timer> mTimer;
70 struct BenchmarkParams
72 EGLint requestedRenderer;
74 virtual std::string name() const
76 switch (requestedRenderer)
78 case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE: return "D3D11";
79 case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE: return "D3D9";
80 default: return "Unknown Renderer";
85 template <typename BenchmarkT, typename ParamsT>
86 inline int RunBenchmarks(const std::vector<ParamsT> &benchmarks)
90 for (size_t benchIndex = 0; benchIndex < benchmarks.size(); benchIndex++)
92 BenchmarkT benchmark(benchmarks[benchIndex]);
93 result = benchmark.run();
94 if (result != 0) { return result; }
100 #endif // SAMPLE_UTIL_SIMPLE_BENCHMARK_H