diff --git a/graphics/composer/2.4/Android.bp b/graphics/composer/2.4/Android.bp new file mode 100644 index 0000000000..4a92df2c5b --- /dev/null +++ b/graphics/composer/2.4/Android.bp @@ -0,0 +1,24 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.graphics.composer@2.4", + root: "android.hardware", + vndk: { + // TODO(b/135929065) enable once we are ready to use. + enabled: false, + }, + srcs: [ + "IComposer.hal", + "IComposerClient.hal", + ], + interfaces: [ + "android.hardware.graphics.common@1.0", + "android.hardware.graphics.common@1.1", + "android.hardware.graphics.common@1.2", + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.3", + "android.hidl.base@1.0", + ], + gen_java: false, +} diff --git a/graphics/composer/2.4/IComposer.hal b/graphics/composer/2.4/IComposer.hal new file mode 100644 index 0000000000..34801daa27 --- /dev/null +++ b/graphics/composer/2.4/IComposer.hal @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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.4; + +import IComposerClient; + +import @2.1::Error; +import @2.3::IComposer; + +interface IComposer extends @2.3::IComposer { + + /** + * Creates a v2.4 client of the composer. Supersedes @2.3::createClient. + * + * @return error is NONE upon success. Otherwise, + * NO_RESOURCES when the client could not be created. + * @return client is the newly created client. + */ + createClient_2_4() generates (Error error, IComposerClient client); +}; diff --git a/graphics/composer/2.4/IComposerClient.hal b/graphics/composer/2.4/IComposerClient.hal new file mode 100644 index 0000000000..8fe0976781 --- /dev/null +++ b/graphics/composer/2.4/IComposerClient.hal @@ -0,0 +1,51 @@ +/* + * Copyright 2019 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.4; + +import @2.1::Display; +import @2.1::Error; +import @2.3::IComposerClient; + +interface IComposerClient extends @2.3::IComposerClient { + + /** + * Required capabilities which are supported by the display. The + * particular set of supported capabilities for a given display may be + * retrieved using getDisplayCapabilities. + */ + enum DisplayCapability : uint32_t { + /** + * Indicates that the display supports protected contents. + * When returned, hardware composer must be able to accept client target + * with protected buffers. + */ + PROTECTED_CONTENTS = 4, + }; + + /** + * Provides a list of supported capabilities (as described in the + * definition of DisplayCapability above). This list must not change after + * initialization. + * + * @return error is NONE upon success. Otherwise, + * BAD_DISPLAY when an invalid display handle was passed in. + * @return capabilities is a list of supported capabilities. + */ + getDisplayCapabilities_2_4(Display display) + generates (Error error, + vec capabilities); +}; diff --git a/graphics/composer/2.4/default/Android.bp b/graphics/composer/2.4/default/Android.bp new file mode 100644 index 0000000000..1bf51e0250 --- /dev/null +++ b/graphics/composer/2.4/default/Android.bp @@ -0,0 +1,47 @@ +// +// Copyright 2019 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.4-service", + defaults: ["hidl_defaults"], + vendor: true, + relative_install_path: "hw", + srcs: ["service.cpp"], + init_rc: ["android.hardware.graphics.composer@2.4-service.rc"], + header_libs: [ + "android.hardware.graphics.composer@2.4-passthrough", + ], + shared_libs: [ + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.3", + "android.hardware.graphics.composer@2.4", + "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", + "libbase", + "libbinder", + "libcutils", + "libfmq", + "libhardware", + "libhidlbase", + "libhidltransport", + "libhwc2on1adapter", + "libhwc2onfbadapter", + "liblog", + "libsync", + "libutils", + ], +} diff --git a/graphics/composer/2.4/default/OWNERS b/graphics/composer/2.4/default/OWNERS new file mode 100644 index 0000000000..cc6d937cad --- /dev/null +++ b/graphics/composer/2.4/default/OWNERS @@ -0,0 +1,4 @@ +# Graphics team +lpy@google.com +stoza@google.com +vhau@google.com diff --git a/graphics/composer/2.4/default/android.hardware.graphics.composer@2.4-service.rc b/graphics/composer/2.4/default/android.hardware.graphics.composer@2.4-service.rc new file mode 100644 index 0000000000..a296b0aace --- /dev/null +++ b/graphics/composer/2.4/default/android.hardware.graphics.composer@2.4-service.rc @@ -0,0 +1,7 @@ +service vendor.hwcomposer-2-4 /vendor/bin/hw/android.hardware.graphics.composer@2.4-service + class hal animation + user system + group graphics drmrpc + capabilities SYS_NICE + onrestart restart surfaceflinger + writepid /dev/cpuset/system-background/tasks diff --git a/graphics/composer/2.4/default/service.cpp b/graphics/composer/2.4/default/service.cpp new file mode 100644 index 0000000000..98dac3e258 --- /dev/null +++ b/graphics/composer/2.4/default/service.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2019 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_4::IComposer; +using android::hardware::graphics::composer::V2_4::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.4/utils/OWNERS b/graphics/composer/2.4/utils/OWNERS new file mode 100644 index 0000000000..cc6d937cad --- /dev/null +++ b/graphics/composer/2.4/utils/OWNERS @@ -0,0 +1,4 @@ +# Graphics team +lpy@google.com +stoza@google.com +vhau@google.com diff --git a/graphics/composer/2.4/utils/command-buffer/Android.bp b/graphics/composer/2.4/utils/command-buffer/Android.bp new file mode 100644 index 0000000000..8acf0e13ca --- /dev/null +++ b/graphics/composer/2.4/utils/command-buffer/Android.bp @@ -0,0 +1,18 @@ +cc_library_headers { + name: "android.hardware.graphics.composer@2.4-command-buffer", + defaults: ["hidl_defaults"], + vendor_available: true, + shared_libs: [ + "android.hardware.graphics.composer@2.4", + ], + export_shared_lib_headers: [ + "android.hardware.graphics.composer@2.4", + ], + header_libs: [ + "android.hardware.graphics.composer@2.3-command-buffer", + ], + export_header_lib_headers: [ + "android.hardware.graphics.composer@2.3-command-buffer", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h b/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h new file mode 100644 index 0000000000..6b64c163c0 --- /dev/null +++ b/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h @@ -0,0 +1,58 @@ +/* + * Copyright 2019 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 +#warn "ComposerCommandBuffer.h included without LOG_TAG" +#endif + +#undef LOG_NDEBUG +#define LOG_NDEBUG 0 + +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_4 { + +using android::hardware::MessageQueue; +using android::hardware::graphics::composer::V2_1::Error; +using android::hardware::graphics::composer::V2_4::IComposerClient; + +// This class helps build a command queue. Note that all sizes/lengths are in +// units of uint32_t's. +class CommandWriterBase : public V2_3::CommandWriterBase { + public: + CommandWriterBase(uint32_t initialMaxSize) : V2_3::CommandWriterBase(initialMaxSize) {} +}; + +// This class helps parse a command queue. Note that all sizes/lengths are in +// units of uint32_t's. +class CommandReaderBase : public V2_3::CommandReaderBase { + public: + CommandReaderBase() : V2_3::CommandReaderBase(){}; +}; + +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/hal/Android.bp b/graphics/composer/2.4/utils/hal/Android.bp new file mode 100644 index 0000000000..3ee4e19a7d --- /dev/null +++ b/graphics/composer/2.4/utils/hal/Android.bp @@ -0,0 +1,36 @@ +// +// Copyright 2019 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.4-hal", + defaults: ["hidl_defaults"], + vendor_available: true, + shared_libs: [ + "android.hardware.graphics.composer@2.4", + ], + export_shared_lib_headers: [ + "android.hardware.graphics.composer@2.4", + ], + header_libs: [ + "android.hardware.graphics.composer@2.3-hal", + "android.hardware.graphics.composer@2.3-command-buffer", + ], + export_header_lib_headers: [ + "android.hardware.graphics.composer@2.3-hal", + "android.hardware.graphics.composer@2.3-command-buffer", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/Composer.h b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/Composer.h new file mode 100644 index 0000000000..129bae6eb9 --- /dev/null +++ b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/Composer.h @@ -0,0 +1,89 @@ +/* + * Copyright 2019 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_4 { +namespace hal { + +namespace detail { + +// ComposerImpl implements V2_*::IComposer on top of V2_*::ComposerHal +template +class ComposerImpl : public V2_3::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_3(std::move(hal)) {} + + // IComposer 2.4 interface + + Return createClient_2_4(IComposer::createClient_2_4_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_3 = V2_3::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_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerClient.h b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerClient.h new file mode 100644 index 0000000000..7110c80db0 --- /dev/null +++ b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerClient.h @@ -0,0 +1,69 @@ +/* + * Copyright 2019 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 + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_4 { +namespace hal { + +namespace detail { + +// ComposerClientImpl implements V2_*::IComposerClient on top of V2_*::ComposerHal +template +class ComposerClientImpl : public V2_3::hal::detail::ComposerClientImpl { + public: + ComposerClientImpl(Hal* hal) : BaseType2_3(hal) {} + + Return getDisplayCapabilities_2_4( + Display display, IComposerClient::getDisplayCapabilities_2_4_cb hidl_cb) override { + std::vector capabilities; + Error error = mHal->getDisplayCapabilities_2_4(display, &capabilities); + hidl_cb(error, capabilities); + return Void(); + } + + static std::unique_ptr create(Hal* hal) { + auto client = std::make_unique(hal); + return client->init() ? std::move(client) : nullptr; + } + + private: + using BaseType2_3 = V2_3::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_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerHal.h b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerHal.h new file mode 100644 index 0000000000..0074808309 --- /dev/null +++ b/graphics/composer/2.4/utils/hal/include/composer-hal/2.4/ComposerHal.h @@ -0,0 +1,48 @@ +/* + * 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_4 { +namespace hal { + +using common::V1_1::RenderIntent; +using common::V1_2::ColorMode; +using common::V1_2::Dataspace; +using common::V1_2::Hdr; +using common::V1_2::PixelFormat; +using V2_1::Display; +using V2_1::Error; +using V2_1::Layer; + +class ComposerHal : public V2_3::hal::ComposerHal { + public: + virtual Error getDisplayCapabilities_2_4( + Display display, std::vector* outCapabilities) = 0; +}; + +} // namespace hal +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/passthrough/Android.bp b/graphics/composer/2.4/utils/passthrough/Android.bp new file mode 100644 index 0000000000..43d9aaaa78 --- /dev/null +++ b/graphics/composer/2.4/utils/passthrough/Android.bp @@ -0,0 +1,30 @@ +// +// Copyright 2019 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.4-passthrough", + defaults: ["hidl_defaults"], + vendor: true, + header_libs: [ + "android.hardware.graphics.composer@2.3-passthrough", + "android.hardware.graphics.composer@2.4-hal", + ], + export_header_lib_headers: [ + "android.hardware.graphics.composer@2.3-passthrough", + "android.hardware.graphics.composer@2.4-hal", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcHal.h b/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcHal.h new file mode 100644 index 0000000000..65d47d781d --- /dev/null +++ b/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcHal.h @@ -0,0 +1,88 @@ +/* + * Copyright 2019 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_4 { +namespace passthrough { + +namespace detail { + +using common::V1_1::RenderIntent; +using common::V1_2::ColorMode; +using common::V1_2::Dataspace; +using common::V1_2::Hdr; +using common::V1_2::PixelFormat; +using V2_1::Display; +using V2_1::Error; + +// HwcHalImpl implements V2_*::hal::ComposerHal on top of hwcomposer2 +template +class HwcHalImpl : public V2_3::passthrough::detail::HwcHalImpl { + public: + Error getDisplayCapabilities_2_4( + Display display, + std::vector* outCapabilities) override { + std::vector capabilities; + Error error = BaseType2_3::getDisplayCapabilities(display, &capabilities); + if (error != Error::NONE) { + return error; + } + outCapabilities->clear(); + outCapabilities->reserve(capabilities.size()); + for (auto capability : capabilities) { + outCapabilities->push_back(static_cast(capability)); + } + return Error::NONE; + } + + protected: + bool initDispatch() override { + if (!BaseType2_3::initDispatch()) { + return false; + } + return true; + } + + private: + using BaseType2_1 = V2_1::passthrough::detail::HwcHalImpl; + using BaseType2_3 = V2_3::passthrough::detail::HwcHalImpl; + using BaseType2_1::mDevice; +}; + +} // namespace detail + +using HwcHal = detail::HwcHalImpl; + +} // namespace passthrough +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcLoader.h b/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcLoader.h new file mode 100644 index 0000000000..a7cc5886e0 --- /dev/null +++ b/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcLoader.h @@ -0,0 +1,79 @@ +/* + * Copyright 2019 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_4 { +namespace passthrough { + +class HwcLoader : public V2_3::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_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/vts/Android.bp b/graphics/composer/2.4/utils/vts/Android.bp new file mode 100644 index 0000000000..b87a116865 --- /dev/null +++ b/graphics/composer/2.4/utils/vts/Android.bp @@ -0,0 +1,42 @@ +// +// Copyright 2019 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.4-vts", + defaults: ["hidl_defaults"], + srcs: [ + "ComposerVts.cpp", + ], + static_libs: [ + "VtsHalHidlTargetTestBase", + "android.hardware.graphics.composer@2.1", + "android.hardware.graphics.composer@2.2", + "android.hardware.graphics.composer@2.3-vts", + "android.hardware.graphics.composer@2.3", + "android.hardware.graphics.composer@2.4", + ], + header_libs: [ + "android.hardware.graphics.composer@2.1-command-buffer", + "android.hardware.graphics.composer@2.2-command-buffer", + "android.hardware.graphics.composer@2.3-command-buffer", + ], + cflags: [ + "-O0", + "-g", + "-DLOG_TAG=\"ComposerVts\"", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/2.4/utils/vts/ComposerVts.cpp b/graphics/composer/2.4/utils/vts/ComposerVts.cpp new file mode 100644 index 0000000000..ee4f3a3959 --- /dev/null +++ b/graphics/composer/2.4/utils/vts/ComposerVts.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019 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_4 { +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_3::vts::Composer(composer), mComposer(composer) {} + +std::unique_ptr Composer::createClient() { + std::unique_ptr client; + mComposer->createClient_2_4([&client](const auto& tmpError, const auto& tmpClient) { + ASSERT_EQ(Error::NONE, tmpError) << "failed to create client"; + client = std::make_unique(tmpClient); + }); + + return client; +} + +sp ComposerClient::getRaw() const { + return mClient; +} + +Error ComposerClient::getDisplayCapabilities( + Display display, std::vector* outCapabilities) { + std::vector capabilities; + Error error = Error::NONE; + mClient->getDisplayCapabilities_2_4(display, + [&](const auto& tmpError, const auto& tmpCapabilities) { + error = tmpError; + *outCapabilities = tmpCapabilities; + }); + return error; +} + +} // namespace vts +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h new file mode 100644 index 0000000000..0a301c6ca7 --- /dev/null +++ b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h @@ -0,0 +1,83 @@ +/* + * Copyright 2019 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_4 { +namespace vts { + +using common::V1_1::RenderIntent; +using common::V1_2::ColorMode; +using common::V1_2::Dataspace; +using common::V1_2::Hdr; +using common::V1_2::PixelFormat; +using V2_1::Display; +using V2_1::Error; +using V2_4::IComposer; +using V2_4::IComposerClient; + +class ComposerClient; + +// A wrapper to IComposer. +class Composer : public V2_3::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_3::vts::ComposerClient { + public: + explicit ComposerClient(const sp& client) + : V2_3::vts::ComposerClient(client), mClient(client) {} + + sp getRaw() const; + + Error getDisplayCapabilities( + Display display, + std::vector* outDisplayCapabilities); + + private: + const sp mClient; +}; + +} // namespace vts +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/composer/2.4/vts/functional/Android.bp b/graphics/composer/2.4/vts/functional/Android.bp new file mode 100644 index 0000000000..d437f2486e --- /dev/null +++ b/graphics/composer/2.4/vts/functional/Android.bp @@ -0,0 +1,48 @@ +// +// Copyright 2019 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_4TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalGraphicsComposerV2_4TargetTest.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.composer@2.4", + "android.hardware.graphics.composer@2.4-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", + "android.hardware.graphics.composer@2.3-command-buffer", + "android.hardware.graphics.composer@2.4-command-buffer", + ], +} diff --git a/graphics/composer/2.4/vts/functional/OWNERS b/graphics/composer/2.4/vts/functional/OWNERS new file mode 100644 index 0000000000..b3ea6bef7b --- /dev/null +++ b/graphics/composer/2.4/vts/functional/OWNERS @@ -0,0 +1,8 @@ +# Graphics team +lpy@google.com +stoza@google.com +vhau@google.com + +# VTS team +yim@google.com +zhuoyao@google.com diff --git a/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp new file mode 100644 index 0000000000..0fccc58637 --- /dev/null +++ b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp @@ -0,0 +1,197 @@ +/* + * Copyright 2019 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.4" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace composer { +namespace V2_4 { +namespace vts { +namespace { + +using common::V1_0::BufferUsage; +using common::V1_1::RenderIntent; +using common::V1_2::ColorMode; +using common::V1_2::Dataspace; +using common::V1_2::PixelFormat; +using mapper::V2_0::IMapper; +using mapper::V2_0::vts::Gralloc; + +// 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(); + + mInvalidDisplayId = GetInvalidDisplayId(); + + // explicitly disable vsync + mComposerClient->setVsyncEnabled(mPrimaryDisplay, false); + mComposerCallback->setVsyncAllowed(false); + + mWriter = std::make_unique(1024); + mReader = std::make_unique(); + } + + void TearDown() override { + ASSERT_EQ(0, mReader->mErrors.size()); + ASSERT_EQ(0, mReader->mCompositionChanges.size()); + if (mComposerCallback != nullptr) { + EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount()); + EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount()); + EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount()); + } + } + + // returns an invalid display id (one that has not been registered to a + // display. Currently assuming that a device will never have close to + // std::numeric_limit::max() displays registered while running tests + Display GetInvalidDisplayId() { + std::vector validDisplays = mComposerCallback->getDisplays(); + uint64_t id = std::numeric_limits::max(); + while (id > 0) { + if (std::find(validDisplays.begin(), validDisplays.end(), id) == validDisplays.end()) { + return id; + } + id--; + } + + return 0; + } + + void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); } + + std::unique_ptr mComposer; + std::unique_ptr mComposerClient; + sp mComposerCallback; + // the first display and is assumed never to be removed + Display mPrimaryDisplay; + Display mInvalidDisplayId; + std::unique_ptr mWriter; + std::unique_ptr mReader; + + private: + Display waitForFirstDisplay() { + while (true) { + std::vector displays = mComposerCallback->getDisplays(); + if (displays.empty()) { + usleep(5 * 1000); + continue; + } + + return displays[0]; + } + } +}; + +// Tests for IComposerClient::Command. +class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest { + protected: + void SetUp() override { + ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp()); + + ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique()); + + mWriter = std::make_unique(1024); + mReader = std::make_unique(); + } + + void TearDown() override { + ASSERT_EQ(0, mReader->mErrors.size()); + ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown()); + } + + const native_handle_t* allocate() { + IMapper::BufferDescriptorInfo info{}; + info.width = 64; + info.height = 64; + info.layerCount = 1; + info.format = static_cast(PixelFormat::RGBA_8888); + info.usage = + static_cast(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN); + + return mGralloc->allocate(info); + } + + void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); } + + std::unique_ptr mWriter; + std::unique_ptr mReader; + + private: + std::unique_ptr mGralloc; +}; + +TEST_F(GraphicsComposerHidlTest, getDisplayCapabilitiesBadDisplay) { + std::vector capabilities; + const auto error = mComposerClient->getDisplayCapabilities(mInvalidDisplayId, &capabilities); + EXPECT_EQ(Error::BAD_DISPLAY, error); +} + +} // namespace +} // namespace vts +} // namespace V2_4 +} // namespace composer +} // namespace graphics +} // namespace hardware +} // namespace android + +int main(int argc, char** argv) { + using android::hardware::graphics::composer::V2_4::vts::GraphicsComposerHidlEnvironment; + ::testing::AddGlobalTestEnvironment(GraphicsComposerHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + GraphicsComposerHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + return status; +}