From 16f8832fa63eae804c0ee031eefed6a507658b3c Mon Sep 17 00:00:00 2001 From: Xiaosong Wei Date: Wed, 22 Nov 2017 16:28:32 +0800 Subject: [PATCH] Add hwcservice_test A native test app to verify HwcService remotely. Jira: GSE-489 Test: Build passed on Android and works as expected Signed-off-by: Xiaosong Wei --- Android.mk | 2 +- .../libhwcservice/{utils => test}/Android.mk | 9 +- os/android/libhwcservice/test/hwcservice_test.cpp | 116 +++++++++++++++++++++ os/android/libhwcservice/utils/mode.cpp | 109 ------------------- 4 files changed, 124 insertions(+), 112 deletions(-) rename os/android/libhwcservice/{utils => test}/Android.mk (77%) create mode 100644 os/android/libhwcservice/test/hwcservice_test.cpp delete mode 100644 os/android/libhwcservice/utils/mode.cpp diff --git a/Android.mk b/Android.mk index ce9c616..b49afbd 100644 --- a/Android.mk +++ b/Android.mk @@ -37,7 +37,7 @@ ifeq ($(strip $(TARGET_USES_HWC2)), true) # libhwcservice HWC_BUILD_DIRS := \ $(HWC_PATH)/os/android/libhwcservice/Android.mk \ -$(HWC_PATH)/os/android/libhwcservice/utils/Android.mk \ +$(HWC_PATH)/os/android/libhwcservice/test/Android.mk \ # Include tests only if eng build ifneq (,$(filter eng,$(TARGET_BUILD_VARIANT))) diff --git a/os/android/libhwcservice/utils/Android.mk b/os/android/libhwcservice/test/Android.mk similarity index 77% rename from os/android/libhwcservice/utils/Android.mk rename to os/android/libhwcservice/test/Android.mk index 5d8dc8c..b0ef651 100644 --- a/os/android/libhwcservice/utils/Android.mk +++ b/os/android/libhwcservice/test/Android.mk @@ -14,10 +14,15 @@ LOCAL_PATH := $(call my-dir) +ANDROID_VERSION := $(word 1, $(subst ., , $(PLATFORM_VERSION))) + include $(CLEAR_VARS) -LOCAL_MODULE:= hwcmode +LOCAL_MODULE:= hwcservice_test LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ -LOCAL_SRC_FILES:= mode.cpp +LOCAL_SRC_FILES:= hwcservice_test.cpp LOCAL_SHARED_LIBRARIES := libutils libbinder liblog libhwcservice LOCAL_PROPRIETARY_MODULE := true +ifeq ($(shell test $(ANDROID_VERSION) -ge 8; echo $$?), 0) +LOCAL_CFLAGS += -DUSE_PROCESS_STATE +endif include $(BUILD_EXECUTABLE) diff --git a/os/android/libhwcservice/test/hwcservice_test.cpp b/os/android/libhwcservice/test/hwcservice_test.cpp new file mode 100644 index 0000000..e37e804 --- /dev/null +++ b/os/android/libhwcservice/test/hwcservice_test.cpp @@ -0,0 +1,116 @@ +/* +// Copyright (c) 2017 Intel Corporation +// +// 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 +#include +#include +#include +#include +#include "hwcserviceapi.h" +#include "iservice.h" + +using namespace android; +using namespace hwcomposer; + +static void usage() { + aout << "Usage: hwcservice_test \n" + "\t-g: Get current display mode\n" + "\t-s: Set display mode\n" + "\t-p: Print all available display modes\n" + "\t-u: Set Hue\n"; + exit(-1); +} + +int main(int argc, char** argv) { + uint32_t display = 0; + uint32_t display_mode_index = 0; + bool print_mode = false; + bool get_mode = false; + bool set_mode = false; + bool set_hue = false; + int ch; + while ((ch = getopt(argc, argv, "gsphu")) != -1) { + switch (ch) { + case 'g': + get_mode = true; + break; + case 's': + set_mode = true; + break; + case 'p': + print_mode = true; + break; + case 'u': + set_hue = true; + break; + case 'h': + default: + usage(); + } + } + argc -= optind; + argv += optind; + +#ifdef USE_PROCESS_STATE + // Initialize ProcessState with /dev/vndbinder as HwcService is + // in the vndbinder context + android::ProcessState::initWithDriver("/dev/vndbinder"); +#endif + + // Connect to HWC service + HWCSHANDLE hwcs = HwcService_Connect(); + if (hwcs == NULL) { + aout << "Could not connect to service\n"; + return -1; + } + + std::vector modes; + HwcService_DisplayMode_GetAvailableModes(hwcs, display, modes); + if (print_mode) { + aout << "Mode Width x Height\tRefreshRate\tXDpi\tYDpi\n"; + for (uint32_t i = 0; i < modes.size(); i++) { + aout << i << "\t" << modes[i].width << "\t" << modes[i].height << "\t" + << modes[i].refresh << "\t" << modes[i].xdpi << "\t" << modes[i].ydpi + << endl; + } + } + + if (get_mode) { + HwcsDisplayModeInfo mode; + HwcService_DisplayMode_GetMode(hwcs, display, &mode); + aout << "Width x Height\tRefreshRate\tXDpi\tYDpi\n"; + aout << mode.width << "\t" << mode.height << "\t" << mode.refresh << "\t" + << mode.xdpi << "\t" << mode.ydpi << endl; + } + + if (set_mode) { + status_t ret = + HwcService_DisplayMode_SetMode(hwcs, display, display_mode_index); + if (ret != OK) { + aout << "Mode set failed\n"; + HwcService_Disconnect(hwcs); + return 1; + } + } + + if (set_hue) { + HwcService_Display_SetColorParam(hwcs, display, HWCS_COLOR_HUE, + atoi(argv[0])); + } + + HwcService_Disconnect(hwcs); + return 0; +} diff --git a/os/android/libhwcservice/utils/mode.cpp b/os/android/libhwcservice/utils/mode.cpp deleted file mode 100644 index 92688b7..0000000 --- a/os/android/libhwcservice/utils/mode.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -// Copyright (c) 2017 Intel Corporation -// -// 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 -#include -#include -#include -#include -#include "hwcserviceapi.h" -#include "iservice.h" - -using namespace android; -using namespace hwcomposer; - -int main(int argc, char** argv) { - // Argument parameters - uint32_t display = 0; - uint32_t displayModeIndex = 0; - bool printModes = false; - bool bPreferred = false; - bool getMode = false; - bool setMode = false; - int argIndex = 1; - int nonOptions = 0; - - // Process options - while (argIndex < argc) { - // Process any non options - switch (nonOptions) { - case 0: - display = atoi(argv[argIndex]); - break; - case 1: - if (strcmp(argv[argIndex], "get") == 0) { - getMode = true; - } else if (strcmp(argv[argIndex], "set") == 0) { - setMode = true; - displayModeIndex = atoi(argv[argIndex++]); - } else if (strcmp(argv[argIndex], "print") == 0) - printModes = true; - break; - } - nonOptions++; - argIndex++; - } - - if (nonOptions == 0) { - printf("Usage: %s [displayId >]\n", - argv[0]); - return 1; - } -#ifdef USE_PROCESS_STATE - android::ProcessState::initWithDriver("/dev/vndbinder"); -#endif - // Find and connect to HWC service - sp hwcService = interface_cast( - defaultServiceManager()->getService(String16(IA_HWC_SERVICE_NAME))); - if (hwcService == NULL) { - printf("Could not connect to service %s\n", IA_HWC_SERVICE_NAME); - return -1; - } - - // Connect to HWC service - HWCSHANDLE hwcs = HwcService_Connect(); - if (hwcs == NULL) { - printf("Could not connect to service\n"); - return -1; - } - - std::vector modes; - HwcService_DisplayMode_GetAvailableModes(hwcs, display, modes); - if (printModes) { - for (uint32_t i = 0; i < modes.size(); i++) { - printf("\nMode WidthxHeight\tRefreshRate\tXDpi\tYDpi\n"); - printf("%-6d %-4d %-6d\t%d\t%d\t%d\t\n", i, modes[i].width, - modes[i].height, modes[i].refresh, modes[i].xdpi, modes[i].ydpi); - } - } - if (getMode) { - HwcsDisplayModeInfo mode; - HwcService_DisplayMode_GetMode(hwcs, display, &mode); - printf("%-4d %-6d\t%d\t%d\t%d\t\n", mode.width, mode.height, mode.refresh, - mode.xdpi, mode.ydpi); - } - if (setMode) { - status_t ret = - HwcService_DisplayMode_SetMode(hwcs, display, displayModeIndex); - if (ret != OK) { - printf("Mode set failed\n"); - HwcService_Disconnect(hwcs); - return 1; - } - } - HwcService_Disconnect(hwcs); - return 0; -} -- 2.11.0