From cd2e9f587d9d24fc0e5b1058e8a05c573714ec02 Mon Sep 17 00:00:00 2001 From: Dominik Laskowski Date: Mon, 12 Mar 2018 19:41:03 -0700 Subject: [PATCH] graphics: Add composer 2.3 The 2.3 interface adds IComposerClient.getDisplayIdentificationData, which enables display identification for generalized multi-display support. Bug: 74619554 Test: VtsHalGraphicsComposerV2_3TargetTest Change-Id: I303e722ce938fe0af4fc77da812e3525d8c90251 --- graphics/composer/2.3/Android.bp | 21 +++ graphics/composer/2.3/IComposer.hal | 37 +++++ graphics/composer/2.3/IComposerClient.hal | 45 ++++++ graphics/composer/2.3/default/Android.bp | 45 ++++++ graphics/composer/2.3/default/OWNERS | 4 + ....hardware.graphics.composer@2.3-service.rc | 6 + graphics/composer/2.3/default/service.cpp | 55 ++++++++ graphics/composer/2.3/utils/OWNERS | 7 + graphics/composer/2.3/utils/hal/Android.bp | 34 +++++ .../hal/include/composer-hal/2.3/Composer.h | 89 ++++++++++++ .../include/composer-hal/2.3/ComposerClient.h | 74 ++++++++++ .../include/composer-hal/2.3/ComposerHal.h | 42 ++++++ .../composer/2.3/utils/passthrough/Android.bp | 30 ++++ .../include/composer-passthrough/2.3/HwcHal.h | 99 +++++++++++++ .../composer-passthrough/2.3/HwcLoader.h | 79 +++++++++++ graphics/composer/2.3/utils/vts/Android.bp | 41 ++++++ .../composer/2.3/utils/vts/ComposerVts.cpp | 72 ++++++++++ .../include/composer-vts/2.3/ComposerVts.h | 74 ++++++++++ .../composer/2.3/vts/functional/Android.bp | 44 ++++++ graphics/composer/2.3/vts/functional/OWNERS | 7 + .../VtsHalGraphicsComposerV2_3TargetTest.cpp | 133 ++++++++++++++++++ 21 files changed, 1038 insertions(+) create mode 100644 graphics/composer/2.3/Android.bp create mode 100644 graphics/composer/2.3/IComposer.hal create mode 100644 graphics/composer/2.3/IComposerClient.hal create mode 100644 graphics/composer/2.3/default/Android.bp create mode 100644 graphics/composer/2.3/default/OWNERS create mode 100644 graphics/composer/2.3/default/android.hardware.graphics.composer@2.3-service.rc create mode 100644 graphics/composer/2.3/default/service.cpp create mode 100644 graphics/composer/2.3/utils/OWNERS create mode 100644 graphics/composer/2.3/utils/hal/Android.bp create mode 100644 graphics/composer/2.3/utils/hal/include/composer-hal/2.3/Composer.h create mode 100644 graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h create mode 100644 graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerHal.h create mode 100644 graphics/composer/2.3/utils/passthrough/Android.bp create mode 100644 graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h create mode 100644 graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcLoader.h create mode 100644 graphics/composer/2.3/utils/vts/Android.bp create mode 100644 graphics/composer/2.3/utils/vts/ComposerVts.cpp create mode 100644 graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h create mode 100644 graphics/composer/2.3/vts/functional/Android.bp create mode 100644 graphics/composer/2.3/vts/functional/OWNERS create mode 100644 graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp diff --git a/graphics/composer/2.3/Android.bp b/graphics/composer/2.3/Android.bp new file mode 100644 index 0000000000..23061dda5b --- /dev/null +++ b/graphics/composer/2.3/Android.bp @@ -0,0 +1,21 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.graphics.composer@2.3", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "IComposer.hal", + "IComposerClient.hal", + ], + interfaces: [ + "android.hardware.graphics.common@1.0", + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.2", + "android.hidl.base@1.0", + ], + gen_java: false, +} + diff --git a/graphics/composer/2.3/IComposer.hal b/graphics/composer/2.3/IComposer.hal new file mode 100644 index 0000000000..90b2427c7c --- /dev/null +++ b/graphics/composer/2.3/IComposer.hal @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 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. + */ + +package android.hardware.graphics.composer@2.3; + +import IComposerClient; + +import @2.1::Error; +import @2.2::IComposer; + +interface IComposer extends @2.2::IComposer { + + /** + * Creates a v2.3 client of the composer. Supersedes @2.1::createClient. + * + * @return error is NONE upon success. Otherwise, + * NO_RESOURCES when the client could not be created. + * @return client is the newly created client. + */ + @entry + @callflow(next="*") + createClient_2_3() generates (Error error, IComposerClient client); + +}; diff --git a/graphics/composer/2.3/IComposerClient.hal b/graphics/composer/2.3/IComposerClient.hal new file mode 100644 index 0000000000..77dd3eed72 --- /dev/null +++ b/graphics/composer/2.3/IComposerClient.hal @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 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. + */ + +package android.hardware.graphics.composer@2.3; + +import @2.2::IComposerClient; +import @2.1::Display; +import @2.1::Error; + +interface IComposerClient extends @2.2::IComposerClient { + + /** + * Returns the port and data that describe a physical display. The port is + * a unique number that identifies a physical connector (e.g. eDP, HDMI) + * for display output. The data blob is parsed to determine its format, + * typically EDID 1.3 as specified in VESA E-EDID Standard Release A + * Revision 1. + * + * @param display is the display to query. + * @return error is NONE upon success. Otherwise, + * BAD_DISPLAY when an invalid display handle was passed in. + * UNSUPPORTED when identification data is unavailable. + * @return port is the connector to which the display is connected. + * @return data is the EDID 1.3 blob identifying the display. + */ + @callflow(next="*") + getDisplayIdentificationData(Display display) + generates (Error error, + uint8_t port, + vec data); + +}; diff --git a/graphics/composer/2.3/default/Android.bp b/graphics/composer/2.3/default/Android.bp new file mode 100644 index 0000000000..ad49ec3adf --- /dev/null +++ b/graphics/composer/2.3/default/Android.bp @@ -0,0 +1,45 @@ +// +// Copyright (C) 2018 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. +// + +cc_binary { + name: "android.hardware.graphics.composer@2.3-service", + defaults: ["hidl_defaults"], + vendor: true, + relative_install_path: "hw", + srcs: ["service.cpp"], + init_rc: ["android.hardware.graphics.composer@2.3-service.rc"], + header_libs: [ + "android.hardware.graphics.composer@2.3-passthrough", + ], + shared_libs: [ + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.3", + "android.hardware.graphics.mapper@2.0", + "libbase", + "libbinder", + "libcutils", + "libfmq", + "libhardware", + "libhidlbase", + "libhidltransport", + "libhwc2on1adapter", + "libhwc2onfbadapter", + "liblog", + "libsync", + "libutils", + ], +} diff --git a/graphics/composer/2.3/default/OWNERS b/graphics/composer/2.3/default/OWNERS new file mode 100644 index 0000000000..3aa5fa1ffd --- /dev/null +++ b/graphics/composer/2.3/default/OWNERS @@ -0,0 +1,4 @@ +# Graphics team +jessehall@google.com +olv@google.com +stoza@google.com diff --git a/graphics/composer/2.3/default/android.hardware.graphics.composer@2.3-service.rc b/graphics/composer/2.3/default/android.hardware.graphics.composer@2.3-service.rc new file mode 100644 index 0000000000..08e32d8f13 --- /dev/null +++ b/graphics/composer/2.3/default/android.hardware.graphics.composer@2.3-service.rc @@ -0,0 +1,6 @@ +service vendor.hwcomposer-2-3 /vendor/bin/hw/android.hardware.graphics.composer@2.3-service + class hal animation + user system + group graphics drmrpc + capabilities SYS_NICE + onrestart restart surfaceflinger diff --git a/graphics/composer/2.3/default/service.cpp b/graphics/composer/2.3/default/service.cpp new file mode 100644 index 0000000000..347d8be278 --- /dev/null +++ b/graphics/composer/2.3/default/service.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2018 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 + +#include +#include +#include +#include + +using android::hardware::graphics::composer::V2_3::IComposer; +using android::hardware::graphics::composer::V2_3::passthrough::HwcLoader; + +int main() { + // the conventional HAL might start binder services + android::ProcessState::initWithDriver("/dev/vndbinder"); + android::ProcessState::self()->setThreadPoolMaxThreadCount(4); + android::ProcessState::self()->startThreadPool(); + + // same as SF main thread + struct sched_param param = {0}; + param.sched_priority = 2; + if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, ¶m) != 0) { + ALOGE("Couldn't set SCHED_FIFO: %d", errno); + } + + android::hardware::configureRpcThreadpool(4, true /* will join */); + + android::sp composer = HwcLoader::load(); + if (composer == nullptr) { + return 1; + } + if (composer->registerAsService() != android::NO_ERROR) { + ALOGE("failed to register service"); + return 1; + } + + android::hardware::joinRpcThreadpool(); + + ALOGE("service is terminating"); + return 1; +} diff --git a/graphics/composer/2.3/utils/OWNERS b/graphics/composer/2.3/utils/OWNERS new file mode 100644 index 0000000000..234bc7559f --- /dev/null +++ b/graphics/composer/2.3/utils/OWNERS @@ -0,0 +1,7 @@ +# Graphics team +olv@google.com +stoza@google.com + +# VTS team +yim@google.com +zhuoyao@google.com diff --git a/graphics/composer/2.3/utils/hal/Android.bp b/graphics/composer/2.3/utils/hal/Android.bp new file mode 100644 index 0000000000..aa46df1ebb --- /dev/null +++ b/graphics/composer/2.3/utils/hal/Android.bp @@ -0,0 +1,34 @@ +// +// Copyright (C) 2018 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. +// + +cc_library_headers { + name: "android.hardware.graphics.composer@2.3-hal", + defaults: ["hidl_defaults"], + vendor_available: true, + shared_libs: [ + "android.hardware.graphics.composer@2.3", + ], + export_shared_lib_headers: [ + "android.hardware.graphics.composer@2.3", + ], + header_libs: [ + "android.hardware.graphics.composer@2.2-hal", + ], + export_header_lib_headers: [ + "android.hardware.graphics.composer@2.2-hal", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/Composer.h b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/Composer.h new file mode 100644 index 0000000000..8e11a5ae1a --- /dev/null +++ b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/Composer.h @@ -0,0 +1,89 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#ifndef LOG_TAG +#warning "Composer.h included without LOG_TAG" +#endif + +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace hal { + +namespace detail { + +// ComposerImpl implements V2_*::IComposer on top of V2_*::ComposerHal +template +class ComposerImpl : public V2_2::hal::detail::ComposerImpl { + public: + static std::unique_ptr create(std::unique_ptr hal) { + return std::make_unique(std::move(hal)); + } + + explicit ComposerImpl(std::unique_ptr hal) : BaseType2_2(std::move(hal)) {} + + // IComposer 2.3 interface + + Return createClient_2_3(IComposer::createClient_2_3_cb hidl_cb) override { + std::unique_lock lock(mClientMutex); + if (!waitForClientDestroyedLocked(lock)) { + hidl_cb(Error::NO_RESOURCES, nullptr); + return Void(); + } + + sp client = ComposerClient::create(mHal.get()).release(); + if (!client) { + hidl_cb(Error::NO_RESOURCES, nullptr); + return Void(); + } + + auto clientDestroyed = [this]() { onClientDestroyed(); }; + client->setOnClientDestroyed(clientDestroyed); + + mClient = client; + hidl_cb(Error::NONE, client); + return Void(); + } + + private: + using BaseType2_2 = V2_2::hal::detail::ComposerImpl; + using BaseType2_1 = V2_1::hal::detail::ComposerImpl; + + using BaseType2_1::mClient; + using BaseType2_1::mClientMutex; + using BaseType2_1::mHal; + using BaseType2_1::onClientDestroyed; + using BaseType2_1::waitForClientDestroyedLocked; +}; + +} // namespace detail + +using Composer = detail::ComposerImpl; + +} // namespace hal +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h new file mode 100644 index 0000000000..e717d84ba8 --- /dev/null +++ b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h @@ -0,0 +1,74 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#ifndef LOG_TAG +#warning "ComposerClient.h included without LOG_TAG" +#endif + +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace hal { + +namespace detail { + +// ComposerClientImpl implements V2_*::IComposerClient on top of V2_*::ComposerHal +template +class ComposerClientImpl : public V2_2::hal::detail::ComposerClientImpl { + public: + static std::unique_ptr create(Hal* hal) { + auto client = std::make_unique(hal); + return client->init() ? std::move(client) : nullptr; + } + + ComposerClientImpl(Hal* hal) : BaseType2_2(hal) {} + + // IComposerClient 2.3 interface + + Return getDisplayIdentificationData( + Display display, IComposerClient::getDisplayIdentificationData_cb hidl_cb) override { + uint8_t port = 0; + std::vector data; + Error error = mHal->getDisplayIdentificationData(display, &port, &data); + hidl_cb(error, port, data); + return Void(); + } + + private: + using BaseType2_2 = V2_2::hal::detail::ComposerClientImpl; + using BaseType2_1 = V2_1::hal::detail::ComposerClientImpl; + + using BaseType2_1::mHal; +}; + +} // namespace detail + +using ComposerClient = detail::ComposerClientImpl; + +} // namespace hal +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerHal.h b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerHal.h new file mode 100644 index 0000000000..37ea0a3c46 --- /dev/null +++ b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerHal.h @@ -0,0 +1,42 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace hal { + +using V2_1::Display; +using V2_1::Error; + +class ComposerHal : public V2_2::hal::ComposerHal { + public: + virtual Error getDisplayIdentificationData(Display display, uint8_t* outPort, + std::vector* outData) = 0; +}; + +} // namespace hal +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/passthrough/Android.bp b/graphics/composer/2.3/utils/passthrough/Android.bp new file mode 100644 index 0000000000..3ae6b1648d --- /dev/null +++ b/graphics/composer/2.3/utils/passthrough/Android.bp @@ -0,0 +1,30 @@ +// +// Copyright (C) 2018 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. +// + +cc_library_headers { + name: "android.hardware.graphics.composer@2.3-passthrough", + defaults: ["hidl_defaults"], + vendor: true, + header_libs: [ + "android.hardware.graphics.composer@2.2-passthrough", + "android.hardware.graphics.composer@2.3-hal", + ], + export_header_lib_headers: [ + "android.hardware.graphics.composer@2.2-passthrough", + "android.hardware.graphics.composer@2.3-hal", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h new file mode 100644 index 0000000000..53f2d1b254 --- /dev/null +++ b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h @@ -0,0 +1,99 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#ifndef LOG_TAG +#warning "HwcHal.h included without LOG_TAG" +#endif + +#include + +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace passthrough { + +namespace detail { + +using V2_1::Display; +using V2_1::Error; + +// HwcHalImpl implements V2_*::hal::ComposerHal on top of hwcomposer2 +template +class HwcHalImpl : public V2_2::passthrough::detail::HwcHalImpl { + public: + Error getDisplayIdentificationData(Display display, uint8_t* outPort, + std::vector* outData) override { + if (!mDispatch.getDisplayIdentificationData) { + return Error::UNSUPPORTED; + } + + uint32_t size = 0; + int32_t error = + mDispatch.getDisplayIdentificationData(mDevice, display, outPort, &size, nullptr); + if (error != HWC2_ERROR_NONE) { + return static_cast(error); + } + + std::vector data(size); + error = + mDispatch.getDisplayIdentificationData(mDevice, display, outPort, &size, data.data()); + if (error != HWC2_ERROR_NONE) { + return static_cast(error); + } + + data.resize(size); + *outData = std::move(data); + return Error::NONE; + } + + protected: + bool initDispatch() override { + if (!BaseType2_2::initDispatch()) { + return false; + } + + this->initOptionalDispatch(HWC2_FUNCTION_GET_DISPLAY_IDENTIFICATION_DATA, + &mDispatch.getDisplayIdentificationData); + return true; + } + + private: + struct { + HWC2_PFN_GET_DISPLAY_IDENTIFICATION_DATA getDisplayIdentificationData; + } mDispatch = {}; + + using BaseType2_2 = V2_2::passthrough::detail::HwcHalImpl; + using BaseType2_1 = V2_1::passthrough::detail::HwcHalImpl; + using BaseType2_1::mDevice; +}; + +} // namespace detail + +using HwcHal = detail::HwcHalImpl; + +} // namespace passthrough +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcLoader.h b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcLoader.h new file mode 100644 index 0000000000..afef475e78 --- /dev/null +++ b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcLoader.h @@ -0,0 +1,79 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#ifndef LOG_TAG +#warning "HwcLoader.h included without LOG_TAG" +#endif + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace passthrough { + +class HwcLoader : public V2_2::passthrough::HwcLoader { + public: + static IComposer* load() { + const hw_module_t* module = loadModule(); + if (!module) { + return nullptr; + } + + auto hal = createHalWithAdapter(module); + if (!hal) { + return nullptr; + } + + return createComposer(std::move(hal)).release(); + } + + // create a ComposerHal instance + static std::unique_ptr createHal(const hw_module_t* module) { + auto hal = std::make_unique(); + return hal->initWithModule(module) ? std::move(hal) : nullptr; + } + + // create a ComposerHal instance, insert an adapter if necessary + static std::unique_ptr createHalWithAdapter(const hw_module_t* module) { + bool adapted; + hwc2_device_t* device = openDeviceWithAdapter(module, &adapted); + if (!device) { + return nullptr; + } + auto hal = std::make_unique(); + return hal->initWithDevice(std::move(device), !adapted) ? std::move(hal) : nullptr; + } + + // create an IComposer instance + static std::unique_ptr createComposer(std::unique_ptr hal) { + return hal::Composer::create(std::move(hal)); + } +}; + +} // namespace passthrough +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/vts/Android.bp b/graphics/composer/2.3/utils/vts/Android.bp new file mode 100644 index 0000000000..05532586ef --- /dev/null +++ b/graphics/composer/2.3/utils/vts/Android.bp @@ -0,0 +1,41 @@ +// +// Copyright (C) 2018 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. +// + +cc_library_static { + name: "android.hardware.graphics.composer@2.3-vts", + defaults: ["hidl_defaults"], + srcs: [ + "ComposerVts.cpp", + ], + static_libs: [ + "VtsHalHidlTargetTestBase", + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.1-vts", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.2-vts", + "android.hardware.graphics.composer@2.3", + ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + "android.hardware.graphics.composer@2.2-command-buffer", + ], + cflags: [ + "-O0", + "-g", + "-DLOG_TAG=\"ComposerVts\"", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.3/utils/vts/ComposerVts.cpp b/graphics/composer/2.3/utils/vts/ComposerVts.cpp new file mode 100644 index 0000000000..f1d3a5093a --- /dev/null +++ b/graphics/composer/2.3/utils/vts/ComposerVts.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 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 + +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace vts { + +using V2_1::Error; + +Composer::Composer() : Composer(::testing::VtsHalHidlTargetTestBase::getService()) {} + +Composer::Composer(const std::string& name) + : Composer(::testing::VtsHalHidlTargetTestBase::getService(name)) {} + +Composer::Composer(const sp& composer) + : V2_2::vts::Composer(composer), mComposer(composer) {} + +std::unique_ptr Composer::createClient() { + std::unique_ptr client; + mComposer->createClient_2_3([&client](const auto& tmpError, const auto& tmpClient) { + ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; + client = std::make_unique(tmpClient); + }); + + return client; +} + +bool ComposerClient::getDisplayIdentificationData(Display display, uint8_t* outPort, + std::vector* outData) { + bool supported = true; + mClient->getDisplayIdentificationData( + display, [&](const auto& tmpError, const auto& tmpPort, const auto& tmpData) { + if (tmpError == Error::UNSUPPORTED) { + supported = false; + return; + } + ASSERT_EQ(Error::NONE, tmpError) << "failed to get display identification data"; + + *outPort = tmpPort; + *outData = tmpData; + ASSERT_FALSE(outData->empty()) << "data is empty"; + }); + + return supported; +} + +} // namespace vts +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h b/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h new file mode 100644 index 0000000000..103b85a830 --- /dev/null +++ b/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 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. + */ + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace vts { + +using V2_1::Display; +using V2_3::IComposer; +using V2_3::IComposerClient; + +class ComposerClient; + +// A wrapper to IComposer. +class Composer : public V2_2::vts::Composer { + public: + Composer(); + explicit Composer(const std::string& name); + + std::unique_ptr createClient(); + + protected: + explicit Composer(const sp& composer); + + private: + const sp mComposer; +}; + +// A wrapper to IComposerClient. +class ComposerClient : public V2_2::vts::ComposerClient { + public: + explicit ComposerClient(const sp& client) + : V2_2::vts::ComposerClient(client), mClient(client) {} + + bool getDisplayIdentificationData(Display display, uint8_t* outPort, + std::vector* outData); + + private: + const sp mClient; +}; + +} // namespace vts +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.3/vts/functional/Android.bp b/graphics/composer/2.3/vts/functional/Android.bp new file mode 100644 index 0000000000..df696c9273 --- /dev/null +++ b/graphics/composer/2.3/vts/functional/Android.bp @@ -0,0 +1,44 @@ +// +// Copyright (C) 2018 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. +// + +cc_test { + name: "VtsHalGraphicsComposerV2_3TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalGraphicsComposerV2_3TargetTest.cpp"], + + // TODO(b/64437680): Assume these libs are always available on the device. + shared_libs: [ + "libfmq", + "libhidltransport", + "libsync", + ], + static_libs: [ + "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.1-vts", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.2-vts", + "android.hardware.graphics.composer@2.3", + "android.hardware.graphics.composer@2.3-vts", + "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.0-vts", + "android.hardware.graphics.mapper@2.1", + ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + "android.hardware.graphics.composer@2.2-command-buffer", + ], +} diff --git a/graphics/composer/2.3/vts/functional/OWNERS b/graphics/composer/2.3/vts/functional/OWNERS new file mode 100644 index 0000000000..234bc7559f --- /dev/null +++ b/graphics/composer/2.3/vts/functional/OWNERS @@ -0,0 +1,7 @@ +# Graphics team +olv@google.com +stoza@google.com + +# VTS team +yim@google.com +zhuoyao@google.com diff --git a/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp b/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp new file mode 100644 index 0000000000..f4e34f08ff --- /dev/null +++ b/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2018 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. + */ + +#define LOG_TAG "graphics_composer_hidl_hal_test@2.3" + +#include + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_3 { +namespace vts { +namespace { + +// Test environment for graphics.composer +class GraphicsComposerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static GraphicsComposerHidlEnvironment* Instance() { + static GraphicsComposerHidlEnvironment* instance = new GraphicsComposerHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } + + private: + GraphicsComposerHidlEnvironment() {} + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GraphicsComposerHidlEnvironment); +}; + +class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase { + protected: + void SetUp() override { + ASSERT_NO_FATAL_FAILURE( + mComposer = std::make_unique( + GraphicsComposerHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient()); + + mComposerCallback = new V2_1::vts::GraphicsComposerCallback; + mComposerClient->registerCallback(mComposerCallback); + + // assume the first display is primary and is never removed + mPrimaryDisplay = waitForFirstDisplay(); + + // explicitly disable vsync + mComposerClient->setVsyncEnabled(mPrimaryDisplay, false); + mComposerCallback->setVsyncAllowed(false); + } + + void TearDown() override { + if (mComposerCallback != nullptr) { + EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount()); + EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount()); + EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount()); + } + } + + std::unique_ptr mComposer; + std::unique_ptr mComposerClient; + sp mComposerCallback; + // the first display and is assumed never to be removed + Display mPrimaryDisplay; + + private: + Display waitForFirstDisplay() { + while (true) { + std::vector displays = mComposerCallback->getDisplays(); + if (displays.empty()) { + usleep(5 * 1000); + continue; + } + + return displays[0]; + } + } +}; + +/** + * Test IComposerClient::getDisplayIdentificationData. + * + * TODO: Check that ports are unique for multiple displays. + */ +TEST_F(GraphicsComposerHidlTest, GetDisplayIdentificationData) { + uint8_t port0; + std::vector data0; + if (mComposerClient->getDisplayIdentificationData(mPrimaryDisplay, &port0, &data0)) { + uint8_t port1; + std::vector data1; + ASSERT_TRUE(mComposerClient->getDisplayIdentificationData(mPrimaryDisplay, &port1, &data1)); + + ASSERT_EQ(port0, port1) << "ports are not stable"; + ASSERT_TRUE(data0.size() == data1.size() && + std::equal(data0.begin(), data0.end(), data1.begin())) + << "data is not stable"; + } +} + +} // namespace +} // namespace vts +} // namespace V2_3 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android + +int main(int argc, char** argv) { + using android::hardware::graphics::composer::V2_3::vts::GraphicsComposerHidlEnvironment; + ::testing::AddGlobalTestEnvironment(GraphicsComposerHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + GraphicsComposerHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + return status; +}