From 88930f96e88c4d23fa1265cca3e2fdb7aca4fb52 Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Wed, 7 Jun 2023 10:32:08 -0700 Subject: SF: improve RenderThread jank classificaion Mark UI frames that didn't make it to their expected presentation due to RenderThread animations as dropped. Screenshot from Perfetto: https://screenshot.googleplex.com/3pQuNaDYAhHLYu7 Bug: 210605870 Test: manual Change-Id: Ibc91bcaac2f9296ec0bddd5deebb4289c5b5bf7e --- libs/gui/Surface.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index ed691006e9..53a2f64d11 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1792,19 +1792,20 @@ int Surface::dispatchGetLastQueuedBuffer2(va_list args) { int Surface::dispatchSetFrameTimelineInfo(va_list args) { ATRACE_CALL(); - auto frameNumber = static_cast(va_arg(args, uint64_t)); - 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)); - auto useForRefreshRateSelection = static_cast(va_arg(args, int32_t)); - ALOGV("Surface::%s", __func__); + + const auto nativeWindowFtlInfo = static_cast( + va_arg(args, ANativeWindowFrameTimelineInfo)); + FrameTimelineInfo ftlInfo; - ftlInfo.vsyncId = frameTimelineVsyncId; - ftlInfo.inputEventId = inputEventId; - ftlInfo.startTimeNanos = startTimeNanos; - ftlInfo.useForRefreshRateSelection = useForRefreshRateSelection; - return setFrameTimelineInfo(frameNumber, ftlInfo); + ftlInfo.vsyncId = nativeWindowFtlInfo.frameTimelineVsyncId; + ftlInfo.inputEventId = nativeWindowFtlInfo.inputEventId; + ftlInfo.startTimeNanos = nativeWindowFtlInfo.startTimeNanos; + ftlInfo.useForRefreshRateSelection = nativeWindowFtlInfo.useForRefreshRateSelection; + ftlInfo.skippedFrameVsyncId = nativeWindowFtlInfo.skippedFrameVsyncId; + ftlInfo.skippedFrameStartTimeNanos = nativeWindowFtlInfo.skippedFrameStartTimeNanos; + + return setFrameTimelineInfo(nativeWindowFtlInfo.frameNumber, ftlInfo); } bool Surface::transformToDisplayInverse() const { -- cgit v1.2.3-59-g8ed1b From 6cdd3fd7dab0149041ee8dd7273fe83888d2b1e3 Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Thu, 7 Sep 2023 18:45:58 -0700 Subject: libgui: plumb setFrameRate thru BufferQueue The current implementation just assumes that the Surface and BLASTBufferQueue lives in the same process and rely on inheritance to handle setFrameRate. This doesn't work for any usecase that the Surface is Parceled to a diffrent process. Bug: 281695725 Test: atest CtsGraphicsTestCases --test-filter SetFrameRateTest* Change-Id: I4e08b92b618fa7b863ca3ef4f7b46d9f1c30c775 --- libs/gui/Android.bp | 53 ++++++++++------ libs/gui/BLASTBufferQueue.cpp | 19 ++++++ libs/gui/BufferQueue.cpp | 11 ++++ libs/gui/BufferQueueProducer.cpp | 25 ++++++++ libs/gui/FrameRateUtils.cpp | 65 +++++++++++++++++++ libs/gui/IGraphicBufferProducer.cpp | 40 +++++++++++- libs/gui/LayerState.cpp | 29 +-------- libs/gui/Surface.cpp | 22 ++++++- libs/gui/SurfaceComposerClient.cpp | 1 + libs/gui/include/gui/BLASTBufferQueue.h | 9 ++- libs/gui/include/gui/BufferQueue.h | 7 +- libs/gui/include/gui/BufferQueueProducer.h | 6 ++ libs/gui/include/gui/Flags.h | 22 +++++++ libs/gui/include/gui/FrameRateUtils.h | 26 ++++++++ libs/gui/include/gui/IConsumerListener.h | 8 +++ libs/gui/include/gui/IGraphicBufferProducer.h | 7 ++ libs/gui/include/gui/LayerState.h | 10 --- libs/gui/tests/Android.bp | 22 +++---- libs/gui/tests/BufferQueue_test.cpp | 29 +++++++++ libs/gui/tests/FrameRateUtilsTest.cpp | 74 ++++++++++++++++++++++ .../tests/unittests/SetFrameRateTest.cpp | 43 +------------ 21 files changed, 408 insertions(+), 120 deletions(-) create mode 100644 libs/gui/FrameRateUtils.cpp create mode 100644 libs/gui/include/gui/Flags.h create mode 100644 libs/gui/include/gui/FrameRateUtils.h create mode 100644 libs/gui/tests/FrameRateUtilsTest.cpp (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 2ea4d16260..9a27d2321b 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -204,27 +204,8 @@ cc_aconfig_library { aconfig_declarations: "libgui_flags", } -cc_library_shared { - name: "libgui", - vendor_available: true, - vndk: { - enabled: true, - private: true, - }, - double_loadable: true, - - defaults: ["libgui_bufferqueue-defaults"], - - static_libs: [ - "libgui_aidl_static", - "libgui_window_info_static", - "libguiflags", - ], - export_static_lib_headers: [ - "libgui_aidl_static", - "libgui_window_info_static", - ], - +filegroup { + name: "libgui-sources", srcs: [ ":framework_native_aidl_binder", ":framework_native_aidl_gui", @@ -268,11 +249,40 @@ cc_library_shared { "bufferqueue/2.0/B2HProducerListener.cpp", "bufferqueue/2.0/H2BGraphicBufferProducer.cpp", ], +} +cc_defaults { + name: "libgui-defaults", + defaults: ["libgui_bufferqueue-defaults"], + srcs: [":libgui-sources"], + static_libs: [ + "libgui_aidl_static", + "libgui_window_info_static", + "libguiflags", + ], shared_libs: [ "libbinder", "libGLESv2", ], +} + +cc_library_shared { + name: "libgui", + vendor_available: true, + vndk: { + enabled: true, + private: true, + }, + double_loadable: true, + + defaults: [ + "libgui-defaults", + ], + + export_static_lib_headers: [ + "libgui_aidl_static", + "libgui_window_info_static", + ], export_shared_lib_headers: [ "libbinder", @@ -346,6 +356,7 @@ filegroup { "BufferQueueProducer.cpp", "BufferQueueThreadState.cpp", "BufferSlot.cpp", + "FrameRateUtils.cpp", "FrameTimestamps.cpp", "GLConsumerUtils.cpp", "HdrMetadata.cpp", diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 207fa4fd31..dd0a028865 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,9 @@ #include #include +#include + +using namespace com::android::graphics::libgui; using namespace std::chrono_literals; namespace { @@ -139,6 +144,16 @@ void BLASTBufferItemConsumer::onSidebandStreamChanged() { } } +#if FLAG_BQ_SET_FRAME_RATE +void BLASTBufferItemConsumer::onSetFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) { + sp bbq = mBLASTBufferQueue.promote(); + if (bbq != nullptr) { + bbq->setFrameRate(frameRate, compatibility, changeFrameRateStrategy); + } +} +#endif + void BLASTBufferItemConsumer::resizeFrameEventHistory(size_t newSize) { Mutex::Autolock lock(mMutex); mFrameEventHistory.resize(newSize); @@ -890,6 +905,10 @@ public: status_t setFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override { + if (flags::bq_setframerate()) { + return Surface::setFrameRate(frameRate, compatibility, changeFrameRateStrategy); + } + std::lock_guard _lock{mMutex}; if (mDestroyed) { return DEAD_OBJECT; diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index 66cad03fec..ab0f6d213f 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace android { @@ -98,6 +99,16 @@ void BufferQueue::ProxyConsumerListener::addAndGetFrameTimestamps( } } +#if FLAG_BQ_SET_FRAME_RATE +void BufferQueue::ProxyConsumerListener::onSetFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) { + sp listener(mConsumerListener.promote()); + if (listener != nullptr) { + listener->onSetFrameRate(frameRate, compatibility, changeFrameRateStrategy); + } +} +#endif + void BufferQueue::createBufferQueue(sp* outProducer, sp* outConsumer, bool consumerIsSurfaceFlinger) { diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 920b83dba9..67dff6dec6 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -1751,4 +1753,27 @@ status_t BufferQueueProducer::setAutoPrerotation(bool autoPrerotation) { return NO_ERROR; } +#if FLAG_BQ_SET_FRAME_RATE +status_t BufferQueueProducer::setFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) { + ATRACE_CALL(); + BQ_LOGV("setFrameRate: %.2f", frameRate); + + if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy, + "BufferQueueProducer::setFrameRate")) { + return BAD_VALUE; + } + + sp listener; + { + std::lock_guard lock(mCore->mMutex); + listener = mCore->mConsumerListener; + } + if (listener != nullptr) { + listener->onSetFrameRate(frameRate, compatibility, changeFrameRateStrategy); + } + return NO_ERROR; +} +#endif + } // namespace android diff --git a/libs/gui/FrameRateUtils.cpp b/libs/gui/FrameRateUtils.cpp new file mode 100644 index 0000000000..6993bfab45 --- /dev/null +++ b/libs/gui/FrameRateUtils.cpp @@ -0,0 +1,65 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include + +namespace android { +// Returns true if the frameRate is valid. +// +// @param frameRate the frame rate in Hz +// @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* +// @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_* +// @param functionName calling function or nullptr. Used for logging +// @param privileged whether caller has unscoped surfaceflinger access +bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, + const char* inFunctionName, bool privileged) { + const char* functionName = inFunctionName != nullptr ? inFunctionName : "call"; + int floatClassification = std::fpclassify(frameRate); + if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) { + ALOGE("%s failed - invalid frame rate %f", functionName, frameRate); + return false; + } + + if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT && + compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE && + (!privileged || + (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT && + compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) { + ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName, + compatibility, privileged ? "yes" : "no"); + return false; + } + + if (__builtin_available(android 31, *)) { + if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS && + changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) { + ALOGE("%s failed - invalid change frame rate strategy value %d", functionName, + changeFrameRateStrategy); + if (FLAG_BQ_SET_FRAME_RATE) { + return false; + } + } + } + + return true; +} + +} // namespace android diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index 918ff2dd25..d0c09e481d 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -27,11 +27,12 @@ #include #include -#include -#include #include +#include #include #include +#include +#include namespace android { // ---------------------------------------------------------------------------- @@ -78,6 +79,7 @@ enum { CANCEL_BUFFERS, QUERY_MULTIPLE, GET_LAST_QUEUED_BUFFER2, + SET_FRAME_RATE, }; class BpGraphicBufferProducer : public BpInterface @@ -761,6 +763,21 @@ public: } return result; } +#if FLAG_BQ_SET_FRAME_RATE + virtual status_t setFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) override { + Parcel data, reply; + data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); + data.writeFloat(frameRate); + data.writeInt32(compatibility); + data.writeInt32(changeFrameRateStrategy); + status_t result = remote()->transact(SET_FRAME_RATE, data, &reply); + if (result == NO_ERROR) { + result = reply.readInt32(); + } + return result; + } +#endif }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -956,6 +973,14 @@ status_t IGraphicBufferProducer::setAutoPrerotation(bool autoPrerotation) { return INVALID_OPERATION; } +#if FLAG_BQ_SET_FRAME_RATE +status_t IGraphicBufferProducer::setFrameRate(float /*frameRate*/, int8_t /*compatibility*/, + int8_t /*changeFrameRateStrategy*/) { + // No-op for IGBP other than BufferQueue. + return INVALID_OPERATION; +} +#endif + status_t IGraphicBufferProducer::exportToParcel(Parcel* parcel) { status_t res = OK; res = parcel->writeUint32(USE_BUFFER_QUEUE); @@ -1497,6 +1522,17 @@ status_t BnGraphicBufferProducer::onTransact( reply->writeInt32(result); return NO_ERROR; } +#if FLAG_BQ_SET_FRAME_RATE + case SET_FRAME_RATE: { + CHECK_INTERFACE(IGraphicBuffer, data, reply); + float frameRate = data.readFloat(); + int8_t compatibility = data.readInt32(); + int8_t changeFrameRateStrategy = data.readInt32(); + status_t result = setFrameRate(frameRate, compatibility, changeFrameRateStrategy); + reply->writeInt32(result); + return NO_ERROR; + } +#endif } return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index e1afb524e7..9847c056b8 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -863,34 +864,6 @@ status_t InputWindowCommands::read(const Parcel& input) { return NO_ERROR; } -bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, - const char* inFunctionName, bool privileged) { - const char* functionName = inFunctionName != nullptr ? inFunctionName : "call"; - int floatClassification = std::fpclassify(frameRate); - if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) { - ALOGE("%s failed - invalid frame rate %f", functionName, frameRate); - return false; - } - - if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT && - compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE && - (!privileged || - (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT && - compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) { - ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName, - compatibility, privileged ? "yes" : "no"); - return false; - } - - if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS && - changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) { - ALOGE("%s failed - invalid change frame rate strategy value %d", functionName, - changeFrameRateStrategy); - } - - return true; -} - // ---------------------------------------------------------------------------- namespace gui { diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 53a2f64d11..a87f05357f 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -50,8 +51,11 @@ #include #include +#include + namespace android { +using namespace com::android::graphics::libgui; using gui::aidl_utils::statusTFromBinderStatus; using ui::Dataspace; @@ -2565,8 +2569,22 @@ void Surface::ProducerListenerProxy::onBuffersDiscarded(const std::vectoronBuffersDiscarded(discardedBufs); } -[[deprecated]] status_t Surface::setFrameRate(float /*frameRate*/, int8_t /*compatibility*/, - int8_t /*changeFrameRateStrategy*/) { +status_t Surface::setFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) { +#if FLAG_BQ_SET_FRAME_RATE + if (flags::bq_setframerate()) { + status_t err = mGraphicBufferProducer->setFrameRate(frameRate, compatibility, + changeFrameRateStrategy); + ALOGE_IF(err, "IGraphicBufferProducer::setFrameRate(%.2f) returned %s", frameRate, + strerror(-err)); + return err; + } +#else + static_cast(frameRate); + static_cast(compatibility); + static_cast(changeFrameRateStrategy); +#endif + ALOGI("Surface::setFrameRate is deprecated, setFrameRate hint is dropped as destination is not " "SurfaceFlinger"); // ISurfaceComposer no longer supports setFrameRate, we will return NO_ERROR when the api is diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 4db960e7fa..e0882ac6bb 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h index a49a85984f..02d7c4d2ac 100644 --- a/libs/gui/include/gui/BLASTBufferQueue.h +++ b/libs/gui/include/gui/BLASTBufferQueue.h @@ -17,9 +17,10 @@ #ifndef ANDROID_GUI_BLAST_BUFFER_QUEUE_H #define ANDROID_GUI_BLAST_BUFFER_QUEUE_H -#include -#include #include +#include +#include +#include #include #include @@ -58,6 +59,10 @@ public: protected: void onSidebandStreamChanged() override EXCLUDES(mMutex); +#if FLAG_BQ_SET_FRAME_RATE + void onSetFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) override; +#endif private: const wp mBLASTBufferQueue; diff --git a/libs/gui/include/gui/BufferQueue.h b/libs/gui/include/gui/BufferQueue.h index 690587f0e6..2756277f2c 100644 --- a/libs/gui/include/gui/BufferQueue.h +++ b/libs/gui/include/gui/BufferQueue.h @@ -19,9 +19,10 @@ #include #include +#include +#include #include #include -#include namespace android { @@ -69,6 +70,10 @@ public: void addAndGetFrameTimestamps( const NewFrameEventsEntry* newTimestamps, FrameEventHistoryDelta* outDelta) override; +#if FLAG_BQ_SET_FRAME_RATE + void onSetFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) override; +#endif private: // mConsumerListener is a weak reference to the IConsumerListener. This is // the raison d'etre of ProxyConsumerListener. diff --git a/libs/gui/include/gui/BufferQueueProducer.h b/libs/gui/include/gui/BufferQueueProducer.h index 1d13dab623..38805d0221 100644 --- a/libs/gui/include/gui/BufferQueueProducer.h +++ b/libs/gui/include/gui/BufferQueueProducer.h @@ -18,6 +18,7 @@ #define ANDROID_GUI_BUFFERQUEUEPRODUCER_H #include +#include #include namespace android { @@ -201,6 +202,11 @@ public: // See IGraphicBufferProducer::setAutoPrerotation virtual status_t setAutoPrerotation(bool autoPrerotation); +#if FLAG_BQ_SET_FRAME_RATE + // See IGraphicBufferProducer::setFrameRate + status_t setFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy) override; +#endif protected: // see IGraphicsBufferProducer::setMaxDequeuedBufferCount, but with the ability to retrieve the diff --git a/libs/gui/include/gui/Flags.h b/libs/gui/include/gui/Flags.h new file mode 100644 index 0000000000..a2cff56e97 --- /dev/null +++ b/libs/gui/include/gui/Flags.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +// TODO(281695725): replace this with build time flags, whenever they are available +#ifndef FLAG_BQ_SET_FRAME_RATE +#define FLAG_BQ_SET_FRAME_RATE false +#endif \ No newline at end of file diff --git a/libs/gui/include/gui/FrameRateUtils.h b/libs/gui/include/gui/FrameRateUtils.h new file mode 100644 index 0000000000..16896efe1f --- /dev/null +++ b/libs/gui/include/gui/FrameRateUtils.h @@ -0,0 +1,26 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace android { + +bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, + const char* inFunctionName, bool privileged = false); + +} // namespace android \ No newline at end of file diff --git a/libs/gui/include/gui/IConsumerListener.h b/libs/gui/include/gui/IConsumerListener.h index 0ab2399eb2..e183bf2668 100644 --- a/libs/gui/include/gui/IConsumerListener.h +++ b/libs/gui/include/gui/IConsumerListener.h @@ -19,6 +19,8 @@ #include #include +#include + #include #include @@ -90,6 +92,12 @@ public: // WARNING: This method can only be called when the BufferQueue is in the consumer's process. virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/, FrameEventHistoryDelta* /*outDelta*/) {} + +#if FLAG_BQ_SET_FRAME_RATE + // Notifies the consumer of a setFrameRate call from the producer side. + virtual void onSetFrameRate(float /*frameRate*/, int8_t /*compatibility*/, + int8_t /*changeFrameRateStrategy*/) {} +#endif }; #ifndef NO_BINDER diff --git a/libs/gui/include/gui/IGraphicBufferProducer.h b/libs/gui/include/gui/IGraphicBufferProducer.h index 98df83453d..3562906870 100644 --- a/libs/gui/include/gui/IGraphicBufferProducer.h +++ b/libs/gui/include/gui/IGraphicBufferProducer.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -676,6 +677,12 @@ public: // the width and height used for dequeueBuffer will be additionally swapped. virtual status_t setAutoPrerotation(bool autoPrerotation); +#if FLAG_BQ_SET_FRAME_RATE + // Sets the apps intended frame rate. + virtual status_t setFrameRate(float frameRate, int8_t compatibility, + int8_t changeFrameRateStrategy); +#endif + struct RequestBufferOutput : public Flattenable { RequestBufferOutput() = default; diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 8c360589f0..102a3c1e25 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -476,16 +476,6 @@ static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) return compare_type(lhs.token, rhs.token); } -// Returns true if the frameRate is valid. -// -// @param frameRate the frame rate in Hz -// @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* -// @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_* -// @param functionName calling function or nullptr. Used for logging -// @param privileged whether caller has unscoped surfaceflinger access -bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, - const char* functionName, bool privileged = false); - }; // namespace android #endif // ANDROID_SF_LAYER_STATE_H diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp index 462ce6e14f..38c0eed474 100644 --- a/libs/gui/tests/Android.bp +++ b/libs/gui/tests/Android.bp @@ -15,9 +15,13 @@ cc_test { name: "libgui_test", test_suites: ["device-tests"], - cflags: [ + defaults: ["libgui-defaults"], + + cppflags: [ "-Wall", "-Werror", + "-Wno-extra", + "-DFLAG_BQ_SET_FRAME_RATE=true", ], srcs: [ @@ -28,6 +32,7 @@ cc_test { "CompositorTiming_test.cpp", "CpuConsumer_test.cpp", "EndToEndNativeInputTest.cpp", + "FrameRateUtilsTest.cpp", "DisplayInfo_test.cpp", "DisplayedContentSampling_test.cpp", "FillBuffer.cpp", @@ -53,19 +58,12 @@ cc_test { "android.hardware.configstore@1.0", "android.hardware.configstore-utils", "libSurfaceFlingerProp", - "libbase", - "liblog", - "libEGL", "libGLESv1_CM", - "libGLESv2", - "libbinder", - "libcutils", - "libgui", - "libhidlbase", "libinput", - "libui", - "libutils", - "libnativewindow", + ], + + static_libs: [ + "libgmock", ], header_libs: ["libsurfaceflinger_headers"], diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp index 0168877478..17aa5f1350 100644 --- a/libs/gui/tests/BufferQueue_test.cpp +++ b/libs/gui/tests/BufferQueue_test.cpp @@ -37,14 +37,18 @@ #include +#include #include #include #include +#include + using namespace std::chrono_literals; namespace android { +using namespace com::android::graphics::libgui; class BufferQueueTest : public ::testing::Test { @@ -1261,6 +1265,31 @@ TEST_F(BufferQueueTest, TestProducerConnectDisconnect) { ASSERT_EQ(NO_INIT, mProducer->disconnect(NATIVE_WINDOW_API_CPU)); } +TEST_F(BufferQueueTest, TestBqSetFrameRateFlagBuildTimeIsSet) { + if (flags::bq_setframerate()) { + ASSERT_EQ(true, FLAG_BQ_SET_FRAME_RATE); + } +} + +struct BufferItemConsumerSetFrameRateListener : public BufferItemConsumer { + BufferItemConsumerSetFrameRateListener(const sp& consumer) + : BufferItemConsumer(consumer, GRALLOC_USAGE_SW_READ_OFTEN, 1) {} + + MOCK_METHOD(void, onSetFrameRate, (float, int8_t, int8_t), (override)); +}; + +TEST_F(BufferQueueTest, TestSetFrameRate) { + sp producer; + sp consumer; + BufferQueue::createBufferQueue(&producer, &consumer); + + sp bufferConsumer = + sp::make(consumer); + + EXPECT_CALL(*bufferConsumer, onSetFrameRate(12.34f, 1, 0)).Times(1); + producer->setFrameRate(12.34f, 1, 0); +} + class Latch { public: explicit Latch(int expected) : mExpected(expected) {} diff --git a/libs/gui/tests/FrameRateUtilsTest.cpp b/libs/gui/tests/FrameRateUtilsTest.cpp new file mode 100644 index 0000000000..5fe22b05f9 --- /dev/null +++ b/libs/gui/tests/FrameRateUtilsTest.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include + +namespace android { +using namespace com::android::graphics::libgui; + +TEST(FrameRateUtilsTest, ValidateFrameRate) { + EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, "")); + EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + + // Privileged APIs. + EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_FALSE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + + constexpr bool kPrivileged = true; + EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "", + kPrivileged)); + EXPECT_TRUE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "", + kPrivileged)); + + // Invalid frame rate. + EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, + ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + + // Invalid compatibility. + EXPECT_FALSE( + ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); + + // Invalid change frame rate strategy. + if (flags::bq_setframerate()) { + EXPECT_FALSE( + ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, -1, "")); + EXPECT_FALSE( + ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, 2, "")); + } +} + +} // namespace android diff --git a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp index 608fa762ef..9899d4290b 100644 --- a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp +++ b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp @@ -19,6 +19,7 @@ #include #include +#include #include // TODO(b/129481165): remove the #pragma below and fix conversion issues @@ -325,48 +326,6 @@ INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest, std::make_shared()), PrintToStringParamName); -TEST_F(SetFrameRateTest, ValidateFrameRate) { - EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, "")); - EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - - // Privileged APIs. - EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_FALSE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - - constexpr bool kPrivileged = true; - EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "", - kPrivileged)); - EXPECT_TRUE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "", - kPrivileged)); - - // Invalid frame rate. - EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT, - ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - - // Invalid compatibility. - EXPECT_FALSE( - ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "")); - - // Invalid change frame rate strategy. - EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, -1, "")); - EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, 2, "")); -} - TEST_P(SetFrameRateTest, SetOnParentActivatesTree) { const auto& layerFactory = GetParam(); -- cgit v1.2.3-59-g8ed1b From 107788e8ce8f855b7555680e222f563810a51793 Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Tue, 17 Oct 2023 12:31:08 -0700 Subject: libgui: use flag MACRO for BQ_SETFRAMERATE Bug: 281695725 Test: presubmit Change-Id: I644dadbfc72cd50d80c50d36da96078253bbc009 --- libs/bufferqueueconverter/Android.bp | 2 ++ libs/gui/Android.bp | 38 ++++++++++++++-------- libs/gui/BLASTBufferQueue.cpp | 6 ++-- libs/gui/BufferQueue.cpp | 3 +- libs/gui/BufferQueueProducer.cpp | 4 +-- libs/gui/FrameRateUtils.cpp | 6 ++-- libs/gui/IGraphicBufferProducer.cpp | 8 ++--- libs/gui/Surface.cpp | 4 +-- libs/gui/include/gui/BLASTBufferQueue.h | 6 ++-- libs/gui/include/gui/BufferQueue.h | 6 ++-- libs/gui/include/gui/BufferQueueProducer.h | 4 +-- libs/gui/include/gui/Flags.h | 22 ------------- libs/gui/include/gui/IConsumerListener.h | 6 ++-- libs/gui/include/gui/IGraphicBufferProducer.h | 5 +-- libs/gui/tests/Android.bp | 2 +- libs/gui/tests/BufferQueue_test.cpp | 4 +-- .../include/surfacetexture/SurfaceTexture.h | 4 +-- .../surfacetexture/SurfaceTexture.cpp | 2 +- 18 files changed, 63 insertions(+), 69 deletions(-) delete mode 100644 libs/gui/include/gui/Flags.h (limited to 'libs/gui/Surface.cpp') diff --git a/libs/bufferqueueconverter/Android.bp b/libs/bufferqueueconverter/Android.bp index d4605ea13a..3fe71cefce 100644 --- a/libs/bufferqueueconverter/Android.bp +++ b/libs/bufferqueueconverter/Android.bp @@ -34,5 +34,7 @@ cc_library { "libbase", "liblog", ], + static_libs: ["libguiflags"], export_include_dirs: ["include"], + export_static_lib_headers: ["libguiflags"], } diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index f17a6547f7..c84ee1f9da 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -20,6 +20,25 @@ package { default_applicable_licenses: ["frameworks_native_license"], } +aconfig_declarations { + name: "libgui_flags", + package: "com.android.graphics.libgui.flags", + srcs: ["libgui_flags.aconfig"], +} + +cc_aconfig_library { + name: "libguiflags", + host_supported: true, + vendor_available: true, + min_sdk_version: "29", + apex_available: [ + "//apex_available:platform", + "com.android.media.swcodec", + "test_com.android.media.swcodec", + ], + aconfig_declarations: "libgui_flags", +} + cc_library_headers { name: "libgui_headers", vendor_available: true, @@ -36,6 +55,8 @@ cc_library_headers { "android.hardware.graphics.bufferqueue@1.0", "android.hardware.graphics.bufferqueue@2.0", ], + static_libs: ["libguiflags"], + export_static_lib_headers: ["libguiflags"], min_sdk_version: "29", // TODO(b/218719284) can media use be constrained to libgui_bufferqueue_static? apex_available: [ @@ -192,19 +213,6 @@ cc_library_static { }, } -aconfig_declarations { - name: "libgui_flags", - package: "com.android.graphics.libgui.flags", - srcs: ["libgui_flags.aconfig"], -} - -cc_aconfig_library { - name: "libguiflags", - host_supported: true, - vendor_available: true, - aconfig_declarations: "libgui_flags", -} - filegroup { name: "libgui-sources", srcs: [ @@ -265,6 +273,9 @@ cc_defaults { "libbinder", "libGLESv2", ], + export_static_lib_headers: [ + "libguiflags", + ], } cc_library_shared { @@ -460,6 +471,7 @@ cc_library_static { static_libs: [ "libgtest", "libgmock", + "libguiflags", ], srcs: [ diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index dd0a028865..8d0331ebb5 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -26,7 +26,7 @@ #include #include #include -#include + #include #include #include @@ -41,8 +41,6 @@ #include #include -#include - using namespace com::android::graphics::libgui; using namespace std::chrono_literals; @@ -144,7 +142,7 @@ void BLASTBufferItemConsumer::onSidebandStreamChanged() { } } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void BLASTBufferItemConsumer::onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) { sp bbq = mBLASTBufferQueue.promote(); diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index ab0f6d213f..b0f6e69115 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -22,7 +22,6 @@ #include #include #include -#include namespace android { @@ -99,7 +98,7 @@ void BufferQueue::ProxyConsumerListener::addAndGetFrameTimestamps( } } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void BufferQueue::ProxyConsumerListener::onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) { sp listener(mConsumerListener.promote()); diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 67dff6dec6..19693e37cf 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -32,7 +32,7 @@ #include #include #include -#include + #include #include #include @@ -1753,7 +1753,7 @@ status_t BufferQueueProducer::setAutoPrerotation(bool autoPrerotation) { return NO_ERROR; } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) status_t BufferQueueProducer::setFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) { ATRACE_CALL(); diff --git a/libs/gui/FrameRateUtils.cpp b/libs/gui/FrameRateUtils.cpp index 6993bfab45..11524e2b51 100644 --- a/libs/gui/FrameRateUtils.cpp +++ b/libs/gui/FrameRateUtils.cpp @@ -14,14 +14,16 @@ * limitations under the License. */ -#include #include #include #include #include +#include + namespace android { +using namespace com::android::graphics::libgui; // Returns true if the frameRate is valid. // // @param frameRate the frame rate in Hz @@ -53,7 +55,7 @@ bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrame changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) { ALOGE("%s failed - invalid change frame rate strategy value %d", functionName, changeFrameRateStrategy); - if (FLAG_BQ_SET_FRAME_RATE) { + if (flags::bq_setframerate()) { return false; } } diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index d0c09e481d..e81c098b85 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -28,7 +28,7 @@ #include #include -#include + #include #include #include @@ -763,7 +763,7 @@ public: } return result; } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) virtual status_t setFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override { Parcel data, reply; @@ -973,7 +973,7 @@ status_t IGraphicBufferProducer::setAutoPrerotation(bool autoPrerotation) { return INVALID_OPERATION; } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) status_t IGraphicBufferProducer::setFrameRate(float /*frameRate*/, int8_t /*compatibility*/, int8_t /*changeFrameRateStrategy*/) { // No-op for IGBP other than BufferQueue. @@ -1522,7 +1522,7 @@ status_t BnGraphicBufferProducer::onTransact( reply->writeInt32(result); return NO_ERROR; } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) case SET_FRAME_RATE: { CHECK_INTERFACE(IGraphicBuffer, data, reply); float frameRate = data.readFloat(); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index a87f05357f..07a0cfed63 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -43,7 +43,7 @@ #include #include -#include + #include #include @@ -2571,7 +2571,7 @@ void Surface::ProducerListenerProxy::onBuffersDiscarded(const std::vectorsetFrameRate(frameRate, compatibility, changeFrameRateStrategy); diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h index 02d7c4d2ac..892215ec32 100644 --- a/libs/gui/include/gui/BLASTBufferQueue.h +++ b/libs/gui/include/gui/BLASTBufferQueue.h @@ -19,7 +19,7 @@ #include #include -#include + #include #include @@ -31,6 +31,8 @@ #include #include +#include + namespace android { class BLASTBufferQueue; @@ -59,7 +61,7 @@ public: protected: void onSidebandStreamChanged() override EXCLUDES(mMutex); -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override; #endif diff --git a/libs/gui/include/gui/BufferQueue.h b/libs/gui/include/gui/BufferQueue.h index 2756277f2c..0948c4d076 100644 --- a/libs/gui/include/gui/BufferQueue.h +++ b/libs/gui/include/gui/BufferQueue.h @@ -19,11 +19,13 @@ #include #include -#include + #include #include #include +#include + namespace android { class BufferQueue { @@ -70,7 +72,7 @@ public: void addAndGetFrameTimestamps( const NewFrameEventsEntry* newTimestamps, FrameEventHistoryDelta* outDelta) override; -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override; #endif diff --git a/libs/gui/include/gui/BufferQueueProducer.h b/libs/gui/include/gui/BufferQueueProducer.h index 38805d0221..de47483dca 100644 --- a/libs/gui/include/gui/BufferQueueProducer.h +++ b/libs/gui/include/gui/BufferQueueProducer.h @@ -18,7 +18,7 @@ #define ANDROID_GUI_BUFFERQUEUEPRODUCER_H #include -#include + #include namespace android { @@ -202,7 +202,7 @@ public: // See IGraphicBufferProducer::setAutoPrerotation virtual status_t setAutoPrerotation(bool autoPrerotation); -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) // See IGraphicBufferProducer::setFrameRate status_t setFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override; diff --git a/libs/gui/include/gui/Flags.h b/libs/gui/include/gui/Flags.h deleted file mode 100644 index a2cff56e97..0000000000 --- a/libs/gui/include/gui/Flags.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -// TODO(281695725): replace this with build time flags, whenever they are available -#ifndef FLAG_BQ_SET_FRAME_RATE -#define FLAG_BQ_SET_FRAME_RATE false -#endif \ No newline at end of file diff --git a/libs/gui/include/gui/IConsumerListener.h b/libs/gui/include/gui/IConsumerListener.h index e183bf2668..51d3959de7 100644 --- a/libs/gui/include/gui/IConsumerListener.h +++ b/libs/gui/include/gui/IConsumerListener.h @@ -19,13 +19,13 @@ #include #include -#include - #include #include #include +#include + namespace android { class BufferItem; @@ -93,7 +93,7 @@ public: virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/, FrameEventHistoryDelta* /*outDelta*/) {} -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) // Notifies the consumer of a setFrameRate call from the producer side. virtual void onSetFrameRate(float /*frameRate*/, int8_t /*compatibility*/, int8_t /*changeFrameRateStrategy*/) {} diff --git a/libs/gui/include/gui/IGraphicBufferProducer.h b/libs/gui/include/gui/IGraphicBufferProducer.h index 3562906870..7639e709ca 100644 --- a/libs/gui/include/gui/IGraphicBufferProducer.h +++ b/libs/gui/include/gui/IGraphicBufferProducer.h @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -42,6 +41,8 @@ #include #include +#include + namespace android { // ---------------------------------------------------------------------------- @@ -677,7 +678,7 @@ public: // the width and height used for dequeueBuffer will be additionally swapped. virtual status_t setAutoPrerotation(bool autoPrerotation); -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) // Sets the apps intended frame rate. virtual status_t setFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy); diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp index 38c0eed474..6dcd501404 100644 --- a/libs/gui/tests/Android.bp +++ b/libs/gui/tests/Android.bp @@ -21,7 +21,7 @@ cc_test { "-Wall", "-Werror", "-Wno-extra", - "-DFLAG_BQ_SET_FRAME_RATE=true", + "-DCOM_ANDROID_GRAPHICS_LIBGUI_FLAGS_BQ_SETFRAMERATE=true", ], srcs: [ diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp index 17aa5f1350..1410c7dce0 100644 --- a/libs/gui/tests/BufferQueue_test.cpp +++ b/libs/gui/tests/BufferQueue_test.cpp @@ -1266,9 +1266,7 @@ TEST_F(BufferQueueTest, TestProducerConnectDisconnect) { } TEST_F(BufferQueueTest, TestBqSetFrameRateFlagBuildTimeIsSet) { - if (flags::bq_setframerate()) { - ASSERT_EQ(true, FLAG_BQ_SET_FRAME_RATE); - } + ASSERT_EQ(flags::bq_setframerate(), COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE)); } struct BufferItemConsumerSetFrameRateListener : public BufferItemConsumer { diff --git a/libs/nativedisplay/include/surfacetexture/SurfaceTexture.h b/libs/nativedisplay/include/surfacetexture/SurfaceTexture.h index 32fb3508ff..099f47dbe1 100644 --- a/libs/nativedisplay/include/surfacetexture/SurfaceTexture.h +++ b/libs/nativedisplay/include/surfacetexture/SurfaceTexture.h @@ -19,7 +19,7 @@ #include #include #include -#include + #include #include #include @@ -352,7 +352,7 @@ protected: /** * onSetFrameRate Notifies the consumer of a setFrameRate call from the producer side. */ -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) override; #endif diff --git a/libs/nativedisplay/surfacetexture/SurfaceTexture.cpp b/libs/nativedisplay/surfacetexture/SurfaceTexture.cpp index c2535e0bf6..3a09204878 100644 --- a/libs/nativedisplay/surfacetexture/SurfaceTexture.cpp +++ b/libs/nativedisplay/surfacetexture/SurfaceTexture.cpp @@ -515,7 +515,7 @@ void SurfaceTexture::FrameAvailableListenerProxy::onFrameAvailable(const BufferI } } -#if FLAG_BQ_SET_FRAME_RATE +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) void SurfaceTexture::onSetFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy) { SFT_LOGV("onSetFrameRate: %.2f", frameRate); -- cgit v1.2.3-59-g8ed1b