Home | History | Annotate | Download | only in common
      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         int renderAhead = 0;
     42     };
     43 
     44     template <class T>
     45     static test::TestScene* simpleCreateScene(const TestScene::Options&) {
     46         return new T();
     47     }
     48 
     49     typedef test::TestScene* (*CreateScene)(const TestScene::Options&);
     50 
     51     struct Info {
     52         std::string name;
     53         std::string description;
     54         CreateScene createScene;
     55     };
     56 
     57     class Registrar {
     58     public:
     59         explicit Registrar(const TestScene::Info& info) { TestScene::registerScene(info); }
     60 
     61     private:
     62         Registrar() = delete;
     63         Registrar(const Registrar&) = delete;
     64         Registrar& operator=(const Registrar&) = delete;
     65     };
     66 
     67     virtual ~TestScene() {}
     68     virtual void createContent(int width, int height, Canvas& renderer) = 0;
     69     virtual void doFrame(int frameNr) = 0;
     70 
     71     static std::unordered_map<std::string, Info>& testMap();
     72     static void registerScene(const Info& info);
     73 
     74     sp<Surface> renderTarget;
     75 };
     76 
     77 }  // namespace test
     78 }  // namespace uirenderer
     79 }  // namespace android
     80