From 228f46b5b9c3eac674aceb579a718cd459165f2e Mon Sep 17 00:00:00 2001 From: Marin Shalamanov Date: Thu, 28 Jan 2021 21:11:45 +0100 Subject: Introduce DynamicDisplayInfo In this CL we introduce the getDynamicDisplayInfo call on ISurfaceComposer which replaces the existing - getDisplayModes - getActiveDisplayMode - getColorModes - getActiveColorMode - getHdrCapabilities This way all display properties can be queried atomically. The current DisplayInfo class is moved to the androd::ui namespace and it's renamed to StaticDisplayInfo. ui::DisplayMode is now LightFlattenable and the mode ID is int32_t instead of size_t in order to prevent serialization problems. Additionally we add the ID field to ui::DisplayMode. This way we no longer need the supported display IDs to be from 0 to N-1. Bug: 159590486 Bug: 180539476 Test: presubmit, manually test that device boots Change-Id: I52b170913ce47cb5df2e8417e6cc95d395df1fda --- libs/ui/DynamicDisplayInfo.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 libs/ui/DynamicDisplayInfo.cpp (limited to 'libs/ui/DynamicDisplayInfo.cpp') diff --git a/libs/ui/DynamicDisplayInfo.cpp b/libs/ui/DynamicDisplayInfo.cpp new file mode 100644 index 0000000000..11acdae921 --- /dev/null +++ b/libs/ui/DynamicDisplayInfo.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 2021 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 + +#define RETURN_IF_ERROR(op) \ + if (const status_t status = (op); status != OK) return status; + +namespace android::ui { + +std::optional DynamicDisplayInfo::getActiveDisplayMode() const { + for (const auto& currMode : supportedDisplayModes) { + if (currMode.id == activeDisplayModeId) { + return currMode; + } + } + return {}; +} + +size_t DynamicDisplayInfo::getFlattenedSize() const { + return FlattenableHelpers::getFlattenedSize(supportedDisplayModes) + + FlattenableHelpers::getFlattenedSize(activeDisplayModeId) + + FlattenableHelpers::getFlattenedSize(supportedColorModes) + + FlattenableHelpers::getFlattenedSize(activeColorMode) + + FlattenableHelpers::getFlattenedSize(hdrCapabilities); +} + +status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { + if (size < getFlattenedSize()) { + return NO_MEMORY; + } + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedDisplayModes)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeDisplayModeId)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities)); + return OK; +} + +status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) { + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedDisplayModes)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeDisplayModeId)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities)); + return OK; +} + +} // namespace android::ui -- cgit v1.2.3-59-g8ed1b From b173f7599a8f93786342d27167facf7eae02845e Mon Sep 17 00:00:00 2001 From: Marin Shalamanov Date: Tue, 16 Feb 2021 19:38:36 +0100 Subject: SF: Move ALLM and GameContentType to DynamicDisplayInfo ALLM and Game content type support may change after a hotplug, for that reason we move them to DynamicDisplayInfo. Bug: 180108954 Test: flash a device and manually test that the values are properly piped to DisplayManager Change-Id: I05810c620b241e204d2c01618bb8a4069c41d32d --- libs/gui/ISurfaceComposer.cpp | 70 ---------------------------- libs/gui/SurfaceComposerClient.cpp | 12 ----- libs/gui/include/gui/ISurfaceComposer.h | 27 +++-------- libs/gui/include/gui/SurfaceComposerClient.h | 6 --- libs/gui/tests/Surface_test.cpp | 8 ---- libs/ui/DynamicDisplayInfo.cpp | 8 +++- libs/ui/include/ui/DynamicDisplayInfo.h | 8 ++++ services/surfaceflinger/SurfaceFlinger.cpp | 50 ++++---------------- services/surfaceflinger/SurfaceFlinger.h | 4 -- 9 files changed, 31 insertions(+), 162 deletions(-) (limited to 'libs/ui/DynamicDisplayInfo.cpp') diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 2e4f858a9d..eba7b3c9fd 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -411,24 +411,6 @@ public: return static_cast(reply.readInt32()); } - status_t getAutoLowLatencyModeSupport(const sp& display, - bool* outSupport) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result); - return result; - } - result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data, - &reply); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result); - return result; - } - return reply.readBool(outSupport); - } - void setAutoLowLatencyMode(const sp& display, bool on) override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -454,23 +436,6 @@ public: } } - status_t getGameContentTypeSupport(const sp& display, - bool* outSupport) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result); - return result; - } - result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to transact: %d", result); - return result; - } - return reply.readBool(outSupport); - } - void setGameContentType(const sp& display, bool on) override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -1423,23 +1388,6 @@ status_t BnSurfaceComposer::onTransact( result = reply->writeInt32(result); return result; } - - case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result); - return result; - } - bool supported = false; - result = getAutoLowLatencyModeSupport(display, &supported); - if (result == NO_ERROR) { - result = reply->writeBool(supported); - } - return result; - } - case SET_AUTO_LOW_LATENCY_MODE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp display = nullptr; @@ -1457,23 +1405,6 @@ status_t BnSurfaceComposer::onTransact( setAutoLowLatencyMode(display, setAllm); return result; } - - case GET_GAME_CONTENT_TYPE_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result); - return result; - } - bool supported = false; - result = getGameContentTypeSupport(display, &supported); - if (result == NO_ERROR) { - result = reply->writeBool(supported); - } - return result; - } - case SET_GAME_CONTENT_TYPE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp display = nullptr; @@ -1491,7 +1422,6 @@ status_t BnSurfaceComposer::onTransact( setGameContentType(display, setGameContentTypeOn); return result; } - case CLEAR_ANIMATION_FRAME_STATS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); status_t result = clearAnimationFrameStats(); diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 0bd2c8811b..f78c12e61e 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1876,22 +1876,10 @@ status_t SurfaceComposerClient::setActiveColorMode(const sp& display, return ComposerService::getComposerService()->setActiveColorMode(display, colorMode); } -bool SurfaceComposerClient::getAutoLowLatencyModeSupport(const sp& display) { - bool supported = false; - ComposerService::getComposerService()->getAutoLowLatencyModeSupport(display, &supported); - return supported; -} - void SurfaceComposerClient::setAutoLowLatencyMode(const sp& display, bool on) { ComposerService::getComposerService()->setAutoLowLatencyMode(display, on); } -bool SurfaceComposerClient::getGameContentTypeSupport(const sp& display) { - bool supported = false; - ComposerService::getComposerService()->getGameContentTypeSupport(display, &supported); - return supported; -} - void SurfaceComposerClient::setGameContentType(const sp& display, bool on) { ComposerService::getComposerService()->setGameContentType(display, on); } diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index d0ab4802e1..6289e5a5d0 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -218,33 +218,18 @@ public: virtual status_t setActiveColorMode(const sp& display, ui::ColorMode colorMode) = 0; - /** - * Returns true if the connected display reports support for HDMI 2.1 Auto - * Low Latency Mode. - * For more information, see the HDMI 2.1 specification. - */ - virtual status_t getAutoLowLatencyModeSupport(const sp& display, - bool* outSupport) const = 0; - /** * Switches Auto Low Latency Mode on/off on the connected display, if it is - * available. This should only be called if #getAutoLowLatencyMode returns - * true. + * available. This should only be called if the display supports Auto Low + * Latency Mode as reported in #getDynamicDisplayInfo. * For more information, see the HDMI 2.1 specification. */ virtual void setAutoLowLatencyMode(const sp& display, bool on) = 0; - /** - * Returns true if the connected display reports support for Game Content Type. - * For more information, see the HDMI 1.4 specification. - */ - virtual status_t getGameContentTypeSupport(const sp& display, - bool* outSupport) const = 0; - /** * This will start sending infoframes to the connected display with - * ContentType=Game (if on=true). This will switch the disply to Game mode. - * This should only be called if #getGameContentTypeSupport returns true. + * ContentType=Game (if on=true). This should only be called if the display + * Game Content Type as reported in #getDynamicDisplayInfo. * For more information, see the HDMI 1.4 specification. */ virtual void setGameContentType(const sp& display, bool on) = 0; @@ -563,9 +548,9 @@ public: CAPTURE_DISPLAY_BY_ID, NOTIFY_POWER_BOOST, SET_GLOBAL_SHADOW_SETTINGS, - GET_AUTO_LOW_LATENCY_MODE_SUPPORT, + GET_AUTO_LOW_LATENCY_MODE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. SET_AUTO_LOW_LATENCY_MODE, - GET_GAME_CONTENT_TYPE_SUPPORT, + GET_GAME_CONTENT_TYPE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. SET_GAME_CONTENT_TYPE, SET_FRAME_RATE, ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 2b72b73d96..2553d40136 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -139,17 +139,11 @@ public: static status_t setActiveColorMode(const sp& display, ui::ColorMode colorMode); - // Reports whether the connected display supports Auto Low Latency Mode - static bool getAutoLowLatencyModeSupport(const sp& display); - // Switches on/off Auto Low Latency Mode on the connected display. This should only be // called if the connected display supports Auto Low Latency Mode as reported by // #getAutoLowLatencyModeSupport static void setAutoLowLatencyMode(const sp& display, bool on); - // Reports whether the connected display supports Game content type - static bool getGameContentTypeSupport(const sp& display); - // Turns Game mode on/off on the connected display. This should only be called // if the display supports Game content type, as reported by #getGameContentTypeSupport static void setGameContentType(const sp& display, bool on); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 3397198fa0..69bb86649c 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -757,15 +757,7 @@ public: const sp& /* captureListener */) override { return NO_ERROR; } - status_t getAutoLowLatencyModeSupport(const sp& /*display*/, - bool* /*outSupport*/) const override { - return NO_ERROR; - } void setAutoLowLatencyMode(const sp& /*display*/, bool /*on*/) override {} - status_t getGameContentTypeSupport(const sp& /*display*/, - bool* /*outSupport*/) const override { - return NO_ERROR; - } void setGameContentType(const sp& /*display*/, bool /*on*/) override {} status_t captureDisplay(uint64_t /*displayOrLayerStack*/, const sp& /* captureListener */) override { diff --git a/libs/ui/DynamicDisplayInfo.cpp b/libs/ui/DynamicDisplayInfo.cpp index 11acdae921..d5c4ef0c17 100644 --- a/libs/ui/DynamicDisplayInfo.cpp +++ b/libs/ui/DynamicDisplayInfo.cpp @@ -39,7 +39,9 @@ size_t DynamicDisplayInfo::getFlattenedSize() const { FlattenableHelpers::getFlattenedSize(activeDisplayModeId) + FlattenableHelpers::getFlattenedSize(supportedColorModes) + FlattenableHelpers::getFlattenedSize(activeColorMode) + - FlattenableHelpers::getFlattenedSize(hdrCapabilities); + FlattenableHelpers::getFlattenedSize(hdrCapabilities) + + FlattenableHelpers::getFlattenedSize(autoLowLatencyModeSupported) + + FlattenableHelpers::getFlattenedSize(gameContentTypeSupported); } status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { @@ -51,6 +53,8 @@ status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes)); RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode)); RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, autoLowLatencyModeSupported)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, gameContentTypeSupported)); return OK; } @@ -60,6 +64,8 @@ status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) { RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes)); RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode)); RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &autoLowLatencyModeSupported)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &gameContentTypeSupported)); return OK; } diff --git a/libs/ui/include/ui/DynamicDisplayInfo.h b/libs/ui/include/ui/DynamicDisplayInfo.h index 6c349b749d..a4c2f71a4c 100644 --- a/libs/ui/include/ui/DynamicDisplayInfo.h +++ b/libs/ui/include/ui/DynamicDisplayInfo.h @@ -41,6 +41,14 @@ struct DynamicDisplayInfo : LightFlattenable { ui::ColorMode activeColorMode; HdrCapabilities hdrCapabilities; + // True if the display reports support for HDMI 2.1 Auto Low Latency Mode. + // For more information, see the HDMI 2.1 specification. + bool autoLowLatencyModeSupported; + + // True if the display reports support for Game Content Type. + // For more information, see the HDMI 1.4 specification. + bool gameContentTypeSupported; + std::optional getActiveDisplayMode() const; bool isFixedSize() const { return false; } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index ecf535835a..549c123cde 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -966,9 +966,18 @@ status_t SurfaceFlinger::getDynamicDisplayInfo(const sp& displayToken, } info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; - info->supportedColorModes = getDisplayColorModes(display->getPhysicalId()); + const auto displayId = display->getPhysicalId(); + info->supportedColorModes = getDisplayColorModes(displayId); info->hdrCapabilities = display->getHdrCapabilities(); + info->autoLowLatencyModeSupported = + getHwComposer().hasDisplayCapability(displayId, + hal::DisplayCapability::AUTO_LOW_LATENCY_MODE); + std::vector types; + getHwComposer().getSupportedContentTypes(displayId, &types); + info->gameContentTypeSupported = std::any_of(types.begin(), types.end(), [](auto type) { + return type == hal::ContentType::GAME; + }); return NO_ERROR; } @@ -1243,24 +1252,6 @@ status_t SurfaceFlinger::setActiveColorMode(const sp& displayToken, Col return NO_ERROR; } -status_t SurfaceFlinger::getAutoLowLatencyModeSupport(const sp& displayToken, - bool* outSupport) const { - if (!displayToken) { - return BAD_VALUE; - } - - Mutex::Autolock lock(mStateLock); - - const auto displayId = getPhysicalDisplayIdLocked(displayToken); - if (!displayId) { - return NAME_NOT_FOUND; - } - *outSupport = - getHwComposer().hasDisplayCapability(*displayId, - hal::DisplayCapability::AUTO_LOW_LATENCY_MODE); - return NO_ERROR; -} - void SurfaceFlinger::setAutoLowLatencyMode(const sp& displayToken, bool on) { static_cast(schedule([=]() MAIN_THREAD { if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { @@ -1271,27 +1262,6 @@ void SurfaceFlinger::setAutoLowLatencyMode(const sp& displayToken, bool })); } -status_t SurfaceFlinger::getGameContentTypeSupport(const sp& displayToken, - bool* outSupport) const { - if (!displayToken) { - return BAD_VALUE; - } - - Mutex::Autolock lock(mStateLock); - - const auto displayId = getPhysicalDisplayIdLocked(displayToken); - if (!displayId) { - return NAME_NOT_FOUND; - } - - std::vector types; - getHwComposer().getSupportedContentTypes(*displayId, &types); - - *outSupport = std::any_of(types.begin(), types.end(), - [](auto type) { return type == hal::ContentType::GAME; }); - return NO_ERROR; -} - void SurfaceFlinger::setGameContentType(const sp& displayToken, bool on) { static_cast(schedule([=]() MAIN_THREAD { if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 21cd2a5682..d9af7509a1 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -561,11 +561,7 @@ private: status_t getDisplayNativePrimaries(const sp& displayToken, ui::DisplayPrimaries&) override; status_t setActiveColorMode(const sp& displayToken, ui::ColorMode colorMode) override; - status_t getAutoLowLatencyModeSupport(const sp& displayToken, - bool* outSupported) const override; void setAutoLowLatencyMode(const sp& displayToken, bool on) override; - status_t getGameContentTypeSupport(const sp& displayToken, - bool* outSupported) const override; void setGameContentType(const sp& displayToken, bool on) override; void setPowerMode(const sp& displayToken, int mode) override; status_t clearAnimationFrameStats() override; -- cgit v1.2.3-59-g8ed1b