diff options
Diffstat (limited to 'services/surfaceflinger/DisplayHardware/HWC2.h')
-rw-r--r-- | services/surfaceflinger/DisplayHardware/HWC2.h | 213 |
1 files changed, 158 insertions, 55 deletions
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index 871465d717..6819ff43d2 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#pragma once +#ifndef ANDROID_SF_HWC2_H +#define ANDROID_SF_HWC2_H -#include <android-base/expected.h> #include <gui/HdrMetadata.h> #include <math/mat4.h> +#include <ui/DisplayInfo.h> #include <ui/HdrCapabilities.h> #include <ui/Region.h> -#include <ui/StaticDisplayInfo.h> #include <utils/Log.h> #include <utils/StrongPointer.h> #include <utils/Timers.h> @@ -36,16 +36,15 @@ #include "Hal.h" namespace android { + struct DisplayedFrameStats; + class Fence; + class FloatRect; + class GraphicBuffer; + namespace Hwc2 { + class Composer; + } -class Fence; -class FloatRect; -class GraphicBuffer; -class TestableSurfaceFlinger; -struct DisplayedFrameStats; - -namespace Hwc2 { -class Composer; -} // namespace Hwc2 + class TestableSurfaceFlinger; namespace HWC2 { @@ -56,19 +55,25 @@ namespace hal = android::hardware::graphics::composer::hal; // Implement this interface to receive hardware composer events. // // These callback functions will generally be called on a hwbinder thread, but -// when first registering the callback the onComposerHalHotplug() function will +// when first registering the callback the onHotplugReceived() function will // immediately be called on the thread calling registerCallback(). -struct ComposerCallback { - virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0; - virtual void onComposerHalRefresh(hal::HWDisplayId) = 0; - virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp, - std::optional<hal::VsyncPeriodNanos>) = 0; - virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, - const hal::VsyncPeriodChangeTimeline&) = 0; - virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0; - -protected: - ~ComposerCallback() = default; +// +// All calls receive a sequenceId, which will be the value that was supplied to +// HWC2::Device::registerCallback(). It's used to help differentiate callbacks +// from different hardware composer instances. +class ComposerCallback { + public: + virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display, + hal::Connection connection) = 0; + virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId display) = 0; + virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId display, int64_t timestamp, + std::optional<hal::VsyncPeriodNanos> vsyncPeriod) = 0; + virtual void onVsyncPeriodTimingChangedReceived( + int32_t sequenceId, hal::HWDisplayId display, + const hal::VsyncPeriodChangeTimeline& updatedTimeline) = 0; + virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId display) = 0; + + virtual ~ComposerCallback() = default; }; // Convenience C++ class to access per display functions directly. @@ -76,16 +81,92 @@ 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 virtual const std::unordered_set<hal::DisplayCapability>& getCapabilities() const = 0; virtual bool isVsyncPeriodSwitchSupported() const = 0; - virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0; [[clang::warn_unused_result]] virtual hal::Error acceptChanges() = 0; - [[clang::warn_unused_result]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> - createLayer() = 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( @@ -97,12 +178,16 @@ 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, std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0; [[clang::warn_unused_result]] virtual hal::Error getConnectionType( - ui::DisplayConnectionType*) const = 0; + android::DisplayConnectionType*) const = 0; [[clang::warn_unused_result]] virtual hal::Error supportsDoze(bool* outSupport) const = 0; [[clang::warn_unused_result]] virtual hal::Error getHdrCapabilities( android::HdrCapabilities* outCapabilities) const = 0; @@ -118,6 +203,8 @@ 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; @@ -137,8 +224,11 @@ 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( - hal::HWConfigId configId, const hal::VsyncPeriodChangeConstraints& constraints, + const std::shared_ptr<const HWC2::Display::Config>& config, + 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( @@ -150,31 +240,37 @@ public: namespace impl { -class Layer; - class Display : public HWC2::Display { public: - Display(android::Hwc2::Composer&, const std::unordered_set<hal::Capability>&, hal::HWDisplayId, - hal::DisplayType); + Display(android::Hwc2::Composer& composer, + const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId id, + hal::DisplayType type); ~Display() override; // Required by HWC2 hal::Error acceptChanges() override; - base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() override; + hal::Error createLayer(Layer** outLayer) override; + hal::Error destroyLayer(Layer* 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<HWC2::Layer*, hal::Composition>* outTypes) override; + std::unordered_map<Layer*, hal::Composition>* outTypes) override; hal::Error getColorModes(std::vector<hal::ColorMode>* outModes) const override; // Returns a bitmask which contains HdrMetadata::Type::*. int32_t getSupportedPerFrameMetadata() const override; hal::Error getRenderIntents(hal::ColorMode colorMode, std::vector<hal::RenderIntent>* outRenderIntents) const override; - hal::Error getDataspaceSaturationMatrix(hal::Dataspace, android::mat4* outMatrix) override; + hal::Error getDataspaceSaturationMatrix(hal::Dataspace 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, - std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override; - hal::Error getConnectionType(ui::DisplayConnectionType*) const override; + std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) override; + hal::Error getConnectionType(android::DisplayConnectionType*) const override; hal::Error supportsDoze(bool* outSupport) const override; hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override; hal::Error getDisplayedContentSamplingAttributes(hal::PixelFormat* outFormat, @@ -184,26 +280,29 @@ public: uint64_t maxFrames) const override; hal::Error getDisplayedContentSample(uint64_t maxFrames, uint64_t timestamp, android::DisplayedFrameStats* outStats) const override; - hal::Error getReleaseFences(std::unordered_map<HWC2::Layer*, android::sp<android::Fence>>* - outFences) const override; + 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; - hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override; + hal::Error setColorMode(hal::ColorMode mode, hal::RenderIntent renderIntent) override; hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override; - hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&, + hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>& buffer, const android::sp<android::Fence>& releaseFence) override; - hal::Error setPowerMode(hal::PowerMode) override; + hal::Error setPowerMode(hal::PowerMode mode) override; hal::Error setVsyncEnabled(hal::Vsync enabled) override; hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override; hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests, android::sp<android::Fence>* outPresentFence, uint32_t* state) override; std::future<hal::Error> setDisplayBrightness(float brightness) override; - hal::Error setActiveConfigWithConstraints(hal::HWConfigId configId, - const hal::VsyncPeriodChangeConstraints& constraints, - hal::VsyncPeriodChangeTimeline* outTimeline) 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 setAutoLowLatencyMode(bool on) override; hal::Error getSupportedContentTypes( std::vector<hal::ContentType>* outSupportedContentTypes) const override; @@ -217,14 +316,16 @@ public: const std::unordered_set<hal::DisplayCapability>& getCapabilities() const override { return mDisplayCapabilities; }; - bool isVsyncPeriodSwitchSupported() const override; - void onLayerDestroyed(hal::HWLayerId layerId) override; + virtual bool isVsyncPeriodSwitchSupported() const override; private: + int32_t getAttribute(hal::HWConfigId configId, hal::Attribute attribute); + void loadConfig(hal::HWConfigId configId); + void loadConfigs(); // This may fail (and return a null pointer) if no layer with this ID exists // on this display - std::shared_ptr<HWC2::Layer> getLayerById(hal::HWLayerId id) const; + Layer* getLayerById(hal::HWLayerId id) const; friend android::TestableSurfaceFlinger; @@ -240,8 +341,8 @@ private: hal::DisplayType mType; bool mIsConnected = false; - using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>; - Layers mLayers; + 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; @@ -279,6 +380,7 @@ public: [[clang::warn_unused_result]] virtual hal::Error setVisibleRegion( const android::Region& region) = 0; [[clang::warn_unused_result]] virtual hal::Error setZOrder(uint32_t z) = 0; + [[clang::warn_unused_result]] virtual hal::Error setInfo(uint32_t type, uint32_t appId) = 0; // Composer HAL 2.3 [[clang::warn_unused_result]] virtual hal::Error setColorTransform( @@ -296,12 +398,10 @@ namespace impl { class Layer : public HWC2::Layer { public: Layer(android::Hwc2::Composer& composer, - const std::unordered_set<hal::Capability>& capabilities, HWC2::Display& display, + const std::unordered_set<hal::Capability>& capabilities, hal::HWDisplayId displayId, hal::HWLayerId layerId); ~Layer() override; - void onOwningDisplayDestroyed(); - hal::HWLayerId getId() const override { return mId; } hal::Error setCursorPosition(int32_t x, int32_t y) override; @@ -322,6 +422,7 @@ public: hal::Error setTransform(hal::Transform transform) override; hal::Error setVisibleRegion(const android::Region& region) override; hal::Error setZOrder(uint32_t z) override; + hal::Error setInfo(uint32_t type, uint32_t appId) override; // Composer HAL 2.3 hal::Error setColorTransform(const android::mat4& matrix) override; @@ -337,7 +438,7 @@ private: android::Hwc2::Composer& mComposer; const std::unordered_set<hal::Capability>& mCapabilities; - HWC2::Display* mDisplay; + hal::HWDisplayId mDisplayId; hal::HWLayerId mId; // Cached HWC2 data, to ensure the same commands aren't sent to the HWC @@ -353,3 +454,5 @@ private: } // namespace impl } // namespace HWC2 } // namespace android + +#endif // ANDROID_SF_HWC2_H |