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 | */ |
| 16 | #ifndef TESTS_TESTSCENE_H |
| 17 | #define TESTS_TESTSCENE_H |
| 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; |
| 25 | |
| 26 | #if HWUI_NEW_OPS |
| 27 | class RecordingCanvas; |
| 28 | typedef RecordingCanvas TestCanvas; |
| 29 | #else |
| 30 | class DisplayListCanvas; |
| 31 | typedef DisplayListCanvas TestCanvas; |
| 32 | #endif |
| 33 | |
| 34 | namespace test { |
| 35 | |
| 36 | class TestScene { |
| 37 | public: |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 38 | struct Options { |
| 39 | int count = 0; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 40 | int reportFrametimeWeight = 0; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 41 | }; |
| 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: |
| 58 | Registrar(const TestScene::Info& info) { |
| 59 | TestScene::registerScene(info); |
| 60 | } |
| 61 | private: |
| 62 | Registrar() = delete; |
| 63 | Registrar(const Registrar&) = delete; |
| 64 | Registrar& operator=(const Registrar&) = delete; |
| 65 | }; |
| 66 | |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 67 | virtual ~TestScene() {} |
| 68 | virtual void createContent(int width, int height, TestCanvas& renderer) = 0; |
| 69 | virtual void doFrame(int frameNr) = 0; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 70 | |
| 71 | static std::unordered_map<std::string, Info>& testMap(); |
| 72 | static void registerScene(const Info& info); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace test |
| 76 | } // namespace uirenderer |
| 77 | } // namespace android |
| 78 | |
| 79 | #endif /* TESTS_TESTSCENE_H */ |