Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / perf_tests / SimpleBenchmark.h
1 //
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.
5 //
6
7 #ifndef SAMPLE_UTIL_SIMPLE_BENCHMARK_H
8 #define SAMPLE_UTIL_SIMPLE_BENCHMARK_H
9
10 #include <memory>
11 #include <vector>
12 #include <EGL/egl.h>
13 #include <EGL/eglext.h>
14 #include <string>
15
16 #include "shared_utils.h"
17
18 #include "OSWindow.h"
19 #include "EGLWindow.h"
20 #include "Timer.h"
21
22 class Event;
23
24 // Base class
25 struct BenchmarkParams
26 {
27     EGLint requestedRenderer;
28
29     virtual std::string suffix() const;
30 };
31
32 class SimpleBenchmark
33 {
34   public:
35     SimpleBenchmark(const std::string &name, size_t width, size_t height,
36                     EGLint glesMajorVersion, const BenchmarkParams &params);
37
38     virtual ~SimpleBenchmark() { };
39
40     virtual bool initializeBenchmark() { return true; }
41     virtual void destroyBenchmark() { }
42
43     virtual void stepBenchmark(float dt, double totalTime) { }
44
45     virtual void beginDrawBenchmark() { }
46     virtual void drawBenchmark() = 0;
47     virtual void endDrawBenchmark() { }
48
49     int run();
50     bool popEvent(Event *event);
51
52     OSWindow *getWindow();
53
54   protected:
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;
57
58     unsigned int mDrawIterations;
59     double mRunTimeSeconds;
60     int mNumFrames;
61
62   private:
63     DISALLOW_COPY_AND_ASSIGN(SimpleBenchmark);
64
65     bool initialize();
66     void destroy();
67
68     void step(float dt, double totalTime);
69     void draw();
70
71     std::string mName;
72     bool mRunning;
73     std::string mSuffix;
74
75     std::unique_ptr<EGLWindow> mEGLWindow;
76     std::unique_ptr<OSWindow> mOSWindow;
77     std::unique_ptr<Timer> mTimer;
78 };
79
80 template <typename BenchmarkT, typename ParamsT>
81 inline int RunBenchmarks(const std::vector<ParamsT> &benchmarks)
82 {
83     int result;
84
85     for (size_t benchIndex = 0; benchIndex < benchmarks.size(); benchIndex++)
86     {
87         BenchmarkT benchmark(benchmarks[benchIndex]);
88         result = benchmark.run();
89         if (result != 0) { return result; }
90     }
91
92     return 0;
93 }
94
95 #endif // SAMPLE_UTIL_SIMPLE_BENCHMARK_H