diff options
25 files changed, 212 insertions, 52 deletions
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 6bb80dca32..063aabbdef 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1939,6 +1939,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesir return *this; } +SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLuts( + const sp<SurfaceControl>& sc, const base::unique_fd& /*lutFd*/, + const std::vector<int32_t>& /*offsets*/, const std::vector<int32_t>& /*dimensions*/, + const std::vector<int32_t>& /*sizes*/, const std::vector<int32_t>& /*samplingKeys*/) { + layer_state_t* s = getLayerState(sc); + if (!s) { + mStatus = BAD_INDEX; + return *this; + } + // TODO (b/329472856): update layer_state_t for lut(s) + registerSurfaceControlForCallback(sc); + return *this; +} + SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCachingHint( const sp<SurfaceControl>& sc, gui::CachingHint cachingHint) { layer_state_t* s = getLayerState(sc); diff --git a/libs/gui/aidl/android/gui/Lut.aidl b/libs/gui/aidl/android/gui/Lut.aidl new file mode 100644 index 0000000000..a06e521789 --- /dev/null +++ b/libs/gui/aidl/android/gui/Lut.aidl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.gui; + +import android.gui.LutProperties; +import android.os.ParcelFileDescriptor; + +/** + * This mirrors aidl::android::hardware::graphics::composer3::Lut definition + * @hide + */ +parcelable Lut { + @nullable ParcelFileDescriptor pfd; + + LutProperties lutProperties; +}
\ No newline at end of file diff --git a/libs/gui/aidl/android/gui/LutProperties.aidl b/libs/gui/aidl/android/gui/LutProperties.aidl new file mode 100644 index 0000000000..561e0c069c --- /dev/null +++ b/libs/gui/aidl/android/gui/LutProperties.aidl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.gui; + +/** + * This mirrors aidl::android::hardware::graphics::composer3::LutProperties definition. + * @hide + */ +parcelable LutProperties { + @Backing(type="int") + enum Dimension { ONE_D = 1, THREE_D = 3 } + Dimension dimension; + + long size; + @Backing(type="int") + enum SamplingKey { RGB, MAX_RGB } + SamplingKey[] samplingKeys; +}
\ No newline at end of file diff --git a/libs/gui/aidl/android/gui/OverlayProperties.aidl b/libs/gui/aidl/android/gui/OverlayProperties.aidl index 5fb1a83c65..7f41bdab2f 100644 --- a/libs/gui/aidl/android/gui/OverlayProperties.aidl +++ b/libs/gui/aidl/android/gui/OverlayProperties.aidl @@ -16,6 +16,8 @@ package android.gui; +import android.gui.LutProperties; + /** @hide */ parcelable OverlayProperties { parcelable SupportedBufferCombinations { @@ -27,4 +29,6 @@ parcelable OverlayProperties { SupportedBufferCombinations[] combinations; boolean supportMixedColorSpaces; + + @nullable LutProperties[] lutProperties; } diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 2b99c0feb3..5ea0c1619b 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -602,6 +602,11 @@ public: Transaction& setExtendedRangeBrightness(const sp<SurfaceControl>& sc, float currentBufferRatio, float desiredRatio); Transaction& setDesiredHdrHeadroom(const sp<SurfaceControl>& sc, float desiredRatio); + Transaction& setLuts(const sp<SurfaceControl>& sc, const base::unique_fd& lutFd, + const std::vector<int32_t>& offsets, + const std::vector<int32_t>& dimensions, + const std::vector<int32_t>& sizes, + const std::vector<int32_t>& samplingKeys); Transaction& setCachingHint(const sp<SurfaceControl>& sc, gui::CachingHint cachingHint); Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata); Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc, diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h index 4dbf8d2fce..dcfe21a849 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h @@ -128,6 +128,10 @@ public: // Applies a HWC device layer request virtual void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) = 0; + // Applies a HWC device layer lut + virtual void applyDeviceLayerLut(aidl::android::hardware::graphics::composer3::LutProperties, + ndk::ScopedFileDescriptor) = 0; + // Returns true if the composition settings scale pixels virtual bool needsFiltering() const = 0; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h index d1eff241d3..a39abb40d2 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h @@ -82,11 +82,13 @@ public: using DisplayRequests = android::HWComposer::DeviceRequestedChanges::DisplayRequests; using LayerRequests = android::HWComposer::DeviceRequestedChanges::LayerRequests; using ClientTargetProperty = android::HWComposer::DeviceRequestedChanges::ClientTargetProperty; + using LayerLuts = android::HWComposer::DeviceRequestedChanges::LayerLuts; virtual bool allLayersRequireClientComposition() const; virtual void applyChangedTypesToLayers(const ChangedTypes&); virtual void applyDisplayRequests(const DisplayRequests&); virtual void applyLayerRequestsToLayers(const LayerRequests&); virtual void applyClientTargetRequests(const ClientTargetProperty&); + virtual void applyLayerLutsToLayers(const LayerLuts&); // Internal virtual void setConfiguration(const compositionengine::DisplayCreationArgs&); diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h index f383392e55..354a4416f2 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h @@ -60,6 +60,8 @@ public: aidl::android::hardware::graphics::composer3::Composition) override; void prepareForDeviceLayerRequests() override; void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) override; + void applyDeviceLayerLut(aidl::android::hardware::graphics::composer3::LutProperties, + ndk::ScopedFileDescriptor) override; bool needsFiltering() const override; std::optional<LayerFE::LayerSettings> getOverrideCompositionSettings() const override; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h index 5fef63a510..48c2f9c483 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h @@ -56,6 +56,9 @@ public: MOCK_METHOD1(applyDeviceLayerRequest, void(Hwc2::IComposerClient::LayerRequest request)); MOCK_CONST_METHOD0(needsFiltering, bool()); MOCK_CONST_METHOD0(getOverrideCompositionSettings, std::optional<LayerFE::LayerSettings>()); + MOCK_METHOD(void, applyDeviceLayerLut, + (aidl::android::hardware::graphics::composer3::LutProperties, + ndk::ScopedFileDescriptor)); MOCK_CONST_METHOD1(dump, void(std::string&)); }; diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index 77b1940e23..b0164b7c33 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -278,6 +278,7 @@ void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChange applyDisplayRequests(changes->displayRequests); applyLayerRequestsToLayers(changes->layerRequests); applyClientTargetRequests(changes->clientTargetProperty); + applyLayerLutsToLayers(changes->layerLuts); } // Determine what type of composition we are doing from the final state @@ -359,6 +360,25 @@ void Display::applyClientTargetRequests(const ClientTargetProperty& clientTarget static_cast<ui::PixelFormat>(clientTargetProperty.clientTargetProperty.pixelFormat)); } +void Display::applyLayerLutsToLayers(const LayerLuts& layerLuts) { + auto& mapper = getCompositionEngine().getHwComposer().getLutFileDescriptorMapper(); + for (auto* layer : getOutputLayersOrderedByZ()) { + auto hwcLayer = layer->getHwcLayer(); + if (!hwcLayer) { + continue; + } + + if (auto lutsIt = layerLuts.find(hwcLayer); lutsIt != layerLuts.end()) { + if (auto mapperIt = mapper.find(hwcLayer); mapperIt != mapper.end()) { + layer->applyDeviceLayerLut(lutsIt->second, + ndk::ScopedFileDescriptor(mapperIt->second.release())); + } + } + } + + mapper.clear(); +} + void Display::executeCommands() { const auto halDisplayIdOpt = HalDisplayId::tryCast(mId); if (mIsDisconnected || !halDisplayIdOpt) { diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp index e6f0d2da7f..2d46dc0702 100644 --- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp +++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp @@ -38,6 +38,7 @@ #pragma clang diagnostic pop // ignored "-Wconversion" using aidl::android::hardware::graphics::composer3::Composition; +using aidl::android::hardware::graphics::composer3::LutProperties; namespace android::compositionengine { @@ -848,6 +849,12 @@ void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) { } } +void OutputLayer::applyDeviceLayerLut(LutProperties /*lutProperties*/, + ndk::ScopedFileDescriptor /*lutPfd*/) { + // TODO(b/329472856): decode the shared memory of the pfd, and store the lut data into + // OutputLayerCompositionState#hwc struct +} + bool OutputLayer::needsFiltering() const { const auto& state = getState(); const auto& sourceCrop = state.sourceCrop; diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp index 39163ea60f..9c0e62c643 100644 --- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp @@ -133,6 +133,7 @@ struct DisplayTestCommon : public testing::Test { MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&)); MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&)); MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&)); + MOCK_METHOD1(applyLayerLutsToLayers, void(const impl::Display::LayerLuts&)); const compositionengine::CompositionEngine& mCompositionEngine; impl::OutputCompositionState mState; @@ -212,6 +213,7 @@ struct PartialMockDisplayTestCommon : public DisplayTestCommon { aidl::android::hardware::graphics::common::Dataspace::UNKNOWN}, -1.f, DimmingStage::NONE}, + {}, }; void chooseCompositionStrategy(Display* display) { @@ -615,6 +617,7 @@ TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) { EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests)) .Times(1); EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); + EXPECT_CALL(*mDisplay, applyLayerLutsToLayers(mDeviceRequestedChanges.layerLuts)).Times(1); chooseCompositionStrategy(mDisplay.get()); @@ -667,6 +670,7 @@ TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests)) .Times(1); EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); + EXPECT_CALL(*mDisplay, applyLayerLutsToLayers(mDeviceRequestedChanges.layerLuts)).Times(1); chooseCompositionStrategy(mDisplay.get()); diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index e910c72e2e..5c55ce739a 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -152,10 +152,7 @@ public: getOverlaySupport, (), (const, override)); MOCK_METHOD(status_t, setRefreshRateChangedCallbackDebugEnabled, (PhysicalDisplayId, bool)); MOCK_METHOD(status_t, notifyExpectedPresent, (PhysicalDisplayId, TimePoint, Fps)); - MOCK_METHOD(status_t, getRequestedLuts, - (PhysicalDisplayId, - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*), - (override)); + MOCK_METHOD((HWC2::Display::LutFileDescriptorMapper&), getLutFileDescriptorMapper, (), ()); }; } // namespace mock diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp index 66237b9d8a..77bd8040c5 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp @@ -1547,7 +1547,8 @@ Error AidlComposer::getClientTargetProperty( return error; } -Error AidlComposer::getRequestedLuts(Display display, std::vector<DisplayLuts::LayerLut>* outLuts) { +Error AidlComposer::getRequestedLuts(Display display, std::vector<Layer>* outLayers, + std::vector<DisplayLuts::LayerLut>* outLuts) { Error error = Error::NONE; mMutex.lock_shared(); if (auto reader = getReader(display)) { @@ -1556,6 +1557,11 @@ Error AidlComposer::getRequestedLuts(Display display, std::vector<DisplayLuts::L error = Error::BAD_DISPLAY; } mMutex.unlock_shared(); + + outLayers->reserve(outLuts->size()); + for (const auto& layerLut : *outLuts) { + outLayers->emplace_back(translate<Layer>(layerLut.layer)); + } return error; } diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h index 246223a668..cdb67e4e5c 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h @@ -245,7 +245,7 @@ public: Error notifyExpectedPresent(Display, nsecs_t expectedPresentTime, int32_t frameIntervalNs) override; Error getRequestedLuts( - Display display, + Display display, std::vector<Layer>* outLayers, std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>* outLuts) override; Error setLayerLuts( diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h index 7db9a94e54..09056631d0 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h @@ -305,7 +305,7 @@ public: virtual Error setRefreshRateChangedCallbackDebugEnabled(Display, bool) = 0; virtual Error notifyExpectedPresent(Display, nsecs_t expectedPresentTime, int32_t frameIntervalNs) = 0; - virtual Error getRequestedLuts(Display display, + virtual Error getRequestedLuts(Display display, std::vector<Layer>* outLayers, std::vector<V3_0::DisplayLuts::LayerLut>* outLuts) = 0; virtual Error setLayerLuts(Display display, Layer layer, std::vector<V3_0::Lut>& luts) = 0; }; diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp index f1fa9389eb..1df2ab12ce 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp @@ -609,17 +609,29 @@ Error Display::getClientTargetProperty( return static_cast<Error>(error); } -Error Display::getRequestedLuts(std::vector<DisplayLuts::LayerLut>* outLayerLuts) { - std::vector<DisplayLuts::LayerLut> tmpLayerLuts; - const auto error = mComposer.getRequestedLuts(mId, &tmpLayerLuts); - for (DisplayLuts::LayerLut& layerLut : tmpLayerLuts) { - if (layerLut.lut.pfd.get() >= 0) { - outLayerLuts->push_back({layerLut.layer, - Lut{ndk::ScopedFileDescriptor(layerLut.lut.pfd.release()), - layerLut.lut.lutProperties}}); +Error Display::getRequestedLuts(LayerLuts* outLuts, + LutFileDescriptorMapper& lutFileDescriptorMapper) { + std::vector<Hwc2::Layer> layerIds; + std::vector<DisplayLuts::LayerLut> tmpLuts; + const auto error = static_cast<Error>(mComposer.getRequestedLuts(mId, &layerIds, &tmpLuts)); + if (error != Error::NONE) { + return error; + } + + uint32_t numElements = layerIds.size(); + outLuts->clear(); + for (uint32_t i = 0; i < numElements; ++i) { + auto layer = getLayerById(layerIds[i]); + if (layer) { + auto& layerLut = tmpLuts[i]; + outLuts->emplace_or_replace(layer.get(), layerLut.lut.lutProperties); + lutFileDescriptorMapper.emplace_or_replace(layer.get(), + ndk::ScopedFileDescriptor( + layerLut.lut.pfd.release())); } } - return static_cast<Error>(error); + + return Error::NONE; } Error Display::getDisplayDecorationSupport( diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index 8e2aeaf234..61f92f4d74 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -20,6 +20,7 @@ #include <android-base/thread_annotations.h> #include <ftl/expected.h> #include <ftl/future.h> +#include <ftl/small_map.h> #include <gui/HdrMetadata.h> #include <math/mat4.h> #include <ui/HdrCapabilities.h> @@ -107,6 +108,13 @@ public: virtual void onLayerDestroyed(hal::HWLayerId layerId) = 0; virtual std::optional<ui::Size> getPhysicalSizeInMm() const = 0; + static const int kLutFileDescriptorMapperSize = 20; + using LayerLuts = + ftl::SmallMap<HWC2::Layer*, aidl::android::hardware::graphics::composer3::LutProperties, + kLutFileDescriptorMapperSize>; + using LutFileDescriptorMapper = + ftl::SmallMap<HWC2::Layer*, ndk::ScopedFileDescriptor, kLutFileDescriptorMapperSize>; + [[nodiscard]] virtual hal::Error acceptChanges() = 0; [[nodiscard]] virtual base::expected<std::shared_ptr<HWC2::Layer>, hal::Error> createLayer() = 0; @@ -183,8 +191,7 @@ public: aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* outClientTargetProperty) = 0; [[nodiscard]] virtual hal::Error getRequestedLuts( - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>* - outLuts) = 0; + LayerLuts* outLuts, LutFileDescriptorMapper& lutFileDescriptorMapper) = 0; [[nodiscard]] virtual hal::Error getDisplayDecorationSupport( std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* support) = 0; @@ -268,9 +275,8 @@ public: hal::Error getClientTargetProperty( aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness* outClientTargetProperty) override; - hal::Error getRequestedLuts( - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>* - outLuts) override; + hal::Error getRequestedLuts(LayerLuts* outLuts, + LutFileDescriptorMapper& lutFileDescriptorMapper) override; hal::Error getDisplayDecorationSupport( std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>* support) override; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index d08e261e6c..e37c0ba296 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -587,9 +587,14 @@ status_t HWComposer::getDeviceCompositionChanges( error = hwcDisplay->getClientTargetProperty(&clientTargetProperty); RETURN_IF_HWC_ERROR_FOR("getClientTargetProperty", error, displayId, BAD_INDEX); + DeviceRequestedChanges::LayerLuts layerLuts; + error = hwcDisplay->getRequestedLuts(&layerLuts, mLutFileDescriptorMapper); + RETURN_IF_HWC_ERROR_FOR("getRequestedLuts", error, displayId, BAD_INDEX); + outChanges->emplace(DeviceRequestedChanges{std::move(changedTypes), std::move(displayRequests), std::move(layerRequests), - std::move(clientTargetProperty)}); + std::move(clientTargetProperty), + std::move(layerLuts)}); error = hwcDisplay->acceptChanges(); RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX); @@ -978,21 +983,6 @@ status_t HWComposer::getDisplayDecorationSupport( return NO_ERROR; } -status_t HWComposer::getRequestedLuts( - PhysicalDisplayId displayId, - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>* outLuts) { - RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); - const auto error = mDisplayData[displayId].hwcDisplay->getRequestedLuts(outLuts); - if (error == hal::Error::UNSUPPORTED) { - RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION); - } - if (error == hal::Error::BAD_PARAMETER) { - RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); - } - RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); - return NO_ERROR; -} - status_t HWComposer::setAutoLowLatencyMode(PhysicalDisplayId displayId, bool on) { RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); const auto error = mDisplayData[displayId].hwcDisplay->setAutoLowLatencyMode(on); @@ -1036,6 +1026,11 @@ const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGeneri return mSupportedLayerGenericMetadata; } +ftl::SmallMap<HWC2::Layer*, ndk::ScopedFileDescriptor, 20>& +HWComposer::getLutFileDescriptorMapper() { + return mLutFileDescriptorMapper; +} + void HWComposer::dumpOverlayProperties(std::string& result) const { // dump overlay properties result.append("OverlayProperties:\n"); diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index b95c619f75..7b04d6755a 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -53,6 +53,7 @@ #include <aidl/android/hardware/graphics/composer3/Composition.h> #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> #include <aidl/android/hardware/graphics/composer3/DisplayLuts.h> +#include <aidl/android/hardware/graphics/composer3/LutProperties.h> #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h> namespace android { @@ -90,11 +91,14 @@ public: aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness; using DisplayRequests = hal::DisplayRequest; using LayerRequests = std::unordered_map<HWC2::Layer*, hal::LayerRequest>; + using LutProperties = aidl::android::hardware::graphics::composer3::LutProperties; + using LayerLuts = HWC2::Display::LayerLuts; ChangedTypes changedTypes; DisplayRequests displayRequests; LayerRequests layerRequests; ClientTargetProperty clientTargetProperty; + LayerLuts layerLuts; }; struct HWCDisplayMode { @@ -311,18 +315,15 @@ public: virtual status_t setRefreshRateChangedCallbackDebugEnabled(PhysicalDisplayId, bool enabled) = 0; virtual status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, Fps frameInterval) = 0; - - // Composer 4.0 - virtual status_t getRequestedLuts( - PhysicalDisplayId, - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*) = 0; + // mapper + virtual HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() = 0; }; static inline bool operator==(const android::HWComposer::DeviceRequestedChanges& lhs, const android::HWComposer::DeviceRequestedChanges& rhs) { return lhs.changedTypes == rhs.changedTypes && lhs.displayRequests == rhs.displayRequests && lhs.layerRequests == rhs.layerRequests && - lhs.clientTargetProperty == rhs.clientTargetProperty; + lhs.clientTargetProperty == rhs.clientTargetProperty && lhs.layerLuts == rhs.layerLuts; } namespace impl { @@ -480,11 +481,8 @@ public: status_t notifyExpectedPresent(PhysicalDisplayId, TimePoint expectedPresentTime, Fps frameInterval) override; - // Composer 4.0 - status_t getRequestedLuts( - PhysicalDisplayId, - std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*) - override; + // get a mapper + HWC2::Display::LutFileDescriptorMapper& getLutFileDescriptorMapper() override; // for debugging ---------------------------------------------------------- void dump(std::string& out) const override; @@ -571,6 +569,8 @@ private: const size_t mMaxVirtualDisplayDimension; const bool mUpdateDeviceProductInfoOnHotplugReconnect; bool mEnableVrrTimeout; + + HWC2::Display::LutFileDescriptorMapper mLutFileDescriptorMapper; }; } // namespace impl diff --git a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp index ee1e07ae7d..056ecd78f4 100644 --- a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp @@ -1410,7 +1410,8 @@ Error HidlComposer::getClientTargetProperty( return Error::NONE; } -Error HidlComposer::getRequestedLuts(Display, std::vector<DisplayLuts::LayerLut>*) { +Error HidlComposer::getRequestedLuts(Display, std::vector<Layer>*, + std::vector<DisplayLuts::LayerLut>*) { return Error::NONE; } diff --git a/services/surfaceflinger/DisplayHardware/HidlComposerHal.h b/services/surfaceflinger/DisplayHardware/HidlComposerHal.h index 701a54bc66..1cc23d1409 100644 --- a/services/surfaceflinger/DisplayHardware/HidlComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/HidlComposerHal.h @@ -352,7 +352,7 @@ public: Error setRefreshRateChangedCallbackDebugEnabled(Display, bool) override; Error notifyExpectedPresent(Display, nsecs_t, int32_t) override; Error getRequestedLuts( - Display, + Display, std::vector<Layer>*, std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*) override; Error setLayerLuts(Display, Layer, diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 75121cba19..a821e3d494 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1654,6 +1654,22 @@ status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties outProperties->combinations.emplace_back(outCombination); } outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; + if (aidlProperties.lutProperties.has_value()) { + std::vector<gui::LutProperties> outLutProperties; + for (const auto& properties : aidlProperties.lutProperties.value()) { + gui::LutProperties currentProperties; + currentProperties.dimension = + static_cast<gui::LutProperties::Dimension>(properties->dimension); + currentProperties.size = properties->size; + currentProperties.samplingKeys.reserve(properties->samplingKeys.size()); + std::transform(properties->samplingKeys.cbegin(), properties->samplingKeys.cend(), + std::back_inserter(currentProperties.samplingKeys), [](const auto& val) { + return static_cast<gui::LutProperties::SamplingKey>(val); + }); + outLutProperties.push_back(std::move(currentProperties)); + } + outProperties->lutProperties.emplace(outLutProperties.begin(), outLutProperties.end()); + } return NO_ERROR; } diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h index f472d8fefe..615cc948ed 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h @@ -182,7 +182,7 @@ public: MOCK_METHOD(Error, notifyExpectedPresent, (Display, nsecs_t, int32_t)); MOCK_METHOD( Error, getRequestedLuts, - (Display, + (Display, std::vector<Layer>*, std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*)); MOCK_METHOD(Error, setLayerLuts, (Display, Layer, std::vector<aidl::android::hardware::graphics::composer3::Lut>&)); diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h index 5edd2cd9e3..53ed2e1f20 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h @@ -111,7 +111,7 @@ public: (aidl::android::hardware::graphics::composer3::OverlayProperties *), (const override)); MOCK_METHOD(hal::Error, getRequestedLuts, - (std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*), + ((HWC2::Display::LayerLuts*), (HWC2::Display::LutFileDescriptorMapper&)), (override)); }; |