TestScene.h revision 27e58b4f54d693ff1db7ab2edb5d47ca296c1278
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 19#include <string> 20#include <unordered_map> 21 22namespace 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: 38 struct Options { 39 int count = 0; 40 }; 41 42 template <class T> 43 static test::TestScene* simpleCreateScene(const TestScene::Options&) { 44 return new T(); 45 } 46 47 typedef test::TestScene* (*CreateScene)(const TestScene::Options&); 48 49 struct Info { 50 std::string name; 51 std::string description; 52 CreateScene createScene; 53 }; 54 55 class Registrar { 56 public: 57 Registrar(const TestScene::Info& info) { 58 TestScene::registerScene(info); 59 } 60 private: 61 Registrar() = delete; 62 Registrar(const Registrar&) = delete; 63 Registrar& operator=(const Registrar&) = delete; 64 }; 65 66 virtual ~TestScene() {} 67 virtual void createContent(int width, int height, TestCanvas& 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 74} // namespace test 75} // namespace uirenderer 76} // namespace android 77 78#endif /* TESTS_TESTSCENE_H */ 79