From ed511efbdfac3408cb3ae237016f095fd64cebec Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Mon, 11 Oct 2021 15:09:51 -0700 Subject: Add frame timeline method to ASurfaceControl NDK. Bug: 198192003 Test: atest ASurfaceControlTest perfetto trace Change-Id: I04310bd9190cfc227ff5ba892c7187d3b8a20463 --- libs/gui/Surface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 353a91d062..20c41460d4 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1846,9 +1846,10 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) { ATRACE_CALL(); auto frameTimelineVsyncId = static_cast(va_arg(args, int64_t)); auto inputEventId = static_cast(va_arg(args, int32_t)); + auto startTimeNanos = static_cast(va_arg(args, int64_t)); ALOGV("Surface::%s", __func__); - return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId}); + return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId, startTimeNanos}); } bool Surface::transformToDisplayInverse() const { -- cgit v1.2.3-59-g8ed1b From 9c604e3c31869d1a7a1654ea791267a29b053966 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Fri, 18 Mar 2022 22:47:44 +0000 Subject: Polish up metadata propagation for native window Allow for native window apis to attempt to apply gralloc4 metadata whenever a buffer is queued onto a native window for dataspace and existing apis for HDR metadata. Motivation: 1. We are attempting to move to Gralloc 4 metadata as the source of truth for this information, rather than a separate side-channel. 2. ANativeWindow_setBuffersDataspace is a public api, but gralloc4 metadata is not public, so the only way to keep the gralloc4 metadata in sync for dataspace is to intercept on Surface. 3. HDR Metadata may be applied on eglSurface and vkSwapchain, which must be propagated to gralloc4 metadata to ensure consistency. 4. None of the plumbing for setting gralloc4 metadata existed, so now's a good time as any to add the plumbing so that we can start at least best-effort using this metadata infrastructure in the framework and so that vendor's don't have to reinvent setting metadata. Bug: 210498094 Test: builds, boots Change-Id: I6d19dc4ceca8fa885363faf84f57885e58e88240 --- libs/gui/Surface.cpp | 13 +++++++ libs/gui/include/gui/HdrMetadata.h | 23 ++++++++++++ libs/gui/include/gui/Surface.h | 7 ++++ libs/ui/Gralloc4.cpp | 61 ++++++++++++++++++++++++++++++++ libs/ui/GraphicBufferMapper.cpp | 24 +++++++++++++ libs/ui/include/ui/Gralloc.h | 21 ++++++++++- libs/ui/include/ui/Gralloc4.h | 18 +++++++++- libs/ui/include/ui/GraphicBufferMapper.h | 7 ++++ libs/ui/include/ui/GraphicTypes.h | 18 ++++++++++ 9 files changed, 190 insertions(+), 2 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 20c41460d4..1fb11e0675 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1096,6 +1096,17 @@ void Surface::getQueueBufferInputLocked(android_native_buffer_t* buffer, int fen *out = input; } +void Surface::applyGrallocMetadataLocked( + android_native_buffer_t* buffer, + const IGraphicBufferProducer::QueueBufferInput& queueBufferInput) { + ATRACE_CALL(); + auto& mapper = GraphicBufferMapper::get(); + mapper.setDataspace(buffer->handle, static_cast(queueBufferInput.dataSpace)); + mapper.setSmpte2086(buffer->handle, queueBufferInput.getHdrMetadata().getSmpte2086()); + mapper.setCta861_3(buffer->handle, queueBufferInput.getHdrMetadata().getCta8613()); + mapper.setSmpte2094_40(buffer->handle, queueBufferInput.getHdrMetadata().getHdr10Plus()); +} + void Surface::onBufferQueuedLocked(int slot, sp fence, const IGraphicBufferProducer::QueueBufferOutput& output) { mDequeuedSlots.erase(slot); @@ -1166,9 +1177,11 @@ int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { IGraphicBufferProducer::QueueBufferOutput output; IGraphicBufferProducer::QueueBufferInput input; getQueueBufferInputLocked(buffer, fenceFd, mTimestamp, &input); + applyGrallocMetadataLocked(buffer, input); sp fence = input.fence; nsecs_t now = systemTime(); + status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); mLastQueueDuration = systemTime() - now; if (err != OK) { diff --git a/libs/gui/include/gui/HdrMetadata.h b/libs/gui/include/gui/HdrMetadata.h index 0bdffac5c6..98a07a3c07 100644 --- a/libs/gui/include/gui/HdrMetadata.h +++ b/libs/gui/include/gui/HdrMetadata.h @@ -17,6 +17,8 @@ #pragma once #include +#include +#include #include #include @@ -43,6 +45,27 @@ struct HdrMetadata : public LightFlattenable { status_t flatten(void* buffer, size_t size) const; status_t unflatten(void const* buffer, size_t size); + std::optional getSmpte2086() const { + if (validTypes & Type::SMPTE2086) { + return ui::translate(smpte2086); + } + return {}; + } + + std::optional getCta8613() const { + if (validTypes & Type::CTA861_3) { + return ui::translate(cta8613); + } + return {}; + } + + std::optional> getHdr10Plus() const { + if (validTypes & Type::HDR10PLUS) { + return hdr10plus; + } + return {}; + } + bool operator==(const HdrMetadata& rhs) const; bool operator!=(const HdrMetadata& rhs) const { return !(*this == rhs); } }; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 40d096e1e5..5fe308cf9f 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -398,6 +398,13 @@ protected: void getQueueBufferInputLocked(android_native_buffer_t* buffer, int fenceFd, nsecs_t timestamp, IGraphicBufferProducer::QueueBufferInput* out); + // For easing in adoption of gralloc4 metadata by vendor components, as well as for supporting + // the public ANativeWindow api, allow setting relevant metadata when queueing a buffer through + // a native window + void applyGrallocMetadataLocked( + android_native_buffer_t* buffer, + const IGraphicBufferProducer::QueueBufferInput& queueBufferInput); + void onBufferQueuedLocked(int slot, sp fence, const IGraphicBufferProducer::QueueBufferOutput& output); diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 1a42642838..8de91dac61 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -524,6 +525,37 @@ status_t Gralloc4Mapper::get(buffer_handle_t bufferHandle, const MetadataType& m return decodeFunction(vec, outMetadata); } +template +status_t Gralloc4Mapper::set(buffer_handle_t bufferHandle, const MetadataType& metadataType, + const T& metadata, EncodeFunction encodeFunction) const { + hidl_vec encodedMetadata; + if (const status_t status = encodeFunction(metadata, &encodedMetadata); status != OK) { + ALOGE("Encoding metadata(%s) failed with %d", metadataType.name.c_str(), status); + return status; + } + hidl_vec vec; + auto ret = + mMapper->set(const_cast(bufferHandle), metadataType, encodedMetadata); + + const Error error = ret.withDefault(kTransactionError); + switch (error) { + case Error::BAD_DESCRIPTOR: + case Error::BAD_BUFFER: + case Error::BAD_VALUE: + case Error::NO_RESOURCES: + ALOGE("set(%s, %" PRIu64 ", ...) failed with %d", metadataType.name.c_str(), + metadataType.value, error); + break; + // It is not an error to attempt to set metadata that a particular gralloc implementation + // happens to not support. + case Error::UNSUPPORTED: + case Error::NONE: + break; + } + + return static_cast(error); +} + status_t Gralloc4Mapper::getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) const { return get(bufferHandle, gralloc4::MetadataType_BufferId, gralloc4::decodeBufferId, outBufferId); @@ -673,6 +705,12 @@ status_t Gralloc4Mapper::getDataspace(buffer_handle_t bufferHandle, return NO_ERROR; } +status_t Gralloc4Mapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const { + return set(bufferHandle, gralloc4::MetadataType_Dataspace, + static_cast(dataspace), + gralloc4::encodeDataspace); +} + status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const { return get(bufferHandle, gralloc4::MetadataType_BlendMode, gralloc4::decodeBlendMode, @@ -685,24 +723,47 @@ status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle, outSmpte2086); } +status_t Gralloc4Mapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2086, smpte2086, + gralloc4::encodeSmpte2086); +} + status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) const { return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3, outCta861_3); } +status_t Gralloc4Mapper::setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) const { + return set(bufferHandle, gralloc4::MetadataType_Cta861_3, cta861_3, gralloc4::encodeCta861_3); +} + status_t Gralloc4Mapper::getSmpte2094_40( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const { return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40, outSmpte2094_40); } +status_t Gralloc4Mapper::setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2094_40, smpte2094_40, + gralloc4::encodeSmpte2094_40); +} + status_t Gralloc4Mapper::getSmpte2094_10( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) const { return get(bufferHandle, gralloc4::MetadataType_Smpte2094_10, gralloc4::decodeSmpte2094_10, outSmpte2094_10); } +status_t Gralloc4Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2094_10, smpte2094_10, + gralloc4::encodeSmpte2094_10); +} + template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 82d6cd5ba3..a98e697eb1 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -281,6 +281,10 @@ status_t GraphicBufferMapper::getDataspace(buffer_handle_t bufferHandle, return mMapper->getDataspace(bufferHandle, outDataspace); } +status_t GraphicBufferMapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) { + return mMapper->setDataspace(bufferHandle, dataspace); +} + status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) { return mMapper->getBlendMode(bufferHandle, outBlendMode); @@ -291,21 +295,41 @@ status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle, return mMapper->getSmpte2086(bufferHandle, outSmpte2086); } +status_t GraphicBufferMapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) { + return mMapper->setSmpte2086(bufferHandle, smpte2086); +} + status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) { return mMapper->getCta861_3(bufferHandle, outCta861_3); } +status_t GraphicBufferMapper::setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) { + return mMapper->setCta861_3(bufferHandle, cta861_3); +} + status_t GraphicBufferMapper::getSmpte2094_40( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) { return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40); } +status_t GraphicBufferMapper::setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) { + return mMapper->setSmpte2094_40(bufferHandle, smpte2094_40); +} + status_t GraphicBufferMapper::getSmpte2094_10( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) { return mMapper->getSmpte2094_10(bufferHandle, outSmpte2094_10); } +status_t GraphicBufferMapper::setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) { + return mMapper->setSmpte2094_10(bufferHandle, smpte2094_10); +} + status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index 753b0a6794..6101d4b43b 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -161,6 +161,10 @@ public: ui::Dataspace* /*outDataspace*/) const { return INVALID_OPERATION; } + virtual status_t setDataspace(buffer_handle_t /*bufferHandle*/, + ui::Dataspace /*dataspace*/) const { + return INVALID_OPERATION; + } virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, ui::BlendMode* /*outBlendMode*/) const { return INVALID_OPERATION; @@ -169,21 +173,36 @@ public: std::optional* /*outSmpte2086*/) const { return INVALID_OPERATION; } + virtual status_t setSmpte2086(buffer_handle_t /*bufferHandle*/, + std::optional /*smpte2086*/) const { + return INVALID_OPERATION; + } virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, std::optional* /*outCta861_3*/) const { return INVALID_OPERATION; } + virtual status_t setCta861_3(buffer_handle_t /*bufferHandle*/, + std::optional /*cta861_3*/) const { + return INVALID_OPERATION; + } virtual status_t getSmpte2094_40( buffer_handle_t /*bufferHandle*/, std::optional>* /*outSmpte2094_40*/) const { return INVALID_OPERATION; } + virtual status_t setSmpte2094_40(buffer_handle_t /*bufferHandle*/, + std::optional> /*smpte2094_40*/) const { + return INVALID_OPERATION; + } virtual status_t getSmpte2094_10( buffer_handle_t /*bufferHandle*/, std::optional>* /*outSmpte2094_10*/) const { return INVALID_OPERATION; } - + virtual status_t setSmpte2094_10(buffer_handle_t /*bufferHandle*/, + std::optional> /*smpte2094_10*/) const { + return INVALID_OPERATION; + } virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, uint32_t /*layerCount*/, uint64_t /*usage*/, diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index fe387090cc..cf023c9bcc 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -102,16 +102,24 @@ public: status_t getPlaneLayouts(buffer_handle_t bufferHandle, std::vector* outPlaneLayouts) const override; status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; + status_t setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const override; status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086) const override; + status_t setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) const override; status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) const override; + status_t setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) const override; status_t getSmpte2094_40(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const override; + status_t setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) const override; status_t getSmpte2094_10(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) const override; - + status_t setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) const override; status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t* outPixelFormatFourCC) const override; @@ -157,6 +165,8 @@ private: template using DecodeFunction = status_t (*)(const hardware::hidl_vec& input, T* output); + template + using EncodeFunction = status_t (*)(const T& input, hardware::hidl_vec* output); template status_t get( @@ -164,6 +174,12 @@ private: const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, DecodeFunction decodeFunction, T* outMetadata) const; + template + status_t set( + buffer_handle_t bufferHandle, + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, + const T& metadata, EncodeFunction encodeFunction) const; + template status_t getDefault( uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 257c155efd..507fa355a4 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -121,13 +121,20 @@ public: status_t getPlaneLayouts(buffer_handle_t bufferHandle, std::vector* outPlaneLayouts); status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); + status_t setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace); status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086); + status_t setSmpte2086(buffer_handle_t bufferHandle, std::optional smpte2086); status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); + status_t setCta861_3(buffer_handle_t bufferHandle, std::optional cta861_3); status_t getSmpte2094_40(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40); + status_t setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40); status_t getSmpte2094_10(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10); + status_t setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10); /** * Gets the default metadata for a gralloc buffer allocated with the given parameters. diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index 4bdacb0883..8661c36676 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -62,5 +62,23 @@ using ChromaSiting = aidl::android::hardware::graphics::common::ChromaSiting; using Compression = aidl::android::hardware::graphics::common::Compression; using Interlaced = aidl::android::hardware::graphics::common::Interlaced; +inline aidl::android::hardware::graphics::common::XyColor translate(const android_xy_color& color) { + return aidl::android::hardware::graphics::common::XyColor{.x = color.x, .y = color.y}; +} + +inline Smpte2086 translate(const android_smpte2086_metadata& metadata) { + return Smpte2086{.primaryRed = translate(metadata.displayPrimaryRed), + .primaryGreen = translate(metadata.displayPrimaryGreen), + .primaryBlue = translate(metadata.displayPrimaryBlue), + .whitePoint = translate(metadata.whitePoint), + .maxLuminance = metadata.maxLuminance, + .minLuminance = metadata.minLuminance}; +} + +inline Cta861_3 translate(const android_cta861_3_metadata& metadata) { + return Cta861_3{.maxContentLightLevel = metadata.maxContentLightLevel, + .maxFrameAverageLightLevel = metadata.maxFrameAverageLightLevel}; +} + } // namespace ui } // namespace android -- cgit v1.2.3-59-g8ed1b From b5cb7c155ff3ac1f8fc6d946fc1faf01ce8d8ed5 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Mon, 14 Feb 2022 14:26:04 -0800 Subject: Migrate display related methods to AIDL This migrates display related methods from ISurfaceComposer.h to the AIDL interface. Bug: 219574942 Test: manual Merged-In: I11f011ce61bdd6dfbd8e0f1a1af8925820e3de58 Change-Id: I11f011ce61bdd6dfbd8e0f1a1af8925820e3de58 (cherry picked from commit 07e723660ca6265844be1ebd8c4696977151eeba) --- libs/gui/ISurfaceComposer.cpp | 116 --------------------- libs/gui/Surface.cpp | 5 +- libs/gui/SurfaceComposerClient.cpp | 43 ++++++-- libs/gui/aidl/android/gui/ISurfaceComposer.aidl | 22 ++++ libs/gui/include/gui/ISurfaceComposer.h | 44 +------- libs/gui/include/private/gui/ComposerServiceAIDL.h | 21 ++++ libs/gui/tests/Surface_test.cpp | 10 +- services/surfaceflinger/SurfaceFlinger.cpp | 75 +++++++++++-- services/surfaceflinger/SurfaceFlinger.h | 34 +++++- 9 files changed, 185 insertions(+), 185 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 5532c6e747..2da48b81f6 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -226,81 +226,6 @@ public: return result; } - sp createDisplay(const String8& displayName, bool secure) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t status = data.writeString8(displayName); - if (status) { - return nullptr; - } - status = data.writeBool(secure); - if (status) { - return nullptr; - } - - status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply); - if (status) { - return nullptr; - } - sp display; - status = reply.readNullableStrongBinder(&display); - if (status) { - return nullptr; - } - return display; - } - - void destroyDisplay(const sp& display) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply); - } - - std::vector getPhysicalDisplayIds() const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) == - NO_ERROR) { - std::vector rawIds; - if (reply.readUint64Vector(&rawIds) == NO_ERROR) { - std::vector displayIds; - displayIds.reserve(rawIds.size()); - - for (const uint64_t rawId : rawIds) { - if (const auto id = DisplayId::fromValue(rawId)) { - displayIds.push_back(*id); - } - } - return displayIds; - } - } - - return {}; - } - - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId* displayId) const override { - Parcel data, reply; - SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor()); - SAFE_PARCEL(remote()->transact, BnSurfaceComposer::GET_PRIMARY_PHYSICAL_DISPLAY_ID, data, - &reply); - uint64_t rawId; - SAFE_PARCEL(reply.readUint64, &rawId); - if (const auto id = DisplayId::fromValue(rawId)) { - *displayId = *id; - return NO_ERROR; - } - return NAME_NOT_FOUND; - } - - sp getPhysicalDisplayToken(PhysicalDisplayId displayId) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeUint64(displayId.value); - remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply); - return reply.readStrongBinder(); - } - void setPowerMode(const sp& display, int mode) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -1467,29 +1392,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeStrongBinder(IInterface::asBinder(connection)); return NO_ERROR; } - case CREATE_DISPLAY: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - String8 displayName; - SAFE_PARCEL(data.readString8, &displayName); - bool secure = false; - SAFE_PARCEL(data.readBool, &secure); - sp display = createDisplay(displayName, secure); - SAFE_PARCEL(reply->writeStrongBinder, display); - return NO_ERROR; - } - case DESTROY_DISPLAY: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = data.readStrongBinder(); - destroyDisplay(display); - return NO_ERROR; - } - case GET_PHYSICAL_DISPLAY_TOKEN: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - const auto id = DisplayId::fromValue(data.readUint64()); - if (!id) return BAD_VALUE; - reply->writeStrongBinder(getPhysicalDisplayToken(*id)); - return NO_ERROR; - } case GET_DISPLAY_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); ui::DisplayState state; @@ -1826,24 +1728,6 @@ status_t BnSurfaceComposer::onTransact( } return error; } - case GET_PHYSICAL_DISPLAY_IDS: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - std::vector ids = getPhysicalDisplayIds(); - std::vector rawIds(ids.size()); - std::transform(ids.begin(), ids.end(), rawIds.begin(), - [](PhysicalDisplayId id) { return id.value; }); - return reply->writeUint64Vector(rawIds); - } - case GET_PRIMARY_PHYSICAL_DISPLAY_ID: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - PhysicalDisplayId id; - status_t result = getPrimaryPhysicalDisplayId(&id); - if (result != NO_ERROR) { - ALOGE("getPrimaryPhysicalDisplayId: Failed to get id"); - return result; - } - return reply->writeUint64(id.value); - } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); Rect samplingArea; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 1fb11e0675..ff8f529385 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -45,6 +45,7 @@ #include #include #include +#include namespace android { @@ -343,7 +344,7 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber, status_t Surface::getWideColorSupport(bool* supported) { ATRACE_CALL(); - const sp display = composerService()->getInternalDisplayToken(); + const sp display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); if (display == nullptr) { return NAME_NOT_FOUND; } @@ -356,7 +357,7 @@ status_t Surface::getWideColorSupport(bool* supported) { status_t Surface::getHdrSupport(bool* supported) { ATRACE_CALL(); - const sp display = composerService()->getInternalDisplayToken(); + const sp display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); if (display == nullptr) { return NAME_NOT_FOUND; } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 6c197c457c..ec7a9483b6 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1022,32 +1022,59 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay // --------------------------------------------------------------------------- sp SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) { - return ComposerService::getComposerService()->createDisplay(displayName, - secure); + sp display = nullptr; + binder::Status status = + ComposerServiceAIDL::getComposerService()->createDisplay(std::string( + displayName.string()), + secure, &display); + return status.isOk() ? display : nullptr; } void SurfaceComposerClient::destroyDisplay(const sp& display) { - return ComposerService::getComposerService()->destroyDisplay(display); + ComposerServiceAIDL::getComposerService()->destroyDisplay(display); } std::vector SurfaceComposerClient::getPhysicalDisplayIds() { - return ComposerService::getComposerService()->getPhysicalDisplayIds(); + std::vector displayIds; + std::vector physicalDisplayIds; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPhysicalDisplayIds(&displayIds); + if (status.isOk()) { + physicalDisplayIds.reserve(displayIds.size()); + for (auto item : displayIds) { + auto id = DisplayId::fromValue(static_cast(item)); + physicalDisplayIds.push_back(*id); + } + } + return physicalDisplayIds; } status_t SurfaceComposerClient::getPrimaryPhysicalDisplayId(PhysicalDisplayId* id) { - return ComposerService::getComposerService()->getPrimaryPhysicalDisplayId(id); + int64_t displayId; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPrimaryPhysicalDisplayId(&displayId); + if (status.isOk()) { + *id = *DisplayId::fromValue(static_cast(displayId)); + } + return status.transactionError(); } std::optional SurfaceComposerClient::getInternalDisplayId() { - return ComposerService::getComposerService()->getInternalDisplayId(); + ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance(); + return instance.getInternalDisplayId(); } sp SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) { - return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId); + sp display = nullptr; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPhysicalDisplayToken(displayId.value, + &display); + return status.isOk() ? display : nullptr; } sp SurfaceComposerClient::getInternalDisplayToken() { - return ComposerService::getComposerService()->getInternalDisplayToken(); + ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance(); + return instance.getInternalDisplayToken(); } void SurfaceComposerClient::Transaction::setAnimationTransaction() { diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl index 07921a59a5..345c47d5b9 100644 --- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl +++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl @@ -22,6 +22,28 @@ import android.gui.IScreenCaptureListener; /** @hide */ interface ISurfaceComposer { + + /* create a virtual display + * requires ACCESS_SURFACE_FLINGER permission. + */ + @nullable IBinder createDisplay(@utf8InCpp String displayName, boolean secure); + + /* destroy a virtual display + * requires ACCESS_SURFACE_FLINGER permission. + */ + void destroyDisplay(IBinder display); + + /* get stable IDs for connected physical displays. + */ + long[] getPhysicalDisplayIds(); + + long getPrimaryPhysicalDisplayId(); + + /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a + * DisplayEventReceiver hotplug event. + */ + @nullable IBinder getPhysicalDisplayToken(long displayId); + /** * Capture the specified screen. This requires READ_FRAME_BUFFER * permission. This function will fail if there is a secure window on diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index b11e6748f0..91d44da03d 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -138,40 +138,6 @@ public: VsyncSource vsyncSource = eVsyncSourceApp, EventRegistrationFlags eventRegistration = {}) = 0; - /* create a virtual display - * requires ACCESS_SURFACE_FLINGER permission. - */ - virtual sp createDisplay(const String8& displayName, - bool secure) = 0; - - /* destroy a virtual display - * requires ACCESS_SURFACE_FLINGER permission. - */ - virtual void destroyDisplay(const sp& display) = 0; - - /* get stable IDs for connected physical displays. - */ - virtual std::vector getPhysicalDisplayIds() const = 0; - - virtual status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const = 0; - - // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. - std::optional getInternalDisplayId() const { - const auto displayIds = getPhysicalDisplayIds(); - return displayIds.empty() ? std::nullopt : std::make_optional(displayIds.front()); - } - - /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a - * DisplayEventReceiver hotplug event. - */ - virtual sp getPhysicalDisplayToken(PhysicalDisplayId displayId) const = 0; - - // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. - sp getInternalDisplayToken() const { - const auto displayId = getInternalDisplayId(); - return displayId ? getPhysicalDisplayToken(*displayId) : nullptr; - } - /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, const Vector& state, @@ -597,9 +563,9 @@ public: CREATE_CONNECTION, GET_STATIC_DISPLAY_INFO, CREATE_DISPLAY_EVENT_CONNECTION, - CREATE_DISPLAY, - DESTROY_DISPLAY, - GET_PHYSICAL_DISPLAY_TOKEN, + CREATE_DISPLAY, // Deprecated. Autogenerated by .aidl now. + DESTROY_DISPLAY, // Deprecated. Autogenerated by .aidl now. + GET_PHYSICAL_DISPLAY_TOKEN, // Deprecated. Autogenerated by .aidl now. SET_TRANSACTION_STATE, AUTHENTICATE_SURFACE, GET_SUPPORTED_FRAME_TIMESTAMPS, @@ -627,7 +593,7 @@ public: GET_PROTECTED_CONTENT_SUPPORT, IS_WIDE_COLOR_DISPLAY, GET_DISPLAY_NATIVE_PRIMARIES, - GET_PHYSICAL_DISPLAY_IDS, + GET_PHYSICAL_DISPLAY_IDS, // Deprecated. Autogenerated by .aidl now. ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, SET_DESIRED_DISPLAY_MODE_SPECS, @@ -659,7 +625,7 @@ public: REMOVE_TUNNEL_MODE_ENABLED_LISTENER, ADD_WINDOW_INFOS_LISTENER, REMOVE_WINDOW_INFOS_LISTENER, - GET_PRIMARY_PHYSICAL_DISPLAY_ID, + GET_PRIMARY_PHYSICAL_DISPLAY_ID, // Deprecated. Autogenerated by .aidl now. GET_DISPLAY_DECORATION_SUPPORT, GET_BOOT_DISPLAY_MODE_SUPPORT, SET_BOOT_DISPLAY_MODE, diff --git a/libs/gui/include/private/gui/ComposerServiceAIDL.h b/libs/gui/include/private/gui/ComposerServiceAIDL.h index fee37eefe0..b32cf2a9c2 100644 --- a/libs/gui/include/private/gui/ComposerServiceAIDL.h +++ b/libs/gui/include/private/gui/ComposerServiceAIDL.h @@ -50,6 +50,27 @@ public: // Get a connection to the Composer Service. This will block until // a connection is established. Returns null if permission is denied. static sp getComposerService(); + + // the following two methods are moved from ISurfaceComposer.h + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + std::optional getInternalDisplayId() const { + std::vector displayIds; + binder::Status status = mComposerService->getPhysicalDisplayIds(&displayIds); + return (!status.isOk() || displayIds.empty()) + ? std::nullopt + : DisplayId::fromValue( + static_cast(displayIds.front())); + } + + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + sp getInternalDisplayToken() const { + const auto displayId = getInternalDisplayId(); + if (!displayId) return nullptr; + sp display; + binder::Status status = + mComposerService->getPhysicalDisplayToken(displayId->value, &display); + return status.isOk() ? display : nullptr; + } }; // --------------------------------------------------------------------------- diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index a885e926a3..07ac2d4065 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -260,9 +260,7 @@ TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersDontSucceed) { sp anw(mSurface); // Verify the screenshot works with no protected buffers. - sp sf(ComposerService::getComposerService()); - - const sp display = sf->getInternalDisplayToken(); + const sp display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); ASSERT_FALSE(display == nullptr); DisplayCaptureArgs captureArgs; @@ -696,12 +694,6 @@ public: ISurfaceComposer::VsyncSource, ISurfaceComposer::EventRegistrationFlags) override { return nullptr; } - sp createDisplay(const String8& /*displayName*/, - bool /*secure*/) override { return nullptr; } - void destroyDisplay(const sp& /*display */) override {} - std::vector getPhysicalDisplayIds() const override { return {}; } - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const override { return NO_ERROR; } - sp getPhysicalDisplayToken(PhysicalDisplayId) const override { return nullptr; } status_t setTransactionState(const FrameTimelineInfo& /*frameTimelineInfo*/, const Vector& /*state*/, const Vector& /*displays*/, uint32_t /*flags*/, diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 4c830307e8..ff977b226a 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5467,8 +5467,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // access to SF. case BOOT_FINISHED: case CLEAR_ANIMATION_FRAME_STATS: - case CREATE_DISPLAY: - case DESTROY_DISPLAY: case GET_ANIMATION_FRAME_STATS: case OVERRIDE_HDR_TYPES: case GET_HDR_CAPABILITIES: @@ -5490,7 +5488,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: case NOTIFY_POWER_BOOST: case SET_GLOBAL_SHADOW_SETTINGS: - case GET_PRIMARY_PHYSICAL_DISPLAY_ID: case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary // permission dynamically. Don't use the permission cache for this check. @@ -5521,8 +5518,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case AUTHENTICATE_SURFACE: case GET_ACTIVE_COLOR_MODE: case GET_ACTIVE_DISPLAY_MODE: - case GET_PHYSICAL_DISPLAY_IDS: - case GET_PHYSICAL_DISPLAY_TOKEN: case GET_DISPLAY_COLOR_MODES: case GET_DISPLAY_NATIVE_PRIMARIES: case GET_STATIC_DISPLAY_INFO: @@ -5608,10 +5603,15 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { } return PERMISSION_DENIED; } + case CREATE_DISPLAY: + case DESTROY_DISPLAY: + case GET_PRIMARY_PHYSICAL_DISPLAY_ID: + case GET_PHYSICAL_DISPLAY_IDS: + case GET_PHYSICAL_DISPLAY_TOKEN: case CAPTURE_LAYERS: case CAPTURE_DISPLAY: case CAPTURE_DISPLAY_BY_ID: - LOG_FATAL("Deprecated opcode: %d", code); + LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); return PERMISSION_DENIED; } @@ -7316,6 +7316,59 @@ bool SurfaceFlinger::commitCreatedLayers() { } // gui::ISurfaceComposer + +binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, + sp* outDisplay) { + status_t status = checkAccessPermission(); + if (status == OK) { + String8 displayName8 = String8::format("%s", displayName.c_str()); + *outDisplay = mFlinger->createDisplay(displayName8, secure); + return binder::Status::ok(); + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::destroyDisplay(const sp& display) { + status_t status = checkAccessPermission(); + if (status == OK) { + mFlinger->destroyDisplay(display); + return binder::Status::ok(); + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector* outDisplayIds) { + std::vector physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); + std::vector displayIds; + displayIds.reserve(physicalDisplayIds.size()); + for (auto item : physicalDisplayIds) { + displayIds.push_back(static_cast(item.value)); + } + *outDisplayIds = displayIds; + return binder::Status::ok(); +} + +binder::Status SurfaceComposerAIDL::getPrimaryPhysicalDisplayId(int64_t* outDisplayId) { + status_t status = checkAccessPermission(); + if (status != OK) { + return binder::Status::fromStatusT(status); + } + + PhysicalDisplayId id; + status = mFlinger->getPrimaryPhysicalDisplayId(&id); + if (status == NO_ERROR) { + *outDisplayId = id.value; + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, + sp* outDisplay) { + const auto id = DisplayId::fromValue(static_cast(displayId)); + *outDisplay = mFlinger->getPhysicalDisplayToken(*id); + return binder::Status::ok(); +} + binder::Status SurfaceComposerAIDL::captureDisplay( const DisplayCaptureArgs& args, const sp& captureListener) { status_t status = mFlinger->captureDisplay(args, captureListener); @@ -7342,6 +7395,16 @@ binder::Status SurfaceComposerAIDL::captureLayers( return binder::Status::fromStatusT(status); } +status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { + if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { + IPCThreadState* ipc = IPCThreadState::self(); + ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), + ipc->getCallingUid()); + return PERMISSION_DENIED; + } + return OK; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 97b0e8db5c..bc3d83e2b0 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -518,17 +518,30 @@ private: bool callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache = true) EXCLUDES(mStateLock); + // the following two methods are moved from ISurfaceComposer.h + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + std::optional getInternalDisplayId() const { + const auto displayIds = getPhysicalDisplayIds(); + return displayIds.empty() ? std::nullopt : std::make_optional(displayIds.front()); + } + + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + sp getInternalDisplayToken() const { + const auto displayId = getInternalDisplayId(); + return displayId ? getPhysicalDisplayToken(*displayId) : nullptr; + } + // Implements ISurfaceComposer sp createConnection() override; - sp createDisplay(const String8& displayName, bool secure) override; - void destroyDisplay(const sp& displayToken) override; - std::vector getPhysicalDisplayIds() const override EXCLUDES(mStateLock) { + sp createDisplay(const String8& displayName, bool secure); + void destroyDisplay(const sp& displayToken); + std::vector getPhysicalDisplayIds() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getPhysicalDisplayIdsLocked(); } - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const override EXCLUDES(mStateLock); + status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const EXCLUDES(mStateLock); - sp getPhysicalDisplayToken(PhysicalDisplayId displayId) const override; + sp getPhysicalDisplayToken(PhysicalDisplayId displayId) const; status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo, const Vector& state, const Vector& displays, uint32_t flags, @@ -1438,12 +1451,23 @@ class SurfaceComposerAIDL : public gui::BnSurfaceComposer { public: SurfaceComposerAIDL(sp sf) { mFlinger = sf; } + binder::Status createDisplay(const std::string& displayName, bool secure, + sp* outDisplay) override; + binder::Status destroyDisplay(const sp& display) override; + binder::Status getPhysicalDisplayIds(std::vector* outDisplayIds) override; + binder::Status getPrimaryPhysicalDisplayId(int64_t* outDisplayId) override; + binder::Status getPhysicalDisplayToken(int64_t displayId, sp* outDisplay) override; + binder::Status captureDisplay(const DisplayCaptureArgs&, const sp&) override; binder::Status captureDisplayById(int64_t, const sp&) override; binder::Status captureLayers(const LayerCaptureArgs&, const sp&) override; +private: + static const constexpr bool kUsePermissionCache = true; + status_t checkAccessPermission(bool usePermissionCache = kUsePermissionCache); + private: sp mFlinger; }; -- cgit v1.2.3-59-g8ed1b From 694aeffba34baf6651833c56e18a4c5c6c8a25c0 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Tue, 15 Feb 2022 10:43:00 -0800 Subject: Migrate display related methods to AIDL part 2 This migrates more display related methods with simple arguments from ISurfaceComposer.h to the new AIDL interface. Bug: 219574942 Test: atest SurfaceFlinger_test libsurfaceflinger_unittest libgui_test Merged-In: I57f428f6934e784cb234704ad89ef22218e441b4 Change-Id: I57f428f6934e784cb234704ad89ef22218e441b4 --- libs/gui/ISurfaceComposer.cpp | 366 --------------------- libs/gui/Surface.cpp | 8 +- libs/gui/SurfaceComposerClient.cpp | 45 ++- libs/gui/aidl/android/gui/ISurfaceComposer.aidl | 106 ++++++ libs/gui/include/gui/ISurfaceComposer.h | 133 +------- libs/gui/include/gui/Surface.h | 5 + libs/gui/include/private/gui/ComposerServiceAIDL.h | 3 +- libs/gui/tests/Surface_test.cpp | 31 +- services/surfaceflinger/SurfaceFlinger.cpp | 131 ++++++-- services/surfaceflinger/SurfaceFlinger.h | 43 ++- .../surfaceflinger/tests/BootDisplayMode_test.cpp | 15 +- 11 files changed, 315 insertions(+), 571 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 2da48b81f6..26b31252f3 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -226,14 +226,6 @@ public: return result; } - void setPowerMode(const sp& display, int mode) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(display); - data.writeInt32(mode); - remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply); - } - status_t getDisplayState(const sp& display, ui::DisplayState* state) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -333,29 +325,6 @@ public: return static_cast(reply.readInt32()); } - // TODO(b/213909104) : Add unit tests to verify surface flinger boot time APIs - status_t getBootDisplayModeSupport(bool* outSupport) const override { - Parcel data, reply; - status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (error != NO_ERROR) { - ALOGE("getBootDisplayModeSupport: failed to write interface token: %d", error); - return error; - } - error = remote()->transact(BnSurfaceComposer::GET_BOOT_DISPLAY_MODE_SUPPORT, data, &reply); - if (error != NO_ERROR) { - ALOGE("getBootDisplayModeSupport: failed to transact: %d", error); - return error; - } - bool support; - error = reply.readBool(&support); - if (error != NO_ERROR) { - ALOGE("getBootDisplayModeSupport: failed to read support: %d", error); - return error; - } - *outSupport = support; - return NO_ERROR; - } - status_t setBootDisplayMode(const sp& display, ui::DisplayModeId displayModeId) override { Parcel data, reply; @@ -381,73 +350,6 @@ public: return result; } - status_t clearBootDisplayMode(const sp& display) override { - Parcel data, reply; - status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (result != NO_ERROR) { - ALOGE("clearBootDisplayMode failed to writeInterfaceToken: %d", result); - return result; - } - result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("clearBootDisplayMode failed to writeStrongBinder: %d", result); - return result; - } - result = remote()->transact(BnSurfaceComposer::CLEAR_BOOT_DISPLAY_MODE, data, &reply); - if (result != NO_ERROR) { - ALOGE("clearBootDisplayMode failed to transact: %d", result); - } - return result; - } - - void setAutoLowLatencyMode(const sp& display, bool on) override { - Parcel data, reply; - status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result); - return; - } - - result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result); - return; - } - result = data.writeBool(on); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result); - return; - } - result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to transact: %d", result); - return; - } - } - - void setGameContentType(const sp& display, bool on) override { - Parcel data, reply; - status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to writeInterfaceToken: %d", result); - return; - } - result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to writeStrongBinder: %d", result); - return; - } - result = data.writeBool(on); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to writeBool: %d", result); - return; - } - result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to transact: %d", result); - } - } - status_t clearAnimationFrameStats() override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -722,26 +624,6 @@ public: return error; } - status_t isWideColorDisplay(const sp& token, - bool* outIsWideColorDisplay) const override { - Parcel data, reply; - status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (error != NO_ERROR) { - return error; - } - error = data.writeStrongBinder(token); - if (error != NO_ERROR) { - return error; - } - - error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply); - if (error != NO_ERROR) { - return error; - } - error = reply.readBool(outIsWideColorDisplay); - return error; - } - status_t addRegionSamplingListener(const Rect& samplingArea, const sp& stopLayerHandle, const sp& listener) override { Parcel data, reply; @@ -974,109 +856,6 @@ public: return reply.readInt32(); } - status_t getDisplayBrightnessSupport(const sp& displayToken, - bool* outSupport) const override { - Parcel data, reply; - status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (error != NO_ERROR) { - ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error); - return error; - } - error = data.writeStrongBinder(displayToken); - if (error != NO_ERROR) { - ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error); - return error; - } - error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply); - if (error != NO_ERROR) { - ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error); - return error; - } - bool support; - error = reply.readBool(&support); - if (error != NO_ERROR) { - ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error); - return error; - } - *outSupport = support; - return NO_ERROR; - } - - status_t setDisplayBrightness(const sp& displayToken, - const gui::DisplayBrightness& brightness) override { - Parcel data, reply; - status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to write interface token: %d", error); - return error; - } - error = data.writeStrongBinder(displayToken); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to write display token: %d", error); - return error; - } - error = data.writeParcelable(brightness); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to write brightness: %d", error); - return error; - } - error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to transact: %d", error); - return error; - } - return NO_ERROR; - } - - status_t addHdrLayerInfoListener(const sp& displayToken, - const sp& listener) override { - Parcel data, reply; - SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor()); - SAFE_PARCEL(data.writeStrongBinder, displayToken); - SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener)); - const status_t error = - remote()->transact(BnSurfaceComposer::ADD_HDR_LAYER_INFO_LISTENER, data, &reply); - if (error != OK) { - ALOGE("addHdrLayerInfoListener: Failed to transact; error = %d", error); - } - return error; - } - - status_t removeHdrLayerInfoListener(const sp& displayToken, - const sp& listener) override { - Parcel data, reply; - SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor()); - SAFE_PARCEL(data.writeStrongBinder, displayToken); - SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener)); - const status_t error = - remote()->transact(BnSurfaceComposer::REMOVE_HDR_LAYER_INFO_LISTENER, data, &reply); - if (error != OK) { - ALOGE("removeHdrLayerInfoListener: Failed to transact; error = %d", error); - } - return error; - } - - status_t notifyPowerBoost(int32_t boostId) override { - Parcel data, reply; - status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (error != NO_ERROR) { - ALOGE("notifyPowerBoost: failed to write interface token: %d", error); - return error; - } - error = data.writeInt32(boostId); - if (error != NO_ERROR) { - ALOGE("notifyPowerBoost: failed to write boostId: %d", error); - return error; - } - error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply, - IBinder::FLAG_ONEWAY); - if (error != NO_ERROR) { - ALOGE("notifyPowerBoost: failed to transact: %d", error); - return error; - } - return NO_ERROR; - } - status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, float lightPosY, float lightPosZ, float lightRadius) override { Parcel data, reply; @@ -1475,15 +1254,6 @@ status_t BnSurfaceComposer::onTransact( result = reply->writeInt32(result); return result; } - case GET_BOOT_DISPLAY_MODE_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - bool support = false; - status_t result = getBootDisplayModeSupport(&support); - if (result == NO_ERROR) { - reply->writeBool(support); - } - return result; - } case SET_BOOT_DISPLAY_MODE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp display = nullptr; @@ -1500,50 +1270,6 @@ status_t BnSurfaceComposer::onTransact( } return setBootDisplayMode(display, displayModeId); } - case CLEAR_BOOT_DISPLAY_MODE: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("clearBootDisplayMode failed to readStrongBinder: %d", result); - return result; - } - return clearBootDisplayMode(display); - } - case SET_AUTO_LOW_LATENCY_MODE: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result); - return result; - } - bool setAllm = false; - result = data.readBool(&setAllm); - if (result != NO_ERROR) { - ALOGE("setAutoLowLatencyMode failed to readBool: %d", result); - return result; - } - setAutoLowLatencyMode(display, setAllm); - return result; - } - case SET_GAME_CONTENT_TYPE: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to readStrongBinder: %d", result); - return result; - } - bool setGameContentTypeOn = false; - result = data.readBool(&setGameContentTypeOn); - if (result != NO_ERROR) { - ALOGE("setGameContentType failed to readBool: %d", result); - return result; - } - setGameContentType(display, setGameContentTypeOn); - return result; - } case CLEAR_ANIMATION_FRAME_STATS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); status_t result = clearAnimationFrameStats(); @@ -1558,13 +1284,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeInt32(result); return NO_ERROR; } - case SET_POWER_MODE: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = data.readStrongBinder(); - int32_t mode = data.readInt32(); - setPowerMode(display, mode); - return NO_ERROR; - } case ENABLE_VSYNC_INJECTIONS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); bool enable = false; @@ -1714,20 +1433,6 @@ status_t BnSurfaceComposer::onTransact( } return error; } - case IS_WIDE_COLOR_DISPLAY: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp display = nullptr; - status_t error = data.readStrongBinder(&display); - if (error != NO_ERROR) { - return error; - } - bool result; - error = isWideColorDisplay(display, &result); - if (error == NO_ERROR) { - reply->writeBool(result); - } - return error; - } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); Rect samplingArea; @@ -1925,77 +1630,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeInt32(result); return result; } - case GET_DISPLAY_BRIGHTNESS_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp displayToken; - status_t error = data.readNullableStrongBinder(&displayToken); - if (error != NO_ERROR) { - ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error); - return error; - } - bool support = false; - error = getDisplayBrightnessSupport(displayToken, &support); - reply->writeBool(support); - return error; - } - case SET_DISPLAY_BRIGHTNESS: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp displayToken; - status_t error = data.readNullableStrongBinder(&displayToken); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to read display token: %d", error); - return error; - } - gui::DisplayBrightness brightness; - error = data.readParcelable(&brightness); - if (error != NO_ERROR) { - ALOGE("setDisplayBrightness: failed to read brightness: %d", error); - return error; - } - return setDisplayBrightness(displayToken, brightness); - } - case ADD_HDR_LAYER_INFO_LISTENER: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp displayToken; - status_t error = data.readNullableStrongBinder(&displayToken); - if (error != NO_ERROR) { - ALOGE("addHdrLayerInfoListener: Failed to read display token"); - return error; - } - sp listener; - error = data.readNullableStrongBinder(&listener); - if (error != NO_ERROR) { - ALOGE("addHdrLayerInfoListener: Failed to read listener"); - return error; - } - return addHdrLayerInfoListener(displayToken, listener); - } - case REMOVE_HDR_LAYER_INFO_LISTENER: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp displayToken; - status_t error = data.readNullableStrongBinder(&displayToken); - if (error != NO_ERROR) { - ALOGE("removeHdrLayerInfoListener: Failed to read display token"); - return error; - } - sp listener; - error = data.readNullableStrongBinder(&listener); - if (error != NO_ERROR) { - ALOGE("removeHdrLayerInfoListener: Failed to read listener"); - return error; - } - return removeHdrLayerInfoListener(displayToken, listener); - } - case NOTIFY_POWER_BOOST: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - int32_t boostId; - status_t error = data.readInt32(&boostId); - if (error != NO_ERROR) { - ALOGE("notifyPowerBoost: failed to read boostId: %d", error); - return error; - } - return notifyPowerBoost(boostId); - } case SET_GLOBAL_SHADOW_SETTINGS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index ff8f529385..292250bec4 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -126,6 +126,10 @@ sp Surface::composerService() const { return ComposerService::getComposerService(); } +sp Surface::composerServiceAIDL() const { + return ComposerServiceAIDL::getComposerService(); +} + nsecs_t Surface::now() const { return systemTime(); } @@ -350,8 +354,8 @@ status_t Surface::getWideColorSupport(bool* supported) { } *supported = false; - status_t error = composerService()->isWideColorDisplay(display, supported); - return error; + binder::Status status = composerServiceAIDL()->isWideColorDisplay(display, supported); + return status.transactionError(); } status_t Surface::getHdrSupport(bool* supported) { diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index ec7a9483b6..0a6a9e7cab 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -2191,7 +2191,9 @@ status_t SurfaceComposerClient::setActiveColorMode(const sp& display, } status_t SurfaceComposerClient::getBootDisplayModeSupport(bool* support) { - return ComposerService::getComposerService()->getBootDisplayModeSupport(support); + binder::Status status = + ComposerServiceAIDL::getComposerService()->getBootDisplayModeSupport(support); + return status.transactionError(); } status_t SurfaceComposerClient::setBootDisplayMode(const sp& display, @@ -2200,7 +2202,9 @@ status_t SurfaceComposerClient::setBootDisplayMode(const sp& display, } status_t SurfaceComposerClient::clearBootDisplayMode(const sp& display) { - return ComposerService::getComposerService()->clearBootDisplayMode(display); + binder::Status status = + ComposerServiceAIDL::getComposerService()->clearBootDisplayMode(display); + return status.transactionError(); } status_t SurfaceComposerClient::setOverrideFrameRate(uid_t uid, float frameRate) { @@ -2208,16 +2212,16 @@ status_t SurfaceComposerClient::setOverrideFrameRate(uid_t uid, float frameRate) } void SurfaceComposerClient::setAutoLowLatencyMode(const sp& display, bool on) { - ComposerService::getComposerService()->setAutoLowLatencyMode(display, on); + ComposerServiceAIDL::getComposerService()->setAutoLowLatencyMode(display, on); } void SurfaceComposerClient::setGameContentType(const sp& display, bool on) { - ComposerService::getComposerService()->setGameContentType(display, on); + ComposerServiceAIDL::getComposerService()->setGameContentType(display, on); } void SurfaceComposerClient::setDisplayPowerMode(const sp& token, int mode) { - ComposerService::getComposerService()->setPowerMode(token, mode); + ComposerServiceAIDL::getComposerService()->setPowerMode(token, mode); } status_t SurfaceComposerClient::getCompositionPreference( @@ -2278,8 +2282,10 @@ status_t SurfaceComposerClient::getDisplayedContentSample(const sp& dis status_t SurfaceComposerClient::isWideColorDisplay(const sp& display, bool* outIsWideColorDisplay) { - return ComposerService::getComposerService()->isWideColorDisplay(display, - outIsWideColorDisplay); + binder::Status status = + ComposerServiceAIDL::getComposerService()->isWideColorDisplay(display, + outIsWideColorDisplay); + return status.transactionError(); } status_t SurfaceComposerClient::addRegionSamplingListener( @@ -2316,28 +2322,39 @@ status_t SurfaceComposerClient::removeTunnelModeEnabledListener( bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp& displayToken) { bool support = false; - ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support); - return support; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getDisplayBrightnessSupport(displayToken, + &support); + return status.isOk() ? support : false; } status_t SurfaceComposerClient::setDisplayBrightness(const sp& displayToken, const gui::DisplayBrightness& brightness) { - return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness); + binder::Status status = + ComposerServiceAIDL::getComposerService()->setDisplayBrightness(displayToken, + brightness); + return status.transactionError(); } status_t SurfaceComposerClient::addHdrLayerInfoListener( const sp& displayToken, const sp& listener) { - return ComposerService::getComposerService()->addHdrLayerInfoListener(displayToken, listener); + binder::Status status = + ComposerServiceAIDL::getComposerService()->addHdrLayerInfoListener(displayToken, + listener); + return status.transactionError(); } status_t SurfaceComposerClient::removeHdrLayerInfoListener( const sp& displayToken, const sp& listener) { - return ComposerService::getComposerService()->removeHdrLayerInfoListener(displayToken, - listener); + binder::Status status = + ComposerServiceAIDL::getComposerService()->removeHdrLayerInfoListener(displayToken, + listener); + return status.transactionError(); } status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) { - return ComposerService::getComposerService()->notifyPowerBoost(boostId); + binder::Status status = ComposerServiceAIDL::getComposerService()->notifyPowerBoost(boostId); + return status.transactionError(); } status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor, diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl index 345c47d5b9..526fae8e55 100644 --- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl +++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl @@ -17,6 +17,8 @@ package android.gui; import android.gui.DisplayCaptureArgs; +import android.gui.DisplayBrightness; +import android.gui.IHdrLayerInfoListener; import android.gui.LayerCaptureArgs; import android.gui.IScreenCaptureListener; @@ -44,6 +46,47 @@ interface ISurfaceComposer { */ @nullable IBinder getPhysicalDisplayToken(long displayId); + /* set display power mode. depending on the mode, it can either trigger + * screen on, off or low power mode and wait for it to complete. + * requires ACCESS_SURFACE_FLINGER permission. + */ + void setPowerMode(IBinder display, int mode); + + /** + * Clears the user-preferred display mode. The device should now boot in system preferred + * display mode. + */ + void clearBootDisplayMode(IBinder display); + + /** + * Gets whether boot time display mode operations are supported on the device. + * + * outSupport + * An output parameter for whether boot time display mode operations are supported. + * + * Returns NO_ERROR upon success. Otherwise, + * NAME_NOT_FOUND if the display is invalid, or + * BAD_VALUE if the output parameter is invalid. + */ + // TODO(b/213909104) : Add unit tests to verify surface flinger boot time APIs + boolean getBootDisplayModeSupport(); + + /** + * Switches Auto Low Latency Mode on/off on the connected display, if it is + * available. This should only be called if the display supports Auto Low + * Latency Mode as reported in #getDynamicDisplayInfo. + * For more information, see the HDMI 2.1 specification. + */ + void setAutoLowLatencyMode(IBinder display, boolean on); + + /** + * This will start sending infoframes to the connected display with + * ContentType=Game (if on=true). This should only be called if the display + * Game Content Type as reported in #getDynamicDisplayInfo. + * For more information, see the HDMI 1.4 specification. + */ + void setGameContentType(IBinder display, boolean on); + /** * Capture the specified screen. This requires READ_FRAME_BUFFER * permission. This function will fail if there is a secure window on @@ -61,4 +104,67 @@ interface ISurfaceComposer { * is a secure window on screen */ void captureLayers(in LayerCaptureArgs args, IScreenCaptureListener listener); + + /* + * Queries whether the given display is a wide color display. + * Requires the ACCESS_SURFACE_FLINGER permission. + */ + boolean isWideColorDisplay(IBinder token); + + /* + * Gets whether brightness operations are supported on a display. + * + * displayToken + * The token of the display. + * outSupport + * An output parameter for whether brightness operations are supported. + * + * Returns NO_ERROR upon success. Otherwise, + * NAME_NOT_FOUND if the display is invalid, or + * BAD_VALUE if the output parameter is invalid. + */ + boolean getDisplayBrightnessSupport(IBinder displayToken); + + /* + * Sets the brightness of a display. + * + * displayToken + * The token of the display whose brightness is set. + * brightness + * The DisplayBrightness info to set on the desired display. + * + * Returns NO_ERROR upon success. Otherwise, + * NAME_NOT_FOUND if the display is invalid, or + * BAD_VALUE if the brightness is invalid, or + * INVALID_OPERATION if brightness operations are not supported. + */ + void setDisplayBrightness(IBinder displayToken, in DisplayBrightness brightness); + + /* + * Adds a listener that receives HDR layer information. This is used in combination + * with setDisplayBrightness to adjust the display brightness depending on factors such + * as whether or not HDR is in use. + * + * Returns NO_ERROR upon success or NAME_NOT_FOUND if the display is invalid. + */ + void addHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener); + + /* + * Removes a listener that was added with addHdrLayerInfoListener. + * + * Returns NO_ERROR upon success, NAME_NOT_FOUND if the display is invalid, and BAD_VALUE if + * the listener wasn't registered. + * + */ + void removeHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener); + + /* + * Sends a power boost to the composer. This function is asynchronous. + * + * boostId + * boost id according to android::hardware::power::Boost + * + * Returns NO_ERROR upon success. + */ + void notifyPowerBoost(int boostId); } diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 91d44da03d..10db4d5c99 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -161,13 +161,6 @@ public: virtual status_t getSupportedFrameTimestamps( std::vector* outSupported) const = 0; - /* set display power mode. depending on the mode, it can either trigger - * screen on, off or low power mode and wait for it to complete. - * requires ACCESS_SURFACE_FLINGER permission. - */ - virtual void setPowerMode(const sp& display, int mode) = 0; - - /* returns display statistics for a given display * intended to be used by the media framework to properly schedule * video frames */ @@ -199,40 +192,6 @@ public: */ virtual status_t setBootDisplayMode(const sp& display, ui::DisplayModeId) = 0; - /** - * Clears the user-preferred display mode. The device should now boot in system preferred - * display mode. - */ - virtual status_t clearBootDisplayMode(const sp& display) = 0; - - /** - * Gets whether boot time display mode operations are supported on the device. - * - * outSupport - * An output parameter for whether boot time display mode operations are supported. - * - * Returns NO_ERROR upon success. Otherwise, - * NAME_NOT_FOUND if the display is invalid, or - * BAD_VALUE if the output parameter is invalid. - */ - virtual status_t getBootDisplayModeSupport(bool* outSupport) const = 0; - - /** - * Switches Auto Low Latency Mode on/off on the connected display, if it is - * available. This should only be called if the display supports Auto Low - * Latency Mode as reported in #getDynamicDisplayInfo. - * For more information, see the HDMI 2.1 specification. - */ - virtual void setAutoLowLatencyMode(const sp& display, bool on) = 0; - - /** - * This will start sending infoframes to the connected display with - * ContentType=Game (if on=true). This should only be called if the display - * Game Content Type as reported in #getDynamicDisplayInfo. - * For more information, see the HDMI 1.4 specification. - */ - virtual void setGameContentType(const sp& display, bool on) = 0; - /* Clears the frame statistics for animations. * * Requires the ACCESS_SURFACE_FLINGER permission. @@ -311,13 +270,6 @@ public: */ virtual status_t getProtectedContentSupport(bool* outSupported) const = 0; - /* - * Queries whether the given display is a wide color display. - * Requires the ACCESS_SURFACE_FLINGER permission. - */ - virtual status_t isWideColorDisplay(const sp& token, - bool* outIsWideColorDisplay) const = 0; - /* Registers a listener to stream median luma updates from SurfaceFlinger. * * The sampling area is bounded by both samplingArea and the given stopLayerHandle @@ -398,65 +350,6 @@ public: float* outPrimaryRefreshRateMax, float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) = 0; - /* - * Gets whether brightness operations are supported on a display. - * - * displayToken - * The token of the display. - * outSupport - * An output parameter for whether brightness operations are supported. - * - * Returns NO_ERROR upon success. Otherwise, - * NAME_NOT_FOUND if the display is invalid, or - * BAD_VALUE if the output parameter is invalid. - */ - virtual status_t getDisplayBrightnessSupport(const sp& displayToken, - bool* outSupport) const = 0; - - /* - * Sets the brightness of a display. - * - * displayToken - * The token of the display whose brightness is set. - * brightness - * The DisplayBrightness info to set on the desired display. - * - * Returns NO_ERROR upon success. Otherwise, - * NAME_NOT_FOUND if the display is invalid, or - * BAD_VALUE if the brightness is invalid, or - * INVALID_OPERATION if brightness operations are not supported. - */ - virtual status_t setDisplayBrightness(const sp& displayToken, - const gui::DisplayBrightness& brightness) = 0; - - /* - * Adds a listener that receives HDR layer information. This is used in combination - * with setDisplayBrightness to adjust the display brightness depending on factors such - * as whether or not HDR is in use. - * - * Returns NO_ERROR upon success or NAME_NOT_FOUND if the display is invalid. - */ - virtual status_t addHdrLayerInfoListener(const sp& displayToken, - const sp& listener) = 0; - /* - * Removes a listener that was added with addHdrLayerInfoListener. - * - * Returns NO_ERROR upon success, NAME_NOT_FOUND if the display is invalid, and BAD_VALUE if - * the listener wasn't registered. - * - */ - virtual status_t removeHdrLayerInfoListener(const sp& displayToken, - const sp& listener) = 0; - - /* - * Sends a power boost to the composer. This function is asynchronous. - * - * boostId - * boost id according to android::hardware::power::Boost - * - * Returns NO_ERROR upon success. - */ - virtual status_t notifyPowerBoost(int32_t boostId) = 0; /* * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows @@ -576,7 +469,7 @@ public: CAPTURE_LAYERS, // Deprecated. Autogenerated by .aidl now. CLEAR_ANIMATION_FRAME_STATS, GET_ANIMATION_FRAME_STATS, - SET_POWER_MODE, + SET_POWER_MODE, // Deprecated. Autogenerated by .aidl now. GET_DISPLAY_STATS, GET_HDR_CAPABILITIES, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. GET_DISPLAY_COLOR_MODES, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. @@ -591,22 +484,22 @@ public: SET_DISPLAY_CONTENT_SAMPLING_ENABLED, GET_DISPLAYED_CONTENT_SAMPLE, GET_PROTECTED_CONTENT_SUPPORT, - IS_WIDE_COLOR_DISPLAY, + IS_WIDE_COLOR_DISPLAY, // Deprecated. Autogenerated by .aidl now. GET_DISPLAY_NATIVE_PRIMARIES, GET_PHYSICAL_DISPLAY_IDS, // Deprecated. Autogenerated by .aidl now. ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, SET_DESIRED_DISPLAY_MODE_SPECS, GET_DESIRED_DISPLAY_MODE_SPECS, - GET_DISPLAY_BRIGHTNESS_SUPPORT, - SET_DISPLAY_BRIGHTNESS, - CAPTURE_DISPLAY_BY_ID, // Deprecated. Autogenerated by .aidl now. - NOTIFY_POWER_BOOST, + GET_DISPLAY_BRIGHTNESS_SUPPORT, // Deprecated. Autogenerated by .aidl now. + SET_DISPLAY_BRIGHTNESS, // Deprecated. Autogenerated by .aidl now. + CAPTURE_DISPLAY_BY_ID, // Deprecated. Autogenerated by .aidl now. + NOTIFY_POWER_BOOST, // Deprecated. Autogenerated by .aidl now. SET_GLOBAL_SHADOW_SETTINGS, GET_AUTO_LOW_LATENCY_MODE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. - SET_AUTO_LOW_LATENCY_MODE, - GET_GAME_CONTENT_TYPE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. - SET_GAME_CONTENT_TYPE, + SET_AUTO_LOW_LATENCY_MODE, // Deprecated. Autogenerated by .aidl now. + GET_GAME_CONTENT_TYPE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. + SET_GAME_CONTENT_TYPE, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. SET_FRAME_RATE, // Deprecated. Use DisplayManager.setShouldAlwaysRespectAppRequestedMode(true); ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, @@ -618,8 +511,8 @@ public: ADD_FPS_LISTENER, REMOVE_FPS_LISTENER, OVERRIDE_HDR_TYPES, - ADD_HDR_LAYER_INFO_LISTENER, - REMOVE_HDR_LAYER_INFO_LISTENER, + ADD_HDR_LAYER_INFO_LISTENER, // Deprecated. Autogenerated by .aidl now. + REMOVE_HDR_LAYER_INFO_LISTENER, // Deprecated. Autogenerated by .aidl now. ON_PULL_ATOM, ADD_TUNNEL_MODE_ENABLED_LISTENER, REMOVE_TUNNEL_MODE_ENABLED_LISTENER, @@ -627,9 +520,9 @@ public: REMOVE_WINDOW_INFOS_LISTENER, GET_PRIMARY_PHYSICAL_DISPLAY_ID, // Deprecated. Autogenerated by .aidl now. GET_DISPLAY_DECORATION_SUPPORT, - GET_BOOT_DISPLAY_MODE_SUPPORT, + GET_BOOT_DISPLAY_MODE_SUPPORT, // Deprecated. Autogenerated by .aidl now. SET_BOOT_DISPLAY_MODE, - CLEAR_BOOT_DISPLAY_MODE, + CLEAR_BOOT_DISPLAY_MODE, // Deprecated. Autogenerated by .aidl now. SET_OVERRIDE_FRAME_RATE, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 5fe308cf9f..ab9ebaa882 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -35,6 +35,10 @@ namespace android { +namespace gui { +class ISurfaceComposer; +} // namespace gui + class ISurfaceComposer; /* This is the same as ProducerListener except that onBuffersDiscarded is @@ -196,6 +200,7 @@ protected: // Virtual for testing. virtual sp composerService() const; + virtual sp composerServiceAIDL() const; virtual nsecs_t now() const; private: diff --git a/libs/gui/include/private/gui/ComposerServiceAIDL.h b/libs/gui/include/private/gui/ComposerServiceAIDL.h index b32cf2a9c2..9a96976c0f 100644 --- a/libs/gui/include/private/gui/ComposerServiceAIDL.h +++ b/libs/gui/include/private/gui/ComposerServiceAIDL.h @@ -68,7 +68,8 @@ public: if (!displayId) return nullptr; sp display; binder::Status status = - mComposerService->getPhysicalDisplayToken(displayId->value, &display); + mComposerService->getPhysicalDisplayToken(static_cast(displayId->value), + &display); return status.isOk() ? display : nullptr; } }; diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 07ac2d4065..2e3ab40e2f 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -732,7 +732,6 @@ public: return NO_ERROR; } - void setPowerMode(const sp& /*display*/, int /*mode*/) override {} status_t getStaticDisplayInfo(const sp& /*display*/, ui::StaticDisplayInfo*) override { return NO_ERROR; } @@ -749,15 +748,12 @@ public: ui::DisplayPrimaries& /*primaries*/) override { return NO_ERROR; } - status_t setActiveColorMode(const sp& /*display*/, - ColorMode /*colorMode*/) override { return NO_ERROR; } - status_t getBootDisplayModeSupport(bool* /*outSupport*/) const override { return NO_ERROR; } + status_t setActiveColorMode(const sp& /*display*/, ColorMode /*colorMode*/) override { + return NO_ERROR; + } status_t setBootDisplayMode(const sp& /*display*/, ui::DisplayModeId /*id*/) override { return NO_ERROR; } - status_t clearBootDisplayMode(const sp& /*display*/) override { return NO_ERROR; } - void setAutoLowLatencyMode(const sp& /*display*/, bool /*on*/) override {} - void setGameContentType(const sp& /*display*/, bool /*on*/) override {} status_t clearAnimationFrameStats() override { return NO_ERROR; } status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override { @@ -804,26 +800,6 @@ public: status_t getColorManagement(bool* /*outGetColorManagement*/) const override { return NO_ERROR; } status_t getProtectedContentSupport(bool* /*outSupported*/) const override { return NO_ERROR; } - status_t isWideColorDisplay(const sp&, bool*) const override { return NO_ERROR; } - status_t getDisplayBrightnessSupport(const sp& /*displayToken*/, - bool* /*outSupport*/) const override { - return NO_ERROR; - } - status_t setDisplayBrightness(const sp& /*displayToken*/, - const gui::DisplayBrightness& /*brightness*/) override { - return NO_ERROR; - } - - status_t addHdrLayerInfoListener(const sp&, - const sp&) override { - return NO_ERROR; - } - - status_t removeHdrLayerInfoListener(const sp&, - const sp&) override { - return NO_ERROR; - } - status_t addRegionSamplingListener(const Rect& /*samplingArea*/, const sp& /*stopLayerHandle*/, const sp& /*listener*/) override { @@ -865,7 +841,6 @@ public: float* /*outAppRequestRefreshRateMax*/) override { return NO_ERROR; }; - status_t notifyPowerBoost(int32_t /*boostId*/) override { return NO_ERROR; } status_t setGlobalShadowSettings(const half4& /*ambientColor*/, const half4& /*spotColor*/, float /*lightPosY*/, float /*lightPosZ*/, diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index ff977b226a..bccd460652 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5473,20 +5473,14 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case SET_DESIRED_DISPLAY_MODE_SPECS: case GET_DESIRED_DISPLAY_MODE_SPECS: case SET_ACTIVE_COLOR_MODE: - case GET_BOOT_DISPLAY_MODE_SUPPORT: case SET_BOOT_DISPLAY_MODE: - case CLEAR_BOOT_DISPLAY_MODE: case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: - case SET_AUTO_LOW_LATENCY_MODE: case GET_GAME_CONTENT_TYPE_SUPPORT: - case SET_GAME_CONTENT_TYPE: - case SET_POWER_MODE: case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: case GET_DISPLAYED_CONTENT_SAMPLE: case ADD_TUNNEL_MODE_ENABLED_LISTENER: case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: - case NOTIFY_POWER_BOOST: case SET_GLOBAL_SHADOW_SETTINGS: case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary @@ -5533,11 +5527,9 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_COLOR_MANAGEMENT: case GET_COMPOSITION_PREFERENCE: case GET_PROTECTED_CONTENT_SUPPORT: - case IS_WIDE_COLOR_DISPLAY: // setFrameRate() is deliberately available for apps to call without any // special permissions. case SET_FRAME_RATE: - case GET_DISPLAY_BRIGHTNESS_SUPPORT: case GET_DISPLAY_DECORATION_SUPPORT: case SET_FRAME_TIMELINE_INFO: case GET_GPU_CONTEXT_PRIORITY: @@ -5545,19 +5537,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // This is not sensitive information, so should not require permission control. return OK; } - case SET_DISPLAY_BRIGHTNESS: - case ADD_HDR_LAYER_INFO_LISTENER: - case REMOVE_HDR_LAYER_INFO_LISTENER: { - IPCThreadState* ipc = IPCThreadState::self(); - const int pid = ipc->getCallingPid(); - const int uid = ipc->getCallingUid(); - if ((uid != AID_GRAPHICS) && - !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { - ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); - return PERMISSION_DENIED; - } - return OK; - } case ADD_FPS_LISTENER: case REMOVE_FPS_LISTENER: case ADD_REGION_SAMPLING_LISTENER: @@ -5608,9 +5587,20 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_PRIMARY_PHYSICAL_DISPLAY_ID: case GET_PHYSICAL_DISPLAY_IDS: case GET_PHYSICAL_DISPLAY_TOKEN: + case SET_POWER_MODE: + case CLEAR_BOOT_DISPLAY_MODE: + case GET_BOOT_DISPLAY_MODE_SUPPORT: + case SET_AUTO_LOW_LATENCY_MODE: + case SET_GAME_CONTENT_TYPE: case CAPTURE_LAYERS: case CAPTURE_DISPLAY: case CAPTURE_DISPLAY_BY_ID: + case IS_WIDE_COLOR_DISPLAY: + case GET_DISPLAY_BRIGHTNESS_SUPPORT: + case SET_DISPLAY_BRIGHTNESS: + case ADD_HDR_LAYER_INFO_LISTENER: + case REMOVE_HDR_LAYER_INFO_LISTENER: + case NOTIFY_POWER_BOOST: LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); return PERMISSION_DENIED; } @@ -7369,6 +7359,46 @@ binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, return binder::Status::ok(); } +binder::Status SurfaceComposerAIDL::setPowerMode(const sp& display, int mode) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + mFlinger->setPowerMode(display, mode); + return binder::Status::ok(); +} + +binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp& display) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->clearBootDisplayMode(display); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->getBootDisplayModeSupport(outMode); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp& display, bool on) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + mFlinger->setAutoLowLatencyMode(display, on); + return binder::Status::ok(); +} + +binder::Status SurfaceComposerAIDL::setGameContentType(const sp& display, bool on) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + mFlinger->setGameContentType(display, on); + return binder::Status::ok(); +} + binder::Status SurfaceComposerAIDL::captureDisplay( const DisplayCaptureArgs& args, const sp& captureListener) { status_t status = mFlinger->captureDisplay(args, captureListener); @@ -7395,6 +7425,53 @@ binder::Status SurfaceComposerAIDL::captureLayers( return binder::Status::fromStatusT(status); } +binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp& token, + bool* outIsWideColorDisplay) { + status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp& displayToken, + bool* outSupport) { + status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp& displayToken, + const gui::DisplayBrightness& brightness) { + status_t status = checkControlDisplayBrightnessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->setDisplayBrightness(displayToken, brightness); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( + const sp& displayToken, const sp& listener) { + status_t status = checkControlDisplayBrightnessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->addHdrLayerInfoListener(displayToken, listener); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( + const sp& displayToken, const sp& listener) { + status_t status = checkControlDisplayBrightnessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { + status_t status = checkAccessPermission(); + if (status != OK) return binder::Status::fromStatusT(status); + + status = mFlinger->notifyPowerBoost(boostId); + return binder::Status::fromStatusT(status); +} + status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { IPCThreadState* ipc = IPCThreadState::self(); @@ -7405,6 +7482,18 @@ status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { return OK; } +status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { + IPCThreadState* ipc = IPCThreadState::self(); + const int pid = ipc->getCallingPid(); + const int uid = ipc->getCallingUid(); + if ((uid != AID_GRAPHICS) && + !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { + ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); + return PERMISSION_DENIED; + } + return OK; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index bc3d83e2b0..51852a5f0d 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -573,12 +573,12 @@ private: status_t getDisplayNativePrimaries(const sp& displayToken, ui::DisplayPrimaries&) override; status_t setActiveColorMode(const sp& displayToken, ui::ColorMode colorMode) override; - status_t getBootDisplayModeSupport(bool* outSupport) const override; + status_t getBootDisplayModeSupport(bool* outSupport) const; status_t setBootDisplayMode(const sp& displayToken, ui::DisplayModeId id) override; - status_t clearBootDisplayMode(const sp& displayToken) override; - void setAutoLowLatencyMode(const sp& displayToken, bool on) override; - void setGameContentType(const sp& displayToken, bool on) override; - void setPowerMode(const sp& displayToken, int mode) override; + status_t clearBootDisplayMode(const sp& displayToken); + void setAutoLowLatencyMode(const sp& displayToken, bool on); + void setGameContentType(const sp& displayToken, bool on); + void setPowerMode(const sp& displayToken, int mode); status_t clearAnimationFrameStats() override; status_t getAnimationFrameStats(FrameStats* outStats) const override; status_t overrideHdrTypes(const sp& displayToken, @@ -601,8 +601,7 @@ private: uint64_t timestamp, DisplayedFrameStats* outStats) const override; status_t getProtectedContentSupport(bool* outSupported) const override; - status_t isWideColorDisplay(const sp& displayToken, - bool* outIsWideColorDisplay) const override; + status_t isWideColorDisplay(const sp& displayToken, bool* outIsWideColorDisplay) const; status_t addRegionSamplingListener(const Rect& samplingArea, const sp& stopLayerHandle, const sp& listener) override; status_t removeRegionSamplingListener(const sp& listener) override; @@ -624,15 +623,14 @@ private: float* outPrimaryRefreshRateMax, float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) override; - status_t getDisplayBrightnessSupport(const sp& displayToken, - bool* outSupport) const override; + status_t getDisplayBrightnessSupport(const sp& displayToken, bool* outSupport) const; status_t setDisplayBrightness(const sp& displayToken, - const gui::DisplayBrightness& brightness) override; + const gui::DisplayBrightness& brightness); status_t addHdrLayerInfoListener(const sp& displayToken, - const sp& listener) override; + const sp& listener); status_t removeHdrLayerInfoListener(const sp& displayToken, - const sp& listener) override; - status_t notifyPowerBoost(int32_t boostId) override; + const sp& listener); + status_t notifyPowerBoost(int32_t boostId); status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, float lightPosY, float lightPosZ, float lightRadius) override; status_t getDisplayDecorationSupport( @@ -1457,16 +1455,33 @@ public: binder::Status getPhysicalDisplayIds(std::vector* outDisplayIds) override; binder::Status getPrimaryPhysicalDisplayId(int64_t* outDisplayId) override; binder::Status getPhysicalDisplayToken(int64_t displayId, sp* outDisplay) override; - + binder::Status setPowerMode(const sp& display, int mode) override; + binder::Status clearBootDisplayMode(const sp& display) override; + binder::Status getBootDisplayModeSupport(bool* outMode) override; + binder::Status setAutoLowLatencyMode(const sp& display, bool on) override; + binder::Status setGameContentType(const sp& display, bool on) override; binder::Status captureDisplay(const DisplayCaptureArgs&, const sp&) override; binder::Status captureDisplayById(int64_t, const sp&) override; binder::Status captureLayers(const LayerCaptureArgs&, const sp&) override; + binder::Status isWideColorDisplay(const sp& token, + bool* outIsWideColorDisplay) override; + binder::Status getDisplayBrightnessSupport(const sp& displayToken, + bool* outSupport) override; + binder::Status setDisplayBrightness(const sp& displayToken, + const gui::DisplayBrightness& brightness) override; + binder::Status addHdrLayerInfoListener(const sp& displayToken, + const sp& listener) override; + binder::Status removeHdrLayerInfoListener( + const sp& displayToken, + const sp& listener) override; + binder::Status notifyPowerBoost(int boostId) override; private: static const constexpr bool kUsePermissionCache = true; status_t checkAccessPermission(bool usePermissionCache = kUsePermissionCache); + status_t checkControlDisplayBrightnessPermission(); private: sp mFlinger; diff --git a/services/surfaceflinger/tests/BootDisplayMode_test.cpp b/services/surfaceflinger/tests/BootDisplayMode_test.cpp index abdb16debf..d70908e390 100644 --- a/services/surfaceflinger/tests/BootDisplayMode_test.cpp +++ b/services/surfaceflinger/tests/BootDisplayMode_test.cpp @@ -20,28 +20,33 @@ #include #include +#include #include namespace android { TEST(BootDisplayModeTest, setBootDisplayMode) { sp sf(ComposerService::getComposerService()); + sp sf_aidl(ComposerServiceAIDL::getComposerService()); auto displayToken = SurfaceComposerClient::getInternalDisplayToken(); bool bootModeSupport = false; - ASSERT_NO_FATAL_FAILURE(sf->getBootDisplayModeSupport(&bootModeSupport)); + binder::Status status = sf_aidl->getBootDisplayModeSupport(&bootModeSupport); + ASSERT_NO_FATAL_FAILURE(status.transactionError()); if (bootModeSupport) { ASSERT_EQ(NO_ERROR, sf->setBootDisplayMode(displayToken, 0)); } } TEST(BootDisplayModeTest, clearBootDisplayMode) { - sp sf(ComposerService::getComposerService()); + sp sf(ComposerServiceAIDL::getComposerService()); auto displayToken = SurfaceComposerClient::getInternalDisplayToken(); bool bootModeSupport = false; - ASSERT_NO_FATAL_FAILURE(sf->getBootDisplayModeSupport(&bootModeSupport)); + binder::Status status = sf->getBootDisplayModeSupport(&bootModeSupport); + ASSERT_NO_FATAL_FAILURE(status.transactionError()); if (bootModeSupport) { - ASSERT_EQ(NO_ERROR, sf->clearBootDisplayMode(displayToken)); + status = sf->clearBootDisplayMode(displayToken); + ASSERT_EQ(NO_ERROR, status.transactionError()); } } -} // namespace android \ No newline at end of file +} // namespace android -- cgit v1.2.3-59-g8ed1b From 0fd1af9e0c0dbaea55827c9e808754e138e3a79a Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Tue, 15 Feb 2022 10:43:00 -0800 Subject: Migrate display related methods to AIDL part 3 This migrates more display related methods from ISurfaceComposer.h to the new AIDL interface. (1) migrate getDisplaySttas() and getDisplayState() methods (2) add new parcelables, android.gui.DisplayState, anddroid.gui.DisplayStatInfo and other utilities. (3) all parceables are added into libgui, instead of libui, so libui is isolated from binder serialization code,which is cleaner and avoids libbinder linking errors. Bug: 220043617 Bug: 219574942 Test: atest SurfaceFlinger_test libsurfaceflinger_unittest libgui_test Merged-In: Iacdc42dde1608f883c5578aa3d9f9f8ae9f23038 Change-Id: Iacdc42dde1608f883c5578aa3d9f9f8ae9f23038 --- libs/gui/ISurfaceComposer.cpp | 50 ----------- libs/gui/Surface.cpp | 10 +-- libs/gui/SurfaceComposerClient.cpp | 13 ++- libs/gui/aidl/android/gui/DisplayStatInfo.aidl | 23 +++++ libs/gui/aidl/android/gui/DisplayState.aidl | 27 ++++++ libs/gui/aidl/android/gui/ISurfaceComposer.aidl | 12 +++ libs/gui/aidl/android/gui/Rect.aidl | 35 ++++++++ libs/gui/aidl/android/gui/Rotation.aidl | 26 ++++++ libs/gui/aidl/android/gui/Size.aidl | 23 +++++ libs/gui/include/gui/ISurfaceComposer.h | 11 --- libs/gui/tests/Surface_test.cpp | 114 ++++++++++++++++++++++-- services/surfaceflinger/SurfaceFlinger.cpp | 28 +++++- services/surfaceflinger/SurfaceFlinger.h | 11 ++- 13 files changed, 306 insertions(+), 77 deletions(-) create mode 100644 libs/gui/aidl/android/gui/DisplayStatInfo.aidl create mode 100644 libs/gui/aidl/android/gui/DisplayState.aidl create mode 100644 libs/gui/aidl/android/gui/Rect.aidl create mode 100644 libs/gui/aidl/android/gui/Rotation.aidl create mode 100644 libs/gui/aidl/android/gui/Size.aidl (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 26b31252f3..24d39fe86a 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -226,18 +226,6 @@ public: return result; } - status_t getDisplayState(const sp& display, ui::DisplayState* state) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply); - const status_t result = reply.readInt32(); - if (result == NO_ERROR) { - memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState)); - } - return result; - } - status_t getStaticDisplayInfo(const sp& display, ui::StaticDisplayInfo* info) override { Parcel data, reply; @@ -260,20 +248,6 @@ public: return reply.read(*info); } - status_t getDisplayStats(const sp& display, DisplayStatInfo* stats) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply); - status_t result = reply.readInt32(); - if (result == NO_ERROR) { - memcpy(stats, - reply.readInplace(sizeof(DisplayStatInfo)), - sizeof(DisplayStatInfo)); - } - return result; - } - status_t getDisplayNativePrimaries(const sp& display, ui::DisplayPrimaries& primaries) override { Parcel data, reply; @@ -1171,18 +1145,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeStrongBinder(IInterface::asBinder(connection)); return NO_ERROR; } - case GET_DISPLAY_STATE: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - ui::DisplayState state; - const sp display = data.readStrongBinder(); - const status_t result = getDisplayState(display, &state); - reply->writeInt32(result); - if (result == NO_ERROR) { - memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state, - sizeof(ui::DisplayState)); - } - return NO_ERROR; - } case GET_STATIC_DISPLAY_INFO: { CHECK_INTERFACE(ISurfaceComposer, data, reply); ui::StaticDisplayInfo info; @@ -1203,18 +1165,6 @@ status_t BnSurfaceComposer::onTransact( SAFE_PARCEL(reply->write, info); return NO_ERROR; } - case GET_DISPLAY_STATS: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - DisplayStatInfo stats; - sp display = data.readStrongBinder(); - status_t result = getDisplayStats(display, &stats); - reply->writeInt32(result); - if (result == NO_ERROR) { - memcpy(reply->writeInplace(sizeof(DisplayStatInfo)), - &stats, sizeof(DisplayStatInfo)); - } - return NO_ERROR; - } case GET_DISPLAY_NATIVE_PRIMARIES: { CHECK_INTERFACE(ISurfaceComposer, data, reply); ui::DisplayPrimaries primaries; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 292250bec4..54b6d6a549 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -27,13 +27,13 @@ #include +#include #include #include #include #include -#include #include #include #include @@ -179,10 +179,10 @@ status_t Surface::getLastQueuedBuffer(sp* outBuffer, status_t Surface::getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration) { ATRACE_CALL(); - DisplayStatInfo stats; - status_t result = composerService()->getDisplayStats(nullptr, &stats); - if (result != NO_ERROR) { - return result; + gui::DisplayStatInfo stats; + binder::Status status = composerServiceAIDL()->getDisplayStats(nullptr, &stats); + if (!status.isOk()) { + return status.transactionError(); } *outRefreshDuration = stats.vsyncPeriod; diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 0a6a9e7cab..7182dc7de0 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #include #include @@ -2127,7 +2129,16 @@ status_t SurfaceComposerClient::injectVSync(nsecs_t when) { status_t SurfaceComposerClient::getDisplayState(const sp& display, ui::DisplayState* state) { - return ComposerService::getComposerService()->getDisplayState(display, state); + gui::DisplayState ds; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getDisplayState(display, &ds); + if (status.isOk()) { + state->layerStack = ui::LayerStack::fromValue(ds.layerStack); + state->orientation = static_cast(ds.orientation); + state->layerStackSpaceRect = + ui::Size(ds.layerStackSpaceRect.width, ds.layerStackSpaceRect.height); + } + return status.transactionError(); } status_t SurfaceComposerClient::getStaticDisplayInfo(const sp& display, diff --git a/libs/gui/aidl/android/gui/DisplayStatInfo.aidl b/libs/gui/aidl/android/gui/DisplayStatInfo.aidl new file mode 100644 index 0000000000..68f394281e --- /dev/null +++ b/libs/gui/aidl/android/gui/DisplayStatInfo.aidl @@ -0,0 +1,23 @@ +/* + * Copyright 2022 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; + +/** @hide */ +parcelable DisplayStatInfo { + long vsyncTime; + long vsyncPeriod; +} diff --git a/libs/gui/aidl/android/gui/DisplayState.aidl b/libs/gui/aidl/android/gui/DisplayState.aidl new file mode 100644 index 0000000000..9589ab6b1a --- /dev/null +++ b/libs/gui/aidl/android/gui/DisplayState.aidl @@ -0,0 +1,27 @@ +/* + * Copyright 2022 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.Rotation; +import android.gui.Size; + +/** @hide */ +parcelable DisplayState { + int layerStack; + Rotation orientation = Rotation.Rotation0; + Size layerStackSpaceRect; +} diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl index 526fae8e55..a9977b0f45 100644 --- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl +++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl @@ -18,6 +18,8 @@ package android.gui; import android.gui.DisplayCaptureArgs; import android.gui.DisplayBrightness; +import android.gui.DisplayState; +import android.gui.DisplayStatInfo; import android.gui.IHdrLayerInfoListener; import android.gui.LayerCaptureArgs; import android.gui.IScreenCaptureListener; @@ -52,6 +54,16 @@ interface ISurfaceComposer { */ void setPowerMode(IBinder display, int mode); + /* returns display statistics for a given display + * intended to be used by the media framework to properly schedule + * video frames */ + DisplayStatInfo getDisplayStats(IBinder display); + + /** + * Get transactional state of given display. + */ + DisplayState getDisplayState(IBinder display); + /** * Clears the user-preferred display mode. The device should now boot in system preferred * display mode. diff --git a/libs/gui/aidl/android/gui/Rect.aidl b/libs/gui/aidl/android/gui/Rect.aidl new file mode 100644 index 0000000000..1b13761392 --- /dev/null +++ b/libs/gui/aidl/android/gui/Rect.aidl @@ -0,0 +1,35 @@ +/* + * Copyright 2022 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; + +// copied from libs/arect/include/android/rect.h +// TODO(b/221473398): +// use hardware/interfaces/graphics/common/aidl/android/hardware/graphics/common/Rect.aidl +/** @hide */ +parcelable Rect { + /// Minimum X coordinate of the rectangle. + int left; + + /// Minimum Y coordinate of the rectangle. + int top; + + /// Maximum X coordinate of the rectangle. + int right; + + /// Maximum Y coordinate of the rectangle. + int bottom; +} diff --git a/libs/gui/aidl/android/gui/Rotation.aidl b/libs/gui/aidl/android/gui/Rotation.aidl new file mode 100644 index 0000000000..451ff45ccf --- /dev/null +++ b/libs/gui/aidl/android/gui/Rotation.aidl @@ -0,0 +1,26 @@ +/* + * Copyright 2022 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; + +/** @hide */ +@Backing(type="int") +enum Rotation { + Rotation0 = 0, + Rotation90 = 1, + Rotation180 = 2, + Rotation270 = 3 +} diff --git a/libs/gui/aidl/android/gui/Size.aidl b/libs/gui/aidl/android/gui/Size.aidl new file mode 100644 index 0000000000..415fa36fee --- /dev/null +++ b/libs/gui/aidl/android/gui/Size.aidl @@ -0,0 +1,23 @@ +/* + * Copyright 2022 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; + +/** @hide */ +parcelable Size { + int width = -1; + int height = -1; +} diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 10db4d5c99..a610e940be 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -161,17 +161,6 @@ public: virtual status_t getSupportedFrameTimestamps( std::vector* outSupported) const = 0; - /* returns display statistics for a given display - * intended to be used by the media framework to properly schedule - * video frames */ - virtual status_t getDisplayStats(const sp& display, - DisplayStatInfo* stats) = 0; - - /** - * Get transactional state of given display. - */ - virtual status_t getDisplayState(const sp& display, ui::DisplayState*) = 0; - /** * Gets immutable information about given physical display. */ diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 2e3ab40e2f..065cd7a5c7 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -739,11 +740,6 @@ public: ui::DynamicDisplayInfo*) override { return NO_ERROR; } - status_t getDisplayState(const sp& /*display*/, ui::DisplayState*) override { - return NO_ERROR; - } - status_t getDisplayStats(const sp& /*display*/, - DisplayStatInfo* /*stats*/) override { return NO_ERROR; } status_t getDisplayNativePrimaries(const sp& /*display*/, ui::DisplayPrimaries& /*primaries*/) override { return NO_ERROR; @@ -892,6 +888,114 @@ private: bool mSupportsPresent{true}; }; +class FakeSurfaceComposerAIDL : public gui::ISurfaceComposer { +public: + ~FakeSurfaceComposerAIDL() override {} + + void setSupportsPresent(bool supportsPresent) { mSupportsPresent = supportsPresent; } + + binder::Status createDisplay(const std::string& /*displayName*/, bool /*secure*/, + sp* /*outDisplay*/) override { + return binder::Status::ok(); + } + + binder::Status destroyDisplay(const sp& /*display*/) override { + return binder::Status::ok(); + } + + binder::Status getPhysicalDisplayIds(std::vector* /*outDisplayIds*/) override { + return binder::Status::ok(); + } + + binder::Status getPrimaryPhysicalDisplayId(int64_t* /*outDisplayId*/) override { + return binder::Status::ok(); + } + + binder::Status getPhysicalDisplayToken(int64_t /*displayId*/, + sp* /*outDisplay*/) override { + return binder::Status::ok(); + } + + binder::Status setPowerMode(const sp& /*display*/, int /*mode*/) override { + return binder::Status::ok(); + } + + binder::Status getDisplayStats(const sp& /*display*/, + gui::DisplayStatInfo* /*outStatInfo*/) override { + return binder::Status::ok(); + } + + binder::Status getDisplayState(const sp& /*display*/, + gui::DisplayState* /*outState*/) override { + return binder::Status::ok(); + } + + binder::Status clearBootDisplayMode(const sp& /*display*/) override { + return binder::Status::ok(); + } + + binder::Status getBootDisplayModeSupport(bool* /*outMode*/) override { + return binder::Status::ok(); + } + + binder::Status setAutoLowLatencyMode(const sp& /*display*/, bool /*on*/) override { + return binder::Status::ok(); + } + + binder::Status setGameContentType(const sp& /*display*/, bool /*on*/) override { + return binder::Status::ok(); + } + + binder::Status captureDisplay(const DisplayCaptureArgs&, + const sp&) override { + return binder::Status::ok(); + } + + binder::Status captureDisplayById(int64_t, const sp&) override { + return binder::Status::ok(); + } + + binder::Status captureLayers(const LayerCaptureArgs&, + const sp&) override { + return binder::Status::ok(); + } + + binder::Status isWideColorDisplay(const sp& /*token*/, + bool* /*outIsWideColorDisplay*/) override { + return binder::Status::ok(); + } + + binder::Status getDisplayBrightnessSupport(const sp& /*displayToken*/, + bool* /*outSupport*/) override { + return binder::Status::ok(); + } + + binder::Status setDisplayBrightness(const sp& /*displayToken*/, + const gui::DisplayBrightness& /*brightness*/) override { + return binder::Status::ok(); + } + + binder::Status addHdrLayerInfoListener( + const sp& /*displayToken*/, + const sp& /*listener*/) override { + return binder::Status::ok(); + } + + binder::Status removeHdrLayerInfoListener( + const sp& /*displayToken*/, + const sp& /*listener*/) override { + return binder::Status::ok(); + } + + binder::Status notifyPowerBoost(int /*boostId*/) override { return binder::Status::ok(); } + +protected: + IBinder* onAsBinder() override { return nullptr; } + +private: + bool mSupportsPresent{true}; +}; + class FakeProducerFrameEventHistory : public ProducerFrameEventHistory { public: explicit FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap) : mFenceMap(fenceMap) {} diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index bccd460652..ee6675c8ae 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5517,8 +5517,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_STATIC_DISPLAY_INFO: case GET_DYNAMIC_DISPLAY_INFO: case GET_DISPLAY_MODES: - case GET_DISPLAY_STATE: - case GET_DISPLAY_STATS: case GET_SUPPORTED_FRAME_TIMESTAMPS: // Calling setTransactionState is safe, because you need to have been // granted a reference to Client* and Handle* to do anything with it. @@ -5588,6 +5586,8 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_PHYSICAL_DISPLAY_IDS: case GET_PHYSICAL_DISPLAY_TOKEN: case SET_POWER_MODE: + case GET_DISPLAY_STATE: + case GET_DISPLAY_STATS: case CLEAR_BOOT_DISPLAY_MODE: case GET_BOOT_DISPLAY_MODE_SUPPORT: case SET_AUTO_LOW_LATENCY_MODE: @@ -7367,6 +7367,30 @@ binder::Status SurfaceComposerAIDL::setPowerMode(const sp& display, int return binder::Status::ok(); } +binder::Status SurfaceComposerAIDL::getDisplayStats(const sp& display, + gui::DisplayStatInfo* outStatInfo) { + DisplayStatInfo statInfo; + status_t status = mFlinger->getDisplayStats(display, &statInfo); + if (status == NO_ERROR) { + outStatInfo->vsyncTime = static_cast(statInfo.vsyncTime); + outStatInfo->vsyncPeriod = static_cast(statInfo.vsyncPeriod); + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getDisplayState(const sp& display, + gui::DisplayState* outState) { + ui::DisplayState state; + status_t status = mFlinger->getDisplayState(display, &state); + if (status == NO_ERROR) { + outState->layerStack = state.layerStack.id; + outState->orientation = static_cast(state.orientation); + outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; + outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; + } + return binder::Status::fromStatusT(status); +} + binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp& display) { status_t status = checkAccessPermission(); if (status != OK) return binder::Status::fromStatusT(status); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 51852a5f0d..4a6c0b8342 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -7,7 +7,6 @@ * * 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 @@ -24,6 +23,8 @@ #include #include +#include +#include #include #include #include @@ -563,9 +564,9 @@ private: status_t captureDisplay(DisplayId, const sp&); status_t captureLayers(const LayerCaptureArgs&, const sp&); - status_t getDisplayStats(const sp& displayToken, DisplayStatInfo* stats) override; + status_t getDisplayStats(const sp& displayToken, DisplayStatInfo* stats); status_t getDisplayState(const sp& displayToken, ui::DisplayState*) - EXCLUDES(mStateLock) override; + EXCLUDES(mStateLock); status_t getStaticDisplayInfo(const sp& displayToken, ui::StaticDisplayInfo*) EXCLUDES(mStateLock) override; status_t getDynamicDisplayInfo(const sp& displayToken, ui::DynamicDisplayInfo*) @@ -1456,6 +1457,10 @@ public: binder::Status getPrimaryPhysicalDisplayId(int64_t* outDisplayId) override; binder::Status getPhysicalDisplayToken(int64_t displayId, sp* outDisplay) override; binder::Status setPowerMode(const sp& display, int mode) override; + binder::Status getDisplayStats(const sp& display, + gui::DisplayStatInfo* outStatInfo) override; + binder::Status getDisplayState(const sp& display, + gui::DisplayState* outState) override; binder::Status clearBootDisplayMode(const sp& display) override; binder::Status getBootDisplayModeSupport(bool* outMode) override; binder::Status setAutoLowLatencyMode(const sp& display, bool on) override; -- cgit v1.2.3-59-g8ed1b