John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 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 | */ |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame^] | 16 | |
| 17 | #pragma once |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 18 | |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <unordered_map> |
| 21 | |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | class RenderNode; |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 25 | class RecordingCanvas; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame^] | 26 | |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 27 | typedef RecordingCanvas TestCanvas; |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 28 | |
| 29 | namespace test { |
| 30 | |
| 31 | class TestScene { |
| 32 | public: |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 33 | struct Options { |
| 34 | int count = 0; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 35 | int reportFrametimeWeight = 0; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 36 | bool renderOffscreen = false; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | template <class T> |
| 40 | static test::TestScene* simpleCreateScene(const TestScene::Options&) { |
| 41 | return new T(); |
| 42 | } |
| 43 | |
| 44 | typedef test::TestScene* (*CreateScene)(const TestScene::Options&); |
| 45 | |
| 46 | struct Info { |
| 47 | std::string name; |
| 48 | std::string description; |
| 49 | CreateScene createScene; |
| 50 | }; |
| 51 | |
| 52 | class Registrar { |
| 53 | public: |
| 54 | Registrar(const TestScene::Info& info) { |
| 55 | TestScene::registerScene(info); |
| 56 | } |
| 57 | private: |
| 58 | Registrar() = delete; |
| 59 | Registrar(const Registrar&) = delete; |
| 60 | Registrar& operator=(const Registrar&) = delete; |
| 61 | }; |
| 62 | |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 63 | virtual ~TestScene() {} |
| 64 | virtual void createContent(int width, int height, TestCanvas& renderer) = 0; |
| 65 | virtual void doFrame(int frameNr) = 0; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 66 | |
| 67 | static std::unordered_map<std::string, Info>& testMap(); |
| 68 | static void registerScene(const Info& info); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace test |
| 72 | } // namespace uirenderer |
| 73 | } // namespace android |