diff options
| author | 2021-01-15 15:06:38 +0000 | |
|---|---|---|
| committer | 2021-01-15 15:06:38 +0000 | |
| commit | 88ce0fa5e59d2b19ece38708672baebbc4a19bc0 (patch) | |
| tree | 9f656b0551419932c485e1a98a7872152d956eea | |
| parent | 2416f131f6102f9c60ddbe73f8d43f9f75da1c13 (diff) | |
| parent | 3ea1d605f2edca071ed7c3bbc6de2c7fbbe55e5e (diff) | |
Merge changes I8cb45020,I8787dcca
* changes:
SF: Remove display config functions from HWC2
SF: Clean up Scheduler::registerLayer
24 files changed, 392 insertions, 683 deletions
diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index e64a9f1855..d0ba8fefbd 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -87,20 +87,17 @@ public: MOCK_METHOD2(setVsyncEnabled, void(PhysicalDisplayId, hal::Vsync)); MOCK_CONST_METHOD1(getRefreshTimestamp, nsecs_t(PhysicalDisplayId)); MOCK_CONST_METHOD1(isConnected, bool(PhysicalDisplayId)); - MOCK_CONST_METHOD1( - getConfigs, - std::vector<std::shared_ptr<const HWC2::Display::Config>>(PhysicalDisplayId)); - MOCK_CONST_METHOD1(getActiveConfig, - std::shared_ptr<const HWC2::Display::Config>(PhysicalDisplayId)); - MOCK_CONST_METHOD1(getActiveConfigIndex, int(PhysicalDisplayId)); + MOCK_CONST_METHOD1(getModes, DisplayModes(PhysicalDisplayId)); + MOCK_CONST_METHOD1(getActiveMode, DisplayModePtr(PhysicalDisplayId)); MOCK_CONST_METHOD1(getColorModes, std::vector<ui::ColorMode>(PhysicalDisplayId)); MOCK_METHOD3(setActiveColorMode, status_t(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent)); MOCK_CONST_METHOD0(isUsingVrComposer, bool()); MOCK_CONST_METHOD1(getDisplayConnectionType, DisplayConnectionType(PhysicalDisplayId)); MOCK_CONST_METHOD1(isVsyncPeriodSwitchSupported, bool(PhysicalDisplayId)); MOCK_CONST_METHOD1(getDisplayVsyncPeriod, nsecs_t(PhysicalDisplayId)); - MOCK_METHOD4(setActiveConfigWithConstraints, - status_t(PhysicalDisplayId, size_t, const hal::VsyncPeriodChangeConstraints&, + MOCK_METHOD4(setActiveModeWithConstraints, + status_t(PhysicalDisplayId, HwcConfigIndexType, + const hal::VsyncPeriodChangeConstraints&, hal::VsyncPeriodChangeTimeline*)); MOCK_METHOD2(setAutoLowLatencyMode, status_t(PhysicalDisplayId, bool)); MOCK_METHOD2(getSupportedContentTypes, diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index cbc201fabc..8551365a3b 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -210,7 +210,7 @@ void DisplayDevice::dump(std::string& result) const { result.append(" "); StringAppendF(&result, "powerMode=%s (%d), ", to_string(mPowerMode).c_str(), static_cast<int32_t>(mPowerMode)); - StringAppendF(&result, "activeConfig=%d, ", mActiveConfig.value()); + StringAppendF(&result, "activeConfig=%zu, ", mActiveConfig.value()); StringAppendF(&result, "deviceProductInfo="); if (mDeviceProductInfo) { mDeviceProductInfo->dump(result); diff --git a/services/surfaceflinger/DisplayHardware/DisplayMode.h b/services/surfaceflinger/DisplayHardware/DisplayMode.h new file mode 100644 index 0000000000..69fd00e3a4 --- /dev/null +++ b/services/surfaceflinger/DisplayHardware/DisplayMode.h @@ -0,0 +1,131 @@ +/* + * Copyright 2020 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 "DisplayHardware/Hal.h" +#include "Scheduler/HwcStrongTypes.h" + +#include <android/configuration.h> +#include <utils/Timers.h> + +#include <memory> +#include <vector> + +namespace android { + +namespace hal = android::hardware::graphics::composer::hal; + +class DisplayMode; +using DisplayModePtr = std::shared_ptr<const DisplayMode>; +using DisplayModes = std::vector<DisplayModePtr>; + +class DisplayMode { +public: + class Builder { + public: + explicit Builder(hal::HWConfigId id) : mDisplayMode(new DisplayMode(id)) {} + + DisplayModePtr build() { + return std::const_pointer_cast<const DisplayMode>(std::move(mDisplayMode)); + } + + Builder& setId(HwcConfigIndexType id) { + mDisplayMode->mId = id; + return *this; + } + + Builder& setWidth(int32_t width) { + mDisplayMode->mWidth = width; + return *this; + } + + Builder& setHeight(int32_t height) { + mDisplayMode->mHeight = height; + return *this; + } + + Builder& setVsyncPeriod(int32_t vsyncPeriod) { + mDisplayMode->mVsyncPeriod = vsyncPeriod; + return *this; + } + + Builder& setDpiX(int32_t dpiX) { + if (dpiX == -1) { + mDisplayMode->mDpiX = getDefaultDensity(); + } else { + mDisplayMode->mDpiX = dpiX / 1000.0f; + } + return *this; + } + + Builder& setDpiY(int32_t dpiY) { + if (dpiY == -1) { + mDisplayMode->mDpiY = getDefaultDensity(); + } else { + mDisplayMode->mDpiY = dpiY / 1000.0f; + } + return *this; + } + + Builder& setConfigGroup(int32_t configGroup) { + mDisplayMode->mConfigGroup = configGroup; + return *this; + } + + private: + float getDefaultDensity() { + // Default density is based on TVs: 1080p displays get XHIGH density, lower- + // resolution displays get TV density. Maybe eventually we'll need to update + // it for 4k displays, though hopefully those will just report accurate DPI + // information to begin with. This is also used for virtual displays and + // older HWC implementations, so be careful about orientation. + + auto longDimension = std::max(mDisplayMode->mWidth, mDisplayMode->mHeight); + if (longDimension >= 1080) { + return ACONFIGURATION_DENSITY_XHIGH; + } else { + return ACONFIGURATION_DENSITY_TV; + } + } + std::shared_ptr<DisplayMode> mDisplayMode; + }; + + HwcConfigIndexType getId() const { return mId; } + hal::HWConfigId getHwcId() const { return mHwcId; } + + int32_t getWidth() const { return mWidth; } + int32_t getHeight() const { return mHeight; } + nsecs_t getVsyncPeriod() const { return mVsyncPeriod; } + float getDpiX() const { return mDpiX; } + float getDpiY() const { return mDpiY; } + int32_t getConfigGroup() const { return mConfigGroup; } + +private: + explicit DisplayMode(hal::HWConfigId id) : mHwcId(id) {} + + hal::HWConfigId mHwcId; + HwcConfigIndexType mId; + + int32_t mWidth = -1; + int32_t mHeight = -1; + nsecs_t mVsyncPeriod = -1; + float mDpiX = -1; + float mDpiY = -1; + int32_t mConfigGroup = -1; +}; + +} // namespace android
\ No newline at end of file diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp index 14b54cd6ae..3e856bbbb1 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp @@ -77,9 +77,8 @@ FramebufferSurface::FramebufferSurface(HWComposer& hwc, PhysicalDisplayId displa mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER); - const auto& activeConfig = mHwc.getActiveConfig(displayId); - ui::Size limitedSize = - limitFramebufferSize(activeConfig->getWidth(), activeConfig->getHeight()); + const auto& activeMode = mHwc.getActiveMode(displayId); + ui::Size limitedSize = limitFramebufferSize(activeMode->getWidth(), activeMode->getHeight()); mConsumer->setDefaultBufferSize(limitedSize.width, limitedSize.height); mConsumer->setMaxAcquiredBufferCount( SurfaceFlinger::maxFrameBufferAcquiredBuffers - 1); diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp index 426092dc11..71a3276d1b 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp @@ -68,33 +68,6 @@ inline bool hasMetadataKey(const std::set<Hwc2::PerFrameMetadataKey>& keys, // Display methods Display::~Display() = default; -Display::Config::Config(Display& display, HWConfigId id) - : mDisplay(display), - mId(id), - mWidth(-1), - mHeight(-1), - mVsyncPeriod(-1), - mDpiX(-1), - mDpiY(-1) {} - -Display::Config::Builder::Builder(Display& display, HWConfigId id) - : mConfig(new Config(display, id)) {} - -float Display::Config::Builder::getDefaultDensity() { - // Default density is based on TVs: 1080p displays get XHIGH density, lower- - // resolution displays get TV density. Maybe eventually we'll need to update - // it for 4k displays, though hopefully those will just report accurate DPI - // information to begin with. This is also used for virtual displays and - // older HWC implementations, so be careful about orientation. - - auto longDimension = std::max(mConfig->mWidth, mConfig->mHeight); - if (longDimension >= 1080) { - return ACONFIGURATION_DENSITY_XHIGH; - } else { - return ACONFIGURATION_DENSITY_TV; - } -} - namespace impl { Display::Display(android::Hwc2::Composer& composer, @@ -162,93 +135,12 @@ Error Display::destroyLayer(HWC2::Layer* layer) { return Error::NONE; } -Error Display::getActiveConfig( - std::shared_ptr<const Display::Config>* outConfig) const -{ - ALOGV("[%" PRIu64 "] getActiveConfig", mId); - HWConfigId configId = 0; - auto intError = mComposer.getActiveConfig(mId, &configId); - auto error = static_cast<Error>(intError); - - if (error != Error::NONE) { - ALOGE("Unable to get active config for mId:[%" PRIu64 "]", mId); - *outConfig = nullptr; - return error; - } - - if (mConfigs.count(configId) != 0) { - *outConfig = mConfigs.at(configId); - } else { - ALOGE("[%" PRIu64 "] getActiveConfig returned unknown config %u", mId, - configId); - // Return no error, but the caller needs to check for a null pointer to - // detect this case - *outConfig = nullptr; - } - - return Error::NONE; -} - bool Display::isVsyncPeriodSwitchSupported() const { ALOGV("[%" PRIu64 "] isVsyncPeriodSwitchSupported()", mId); return mComposer.isVsyncPeriodSwitchSupported(); } -Error Display::getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const { - ALOGV("[%" PRIu64 "] getDisplayVsyncPeriod", mId); - - Error error; - - if (isVsyncPeriodSwitchSupported()) { - Hwc2::VsyncPeriodNanos vsyncPeriodNanos = 0; - auto intError = mComposer.getDisplayVsyncPeriod(mId, &vsyncPeriodNanos); - error = static_cast<Error>(intError); - *outVsyncPeriod = static_cast<nsecs_t>(vsyncPeriodNanos); - } else { - // Get the default vsync period - std::shared_ptr<const Display::Config> config; - error = getActiveConfig(&config); - if (error != Error::NONE) { - return error; - } - if (!config) { - // HWC has updated the display modes and hasn't notified us yet. - return Error::BAD_CONFIG; - } - - *outVsyncPeriod = config->getVsyncPeriod(); - } - - return error; -} - -Error Display::getActiveConfigIndex(int* outIndex) const { - ALOGV("[%" PRIu64 "] getActiveConfigIndex", mId); - HWConfigId configId = 0; - auto intError = mComposer.getActiveConfig(mId, &configId); - auto error = static_cast<Error>(intError); - - if (error != Error::NONE) { - ALOGE("Unable to get active config for mId:[%" PRIu64 "]", mId); - *outIndex = -1; - return error; - } - - auto pos = mConfigs.find(configId); - if (pos != mConfigs.end()) { - *outIndex = std::distance(mConfigs.begin(), pos); - ALOGV("[%" PRIu64 "] index = %d", mId, *outIndex); - } else { - ALOGE("[%" PRIu64 "] getActiveConfig returned unknown config %u", mId, configId); - // Return no error, but the caller needs to check for a negative index - // to detect this case - *outIndex = -1; - } - - return Error::NONE; -} - Error Display::getChangedCompositionTypes(std::unordered_map<HWC2::Layer*, Composition>* outTypes) { std::vector<Hwc2::Layer> layerIds; std::vector<Hwc2::IComposerClient::Composition> types; @@ -335,15 +227,6 @@ Error Display::getDataspaceSaturationMatrix(Dataspace dataspace, android::mat4* return static_cast<Error>(intError); } -std::vector<std::shared_ptr<const Display::Config>> Display::getConfigs() const -{ - std::vector<std::shared_ptr<const Config>> configs; - for (const auto& element : mConfigs) { - configs.emplace_back(element.second); - } - return configs; -} - Error Display::getName(std::string* outName) const { auto intError = mComposer.getDisplayName(mId, outName); @@ -486,16 +369,10 @@ Error Display::present(sp<Fence>* outPresentFence) return Error::NONE; } -Error Display::setActiveConfigWithConstraints( - const std::shared_ptr<const HWC2::Display::Config>& config, - const VsyncPeriodChangeConstraints& constraints, VsyncPeriodChangeTimeline* outTimeline) { +Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId, + const VsyncPeriodChangeConstraints& constraints, + VsyncPeriodChangeTimeline* outTimeline) { ALOGV("[%" PRIu64 "] setActiveConfigWithConstraints", mId); - if (config->getDisplayId() != mId) { - ALOGE("setActiveConfigWithConstraints received config %u for the wrong display %" PRIu64 - " (expected %" PRIu64 ")", - config->getId(), config->getDisplayId(), mId); - return Error::BAD_CONFIG; - } if (isVsyncPeriodSwitchSupported()) { Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints; @@ -503,9 +380,8 @@ Error Display::setActiveConfigWithConstraints( hwc2Constraints.seamlessRequired = constraints.seamlessRequired; Hwc2::VsyncPeriodChangeTimeline vsyncPeriodChangeTimeline = {}; - auto intError = - mComposer.setActiveConfigWithConstraints(mId, config->getId(), hwc2Constraints, - &vsyncPeriodChangeTimeline); + auto intError = mComposer.setActiveConfigWithConstraints(mId, configId, hwc2Constraints, + &vsyncPeriodChangeTimeline); outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeTimeline.newVsyncAppliedTimeNanos; outTimeline->refreshRequired = vsyncPeriodChangeTimeline.refreshRequired; outTimeline->refreshTimeNanos = vsyncPeriodChangeTimeline.refreshTimeNanos; @@ -519,25 +395,13 @@ Error Display::setActiveConfigWithConstraints( ALOGE("setActiveConfigWithConstraints received constraints that can't be satisfied"); } - auto intError_2_4 = mComposer.setActiveConfig(mId, config->getId()); + auto intError_2_4 = mComposer.setActiveConfig(mId, configId); outTimeline->newVsyncAppliedTimeNanos = std::max(now, constraints.desiredTimeNanos); outTimeline->refreshRequired = true; outTimeline->refreshTimeNanos = now; return static_cast<Error>(intError_2_4); } -Error Display::setActiveConfig(const std::shared_ptr<const Config>& config) -{ - if (config->getDisplayId() != mId) { - ALOGE("setActiveConfig received config %u for the wrong display %" - PRIu64 " (expected %" PRIu64 ")", config->getId(), - config->getDisplayId(), mId); - return Error::BAD_CONFIG; - } - auto intError = mComposer.setActiveConfig(mId, config->getId()); - return static_cast<Error>(intError); -} - Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, const sp<Fence>& acquireFence, Dataspace dataspace) { @@ -681,58 +545,10 @@ Error Display::getClientTargetProperty(ClientTargetProperty* outClientTargetProp void Display::setConnected(bool connected) { if (!mIsConnected && connected) { mComposer.setClientTargetSlotCount(mId); - if (mType == DisplayType::PHYSICAL) { - loadConfigs(); - } } mIsConnected = connected; } -int32_t Display::getAttribute(HWConfigId configId, Attribute attribute) { - int32_t value = 0; - auto intError = mComposer.getDisplayAttribute(mId, configId, attribute, &value); - auto error = static_cast<Error>(intError); - if (error != Error::NONE) { - ALOGE("getDisplayAttribute(%" PRIu64 ", %u, %s) failed: %s (%d)", mId, - configId, to_string(attribute).c_str(), - to_string(error).c_str(), intError); - return -1; - } - return value; -} - -void Display::loadConfig(HWConfigId configId) { - ALOGV("[%" PRIu64 "] loadConfig(%u)", mId, configId); - - auto config = Config::Builder(*this, configId) - .setWidth(getAttribute(configId, hal::Attribute::WIDTH)) - .setHeight(getAttribute(configId, hal::Attribute::HEIGHT)) - .setVsyncPeriod(getAttribute(configId, hal::Attribute::VSYNC_PERIOD)) - .setDpiX(getAttribute(configId, hal::Attribute::DPI_X)) - .setDpiY(getAttribute(configId, hal::Attribute::DPI_Y)) - .setConfigGroup(getAttribute(configId, hal::Attribute::CONFIG_GROUP)) - .build(); - mConfigs.emplace(configId, std::move(config)); -} - -void Display::loadConfigs() -{ - ALOGV("[%" PRIu64 "] loadConfigs", mId); - - std::vector<HWConfigId> configIds; - auto intError = mComposer.getDisplayConfigs(mId, &configIds); - auto error = static_cast<Error>(intError); - if (error != Error::NONE) { - ALOGE("[%" PRIu64 "] getDisplayConfigs [2] failed: %s (%d)", mId, - to_string(error).c_str(), intError); - return; - } - - for (auto configId : configIds) { - loadConfig(configId); - } -} - // Other Display methods HWC2::Layer* Display::getLayerById(HWLayerId id) const { diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index 89df84b580..4c7f28412d 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -79,80 +79,6 @@ class Display { public: virtual ~Display(); - class Config { - public: - class Builder - { - public: - Builder(Display& display, hal::HWConfigId id); - - std::shared_ptr<const Config> build() { - return std::const_pointer_cast<const Config>( - std::move(mConfig)); - } - - Builder& setWidth(int32_t width) { - mConfig->mWidth = width; - return *this; - } - Builder& setHeight(int32_t height) { - mConfig->mHeight = height; - return *this; - } - Builder& setVsyncPeriod(int32_t vsyncPeriod) { - mConfig->mVsyncPeriod = vsyncPeriod; - return *this; - } - Builder& setDpiX(int32_t dpiX) { - if (dpiX == -1) { - mConfig->mDpiX = getDefaultDensity(); - } else { - mConfig->mDpiX = dpiX / 1000.0f; - } - return *this; - } - Builder& setDpiY(int32_t dpiY) { - if (dpiY == -1) { - mConfig->mDpiY = getDefaultDensity(); - } else { - mConfig->mDpiY = dpiY / 1000.0f; - } - return *this; - } - Builder& setConfigGroup(int32_t configGroup) { - mConfig->mConfigGroup = configGroup; - return *this; - } - - private: - float getDefaultDensity(); - std::shared_ptr<Config> mConfig; - }; - - hal::HWDisplayId getDisplayId() const { return mDisplay.getId(); } - hal::HWConfigId getId() const { return mId; } - - int32_t getWidth() const { return mWidth; } - int32_t getHeight() const { return mHeight; } - nsecs_t getVsyncPeriod() const { return mVsyncPeriod; } - float getDpiX() const { return mDpiX; } - float getDpiY() const { return mDpiY; } - int32_t getConfigGroup() const { return mConfigGroup; } - - private: - Config(Display& display, hal::HWConfigId id); - - Display& mDisplay; - hal::HWConfigId mId; - - int32_t mWidth; - int32_t mHeight; - nsecs_t mVsyncPeriod; - float mDpiX; - float mDpiY; - int32_t mConfigGroup; - }; - virtual hal::HWDisplayId getId() const = 0; virtual bool isConnected() const = 0; virtual void setConnected(bool connected) = 0; // For use by Device only @@ -162,9 +88,6 @@ public: [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0; [[clang::warn_unused_result]] virtual hal::Error createLayer(Layer** outLayer) = 0; [[clang::warn_unused_result]] virtual hal::Error destroyLayer(Layer* layer) = 0; - [[clang::warn_unused_result]] virtual hal::Error getActiveConfig( - std::shared_ptr<const Config>* outConfig) const = 0; - [[clang::warn_unused_result]] virtual hal::Error getActiveConfigIndex(int* outIndex) const = 0; [[clang::warn_unused_result]] virtual hal::Error getChangedCompositionTypes( std::unordered_map<Layer*, hal::Composition>* outTypes) = 0; [[clang::warn_unused_result]] virtual hal::Error getColorModes( @@ -176,10 +99,6 @@ public: [[clang::warn_unused_result]] virtual hal::Error getDataspaceSaturationMatrix( hal::Dataspace dataspace, android::mat4* outMatrix) = 0; - // Doesn't call into the HWC2 device, so no errors are possible - [[clang::warn_unused_result]] virtual std::vector<std::shared_ptr<const Config>> getConfigs() - const = 0; - [[clang::warn_unused_result]] virtual hal::Error getName(std::string* outName) const = 0; [[clang::warn_unused_result]] virtual hal::Error getRequests( hal::DisplayRequest* outDisplayRequests, @@ -201,8 +120,6 @@ public: std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const = 0; [[clang::warn_unused_result]] virtual hal::Error present( android::sp<android::Fence>* outPresentFence) = 0; - [[clang::warn_unused_result]] virtual hal::Error setActiveConfig( - const std::shared_ptr<const Config>& config) = 0; [[clang::warn_unused_result]] virtual hal::Error setClientTarget( uint32_t slot, const android::sp<android::GraphicBuffer>& target, const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) = 0; @@ -222,11 +139,8 @@ public: android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0; [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness( float brightness) = 0; - [[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod( - nsecs_t* outVsyncPeriod) const = 0; [[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints( - const std::shared_ptr<const HWC2::Display::Config>& config, - const hal::VsyncPeriodChangeConstraints& constraints, + hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints, hal::VsyncPeriodChangeTimeline* outTimeline) = 0; [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0; [[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes( @@ -248,8 +162,6 @@ public: hal::Error acceptChanges() override; hal::Error createLayer(Layer** outLayer) override; hal::Error destroyLayer(Layer*) override; - hal::Error getActiveConfig(std::shared_ptr<const Config>* outConfig) const override; - hal::Error getActiveConfigIndex(int* outIndex) const override; hal::Error getChangedCompositionTypes( std::unordered_map<Layer*, hal::Composition>* outTypes) override; hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override; @@ -259,9 +171,6 @@ public: std::vector<hal::RenderIntent>* outRenderIntents) const override; hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override; - // Doesn't call into the HWC2 device, so no errors are possible - std::vector<std::shared_ptr<const Config>> getConfigs() const override; - hal::Error getName(std::string* outName) const override; hal::Error getRequests( hal::DisplayRequest* outDisplayRequests, @@ -279,7 +188,6 @@ public: hal::Error getReleaseFences( std::unordered_map<Layer*, android::sp<android::Fence>>* outFences) const override; hal::Error present(android::sp<android::Fence>* outPresentFence) override; - hal::Error setActiveConfig(const std::shared_ptr<const HWC2::Display::Config>& config) override; hal::Error setClientTarget(uint32_t slot, const android::sp<android::GraphicBuffer>& target, const android::sp<android::Fence>& acquireFence, hal::Dataspace dataspace) override; @@ -294,11 +202,9 @@ public: android::sp<android::Fence>* outPresentFence, uint32_t* state) override; std::future<hal::Error> setDisplayBrightness(float brightness) override; - hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override; - hal::Error setActiveConfigWithConstraints( - const std::shared_ptr<const HWC2::Display::Config>& config, - const hal::VsyncPeriodChangeConstraints& constraints, - hal::VsyncPeriodChangeTimeline* outTimeline) override; + hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId, + const hal::VsyncPeriodChangeConstraints& constraints, + hal::VsyncPeriodChangeTimeline* outTimeline) override; hal::Error setAutoLowLatencyMode(bool on) override; hal::Error getSupportedContentTypes( std::vector<hal::ContentType>* outSupportedContentTypes) const override; @@ -315,9 +221,6 @@ public: virtual bool isVsyncPeriodSwitchSupported() const override; private: - int32_t getAttribute(hal::HWConfigId, hal::Attribute); - void loadConfig(hal::HWConfigId); - void loadConfigs(); // This may fail (and return a null pointer) if no layer with this ID exists // on this display @@ -338,7 +241,6 @@ private: bool mIsConnected = false; std::unordered_map<hal::HWLayerId, std::unique_ptr<Layer>> mLayers; - std::unordered_map<hal::HWConfigId, std::shared_ptr<const Config>> mConfigs; std::once_flag mDisplayCapabilityQueryFlag; std::unordered_set<hal::DisplayCapability> mDisplayCapabilities; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 6f3987f88f..ca679354f9 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -281,6 +281,8 @@ std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, PhysicalDisplayId displayId) { + mPhysicalDisplayIdMap[hwcDisplayId] = displayId; + if (!mInternalHwcDisplayId) { mInternalHwcDisplayId = hwcDisplayId; } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) { @@ -293,8 +295,41 @@ void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, hal::DisplayType::PHYSICAL); newDisplay->setConnected(true); displayData.hwcDisplay = std::move(newDisplay); - displayData.configs = displayData.hwcDisplay->getConfigs(); - mPhysicalDisplayIdMap[hwcDisplayId] = displayId; + loadModes(displayData, hwcDisplayId); +} + +int32_t HWComposer::getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId, + hal::Attribute attribute) { + int32_t value = 0; + auto error = static_cast<hal::Error>( + mComposer->getDisplayAttribute(hwcDisplayId, configId, attribute, &value)); + + RETURN_IF_HWC_ERROR_FOR("getDisplayAttribute", error, *toPhysicalDisplayId(hwcDisplayId), -1); + return value; +} + +void HWComposer::loadModes(DisplayData& displayData, hal::HWDisplayId hwcDisplayId) { + ALOGV("[HWC display %" PRIu64 "] %s", hwcDisplayId, __FUNCTION__); + + std::vector<hal::HWConfigId> configIds; + auto error = static_cast<hal::Error>(mComposer->getDisplayConfigs(hwcDisplayId, &configIds)); + RETURN_IF_HWC_ERROR_FOR("getDisplayConfigs", error, *toPhysicalDisplayId(hwcDisplayId)); + + displayData.modes.clear(); + for (auto configId : configIds) { + auto mode = DisplayMode::Builder(configId) + .setId(HwcConfigIndexType(displayData.modes.size())) + .setWidth(getAttribute(hwcDisplayId, configId, hal::Attribute::WIDTH)) + .setHeight(getAttribute(hwcDisplayId, configId, hal::Attribute::HEIGHT)) + .setVsyncPeriod(getAttribute(hwcDisplayId, configId, + hal::Attribute::VSYNC_PERIOD)) + .setDpiX(getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_X)) + .setDpiY(getAttribute(hwcDisplayId, configId, hal::Attribute::DPI_Y)) + .setConfigGroup(getAttribute(hwcDisplayId, configId, + hal::Attribute::CONFIG_GROUP)) + .build(); + displayData.modes.push_back(std::move(mode)); + } } HWC2::Layer* HWComposer::createLayer(HalDisplayId displayId) { @@ -330,34 +365,38 @@ bool HWComposer::isConnected(PhysicalDisplayId displayId) const { return mDisplayData.at(displayId).hwcDisplay->isConnected(); } -std::vector<std::shared_ptr<const HWC2::Display::Config>> HWComposer::getConfigs( - PhysicalDisplayId displayId) const { +DisplayModes HWComposer::getModes(PhysicalDisplayId displayId) const { RETURN_IF_INVALID_DISPLAY(displayId, {}); - // We cache the configs when the DisplayData is created on hotplug. If the configs need to + // We cache the modes when the DisplayData is created on hotplug. If the modes need to // change HWC will send a hotplug event which will recreate displayData. - return mDisplayData.at(displayId).configs; + return mDisplayData.at(displayId).modes; } -std::shared_ptr<const HWC2::Display::Config> HWComposer::getActiveConfig( - PhysicalDisplayId displayId) const { +DisplayModePtr HWComposer::getActiveMode(PhysicalDisplayId displayId) const { RETURN_IF_INVALID_DISPLAY(displayId, nullptr); - std::shared_ptr<const HWC2::Display::Config> config; - auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfig(&config); + const auto hwcId = *fromPhysicalDisplayId(displayId); + ALOGV("[%" PRIu64 "] getActiveMode", hwcId); + hal::HWConfigId configId; + auto error = static_cast<hal::Error>(mComposer->getActiveConfig(hwcId, &configId)); + + const auto& modes = mDisplayData.at(displayId).modes; if (error == hal::Error::BAD_CONFIG) { - LOG_DISPLAY_ERROR(displayId, "No active config"); + LOG_DISPLAY_ERROR(displayId, "No active mode"); return nullptr; } RETURN_IF_HWC_ERROR(error, displayId, nullptr); - if (!config) { - LOG_DISPLAY_ERROR(displayId, "Unknown config"); + const auto it = std::find_if(modes.begin(), modes.end(), + [configId](auto mode) { return mode->getHwcId() == configId; }); + if (it == modes.end()) { + LOG_DISPLAY_ERROR(displayId, "Unknown mode"); return nullptr; } - return config; + return *it; } // Composer 2.4 @@ -385,30 +424,24 @@ bool HWComposer::isVsyncPeriodSwitchSupported(PhysicalDisplayId displayId) const nsecs_t HWComposer::getDisplayVsyncPeriod(PhysicalDisplayId displayId) const { RETURN_IF_INVALID_DISPLAY(displayId, 0); - nsecs_t vsyncPeriodNanos; - auto error = mDisplayData.at(displayId).hwcDisplay->getDisplayVsyncPeriod(&vsyncPeriodNanos); - RETURN_IF_HWC_ERROR(error, displayId, 0); - return vsyncPeriodNanos; -} - -int HWComposer::getActiveConfigIndex(PhysicalDisplayId displayId) const { - RETURN_IF_INVALID_DISPLAY(displayId, -1); - - int index; - auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfigIndex(&index); - if (error == hal::Error::BAD_CONFIG) { - LOG_DISPLAY_ERROR(displayId, "No active config"); - return -1; + if (isVsyncPeriodSwitchSupported(displayId)) { + const auto hwcId = *fromPhysicalDisplayId(displayId); + Hwc2::VsyncPeriodNanos vsyncPeriodNanos = 0; + auto error = + static_cast<hal::Error>(mComposer->getDisplayVsyncPeriod(hwcId, &vsyncPeriodNanos)); + RETURN_IF_HWC_ERROR(error, displayId, 0); + return static_cast<nsecs_t>(vsyncPeriodNanos); } - RETURN_IF_HWC_ERROR(error, displayId, -1); + // Get the default vsync period + auto mode = getActiveMode(displayId); - if (index < 0) { - LOG_DISPLAY_ERROR(displayId, "Unknown config"); - return -1; + if (!mode) { + // HWC has updated the display modes and hasn't notified us yet. + RETURN_IF_HWC_ERROR(hal::Error::BAD_CONFIG, displayId, 0); } - return index; + return mode->getVsyncPeriod(); } std::vector<ui::ColorMode> HWComposer::getColorModes(PhysicalDisplayId displayId) const { @@ -640,21 +673,21 @@ status_t HWComposer::setPowerMode(PhysicalDisplayId displayId, hal::PowerMode mo return NO_ERROR; } -status_t HWComposer::setActiveConfigWithConstraints( - PhysicalDisplayId displayId, size_t configId, +status_t HWComposer::setActiveModeWithConstraints( + PhysicalDisplayId displayId, HwcConfigIndexType modeId, const hal::VsyncPeriodChangeConstraints& constraints, hal::VsyncPeriodChangeTimeline* outTimeline) { RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); auto& displayData = mDisplayData[displayId]; - if (configId >= displayData.configs.size()) { - LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str()); + if (modeId.value() >= displayData.modes.size()) { + LOG_DISPLAY_ERROR(displayId, ("Invalid mode " + std::to_string(modeId.value())).c_str()); return BAD_INDEX; } - auto error = - displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configs[configId], - constraints, outTimeline); + const auto hwcConfigId = displayData.modes[modeId.value()]->getHwcId(); + auto error = displayData.hwcDisplay->setActiveConfigWithConstraints(hwcConfigId, constraints, + outTimeline); RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); return NO_ERROR; } diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 7e1da252d3..2b3d2d4db6 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -41,6 +41,7 @@ #include "DisplayIdGenerator.h" #include "DisplayIdentification.h" +#include "DisplayMode.h" #include "HWC2.h" #include "Hal.h" @@ -184,12 +185,9 @@ public: virtual nsecs_t getRefreshTimestamp(PhysicalDisplayId) const = 0; virtual bool isConnected(PhysicalDisplayId) const = 0; - virtual std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( - PhysicalDisplayId) const = 0; + virtual DisplayModes getModes(PhysicalDisplayId) const = 0; - virtual std::shared_ptr<const HWC2::Display::Config> getActiveConfig( - PhysicalDisplayId) const = 0; - virtual int getActiveConfigIndex(PhysicalDisplayId) const = 0; + virtual DisplayModePtr getActiveMode(PhysicalDisplayId) const = 0; virtual std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const = 0; @@ -200,9 +198,9 @@ public: virtual DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const = 0; virtual bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const = 0; virtual nsecs_t getDisplayVsyncPeriod(PhysicalDisplayId) const = 0; - virtual status_t setActiveConfigWithConstraints( - PhysicalDisplayId, size_t configId, const hal::VsyncPeriodChangeConstraints&, - hal::VsyncPeriodChangeTimeline* outTimeline) = 0; + virtual status_t setActiveModeWithConstraints(PhysicalDisplayId, HwcConfigIndexType, + const hal::VsyncPeriodChangeConstraints&, + hal::VsyncPeriodChangeTimeline* outTimeline) = 0; virtual status_t setAutoLowLatencyMode(PhysicalDisplayId, bool on) = 0; virtual status_t getSupportedContentTypes( PhysicalDisplayId, std::vector<hal::ContentType>* outSupportedContentTypes) = 0; @@ -319,11 +317,9 @@ public: nsecs_t getRefreshTimestamp(PhysicalDisplayId) const override; bool isConnected(PhysicalDisplayId) const override; - std::vector<std::shared_ptr<const HWC2::Display::Config>> getConfigs( - PhysicalDisplayId) const override; + DisplayModes getModes(PhysicalDisplayId) const override; - std::shared_ptr<const HWC2::Display::Config> getActiveConfig(PhysicalDisplayId) const override; - int getActiveConfigIndex(PhysicalDisplayId) const override; + DisplayModePtr getActiveMode(PhysicalDisplayId) const override; std::vector<ui::ColorMode> getColorModes(PhysicalDisplayId) const override; @@ -332,10 +328,10 @@ public: // Composer 2.4 DisplayConnectionType getDisplayConnectionType(PhysicalDisplayId) const override; bool isVsyncPeriodSwitchSupported(PhysicalDisplayId) const override; - nsecs_t getDisplayVsyncPeriod(PhysicalDisplayId) const override; - status_t setActiveConfigWithConstraints(PhysicalDisplayId, size_t configId, - const hal::VsyncPeriodChangeConstraints&, - hal::VsyncPeriodChangeTimeline* outTimeline) override; + nsecs_t getDisplayVsyncPeriod(PhysicalDisplayId displayId) const override; + status_t setActiveModeWithConstraints(PhysicalDisplayId, HwcConfigIndexType, + const hal::VsyncPeriodChangeConstraints&, + hal::VsyncPeriodChangeTimeline* outTimeline) override; status_t setAutoLowLatencyMode(PhysicalDisplayId, bool) override; status_t getSupportedContentTypes(PhysicalDisplayId, std::vector<hal::ContentType>*) override; status_t setContentType(PhysicalDisplayId, hal::ContentType) override; @@ -362,14 +358,6 @@ private: // For unit tests friend TestableSurfaceFlinger; - std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId); - std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId); - bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const; - - void loadCapabilities(); - void loadLayerMetadataSupport(); - uint32_t getMaxVirtualDisplayCount() const; - struct DisplayData { bool isVirtual = false; std::unique_ptr<HWC2::Display> hwcDisplay; @@ -377,7 +365,7 @@ private: std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; buffer_handle_t outbufHandle = nullptr; sp<Fence> outbufAcquireFence = Fence::NO_FENCE; - std::vector<std::shared_ptr<const HWC2::Display::Config>> configs; + DisplayModes modes; bool validateWasSkipped; hal::Error presentError; @@ -391,6 +379,18 @@ private: nsecs_t lastHwVsync GUARDED_BY(lastHwVsyncLock) = 0; }; + std::optional<DisplayIdentificationInfo> onHotplugConnect(hal::HWDisplayId); + std::optional<DisplayIdentificationInfo> onHotplugDisconnect(hal::HWDisplayId); + bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const; + + int32_t getAttribute(hal::HWDisplayId hwcDisplayId, hal::HWConfigId configId, + hal::Attribute attribute); + void loadModes(DisplayData& displayData, hal::HWDisplayId hwcDisplayId); + + void loadCapabilities(); + void loadLayerMetadataSupport(); + uint32_t getMaxVirtualDisplayCount() const; + std::unordered_map<HalDisplayId, DisplayData> mDisplayData; std::unique_ptr<android::Hwc2::Composer> mComposer; diff --git a/services/surfaceflinger/Scheduler/HwcStrongTypes.h b/services/surfaceflinger/Scheduler/HwcStrongTypes.h index 8ba4f20b84..b6a33a28f8 100644 --- a/services/surfaceflinger/Scheduler/HwcStrongTypes.h +++ b/services/surfaceflinger/Scheduler/HwcStrongTypes.h @@ -18,9 +18,11 @@ #include "StrongTyping.h" +#include <cstddef> + namespace android { // Strong types for the different indexes as they are referring to a different base. -using HwcConfigIndexType = StrongTyping<int, struct HwcConfigIndexTypeTag, Compare, Add, Hash>; +using HwcConfigIndexType = StrongTyping<size_t, struct HwcConfigIndexTypeTag, Compare, Add, Hash>; } // namespace android
\ No newline at end of file diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp index 975754b064..b02596ac53 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp @@ -40,8 +40,7 @@ std::string formatLayerInfo(const RefreshRateConfigs::LayerRequirement& layer, f to_string(layer.desiredRefreshRate).c_str()); } -std::vector<Fps> constructKnownFrameRates( - const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) { +std::vector<Fps> constructKnownFrameRates(const DisplayModes& configs) { std::vector<Fps> knownFrameRates = {Fps(24.0f), Fps(30.0f), Fps(45.0f), Fps(60.0f), Fps(72.0f)}; knownFrameRates.reserve(knownFrameRates.size() + configs.size()); @@ -65,8 +64,8 @@ using AllRefreshRatesMapType = RefreshRateConfigs::AllRefreshRatesMapType; using RefreshRate = RefreshRateConfigs::RefreshRate; std::string RefreshRate::toString() const { - return base::StringPrintf("{id=%d, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}", - getConfigId().value(), hwcConfig->getId(), getFps().getValue(), + return base::StringPrintf("{id=%zu, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}", + getConfigId().value(), hwcConfig->getHwcId(), getFps().getValue(), hwcConfig->getWidth(), hwcConfig->getHeight(), getConfigGroup()); } @@ -88,7 +87,7 @@ std::string RefreshRateConfigs::layerVoteTypeString(LayerVoteType vote) { } std::string RefreshRateConfigs::Policy::toString() const { - return base::StringPrintf("default config ID: %d, allowGroupSwitching = %d" + return base::StringPrintf("default config ID: %zu, allowGroupSwitching = %d" ", primary range: %s, app request range: %s", defaultConfig.value(), allowGroupSwitching, primaryRange.toString().c_str(), appRequestRange.toString().c_str()); @@ -560,19 +559,16 @@ void RefreshRateConfigs::setCurrentConfigId(HwcConfigIndexType configId) { mCurrentRefreshRate = mRefreshRates.at(configId).get(); } -RefreshRateConfigs::RefreshRateConfigs( - const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, - HwcConfigIndexType currentConfigId) +RefreshRateConfigs::RefreshRateConfigs(const DisplayModes& configs, + HwcConfigIndexType currentConfigId) : mKnownFrameRates(constructKnownFrameRates(configs)) { updateDisplayConfigs(configs, currentConfigId); } -void RefreshRateConfigs::updateDisplayConfigs( - const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, - HwcConfigIndexType currentConfigId) { +void RefreshRateConfigs::updateDisplayConfigs(const DisplayModes& configs, + HwcConfigIndexType currentConfigId) { std::lock_guard lock(mLock); LOG_ALWAYS_FATAL_IF(configs.empty()); - LOG_ALWAYS_FATAL_IF(currentConfigId.value() < 0); LOG_ALWAYS_FATAL_IF(currentConfigId.value() >= configs.size()); mRefreshRates.clear(); @@ -684,7 +680,7 @@ void RefreshRateConfigs::getSortedRefreshRateListLocked( outRefreshRates->reserve(mRefreshRates.size()); for (const auto& [type, refreshRate] : mRefreshRates) { if (shouldAddRefreshRate(*refreshRate)) { - ALOGV("getSortedRefreshRateListLocked: config %d added to list policy", + ALOGV("getSortedRefreshRateListLocked: config %zu added to list policy", refreshRate->configId.value()); outRefreshRates->push_back(refreshRate.get()); } diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h index 4b99145184..a5d37c2c0e 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h @@ -24,6 +24,7 @@ #include <optional> #include <type_traits> +#include "DisplayHardware/DisplayMode.h" #include "DisplayHardware/HWComposer.h" #include "Fps.h" #include "HwcStrongTypes.h" @@ -64,8 +65,7 @@ public: }; public: - RefreshRate(HwcConfigIndexType configId, - std::shared_ptr<const HWC2::Display::Config> config, Fps fps, ConstructorTag) + RefreshRate(HwcConfigIndexType configId, DisplayModePtr config, Fps fps, ConstructorTag) : configId(configId), hwcConfig(config), fps(std::move(fps)) {} HwcConfigIndexType getConfigId() const { return configId; } @@ -101,7 +101,7 @@ public: // on the device. const HwcConfigIndexType configId; // The config itself - std::shared_ptr<const HWC2::Display::Config> hwcConfig; + DisplayModePtr hwcConfig; // Refresh rate in frames per second const Fps fps{0.0f}; }; @@ -296,12 +296,10 @@ public: // Returns a known frame rate that is the closest to frameRate Fps findClosestKnownFrameRate(Fps frameRate) const; - RefreshRateConfigs(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, - HwcConfigIndexType currentConfigId); + RefreshRateConfigs(const DisplayModes& configs, HwcConfigIndexType currentConfigId); - void updateDisplayConfigs( - const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs, - HwcConfigIndexType currentConfig) EXCLUDES(mLock); + void updateDisplayConfigs(const DisplayModes& configs, HwcConfigIndexType currentConfig) + EXCLUDES(mLock); // Returns whether switching configs (refresh rate or resolution) is possible. // TODO(b/158780872): Consider HAL support, and skip frame rate detection if the configs only diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index 49e3903eb2..92786fda0c 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -564,21 +564,23 @@ void Scheduler::setIgnorePresentFences(bool ignore) { void Scheduler::registerLayer(Layer* layer) { if (!mLayerHistory) return; + scheduler::LayerHistory::LayerVoteType voteType; + if (layer->getWindowType() == InputWindowInfo::Type::STATUS_BAR) { - mLayerHistory->registerLayer(layer, scheduler::LayerHistory::LayerVoteType::NoVote); + voteType = scheduler::LayerHistory::LayerVoteType::NoVote; } else if (!mOptions.useContentDetection) { // If the content detection feature is off, all layers are registered at Max. We still keep // the layer history, since we use it for other features (like Frame Rate API), so layers // still need to be registered. - mLayerHistory->registerLayer(layer, scheduler::LayerHistory::LayerVoteType::Max); + voteType = scheduler::LayerHistory::LayerVoteType::Max; + } else if (layer->getWindowType() == InputWindowInfo::Type::WALLPAPER) { + // Running Wallpaper at Min is considered as part of content detection. + voteType = scheduler::LayerHistory::LayerVoteType::Min; } else { - if (layer->getWindowType() == InputWindowInfo::Type::WALLPAPER) { - // Running Wallpaper at Min is considered as part of content detection. - mLayerHistory->registerLayer(layer, scheduler::LayerHistory::LayerVoteType::Min); - } else { - mLayerHistory->registerLayer(layer, scheduler::LayerHistory::LayerVoteType::Heuristic); - } + voteType = scheduler::LayerHistory::LayerVoteType::Heuristic; } + + mLayerHistory->registerLayer(layer, voteType); } void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime, diff --git a/services/surfaceflinger/Scheduler/StrongTyping.h b/services/surfaceflinger/Scheduler/StrongTyping.h index 6a60257c81..a05c123956 100644 --- a/services/surfaceflinger/Scheduler/StrongTyping.h +++ b/services/surfaceflinger/Scheduler/StrongTyping.h @@ -62,8 +62,8 @@ struct Hash : Ability<T, Hash> { template <typename T, typename W, template <typename> class... Ability> struct StrongTyping : Ability<StrongTyping<T, W, Ability...>>... { - StrongTyping() : mValue(0) {} - explicit StrongTyping(T const& value) : mValue(value) {} + constexpr StrongTyping() = default; + constexpr explicit StrongTyping(T const& value) : mValue(value) {} StrongTyping(StrongTyping const&) = default; StrongTyping& operator=(StrongTyping const&) = default; explicit inline operator T() const { return mValue; } @@ -75,7 +75,7 @@ struct StrongTyping : Ability<StrongTyping<T, W, Ability...>>... { } private: - T mValue; + T mValue{0}; }; } // namespace android diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 2e00ca8939..10bdf942a5 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -226,7 +226,7 @@ struct SCOPED_CAPABILITY UnnecessaryLock { ~UnnecessaryLock() RELEASE() {} }; -// TODO(b/141333600): Consolidate with HWC2::Display::Config::Builder::getDefaultDensity. +// TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; float getDensityFromProperty(const char* property, bool required) { @@ -904,14 +904,14 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, configs->clear(); - for (const auto& hwConfig : getHwComposer().getConfigs(*displayId)) { + for (const auto& mode : getHwComposer().getModes(*displayId)) { DisplayConfig config; - auto width = hwConfig->getWidth(); - auto height = hwConfig->getHeight(); + auto width = mode->getWidth(); + auto height = mode->getHeight(); - auto xDpi = hwConfig->getDpiX(); - auto yDpi = hwConfig->getDpiY(); + auto xDpi = mode->getDpiX(); + auto yDpi = mode->getDpiY(); if (isInternal && (internalDisplayOrientation == ui::ROTATION_90 || @@ -930,14 +930,14 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, config.yDpi = yDpi; } - const nsecs_t period = hwConfig->getVsyncPeriod(); + const nsecs_t period = mode->getVsyncPeriod(); config.refreshRate = Fps::fromPeriodNsecs(period).getValue(); const auto vsyncConfigSet = mVsyncConfiguration->getConfigsForRefreshRate(Fps(config.refreshRate)); config.appVsyncOffset = vsyncConfigSet.late.appOffset; config.sfVsyncOffset = vsyncConfigSet.late.sfOffset; - config.configGroup = hwConfig->getConfigGroup(); + config.configGroup = mode->getConfigGroup(); // This is how far in advance a buffer must be queued for // presentation at a given time. If you want a buffer to appear @@ -1128,7 +1128,7 @@ void SurfaceFlinger::performSetActiveConfig() { auto refreshRate = mRefreshRateConfigs->getRefreshRateFromConfigId(desiredActiveConfig->configId); - ALOGV("performSetActiveConfig changing active config to %d(%s)", + ALOGV("performSetActiveConfig changing active config to %zu(%s)", refreshRate.getConfigId().value(), refreshRate.getName().c_str()); const auto display = getDefaultDisplayDeviceLocked(); if (!display || display->getActiveConfig() == desiredActiveConfig->configId) { @@ -1158,13 +1158,12 @@ void SurfaceFlinger::performSetActiveConfig() { hal::VsyncPeriodChangeTimeline outTimeline; auto status = - getHwComposer().setActiveConfigWithConstraints(displayId, - mUpcomingActiveConfig.configId.value(), - constraints, &outTimeline); + getHwComposer().setActiveModeWithConstraints(displayId, mUpcomingActiveConfig.configId, + constraints, &outTimeline); if (status != NO_ERROR) { - // setActiveConfigWithConstraints may fail if a hotplug event is just about + // setActiveModeWithConstraints may fail if a hotplug event is just about // to be sent. We just log the error in this case. - ALOGW("setActiveConfigWithConstraints failed: %d", status); + ALOGW("setActiveModeWithConstraints failed: %d", status); return; } @@ -1618,7 +1617,7 @@ void SurfaceFlinger::changeRefreshRateLocked(const RefreshRate& refreshRate, // Don't do any updating if the current fps is the same as the new one. if (!isDisplayConfigAllowed(refreshRate.getConfigId())) { - ALOGV("Skipping config %d as it is not part of allowed configs", + ALOGV("Skipping config %zu as it is not part of allowed configs", refreshRate.getConfigId().value()); return; } @@ -1663,7 +1662,7 @@ void SurfaceFlinger::onVsyncPeriodTimingChangedReceived( } void SurfaceFlinger::onSeamlessPossible(int32_t /*sequenceId*/, hal::HWDisplayId /*display*/) { - // TODO(b/142753666): use constraints when calling to setActiveConfigWithConstrains and + // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. } @@ -2472,7 +2471,7 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( Dataspace::UNKNOWN}); if (!state.isVirtual()) { const auto physicalId = display->getPhysicalId(); - auto activeConfigId = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(physicalId)); + auto activeConfigId = getHwComposer().getActiveMode(physicalId)->getId(); display->setActiveConfig(activeConfigId); display->setDeviceProductInfo(state.physical->deviceProductInfo); } @@ -2492,7 +2491,7 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); if (state.physical) { const auto& activeConfig = - getCompositionEngine().getHwComposer().getActiveConfig(state.physical->id); + getCompositionEngine().getHwComposer().getActiveMode(state.physical->id); width = activeConfig->getWidth(); height = activeConfig->getHeight(); pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); @@ -2619,9 +2618,9 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, // TODO(b/175678251) Call a listener instead. if (currentState.physical->hwcDisplayId == getHwComposer().getInternalHwcDisplayId()) { const auto displayId = currentState.physical->id; - const auto configs = getHwComposer().getConfigs(displayId); - const auto currentConfig = - HwcConfigIndexType(getHwComposer().getActiveConfigIndex(displayId)); + const auto configs = getHwComposer().getModes(displayId); + const auto currentConfig = getHwComposer().getActiveMode(displayId)->getId(); + // TODO(b/175678215) Handle the case when currentConfig is not in configs mRefreshRateConfigs->updateDisplayConfigs(configs, currentConfig); mVsyncConfiguration->reset(); updatePhaseConfiguration(mRefreshRateConfigs->getCurrentRefreshRate()); @@ -2907,11 +2906,9 @@ void SurfaceFlinger::initScheduler(PhysicalDisplayId primaryDisplayId) { return; } - auto currentConfig = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(primaryDisplayId)); - mRefreshRateConfigs = - std::make_unique<scheduler::RefreshRateConfigs>(getHwComposer().getConfigs( - primaryDisplayId), - currentConfig); + auto currentConfig = getHwComposer().getActiveMode(primaryDisplayId)->getId(); + const auto modes = getHwComposer().getModes(primaryDisplayId); + mRefreshRateConfigs = std::make_unique<scheduler::RefreshRateConfigs>(modes, currentConfig); const auto& currRefreshRate = mRefreshRateConfigs->getRefreshRateFromConfigId(currentConfig); mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(*mTimeStats, currRefreshRate.getFps(), @@ -4797,7 +4794,7 @@ void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, std::string& result) co if (const auto displayId = getInternalDisplayIdLocked(); displayId && getHwComposer().isConnected(*displayId)) { - const auto activeConfig = getHwComposer().getActiveConfig(*displayId); + const auto activeConfig = getHwComposer().getActiveMode(*displayId); std::string fps, xDpi, yDpi; if (activeConfig) { const auto vsyncPeriod = getHwComposer().getDisplayVsyncPeriod(*displayId); @@ -5327,7 +5324,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r ALOGE("No internal display found."); return NO_ERROR; } - const auto numConfigs = getHwComposer().getConfigs(*displayId).size(); + const auto numConfigs = getHwComposer().getModes(*displayId).size(); if (newConfigId >= 0 && newConfigId < numConfigs) { const auto displayToken = getInternalDisplayToken(); status_t result = setActiveConfig(displayToken, newConfigId); @@ -6017,7 +6014,7 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( if (!display->isPrimary()) { // TODO(b/144711714): For non-primary displays we should be able to set an active config - // as well. For now, just call directly to setActiveConfigWithConstraints but ideally + // as well. For now, just call directly to setActiveModeWithConstraints but ideally // it should go thru setDesiredActiveConfig, similar to primary display. ALOGV("setAllowedDisplayConfigsInternal for non-primary display"); const auto displayId = display->getPhysicalId(); @@ -6027,8 +6024,8 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( constraints.seamlessRequired = false; hal::VsyncPeriodChangeTimeline timeline = {0, 0, 0}; - if (getHwComposer().setActiveConfigWithConstraints(displayId, policy->defaultConfig.value(), - constraints, &timeline) < 0) { + if (getHwComposer().setActiveModeWithConstraints(displayId, policy->defaultConfig, + constraints, &timeline) < 0) { return BAD_VALUE; } if (timeline.refreshRequired) { @@ -6037,7 +6034,7 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( display->setActiveConfig(policy->defaultConfig); const nsecs_t vsyncPeriod = getHwComposer() - .getConfigs(displayId)[policy->defaultConfig.value()] + .getModes(displayId)[policy->defaultConfig.value()] ->getVsyncPeriod(); mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle, displayId, policy->defaultConfig, vsyncPeriod); @@ -6077,16 +6074,16 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( ? mRefreshRateConfigs->getRefreshRateFromConfigId(*configId) // NOTE: Choose the default config ID, if Scheduler doesn't have one in mind. : mRefreshRateConfigs->getRefreshRateFromConfigId(currentPolicy.defaultConfig); - ALOGV("trying to switch to Scheduler preferred config %d (%s)", + ALOGV("trying to switch to Scheduler preferred config %zu (%s)", preferredRefreshRate.getConfigId().value(), preferredRefreshRate.getName().c_str()); if (isDisplayConfigAllowed(preferredRefreshRate.getConfigId())) { - ALOGV("switching to Scheduler preferred config %d", + ALOGV("switching to Scheduler preferred config %zu", preferredRefreshRate.getConfigId().value()); setDesiredActiveConfig( {preferredRefreshRate.getConfigId(), Scheduler::ConfigEvent::Changed}); } else { - LOG_ALWAYS_FATAL("Desired config not allowed: %d", + LOG_ALWAYS_FATAL("Desired config not allowed: %zu", preferredRefreshRate.getConfigId().value()); } @@ -6158,9 +6155,10 @@ status_t SurfaceFlinger::getDesiredDisplayConfigSpecs( return INVALID_OPERATION; } else { const auto displayId = display->getPhysicalId(); - *outDefaultConfig = getHwComposer().getActiveConfigIndex(displayId); + const auto activeMode = getHwComposer().getActiveMode(displayId); + *outDefaultConfig = activeMode->getId().value(); *outAllowGroupSwitching = false; - auto vsyncPeriod = getHwComposer().getActiveConfig(displayId)->getVsyncPeriod(); + auto vsyncPeriod = activeMode->getVsyncPeriod(); *outPrimaryRefreshRateMin = Fps::fromPeriodNsecs(vsyncPeriod).getValue(); *outPrimaryRefreshRateMax = Fps::fromPeriodNsecs(vsyncPeriod).getValue(); *outAppRequestRefreshRateMin = Fps::fromPeriodNsecs(vsyncPeriod).getValue(); diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp index 13c7c8b976..a42daae536 100644 --- a/services/surfaceflinger/tests/unittests/Android.bp +++ b/services/surfaceflinger/tests/unittests/Android.bp @@ -80,7 +80,6 @@ cc_test { "VSyncReactorTest.cpp", "VsyncConfigurationTest.cpp", "mock/DisplayHardware/MockComposer.cpp", - "mock/DisplayHardware/MockDisplay.cpp", "mock/DisplayHardware/MockPowerAdvisor.cpp", "mock/MockEventThread.cpp", "mock/MockFrameTimeline.cpp", diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp index bc1e88aeee..5bab534406 100644 --- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp +++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp @@ -190,10 +190,10 @@ public: .WillRepeatedly(DoAll(SetArgPointee<3>(1), Return(V2_1::Error::NONE))); } - void testSetActiveConfigWithConstraintsCommon(bool isVsyncPeriodSwitchSupported); + void testSetActiveModeWithConstraintsCommon(bool isVsyncPeriodSwitchSupported); }; -void HWComposerConfigsTest::testSetActiveConfigWithConstraintsCommon( +void HWComposerConfigsTest::testSetActiveModeWithConstraintsCommon( bool isVsyncPeriodSwitchSupported) { EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0)); EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{})); @@ -229,9 +229,9 @@ void HWComposerConfigsTest::testSetActiveConfigWithConstraintsCommon( constraints.seamlessRequired = false; hal::VsyncPeriodChangeTimeline timeline = {0, 0, 0}; - constexpr size_t kConfigIndex = 0; + constexpr HwcConfigIndexType kConfigIndex(0); const auto status = - hwc.setActiveConfigWithConstraints(physicalId, kConfigIndex, constraints, &timeline); + hwc.setActiveModeWithConstraints(physicalId, kConfigIndex, constraints, &timeline); EXPECT_EQ(NO_ERROR, status); const std::vector<Config> kConfigs{7, 8, 9, 10, 11}; @@ -243,17 +243,18 @@ void HWComposerConfigsTest::testSetActiveConfigWithConstraintsCommon( for (size_t configIndex = 0; configIndex < kConfigs.size(); configIndex++) { const auto status = - hwc.setActiveConfigWithConstraints(physicalId, configIndex, constraints, &timeline); + hwc.setActiveModeWithConstraints(physicalId, HwcConfigIndexType(configIndex), + constraints, &timeline); EXPECT_EQ(NO_ERROR, status) << "Error when switching to config " << configIndex; } } -TEST_F(HWComposerConfigsTest, setActiveConfigWithConstraintsWithVsyncSwitchingSupported) { - testSetActiveConfigWithConstraintsCommon(/*supported=*/true); +TEST_F(HWComposerConfigsTest, setActiveModeWithConstraintsWithVsyncSwitchingSupported) { + testSetActiveModeWithConstraintsCommon(/*supported=*/true); } -TEST_F(HWComposerConfigsTest, setActiveConfigWithConstraintsWithVsyncSwitchingNotSupported) { - testSetActiveConfigWithConstraintsCommon(/*supported=*/false); +TEST_F(HWComposerConfigsTest, setActiveModeWithConstraintsWithVsyncSwitchingNotSupported) { + testSetActiveModeWithConstraintsCommon(/*supported=*/false); } } // namespace diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp index 2ee9c64478..5abe38b8d9 100644 --- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp @@ -110,12 +110,11 @@ protected: << "Frame rate is " << frameRate; } - Hwc2::mock::Display mDisplay; - RefreshRateConfigs mConfigs{{HWC2::Display::Config::Builder(mDisplay, 0) + RefreshRateConfigs mConfigs{{DisplayMode::Builder(0) .setVsyncPeriod(int32_t(LO_FPS_PERIOD)) .setConfigGroup(0) .build(), - HWC2::Display::Config::Builder(mDisplay, 1) + DisplayMode::Builder(1) .setVsyncPeriod(int32_t(HI_FPS_PERIOD)) .setConfigGroup(0) .build()}, diff --git a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp index 0813968334..27c181db88 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp @@ -25,13 +25,13 @@ #include <log/log.h> #include <thread> +#include <ui/Size.h> + #include "../../Scheduler/RefreshRateConfigs.h" #include "DisplayHardware/HWC2.h" #include "Scheduler/RefreshRateConfigs.h" -#include "mock/DisplayHardware/MockDisplay.h" using namespace std::chrono_literals; -using testing::_; namespace android { @@ -81,67 +81,48 @@ protected: static inline const HwcConfigIndexType HWC_CONFIG_ID_50 = HwcConfigIndexType(6); // Test configs - std::shared_ptr<const HWC2::Display::Config> mConfig60 = - createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig90 = - createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentGroup = + DisplayModePtr mConfig60 = createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs()); + DisplayModePtr mConfig90 = createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs()); + DisplayModePtr mConfig90DifferentGroup = createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentResolution = - createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), 111, 222); - std::shared_ptr<const HWC2::Display::Config> mConfig72 = - createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig72DifferentGroup = + DisplayModePtr mConfig90DifferentResolution = + createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), ui::Size(111, 222)); + DisplayModePtr mConfig72 = createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs()); + DisplayModePtr mConfig72DifferentGroup = createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig120 = - createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig120DifferentGroup = + DisplayModePtr mConfig120 = createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs()); + DisplayModePtr mConfig120DifferentGroup = createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig30 = - createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig30DifferentGroup = + DisplayModePtr mConfig30 = createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs()); + DisplayModePtr mConfig30DifferentGroup = createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig25DifferentGroup = + DisplayModePtr mConfig25DifferentGroup = createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs()); - std::shared_ptr<const HWC2::Display::Config> mConfig50 = - createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs()); + DisplayModePtr mConfig50 = createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs()); // Test device configurations // The positions of the configs in the arrays below MUST match their IDs. For example, // the first config should always be 60Hz, the second 90Hz etc. - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60OnlyConfigDevice = {mConfig60}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90Device = {mConfig60, mConfig90}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentGroups = - {mConfig60, mConfig90DifferentGroup}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentResolutions = - {mConfig60, mConfig90DifferentResolution}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_72_90Device = {mConfig60, - mConfig90, - mConfig72}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90_72_120Device = {mConfig60, - mConfig90, - mConfig72, - mConfig120}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90_120Device = {mConfig60, - mConfig90, - mConfig72, - mConfig120, - mConfig30}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60Device = - {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, mConfig120DifferentGroup, - mConfig30}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90Device = - {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, mConfig30}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_90Device = - {mConfig60, mConfig90, mConfig72DifferentGroup, mConfig120DifferentGroup, mConfig30}; - std::vector<std::shared_ptr<const HWC2::Display::Config>> m25_30_50_60Device = - {mConfig60, - mConfig90, - mConfig72DifferentGroup, - mConfig120DifferentGroup, - mConfig30DifferentGroup, - mConfig25DifferentGroup, - mConfig50}; + DisplayModes m60OnlyConfigDevice = {mConfig60}; + DisplayModes m60_90Device = {mConfig60, mConfig90}; + DisplayModes m60_90DeviceWithDifferentGroups = {mConfig60, mConfig90DifferentGroup}; + DisplayModes m60_90DeviceWithDifferentResolutions = {mConfig60, mConfig90DifferentResolution}; + DisplayModes m60_72_90Device = {mConfig60, mConfig90, mConfig72}; + DisplayModes m60_90_72_120Device = {mConfig60, mConfig90, mConfig72, mConfig120}; + DisplayModes m30_60_72_90_120Device = {mConfig60, mConfig90, mConfig72, mConfig120, mConfig30}; + DisplayModes m30_60Device = {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, + mConfig120DifferentGroup, mConfig30}; + DisplayModes m30_60_72_90Device = {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, + mConfig30}; + DisplayModes m30_60_90Device = {mConfig60, mConfig90, mConfig72DifferentGroup, + mConfig120DifferentGroup, mConfig30}; + DisplayModes m25_30_50_60Device = {mConfig60, + mConfig90, + mConfig72DifferentGroup, + mConfig120DifferentGroup, + mConfig30DifferentGroup, + mConfig25DifferentGroup, + mConfig50}; // Expected RefreshRate objects RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, Fps(60), @@ -162,18 +143,12 @@ protected: RefreshRate::ConstructorTag(0)}; RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, Fps(120), RefreshRate::ConstructorTag(0)}; - - Hwc2::mock::Display mDisplay; - private: - std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId, - int32_t configGroup, - int64_t vsyncPeriod, - int32_t hight = -1, - int32_t width = -1); + DisplayModePtr createConfig(HwcConfigIndexType configId, int32_t configGroup, + int64_t vsyncPeriod, ui::Size resolution = ui::Size()); }; -using Builder = HWC2::Display::Config::Builder; +using Builder = DisplayMode::Builder; RefreshRateConfigsTest::RefreshRateConfigsTest() { const ::testing::TestInfo* const test_info = @@ -187,14 +162,14 @@ RefreshRateConfigsTest::~RefreshRateConfigsTest() { ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } -std::shared_ptr<const HWC2::Display::Config> RefreshRateConfigsTest::createConfig( - HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod, int32_t hight, - int32_t width) { - return HWC2::Display::Config::Builder(mDisplay, hal::HWConfigId(configId.value())) +DisplayModePtr RefreshRateConfigsTest::createConfig(HwcConfigIndexType configId, + int32_t configGroup, int64_t vsyncPeriod, + ui::Size resolution) { + return DisplayMode::Builder(hal::HWConfigId(configId.value())) .setVsyncPeriod(int32_t(vsyncPeriod)) .setConfigGroup(configGroup) - .setHeight(hight) - .setWidth(width) + .setHeight(resolution.height) + .setWidth(resolution.width) .build(); } diff --git a/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp index 218840230b..4a96fc5318 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp @@ -28,7 +28,6 @@ #include "Scheduler/HwcStrongTypes.h" #include "Scheduler/RefreshRateConfigs.h" #include "Scheduler/RefreshRateStats.h" -#include "mock/DisplayHardware/MockDisplay.h" #include "mock/MockTimeStats.h" using namespace std::chrono_literals; @@ -50,7 +49,7 @@ protected: RefreshRateStatsTest(); ~RefreshRateStatsTest(); - void init(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) { + void init(const DisplayModes& configs) { mRefreshRateConfigs = std::make_unique<RefreshRateConfigs>(configs, /*currentConfig=*/CONFIG_ID_0); @@ -59,14 +58,12 @@ protected: /*currentPowerMode=*/PowerMode::OFF); } - Hwc2::mock::Display mDisplay; mock::TimeStats mTimeStats; std::unique_ptr<RefreshRateConfigs> mRefreshRateConfigs; std::unique_ptr<RefreshRateStats> mRefreshRateStats; - std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId, - int32_t configGroup, - int64_t vsyncPeriod); + DisplayModePtr createConfig(HwcConfigIndexType configId, int32_t configGroup, + int64_t vsyncPeriod); }; RefreshRateStatsTest::RefreshRateStatsTest() { @@ -81,9 +78,9 @@ RefreshRateStatsTest::~RefreshRateStatsTest() { ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } -std::shared_ptr<const HWC2::Display::Config> RefreshRateStatsTest::createConfig( - HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod) { - return HWC2::Display::Config::Builder(mDisplay, static_cast<hal::HWConfigId>(configId.value())) +DisplayModePtr RefreshRateStatsTest::createConfig(HwcConfigIndexType configId, int32_t configGroup, + int64_t vsyncPeriod) { + return DisplayMode::Builder(static_cast<hal::HWConfigId>(configId.value())) .setVsyncPeriod(static_cast<int32_t>(vsyncPeriod)) .setConfigGroup(configGroup) .build(); diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index fb02a33cb3..757c702738 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -24,7 +24,6 @@ #include "Scheduler/RefreshRateConfigs.h" #include "TestableScheduler.h" #include "TestableSurfaceFlinger.h" -#include "mock/DisplayHardware/MockDisplay.h" #include "mock/MockEventThread.h" #include "mock/MockLayer.h" #include "mock/MockSchedulerCallback.h" @@ -52,12 +51,9 @@ protected: SchedulerTest(); - Hwc2::mock::Display mDisplay; - const scheduler::RefreshRateConfigs mConfigs{{HWC2::Display::Config::Builder(mDisplay, 0) - .setVsyncPeriod(16'666'667) - .setConfigGroup(0) - .build()}, - HwcConfigIndexType(0)}; + const scheduler::RefreshRateConfigs + mConfigs{{DisplayMode::Builder(0).setVsyncPeriod(16'666'667).setConfigGroup(0).build()}, + HwcConfigIndexType(0)}; mock::SchedulerCallback mSchedulerCallback; diff --git a/services/surfaceflinger/tests/unittests/StrongTypingTest.cpp b/services/surfaceflinger/tests/unittests/StrongTypingTest.cpp index 54068797a1..45b761036a 100644 --- a/services/surfaceflinger/tests/unittests/StrongTypingTest.cpp +++ b/services/surfaceflinger/tests/unittests/StrongTypingTest.cpp @@ -24,7 +24,6 @@ namespace android { TEST(StrongTypeTest, comparison) { using SpunkyType = StrongTyping<int, struct SpunkyTypeTag, Compare>; - SpunkyType f2(22); SpunkyType f1(10); EXPECT_TRUE(f1 == f1); diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 739a9b2764..e7ded8b5af 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -41,7 +41,6 @@ #include "SurfaceFlingerDefaultFactory.h" #include "SurfaceInterceptor.h" #include "TestableScheduler.h" -#include "mock/DisplayHardware/MockDisplay.h" #include "mock/MockDisplayIdGenerator.h" #include "mock/MockFrameTimeline.h" #include "mock/MockFrameTracer.h" @@ -211,17 +210,12 @@ public: std::unique_ptr<EventThread> appEventThread, std::unique_ptr<EventThread> sfEventThread, ISchedulerCallback* callback = nullptr, bool hasMultipleConfigs = false) { - std::vector<std::shared_ptr<const HWC2::Display::Config>> configs{ - HWC2::Display::Config::Builder(mDisplay, 0) - .setVsyncPeriod(16'666'667) - .setConfigGroup(0) - .build()}; + DisplayModes configs{ + DisplayMode::Builder(0).setVsyncPeriod(16'666'667).setConfigGroup(0).build()}; if (hasMultipleConfigs) { - configs.emplace_back(HWC2::Display::Config::Builder(mDisplay, 1) - .setVsyncPeriod(11'111'111) - .setConfigGroup(0) - .build()); + configs.emplace_back( + DisplayMode::Builder(1).setVsyncPeriod(11'111'111).setConfigGroup(0).build()); } const auto currConfig = HwcConfigIndexType(0); @@ -470,7 +464,6 @@ public: } auto& mutableIsConnected() { return this->mIsConnected; } - auto& mutableConfigs() { return this->mConfigs; } auto& mutableLayers() { return this->mLayers; } }; @@ -545,19 +538,20 @@ public: auto display = std::make_unique<HWC2Display>(*composer, *mCapabilities, mHwcDisplayId, mHwcDisplayType); - auto config = HWC2::Display::Config::Builder(*display, mActiveConfig); - config.setWidth(mWidth); - config.setHeight(mHeight); - config.setVsyncPeriod(mRefreshRate); - config.setDpiX(mDpiX); - config.setDpiY(mDpiY); - config.setConfigGroup(mConfigGroup); - display->mutableConfigs().emplace(static_cast<int32_t>(mActiveConfig), config.build()); display->mutableIsConnected() = true; display->setPowerMode(mPowerMode); - flinger->mutableHwcDisplayData()[mDisplayId].hwcDisplay = std::move(display); + auto config = DisplayMode::Builder(mActiveConfig) + .setWidth(mWidth) + .setHeight(mHeight) + .setVsyncPeriod(mRefreshRate) + .setDpiX(mDpiX) + .setDpiY(mDpiY) + .setConfigGroup(mConfigGroup) + .build(); + flinger->mutableHwcDisplayData()[mDisplayId].modes.push_back(config); + if (mHwcDisplayType == hal::DisplayType::PHYSICAL) { const auto physicalId = PhysicalDisplayId::tryCast(mDisplayId); LOG_ALWAYS_FATAL_IF(!physicalId); @@ -704,7 +698,6 @@ private: surfaceflinger::test::Factory mFactory; sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization); TestableScheduler* mScheduler = nullptr; - Hwc2::mock::Display mDisplay; mock::DisplayIdGenerator<GpuVirtualDisplayId> mGpuVirtualDisplayIdGenerator; }; diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.cpp b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.cpp deleted file mode 100644 index c9788afbe4..0000000000 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 "mock/DisplayHardware/MockDisplay.h" - -namespace android::Hwc2::mock { - -// Explicit default instantiation is recommended. -Display::Display() = default; -Display::~Display() = default; - -} // namespace android::Hwc2::mock
\ No newline at end of file diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.h deleted file mode 100644 index a96d9dbe2a..0000000000 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockDisplay.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 <gmock/gmock.h> - -#include "DisplayHardware/HWC2.h" - -using android::HWC2::Layer; - -namespace android::Hwc2::mock { - -namespace hal = android::hardware::graphics::composer::hal; - -class Display : public HWC2::Display { -public: - using Layer = ::Layer; - - Display(); - ~Display(); - - MOCK_CONST_METHOD0(getId, hal::HWDisplayId()); - MOCK_CONST_METHOD0(isConnected, bool()); - MOCK_METHOD1(setConnected, void(bool)); - MOCK_CONST_METHOD0(getCapabilities, const std::unordered_set<hal::DisplayCapability>&()); - - MOCK_METHOD0(acceptChanges, hal::Error()); - MOCK_METHOD1(createLayer, hal::Error(Layer**)); - MOCK_METHOD1(destroyLayer, hal::Error(Layer*)); - MOCK_CONST_METHOD1(getActiveConfig, hal::Error(std::shared_ptr<const Config>*)); - MOCK_CONST_METHOD1(getActiveConfigIndex, hal::Error(int* outIndex)); - MOCK_METHOD1(getChangedCompositionTypes, - hal::Error(std::unordered_map<Layer*, hal::Composition>*)); - MOCK_CONST_METHOD1(getColorModes, hal::Error(std::vector<hal::ColorMode>*)); - - MOCK_CONST_METHOD0(getSupportedPerFrameMetadata, int32_t()); - MOCK_CONST_METHOD2(getRenderIntents, - hal::Error(hal::ColorMode, std::vector<hal::RenderIntent>*)); - MOCK_METHOD2(getDataspaceSaturationMatrix, hal::Error(hal::Dataspace, android::mat4*)); - MOCK_CONST_METHOD0(getConfigs, std::vector<std::shared_ptr<const Config>>()); - - MOCK_CONST_METHOD1(getName, hal::Error(std::string*)); - MOCK_METHOD2(getRequests, - hal::Error(hal::DisplayRequest*, std::unordered_map<Layer*, hal::LayerRequest>*)); - MOCK_CONST_METHOD1(getType, hal::Error(hal::DisplayType*)); - MOCK_CONST_METHOD1(supportsDoze, hal::Error(bool*)); - MOCK_CONST_METHOD1(getHdrCapabilities, hal::Error(android::HdrCapabilities*)); - MOCK_CONST_METHOD3(getDisplayedContentSamplingAttributes, - hal::Error(hal::PixelFormat*, hal::Dataspace*, uint8_t*)); - MOCK_CONST_METHOD3(setDisplayContentSamplingEnabled, hal::Error(bool, uint8_t, uint64_t)); - MOCK_CONST_METHOD3(getDisplayedContentSample, - hal::Error(uint64_t, uint64_t, android::DisplayedFrameStats*)); - MOCK_CONST_METHOD1( - getReleaseFences, - hal::Error(std::unordered_map<Layer*, android::sp<android::Fence>>* outFences)); - MOCK_METHOD1(present, hal::Error(android::sp<android::Fence>*)); - MOCK_METHOD1(setActiveConfig, hal::Error(const std::shared_ptr<const HWC2::Display::Config>&)); - MOCK_METHOD4(setClientTarget, - hal::Error(uint32_t, const android::sp<android::GraphicBuffer>&, - const android::sp<android::Fence>&, hal::Dataspace)); - MOCK_METHOD2(setColorMode, hal::Error(hal::ColorMode, hal::RenderIntent)); - MOCK_METHOD2(setColorTransform, hal::Error(const android::mat4&, hal::ColorTransform)); - MOCK_METHOD2(setOutputBuffer, - hal::Error(const android::sp<android::GraphicBuffer>&, - const android::sp<android::Fence>&)); - MOCK_METHOD1(setPowerMode, hal::Error(hal::PowerMode)); - MOCK_METHOD1(setVsyncEnabled, hal::Error(hal::Vsync)); - MOCK_METHOD2(validate, hal::Error(uint32_t*, uint32_t*)); - MOCK_METHOD4(presentOrValidate, - hal::Error(uint32_t*, uint32_t*, android::sp<android::Fence>*, uint32_t*)); - MOCK_METHOD1(setDisplayBrightness, std::future<hal::Error>(float)); - MOCK_CONST_METHOD1(getDisplayVsyncPeriod, hal::Error(nsecs_t*)); - MOCK_METHOD3(setActiveConfigWithConstraints, - hal::Error(const std::shared_ptr<const HWC2::Display::Config>&, - const hal::VsyncPeriodChangeConstraints&, - hal::VsyncPeriodChangeTimeline*)); - MOCK_METHOD1(setAutoLowLatencyMode, hal::Error(bool on)); - MOCK_CONST_METHOD1(getSupportedContentTypes, hal::Error(std::vector<hal::ContentType>*)); - MOCK_METHOD1(setContentType, hal::Error(hal::ContentType)); - MOCK_METHOD1(getClientTargetProperty, hal::Error(hal::ClientTargetProperty*)); - MOCK_CONST_METHOD1(getConnectionType, hal::Error(android::DisplayConnectionType*)); - MOCK_CONST_METHOD0(isVsyncPeriodSwitchSupported, bool()); -}; - -} // namespace android::Hwc2::mock |