Build hwui test scenes as common test code
And start using them in other non-macrobench tests
Change-Id: If155b531f3c89f97491001c06d1996df527b9f85
diff --git a/libs/hwui/tests/macrobench/Benchmark.h b/libs/hwui/tests/macrobench/Benchmark.h
deleted file mode 100644
index aad8eb3..0000000
--- a/libs/hwui/tests/macrobench/Benchmark.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * 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 {
-
-struct BenchmarkOptions {
- int count;
-};
-
-typedef test::TestScene* (*CreateScene)(const BenchmarkOptions&);
-
-template <class T>
-test::TestScene* simpleCreateScene(const BenchmarkOptions&) {
- return new T();
-}
-
-struct BenchmarkInfo {
- std::string name;
- std::string description;
- CreateScene createScene;
-};
-
-class Benchmark {
-public:
- Benchmark(const BenchmarkInfo& info) {
- registerBenchmark(info);
- }
-
-private:
- Benchmark() = delete;
- Benchmark(const Benchmark&) = delete;
- Benchmark& operator=(const Benchmark&) = delete;
-
- static void registerBenchmark(const BenchmarkInfo& info);
-};
-
-} /* namespace uirenderer */
-} /* namespace android */
-
-#endif /* TESTS_BENCHMARK_H */
diff --git a/libs/hwui/tests/macrobench/TestContext.cpp b/libs/hwui/tests/macrobench/TestContext.cpp
deleted file mode 100644
index ba763a8..0000000
--- a/libs/hwui/tests/macrobench/TestContext.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "TestContext.h"
-
-namespace android {
-namespace uirenderer {
-namespace test {
-
-static const int IDENT_DISPLAYEVENT = 1;
-
-static android::DisplayInfo DUMMY_DISPLAY {
- 1080, //w
- 1920, //h
- 320.0, // xdpi
- 320.0, // ydpi
- 60.0, // fps
- 2.0, // density
- 0, // orientation
- false, // secure?
- 0, // appVsyncOffset
- 0, // presentationDeadline
- 0, // colorTransform
-};
-
-DisplayInfo getBuiltInDisplay() {
-#if !HWUI_NULL_GPU
- DisplayInfo display;
- sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
- ISurfaceComposer::eDisplayIdMain));
- status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display);
- LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
- return display;
-#else
- return DUMMY_DISPLAY;
-#endif
-}
-
-// Initialize to a dummy default
-android::DisplayInfo gDisplay = DUMMY_DISPLAY;
-
-TestContext::TestContext() {
- mLooper = new Looper(true);
- mSurfaceComposerClient = new SurfaceComposerClient();
- mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT,
- Looper::EVENT_INPUT, nullptr, nullptr);
-}
-
-TestContext::~TestContext() {}
-
-sp<Surface> TestContext::surface() {
- if (!mSurfaceControl.get()) {
- mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"),
- gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888);
-
- SurfaceComposerClient::openGlobalTransaction();
- mSurfaceControl->setLayer(0x7FFFFFF);
- mSurfaceControl->show();
- SurfaceComposerClient::closeGlobalTransaction();
- }
-
- return mSurfaceControl->getSurface();
-}
-
-void TestContext::waitForVsync() {
-#if !HWUI_NULL_GPU
- // Request vsync
- mDisplayEventReceiver.requestNextVsync();
-
- // Wait
- mLooper->pollOnce(-1);
-
- // Drain it
- DisplayEventReceiver::Event buf[100];
- while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { }
-#endif
-}
-
-} // namespace test
-} // namespace uirenderer
-} // namespace android
diff --git a/libs/hwui/tests/macrobench/TestContext.h b/libs/hwui/tests/macrobench/TestContext.h
deleted file mode 100644
index 2bbe5df..0000000
--- a/libs/hwui/tests/macrobench/TestContext.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TESTCONTEXT_H
-#define TESTCONTEXT_H
-
-#include <gui/DisplayEventReceiver.h>
-#include <gui/ISurfaceComposer.h>
-#include <gui/SurfaceComposerClient.h>
-#include <gui/SurfaceControl.h>
-#include <gui/Surface.h>
-#include <ui/DisplayInfo.h>
-#include <utils/Looper.h>
-
-namespace android {
-namespace uirenderer {
-namespace test {
-
-extern DisplayInfo gDisplay;
-#define dp(x) ((x) * android::uirenderer::test::gDisplay.density)
-
-DisplayInfo getBuiltInDisplay();
-
-class TestContext {
-public:
- TestContext();
- ~TestContext();
-
- sp<Surface> surface();
-
- void waitForVsync();
-
-private:
- sp<SurfaceComposerClient> mSurfaceComposerClient;
- sp<SurfaceControl> mSurfaceControl;
- DisplayEventReceiver mDisplayEventReceiver;
- sp<Looper> mLooper;
-};
-
-} // namespace test
-} // namespace uirenderer
-} // namespace android
-
-#endif
diff --git a/libs/hwui/tests/macrobench/TestSceneRunner.cpp b/libs/hwui/tests/macrobench/TestSceneRunner.cpp
index 1e1c6a1..8261220 100644
--- a/libs/hwui/tests/macrobench/TestSceneRunner.cpp
+++ b/libs/hwui/tests/macrobench/TestSceneRunner.cpp
@@ -15,9 +15,9 @@
*/
#include "AnimationContext.h"
-#include "Benchmark.h"
#include "RenderNode.h"
-#include "TestContext.h"
+#include "tests/common/TestContext.h"
+#include "tests/common/TestScene.h"
#include "tests/common/scenes/TestSceneBase.h"
#include "renderthread/RenderProxy.h"
#include "renderthread/RenderTask.h"
@@ -38,7 +38,7 @@
}
};
-void run(const BenchmarkInfo& info, const BenchmarkOptions& opts) {
+void run(const TestScene::Info& info, const TestScene::Options& opts) {
// Switch to the real display
gDisplay = getBuiltInDisplay();
diff --git a/libs/hwui/tests/macrobench/main.cpp b/libs/hwui/tests/macrobench/main.cpp
index 48566e8..619713c 100644
--- a/libs/hwui/tests/macrobench/main.cpp
+++ b/libs/hwui/tests/macrobench/main.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "Benchmark.h"
+#include "tests/common/TestScene.h"
#include "protos/hwui.pb.h"
@@ -27,23 +27,13 @@
using namespace android;
using namespace android::uirenderer;
-
-// 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, BenchmarkInfo>& testMap() {
- static std::unordered_map<std::string, BenchmarkInfo> testMap;
- return testMap;
-}
-
-void Benchmark::registerBenchmark(const BenchmarkInfo& info) {
- testMap()[info.name] = info;
-}
+using namespace android::uirenderer::test;
static int gFrameCount = 150;
static int gRepeatCount = 1;
-static std::vector<BenchmarkInfo> gRunTests;
+static std::vector<TestScene::Info> gRunTests;
-void run(const BenchmarkInfo& info, const BenchmarkOptions& opts);
+void run(const TestScene::Info& info, const TestScene::Options& opts);
static void printHelp() {
printf("\
@@ -59,7 +49,7 @@
static void listTests() {
printf("Tests: \n");
- for (auto&& test : testMap()) {
+ for (auto&& test : TestScene::testMap()) {
auto&& info = test.second;
const char* col1 = info.name.c_str();
int dlen = info.description.length();
@@ -168,8 +158,8 @@
if (optind < argc) {
do {
const char* test = argv[optind++];
- auto pos = testMap().find(test);
- if (pos == testMap().end()) {
+ auto pos = TestScene::testMap().find(test);
+ if (pos == TestScene::testMap().end()) {
fprintf(stderr, "Unknown test '%s'\n", test);
exit(EXIT_FAILURE);
} else {
@@ -177,14 +167,14 @@
}
} while (optind < argc);
} else {
- gRunTests.push_back(testMap()["shadowgrid"]);
+ gRunTests.push_back(TestScene::testMap()["shadowgrid"]);
}
}
int main(int argc, char* argv[]) {
parseOptions(argc, argv);
- BenchmarkOptions opts;
+ TestScene::Options opts;
opts.count = gFrameCount;
for (int i = 0; i < gRepeatCount; i++) {
for (auto&& test : gRunTests) {