1 /*
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 
17 #pragma once
18 
19 #include <gui/Surface.h>
20 #include <utils/StrongPointer.h>
21 
22 #include <string>
23 #include <unordered_map>
24 
25 namespace android {
26 
27 class Canvas;
28 
29 namespace uirenderer {
30 class RenderNode;
31 class RecordingCanvas;
32 
33 namespace test {
34 
35 class TestScene {
36 public:
37     struct Options {
38         int count = 0;
39         int reportFrametimeWeight = 0;
40         bool renderOffscreen = true;
41     };
42 
43     template <class T>
simpleCreateScene(const TestScene::Options &)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:
Registrar(const TestScene::Info & info)58         explicit Registrar(const TestScene::Info& info) { TestScene::registerScene(info); }
59 
60     private:
61         Registrar() = delete;
62         Registrar(const Registrar&) = delete;
63         Registrar& operator=(const Registrar&) = delete;
64     };
65 
~TestScene()66     virtual ~TestScene() {}
67     virtual void createContent(int width, int height, Canvas& renderer) = 0;
68     virtual void doFrame(int frameNr) = 0;
69 
70     static std::unordered_map<std::string, Info>& testMap();
71     static void registerScene(const Info& info);
72 
73     sp<Surface> renderTarget;
74 };
75 
76 }  // namespace test
77 }  // namespace uirenderer
78 }  // namespace android
79