test-hwc2: set layer z order
Test: Add "#define HAVE_NO_SURFACE_FLINGER" to
frameworks/native/libs/gui/BufferQueueCore.cpp.
Recompile and flash.
Run "mm" in frameworks/native/services/surfaceflinger/tests/hwc2.
Push test-hwc2 to device.
Run "adb root && adb shell stop".
Run test case. Ex: "./test-hwc2"
Change-Id: I2c51df36d62f9d809583003b81c24dbd7a744301
diff --git a/services/surfaceflinger/tests/hwc2/Android.mk b/services/surfaceflinger/tests/hwc2/Android.mk
index 66a390d..08103fc 100644
--- a/services/surfaceflinger/tests/hwc2/Android.mk
+++ b/services/surfaceflinger/tests/hwc2/Android.mk
@@ -30,6 +30,7 @@
LOCAL_SRC_FILES := \
Hwc2Test.cpp \
Hwc2TestProperties.cpp \
- Hwc2TestLayer.cpp
+ Hwc2TestLayer.cpp \
+ Hwc2TestLayers.cpp
include $(BUILD_NATIVE_TEST)
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
index dbce9d5..041f5d7 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
+++ b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
@@ -27,6 +27,7 @@
#undef HWC2_USE_CPP11
#include "Hwc2TestLayer.h"
+#include "Hwc2TestLayers.h"
void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData,
hwc2_display_t display, int32_t connected);
@@ -424,6 +425,23 @@
}
}
+ void setLayerZOrder(hwc2_display_t display, hwc2_layer_t layer,
+ uint32_t zOrder, hwc2_error_t* outErr = nullptr)
+ {
+ auto pfn = reinterpret_cast<HWC2_PFN_SET_LAYER_Z_ORDER>(
+ getFunction(HWC2_FUNCTION_SET_LAYER_Z_ORDER));
+ ASSERT_TRUE(pfn) << "failed to get function";
+
+ auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer,
+ zOrder));
+ if (outErr) {
+ *outErr = err;
+ } else {
+ ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set layer z order "
+ << zOrder;
+ }
+ }
+
protected:
hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor)
{
@@ -567,6 +585,12 @@
hwc2_display_t display, hwc2_layer_t layer,
const Hwc2TestLayer& testLayer, hwc2_error_t* outErr);
+ /* Calls a set property function from Hwc2Test to set property values from
+ * Hwc2TestLayers to hwc2_layer_t on hwc2_display_t */
+ using TestLayerPropertiesFunction = void (*)(Hwc2Test* test,
+ hwc2_display_t display, hwc2_layer_t layer,
+ const Hwc2TestLayers& testLayers);
+
/* Calls a set property function from Hwc2Test to set a bad property value
* on hwc2_layer_t on hwc2_display_t */
using TestLayerPropertyBadLayerFunction = void (*)(Hwc2Test* test,
@@ -639,6 +663,36 @@
}
}
+ /* For each active display it cycles through each display config and tests
+ * each property value. It creates multiple layers, calls the
+ * TestLayerPropertiesFunction to set property values and then
+ * destroys the layers */
+ void setLayerProperties(Hwc2TestCoverage coverage, size_t layerCnt,
+ TestLayerPropertiesFunction function)
+ {
+ for (auto display : mDisplays) {
+ std::vector<hwc2_config_t> configs;
+
+ ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs));
+
+ for (auto config : configs) {
+ std::vector<hwc2_layer_t> layers;
+
+ ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config));
+
+ ASSERT_NO_FATAL_FAILURE(createLayers(display, &layers, layerCnt));
+ Hwc2TestLayers testLayers(layers, coverage);
+
+ for (auto layer : layers) {
+ EXPECT_NO_FATAL_FAILURE(function(this, display, layer,
+ testLayers));
+ }
+
+ ASSERT_NO_FATAL_FAILURE(destroyLayers(display, std::move(layers)));
+ }
+ }
+ }
+
/* For each active display it cycles through each display config.
* 1) It attempts to set a valid property value to bad layer handle.
* 2) It creates a layer x and attempts to set a valid property value to
@@ -801,6 +855,13 @@
testLayer.getTransform(), outErr));
}
+void setZOrder(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
+ const Hwc2TestLayer& testLayer, hwc2_error_t* outErr)
+{
+ EXPECT_NO_FATAL_FAILURE(test->setLayerZOrder(display, layer,
+ testLayer.getZOrder(), outErr));
+}
+
bool advanceBlendMode(Hwc2TestLayer* testLayer)
{
return testLayer->advanceBlendMode();
@@ -1776,3 +1837,52 @@
ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default,
setTransform));
}
+
+/* TESTCASE: Tests that the HWC2 can set the z order of a layer. */
+TEST_F(Hwc2Test, SET_LAYER_Z_ORDER)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerProperties(Hwc2TestCoverage::Complete, 10,
+ [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
+ const Hwc2TestLayers& testLayers) {
+
+ EXPECT_NO_FATAL_FAILURE(test->setLayerZOrder(display, layer,
+ testLayers.getZOrder(layer)));
+ }
+ ));
+}
+
+/* TESTCASE: Tests that the HWC2 can update the z order of a layer. */
+TEST_F(Hwc2Test, SET_LAYER_Z_ORDER_update)
+{
+ const std::vector<uint32_t> zOrders = { static_cast<uint32_t>(0),
+ static_cast<uint32_t>(1), static_cast<uint32_t>(UINT32_MAX / 4),
+ static_cast<uint32_t>(UINT32_MAX / 2),
+ static_cast<uint32_t>(UINT32_MAX) };
+
+ for (auto display : mDisplays) {
+ std::vector<hwc2_config_t> configs;
+
+ ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs));
+
+ for (auto config : configs) {
+ hwc2_layer_t layer;
+
+ ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config));
+
+ ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer));
+
+ for (uint32_t zOrder : zOrders) {
+ EXPECT_NO_FATAL_FAILURE(setLayerZOrder(display, layer, zOrder));
+ }
+
+ ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer));
+ }
+ }
+}
+
+/* TESTCASE: Tests that the HWC2 cannot set the z order of a bad layer. */
+TEST_F(Hwc2Test, SET_LAYER_Z_ORDER_bad_layer)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default,
+ setZOrder));
+}
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
index 5445a77..b9ca9c3 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
@@ -18,12 +18,13 @@
#include "Hwc2TestLayer.h"
-Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage)
+Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage, uint32_t zOrder)
: mBlendMode(coverage),
mComposition(coverage),
mDataspace(coverage),
mPlaneAlpha(coverage),
- mTransform(coverage) { }
+ mTransform(coverage),
+ mZOrder(zOrder) { }
std::string Hwc2TestLayer::dump() const
{
@@ -35,6 +36,8 @@
dmp << property->dump();
}
+ dmp << "\tz order: " << mZOrder << "\n";
+
return dmp.str();
}
@@ -70,6 +73,11 @@
return mTransform.get();
}
+uint32_t Hwc2TestLayer::getZOrder() const
+{
+ return mZOrder;
+}
+
bool Hwc2TestLayer::advanceBlendMode()
{
return mBlendMode.advance();
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
index d259ad9..855f7bb 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
@@ -27,7 +27,7 @@
class Hwc2TestLayer {
public:
- Hwc2TestLayer(Hwc2TestCoverage coverage);
+ Hwc2TestLayer(Hwc2TestCoverage coverage, uint32_t zOrder = 0);
std::string dump() const;
@@ -38,6 +38,7 @@
android_dataspace_t getDataspace() const;
float getPlaneAlpha() const;
hwc_transform_t getTransform() const;
+ uint32_t getZOrder() const;
bool advanceBlendMode();
bool advanceComposition();
@@ -55,6 +56,8 @@
Hwc2TestDataspace mDataspace;
Hwc2TestPlaneAlpha mPlaneAlpha;
Hwc2TestTransform mTransform;
+
+ uint32_t mZOrder;
};
#endif /* ifndef _HWC2_TEST_LAYER_H */
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.cpp b/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.cpp
new file mode 100644
index 0000000..b2318b1
--- /dev/null
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.cpp
@@ -0,0 +1,55 @@
+/* * Copyright (C) 2016 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 <sstream>
+#include <gtest/gtest.h>
+
+#include "Hwc2TestLayers.h"
+
+Hwc2TestLayers::Hwc2TestLayers(const std::vector<hwc2_layer_t>& layers,
+ Hwc2TestCoverage coverage)
+{
+ uint32_t nextZOrder = 0;
+
+ for (auto layer : layers) {
+ mTestLayers.emplace(std::piecewise_construct,
+ std::forward_as_tuple(layer),
+ std::forward_as_tuple(coverage, nextZOrder++));
+ }
+}
+
+std::string Hwc2TestLayers::dump() const
+{
+ std::stringstream dmp;
+ for (auto& testLayer : mTestLayers) {
+ dmp << testLayer.second.dump();
+ }
+ return dmp.str();
+}
+
+void Hwc2TestLayers::reset()
+{
+ for (auto& testLayer : mTestLayers) {
+ testLayer.second.reset();
+ }
+}
+
+uint32_t Hwc2TestLayers::getZOrder(hwc2_layer_t layer) const
+{
+ if (mTestLayers.count(layer) == 0) {
+ []() { GTEST_FAIL(); }();
+ }
+ return mTestLayers.at(layer).getZOrder();
+}
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.h b/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.h
new file mode 100644
index 0000000..fcc903a
--- /dev/null
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayers.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2016 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 _HWC2_TEST_LAYERS_H
+#define _HWC2_TEST_LAYERS_H
+
+#include <map>
+
+#define HWC2_INCLUDE_STRINGIFICATION
+#define HWC2_USE_CPP11
+#include <hardware/hwcomposer2.h>
+#undef HWC2_INCLUDE_STRINGIFICATION
+#undef HWC2_USE_CPP11
+
+#include "Hwc2TestProperties.h"
+#include "Hwc2TestLayer.h"
+
+class Hwc2TestLayers {
+public:
+ Hwc2TestLayers(const std::vector<hwc2_layer_t>& layers,
+ Hwc2TestCoverage coverage);
+
+ std::string dump() const;
+
+ void reset();
+
+ uint32_t getZOrder(hwc2_layer_t layer) const;
+
+private:
+ std::map<hwc2_layer_t, Hwc2TestLayer> mTestLayers;
+};
+
+#endif /* ifndef _HWC2_TEST_LAYERS_H */