Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27e58b4f authored by Chris Craik's avatar Chris Craik
Browse files

Build hwui test scenes as common test code

And start using them in other non-macrobench tests

Change-Id: If155b531f3c89f97491001c06d1996df527b9f85
parent 1daf35db
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -90,6 +90,9 @@ hwui_src_files := \
    protos/hwui.proto

hwui_test_common_src_files := \
    $(call all-cpp-files-under, tests/common/scenes) \
    tests/common/TestContext.cpp \
    tests/common/TestScene.cpp \
    tests/common/TestUtils.cpp

hwui_cflags := \
@@ -259,12 +262,9 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libhwui_static

LOCAL_SRC_FILES += \
    $(hwui_test_common_src_files) \
    tests/macrobench/TestContext.cpp \
    tests/macrobench/TestSceneRunner.cpp \
    tests/macrobench/main.cpp

LOCAL_SRC_FILES += $(call all-cpp-files-under, tests/common/scenes)

include $(BUILD_EXECUTABLE)

# ------------------------
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

#include "TestContext.h"
#include "tests/common/TestContext.h"

namespace android {
namespace uirenderer {
+10 −35
Original line number Diff line number Diff line
@@ -13,49 +13,24 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef TESTS_BENCHMARK_H
#define TESTS_BENCHMARK_H

#include "tests/common/TestScene.h"

#include <string>
#include <vector>

namespace android {
namespace uirenderer {
namespace test {

struct BenchmarkOptions {
    int count;
};

typedef test::TestScene* (*CreateScene)(const BenchmarkOptions&);

template <class T>
test::TestScene* simpleCreateScene(const BenchmarkOptions&) {
    return new T();
// Not a static global because we need to force the map to be constructed
// before we try to add things to it.
std::unordered_map<std::string, TestScene::Info>& TestScene::testMap() {
    static std::unordered_map<std::string, TestScene::Info> testMap;
    return testMap;
}

struct BenchmarkInfo {
    std::string name;
    std::string description;
    CreateScene createScene;
};

class Benchmark {
public:
    Benchmark(const BenchmarkInfo& info) {
        registerBenchmark(info);
void TestScene::registerScene(const TestScene::Info& info) {
    testMap()[info.name] = info;
}

private:
    Benchmark() = delete;
    Benchmark(const Benchmark&) = delete;
    Benchmark& operator=(const Benchmark&) = delete;

    static void registerBenchmark(const BenchmarkInfo& info);
};

} /* namespace test */
} /* namespace uirenderer */
} /* namespace android */

#endif /* TESTS_BENCHMARK_H */
+34 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@
#ifndef TESTS_TESTSCENE_H
#define TESTS_TESTSCENE_H

#include <string>
#include <unordered_map>

namespace android {
namespace uirenderer {
class RenderNode;
@@ -32,9 +35,40 @@ namespace test {

class TestScene {
public:
    struct Options {
        int count = 0;
    };

    template <class T>
    static test::TestScene* simpleCreateScene(const TestScene::Options&) {
        return new T();
    }

    typedef test::TestScene* (*CreateScene)(const TestScene::Options&);

    struct Info {
        std::string name;
        std::string description;
        CreateScene createScene;
    };

    class Registrar {
    public:
        Registrar(const TestScene::Info& info) {
            TestScene::registerScene(info);
        }
    private:
        Registrar() = delete;
        Registrar(const Registrar&) = delete;
        Registrar& operator=(const Registrar&) = delete;
    };

    virtual ~TestScene() {}
    virtual void createContent(int width, int height, TestCanvas& renderer) = 0;
    virtual void doFrame(int frameNr) = 0;

    static std::unordered_map<std::string, Info>& testMap();
    static void registerScene(const Info& info);
};

} // namespace test
Loading