blob: 060984ea9f3206e1ce27aba83c336956af800e86 [file] [log] [blame]
John Reck16c9d6a2015-11-17 15:51:08 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef TESTS_TESTSCENE_H
17#define TESTS_TESTSCENE_H
18
Chris Craik27e58b42015-12-07 10:01:38 -080019#include <string>
20#include <unordered_map>
21
John Reck16c9d6a2015-11-17 15:51:08 -080022namespace android {
23namespace uirenderer {
24class RenderNode;
25
26#if HWUI_NEW_OPS
27class RecordingCanvas;
28typedef RecordingCanvas TestCanvas;
29#else
30class DisplayListCanvas;
31typedef DisplayListCanvas TestCanvas;
32#endif
33
34namespace test {
35
36class TestScene {
37public:
Chris Craik27e58b42015-12-07 10:01:38 -080038 struct Options {
39 int count = 0;
John Reck682573c2015-10-30 10:37:35 -070040 int reportFrametimeWeight = 0;
Chris Craik27e58b42015-12-07 10:01:38 -080041 };
42
43 template <class T>
44 static test::TestScene* simpleCreateScene(const TestScene::Options&) {
45 return new T();
46 }
47
48 typedef test::TestScene* (*CreateScene)(const TestScene::Options&);
49
50 struct Info {
51 std::string name;
52 std::string description;
53 CreateScene createScene;
54 };
55
56 class Registrar {
57 public:
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -070058 explicit Registrar(const TestScene::Info& info) {
Chris Craik27e58b42015-12-07 10:01:38 -080059 TestScene::registerScene(info);
60 }
61 private:
62 Registrar() = delete;
63 Registrar(const Registrar&) = delete;
64 Registrar& operator=(const Registrar&) = delete;
65 };
66
John Reck16c9d6a2015-11-17 15:51:08 -080067 virtual ~TestScene() {}
68 virtual void createContent(int width, int height, TestCanvas& renderer) = 0;
69 virtual void doFrame(int frameNr) = 0;
Chris Craik27e58b42015-12-07 10:01:38 -080070
71 static std::unordered_map<std::string, Info>& testMap();
72 static void registerScene(const Info& info);
John Reck16c9d6a2015-11-17 15:51:08 -080073};
74
75} // namespace test
76} // namespace uirenderer
77} // namespace android
78
79#endif /* TESTS_TESTSCENE_H */