diff options
89 files changed, 1523 insertions, 1434 deletions
diff --git a/cmds/flatland/GLHelper.cpp b/cmds/flatland/GLHelper.cpp index 3a3df08534..01f7d30a42 100644 --- a/cmds/flatland/GLHelper.cpp +++ b/cmds/flatland/GLHelper.cpp @@ -19,7 +19,7 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> namespace android { @@ -227,15 +227,15 @@ bool GLHelper::computeWindowScale(uint32_t w, uint32_t h, float* scale) { return false; } - DisplayConfig config; - status_t err = mSurfaceComposerClient->getActiveDisplayConfig(dpy, &config); + ui::DisplayMode mode; + status_t err = mSurfaceComposerClient->getActiveDisplayMode(dpy, &mode); if (err != NO_ERROR) { - fprintf(stderr, "SurfaceComposer::getActiveDisplayConfig failed: %#x\n", err); + fprintf(stderr, "SurfaceComposer::getActiveDisplayMode failed: %#x\n", err); return false; } - float scaleX = static_cast<float>(config.resolution.getWidth()) / w; - float scaleY = static_cast<float>(config.resolution.getHeight()) / h; + float scaleX = static_cast<float>(mode.resolution.getWidth()) / w; + float scaleY = static_cast<float>(mode.resolution.getHeight()) / h; *scale = scaleX < scaleY ? scaleX : scaleY; return true; diff --git a/include/android/bitmap.h b/include/android/bitmap.h index 2362c9e491..a70dffd756 100644 --- a/include/android/bitmap.h +++ b/include/android/bitmap.h @@ -31,18 +31,8 @@ #include <stddef.h> #include <jni.h> -#ifndef __ANDROID__ - // Value copied from 'bionic/libc/include/android/api-level.h' which is not available on - // non Android systems. It is set to 10000 which is same as __ANDROID_API_FUTURE__ value. - #ifndef __ANDROID_API__ - #define __ANDROID_API__ 10000 - #endif - - // Value copied from 'bionic/libc/include/android/versioning.h' which is not available on - // non Android systems - #ifndef __INTRODUCED_IN - #define __INTRODUCED_IN(api_level) - #endif +#if !defined(__INTRODUCED_IN) +#define __INTRODUCED_IN(__api_level) /* nothing */ #endif #ifdef __cplusplus diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h index 819a6a4c1f..cac67d4f8f 100644 --- a/include/android/imagedecoder.h +++ b/include/android/imagedecoder.h @@ -51,18 +51,8 @@ #include <android/rect.h> #include <stdint.h> -#ifndef __ANDROID__ - // Value copied from 'bionic/libc/include/android/api-level.h' which is not available on - // non Android systems. It is set to 10000 which is same as __ANDROID_API_FUTURE__ value. - #ifndef __ANDROID_API__ - #define __ANDROID_API__ 10000 - #endif - - // Value copied from 'bionic/libc/include/android/versioning.h' which is not available on - // non Android systems - #ifndef __INTRODUCED_IN - #define __INTRODUCED_IN(api_level) - #endif +#if !defined(__INTRODUCED_IN) +#define __INTRODUCED_IN(__api_level) /* nothing */ #endif #ifdef __cplusplus diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h index bb70588b8a..a44c261b3b 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h @@ -41,8 +41,6 @@ __BEGIN_DECLS android platform host build, you must use libbinder_ndk_host_user. #endif -#if __ANDROID_API__ >= 29 - typedef uint32_t binder_flags_t; enum { /** @@ -567,10 +565,6 @@ __attribute__((warn_unused_result)) AIBinder_DeathRecipient* AIBinder_DeathRecip */ void AIBinder_DeathRecipient_delete(AIBinder_DeathRecipient* recipient) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= 29 - -#if __ANDROID_API__ >= 30 - /** * Gets the extension registered with AIBinder_setExtension. * @@ -640,10 +634,6 @@ binder_status_t AIBinder_getExtension(AIBinder* binder, AIBinder** outExt) __INT */ binder_status_t AIBinder_setExtension(AIBinder* binder, AIBinder* ext) __INTRODUCED_IN(30); -#endif //__ANDROID_API__ >= 30 - -#if __ANDROID_API__ >= 31 - /** * Retrieve the class descriptor for the class. * @@ -728,8 +718,6 @@ AIBinder_Weak* AIBinder_Weak_clone(const AIBinder_Weak* weak); */ bool AIBinder_Weak_lt(const AIBinder_Weak* lhs, const AIBinder_Weak* rhs); -#endif //__ANDROID_API__ >= 31 - __END_DECLS /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h b/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h index cd1ff1fd79..6880d86e1a 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder_jni.h @@ -31,7 +31,6 @@ #include <jni.h> __BEGIN_DECLS -#if __ANDROID_API__ >= 29 /** * Converts an android.os.IBinder object into an AIBinder* object. @@ -67,7 +66,6 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_fromJavaBinder(JNIEnv* en __attribute__((warn_unused_result)) jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= 29 __END_DECLS /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel.h b/libs/binder/ndk/include_ndk/android/binder_parcel.h index ab67017fee..527b151457 100644 --- a/libs/binder/ndk/include_ndk/android/binder_parcel.h +++ b/libs/binder/ndk/include_ndk/android/binder_parcel.h @@ -36,7 +36,6 @@ struct AIBinder; typedef struct AIBinder AIBinder; __BEGIN_DECLS -#if __ANDROID_API__ >= 29 /** * This object represents a package of data that can be sent between processes. When transacting, an @@ -1119,7 +1118,6 @@ binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, // @END-PRIMITIVE-READ-WRITE -#endif //__ANDROID_API__ >= 29 /** * Reset the parcel to the initial status. * diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel_jni.h b/libs/binder/ndk/include_ndk/android/binder_parcel_jni.h index 65e1704439..384d4f7772 100644 --- a/libs/binder/ndk/include_ndk/android/binder_parcel_jni.h +++ b/libs/binder/ndk/include_ndk/android/binder_parcel_jni.h @@ -31,7 +31,6 @@ #include <jni.h> __BEGIN_DECLS -#if __ANDROID_API__ >= 30 /** * Converts an android.os.Parcel object into an AParcel* object. @@ -50,7 +49,6 @@ __BEGIN_DECLS __attribute__((warn_unused_result)) AParcel* AParcel_fromJavaParcel(JNIEnv* env, jobject parcel) __INTRODUCED_IN(30); -#endif //__ANDROID_API__ >= 30 __END_DECLS /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_status.h b/libs/binder/ndk/include_ndk/android/binder_status.h index 3a55f9480c..05b25e7c40 100644 --- a/libs/binder/ndk/include_ndk/android/binder_status.h +++ b/libs/binder/ndk/include_ndk/android/binder_status.h @@ -31,7 +31,6 @@ #include <sys/cdefs.h> __BEGIN_DECLS -#if __ANDROID_API__ >= 29 enum { STATUS_OK = 0, @@ -275,7 +274,6 @@ void AStatus_deleteDescription(const char* description) __INTRODUCED_IN(30); */ void AStatus_delete(AStatus* status) __INTRODUCED_IN(29); -#endif //__ANDROID_API__ >= 29 __END_DECLS /** @} */ diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index c2ec0fe078..1e6fc2b217 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -133,8 +133,10 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont if (enableTripleBuffering) { mProducer->setMaxDequeuedBufferCount(2); } - mBufferItemConsumer = - new BLASTBufferItemConsumer(mConsumer, GraphicBuffer::USAGE_HW_COMPOSER, 1, false); + mBufferItemConsumer = new BLASTBufferItemConsumer(mConsumer, + GraphicBuffer::USAGE_HW_COMPOSER | + GraphicBuffer::USAGE_HW_TEXTURE, + 1, false); static int32_t id = 0; auto consumerName = mName + "(BLAST Consumer)" + std::to_string(id); id++; diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp index 2ad484add3..9cd3f631c8 100644 --- a/libs/gui/DisplayEventDispatcher.cpp +++ b/libs/gui/DisplayEventDispatcher.cpp @@ -36,9 +36,7 @@ static const size_t EVENT_BUFFER_SIZE = 100; DisplayEventDispatcher::DisplayEventDispatcher( const sp<Looper>& looper, ISurfaceComposer::VsyncSource vsyncSource, ISurfaceComposer::EventRegistrationFlags eventRegistration) - : mLooper(looper), - mReceiver(vsyncSource, eventRegistration), - mVsyncState(VsyncState::Unregistered) { + : mLooper(looper), mReceiver(vsyncSource, eventRegistration), mWaitingForVsync(false) { ALOGV("dispatcher %p ~ Initializing display event dispatcher.", this); } @@ -68,37 +66,26 @@ void DisplayEventDispatcher::dispose() { } status_t DisplayEventDispatcher::scheduleVsync() { - switch (mVsyncState) { - case VsyncState::Unregistered: { - ALOGV("dispatcher %p ~ Scheduling vsync.", this); - - // Drain all pending events. - nsecs_t vsyncTimestamp; - PhysicalDisplayId vsyncDisplayId; - uint32_t vsyncCount; - VsyncEventData vsyncEventData; - if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount, - &vsyncEventData)) { - ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "", - this, ns2ms(static_cast<nsecs_t>(vsyncTimestamp))); - } - - status_t status = mReceiver.setVsyncRate(1); - if (status) { - ALOGW("Failed to set vsync rate, status=%d", status); - return status; - } - - mVsyncState = VsyncState::RegisteredAndWaitingForVsync; - break; + if (!mWaitingForVsync) { + ALOGV("dispatcher %p ~ Scheduling vsync.", this); + + // Drain all pending events. + nsecs_t vsyncTimestamp; + PhysicalDisplayId vsyncDisplayId; + uint32_t vsyncCount; + VsyncEventData vsyncEventData; + if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount, &vsyncEventData)) { + ALOGE("dispatcher %p ~ last event processed while scheduling was for %" PRId64 "", this, + ns2ms(static_cast<nsecs_t>(vsyncTimestamp))); } - case VsyncState::Registered: { - mVsyncState = VsyncState::RegisteredAndWaitingForVsync; - break; - } - case VsyncState::RegisteredAndWaitingForVsync: { - break; + + status_t status = mReceiver.requestNextVsync(); + if (status) { + ALOGW("Failed to request next vsync, status=%d", status); + return status; } + + mWaitingForVsync = true; } return OK; } @@ -136,23 +123,8 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) { ", displayId=%s, count=%d, vsyncId=%" PRId64, this, ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount, vsyncEventData.id); - switch (mVsyncState) { - case VsyncState::Unregistered: - ALOGW("Received unexpected VSYNC event"); - break; - case VsyncState::RegisteredAndWaitingForVsync: - mVsyncState = VsyncState::Registered; - dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData); - break; - case VsyncState::Registered: - status_t status = mReceiver.setVsyncRate(0); - if (status) { - ALOGW("Failed to reset vsync rate, status=%d", status); - return status; - } - mVsyncState = VsyncState::Unregistered; - break; - } + mWaitingForVsync = false; + dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount, vsyncEventData); } return 1; // keep the callback @@ -184,9 +156,9 @@ bool DisplayEventDispatcher::processPendingEvents(nsecs_t* outTimestamp, case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: dispatchHotplug(ev.header.timestamp, ev.header.displayId, ev.hotplug.connected); break; - case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: - dispatchConfigChanged(ev.header.timestamp, ev.header.displayId, - ev.config.configId, ev.config.vsyncPeriod); + case DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE: + dispatchModeChanged(ev.header.timestamp, ev.header.displayId, + ev.modeChange.modeId, ev.modeChange.vsyncPeriod); break; case DisplayEventReceiver::DISPLAY_EVENT_NULL: dispatchNullEvent(ev.header.timestamp, ev.header.displayId); diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index f68f3e134e..762746c0ce 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -36,8 +36,8 @@ #include <system/graphics.h> -#include <ui/DisplayConfig.h> #include <ui/DisplayInfo.h> +#include <ui/DisplayMode.h> #include <ui/DisplayStatInfo.h> #include <ui/DisplayState.h> #include <ui/HdrCapabilities.h> @@ -333,20 +333,19 @@ public: return reply.read(*info); } - status_t getDisplayConfigs(const sp<IBinder>& display, - Vector<DisplayConfig>* configs) override { + status_t getDisplayModes(const sp<IBinder>& display, Vector<ui::DisplayMode>* modes) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply); + remote()->transact(BnSurfaceComposer::GET_DISPLAY_MODES, data, &reply); const status_t result = reply.readInt32(); if (result == NO_ERROR) { - const size_t numConfigs = reply.readUint32(); - configs->clear(); - configs->resize(numConfigs); - for (size_t c = 0; c < numConfigs; ++c) { - memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)), - sizeof(DisplayConfig)); + const size_t numModes = reply.readUint32(); + modes->clear(); + modes->resize(numModes); + for (size_t i = 0; i < numModes; i++) { + memcpy(&(modes->editItemAt(i)), reply.readInplace(sizeof(ui::DisplayMode)), + sizeof(ui::DisplayMode)); } } return result; @@ -366,11 +365,11 @@ public: return result; } - int getActiveConfig(const sp<IBinder>& display) override { + int getActiveDisplayModeId(const sp<IBinder>& display) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply); + remote()->transact(BnSurfaceComposer::GET_ACTIVE_DISPLAY_MODE, data, &reply); return reply.readInt32(); } @@ -882,71 +881,70 @@ public: return error; } - status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, int32_t defaultConfig, - bool allowGroupSwitching, float primaryRefreshRateMin, - float primaryRefreshRateMax, - float appRequestRefreshRateMin, - float appRequestRefreshRateMax) override { + status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t defaultMode, + bool allowGroupSwitching, float primaryRefreshRateMin, + float primaryRefreshRateMax, float appRequestRefreshRateMin, + float appRequestRefreshRateMax) override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result); + ALOGE("setDesiredDisplayModeSpecs: failed to writeInterfaceToken: %d", result); return result; } result = data.writeStrongBinder(displayToken); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result); + ALOGE("setDesiredDisplayModeSpecs: failed to write display token: %d", result); return result; } - result = data.writeInt32(defaultConfig); + result = data.writeInt32(defaultMode); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result); + ALOGE("setDesiredDisplayModeSpecs failed to write defaultMode: %d", result); return result; } result = data.writeBool(allowGroupSwitching); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write allowGroupSwitching: %d", result); + ALOGE("setDesiredDisplayModeSpecs failed to write allowGroupSwitching: %d", result); return result; } result = data.writeFloat(primaryRefreshRateMin); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result); + ALOGE("setDesiredDisplayModeSpecs failed to write primaryRefreshRateMin: %d", result); return result; } result = data.writeFloat(primaryRefreshRateMax); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result); + ALOGE("setDesiredDisplayModeSpecs failed to write primaryRefreshRateMax: %d", result); return result; } result = data.writeFloat(appRequestRefreshRateMin); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d", + ALOGE("setDesiredDisplayModeSpecs failed to write appRequestRefreshRateMin: %d", result); return result; } result = data.writeFloat(appRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d", + ALOGE("setDesiredDisplayModeSpecs failed to write appRequestRefreshRateMax: %d", result); return result; } - result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data, - &reply); + result = + remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_MODE_SPECS, data, &reply); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result); + ALOGE("setDesiredDisplayModeSpecs failed to transact: %d", result); return result; } return reply.readInt32(); } - status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t* outDefaultConfig, bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax) override { - if (!outDefaultConfig || !outAllowGroupSwitching || !outPrimaryRefreshRateMin || + status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t* outDefaultMode, + bool* outAllowGroupSwitching, + float* outPrimaryRefreshRateMin, + float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, + float* outAppRequestRefreshRateMax) override { + if (!outDefaultMode || !outAllowGroupSwitching || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax || !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) { return BAD_VALUE; @@ -954,50 +952,55 @@ public: Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to writeInterfaceToken: %d", result); return result; } result = data.writeStrongBinder(displayToken); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to writeStrongBinder: %d", result); return result; } - result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data, - &reply); + result = + remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_MODE_SPECS, data, &reply); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to transact: %d", result); return result; } - result = reply.readInt32(outDefaultConfig); + int32_t defaultMode; + result = reply.readInt32(&defaultMode); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to read defaultMode: %d", result); return result; } + if (defaultMode < 0) { + ALOGE("%s: defaultMode must be non-negative but it was %d", __func__, defaultMode); + return BAD_VALUE; + } + *outDefaultMode = static_cast<size_t>(defaultMode); + result = reply.readBool(outAllowGroupSwitching); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read allowGroupSwitching: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to read allowGroupSwitching: %d", result); return result; } result = reply.readFloat(outPrimaryRefreshRateMin); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to read primaryRefreshRateMin: %d", result); return result; } result = reply.readFloat(outPrimaryRefreshRateMax); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result); + ALOGE("getDesiredDisplayModeSpecs failed to read primaryRefreshRateMax: %d", result); return result; } result = reply.readFloat(outAppRequestRefreshRateMin); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d", - result); + ALOGE("getDesiredDisplayModeSpecs failed to read appRequestRefreshRateMin: %d", result); return result; } result = reply.readFloat(outAppRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d", - result); + ALOGE("getDesiredDisplayModeSpecs failed to read appRequestRefreshRateMax: %d", result); return result; } return reply.readInt32(); @@ -1232,6 +1235,18 @@ public: } return reply.readInt32(); } + + status_t getExtraBufferCount(int* extraBuffers) const override { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); + status_t err = remote()->transact(BnSurfaceComposer::GET_EXTRA_BUFFER_COUNT, data, &reply); + if (err != NO_ERROR) { + ALOGE("getExtraBufferCount failed to read data: %s (%d)", strerror(-err), err); + return err; + } + + return reply.readInt32(extraBuffers); + } }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -1430,17 +1445,17 @@ status_t BnSurfaceComposer::onTransact( if (result != NO_ERROR) return result; return reply->write(info); } - case GET_DISPLAY_CONFIGS: { + case GET_DISPLAY_MODES: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - Vector<DisplayConfig> configs; + Vector<ui::DisplayMode> modes; const sp<IBinder> display = data.readStrongBinder(); - const status_t result = getDisplayConfigs(display, &configs); + const status_t result = getDisplayModes(display, &modes); reply->writeInt32(result); if (result == NO_ERROR) { - reply->writeUint32(static_cast<uint32_t>(configs.size())); - for (size_t c = 0; c < configs.size(); ++c) { - memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c], - sizeof(DisplayConfig)); + reply->writeUint32(static_cast<uint32_t>(modes.size())); + for (size_t i = 0; i < modes.size(); i++) { + memcpy(reply->writeInplace(sizeof(ui::DisplayMode)), &modes[i], + sizeof(ui::DisplayMode)); } } return NO_ERROR; @@ -1457,10 +1472,10 @@ status_t BnSurfaceComposer::onTransact( } return NO_ERROR; } - case GET_ACTIVE_CONFIG: { + case GET_ACTIVE_DISPLAY_MODE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IBinder> display = data.readStrongBinder(); - int id = getActiveConfig(display); + int id = getActiveDisplayModeId(display); reply->writeInt32(id); return NO_ERROR; } @@ -1844,56 +1859,59 @@ status_t BnSurfaceComposer::onTransact( } return removeRegionSamplingListener(listener); } - case SET_DESIRED_DISPLAY_CONFIG_SPECS: { + case SET_DESIRED_DISPLAY_MODE_SPECS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IBinder> displayToken = data.readStrongBinder(); - int32_t defaultConfig; - status_t result = data.readInt32(&defaultConfig); + int32_t defaultMode; + status_t result = data.readInt32(&defaultMode); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result); + ALOGE("setDesiredDisplayModeSpecs: failed to read defaultMode: %d", result); return result; } + if (defaultMode < 0) { + ALOGE("%s: defaultMode must be non-negative but it was %d", __func__, defaultMode); + return BAD_VALUE; + } bool allowGroupSwitching; result = data.readBool(&allowGroupSwitching); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read allowGroupSwitching: %d", - result); + ALOGE("setDesiredDisplayModeSpecs: failed to read allowGroupSwitching: %d", result); return result; } float primaryRefreshRateMin; result = data.readFloat(&primaryRefreshRateMin); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d", + ALOGE("setDesiredDisplayModeSpecs: failed to read primaryRefreshRateMin: %d", result); return result; } float primaryRefreshRateMax; result = data.readFloat(&primaryRefreshRateMax); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d", + ALOGE("setDesiredDisplayModeSpecs: failed to read primaryRefreshRateMax: %d", result); return result; } float appRequestRefreshRateMin; result = data.readFloat(&appRequestRefreshRateMin); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d", + ALOGE("setDesiredDisplayModeSpecs: failed to read appRequestRefreshRateMin: %d", result); return result; } float appRequestRefreshRateMax; result = data.readFloat(&appRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d", + ALOGE("setDesiredDisplayModeSpecs: failed to read appRequestRefreshRateMax: %d", result); return result; } - result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, allowGroupSwitching, - primaryRefreshRateMin, primaryRefreshRateMax, - appRequestRefreshRateMin, - appRequestRefreshRateMax); + result = setDesiredDisplayModeSpecs(displayToken, static_cast<size_t>(defaultMode), + allowGroupSwitching, primaryRefreshRateMin, + primaryRefreshRateMax, appRequestRefreshRateMin, + appRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: " + ALOGE("setDesiredDisplayModeSpecs: failed to call setDesiredDisplayModeSpecs: " "%d", result); return result; @@ -1901,10 +1919,10 @@ status_t BnSurfaceComposer::onTransact( reply->writeInt32(result); return result; } - case GET_DESIRED_DISPLAY_CONFIG_SPECS: { + case GET_DESIRED_DISPLAY_MODE_SPECS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IBinder> displayToken = data.readStrongBinder(); - int32_t defaultConfig; + size_t defaultMode; bool allowGroupSwitching; float primaryRefreshRateMin; float primaryRefreshRateMax; @@ -1912,49 +1930,49 @@ status_t BnSurfaceComposer::onTransact( float appRequestRefreshRateMax; status_t result = - getDesiredDisplayConfigSpecs(displayToken, &defaultConfig, &allowGroupSwitching, - &primaryRefreshRateMin, &primaryRefreshRateMax, - &appRequestRefreshRateMin, - &appRequestRefreshRateMax); + getDesiredDisplayModeSpecs(displayToken, &defaultMode, &allowGroupSwitching, + &primaryRefreshRateMin, &primaryRefreshRateMax, + &appRequestRefreshRateMin, + &appRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: " + ALOGE("getDesiredDisplayModeSpecs: failed to get getDesiredDisplayModeSpecs: " "%d", result); return result; } - result = reply->writeInt32(defaultConfig); + result = reply->writeInt32(static_cast<int32_t>(defaultMode)); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result); + ALOGE("getDesiredDisplayModeSpecs: failed to write defaultMode: %d", result); return result; } result = reply->writeBool(allowGroupSwitching); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write allowGroupSwitching: %d", + ALOGE("getDesiredDisplayModeSpecs: failed to write allowGroupSwitching: %d", result); return result; } result = reply->writeFloat(primaryRefreshRateMin); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d", + ALOGE("getDesiredDisplayModeSpecs: failed to write primaryRefreshRateMin: %d", result); return result; } result = reply->writeFloat(primaryRefreshRateMax); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d", + ALOGE("getDesiredDisplayModeSpecs: failed to write primaryRefreshRateMax: %d", result); return result; } result = reply->writeFloat(appRequestRefreshRateMin); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d", + ALOGE("getDesiredDisplayModeSpecs: failed to write appRequestRefreshRateMin: %d", result); return result; } result = reply->writeFloat(appRequestRefreshRateMax); if (result != NO_ERROR) { - ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d", + ALOGE("getDesiredDisplayModeSpecs: failed to write appRequestRefreshRateMax: %d", result); return result; } @@ -2101,6 +2119,16 @@ status_t BnSurfaceComposer::onTransact( SAFE_PARCEL(reply->writeInt32, priority); return NO_ERROR; } + case GET_EXTRA_BUFFER_COUNT: { + CHECK_INTERFACE(ISurfaceComposer, data, reply); + int extraBuffers = 0; + int err = getExtraBufferCount(&extraBuffers); + if (err != NO_ERROR) { + return err; + } + SAFE_PARCEL(reply->writeInt32, extraBuffers); + return NO_ERROR; + } default: { return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 59ad8d28bd..07fc0694d6 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1499,6 +1499,9 @@ int Surface::perform(int operation, va_list args) case NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO: res = dispatchSetFrameTimelineInfo(args); break; + case NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT: + res = dispatchGetExtraBufferCount(args); + break; default: res = NAME_NOT_FOUND; break; @@ -1815,6 +1818,14 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) { return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId}); } +int Surface::dispatchGetExtraBufferCount(va_list args) { + ATRACE_CALL(); + auto extraBuffers = static_cast<int*>(va_arg(args, int*)); + + ALOGV("Surface::dispatchGetExtraBufferCount"); + return getExtraBufferCount(extraBuffers); +} + bool Surface::transformToDisplayInverse() { return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) == NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; @@ -2584,4 +2595,8 @@ status_t Surface::setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInf return composerService()->setFrameTimelineInfo(mGraphicBufferProducer, frameTimelineInfo); } +status_t Surface::getExtraBufferCount(int* extraBuffers) const { + return composerService()->getExtraBufferCount(extraBuffers); +} + }; // namespace android diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 73807c4bb6..27fb2a8cd7 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -39,7 +39,7 @@ #include <gui/LayerState.h> #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #ifndef NO_INPUT #include <input/InputWindow.h> @@ -1819,52 +1819,51 @@ status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, Displ return ComposerService::getComposerService()->getDisplayInfo(display, info); } -status_t SurfaceComposerClient::getDisplayConfigs(const sp<IBinder>& display, - Vector<DisplayConfig>* configs) { - return ComposerService::getComposerService()->getDisplayConfigs(display, configs); +status_t SurfaceComposerClient::getDisplayModes(const sp<IBinder>& display, + Vector<ui::DisplayMode>* modes) { + return ComposerService::getComposerService()->getDisplayModes(display, modes); } -status_t SurfaceComposerClient::getActiveDisplayConfig(const sp<IBinder>& display, - DisplayConfig* config) { - Vector<DisplayConfig> configs; - status_t result = getDisplayConfigs(display, &configs); +status_t SurfaceComposerClient::getActiveDisplayMode(const sp<IBinder>& display, + ui::DisplayMode* mode) { + Vector<ui::DisplayMode> modes; + status_t result = getDisplayModes(display, &modes); if (result != NO_ERROR) { return result; } - int activeId = getActiveConfig(display); + int activeId = getActiveDisplayModeId(display); if (activeId < 0) { - ALOGE("No active configuration found"); + ALOGE("No active mode found"); return NAME_NOT_FOUND; } - *config = configs[static_cast<size_t>(activeId)]; + *mode = modes[static_cast<size_t>(activeId)]; return NO_ERROR; } -int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) { - return ComposerService::getComposerService()->getActiveConfig(display); +int SurfaceComposerClient::getActiveDisplayModeId(const sp<IBinder>& display) { + return ComposerService::getComposerService()->getActiveDisplayModeId(display); } -status_t SurfaceComposerClient::setDesiredDisplayConfigSpecs( - const sp<IBinder>& displayToken, int32_t defaultConfig, bool allowGroupSwitching, +status_t SurfaceComposerClient::setDesiredDisplayModeSpecs( + const sp<IBinder>& displayToken, size_t defaultMode, bool allowGroupSwitching, float primaryRefreshRateMin, float primaryRefreshRateMax, float appRequestRefreshRateMin, float appRequestRefreshRateMax) { return ComposerService::getComposerService() - ->setDesiredDisplayConfigSpecs(displayToken, defaultConfig, allowGroupSwitching, - primaryRefreshRateMin, primaryRefreshRateMax, - appRequestRefreshRateMin, appRequestRefreshRateMax); + ->setDesiredDisplayModeSpecs(displayToken, defaultMode, allowGroupSwitching, + primaryRefreshRateMin, primaryRefreshRateMax, + appRequestRefreshRateMin, appRequestRefreshRateMax); } -status_t SurfaceComposerClient::getDesiredDisplayConfigSpecs( - const sp<IBinder>& displayToken, int32_t* outDefaultConfig, bool* outAllowGroupSwitching, +status_t SurfaceComposerClient::getDesiredDisplayModeSpecs( + const sp<IBinder>& displayToken, size_t* outDefaultMode, bool* outAllowGroupSwitching, float* outPrimaryRefreshRateMin, float* outPrimaryRefreshRateMax, float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) { return ComposerService::getComposerService() - ->getDesiredDisplayConfigSpecs(displayToken, outDefaultConfig, outAllowGroupSwitching, - outPrimaryRefreshRateMin, outPrimaryRefreshRateMax, - outAppRequestRefreshRateMin, - outAppRequestRefreshRateMax); + ->getDesiredDisplayModeSpecs(displayToken, outDefaultMode, outAllowGroupSwitching, + outPrimaryRefreshRateMin, outPrimaryRefreshRateMax, + outAppRequestRefreshRateMin, outAppRequestRefreshRateMax); } status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display, diff --git a/libs/gui/include/gui/DisplayEventDispatcher.h b/libs/gui/include/gui/DisplayEventDispatcher.h index 4175a49853..d74c2ba72b 100644 --- a/libs/gui/include/gui/DisplayEventDispatcher.h +++ b/libs/gui/include/gui/DisplayEventDispatcher.h @@ -52,20 +52,7 @@ protected: private: sp<Looper> mLooper; DisplayEventReceiver mReceiver; - // The state of vsync event registration and whether the client is expecting - // an event or not. - enum class VsyncState { - // The dispatcher is not registered for vsync events. - Unregistered, - // The dispatcher is registered to receive vsync events but should not dispatch it to the - // client as the client is not expecting a vsync event. - Registered, - - // The dispatcher is registered to receive vsync events and supposed to dispatch it to - // the client. - RegisteredAndWaitingForVsync, - }; - VsyncState mVsyncState; + bool mWaitingForVsync; std::vector<FrameRateOverride> mFrameRateOverrides; @@ -73,8 +60,8 @@ private: VsyncEventData vsyncEventData) = 0; virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) = 0; - virtual void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId, - int32_t configId, nsecs_t vsyncPeriod) = 0; + virtual void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId, + nsecs_t vsyncPeriod) = 0; // AChoreographer-specific hook for processing null-events so that looper // can be properly poked. virtual void dispatchNullEvent(nsecs_t timestamp, PhysicalDisplayId displayId) = 0; diff --git a/libs/gui/include/gui/DisplayEventReceiver.h b/libs/gui/include/gui/DisplayEventReceiver.h index 3191fc9ab5..7179a20d22 100644 --- a/libs/gui/include/gui/DisplayEventReceiver.h +++ b/libs/gui/include/gui/DisplayEventReceiver.h @@ -52,7 +52,7 @@ public: enum { DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'), DISPLAY_EVENT_HOTPLUG = fourcc('p', 'l', 'u', 'g'), - DISPLAY_EVENT_CONFIG_CHANGED = fourcc('c', 'o', 'n', 'f'), + DISPLAY_EVENT_MODE_CHANGE = fourcc('m', 'o', 'd', 'e'), DISPLAY_EVENT_NULL = fourcc('n', 'u', 'l', 'l'), DISPLAY_EVENT_FRAME_RATE_OVERRIDE = fourcc('r', 'a', 't', 'e'), DISPLAY_EVENT_FRAME_RATE_OVERRIDE_FLUSH = fourcc('f', 'l', 's', 'h'), @@ -82,8 +82,8 @@ public: bool connected; }; - struct Config { - int32_t configId; + struct ModeChange { + int32_t modeId; nsecs_t vsyncPeriod __attribute__((aligned(8))); }; @@ -96,7 +96,7 @@ public: union { VSync vsync; Hotplug hotplug; - Config config; + ModeChange modeChange; FrameRateOverride frameRateOverride; }; }; @@ -106,7 +106,7 @@ public: * DisplayEventReceiver creates and registers an event connection with * SurfaceFlinger. VSync events are disabled by default. Call setVSyncRate * or requestNextVsync to receive them. - * To receive ConfigChanged and/or FrameRateOverrides events specify this in + * To receive ModeChanged and/or FrameRateOverrides events specify this in * the constructor. Other events start being delivered immediately. */ explicit DisplayEventReceiver( diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 81ff6b0d8d..292838e9ae 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -54,7 +54,6 @@ namespace android { struct client_cache_t; struct ComposerState; struct DisplayCaptureArgs; -struct DisplayConfig; struct DisplayInfo; struct DisplayStatInfo; struct DisplayState; @@ -73,6 +72,7 @@ using gui::IScreenCaptureListener; namespace ui { +struct DisplayMode; struct DisplayState; } // namespace ui @@ -112,7 +112,7 @@ public: }; enum class EventRegistration { - configChanged = 1 << 0, + modeChanged = 1 << 0, frameRateOverride = 1 << 1, }; @@ -207,15 +207,15 @@ public: virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*) = 0; /** - * Get configurations supported by given physical display. + * Get modes supported by given physical display. */ - virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*) = 0; + virtual status_t getDisplayModes(const sp<IBinder>& display, Vector<ui::DisplayMode>*) = 0; /** - * Get the index into configurations returned by getDisplayConfigs, - * corresponding to the active configuration. + * Get the index into modes returned by getDisplayModes, + * corresponding to the active mode. */ - virtual int getActiveConfig(const sp<IBinder>& display) = 0; + virtual int getActiveDisplayModeId(const sp<IBinder>& display) = 0; virtual status_t getDisplayColorModes(const sp<IBinder>& display, Vector<ui::ColorMode>* outColorModes) = 0; @@ -386,34 +386,31 @@ public: /* Sets the refresh rate boundaries for the display. * * The primary refresh rate range represents display manager's general guidance on the display - * configs we'll consider when switching refresh rates. Unless we get an explicit signal from an + * modes we'll consider when switching refresh rates. Unless we get an explicit signal from an * app, we should stay within this range. * - * The app request refresh rate range allows us to consider more display configs when switching + * The app request refresh rate range allows us to consider more display modes when switching * refresh rates. Although we should generally stay within the primary range, specific * considerations, such as layer frame rate settings specified via the setFrameRate() api, may * cause us to go outside the primary range. We never go outside the app request range. The app * request range will be greater than or equal to the primary refresh rate range, never smaller. * - * defaultConfig is used to narrow the list of display configs SurfaceFlinger will consider - * switching between. Only configs with a config group and resolution matching defaultConfig - * will be considered for switching. The defaultConfig index corresponds to the list of configs - * returned from getDisplayConfigs(). - */ - virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t defaultConfig, bool allowGroupSwitching, - float primaryRefreshRateMin, - float primaryRefreshRateMax, - float appRequestRefreshRateMin, - float appRequestRefreshRateMax) = 0; - - virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t* outDefaultConfig, - bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax) = 0; + * defaultMode is used to narrow the list of display modes SurfaceFlinger will consider + * switching between. Only modes with a mode group and resolution matching defaultMode + * will be considered for switching. The defaultMode index corresponds to the list of modes + * returned from getDisplayModes(). + */ + virtual status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t defaultMode, + bool allowGroupSwitching, + float primaryRefreshRateMin, + float primaryRefreshRateMax, + float appRequestRefreshRateMin, + float appRequestRefreshRateMax) = 0; + + virtual status_t getDesiredDisplayModeSpecs( + const sp<IBinder>& displayToken, size_t* outDefaultMode, bool* outAllowGroupSwitching, + float* outPrimaryRefreshRateMin, float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) = 0; /* * Gets whether brightness operations are supported on a display. * @@ -508,6 +505,24 @@ public: * Gets priority of the RenderEngine in SurfaceFlinger. */ virtual int getGPUContextPriority() = 0; + + /** + * Gets the extra buffers a client would need to allocate if it passes + * the Choreographer#getVsyncId with its buffers. + * + * When Choreographer#getVsyncId is passed to SurfaceFlinger, it is used + * as an indication of when to latch the buffer. SurfaceFlinger will make + * sure that it will give the app at least the time configured as the + * 'appDuration' before trying to latch the buffer. + * + * The total buffers needed for a given configuration is basically the + * numbers of vsyncs a single buffer is used across the stack. For the default + * configuration a buffer is held ~1 vsync by the app, ~1 vsync by SurfaceFlinger + * and 1 vsync by the display. The extra buffers are calculated as the + * number of additional buffers on top of the 3 buffers already allocated + * by the app. + */ + virtual status_t getExtraBufferCount(int* extraBuffers) const = 0; }; // ---------------------------------------------------------------------------- @@ -527,8 +542,8 @@ public: SET_TRANSACTION_STATE, AUTHENTICATE_SURFACE, GET_SUPPORTED_FRAME_TIMESTAMPS, - GET_DISPLAY_CONFIGS, - GET_ACTIVE_CONFIG, + GET_DISPLAY_MODES, + GET_ACTIVE_DISPLAY_MODE, GET_DISPLAY_STATE, CAPTURE_DISPLAY, CAPTURE_LAYERS, @@ -554,8 +569,8 @@ public: GET_PHYSICAL_DISPLAY_IDS, ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, - SET_DESIRED_DISPLAY_CONFIG_SPECS, - GET_DESIRED_DISPLAY_CONFIG_SPECS, + SET_DESIRED_DISPLAY_MODE_SPECS, + GET_DESIRED_DISPLAY_MODE_SPECS, GET_DISPLAY_BRIGHTNESS_SUPPORT, SET_DISPLAY_BRIGHTNESS, CAPTURE_DISPLAY_BY_ID, @@ -570,6 +585,7 @@ public: SET_FRAME_TIMELINE_INFO, ADD_TRANSACTION_TRACE_LISTENER, GET_GPU_CONTEXT_PRIORITY, + GET_EXTRA_BUFFER_COUNT, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index b6b5c7ca5e..58812214d2 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -189,6 +189,7 @@ public: virtual status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless); virtual status_t setFrameTimelineInfo(const FrameTimelineInfo& info); + virtual status_t getExtraBufferCount(int* extraBuffers) const; protected: virtual ~Surface(); @@ -275,6 +276,7 @@ private: int dispatchAddQueryInterceptor(va_list args); int dispatchGetLastQueuedBuffer(va_list args); int dispatchSetFrameTimelineInfo(va_list args); + int dispatchGetExtraBufferCount(va_list args); bool transformToDisplayInverse(); protected: diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 61c0ab66a1..e89f3a7b44 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -110,30 +110,29 @@ public: // Get immutable information about given physical display. static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*); - // Get configurations supported by given physical display. - static status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*); + // Get modes supported by given physical display. + static status_t getDisplayModes(const sp<IBinder>& display, Vector<ui::DisplayMode>*); - // Get the ID of the active DisplayConfig, as getDisplayConfigs index. - static int getActiveConfig(const sp<IBinder>& display); + // Get the ID of the active DisplayMode, as getDisplayModes index. + static int getActiveDisplayModeId(const sp<IBinder>& display); - // Shorthand for getDisplayConfigs element at getActiveConfig index. - static status_t getActiveDisplayConfig(const sp<IBinder>& display, DisplayConfig*); + // Shorthand for getDisplayModes element at getActiveDisplayModeId index. + static status_t getActiveDisplayMode(const sp<IBinder>& display, ui::DisplayMode*); // Sets the refresh rate boundaries for the display. - static status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t defaultConfig, bool allowGroupSwitching, - float primaryRefreshRateMin, - float primaryRefreshRateMax, - float appRequestRefreshRateMin, - float appRequestRefreshRateMax); + static status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t defaultMode, + bool allowGroupSwitching, + float primaryRefreshRateMin, + float primaryRefreshRateMax, + float appRequestRefreshRateMin, + float appRequestRefreshRateMax); // Gets the refresh rate boundaries for the display. - static status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t* outDefaultConfig, - bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax); + static status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, + size_t* outDefaultMode, bool* outAllowGroupSwitching, + float* outPrimaryRefreshRateMin, + float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, + float* outAppRequestRefreshRateMax); // Gets the list of supported color modes for the given display static status_t getDisplayColorModes(const sp<IBinder>& display, diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp index 70e656da9b..5447b7659b 100644 --- a/libs/gui/tests/BLASTBufferQueue_test.cpp +++ b/libs/gui/tests/BLASTBufferQueue_test.cpp @@ -28,7 +28,7 @@ #include <gui/SurfaceComposerClient.h> #include <gui/SyncScreenCaptureListener.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <ui/GraphicBuffer.h> #include <ui/GraphicTypes.h> #include <ui/Transform.h> @@ -107,9 +107,9 @@ protected: t.apply(); t.clear(); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(mDisplayToken, &config)); - const ui::Size& resolution = config.resolution; + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &mode)); + const ui::Size& resolution = mode.resolution; mDisplayWidth = resolution.getWidth(); mDisplayHeight = resolution.getHeight(); diff --git a/libs/gui/tests/DisplayEventStructLayout_test.cpp b/libs/gui/tests/DisplayEventStructLayout_test.cpp index c5093e2d88..7dbba31ba8 100644 --- a/libs/gui/tests/DisplayEventStructLayout_test.cpp +++ b/libs/gui/tests/DisplayEventStructLayout_test.cpp @@ -25,7 +25,7 @@ namespace android::test { TEST(DisplayEventStructLayoutTest, TestEventAlignment) { CHECK_OFFSET(DisplayEventReceiver::Event, vsync, 24); CHECK_OFFSET(DisplayEventReceiver::Event, hotplug, 24); - CHECK_OFFSET(DisplayEventReceiver::Event, config, 24); + CHECK_OFFSET(DisplayEventReceiver::Event, modeChange, 24); CHECK_OFFSET(DisplayEventReceiver::Event::Header, type, 0); CHECK_OFFSET(DisplayEventReceiver::Event::Header, displayId, 8); @@ -38,8 +38,8 @@ TEST(DisplayEventStructLayoutTest, TestEventAlignment) { CHECK_OFFSET(DisplayEventReceiver::Event::Hotplug, connected, 0); - CHECK_OFFSET(DisplayEventReceiver::Event::Config, configId, 0); - CHECK_OFFSET(DisplayEventReceiver::Event::Config, vsyncPeriod, 8); + CHECK_OFFSET(DisplayEventReceiver::Event::ModeChange, modeId, 0); + CHECK_OFFSET(DisplayEventReceiver::Event::ModeChange, vsyncPeriod, 8); CHECK_OFFSET(DisplayEventReceiver::Event::FrameRateOverride, uid, 0); CHECK_OFFSET(DisplayEventReceiver::Event::FrameRateOverride, frameRateHz, 8); diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index 31cbbdc75c..d65a40baf6 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -41,7 +41,7 @@ #include <input/InputTransport.h> #include <input/InputWindow.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <ui/Rect.h> #include <ui/Region.h> @@ -272,13 +272,13 @@ public: const auto display = mComposerClient->getInternalDisplayToken(); ASSERT_NE(display, nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayConfig(display, &config)); + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayMode(display, &mode)); // After a new buffer is queued, SurfaceFlinger is notified and will // latch the new buffer on next vsync. Let's heuristically wait for 3 // vsyncs. - mBufferPostDelay = static_cast<int32_t>(1e6 / config.refreshRate) * 3; + mBufferPostDelay = static_cast<int32_t>(1e6 / mode.refreshRate) * 3; } void TearDown() { diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 3f7a5b1785..43909ac00d 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -737,7 +737,7 @@ public: status_t getDisplayInfo(const sp<IBinder>& /*display*/, DisplayInfo*) override { return NO_ERROR; } - status_t getDisplayConfigs(const sp<IBinder>& /*display*/, Vector<DisplayConfig>*) override { + status_t getDisplayModes(const sp<IBinder>& /*display*/, Vector<ui::DisplayMode>*) override { return NO_ERROR; } status_t getDisplayState(const sp<IBinder>& /*display*/, ui::DisplayState*) override { @@ -745,7 +745,7 @@ public: } status_t getDisplayStats(const sp<IBinder>& /*display*/, DisplayStatInfo* /*stats*/) override { return NO_ERROR; } - int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; } + int getActiveDisplayModeId(const sp<IBinder>& /*display*/) override { return 0; } status_t getDisplayColorModes(const sp<IBinder>& /*display*/, Vector<ColorMode>* /*outColorModes*/) override { return NO_ERROR; @@ -843,21 +843,21 @@ public: const sp<IRegionSamplingListener>& /*listener*/) override { return NO_ERROR; } - status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& /*displayToken*/, - int32_t /*defaultConfig*/, bool /*allowGroupSwitching*/, - float /*primaryRefreshRateMin*/, - float /*primaryRefreshRateMax*/, - float /*appRequestRefreshRateMin*/, - float /*appRequestRefreshRateMax*/) { + status_t setDesiredDisplayModeSpecs(const sp<IBinder>& /*displayToken*/, size_t /*defaultMode*/, + bool /*allowGroupSwitching*/, + float /*primaryRefreshRateMin*/, + float /*primaryRefreshRateMax*/, + float /*appRequestRefreshRateMin*/, + float /*appRequestRefreshRateMax*/) { return NO_ERROR; } - status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& /*displayToken*/, - int32_t* /*outDefaultConfig*/, - bool* /*outAllowGroupSwitching*/, - float* /*outPrimaryRefreshRateMin*/, - float* /*outPrimaryRefreshRateMax*/, - float* /*outAppRequestRefreshRateMin*/, - float* /*outAppRequestRefreshRateMax*/) override { + status_t getDesiredDisplayModeSpecs(const sp<IBinder>& /*displayToken*/, + size_t* /*outDefaultMode*/, + bool* /*outAllowGroupSwitching*/, + float* /*outPrimaryRefreshRateMin*/, + float* /*outPrimaryRefreshRateMax*/, + float* /*outAppRequestRefreshRateMin*/, + float* /*outAppRequestRefreshRateMax*/) override { return NO_ERROR; }; status_t notifyPowerBoost(int32_t /*boostId*/) override { return NO_ERROR; } @@ -889,6 +889,8 @@ public: int getGPUContextPriority() override { return 0; }; + status_t getExtraBufferCount(int* /*extraBuffers*/) const override { return NO_ERROR; } + protected: IBinder* onAsBinder() override { return nullptr; } diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp index 6b085a3292..dc2dd297c5 100644 --- a/libs/nativedisplay/AChoreographer.cpp +++ b/libs/nativedisplay/AChoreographer.cpp @@ -138,8 +138,8 @@ private: void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count, VsyncEventData vsyncEventData) override; void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override; - void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t configId, - nsecs_t vsyncPeriod) override; + void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId, + nsecs_t vsyncPeriod) override; void dispatchNullEvent(nsecs_t, PhysicalDisplayId) override; void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId, std::vector<FrameRateOverride> overrides) override; @@ -382,8 +382,8 @@ void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool c this, to_string(displayId).c_str(), toString(connected)); } -void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId, int32_t, nsecs_t) { - LOG_ALWAYS_FATAL("dispatchConfigChanged was called but was never registered"); +void Choreographer::dispatchModeChanged(nsecs_t, PhysicalDisplayId, int32_t, nsecs_t) { + LOG_ALWAYS_FATAL("dispatchModeChanged was called but was never registered"); } void Choreographer::dispatchFrameRateOverrides(nsecs_t, PhysicalDisplayId, diff --git a/libs/nativedisplay/ADisplay.cpp b/libs/nativedisplay/ADisplay.cpp index 277635cd34..c595aa6309 100644 --- a/libs/nativedisplay/ADisplay.cpp +++ b/libs/nativedisplay/ADisplay.cpp @@ -16,8 +16,8 @@ #include <apex/display.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> #include <ui/DisplayInfo.h> +#include <ui/DisplayMode.h> #include <ui/GraphicTypes.h> #include <ui/PixelFormat.h> @@ -134,8 +134,8 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) { return NO_INIT; } - std::vector<DisplayConfigImpl> configsPerDisplay[size]; - int numConfigs = 0; + std::vector<DisplayConfigImpl> modesPerDisplay[size]; + int numModes = 0; for (int i = 0; i < size; ++i) { const sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(ids[i]); @@ -145,23 +145,23 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) { return status; } - Vector<DisplayConfig> configs; - if (const status_t status = SurfaceComposerClient::getDisplayConfigs(token, &configs); + Vector<ui::DisplayMode> modes; + if (const status_t status = SurfaceComposerClient::getDisplayModes(token, &modes); status != OK) { return status; } - if (configs.empty()) { + if (modes.empty()) { return NO_INIT; } - numConfigs += configs.size(); - configsPerDisplay[i].reserve(configs.size()); - for (int j = 0; j < configs.size(); ++j) { - const DisplayConfig& config = configs[j]; - configsPerDisplay[i].emplace_back( - DisplayConfigImpl{config.resolution.getWidth(), config.resolution.getHeight(), - info.density, config.refreshRate, config.sfVsyncOffset, - config.appVsyncOffset}); + numModes += modes.size(); + modesPerDisplay[i].reserve(modes.size()); + for (int j = 0; j < modes.size(); ++j) { + const ui::DisplayMode& mode = modes[j]; + modesPerDisplay[i].emplace_back( + DisplayConfigImpl{mode.resolution.getWidth(), mode.resolution.getHeight(), + info.density, mode.refreshRate, mode.sfVsyncOffset, + mode.appVsyncOffset}); } } @@ -192,7 +192,7 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) { // contiguous block of DisplayConfigImpls specific to that display. DisplayImpl** const impls = reinterpret_cast<DisplayImpl**>( malloc((sizeof(DisplayImpl) + sizeof(DisplayImpl*)) * size + - sizeof(DisplayConfigImpl) * numConfigs)); + sizeof(DisplayConfigImpl) * numModes)); DisplayImpl* const displayData = reinterpret_cast<DisplayImpl*>(impls + size); DisplayConfigImpl* configData = reinterpret_cast<DisplayConfigImpl*>(displayData + size); @@ -200,7 +200,7 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) { const PhysicalDisplayId id = ids[i]; const ADisplayType type = (internalId == id) ? ADisplayType::DISPLAY_TYPE_INTERNAL : ADisplayType::DISPLAY_TYPE_EXTERNAL; - const std::vector<DisplayConfigImpl>& configs = configsPerDisplay[i]; + const std::vector<DisplayConfigImpl>& configs = modesPerDisplay[i]; memcpy(configData, configs.data(), sizeof(DisplayConfigImpl) * configs.size()); displayData[i] = DisplayImpl{id, @@ -257,7 +257,7 @@ int ADisplay_getCurrentConfig(ADisplay* display, ADisplayConfig** outConfig) { CHECK_NOT_NULL(display); sp<IBinder> token = getToken(display); - const int index = SurfaceComposerClient::getActiveConfig(token); + const int index = SurfaceComposerClient::getActiveDisplayModeId(token); if (index < 0) { return index; } diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index ffe4412b72..7aa2cf4404 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -256,6 +256,7 @@ enum { NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER = 46, /* private */ NATIVE_WINDOW_SET_QUERY_INTERCEPTOR = 47, /* private */ NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO = 48, /* private */ + NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT = 49, /* private */ // clang-format on }; @@ -1030,6 +1031,11 @@ static inline int native_window_set_frame_timeline_info(struct ANativeWindow* wi frameTimelineVsyncId, inputEventId); } +static inline int native_window_get_extra_buffer_count( + struct ANativeWindow* window, int* extraBuffers) { + return window->perform(window, NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT, extraBuffers); +} + // ------------------------------------------------------------------------------------------------ // Candidates for APEX visibility // These functions are planned to be made stable for APEX modules, but have not diff --git a/libs/ui/include/ui/DisplayConfig.h b/libs/ui/include/ui/DisplayMode.h index d6fbaab387..145d7efd19 100644 --- a/libs/ui/include/ui/DisplayConfig.h +++ b/libs/ui/include/ui/DisplayMode.h @@ -21,10 +21,10 @@ #include <ui/Size.h> #include <utils/Timers.h> -namespace android { +namespace android::ui { -// Configuration supported by physical display. -struct DisplayConfig { +// Mode supported by physical display. +struct DisplayMode { ui::Size resolution; float xDpi = 0; float yDpi = 0; @@ -33,9 +33,9 @@ struct DisplayConfig { nsecs_t appVsyncOffset = 0; nsecs_t sfVsyncOffset = 0; nsecs_t presentationDeadline = 0; - int configGroup = -1; + int group = -1; }; -static_assert(std::is_trivially_copyable_v<DisplayConfig>); +static_assert(std::is_trivially_copyable_v<DisplayMode>); -} // namespace android +} // namespace android::ui diff --git a/libs/ui/include_vndk/ui/DisplayConfig.h b/libs/ui/include_vndk/ui/DisplayConfig.h deleted file mode 120000 index 1450319502..0000000000 --- a/libs/ui/include_vndk/ui/DisplayConfig.h +++ /dev/null @@ -1 +0,0 @@ -../../include/ui/DisplayConfig.h
\ No newline at end of file diff --git a/libs/ui/include_vndk/ui/DisplayMode.h b/libs/ui/include_vndk/ui/DisplayMode.h new file mode 120000 index 0000000000..c87754a682 --- /dev/null +++ b/libs/ui/include_vndk/ui/DisplayMode.h @@ -0,0 +1 @@ +../../include/ui/DisplayMode.h
\ No newline at end of file diff --git a/opengl/tests/lib/WindowSurface.cpp b/opengl/tests/lib/WindowSurface.cpp index dfb9c92b5f..fd4522e757 100644 --- a/opengl/tests/lib/WindowSurface.cpp +++ b/opengl/tests/lib/WindowSurface.cpp @@ -21,7 +21,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <ui/DisplayState.h> using namespace android; @@ -42,10 +42,10 @@ WindowSurface::WindowSurface() { return; } - DisplayConfig displayConfig; - err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); + ui::DisplayMode displayMode; + err = SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode); if (err != NO_ERROR) { - fprintf(stderr, "ERROR: unable to get active display config\n"); + fprintf(stderr, "ERROR: unable to get active display mode\n"); return; } @@ -56,7 +56,7 @@ WindowSurface::WindowSurface() { return; } - const ui::Size& resolution = displayConfig.resolution; + const ui::Size& resolution = displayMode.resolution; auto width = resolution.getWidth(); auto height = resolution.getHeight(); diff --git a/services/automotive/display/AutomotiveDisplayProxyService.cpp b/services/automotive/display/AutomotiveDisplayProxyService.cpp index 321bb8342d..d6fc69562b 100644 --- a/services/automotive/display/AutomotiveDisplayProxyService.cpp +++ b/services/automotive/display/AutomotiveDisplayProxyService.cpp @@ -41,10 +41,10 @@ AutomotiveDisplayProxyService::getIGraphicBufferProducer(uint64_t id) { } // Get the resolution from stored display state. - DisplayConfig displayConfig = {}; - auto err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); + ui::DisplayMode displayMode = {}; + auto err = SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode); if (err != NO_ERROR) { - ALOGE("Failed to get display configuration of %lX. " + ALOGE("Failed to get display mode of %lX. " "This display will be ignored.", (unsigned long)id); return nullptr; } @@ -57,8 +57,8 @@ AutomotiveDisplayProxyService::getIGraphicBufferProducer(uint64_t id) { return nullptr; } - auto displayWidth = displayConfig.resolution.getWidth(); - auto displayHeight = displayConfig.resolution.getHeight(); + auto displayWidth = displayMode.resolution.getWidth(); + auto displayHeight = displayMode.resolution.getHeight(); if ((displayState.orientation != ui::ROTATION_0) && (displayState.orientation != ui::ROTATION_180)) { std::swap(displayWidth, displayHeight); @@ -161,10 +161,10 @@ Return<void> AutomotiveDisplayProxyService::getDisplayInfo(uint64_t id, getDispl if (displayToken == nullptr) { ALOGE("Given display id, 0x%lX, is invalid.", (unsigned long)id); } else { - DisplayConfig displayConfig = {}; - auto err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); + ui::DisplayMode displayMode = {}; + auto err = SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode); if (err != NO_ERROR) { - ALOGW("Failed to get display configuration of %lX. " + ALOGW("Failed to get display mode of %lX. " "This display will be ignored.", (unsigned long)id); } @@ -175,7 +175,7 @@ Return<void> AutomotiveDisplayProxyService::getDisplayInfo(uint64_t id, getDispl "This display will be ignored.", (unsigned long)id); } - activeConfig.setToExternal((uint8_t*)&displayConfig, sizeof(DisplayConfig)); + activeConfig.setToExternal((uint8_t*)&displayMode, sizeof(ui::DisplayMode)); activeState.setToExternal((uint8_t*)&displayState, sizeof(DisplayState)); } diff --git a/services/automotive/display/include/AutomotiveDisplayProxyService.h b/services/automotive/display/include/AutomotiveDisplayProxyService.h index e2fc0d2eec..4482b9beea 100644 --- a/services/automotive/display/include/AutomotiveDisplayProxyService.h +++ b/services/automotive/display/include/AutomotiveDisplayProxyService.h @@ -20,7 +20,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <ui/DisplayState.h> #include <tuple> #include <vector> diff --git a/services/inputflinger/InputClassifier.cpp b/services/inputflinger/InputClassifier.cpp index f5f0400995..a9cbd5ad02 100644 --- a/services/inputflinger/InputClassifier.cpp +++ b/services/inputflinger/InputClassifier.cpp @@ -396,6 +396,11 @@ void InputClassifier::notifySensor(const NotifySensorArgs* args) { mListener->notifySensor(args); } +void InputClassifier::notifyVibratorState(const NotifyVibratorStateArgs* args) { + // pass through + mListener->notifyVibratorState(args); +} + void InputClassifier::notifySwitch(const NotifySwitchArgs* args) { // pass through mListener->notifySwitch(args); diff --git a/services/inputflinger/InputClassifier.h b/services/inputflinger/InputClassifier.h index bf10920e61..1eef02006e 100644 --- a/services/inputflinger/InputClassifier.h +++ b/services/inputflinger/InputClassifier.h @@ -230,6 +230,7 @@ public: virtual void notifyMotion(const NotifyMotionArgs* args) override; virtual void notifySwitch(const NotifySwitchArgs* args) override; virtual void notifySensor(const NotifySensorArgs* args) override; + virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override; virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override; void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override; diff --git a/services/inputflinger/InputListener.cpp b/services/inputflinger/InputListener.cpp index 4be49b120f..4b1f350631 100644 --- a/services/inputflinger/InputListener.cpp +++ b/services/inputflinger/InputListener.cpp @@ -246,6 +246,24 @@ void NotifySensorArgs::notify(const sp<InputListenerInterface>& listener) const listener->notifySensor(this); } +// --- NotifyVibratorStateArgs --- + +NotifyVibratorStateArgs::NotifyVibratorStateArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, + bool isOn) + : NotifyArgs(id, eventTime), deviceId(deviceId), isOn(isOn) {} + +NotifyVibratorStateArgs::NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) + : NotifyArgs(other.id, other.eventTime), deviceId(other.deviceId), isOn(other.isOn) {} + +bool NotifyVibratorStateArgs::operator==(const NotifyVibratorStateArgs rhs) const { + return id == rhs.id && eventTime == rhs.eventTime && deviceId == rhs.deviceId && + isOn == rhs.isOn; +} + +void NotifyVibratorStateArgs::notify(const sp<InputListenerInterface>& listener) const { + listener->notifyVibratorState(this); +} + // --- NotifyDeviceResetArgs --- NotifyDeviceResetArgs::NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId) @@ -326,6 +344,11 @@ void QueuedInputListener::notifySensor(const NotifySensorArgs* args) { mArgsQueue.push_back(new NotifySensorArgs(*args)); } +void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) { + traceEvent(__func__, args->id); + mArgsQueue.push_back(new NotifyVibratorStateArgs(*args)); +} + void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) { traceEvent(__func__, args->id); mArgsQueue.push_back(new NotifyDeviceResetArgs(*args)); diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 887bdd4edc..d6b7259148 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -79,6 +79,8 @@ private: void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy) override {} + void notifyVibratorState(int32_t deviceId, bool isOn) override {} + void notifyUntrustedTouch(const std::string& obscuringPackage) override {} void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 0495d68000..290993935a 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -1247,9 +1247,10 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked( nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry, DropReason& dropReason) { const bool haveWindowWithPointerCapture = mWindowTokenWithPointerCapture != nullptr; - if (entry->pointerCaptureEnabled == haveWindowWithPointerCapture) { - LOG_ALWAYS_FATAL_IF(mFocusedWindowRequestedPointerCapture, - "The Pointer Capture state has already been dispatched to the window."); + if (entry->pointerCaptureEnabled && haveWindowWithPointerCapture) { + LOG_ALWAYS_FATAL("Pointer Capture has already been enabled for the window."); + } + if (!entry->pointerCaptureEnabled && !haveWindowWithPointerCapture) { // Pointer capture was already forcefully disabled because of focus change. dropReason = DropReason::NOT_DROPPED; return; @@ -3747,6 +3748,14 @@ void InputDispatcher::notifySensor(const NotifySensorArgs* args) { } } +void InputDispatcher::notifyVibratorState(const NotifyVibratorStateArgs* args) { +#if DEBUG_INBOUND_EVENT_DETAILS + ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args->eventTime, + args->deviceId, args->isOn); +#endif + mPolicy->notifyVibratorState(args->deviceId, args->isOn); +} + bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) { return mInputFilterEnabled; } diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 02f5b87504..c93d74eb90 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -96,6 +96,7 @@ public: virtual void notifyMotion(const NotifyMotionArgs* args) override; virtual void notifySwitch(const NotifySwitchArgs* args) override; virtual void notifySensor(const NotifySensorArgs* args) override; + virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override; virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override; virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override; diff --git a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h index b976129773..909ce54e4b 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h @@ -84,6 +84,7 @@ public: const std::vector<float>& values) = 0; virtual void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy) = 0; + virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; /* Notifies the system that an untrusted touch occurred. */ virtual void notifyUntrustedTouch(const std::string& obscuringPackage) = 0; diff --git a/services/inputflinger/include/InputListener.h b/services/inputflinger/include/InputListener.h index 11f726d50c..094bc0c1dd 100644 --- a/services/inputflinger/include/InputListener.h +++ b/services/inputflinger/include/InputListener.h @@ -223,6 +223,24 @@ struct NotifyPointerCaptureChangedArgs : public NotifyArgs { virtual void notify(const sp<InputListenerInterface>& listener) const; }; +/* Describes a vibrator state event. */ +struct NotifyVibratorStateArgs : public NotifyArgs { + int32_t deviceId; + bool isOn; + + inline NotifyVibratorStateArgs() {} + + NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn); + + NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other); + + bool operator==(const NotifyVibratorStateArgs rhs) const; + + virtual ~NotifyVibratorStateArgs() {} + + virtual void notify(const sp<InputListenerInterface>& listener) const; +}; + /* * The interface used by the InputReader to notify the InputListener about input events. */ @@ -237,6 +255,7 @@ public: virtual void notifyMotion(const NotifyMotionArgs* args) = 0; virtual void notifySwitch(const NotifySwitchArgs* args) = 0; virtual void notifySensor(const NotifySensorArgs* args) = 0; + virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) = 0; virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0; virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) = 0; }; @@ -259,6 +278,7 @@ public: virtual void notifySwitch(const NotifySwitchArgs* args) override; virtual void notifySensor(const NotifySensorArgs* args) override; virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override; + void notifyVibratorState(const NotifyVibratorStateArgs* args) override; void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override; void flush(); diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index de5d0e6442..c044393c9e 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -928,6 +928,11 @@ void InputReader::ContextImpl::notifySensor(nsecs_t when, int32_t deviceId, mReader->mQueuedListener->notifySensor(&args); } +void InputReader::ContextImpl::notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) { + NotifyVibratorStateArgs args(mIdGenerator.nextId(), when, deviceId, isOn); + mReader->mQueuedListener->notifyVibratorState(&args); +} + void InputReader::ContextImpl::notifySwitch(nsecs_t eventTime, uint32_t switchValues, uint32_t switchMask) { NotifySwitchArgs args(mIdGenerator.nextId(), eventTime, 0 /*policyFlags*/, switchValues, diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h index e2558bcf2e..5f78149d57 100644 --- a/services/inputflinger/reader/include/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -152,6 +152,7 @@ protected: void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy, bool accuracyChanged, nsecs_t timestamp, std::vector<float> values) override; + void notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) override; void notifyDeviceReset(nsecs_t when, int32_t deviceId) override; void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) override; diff --git a/services/inputflinger/reader/include/InputReaderContext.h b/services/inputflinger/reader/include/InputReaderContext.h index edab3128aa..e6ea523c4f 100644 --- a/services/inputflinger/reader/include/InputReaderContext.h +++ b/services/inputflinger/reader/include/InputReaderContext.h @@ -80,6 +80,7 @@ public: virtual void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy, bool accuracyChanged, nsecs_t timestamp, std::vector<float> values) = 0; + virtual void notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) = 0; virtual void notifyDeviceReset(nsecs_t when, int32_t deviceId) = 0; virtual void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) = 0; }; diff --git a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp index f25e59a6bd..2e4ab45b35 100644 --- a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp @@ -52,6 +52,8 @@ void VibratorInputMapper::vibrate(const VibrationSequence& sequence, ssize_t rep mToken = token; mIndex = -1; + // Request InputReader to notify InputManagerService for vibration started. + getContext()->notifyVibratorState(systemTime(), getDeviceId(), true); nextStep(); } @@ -84,6 +86,9 @@ void VibratorInputMapper::timeoutExpired(nsecs_t when) { } void VibratorInputMapper::nextStep() { +#if DEBUG_VIBRATOR + ALOGD("nextStep: index=%d, vibrate deviceId=%d", (int)mIndex, getDeviceId()); +#endif mIndex += 1; if (size_t(mIndex) >= mSequence.pattern.size()) { if (mRepeat < 0) { @@ -124,6 +129,9 @@ void VibratorInputMapper::stopVibrating() { ALOGD("stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId()); #endif getDeviceContext().cancelVibrate(); + + // Request InputReader to notify InputManagerService for vibration complete. + getContext()->notifyVibratorState(systemTime(), getDeviceId(), false); } void VibratorInputMapper::dump(std::string& dump) { diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index c7e05eb86a..01945dbbf1 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -331,6 +331,8 @@ private: void notifySensorAccuracy(int deviceId, InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy) override {} + void notifyVibratorState(int32_t deviceId, bool isOn) override {} + void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { *outConfig = mConfig; } @@ -4215,4 +4217,27 @@ TEST_F(InputDispatcherPointerCaptureTests, UnexpectedStateChangeDisablesPointerC mWindow->assertNoEvents(); } +TEST_F(InputDispatcherPointerCaptureTests, OutOfOrderRequests) { + requestAndVerifyPointerCapture(mWindow, true); + + // The first window loses focus. + setFocusedWindow(mSecondWindow); + mFakePolicy->waitForSetPointerCapture(false); + mWindow->consumeCaptureEvent(false); + + // Request Pointer Capture from the second window before the notification from InputReader + // arrives. + mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true); + mFakePolicy->waitForSetPointerCapture(true); + + // InputReader notifies Pointer Capture was disabled (because of the focus change). + notifyPointerCaptureChanged(false); + + // InputReader notifies Pointer Capture was enabled (because of mSecondWindow's request). + notifyPointerCaptureChanged(true); + + mSecondWindow->consumeFocusEvent(true); + mSecondWindow->consumeCaptureEvent(true); +} + } // namespace android::inputdispatcher diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 0e88312e96..409c62a0e2 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -409,7 +409,7 @@ class FakeEventHub : public EventHubInterface { KeyedVector<int32_t, Device*> mDevices; std::vector<std::string> mExcludedDevices; - List<RawEvent> mEvents GUARDED_BY(mLock); + std::vector<RawEvent> mEvents GUARDED_BY(mLock); std::unordered_map<int32_t /*deviceId*/, std::vector<TouchVideoFrame>> mVideoFrames; std::vector<int32_t> mVibrators = {0, 1}; @@ -722,16 +722,15 @@ private: mExcludedDevices = devices; } - size_t getEvents(int, RawEvent* buffer, size_t) override { - std::scoped_lock<std::mutex> lock(mLock); - if (mEvents.empty()) { - return 0; - } + size_t getEvents(int, RawEvent* buffer, size_t bufferSize) override { + std::scoped_lock lock(mLock); - *buffer = *mEvents.begin(); - mEvents.erase(mEvents.begin()); + const size_t filledSize = std::min(mEvents.size(), bufferSize); + std::copy(mEvents.begin(), mEvents.begin() + filledSize, buffer); + + mEvents.erase(mEvents.begin(), mEvents.begin() + filledSize); mEventsCondition.notify_all(); - return 1; + return filledSize; } std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override { @@ -2678,6 +2677,7 @@ TEST_F(VibratorInputMapperTest, GetVibratorIds) { TEST_F(VibratorInputMapperTest, Vibrate) { constexpr uint8_t DEFAULT_AMPLITUDE = 192; + constexpr int32_t VIBRATION_TOKEN = 100; VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>(); VibrationElement pattern(2); @@ -2695,8 +2695,23 @@ TEST_F(VibratorInputMapperTest, Vibrate) { std::vector<uint8_t> amplitudes = {DEFAULT_AMPLITUDE, DEFAULT_AMPLITUDE / 2}; ASSERT_FALSE(mapper.isVibrating()); - mapper.vibrate(sequence, -1 /* repeat */, 0 /* token */); + // Start vibrating + mapper.vibrate(sequence, -1 /* repeat */, VIBRATION_TOKEN); ASSERT_TRUE(mapper.isVibrating()); + // Verify vibrator state listener was notified. + mReader->loopOnce(); + NotifyVibratorStateArgs args; + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyVibratorStateWasCalled(&args)); + ASSERT_EQ(DEVICE_ID, args.deviceId); + ASSERT_TRUE(args.isOn); + // Stop vibrating + mapper.cancelVibrate(VIBRATION_TOKEN); + ASSERT_FALSE(mapper.isVibrating()); + // Verify vibrator state listener was notified. + mReader->loopOnce(); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyVibratorStateWasCalled(&args)); + ASSERT_EQ(DEVICE_ID, args.deviceId); + ASSERT_FALSE(args.isOn); } // --- SensorInputMapperTest --- diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp index 295c6e3057..fb7de97b49 100644 --- a/services/inputflinger/tests/TestInputListener.cpp +++ b/services/inputflinger/tests/TestInputListener.cpp @@ -86,6 +86,12 @@ void TestInputListener::assertNotifySensorWasCalled(NotifySensorArgs* outEventAr "Expected notifySensor() to have been called.")); } +void TestInputListener::assertNotifyVibratorStateWasCalled(NotifyVibratorStateArgs* outEventArgs) { + ASSERT_NO_FATAL_FAILURE(assertCalled<NotifyVibratorStateArgs>(outEventArgs, + "Expected notifyVibratorState() " + "to have been called.")); +} + void TestInputListener::assertNotifyCaptureWasCalled( NotifyPointerCaptureChangedArgs* outEventArgs) { ASSERT_NO_FATAL_FAILURE( @@ -165,4 +171,8 @@ void TestInputListener::notifySensor(const NotifySensorArgs* args) { notify<NotifySensorArgs>(args); } +void TestInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) { + notify<NotifyVibratorStateArgs>(args); +} + } // namespace android diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h index e54350a4c8..0ffcaaa527 100644 --- a/services/inputflinger/tests/TestInputListener.h +++ b/services/inputflinger/tests/TestInputListener.h @@ -56,6 +56,7 @@ public: void assertNotifyCaptureWasCalled(NotifyPointerCaptureChangedArgs* outEventArgs = nullptr); void assertNotifySensorWasCalled(NotifySensorArgs* outEventArgs = nullptr); + void assertNotifyVibratorStateWasCalled(NotifyVibratorStateArgs* outEventArgs = nullptr); private: template <class NotifyArgsType> @@ -79,6 +80,8 @@ private: virtual void notifySensor(const NotifySensorArgs* args) override; + virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override; + virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override; std::mutex mLock; @@ -92,6 +95,7 @@ private: std::vector<NotifyMotionArgs>, // std::vector<NotifySwitchArgs>, // std::vector<NotifySensorArgs>, // + std::vector<NotifyVibratorStateArgs>, // std::vector<NotifyPointerCaptureChangedArgs>> // mQueues GUARDED_BY(mLock); }; diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 825626a4b2..8d1258a713 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -173,7 +173,7 @@ filegroup { "SurfaceFlingerDefaultFactory.cpp", "SurfaceInterceptor.cpp", "SurfaceTracing.cpp", - "TransactionCompletedThread.cpp", + "TransactionCallbackInvoker.cpp", ], } diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp index e470eb940c..cf87f62745 100644 --- a/services/surfaceflinger/BufferStateLayer.cpp +++ b/services/surfaceflinger/BufferStateLayer.cpp @@ -190,7 +190,7 @@ void BufferStateLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) { JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value())); } - mFlinger->getTransactionCompletedThread().finalizePendingCallbackHandles( + mFlinger->getTransactionCallbackInvoker().finalizePendingCallbackHandles( mDrawingState.callbackHandles, jankData); mDrawingState.callbackHandles = {}; @@ -455,14 +455,14 @@ bool BufferStateLayer::setTransactionCompletedListeners( // Notify the transaction completed thread that there is a pending latched callback // handle - mFlinger->getTransactionCompletedThread().registerPendingCallbackHandle(handle); + mFlinger->getTransactionCallbackInvoker().registerPendingCallbackHandle(handle); // Store so latched time and release fence can be set mCurrentState.callbackHandles.push_back(handle); } else { // If this layer will NOT need to be relatched and presented this frame // Notify the transaction completed thread this handle is done - mFlinger->getTransactionCompletedThread().registerUnpresentedCallbackHandle(handle); + mFlinger->getTransactionCallbackInvoker().registerUnpresentedCallbackHandle(handle); } } diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp index 4f99495ff2..3907ac5359 100644 --- a/services/surfaceflinger/CompositionEngine/src/Output.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp @@ -989,9 +989,16 @@ std::optional<base::unique_fd> Output::composeSurfaces( }); const nsecs_t renderEngineStart = systemTime(); + // Only use the framebuffer cache when rendering to an internal display + // TODO(b/173560331): This is only to help mitigate memory leaks from virtual displays because + // right now we don't have a concrete eviction policy for output buffers: GLESRenderEngine + // bounds its framebuffer cache but Skia RenderEngine has no current policy. The best fix is + // probably to encapsulate the output buffer into a structure that dispatches resource cleanup + // over to RenderEngine, in which case this flag can be removed from the drawLayers interface. + const bool useFramebufferCache = outputState.layerStackInternal; status_t status = renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayerPointers, buf, - /*useFramebufferCache=*/true, std::move(fd), &readyFence); + useFramebufferCache, std::move(fd), &readyFence); if (status != NO_ERROR && mClientCompositionRequestCache) { // If rendering was not successful, remove the request from the cache. diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp index 376bac8c69..c4ae3a7f22 100644 --- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp @@ -3003,7 +3003,7 @@ TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) { .WillRepeatedly(Return()); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, false, _, _)) .WillRepeatedly(Return(NO_ERROR)); verify().execute().expectAFenceWasReturned(); @@ -3030,6 +3030,36 @@ TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) { })); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _)) + .WillRepeatedly(Return(NO_ERROR)); + + verify().execute().expectAFenceWasReturned(); +} + +TEST_F(OutputComposeSurfacesTest, + buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) { + LayerFE::LayerSettings r1; + LayerFE::LayerSettings r2; + + r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; + r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; + const constexpr uint32_t kInternalLayerStack = 1234; + mOutput.setLayerStackFilter(kInternalLayerStack, true); + + EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); + EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); + EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); + EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); + EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace)) + .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); + EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) + .WillRepeatedly( + Invoke([&](const Region&, + std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { + clientCompositionLayers.emplace_back(r2); + })); + + EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _)) .WillRepeatedly(Return(NO_ERROR)); @@ -3054,7 +3084,7 @@ TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithou .WillRepeatedly(Return()); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _)) .Times(2) .WillOnce(Return(NO_ERROR)); @@ -3083,7 +3113,7 @@ TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) { .WillRepeatedly(Return()); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _)) .WillOnce(Return(NO_ERROR)); EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); @@ -3115,7 +3145,7 @@ TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) { EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) .WillOnce(Return(mOutputBuffer)) .WillOnce(Return(otherOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _)) .WillRepeatedly(Return(NO_ERROR)); verify().execute().expectAFenceWasReturned(); @@ -3145,9 +3175,9 @@ TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) { .WillRepeatedly(Return()); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _)) .WillOnce(Return(NO_ERROR)); - EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r3)), _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r3)), _, false, _, _)) .WillOnce(Return(NO_ERROR)); verify().execute().expectAFenceWasReturned(); @@ -3197,7 +3227,7 @@ struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComp struct ExpectDisplaySettingsState : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> { auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) { - EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, true, _, _)) + EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, false, _, _)) .WillOnce(Return(NO_ERROR)); return nextState<ExecuteState>(); } @@ -3296,7 +3326,7 @@ struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeS EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) .WillRepeatedly(Return()); EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)) + EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)) .WillRepeatedly(Return(NO_ERROR)); } @@ -3349,7 +3379,7 @@ TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) { EXPECT_CALL(*mRenderSurface, setProtected(true)); // Must happen after setting the protected content state. EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); - EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR)); + EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR)); mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs); } @@ -3419,7 +3449,7 @@ TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDatas InSequence seq; EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)); - EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR)); + EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR)); mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs); } @@ -3434,7 +3464,7 @@ struct OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur EXPECT_CALL(mLayer.outputLayer, writeStateToHWC(false)); EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace)) .WillOnce(Return(std::vector<LayerFE::LayerSettings>{})); - EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR)); + EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR)); EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) .WillRepeatedly(Return(&mLayer.outputLayer)); diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index a785968515..c751f22c97 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -265,7 +265,8 @@ void DisplayDevice::dump(std::string& result) const { StringAppendF(&result, "+ %s\n", getDebugName().c_str()); StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(), static_cast<int32_t>(mPowerMode)); - StringAppendF(&result, " activeMode=%s\n", to_string(*getActiveMode()).c_str()); + StringAppendF(&result, " activeMode=%s\n", + mSupportedModes.size() ? to_string(*getActiveMode()).c_str() : "none"); result.append(" supportedModes=\n"); diff --git a/services/surfaceflinger/DisplayHardware/DisplayMode.h b/services/surfaceflinger/DisplayHardware/DisplayMode.h index 31d1245ed0..1f0f3c3c33 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayMode.h +++ b/services/surfaceflinger/DisplayHardware/DisplayMode.h @@ -86,8 +86,8 @@ public: return *this; } - Builder& setConfigGroup(int32_t configGroup) { - mDisplayMode->mConfigGroup = configGroup; + Builder& setGroup(int32_t group) { + mDisplayMode->mGroup = group; return *this; } @@ -119,7 +119,10 @@ public: nsecs_t getVsyncPeriod() const { return mFps.getPeriodNsecs(); } float getDpiX() const { return mDpiX; } float getDpiY() const { return mDpiY; } - int32_t getConfigGroup() const { return mConfigGroup; } + + // Switches between modes in the same group are seamless, i.e. + // without visual interruptions such as a black screen. + int32_t getGroup() const { return mGroup; } private: explicit DisplayMode(hal::HWConfigId id) : mHwcId(id) {} @@ -132,15 +135,15 @@ private: Fps mFps; float mDpiX = -1; float mDpiY = -1; - int32_t mConfigGroup = -1; + int32_t mGroup = -1; }; inline std::string to_string(const DisplayMode& mode) { return base::StringPrintf("{id=%zu, hwcId=%d, width=%d, height=%d, refreshRate=%s, " - "dpiX=%.2f, dpiY=%.2f, configGroup=%d}", + "dpiX=%.2f, dpiY=%.2f, group=%d}", mode.getId().value(), mode.getHwcId(), mode.getWidth(), mode.getHeight(), to_string(mode.getFps()).c_str(), mode.getDpiX(), - mode.getDpiY(), mode.getConfigGroup()); + mode.getDpiY(), mode.getGroup()); } } // namespace android
\ No newline at end of file diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 1fe0e2624b..27b2b87d77 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -869,9 +869,7 @@ void Layer::mergeSurfaceFrames(State& source, State& target) { void Layer::popPendingState(State* stateToCommit) { ATRACE_CALL(); - if (stateToCommit != nullptr) { - mergeSurfaceFrames(*stateToCommit, mPendingStates[0]); - } + mergeSurfaceFrames(*stateToCommit, mPendingStates[0]); *stateToCommit = mPendingStates[0]; mPendingStates.pop_front(); ATRACE_INT(mTransactionName.c_str(), mPendingStates.size()); diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 7d70d91bd3..273601f440 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -55,7 +55,7 @@ #include "Scheduler/Seamlessness.h" #include "SurfaceFlinger.h" #include "SurfaceTracing.h" -#include "TransactionCompletedThread.h" +#include "TransactionCallbackInvoker.h" using namespace android::surfaceflinger; diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index f90c130992..ba43e705d4 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -90,9 +90,9 @@ std::string toString(const DisplayEventReceiver::Event& event) { return StringPrintf("VSync{displayId=%s, count=%u, expectedVSyncTimestamp=%" PRId64 "}", to_string(event.header.displayId).c_str(), event.vsync.count, event.vsync.expectedVSyncTimestamp); - case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: - return StringPrintf("ConfigChanged{displayId=%s, configId=%u}", - to_string(event.header.displayId).c_str(), event.config.configId); + case DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE: + return StringPrintf("ModeChanged{displayId=%s, modeId=%u}", + to_string(event.header.displayId).c_str(), event.modeChange.modeId); default: return "Event{}"; } @@ -118,12 +118,12 @@ DisplayEventReceiver::Event makeVSync(PhysicalDisplayId displayId, nsecs_t times return event; } -DisplayEventReceiver::Event makeConfigChanged(PhysicalDisplayId displayId, DisplayModeId configId, - nsecs_t vsyncPeriod) { +DisplayEventReceiver::Event makeModeChanged(PhysicalDisplayId displayId, DisplayModeId modeId, + nsecs_t vsyncPeriod) { DisplayEventReceiver::Event event; - event.header = {DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, displayId, systemTime()}; - event.config.configId = configId.value(); - event.config.vsyncPeriod = vsyncPeriod; + event.header = {DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE, displayId, systemTime()}; + event.modeChange.modeId = modeId.value(); + event.modeChange.vsyncPeriod = vsyncPeriod; return event; } @@ -303,10 +303,6 @@ void EventThread::setVsyncRate(uint32_t rate, const sp<EventThreadConnection>& c std::lock_guard<std::mutex> lock(mMutex); const auto request = rate == 0 ? VSyncRequest::None : static_cast<VSyncRequest>(rate); - if (request != VSyncRequest::None && connection->resyncCallback) { - connection->resyncCallback(); - } - if (connection->vsyncRequest != request) { connection->vsyncRequest = request; mCondition.notify_all(); @@ -373,11 +369,11 @@ void EventThread::onHotplugReceived(PhysicalDisplayId displayId, bool connected) mCondition.notify_all(); } -void EventThread::onConfigChanged(PhysicalDisplayId displayId, DisplayModeId configId, - nsecs_t vsyncPeriod) { +void EventThread::onModeChanged(PhysicalDisplayId displayId, DisplayModeId modeId, + nsecs_t vsyncPeriod) { std::lock_guard<std::mutex> lock(mMutex); - mPendingEvents.push_back(makeConfigChanged(displayId, configId, vsyncPeriod)); + mPendingEvents.push_back(makeModeChanged(displayId, modeId, vsyncPeriod)); mCondition.notify_all(); } @@ -518,9 +514,9 @@ bool EventThread::shouldConsumeEvent(const DisplayEventReceiver::Event& event, case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: return true; - case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: { + case DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE: { return connection->mEventRegistration.test( - ISurfaceComposer::EventRegistration::configChanged); + ISurfaceComposer::EventRegistration::modeChanged); } case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index 15efe219c0..35406041a8 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -123,9 +123,9 @@ public: virtual void onHotplugReceived(PhysicalDisplayId displayId, bool connected) = 0; - // called when SF changes the active config and apps needs to be notified about the change - virtual void onConfigChanged(PhysicalDisplayId displayId, DisplayModeId configId, - nsecs_t vsyncPeriod) = 0; + // called when SF changes the active mode and apps needs to be notified about the change + virtual void onModeChanged(PhysicalDisplayId displayId, DisplayModeId modeId, + nsecs_t vsyncPeriod) = 0; // called when SF updates the Frame Rate Override list virtual void onFrameRateOverridesChanged(PhysicalDisplayId displayId, @@ -173,8 +173,8 @@ public: void onHotplugReceived(PhysicalDisplayId displayId, bool connected) override; - void onConfigChanged(PhysicalDisplayId displayId, DisplayModeId configId, - nsecs_t vsyncPeriod) override; + void onModeChanged(PhysicalDisplayId displayId, DisplayModeId modeId, + nsecs_t vsyncPeriod) override; void onFrameRateOverridesChanged(PhysicalDisplayId displayId, std::vector<FrameRateOverride> overrides) override; diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp index 7ef531df63..ea92ad88bb 100644 --- a/services/surfaceflinger/Scheduler/LayerHistory.cpp +++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp @@ -102,7 +102,7 @@ void LayerHistory::record(Layer* layer, nsecs_t presentTime, nsecs_t now, LOG_FATAL_IF(it == mLayerInfos.end(), "%s: unknown layer %p", __FUNCTION__, layer); const auto& info = it->second; - info->setLastPresentTime(presentTime, now, updateType, mConfigChangePending); + info->setLastPresentTime(presentTime, now, updateType, mModeChangePending); // Activate layer if inactive. if (const auto end = activeLayers().end(); it >= end) { diff --git a/services/surfaceflinger/Scheduler/LayerHistory.h b/services/surfaceflinger/Scheduler/LayerHistory.h index bae9b5a41a..05ecc705cc 100644 --- a/services/surfaceflinger/Scheduler/LayerHistory.h +++ b/services/surfaceflinger/Scheduler/LayerHistory.h @@ -51,8 +51,8 @@ public: // Sets the display size. Client is responsible for synchronization. void setDisplayArea(uint32_t displayArea) { mDisplayArea = displayArea; } - // Sets whether a config change is pending to be applied - void setConfigChangePending(bool pending) { mConfigChangePending = pending; } + // Sets whether a mode change is pending to be applied + void setModeChangePending(bool pending) { mModeChangePending = pending; } // Represents which layer activity is recorded enum class LayerUpdateType { @@ -109,8 +109,8 @@ private: // Whether to use priority sent from WindowManager to determine the relevancy of the layer. const bool mUseFrameRatePriority; - // Whether a config change is in progress or not - std::atomic<bool> mConfigChangePending = false; + // Whether a mode change is in progress or not + std::atomic<bool> mModeChangePending = false; }; } // namespace scheduler diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp index 4324855b70..4b4cdaea09 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.cpp +++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp @@ -44,7 +44,7 @@ LayerInfo::LayerInfo(const std::string& name, LayerHistory::LayerVoteType defaul mRefreshRateHistory(name) {} void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUpdateType updateType, - bool pendingConfigChange) { + bool pendingModeChange) { lastPresentTime = std::max(lastPresentTime, static_cast<nsecs_t>(0)); mLastUpdatedTime = std::max(lastPresentTime, now); @@ -56,7 +56,7 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUp case LayerUpdateType::Buffer: FrameTimeData frameTime = {.presentTime = lastPresentTime, .queueTime = mLastUpdatedTime, - .pendingConfigChange = pendingConfigChange}; + .pendingModeChange = pendingModeChange}; mFrameTimes.push_back(frameTime); if (mFrameTimes.size() > HISTORY_SIZE) { mFrameTimes.pop_front(); @@ -124,11 +124,11 @@ bool LayerInfo::hasEnoughDataForHeuristic() const { } std::optional<nsecs_t> LayerInfo::calculateAverageFrameTime() const { - // Ignore frames captured during a config change - const bool isDuringConfigChange = + // Ignore frames captured during a mode change + const bool isDuringModeChange = std::any_of(mFrameTimes.begin(), mFrameTimes.end(), - [](auto frame) { return frame.pendingConfigChange; }); - if (isDuringConfigChange) { + [](const auto& frame) { return frame.pendingModeChange; }); + if (isDuringModeChange) { return std::nullopt; } diff --git a/services/surfaceflinger/Scheduler/LayerInfo.h b/services/surfaceflinger/Scheduler/LayerInfo.h index e32ba099f6..40c0214408 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.h +++ b/services/surfaceflinger/Scheduler/LayerInfo.h @@ -80,7 +80,7 @@ public: // the layer was last updated. If the present time is farther in the future than the // updated time, the updated time is the present time. void setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUpdateType updateType, - bool pendingConfigChange); + bool pendingModeChange); // Sets an explicit layer vote. This usually comes directly from the application via // ANativeWindow_setFrameRate API @@ -124,7 +124,7 @@ private: struct FrameTimeData { nsecs_t presentTime; // desiredPresentTime, if provided nsecs_t queueTime; // buffer queue time - bool pendingConfigChange; + bool pendingModeChange; }; // Holds information about the calculated and reported refresh rate diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp index 81ffe0f20e..e7a44a70d5 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp @@ -40,13 +40,13 @@ std::string formatLayerInfo(const RefreshRateConfigs::LayerRequirement& layer, f to_string(layer.desiredRefreshRate).c_str()); } -std::vector<Fps> constructKnownFrameRates(const DisplayModes& configs) { +std::vector<Fps> constructKnownFrameRates(const DisplayModes& modes) { std::vector<Fps> knownFrameRates = {Fps(24.0f), Fps(30.0f), Fps(45.0f), Fps(60.0f), Fps(72.0f)}; - knownFrameRates.reserve(knownFrameRates.size() + configs.size()); + knownFrameRates.reserve(knownFrameRates.size() + modes.size()); // Add all supported refresh rates to the set - for (const auto& config : configs) { - const auto refreshRate = Fps::fromPeriodNsecs(config->getVsyncPeriod()); + for (const auto& mode : modes) { + const auto refreshRate = Fps::fromPeriodNsecs(mode->getVsyncPeriod()); knownFrameRates.emplace_back(refreshRate); } @@ -65,8 +65,8 @@ using RefreshRate = RefreshRateConfigs::RefreshRate; std::string RefreshRate::toString() const { return base::StringPrintf("{id=%zu, hwcId=%d, fps=%.2f, width=%d, height=%d group=%d}", - getConfigId().value(), hwcConfig->getHwcId(), getFps().getValue(), - hwcConfig->getWidth(), hwcConfig->getHeight(), getConfigGroup()); + getModeId().value(), mode->getHwcId(), getFps().getValue(), + mode->getWidth(), mode->getHeight(), getModeGroup()); } std::string RefreshRateConfigs::layerVoteTypeString(LayerVoteType vote) { @@ -89,9 +89,9 @@ std::string RefreshRateConfigs::layerVoteTypeString(LayerVoteType vote) { } std::string RefreshRateConfigs::Policy::toString() const { - return base::StringPrintf("default config ID: %zu, allowGroupSwitching = %d" + return base::StringPrintf("default mode ID: %zu, allowGroupSwitching = %d" ", primary range: %s, app request range: %s", - defaultConfig.value(), allowGroupSwitching, + defaultMode.value(), allowGroupSwitching, primaryRange.toString().c_str(), appRequestRange.toString().c_str()); } @@ -291,7 +291,7 @@ RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequir scores.emplace_back(RefreshRateScore{refreshRate, 0.0f}); } - const auto& defaultConfig = mRefreshRates.at(policy->defaultConfig); + const auto& defaultMode = mRefreshRates.at(policy->defaultMode); for (const auto& layer : layers) { ALOGV("Calculating score for %s (%s, weight %.2f)", layer.name.c_str(), @@ -303,11 +303,11 @@ RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequir auto weight = layer.weight; for (auto i = 0u; i < scores.size(); i++) { - const bool isSeamlessSwitch = scores[i].refreshRate->getConfigGroup() == - mCurrentRefreshRate->getConfigGroup(); + const bool isSeamlessSwitch = + scores[i].refreshRate->getModeGroup() == mCurrentRefreshRate->getModeGroup(); if (layer.seamlessness == Seamlessness::OnlySeamless && !isSeamlessSwitch) { - ALOGV("%s ignores %s to avoid non-seamless switch. Current config = %s", + ALOGV("%s ignores %s to avoid non-seamless switch. Current mode = %s", formatLayerInfo(layer, weight).c_str(), scores[i].refreshRate->toString().c_str(), mCurrentRefreshRate->toString().c_str()); @@ -317,26 +317,25 @@ RefreshRate RefreshRateConfigs::getBestRefreshRate(const std::vector<LayerRequir if (layer.seamlessness == Seamlessness::SeamedAndSeamless && !isSeamlessSwitch && !layer.focused) { ALOGV("%s ignores %s because it's not focused and the switch is going to be seamed." - " Current config = %s", + " Current mode = %s", formatLayerInfo(layer, weight).c_str(), scores[i].refreshRate->toString().c_str(), mCurrentRefreshRate->toString().c_str()); continue; } - // Layers with default seamlessness vote for the current config group if + // Layers with default seamlessness vote for the current mode group if // there are layers with seamlessness=SeamedAndSeamless and for the default - // config group otherwise. In second case, if the current config group is different + // mode group otherwise. In second case, if the current mode group is different // from the default, this means a layer with seamlessness=SeamedAndSeamless has just // disappeared. const bool isInPolicyForDefault = seamedLayers > 0 - ? scores[i].refreshRate->getConfigGroup() == - mCurrentRefreshRate->getConfigGroup() - : scores[i].refreshRate->getConfigGroup() == defaultConfig->getConfigGroup(); + ? scores[i].refreshRate->getModeGroup() == mCurrentRefreshRate->getModeGroup() + : scores[i].refreshRate->getModeGroup() == defaultMode->getModeGroup(); if (layer.seamlessness == Seamlessness::Default && !isInPolicyForDefault && !layer.focused) { - ALOGV("%s ignores %s. Current config = %s", formatLayerInfo(layer, weight).c_str(), + ALOGV("%s ignores %s. Current mode = %s", formatLayerInfo(layer, weight).c_str(), scores[i].refreshRate->toString().c_str(), mCurrentRefreshRate->toString().c_str()); continue; @@ -548,12 +547,12 @@ std::optional<Fps> RefreshRateConfigs::onKernelTimerChanged( const RefreshRate& RefreshRateConfigs::getMinRefreshRateByPolicyLocked() const { for (auto refreshRate : mPrimaryRefreshRates) { - if (mCurrentRefreshRate->getConfigGroup() == refreshRate->getConfigGroup()) { + if (mCurrentRefreshRate->getModeGroup() == refreshRate->getModeGroup()) { return *refreshRate; } } - ALOGE("Can't find min refresh rate by policy with the same config group" - " as the current config %s", + ALOGE("Can't find min refresh rate by policy with the same mode group" + " as the current mode %s", mCurrentRefreshRate->toString().c_str()); // Defaulting to the lowest refresh rate return *mPrimaryRefreshRates.front(); @@ -567,12 +566,12 @@ RefreshRate RefreshRateConfigs::getMaxRefreshRateByPolicy() const { const RefreshRate& RefreshRateConfigs::getMaxRefreshRateByPolicyLocked() const { for (auto it = mPrimaryRefreshRates.rbegin(); it != mPrimaryRefreshRates.rend(); it++) { const auto& refreshRate = (**it); - if (mCurrentRefreshRate->getConfigGroup() == refreshRate.getConfigGroup()) { + if (mCurrentRefreshRate->getModeGroup() == refreshRate.getModeGroup()) { return refreshRate; } } - ALOGE("Can't find max refresh rate by policy with the same config group" - " as the current config %s", + ALOGE("Can't find max refresh rate by policy with the same mode group" + " as the current mode %s", mCurrentRefreshRate->toString().c_str()); // Defaulting to the highest refresh rate return *mPrimaryRefreshRates.back(); @@ -593,50 +592,50 @@ const RefreshRate& RefreshRateConfigs::getCurrentRefreshRateByPolicyLocked() con mCurrentRefreshRate) != mAppRequestRefreshRates.end()) { return *mCurrentRefreshRate; } - return *mRefreshRates.at(getCurrentPolicyLocked()->defaultConfig); + return *mRefreshRates.at(getCurrentPolicyLocked()->defaultMode); } -void RefreshRateConfigs::setCurrentConfigId(DisplayModeId configId) { +void RefreshRateConfigs::setCurrentModeId(DisplayModeId modeId) { std::lock_guard lock(mLock); - mCurrentRefreshRate = mRefreshRates.at(configId).get(); + mCurrentRefreshRate = mRefreshRates.at(modeId).get(); } -RefreshRateConfigs::RefreshRateConfigs(const DisplayModes& configs, DisplayModeId currentConfigId, +RefreshRateConfigs::RefreshRateConfigs(const DisplayModes& modes, DisplayModeId currentModeId, bool enableFrameRateOverride) - : mKnownFrameRates(constructKnownFrameRates(configs)), + : mKnownFrameRates(constructKnownFrameRates(modes)), mEnableFrameRateOverride(enableFrameRateOverride) { - updateDisplayConfigs(configs, currentConfigId); + updateDisplayModes(modes, currentModeId); } -void RefreshRateConfigs::updateDisplayConfigs(const DisplayModes& configs, - DisplayModeId currentConfigId) { +void RefreshRateConfigs::updateDisplayModes(const DisplayModes& modes, + DisplayModeId currentModeId) { std::lock_guard lock(mLock); - LOG_ALWAYS_FATAL_IF(configs.empty()); - LOG_ALWAYS_FATAL_IF(currentConfigId.value() >= configs.size()); + LOG_ALWAYS_FATAL_IF(modes.empty()); + LOG_ALWAYS_FATAL_IF(currentModeId.value() >= modes.size()); mRefreshRates.clear(); - for (const auto& config : configs) { - const auto configId = config->getId(); - const auto fps = Fps::fromPeriodNsecs(config->getVsyncPeriod()); - mRefreshRates.emplace(configId, - std::make_unique<RefreshRate>(configId, config, fps, + for (const auto& mode : modes) { + const auto modeId = mode->getId(); + const auto fps = Fps::fromPeriodNsecs(mode->getVsyncPeriod()); + mRefreshRates.emplace(modeId, + std::make_unique<RefreshRate>(modeId, mode, fps, RefreshRate::ConstructorTag(0))); - if (configId == currentConfigId) { - mCurrentRefreshRate = mRefreshRates.at(configId).get(); + if (modeId == currentModeId) { + mCurrentRefreshRate = mRefreshRates.at(modeId).get(); } } - std::vector<const RefreshRate*> sortedConfigs; - getSortedRefreshRateListLocked([](const RefreshRate&) { return true; }, &sortedConfigs); - mDisplayManagerPolicy.defaultConfig = currentConfigId; - mMinSupportedRefreshRate = sortedConfigs.front(); - mMaxSupportedRefreshRate = sortedConfigs.back(); + std::vector<const RefreshRate*> sortedModes; + getSortedRefreshRateListLocked([](const RefreshRate&) { return true; }, &sortedModes); + mDisplayManagerPolicy.defaultMode = currentModeId; + mMinSupportedRefreshRate = sortedModes.front(); + mMaxSupportedRefreshRate = sortedModes.back(); mSupportsFrameRateOverride = false; if (mEnableFrameRateOverride) { - for (const auto& config1 : sortedConfigs) { - for (const auto& config2 : sortedConfigs) { - if (getFrameRateDivider(config1->getFps(), config2->getFps()) >= 2) { + for (const auto& mode1 : sortedModes) { + for (const auto& mode2 : sortedModes) { + if (getFrameRateDivider(mode1->getFps(), mode2->getFps()) >= 2) { mSupportsFrameRateOverride = true; break; } @@ -648,15 +647,15 @@ void RefreshRateConfigs::updateDisplayConfigs(const DisplayModes& configs, } bool RefreshRateConfigs::isPolicyValidLocked(const Policy& policy) const { - // defaultConfig must be a valid config, and within the given refresh rate range. - auto iter = mRefreshRates.find(policy.defaultConfig); + // defaultMode must be a valid mode, and within the given refresh rate range. + auto iter = mRefreshRates.find(policy.defaultMode); if (iter == mRefreshRates.end()) { - ALOGE("Default config is not found."); + ALOGE("Default mode is not found."); return false; } const RefreshRate& refreshRate = *iter->second; if (!refreshRate.inPolicy(policy.primaryRange.min, policy.primaryRange.max)) { - ALOGE("Default config is not in the primary range."); + ALOGE("Default mode is not in the primary range."); return false; } return policy.appRequestRange.min.lessThanOrEqualWithMargin(policy.primaryRange.min) && @@ -706,10 +705,10 @@ RefreshRateConfigs::Policy RefreshRateConfigs::getDisplayManagerPolicy() const { return mDisplayManagerPolicy; } -bool RefreshRateConfigs::isConfigAllowed(DisplayModeId config) const { +bool RefreshRateConfigs::isModeAllowed(DisplayModeId modeId) const { std::lock_guard lock(mLock); for (const RefreshRate* refreshRate : mAppRequestRefreshRates) { - if (refreshRate->configId == config) { + if (refreshRate->modeId == modeId) { return true; } } @@ -723,60 +722,59 @@ void RefreshRateConfigs::getSortedRefreshRateListLocked( outRefreshRates->reserve(mRefreshRates.size()); for (const auto& [type, refreshRate] : mRefreshRates) { if (shouldAddRefreshRate(*refreshRate)) { - ALOGV("getSortedRefreshRateListLocked: config %zu added to list policy", - refreshRate->configId.value()); + ALOGV("getSortedRefreshRateListLocked: mode %zu added to list policy", + refreshRate->modeId.value()); outRefreshRates->push_back(refreshRate.get()); } } std::sort(outRefreshRates->begin(), outRefreshRates->end(), [](const auto refreshRate1, const auto refreshRate2) { - if (refreshRate1->hwcConfig->getVsyncPeriod() != - refreshRate2->hwcConfig->getVsyncPeriod()) { - return refreshRate1->hwcConfig->getVsyncPeriod() > - refreshRate2->hwcConfig->getVsyncPeriod(); + if (refreshRate1->mode->getVsyncPeriod() != + refreshRate2->mode->getVsyncPeriod()) { + return refreshRate1->mode->getVsyncPeriod() > + refreshRate2->mode->getVsyncPeriod(); } else { - return refreshRate1->hwcConfig->getConfigGroup() > - refreshRate2->hwcConfig->getConfigGroup(); + return refreshRate1->mode->getGroup() > refreshRate2->mode->getGroup(); } }); } void RefreshRateConfigs::constructAvailableRefreshRates() { - // Filter configs based on current policy and sort based on vsync period + // Filter modes based on current policy and sort based on vsync period const Policy* policy = getCurrentPolicyLocked(); - const auto& defaultConfig = mRefreshRates.at(policy->defaultConfig)->hwcConfig; + const auto& defaultMode = mRefreshRates.at(policy->defaultMode)->mode; ALOGV("constructAvailableRefreshRates: %s ", policy->toString().c_str()); - auto filterRefreshRates = [&](Fps min, Fps max, const char* listName, - std::vector<const RefreshRate*>* - outRefreshRates) REQUIRES(mLock) { - getSortedRefreshRateListLocked( - [&](const RefreshRate& refreshRate) REQUIRES(mLock) { - const auto& hwcConfig = refreshRate.hwcConfig; - - return hwcConfig->getHeight() == defaultConfig->getHeight() && - hwcConfig->getWidth() == defaultConfig->getWidth() && - hwcConfig->getDpiX() == defaultConfig->getDpiX() && - hwcConfig->getDpiY() == defaultConfig->getDpiY() && - (policy->allowGroupSwitching || - hwcConfig->getConfigGroup() == defaultConfig->getConfigGroup()) && - refreshRate.inPolicy(min, max); - }, - outRefreshRates); - - LOG_ALWAYS_FATAL_IF(outRefreshRates->empty(), - "No matching configs for %s range: min=%s max=%s", listName, - to_string(min).c_str(), to_string(max).c_str()); - auto stringifyRefreshRates = [&]() -> std::string { - std::string str; - for (auto refreshRate : *outRefreshRates) { - base::StringAppendF(&str, "%s ", refreshRate->getName().c_str()); - } - return str; - }; - ALOGV("%s refresh rates: %s", listName, stringifyRefreshRates().c_str()); - }; + auto filterRefreshRates = + [&](Fps min, Fps max, const char* listName, + std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock) { + getSortedRefreshRateListLocked( + [&](const RefreshRate& refreshRate) REQUIRES(mLock) { + const auto& mode = refreshRate.mode; + + return mode->getHeight() == defaultMode->getHeight() && + mode->getWidth() == defaultMode->getWidth() && + mode->getDpiX() == defaultMode->getDpiX() && + mode->getDpiY() == defaultMode->getDpiY() && + (policy->allowGroupSwitching || + mode->getGroup() == defaultMode->getGroup()) && + refreshRate.inPolicy(min, max); + }, + outRefreshRates); + + LOG_ALWAYS_FATAL_IF(outRefreshRates->empty(), + "No matching modes for %s range: min=%s max=%s", listName, + to_string(min).c_str(), to_string(max).c_str()); + auto stringifyRefreshRates = [&]() -> std::string { + std::string str; + for (auto refreshRate : *outRefreshRates) { + base::StringAppendF(&str, "%s ", refreshRate->getName().c_str()); + } + return str; + }; + ALOGV("%s refresh rates: %s", listName, stringifyRefreshRates().c_str()); + }; filterRefreshRates(policy->primaryRange.min, policy->primaryRange.max, "primary", &mPrimaryRefreshRates); @@ -845,20 +843,20 @@ int RefreshRateConfigs::getRefreshRateDivider(Fps frameRate) const { void RefreshRateConfigs::dump(std::string& result) const { std::lock_guard lock(mLock); - base::StringAppendF(&result, "DesiredDisplayConfigSpecs (DisplayManager): %s\n\n", + base::StringAppendF(&result, "DesiredDisplayModeSpecs (DisplayManager): %s\n\n", mDisplayManagerPolicy.toString().c_str()); scheduler::RefreshRateConfigs::Policy currentPolicy = *getCurrentPolicyLocked(); if (mOverridePolicy && currentPolicy != mDisplayManagerPolicy) { - base::StringAppendF(&result, "DesiredDisplayConfigSpecs (Override): %s\n\n", + base::StringAppendF(&result, "DesiredDisplayModeSpecs (Override): %s\n\n", currentPolicy.toString().c_str()); } - auto config = mCurrentRefreshRate->hwcConfig; - base::StringAppendF(&result, "Current config: %s\n", mCurrentRefreshRate->toString().c_str()); + auto mode = mCurrentRefreshRate->mode; + base::StringAppendF(&result, "Current mode: %s\n", mCurrentRefreshRate->toString().c_str()); result.append("Refresh rates:\n"); for (const auto& [id, refreshRate] : mRefreshRates) { - config = refreshRate->hwcConfig; + mode = refreshRate->mode; base::StringAppendF(&result, "\t%s\n", refreshRate->toString().c_str()); } diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h index 0c7dc0515c..2bc22b43f7 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h @@ -64,12 +64,12 @@ public: }; public: - RefreshRate(DisplayModeId configId, DisplayModePtr config, Fps fps, ConstructorTag) - : configId(configId), hwcConfig(config), fps(std::move(fps)) {} + RefreshRate(DisplayModeId modeId, DisplayModePtr mode, Fps fps, ConstructorTag) + : modeId(modeId), mode(mode), fps(std::move(fps)) {} - DisplayModeId getConfigId() const { return configId; } - nsecs_t getVsyncPeriod() const { return hwcConfig->getVsyncPeriod(); } - int32_t getConfigGroup() const { return hwcConfig->getConfigGroup(); } + DisplayModeId getModeId() const { return modeId; } + nsecs_t getVsyncPeriod() const { return mode->getVsyncPeriod(); } + int32_t getModeGroup() const { return mode->getGroup(); } std::string getName() const { return to_string(fps); } Fps getFps() const { return fps; } @@ -81,7 +81,7 @@ public: } bool operator!=(const RefreshRate& other) const { - return configId != other.configId || hwcConfig != other.hwcConfig; + return modeId != other.modeId || mode != other.mode; } bool operator<(const RefreshRate& other) const { @@ -99,11 +99,8 @@ public: friend RefreshRateConfigs; friend class RefreshRateConfigsTest; - // This config ID corresponds to the position of the config in the vector that is stored - // on the device. - const DisplayModeId configId; - // The config itself - DisplayModePtr hwcConfig; + const DisplayModeId modeId; + DisplayModePtr mode; // Refresh rate in frames per second const Fps fps{0.0f}; }; @@ -131,16 +128,16 @@ public: static constexpr int kAllowGroupSwitchingDefault = false; public: - // The default config, used to ensure we only initiate display config switches within the - // same config group as defaultConfigId's group. - DisplayModeId defaultConfig; - // Whether or not we switch config groups to get the best frame rate. + // The default mode, used to ensure we only initiate display mode switches within the + // same mode group as defaultMode's group. + DisplayModeId defaultMode; + // Whether or not we switch mode groups to get the best frame rate. bool allowGroupSwitching = kAllowGroupSwitchingDefault; // The primary refresh rate range represents display manager's general guidance on the - // display configs we'll consider when switching refresh rates. Unless we get an explicit + // display modes we'll consider when switching refresh rates. Unless we get an explicit // signal from an app, we should stay within this range. FpsRange primaryRange; - // The app request refresh rate range allows us to consider more display configs when + // The app request refresh rate range allows us to consider more display modes when // switching refresh rates. Although we should generally stay within the primary range, // specific considerations, such as layer frame rate settings specified via the // setFrameRate() api, may cause us to go outside the primary range. We never go outside the @@ -150,25 +147,25 @@ public: Policy() = default; - Policy(DisplayModeId defaultConfig, const FpsRange& range) - : Policy(defaultConfig, kAllowGroupSwitchingDefault, range, range) {} + Policy(DisplayModeId defaultMode, const FpsRange& range) + : Policy(defaultMode, kAllowGroupSwitchingDefault, range, range) {} - Policy(DisplayModeId defaultConfig, bool allowGroupSwitching, const FpsRange& range) - : Policy(defaultConfig, allowGroupSwitching, range, range) {} + Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& range) + : Policy(defaultMode, allowGroupSwitching, range, range) {} - Policy(DisplayModeId defaultConfig, const FpsRange& primaryRange, + Policy(DisplayModeId defaultMode, const FpsRange& primaryRange, const FpsRange& appRequestRange) - : Policy(defaultConfig, kAllowGroupSwitchingDefault, primaryRange, appRequestRange) {} + : Policy(defaultMode, kAllowGroupSwitchingDefault, primaryRange, appRequestRange) {} - Policy(DisplayModeId defaultConfig, bool allowGroupSwitching, const FpsRange& primaryRange, + Policy(DisplayModeId defaultMode, bool allowGroupSwitching, const FpsRange& primaryRange, const FpsRange& appRequestRange) - : defaultConfig(defaultConfig), + : defaultMode(defaultMode), allowGroupSwitching(allowGroupSwitching), primaryRange(primaryRange), appRequestRange(appRequestRange) {} bool operator==(const Policy& other) const { - return defaultConfig == other.defaultConfig && primaryRange == other.primaryRange && + return defaultMode == other.defaultMode && primaryRange == other.primaryRange && appRequestRange == other.appRequestRange && allowGroupSwitching == other.allowGroupSwitching; } @@ -200,8 +197,8 @@ public: // Gets the display manager policy, regardless of whether an override policy is active. Policy getDisplayManagerPolicy() const EXCLUDES(mLock); - // Returns true if config is allowed by the current policy. - bool isConfigAllowed(DisplayModeId config) const EXCLUDES(mLock); + // Returns true if mode is allowed by the current policy. + bool isModeAllowed(DisplayModeId) const EXCLUDES(mLock); // Describes the different options the layer voted for refresh rate enum class LayerVoteType { @@ -270,7 +267,7 @@ public: return {mMinSupportedRefreshRate->getFps(), mMaxSupportedRefreshRate->getFps()}; } - std::optional<Fps> onKernelTimerChanged(std::optional<DisplayModeId> desiredActiveConfigId, + std::optional<Fps> onKernelTimerChanged(std::optional<DisplayModeId> desiredActiveModeId, bool timerExpired) const EXCLUDES(mLock); // Returns the highest refresh rate according to the current policy. May change at runtime. Only @@ -286,14 +283,14 @@ public: // Returns the refresh rate that corresponds to a DisplayModeId. This may change at // runtime. - // TODO(b/159590486) An invalid config id may be given here if the dipslay configs have changed. - RefreshRate getRefreshRateFromConfigId(DisplayModeId configId) const EXCLUDES(mLock) { + // TODO(b/159590486) An invalid mode id may be given here if the dipslay modes have changed. + RefreshRate getRefreshRateFromModeId(DisplayModeId modeId) const EXCLUDES(mLock) { std::lock_guard lock(mLock); - return *mRefreshRates.at(configId); + return *mRefreshRates.at(modeId); }; - // Stores the current configId the device operates at - void setCurrentConfigId(DisplayModeId configId) EXCLUDES(mLock); + // Stores the current modeId the device operates at + void setCurrentModeId(DisplayModeId) EXCLUDES(mLock); // Returns a string that represents the layer vote type static std::string layerVoteTypeString(LayerVoteType vote); @@ -301,14 +298,13 @@ public: // Returns a known frame rate that is the closest to frameRate Fps findClosestKnownFrameRate(Fps frameRate) const; - RefreshRateConfigs(const DisplayModes& configs, DisplayModeId currentConfigId, + RefreshRateConfigs(const DisplayModes& modes, DisplayModeId currentModeId, bool enableFrameRateOverride = false); - void updateDisplayConfigs(const DisplayModes& configs, DisplayModeId currentConfig) - EXCLUDES(mLock); + void updateDisplayModes(const DisplayModes& mode, DisplayModeId currentModeId) EXCLUDES(mLock); - // Returns whether switching configs (refresh rate or resolution) is possible. - // TODO(b/158780872): Consider HAL support, and skip frame rate detection if the configs only + // Returns whether switching modes (refresh rate or resolution) is possible. + // TODO(b/158780872): Consider HAL support, and skip frame rate detection if the modes only // differ in resolution. bool canSwitch() const EXCLUDES(mLock) { std::lock_guard lock(mLock); @@ -387,7 +383,7 @@ private: float calculateLayerScoreLocked(const LayerRequirement&, const RefreshRate&, bool isSeamlessSwitch) const REQUIRES(mLock); - // The list of refresh rates, indexed by display config ID. This may change after this + // The list of refresh rates, indexed by display modes ID. This may change after this // object is initialized. AllRefreshRatesMapType mRefreshRates GUARDED_BY(mLock); @@ -399,7 +395,7 @@ private: // vsyncPeriod (the first element is the lowest refresh rate). std::vector<const RefreshRate*> mAppRequestRefreshRates GUARDED_BY(mLock); - // The current config. This will change at runtime. This is set by SurfaceFlinger on + // The current display mode. This will change at runtime. This is set by SurfaceFlinger on // the main thread, and read by the Scheduler (and other objects) on other threads. const RefreshRate* mCurrentRefreshRate GUARDED_BY(mLock); diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index d8612098ec..98132701d1 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -348,55 +348,53 @@ void Scheduler::onFrameRateOverridesChanged(ConnectionHandle handle, PhysicalDis thread->onFrameRateOverridesChanged(displayId, std::move(overrides)); } -void Scheduler::onPrimaryDisplayConfigChanged(ConnectionHandle handle, PhysicalDisplayId displayId, - DisplayModeId configId, nsecs_t vsyncPeriod) { +void Scheduler::onPrimaryDisplayModeChanged(ConnectionHandle handle, PhysicalDisplayId displayId, + DisplayModeId modeId, nsecs_t vsyncPeriod) { { std::lock_guard<std::mutex> lock(mFeatureStateLock); - // Cache the last reported config for primary display. - mFeatures.cachedConfigChangedParams = {handle, displayId, configId, vsyncPeriod}; + // Cache the last reported modes for primary display. + mFeatures.cachedModeChangedParams = {handle, displayId, modeId, vsyncPeriod}; } - onNonPrimaryDisplayConfigChanged(handle, displayId, configId, vsyncPeriod); + onNonPrimaryDisplayModeChanged(handle, displayId, modeId, vsyncPeriod); } -void Scheduler::dispatchCachedReportedConfig() { +void Scheduler::dispatchCachedReportedMode() { // Check optional fields first. - if (!mFeatures.configId.has_value()) { - ALOGW("No config ID found, not dispatching cached config."); + if (!mFeatures.modeId.has_value()) { + ALOGW("No mode ID found, not dispatching cached mode."); return; } - if (!mFeatures.cachedConfigChangedParams.has_value()) { - ALOGW("No config changed params found, not dispatching cached config."); + if (!mFeatures.cachedModeChangedParams.has_value()) { + ALOGW("No mode changed params found, not dispatching cached mode."); return; } - const auto configId = *mFeatures.configId; - const auto vsyncPeriod = - mRefreshRateConfigs.getRefreshRateFromConfigId(configId).getVsyncPeriod(); + const auto modeId = *mFeatures.modeId; + const auto vsyncPeriod = mRefreshRateConfigs.getRefreshRateFromModeId(modeId).getVsyncPeriod(); - // If there is no change from cached config, there is no need to dispatch an event - if (configId == mFeatures.cachedConfigChangedParams->configId && - vsyncPeriod == mFeatures.cachedConfigChangedParams->vsyncPeriod) { + // If there is no change from cached mode, there is no need to dispatch an event + if (modeId == mFeatures.cachedModeChangedParams->modeId && + vsyncPeriod == mFeatures.cachedModeChangedParams->vsyncPeriod) { return; } - mFeatures.cachedConfigChangedParams->configId = configId; - mFeatures.cachedConfigChangedParams->vsyncPeriod = vsyncPeriod; - onNonPrimaryDisplayConfigChanged(mFeatures.cachedConfigChangedParams->handle, - mFeatures.cachedConfigChangedParams->displayId, - mFeatures.cachedConfigChangedParams->configId, - mFeatures.cachedConfigChangedParams->vsyncPeriod); + mFeatures.cachedModeChangedParams->modeId = modeId; + mFeatures.cachedModeChangedParams->vsyncPeriod = vsyncPeriod; + onNonPrimaryDisplayModeChanged(mFeatures.cachedModeChangedParams->handle, + mFeatures.cachedModeChangedParams->displayId, + mFeatures.cachedModeChangedParams->modeId, + mFeatures.cachedModeChangedParams->vsyncPeriod); } -void Scheduler::onNonPrimaryDisplayConfigChanged(ConnectionHandle handle, - PhysicalDisplayId displayId, - DisplayModeId configId, nsecs_t vsyncPeriod) { +void Scheduler::onNonPrimaryDisplayModeChanged(ConnectionHandle handle, PhysicalDisplayId displayId, + DisplayModeId modeId, nsecs_t vsyncPeriod) { android::EventThread* thread; { std::lock_guard<std::mutex> lock(mConnectionsLock); RETURN_IF_INVALID_HANDLE(handle); thread = mConnections[handle].thread.get(); } - thread->onConfigChanged(displayId, configId, vsyncPeriod); + thread->onModeChanged(displayId, modeId, vsyncPeriod); } size_t Scheduler::getEventThreadConnectionCount(ConnectionHandle handle) { @@ -590,9 +588,9 @@ void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime, } } -void Scheduler::setConfigChangePending(bool pending) { +void Scheduler::setModeChangePending(bool pending) { if (mLayerHistory) { - mLayerHistory->setConfigChangePending(pending); + mLayerHistory->setModeChangePending(pending); } } @@ -603,7 +601,7 @@ void Scheduler::chooseRefreshRateForContent() { scheduler::LayerHistory::Summary summary = mLayerHistory->summarize(systemTime()); scheduler::RefreshRateConfigs::GlobalSignals consideredSignals; - DisplayModeId newConfigId; + DisplayModeId newModeId; bool frameRateChanged; bool frameRateOverridesChanged; { @@ -613,28 +611,28 @@ void Scheduler::chooseRefreshRateForContent() { } mFeatures.contentRequirements = summary; - newConfigId = calculateRefreshRateConfigIndexType(&consideredSignals); - auto newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); + newModeId = calculateRefreshRateModeId(&consideredSignals); + auto newRefreshRate = mRefreshRateConfigs.getRefreshRateFromModeId(newModeId); frameRateOverridesChanged = updateFrameRateOverrides(consideredSignals, newRefreshRate.getFps()); - if (mFeatures.configId == newConfigId) { - // We don't need to change the config, but we might need to send an event - // about a config change, since it was suppressed due to a previous idleConsidered + if (mFeatures.modeId == newModeId) { + // We don't need to change the display mode, but we might need to send an event + // about a mode change, since it was suppressed due to a previous idleConsidered if (!consideredSignals.idle) { - dispatchCachedReportedConfig(); + dispatchCachedReportedMode(); } frameRateChanged = false; } else { - mFeatures.configId = newConfigId; + mFeatures.modeId = newModeId; frameRateChanged = true; } } if (frameRateChanged) { - auto newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); + auto newRefreshRate = mRefreshRateConfigs.getRefreshRateFromModeId(newModeId); mSchedulerCallback.changeRefreshRate(newRefreshRate, - consideredSignals.idle ? ConfigEvent::None - : ConfigEvent::Changed); + consideredSignals.idle ? ModeEvent::None + : ModeEvent::Changed); } if (frameRateOverridesChanged) { mSchedulerCallback.triggerOnFrameRateOverridesChanged(); @@ -783,7 +781,7 @@ bool Scheduler::updateFrameRateOverrides( template <class T> bool Scheduler::handleTimerStateChanged(T* currentState, T newState) { - DisplayModeId newConfigId; + DisplayModeId newModeId; bool refreshRateChanged = false; bool frameRateOverridesChanged; scheduler::RefreshRateConfigs::GlobalSignals consideredSignals; @@ -793,29 +791,27 @@ bool Scheduler::handleTimerStateChanged(T* currentState, T newState) { return false; } *currentState = newState; - newConfigId = calculateRefreshRateConfigIndexType(&consideredSignals); - const RefreshRate& newRefreshRate = - mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); + newModeId = calculateRefreshRateModeId(&consideredSignals); + const RefreshRate& newRefreshRate = mRefreshRateConfigs.getRefreshRateFromModeId(newModeId); frameRateOverridesChanged = updateFrameRateOverrides(consideredSignals, newRefreshRate.getFps()); - if (mFeatures.configId == newConfigId) { - // We don't need to change the config, but we might need to send an event - // about a config change, since it was suppressed due to a previous idleConsidered + if (mFeatures.modeId == newModeId) { + // We don't need to change the display mode, but we might need to send an event + // about a mode change, since it was suppressed due to a previous idleConsidered if (!consideredSignals.idle) { - dispatchCachedReportedConfig(); + dispatchCachedReportedMode(); } } else { - mFeatures.configId = newConfigId; + mFeatures.modeId = newModeId; refreshRateChanged = true; } } if (refreshRateChanged) { - const RefreshRate& newRefreshRate = - mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); + const RefreshRate& newRefreshRate = mRefreshRateConfigs.getRefreshRateFromModeId(newModeId); mSchedulerCallback.changeRefreshRate(newRefreshRate, - consideredSignals.idle ? ConfigEvent::None - : ConfigEvent::Changed); + consideredSignals.idle ? ModeEvent::None + : ModeEvent::Changed); } if (frameRateOverridesChanged) { mSchedulerCallback.triggerOnFrameRateOverridesChanged(); @@ -823,7 +819,7 @@ bool Scheduler::handleTimerStateChanged(T* currentState, T newState) { return consideredSignals.touch; } -DisplayModeId Scheduler::calculateRefreshRateConfigIndexType( +DisplayModeId Scheduler::calculateRefreshRateModeId( scheduler::RefreshRateConfigs::GlobalSignals* consideredSignals) { ATRACE_CALL(); if (consideredSignals) *consideredSignals = {}; @@ -833,7 +829,7 @@ DisplayModeId Scheduler::calculateRefreshRateConfigIndexType( if (mDisplayPowerTimer && (!mFeatures.isDisplayPowerStateNormal || mFeatures.displayPowerTimer == TimerState::Reset)) { - return mRefreshRateConfigs.getMaxRefreshRateByPolicy().getConfigId(); + return mRefreshRateConfigs.getMaxRefreshRateByPolicy().getModeId(); } const bool touchActive = mTouchTimer && mFeatures.touch == TouchState::Active; @@ -842,16 +838,16 @@ DisplayModeId Scheduler::calculateRefreshRateConfigIndexType( return mRefreshRateConfigs .getBestRefreshRate(mFeatures.contentRequirements, {.touch = touchActive, .idle = idle}, consideredSignals) - .getConfigId(); + .getModeId(); } -std::optional<DisplayModeId> Scheduler::getPreferredConfigId() { +std::optional<DisplayModeId> Scheduler::getPreferredModeId() { std::lock_guard<std::mutex> lock(mFeatureStateLock); - // Make sure that the default config ID is first updated, before returned. - if (mFeatures.configId.has_value()) { - mFeatures.configId = calculateRefreshRateConfigIndexType(); + // Make sure that the default mode ID is first updated, before returned. + if (mFeatures.modeId.has_value()) { + mFeatures.modeId = calculateRefreshRateModeId(); } - return mFeatures.configId; + return mFeatures.modeId; } void Scheduler::onNewVsyncPeriodChangeTimeline(const hal::VsyncPeriodChangeTimeline& timeline) { diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h index 340ca8e88d..5237516f17 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.h +++ b/services/surfaceflinger/Scheduler/Scheduler.h @@ -70,7 +70,7 @@ protected: class Scheduler { public: using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate; - using ConfigEvent = scheduler::RefreshRateConfigEvent; + using ModeEvent = scheduler::RefreshRateConfigEvent; Scheduler(const scheduler::RefreshRateConfigs&, ISchedulerCallback&); ~Scheduler(); @@ -87,10 +87,10 @@ public: sp<EventThreadConnection> getEventConnection(ConnectionHandle); void onHotplugReceived(ConnectionHandle, PhysicalDisplayId, bool connected); - void onPrimaryDisplayConfigChanged(ConnectionHandle, PhysicalDisplayId, DisplayModeId configId, - nsecs_t vsyncPeriod) EXCLUDES(mFeatureStateLock); - void onNonPrimaryDisplayConfigChanged(ConnectionHandle, PhysicalDisplayId, - DisplayModeId configId, nsecs_t vsyncPeriod); + void onPrimaryDisplayModeChanged(ConnectionHandle, PhysicalDisplayId, DisplayModeId, + nsecs_t vsyncPeriod) EXCLUDES(mFeatureStateLock); + void onNonPrimaryDisplayModeChanged(ConnectionHandle, PhysicalDisplayId, DisplayModeId, + nsecs_t vsyncPeriod); void onScreenAcquired(ConnectionHandle); void onScreenReleased(ConnectionHandle); @@ -128,7 +128,7 @@ public: // Layers are registered on creation, and unregistered when the weak reference expires. void registerLayer(Layer*); void recordLayerHistory(Layer*, nsecs_t presentTime, LayerHistory::LayerUpdateType updateType); - void setConfigChangePending(bool pending); + void setModeChangePending(bool pending); // Detects content using layer history, and selects a matching refresh rate. void chooseRefreshRateForContent(); @@ -153,7 +153,7 @@ public: void dumpVsync(std::string&) const; // Get the appropriate refresh for current conditions. - std::optional<DisplayModeId> getPreferredConfigId(); + std::optional<DisplayModeId> getPreferredModeId(); // Notifies the scheduler about a refresh rate timeline change. void onNewVsyncPeriodChangeTimeline(const hal::VsyncPeriodChangeTimeline& timeline); @@ -227,11 +227,11 @@ private: // This function checks whether individual features that are affecting the refresh rate // selection were initialized, prioritizes them, and calculates the DisplayModeId // for the suggested refresh rate. - DisplayModeId calculateRefreshRateConfigIndexType( + DisplayModeId calculateRefreshRateModeId( scheduler::RefreshRateConfigs::GlobalSignals* consideredSignals = nullptr) REQUIRES(mFeatureStateLock); - void dispatchCachedReportedConfig() REQUIRES(mFeatureStateLock); + void dispatchCachedReportedMode() REQUIRES(mFeatureStateLock); bool updateFrameRateOverrides(scheduler::RefreshRateConfigs::GlobalSignals consideredSignals, Fps displayRefreshRate) REQUIRES(mFeatureStateLock) EXCLUDES(mFrameRateOverridesMutex); @@ -283,20 +283,20 @@ private: TouchState touch = TouchState::Inactive; TimerState displayPowerTimer = TimerState::Expired; - std::optional<DisplayModeId> configId; + std::optional<DisplayModeId> modeId; LayerHistory::Summary contentRequirements; bool isDisplayPowerStateNormal = true; - // Used to cache the last parameters of onPrimaryDisplayConfigChanged - struct ConfigChangedParams { + // Used to cache the last parameters of onPrimaryDisplayModeChanged + struct ModeChangedParams { ConnectionHandle handle; PhysicalDisplayId displayId; - DisplayModeId configId; + DisplayModeId modeId; nsecs_t vsyncPeriod; }; - std::optional<ConfigChangedParams> cachedConfigChangedParams; + std::optional<ModeChangedParams> cachedModeChangedParams; } mFeatures GUARDED_BY(mFeatureStateLock); const scheduler::RefreshRateConfigs& mRefreshRateConfigs; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index bbbb0034ce..a36502cea1 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -67,9 +67,9 @@ #include <sys/types.h> #include <ui/ColorSpace.h> #include <ui/DebugUtils.h> -#include <ui/DisplayConfig.h> #include <ui/DisplayId.h> #include <ui/DisplayInfo.h> +#include <ui/DisplayMode.h> #include <ui/DisplayStatInfo.h> #include <ui/DisplayState.h> #include <ui/GraphicBufferAllocator.h> @@ -887,9 +887,9 @@ status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& displayToken, Display return NO_ERROR; } -status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, - Vector<DisplayConfig>* configs) { - if (!displayToken || !configs) { +status_t SurfaceFlinger::getDisplayModes(const sp<IBinder>& displayToken, + Vector<ui::DisplayMode>* modes) { + if (!displayToken || !modes) { return BAD_VALUE; } @@ -900,16 +900,16 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, return NAME_NOT_FOUND; } - configs->clear(); + modes->clear(); - for (const auto& mode : display->getSupportedModes()) { - DisplayConfig config; + for (const auto& supportedMode : display->getSupportedModes()) { + ui::DisplayMode mode; - auto width = mode->getWidth(); - auto height = mode->getHeight(); + auto width = supportedMode->getWidth(); + auto height = supportedMode->getHeight(); - auto xDpi = mode->getDpiX(); - auto yDpi = mode->getDpiY(); + auto xDpi = supportedMode->getDpiX(); + auto yDpi = supportedMode->getDpiY(); if (display->isPrimary() && (internalDisplayOrientation == ui::ROTATION_90 || @@ -918,24 +918,24 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, std::swap(xDpi, yDpi); } - config.resolution = ui::Size(width, height); + mode.resolution = ui::Size(width, height); if (mEmulatedDisplayDensity) { - config.xDpi = mEmulatedDisplayDensity; - config.yDpi = mEmulatedDisplayDensity; + mode.xDpi = mEmulatedDisplayDensity; + mode.yDpi = mEmulatedDisplayDensity; } else { - config.xDpi = xDpi; - config.yDpi = yDpi; + mode.xDpi = xDpi; + mode.yDpi = yDpi; } - const nsecs_t period = mode->getVsyncPeriod(); - config.refreshRate = Fps::fromPeriodNsecs(period).getValue(); + const nsecs_t period = supportedMode->getVsyncPeriod(); + mode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); const auto vsyncConfigSet = - mVsyncConfiguration->getConfigsForRefreshRate(Fps(config.refreshRate)); - config.appVsyncOffset = vsyncConfigSet.late.appOffset; - config.sfVsyncOffset = vsyncConfigSet.late.sfOffset; - config.configGroup = mode->getConfigGroup(); + mVsyncConfiguration->getConfigsForRefreshRate(Fps(mode.refreshRate)); + mode.appVsyncOffset = vsyncConfigSet.late.appOffset; + mode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; + mode.group = supportedMode->getGroup(); // This is how far in advance a buffer must be queued for // presentation at a given time. If you want a buffer to appear @@ -949,9 +949,9 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken, // // We add an additional 1ms to allow for processing time and // differences between the ideal and actual refresh rate. - config.presentationDeadline = period - config.sfVsyncOffset + 1000000; + mode.presentationDeadline = period - mode.sfVsyncOffset + 1000000; - configs->push_back(config); + modes->push_back(mode); } return NO_ERROR; @@ -966,15 +966,15 @@ status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>&, DisplayStatInfo* st return NO_ERROR; } -int SurfaceFlinger::getActiveConfig(const sp<IBinder>& displayToken) { - int activeConfig; +int SurfaceFlinger::getActiveDisplayModeId(const sp<IBinder>& displayToken) { + int activeMode; bool isPrimary; { Mutex::Autolock lock(mStateLock); if (const auto display = getDisplayDeviceLocked(displayToken)) { - activeConfig = display->getActiveMode()->getId().value(); + activeMode = display->getActiveMode()->getId().value(); isPrimary = display->isPrimary(); } else { ALOGE("%s: Invalid display token %p", __FUNCTION__, displayToken.get()); @@ -983,36 +983,35 @@ int SurfaceFlinger::getActiveConfig(const sp<IBinder>& displayToken) { } if (isPrimary) { - if (const auto config = getDesiredActiveConfig()) { - return config->configId.value(); + if (const auto mode = getDesiredActiveMode()) { + return mode->modeId.value(); } } - return activeConfig; + return activeMode; } -void SurfaceFlinger::setDesiredActiveConfig(const ActiveConfigInfo& info) { +void SurfaceFlinger::setDesiredActiveMode(const ActiveModeInfo& info) { ATRACE_CALL(); - auto refreshRate = mRefreshRateConfigs->getRefreshRateFromConfigId(info.configId); - ALOGV("setDesiredActiveConfig(%s)", refreshRate.getName().c_str()); - - std::lock_guard<std::mutex> lock(mActiveConfigLock); - if (mDesiredActiveConfigChanged) { - // If a config change is pending, just cache the latest request in - // mDesiredActiveConfig - const Scheduler::ConfigEvent prevConfig = mDesiredActiveConfig.event; - mDesiredActiveConfig = info; - mDesiredActiveConfig.event = mDesiredActiveConfig.event | prevConfig; + auto refreshRate = mRefreshRateConfigs->getRefreshRateFromModeId(info.modeId); + ALOGV("%s(%s)", __func__, refreshRate.getName().c_str()); + + std::lock_guard<std::mutex> lock(mActiveModeLock); + if (mDesiredActiveModeChanged) { + // If a mode change is pending, just cache the latest request in mDesiredActiveMode + const Scheduler::ModeEvent prevConfig = mDesiredActiveMode.event; + mDesiredActiveMode = info; + mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig; } else { - // Check if we are already at the desired config + // Check if we are already at the desired mode const auto display = getDefaultDisplayDeviceLocked(); - if (!display || display->getActiveMode()->getId() == refreshRate.getConfigId()) { + if (!display || display->getActiveMode()->getId() == refreshRate.getModeId()) { return; } - // Initiate a config change. - mDesiredActiveConfigChanged = true; - mDesiredActiveConfig = info; + // Initiate a mode change. + mDesiredActiveModeChanged = true; + mDesiredActiveMode = info; // This will trigger HWC refresh without resetting the idle timer. repaintEverythingForHWC(); @@ -1024,7 +1023,7 @@ void SurfaceFlinger::setDesiredActiveConfig(const ActiveConfigInfo& info) { modulateVsync(&VsyncModulator::onRefreshRateChangeInitiated); updatePhaseConfiguration(refreshRate.getFps()); - mScheduler->setConfigChangePending(true); + mScheduler->setModeChangePending(true); } if (mRefreshRateOverlay) { @@ -1032,7 +1031,7 @@ void SurfaceFlinger::setDesiredActiveConfig(const ActiveConfigInfo& info) { } } -status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int modeId) { +status_t SurfaceFlinger::setActiveMode(const sp<IBinder>& displayToken, int modeId) { ATRACE_CALL(); if (!displayToken) { @@ -1042,13 +1041,13 @@ status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int mo auto future = schedule([=]() -> status_t { const auto display = ON_MAIN_THREAD(getDisplayDeviceLocked(displayToken)); if (!display) { - ALOGE("Attempt to set allowed display configs for invalid display token %p", + ALOGE("Attempt to set allowed display modes for invalid display token %p", displayToken.get()); return NAME_NOT_FOUND; } if (display->isVirtual()) { - ALOGW("Attempt to set allowed display configs for virtual display"); + ALOGW("Attempt to set allowed display modes for virtual display"); return INVALID_OPERATION; } @@ -1067,13 +1066,13 @@ status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int mo {fps, fps}}; constexpr bool kOverridePolicy = false; - return setDesiredDisplayConfigSpecsInternal(display, policy, kOverridePolicy); + return setDesiredDisplayModeSpecsInternal(display, policy, kOverridePolicy); }); return future.get(); } -void SurfaceFlinger::setActiveConfigInternal() { +void SurfaceFlinger::setActiveModeInternal() { ATRACE_CALL(); const auto display = getDefaultDisplayDeviceLocked(); @@ -1081,21 +1080,21 @@ void SurfaceFlinger::setActiveConfigInternal() { return; } - const auto upcomingConfig = display->getMode(mUpcomingActiveConfig.configId); - if (!upcomingConfig) { - ALOGW("Upcoming active config is no longer supported. ConfigId = %zu", - mUpcomingActiveConfig.configId.value()); + const auto upcomingMode = display->getMode(mUpcomingActiveMode.modeId); + if (!upcomingMode) { + ALOGW("Upcoming active mode is no longer supported. Mode ID = %zu", + mUpcomingActiveMode.modeId.value()); // TODO(b/159590486) Handle the error better. Some parts of SurfaceFlinger may - // have been already updated with the upcoming active config. + // have been already updated with the upcoming active mode. return; } const Fps oldRefreshRate = display->getActiveMode()->getFps(); - std::lock_guard<std::mutex> lock(mActiveConfigLock); - mRefreshRateConfigs->setCurrentConfigId(mUpcomingActiveConfig.configId); - display->setActiveMode(mUpcomingActiveConfig.configId); + std::lock_guard<std::mutex> lock(mActiveModeLock); + mRefreshRateConfigs->setCurrentModeId(mUpcomingActiveMode.modeId); + display->setActiveMode(mUpcomingActiveMode.modeId); - const Fps refreshRate = upcomingConfig->getFps(); + const Fps refreshRate = upcomingMode->getFps(); mRefreshRateStats->setRefreshRate(refreshRate); @@ -1105,71 +1104,71 @@ void SurfaceFlinger::setActiveConfigInternal() { updatePhaseConfiguration(refreshRate); ATRACE_INT("ActiveConfigFPS", refreshRate.getValue()); - if (mUpcomingActiveConfig.event != Scheduler::ConfigEvent::None) { + if (mUpcomingActiveMode.event != Scheduler::ModeEvent::None) { const nsecs_t vsyncPeriod = refreshRate.getPeriodNsecs(); const auto physicalId = display->getPhysicalId(); - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, physicalId, - mUpcomingActiveConfig.configId, vsyncPeriod); + mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, physicalId, + mUpcomingActiveMode.modeId, vsyncPeriod); } } -void SurfaceFlinger::clearDesiredActiveConfigState() { - std::lock_guard<std::mutex> lock(mActiveConfigLock); - mDesiredActiveConfig.event = Scheduler::ConfigEvent::None; - mDesiredActiveConfigChanged = false; - mScheduler->setConfigChangePending(false); +void SurfaceFlinger::clearDesiredActiveModeState() { + std::lock_guard<std::mutex> lock(mActiveModeLock); + mDesiredActiveMode.event = Scheduler::ModeEvent::None; + mDesiredActiveModeChanged = false; + mScheduler->setModeChangePending(false); } -void SurfaceFlinger::desiredActiveConfigChangeDone() { - const auto modeId = getDesiredActiveConfig()->configId; +void SurfaceFlinger::desiredActiveModeChangeDone() { + const auto modeId = getDesiredActiveMode()->modeId; - clearDesiredActiveConfigState(); + clearDesiredActiveModeState(); const auto refreshRate = getDefaultDisplayDeviceLocked()->getMode(modeId)->getFps(); mScheduler->resyncToHardwareVsync(true, refreshRate.getPeriodNsecs()); updatePhaseConfiguration(refreshRate); } -void SurfaceFlinger::performSetActiveConfig() { +void SurfaceFlinger::performSetActiveMode() { ATRACE_CALL(); ALOGV("%s", __FUNCTION__); // Store the local variable to release the lock. - const auto desiredActiveConfig = getDesiredActiveConfig(); - if (!desiredActiveConfig) { - // No desired active config pending to be applied + const auto desiredActiveMode = getDesiredActiveMode(); + if (!desiredActiveMode) { + // No desired active mode pending to be applied return; } const auto display = getDefaultDisplayDeviceLocked(); - const auto desiredConfig = display->getMode(desiredActiveConfig->configId); - if (!desiredConfig) { - ALOGW("Desired display config is no longer supported. Config ID = %zu", - desiredActiveConfig->configId.value()); - clearDesiredActiveConfigState(); + const auto desiredMode = display->getMode(desiredActiveMode->modeId); + if (!desiredMode) { + ALOGW("Desired display mode is no longer supported. Mode ID = %zu", + desiredActiveMode->modeId.value()); + clearDesiredActiveModeState(); return; } - const auto refreshRate = desiredConfig->getFps(); - ALOGV("performSetActiveConfig changing active config to %zu(%s)", - desiredConfig->getId().value(), to_string(refreshRate).c_str()); + const auto refreshRate = desiredMode->getFps(); + ALOGV("%s changing active mode to %zu(%s)", __FUNCTION__, desiredMode->getId().value(), + to_string(refreshRate).c_str()); - if (!display || display->getActiveMode()->getId() == desiredActiveConfig->configId) { + if (!display || display->getActiveMode()->getId() == desiredActiveMode->modeId) { // display is not valid or we are already in the requested mode // on both cases there is nothing left to do - desiredActiveConfigChangeDone(); + desiredActiveModeChangeDone(); return; } - // Desired active config was set, it is different than the config currently in use, however - // allowed configs might have changed by the time we process the refresh. - // Make sure the desired config is still allowed - if (!isDisplayConfigAllowed(desiredActiveConfig->configId)) { - desiredActiveConfigChangeDone(); + // Desired active mode was set, it is different than the mode currently in use, however + // allowed modes might have changed by the time we process the refresh. + // Make sure the desired mode is still allowed + if (!isDisplayModeAllowed(desiredActiveMode->modeId)) { + desiredActiveModeChangeDone(); return; } - mUpcomingActiveConfig = *desiredActiveConfig; + mUpcomingActiveMode = *desiredActiveMode; - ATRACE_INT("ActiveConfigFPS_HWC", refreshRate.getValue()); + ATRACE_INT("ActiveModeFPS_HWC", refreshRate.getValue()); // TODO(b/142753666) use constrains hal::VsyncPeriodChangeConstraints constraints; @@ -1178,7 +1177,7 @@ void SurfaceFlinger::performSetActiveConfig() { hal::VsyncPeriodChangeTimeline outTimeline; const auto status = - display->initiateModeChange(mUpcomingActiveConfig.configId, constraints, &outTimeline); + display->initiateModeChange(mUpcomingActiveMode.modeId, constraints, &outTimeline); if (status != NO_ERROR) { // initiateModeChange may fail if a hotplug event is just about // to be sent. We just log the error in this case. @@ -1188,7 +1187,7 @@ void SurfaceFlinger::performSetActiveConfig() { mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); // Scheduler will submit an empty frame to HWC if needed. - mSetActiveConfigPending = true; + mSetActiveModePending = true; } status_t SurfaceFlinger::getDisplayColorModes(const sp<IBinder>& displayToken, @@ -1627,12 +1626,12 @@ void SurfaceFlinger::getCompositorTiming(CompositorTiming* compositorTiming) { *compositorTiming = getBE().mCompositorTiming; } -bool SurfaceFlinger::isDisplayConfigAllowed(DisplayModeId configId) const { - return mRefreshRateConfigs->isConfigAllowed(configId); +bool SurfaceFlinger::isDisplayModeAllowed(DisplayModeId modeId) const { + return mRefreshRateConfigs->isModeAllowed(modeId); } void SurfaceFlinger::changeRefreshRateLocked(const RefreshRate& refreshRate, - Scheduler::ConfigEvent event) { + Scheduler::ModeEvent event) { const auto display = getDefaultDisplayDeviceLocked(); if (!display || mBootStage != BootStage::FINISHED) { return; @@ -1640,13 +1639,13 @@ void SurfaceFlinger::changeRefreshRateLocked(const RefreshRate& refreshRate, ATRACE_CALL(); // Don't do any updating if the current fps is the same as the new one. - if (!isDisplayConfigAllowed(refreshRate.getConfigId())) { - ALOGV("Skipping config %zu as it is not part of allowed configs", - refreshRate.getConfigId().value()); + if (!isDisplayModeAllowed(refreshRate.getModeId())) { + ALOGV("Skipping mode %zu as it is not part of allowed modes", + refreshRate.getModeId().value()); return; } - setDesiredActiveConfig({refreshRate.getConfigId(), event}); + setDesiredActiveMode({refreshRate.getModeId(), event}); } void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId, @@ -1829,18 +1828,18 @@ void SurfaceFlinger::onMessageInvalidate(int64_t vsyncId, nsecs_t expectedVSyncT mGpuFrameMissedCount++; } - // If we are in the middle of a config change and the fence hasn't + // If we are in the middle of a mode change and the fence hasn't // fired yet just wait for the next invalidate - if (mSetActiveConfigPending) { + if (mSetActiveModePending) { if (framePending) { mEventQueue->invalidate(); return; } // We received the present fence from the HWC, so we assume it successfully updated - // the config, hence we update SF. - mSetActiveConfigPending = false; - ON_MAIN_THREAD(setActiveConfigInternal()); + // the mode, hence we update SF. + mSetActiveModePending = false; + ON_MAIN_THREAD(setActiveModeInternal()); } if (framePending) { @@ -1920,7 +1919,7 @@ void SurfaceFlinger::onMessageInvalidate(int64_t vsyncId, nsecs_t expectedVSyncT mScheduler->chooseRefreshRateForContent(); } - ON_MAIN_THREAD(performSetActiveConfig()); + ON_MAIN_THREAD(performSetActiveMode()); updateCursorAsync(); updateInputFlinger(); @@ -2195,8 +2194,8 @@ void SurfaceFlinger::postComposition() { } }); - mTransactionCompletedThread.addPresentFence(mPreviousPresentFences[0]); - mTransactionCompletedThread.sendCallbacks(); + mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0]); + mTransactionCallbackInvoker.sendCallbacks(); if (display && display->isPrimary() && display->getPowerMode() == hal::PowerMode::ON && presentFenceTime->isValid()) { @@ -2370,7 +2369,7 @@ DisplayModes SurfaceFlinger::loadSupportedDisplayModes(PhysicalDisplayId display .setVsyncPeriod(hwcMode.vsyncPeriod) .setDpiX(hwcMode.dpiX) .setDpiY(hwcMode.dpiY) - .setConfigGroup(hwcMode.configGroup) + .setGroup(hwcMode.configGroup) .build()); } return modes; @@ -2391,7 +2390,7 @@ void SurfaceFlinger::processDisplayHotplugEventsLocked() { if (event.connection == hal::Connection::CONNECTED) { auto supportedModes = loadSupportedDisplayModes(displayId); const auto activeModeHwcId = getHwComposer().getActiveMode(displayId); - LOG_ALWAYS_FATAL_IF(!activeModeHwcId, "HWC returned no active config"); + LOG_ALWAYS_FATAL_IF(!activeModeHwcId, "HWC returned no active mode"); const auto activeMode = *std::find_if(supportedModes.begin(), supportedModes.end(), [activeModeHwcId](const DisplayModePtr& mode) { @@ -2675,9 +2674,8 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, // TODO(b/175678251) Call a listener instead. if (currentState.physical->hwcDisplayId == getHwComposer().getInternalHwcDisplayId()) { - mRefreshRateConfigs - ->updateDisplayConfigs(currentState.physical->supportedModes, - currentState.physical->activeMode->getId()); + mRefreshRateConfigs->updateDisplayModes(currentState.physical->supportedModes, + currentState.physical->activeMode->getId()); mVsyncConfiguration->reset(); updatePhaseConfiguration(mRefreshRateConfigs->getCurrentRefreshRate().getFps()); if (mRefreshRateOverlay) { @@ -2935,8 +2933,7 @@ void SurfaceFlinger::updateCursorAsync() { mCompositionEngine->updateCursorAsync(refreshArgs); } -void SurfaceFlinger::changeRefreshRate(const RefreshRate& refreshRate, - Scheduler::ConfigEvent event) { +void SurfaceFlinger::changeRefreshRate(const RefreshRate& refreshRate, Scheduler::ModeEvent event) { // If this is called from the main thread mStateLock must be locked before // Currently the only way to call this function from the main thread is from // Scheduler::chooseRefreshRateForContent @@ -2996,16 +2993,16 @@ void SurfaceFlinger::initScheduler(const DisplayDeviceState& displayState) { mRegionSamplingThread = new RegionSamplingThread(*this, *mScheduler, RegionSamplingThread::EnvironmentTimingTunables()); - // Dispatch a config change request for the primary display on scheduler + // Dispatch a mode change request for the primary display on scheduler // initialization, so that the EventThreads always contain a reference to a // prior configuration. // // This is a bit hacky, but this avoids a back-pointer into the main SF // classes from EventThread, and there should be no run-time binder cost // anyway since there are no connected apps at this point. - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, displayId, - displayState.physical->activeMode->getId(), - vsyncPeriod); + mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, displayId, + displayState.physical->activeMode->getId(), + vsyncPeriod); static auto ignorePresentFences = base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false); mScheduler->setIgnorePresentFences( @@ -3555,8 +3552,8 @@ void SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin // that listeners with SurfaceControls will start registration during setClientStateLocked // below. for (const auto& listener : listenerCallbacks) { - mTransactionCompletedThread.startRegistration(listener); - mTransactionCompletedThread.endRegistration(listener); + mTransactionCallbackInvoker.startRegistration(listener); + mTransactionCallbackInvoker.endRegistration(listener); } std::unordered_set<ListenerCallbacks, ListenerCallbacksHash> listenerCallbacksWithSurfaces; @@ -3575,12 +3572,12 @@ void SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin } for (const auto& listenerCallback : listenerCallbacksWithSurfaces) { - mTransactionCompletedThread.endRegistration(listenerCallback); + mTransactionCallbackInvoker.endRegistration(listenerCallback); } // If the state doesn't require a traversal and there are callbacks, send them now if (!(clientStateFlags & eTraversalNeeded) && hasListenerCallbacks) { - mTransactionCompletedThread.sendCallbacks(); + mTransactionCallbackInvoker.sendCallbacks(); } transactionFlags |= clientStateFlags; @@ -3695,7 +3692,7 @@ uint32_t SurfaceFlinger::setClientStateLocked( for (auto& listener : s.listeners) { // note that startRegistration will not re-register if the listener has // already be registered for a prior surface control - mTransactionCompletedThread.startRegistration(listener); + mTransactionCallbackInvoker.startRegistration(listener); listenerCallbacks.insert(listener); } @@ -3708,7 +3705,7 @@ uint32_t SurfaceFlinger::setClientStateLocked( } if (layer == nullptr) { for (auto& [listener, callbackIds] : s.listeners) { - mTransactionCompletedThread.registerUnpresentedCallbackHandle( + mTransactionCallbackInvoker.registerUnpresentedCallbackHandle( new CallbackHandle(listener, callbackIds, s.surface)); } return 0; @@ -4548,8 +4545,8 @@ void SurfaceFlinger::dumpVSync(std::string& result) const { mRefreshRateConfigs->dump(result); - StringAppendF(&result, "(config override by backdoor: %s)\n\n", - mDebugDisplayConfigSetByBackdoor ? "yes" : "no"); + StringAppendF(&result, "(mode override by backdoor: %s)\n\n", + mDebugDisplayModeSetByBackdoor ? "yes" : "no"); mScheduler->dump(mAppConnectionHandle, result); mScheduler->dumpVsync(result); @@ -4968,8 +4965,8 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case ENABLE_VSYNC_INJECTIONS: case GET_ANIMATION_FRAME_STATS: case GET_HDR_CAPABILITIES: - case SET_DESIRED_DISPLAY_CONFIG_SPECS: - case GET_DESIRED_DISPLAY_CONFIG_SPECS: + case SET_DESIRED_DISPLAY_MODE_SPECS: + case GET_DESIRED_DISPLAY_MODE_SPECS: case SET_ACTIVE_COLOR_MODE: case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: case SET_AUTO_LOW_LATENCY_MODE: @@ -5011,13 +5008,13 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // information, so it is OK to pass them. case AUTHENTICATE_SURFACE: case GET_ACTIVE_COLOR_MODE: - case GET_ACTIVE_CONFIG: + 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_DISPLAY_INFO: - case GET_DISPLAY_CONFIGS: + case GET_DISPLAY_MODES: case GET_DISPLAY_STATE: case GET_DISPLAY_STATS: case GET_SUPPORTED_FRAME_TIMESTAMPS: @@ -5038,8 +5035,9 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case CAPTURE_DISPLAY: case SET_DISPLAY_BRIGHTNESS: case SET_FRAME_TIMELINE_INFO: - // This is not sensitive information, so should not require permission control. - case GET_GPU_CONTEXT_PRIORITY: { + case GET_GPU_CONTEXT_PRIORITY: + case GET_EXTRA_BUFFER_COUNT: { + // This is not sensitive information, so should not require permission control. return OK; } case ADD_REGION_SAMPLING_LISTENER: @@ -5391,7 +5389,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } case 1035: { const int modeId = data.readInt32(); - mDebugDisplayConfigSetByBackdoor = false; + mDebugDisplayModeSetByBackdoor = false; const auto displayId = getInternalDisplayId(); if (!displayId) { @@ -5399,12 +5397,12 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return NO_ERROR; } - status_t result = setActiveConfig(getPhysicalDisplayToken(*displayId), modeId); + status_t result = setActiveMode(getPhysicalDisplayToken(*displayId), modeId); if (result != NO_ERROR) { return result; } - mDebugDisplayConfigSetByBackdoor = true; + mDebugDisplayModeSetByBackdoor = true; return NO_ERROR; } @@ -5483,14 +5481,13 @@ void SurfaceFlinger::kernelTimerChanged(bool expired) { // Update the overlay on the main thread to avoid race conditions with // mRefreshRateConfigs->getCurrentRefreshRate() static_cast<void>(schedule([=] { - const auto desiredActiveConfig = getDesiredActiveConfig(); - const std::optional<DisplayModeId> desiredConfigId = desiredActiveConfig - ? std::make_optional(desiredActiveConfig->configId) - : std::nullopt; + const auto desiredActiveMode = getDesiredActiveMode(); + const std::optional<DisplayModeId> desiredModeId = + desiredActiveMode ? std::make_optional(desiredActiveMode->modeId) : std::nullopt; const bool timerExpired = mKernelIdleTimerEnabled && expired; const auto newRefreshRate = - mRefreshRateConfigs->onKernelTimerChanged(desiredConfigId, timerExpired); + mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired); if (newRefreshRate) { if (Mutex::Autolock lock(mStateLock); mRefreshRateOverlay) { mRefreshRateOverlay->changeRefreshRate(*newRefreshRate); @@ -6077,7 +6074,7 @@ void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const } } -status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( +status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( const sp<DisplayDevice>& display, const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) { Mutex::Autolock lock(mStateLock); @@ -6087,10 +6084,10 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( LOG_ALWAYS_FATAL_IF(!policy && !overridePolicy, "Can only clear the override policy"); if (!display->isPrimary()) { - // TODO(b/144711714): For non-primary displays we should be able to set an active config + // TODO(b/144711714): For non-primary displays we should be able to set an active mode // as well. For now, just call directly to initiateModeChange but ideally - // it should go thru setDesiredActiveConfig, similar to primary display. - ALOGV("setAllowedDisplayConfigsInternal for non-primary display"); + // it should go thru setDesiredActiveMode, similar to primary display. + ALOGV("%s for non-primary display", __func__); const auto displayId = display->getPhysicalId(); hal::VsyncPeriodChangeConstraints constraints; @@ -6098,23 +6095,22 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( constraints.seamlessRequired = false; hal::VsyncPeriodChangeTimeline timeline = {0, 0, 0}; - if (display->initiateModeChange(policy->defaultConfig, constraints, &timeline) != - NO_ERROR) { + if (display->initiateModeChange(policy->defaultMode, constraints, &timeline) != NO_ERROR) { return BAD_VALUE; } if (timeline.refreshRequired) { repaintEverythingForHWC(); } - display->setActiveMode(policy->defaultConfig); - const nsecs_t vsyncPeriod = display->getMode(policy->defaultConfig)->getVsyncPeriod(); - mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle, displayId, - policy->defaultConfig, vsyncPeriod); + display->setActiveMode(policy->defaultMode); + const nsecs_t vsyncPeriod = display->getMode(policy->defaultMode)->getVsyncPeriod(); + mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, displayId, + policy->defaultMode, vsyncPeriod); return NO_ERROR; } - if (mDebugDisplayConfigSetByBackdoor) { - // ignore this request as config is overridden by backdoor + if (mDebugDisplayModeSetByBackdoor) { + // ignore this request as mode is overridden by backdoor return NO_ERROR; } @@ -6129,42 +6125,43 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( } scheduler::RefreshRateConfigs::Policy currentPolicy = mRefreshRateConfigs->getCurrentPolicy(); - ALOGV("Setting desired display config specs: %s", currentPolicy.toString().c_str()); + ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might // be depending in this callback. - const auto activeConfig = display->getActiveMode(); - const nsecs_t vsyncPeriod = activeConfig->getVsyncPeriod(); + const auto activeMode = display->getActiveMode(); + const nsecs_t vsyncPeriod = activeMode->getVsyncPeriod(); const auto physicalId = display->getPhysicalId(); - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, physicalId, - activeConfig->getId(), vsyncPeriod); + mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, physicalId, activeMode->getId(), + vsyncPeriod); toggleKernelIdleTimer(); - auto configId = mScheduler->getPreferredConfigId(); - auto preferredRefreshRate = configId - ? mRefreshRateConfigs->getRefreshRateFromConfigId(*configId) - // NOTE: Choose the default config ID, if Scheduler doesn't have one in mind. - : mRefreshRateConfigs->getRefreshRateFromConfigId(currentPolicy.defaultConfig); - ALOGV("trying to switch to Scheduler preferred config %zu (%s)", - preferredRefreshRate.getConfigId().value(), preferredRefreshRate.getName().c_str()); - - if (isDisplayConfigAllowed(preferredRefreshRate.getConfigId())) { - ALOGV("switching to Scheduler preferred config %zu", - preferredRefreshRate.getConfigId().value()); - setDesiredActiveConfig( - {preferredRefreshRate.getConfigId(), Scheduler::ConfigEvent::Changed}); + auto modeId = mScheduler->getPreferredModeId(); + auto preferredRefreshRate = modeId + ? mRefreshRateConfigs->getRefreshRateFromModeId(*modeId) + // NOTE: Choose the default mode ID, if Scheduler doesn't have one in mind. + : mRefreshRateConfigs->getRefreshRateFromModeId(currentPolicy.defaultMode); + ALOGV("trying to switch to Scheduler preferred mode %zu (%s)", + preferredRefreshRate.getModeId().value(), preferredRefreshRate.getName().c_str()); + + if (isDisplayModeAllowed(preferredRefreshRate.getModeId())) { + ALOGV("switching to Scheduler preferred display mode %zu", + preferredRefreshRate.getModeId().value()); + setDesiredActiveMode({preferredRefreshRate.getModeId(), Scheduler::ModeEvent::Changed}); } else { - LOG_ALWAYS_FATAL("Desired config not allowed: %zu", - preferredRefreshRate.getConfigId().value()); + LOG_ALWAYS_FATAL("Desired display mode not allowed: %zu", + preferredRefreshRate.getModeId().value()); } return NO_ERROR; } -status_t SurfaceFlinger::setDesiredDisplayConfigSpecs( - const sp<IBinder>& displayToken, int32_t defaultConfig, bool allowGroupSwitching, - float primaryRefreshRateMin, float primaryRefreshRateMax, float appRequestRefreshRateMin, - float appRequestRefreshRateMax) { +status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, + size_t defaultMode, bool allowGroupSwitching, + float primaryRefreshRateMin, + float primaryRefreshRateMax, + float appRequestRefreshRateMin, + float appRequestRefreshRateMax) { ATRACE_CALL(); if (!displayToken) { @@ -6174,34 +6171,34 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecs( auto future = schedule([=]() -> status_t { const auto display = ON_MAIN_THREAD(getDisplayDeviceLocked(displayToken)); if (!display) { - ALOGE("Attempt to set desired display configs for invalid display token %p", + ALOGE("Attempt to set desired display modes for invalid display token %p", displayToken.get()); return NAME_NOT_FOUND; } else if (display->isVirtual()) { - ALOGW("Attempt to set desired display configs for virtual display"); + ALOGW("Attempt to set desired display modes for virtual display"); return INVALID_OPERATION; } else { using Policy = scheduler::RefreshRateConfigs::Policy; - const Policy policy{DisplayModeId(defaultConfig), + const Policy policy{DisplayModeId(defaultMode), allowGroupSwitching, {Fps(primaryRefreshRateMin), Fps(primaryRefreshRateMax)}, {Fps(appRequestRefreshRateMin), Fps(appRequestRefreshRateMax)}}; constexpr bool kOverridePolicy = false; - return setDesiredDisplayConfigSpecsInternal(display, policy, kOverridePolicy); + return setDesiredDisplayModeSpecsInternal(display, policy, kOverridePolicy); } }); return future.get(); } -status_t SurfaceFlinger::getDesiredDisplayConfigSpecs( - const sp<IBinder>& displayToken, int32_t* outDefaultConfig, bool* outAllowGroupSwitching, +status_t SurfaceFlinger::getDesiredDisplayModeSpecs( + const sp<IBinder>& displayToken, size_t* outDefaultMode, bool* outAllowGroupSwitching, float* outPrimaryRefreshRateMin, float* outPrimaryRefreshRateMax, float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) { ATRACE_CALL(); - if (!displayToken || !outDefaultConfig || !outPrimaryRefreshRateMin || + if (!displayToken || !outDefaultMode || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax || !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) { return BAD_VALUE; } @@ -6215,7 +6212,7 @@ status_t SurfaceFlinger::getDesiredDisplayConfigSpecs( if (display->isPrimary()) { scheduler::RefreshRateConfigs::Policy policy = mRefreshRateConfigs->getDisplayManagerPolicy(); - *outDefaultConfig = policy.defaultConfig.value(); + *outDefaultMode = policy.defaultMode.value(); *outAllowGroupSwitching = policy.allowGroupSwitching; *outPrimaryRefreshRateMin = policy.primaryRange.min.getValue(); *outPrimaryRefreshRateMax = policy.primaryRange.max.getValue(); @@ -6226,7 +6223,7 @@ status_t SurfaceFlinger::getDesiredDisplayConfigSpecs( return INVALID_OPERATION; } else { const auto activeMode = display->getActiveMode(); - *outDefaultConfig = activeMode->getId().value(); + *outDefaultMode = activeMode->getId().value(); *outAllowGroupSwitching = false; auto vsyncPeriod = activeMode->getVsyncPeriod(); *outPrimaryRefreshRateMin = Fps::fromPeriodNsecs(vsyncPeriod).getValue(); @@ -6356,16 +6353,15 @@ status_t SurfaceFlinger::acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) const auto display = ON_MAIN_THREAD(getDefaultDisplayDeviceLocked()); // This is a little racy, but not in a way that hurts anything. As we grab the - // defaultConfig from the display manager policy, we could be setting a new display - // manager policy, leaving us using a stale defaultConfig. The defaultConfig doesn't + // defaultMode from the display manager policy, we could be setting a new display + // manager policy, leaving us using a stale defaultMode. The defaultMode doesn't // matter for the override policy though, since we set allowGroupSwitching to // true, so it's not a problem. scheduler::RefreshRateConfigs::Policy overridePolicy; - overridePolicy.defaultConfig = - mRefreshRateConfigs->getDisplayManagerPolicy().defaultConfig; + overridePolicy.defaultMode = mRefreshRateConfigs->getDisplayManagerPolicy().defaultMode; overridePolicy.allowGroupSwitching = true; constexpr bool kOverridePolicy = true; - result = setDesiredDisplayConfigSpecsInternal(display, overridePolicy, kOverridePolicy); + result = setDesiredDisplayModeSpecsInternal(display, overridePolicy, kOverridePolicy); } if (result == NO_ERROR) { @@ -6405,7 +6401,7 @@ void SurfaceFlinger::onFrameRateFlexibilityTokenReleased() { if (mFrameRateFlexibilityTokenCount == 0) { const auto display = ON_MAIN_THREAD(getDefaultDisplayDeviceLocked()); constexpr bool kOverridePolicy = true; - status_t result = setDesiredDisplayConfigSpecsInternal(display, {}, kOverridePolicy); + status_t result = setDesiredDisplayModeSpecsInternal(display, {}, kOverridePolicy); LOG_ALWAYS_FATAL_IF(result < 0, "Failed releasing frame rate flexibility token"); } })); @@ -6466,6 +6462,25 @@ int SurfaceFlinger::getGPUContextPriority() { return getRenderEngine().getContextPriority(); } +int SurfaceFlinger::calculateExtraBufferCount(Fps maxSupportedRefreshRate, + std::chrono::nanoseconds presentLatency) { + auto pipelineDepth = presentLatency.count() / maxSupportedRefreshRate.getPeriodNsecs(); + if (presentLatency.count() % maxSupportedRefreshRate.getPeriodNsecs()) { + pipelineDepth++; + } + return std::max(0ll, pipelineDepth - 2); +} + +status_t SurfaceFlinger::getExtraBufferCount(int* extraBuffers) const { + const auto maxSupportedRefreshRate = mRefreshRateConfigs->getSupportedRefreshRateRange().max; + const auto vsyncConfig = + mVsyncConfiguration->getConfigsForRefreshRate(maxSupportedRefreshRate).late; + const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; + + *extraBuffers = calculateExtraBufferCount(maxSupportedRefreshRate, presentLatency); + return NO_ERROR; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 400345f684..a62d0b9a95 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -64,7 +64,7 @@ #include "SurfaceFlingerFactory.h" #include "SurfaceTracing.h" #include "TracedOrdinal.h" -#include "TransactionCompletedThread.h" +#include "TransactionCallbackInvoker.h" #include <atomic> #include <cstdint> @@ -319,8 +319,8 @@ public: void removeFromOffscreenLayers(Layer* layer); - TransactionCompletedThread& getTransactionCompletedThread() { - return mTransactionCompletedThread; + TransactionCallbackInvoker& getTransactionCallbackInvoker() { + return mTransactionCallbackInvoker; } // Converts from a binder handle to a Layer @@ -414,12 +414,12 @@ private: void traverseInReverseZOrder(const LayerVector::Visitor& visitor) const; }; - struct ActiveConfigInfo { - DisplayModeId configId; - Scheduler::ConfigEvent event = Scheduler::ConfigEvent::None; + struct ActiveModeInfo { + DisplayModeId modeId; + Scheduler::ModeEvent event = Scheduler::ModeEvent::None; - bool operator!=(const ActiveConfigInfo& other) const { - return configId != other.configId || event != other.event; + bool operator!=(const ActiveModeInfo& other) const { + return modeId != other.modeId || event != other.event; } }; @@ -554,8 +554,8 @@ private: status_t getDisplayStats(const sp<IBinder>& displayToken, DisplayStatInfo* stats) override; status_t getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState*) override; status_t getDisplayInfo(const sp<IBinder>& displayToken, DisplayInfo*) override; - status_t getDisplayConfigs(const sp<IBinder>& displayToken, Vector<DisplayConfig>*) override; - int getActiveConfig(const sp<IBinder>& displayToken) override; + status_t getDisplayModes(const sp<IBinder>& displayToken, Vector<ui::DisplayMode>*) override; + int getActiveDisplayModeId(const sp<IBinder>& displayToken) override; status_t getDisplayColorModes(const sp<IBinder>& displayToken, Vector<ui::ColorMode>*) override; status_t getDisplayNativePrimaries(const sp<IBinder>& displayToken, ui::DisplayPrimaries&) override; @@ -594,17 +594,16 @@ private: status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener) override; status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) override; - status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, int32_t displayModeId, - bool allowGroupSwitching, float primaryRefreshRateMin, - float primaryRefreshRateMax, - float appRequestRefreshRateMin, - float appRequestRefreshRateMax) override; - status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, - int32_t* outDefaultConfig, bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax) override; + status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t displayModeId, + bool allowGroupSwitching, float primaryRefreshRateMin, + float primaryRefreshRateMax, float appRequestRefreshRateMin, + float appRequestRefreshRateMax) override; + status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, size_t* outDefaultMode, + bool* outAllowGroupSwitching, + float* outPrimaryRefreshRateMin, + float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, + float* outAppRequestRefreshRateMax) override; status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken, bool* outSupport) const override; status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) override; @@ -623,6 +622,8 @@ private: int getGPUContextPriority() override; + status_t getExtraBufferCount(int* extraBuffers) const override; + // Implements IBinder::DeathRecipient. void binderDied(const wp<IBinder>& who) override; @@ -649,7 +650,7 @@ private: // Toggles hardware VSYNC by calling into HWC. void setVsyncEnabled(bool) override; // Initiates a refresh rate change to be applied on invalidate. - void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ConfigEvent) override; + void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ModeEvent) override; // Forces full composition on all displays without resetting the scheduler idle timer. void repaintEverythingForHWC() override; // Called when kernel idle timer has expired. Used to update the refresh rate overlay. @@ -677,24 +678,24 @@ private: // Called on the main thread in response to initializeDisplays() void onInitializeDisplays() REQUIRES(mStateLock); - // Sets the desired active config bit. It obtains the lock, and sets mDesiredActiveConfig. - void setDesiredActiveConfig(const ActiveConfigInfo& info) REQUIRES(mStateLock); - status_t setActiveConfig(const sp<IBinder>& displayToken, int id); - // Once HWC has returned the present fence, this sets the active config and a new refresh + // Sets the desired active mode bit. It obtains the lock, and sets mDesiredActiveMode. + void setDesiredActiveMode(const ActiveModeInfo& info) REQUIRES(mStateLock); + status_t setActiveMode(const sp<IBinder>& displayToken, int id); + // Once HWC has returned the present fence, this sets the active mode and a new refresh // rate in SF. - void setActiveConfigInternal() REQUIRES(mStateLock); - // Calls to setActiveConfig on the main thread if there is a pending config + void setActiveModeInternal() REQUIRES(mStateLock); + // Calls to setActiveMode on the main thread if there is a pending mode change // that needs to be applied. - void performSetActiveConfig() REQUIRES(mStateLock); - void clearDesiredActiveConfigState() REQUIRES(mStateLock) EXCLUDES(mActiveConfigLock); - // Called when active config is no longer is progress - void desiredActiveConfigChangeDone() REQUIRES(mStateLock); + void performSetActiveMode() REQUIRES(mStateLock); + void clearDesiredActiveModeState() REQUIRES(mStateLock) EXCLUDES(mActiveModeLock); + // Called when active mode is no longer is progress + void desiredActiveModeChangeDone() REQUIRES(mStateLock); // Called on the main thread in response to setPowerMode() void setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) REQUIRES(mStateLock); - // Sets the desired display configs. - status_t setDesiredDisplayConfigSpecsInternal( + // Sets the desired display mode specs. + status_t setDesiredDisplayModeSpecsInternal( const sp<DisplayDevice>& display, const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) EXCLUDES(mStateLock); @@ -929,9 +930,9 @@ private: // Sets the refresh rate by switching active configs, if they are available for // the desired refresh rate. - void changeRefreshRateLocked(const RefreshRate&, Scheduler::ConfigEvent) REQUIRES(mStateLock); + void changeRefreshRateLocked(const RefreshRate&, Scheduler::ModeEvent) REQUIRES(mStateLock); - bool isDisplayConfigAllowed(DisplayModeId configId) const REQUIRES(mStateLock); + bool isDisplayModeAllowed(DisplayModeId) const REQUIRES(mStateLock); // Gets the fence for the previous frame. // Must be called on the main thread. @@ -1047,12 +1048,15 @@ private: * Misc */ - std::optional<ActiveConfigInfo> getDesiredActiveConfig() EXCLUDES(mActiveConfigLock) { - std::lock_guard<std::mutex> lock(mActiveConfigLock); - if (mDesiredActiveConfigChanged) return mDesiredActiveConfig; + std::optional<ActiveModeInfo> getDesiredActiveMode() EXCLUDES(mActiveModeLock) { + std::lock_guard<std::mutex> lock(mActiveModeLock); + if (mDesiredActiveModeChanged) return mDesiredActiveMode; return std::nullopt; } + static int calculateExtraBufferCount(Fps maxSupportedRefreshRate, + std::chrono::nanoseconds presentLatency); + sp<StartPropertySetThread> mStartPropertySetThread; surfaceflinger::Factory& mFactory; @@ -1161,7 +1165,7 @@ private: std::atomic<uint32_t> mHwcFrameMissedCount = 0; std::atomic<uint32_t> mGpuFrameMissedCount = 0; - TransactionCompletedThread mTransactionCompletedThread; + TransactionCallbackInvoker mTransactionCallbackInvoker; // Restrict layers to use two buffers in their bufferqueues. bool mLayerTripleBufferingDisabled = false; @@ -1246,18 +1250,18 @@ private: nsecs_t mScheduledPresentTime = 0; hal::Vsync mHWCVsyncPendingState = hal::Vsync::DISABLE; - std::mutex mActiveConfigLock; - // This bit is set once we start setting the config. We read from this bit during the - // process. If at the end, this bit is different than mDesiredActiveConfig, we restart + std::mutex mActiveModeLock; + // This bit is set once we start setting the mode. We read from this bit during the + // process. If at the end, this bit is different than mDesiredActiveMode, we restart // the process. - ActiveConfigInfo mUpcomingActiveConfig; // Always read and written on the main thread. - // This bit can be set at any point in time when the system wants the new config. - ActiveConfigInfo mDesiredActiveConfig GUARDED_BY(mActiveConfigLock); + ActiveModeInfo mUpcomingActiveMode; // Always read and written on the main thread. + // This bit can be set at any point in time when the system wants the new mode. + ActiveModeInfo mDesiredActiveMode GUARDED_BY(mActiveModeLock); // below flags are set by main thread only - TracedOrdinal<bool> mDesiredActiveConfigChanged - GUARDED_BY(mActiveConfigLock) = {"DesiredActiveConfigChanged", false}; - bool mSetActiveConfigPending = false; + TracedOrdinal<bool> mDesiredActiveModeChanged + GUARDED_BY(mActiveModeLock) = {"DesiredActiveModeChanged", false}; + bool mSetActiveModePending = false; bool mLumaSampling = true; sp<RegionSamplingThread> mRegionSamplingThread; @@ -1281,8 +1285,8 @@ private: void enableRefreshRateOverlay(bool enable); std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay GUARDED_BY(mStateLock); - // Flag used to set override allowed display configs from backdoor - bool mDebugDisplayConfigSetByBackdoor = false; + // Flag used to set override desired display mode from backdoor + bool mDebugDisplayModeSetByBackdoor = false; // A set of layers that have no parent so they are not drawn on screen. // Should only be accessed by the main thread. diff --git a/services/surfaceflinger/TransactionCompletedThread.cpp b/services/surfaceflinger/TransactionCallbackInvoker.cpp index 1797af4cf6..a78510e902 100644 --- a/services/surfaceflinger/TransactionCompletedThread.cpp +++ b/services/surfaceflinger/TransactionCallbackInvoker.cpp @@ -20,10 +20,10 @@ //#define LOG_NDEBUG 0 #undef LOG_TAG -#define LOG_TAG "TransactionCompletedThread" +#define LOG_TAG "TransactionCallbackInvoker" #define ATRACE_TAG ATRACE_TAG_GRAPHICS -#include "TransactionCompletedThread.h" +#include "TransactionCallbackInvoker.h" #include <cinttypes> @@ -45,19 +45,7 @@ static int compareCallbackIds(const std::vector<CallbackId>& c1, return c1.front() - c2.front(); } -TransactionCompletedThread::~TransactionCompletedThread() { - std::lock_guard lockThread(mThreadMutex); - - { - std::lock_guard lock(mMutex); - mKeepRunning = false; - mConditionVariable.notify_all(); - } - - if (mThread.joinable()) { - mThread.join(); - } - +TransactionCallbackInvoker::~TransactionCallbackInvoker() { { std::lock_guard lock(mMutex); for (const auto& [listener, transactionStats] : mCompletedTransactions) { @@ -66,26 +54,8 @@ TransactionCompletedThread::~TransactionCompletedThread() { } } -void TransactionCompletedThread::run() { +status_t TransactionCallbackInvoker::startRegistration(const ListenerCallbacks& listenerCallbacks) { std::lock_guard lock(mMutex); - if (mRunning || !mKeepRunning) { - return; - } - mDeathRecipient = new ThreadDeathRecipient(); - mRunning = true; - - std::lock_guard lockThread(mThreadMutex); - mThread = std::thread(&TransactionCompletedThread::threadMain, this); -} - -status_t TransactionCompletedThread::startRegistration(const ListenerCallbacks& listenerCallbacks) { - // begin running if not already running - run(); - std::lock_guard lock(mMutex); - if (!mRunning) { - ALOGE("cannot add callback because the callback thread isn't running"); - return BAD_VALUE; - } auto [itr, inserted] = mRegisteringTransactions.insert(listenerCallbacks); auto& [listener, callbackIds] = listenerCallbacks; @@ -105,12 +75,8 @@ status_t TransactionCompletedThread::startRegistration(const ListenerCallbacks& return NO_ERROR; } -status_t TransactionCompletedThread::endRegistration(const ListenerCallbacks& listenerCallbacks) { +status_t TransactionCallbackInvoker::endRegistration(const ListenerCallbacks& listenerCallbacks) { std::lock_guard lock(mMutex); - if (!mRunning) { - ALOGE("cannot add callback because the callback thread isn't running"); - return BAD_VALUE; - } auto itr = mRegisteringTransactions.find(listenerCallbacks); if (itr == mRegisteringTransactions.end()) { @@ -123,7 +89,7 @@ status_t TransactionCompletedThread::endRegistration(const ListenerCallbacks& li return NO_ERROR; } -bool TransactionCompletedThread::isRegisteringTransaction( +bool TransactionCallbackInvoker::isRegisteringTransaction( const sp<IBinder>& transactionListener, const std::vector<CallbackId>& callbackIds) { ListenerCallbacks listenerCallbacks(transactionListener, callbackIds); @@ -131,13 +97,9 @@ bool TransactionCompletedThread::isRegisteringTransaction( return itr != mRegisteringTransactions.end(); } -status_t TransactionCompletedThread::registerPendingCallbackHandle( +status_t TransactionCallbackInvoker::registerPendingCallbackHandle( const sp<CallbackHandle>& handle) { std::lock_guard lock(mMutex); - if (!mRunning) { - ALOGE("cannot register callback handle because the callback thread isn't running"); - return BAD_VALUE; - } // If we can't find the transaction stats something has gone wrong. The client should call // startRegistration before trying to register a pending callback handle. @@ -152,16 +114,12 @@ status_t TransactionCompletedThread::registerPendingCallbackHandle( return NO_ERROR; } -status_t TransactionCompletedThread::finalizePendingCallbackHandles( +status_t TransactionCallbackInvoker::finalizePendingCallbackHandles( const std::deque<sp<CallbackHandle>>& handles, const std::vector<JankData>& jankData) { if (handles.empty()) { return NO_ERROR; } std::lock_guard lock(mMutex); - if (!mRunning) { - ALOGE("cannot add presented callback handle because the callback thread isn't running"); - return BAD_VALUE; - } for (const auto& handle : handles) { auto listener = mPendingTransactions.find(handle->listener); @@ -196,18 +154,14 @@ status_t TransactionCompletedThread::finalizePendingCallbackHandles( return NO_ERROR; } -status_t TransactionCompletedThread::registerUnpresentedCallbackHandle( +status_t TransactionCallbackInvoker::registerUnpresentedCallbackHandle( const sp<CallbackHandle>& handle) { std::lock_guard lock(mMutex); - if (!mRunning) { - ALOGE("cannot add unpresented callback handle because the callback thread isn't running"); - return BAD_VALUE; - } return addCallbackHandle(handle, std::vector<JankData>()); } -status_t TransactionCompletedThread::findTransactionStats( +status_t TransactionCallbackInvoker::findTransactionStats( const sp<IBinder>& listener, const std::vector<CallbackId>& callbackIds, TransactionStats** outTransactionStats) { auto& transactionStatsDeque = mCompletedTransactions[listener]; @@ -225,7 +179,7 @@ status_t TransactionCompletedThread::findTransactionStats( return BAD_VALUE; } -status_t TransactionCompletedThread::addCallbackHandle(const sp<CallbackHandle>& handle, +status_t TransactionCallbackInvoker::addCallbackHandle(const sp<CallbackHandle>& handle, const std::vector<JankData>& jankData) { // If we can't find the transaction stats something has gone wrong. The client should call // startRegistration before trying to add a callback handle. @@ -252,111 +206,83 @@ status_t TransactionCompletedThread::addCallbackHandle(const sp<CallbackHandle>& return NO_ERROR; } -void TransactionCompletedThread::addPresentFence(const sp<Fence>& presentFence) { +void TransactionCallbackInvoker::addPresentFence(const sp<Fence>& presentFence) { std::lock_guard<std::mutex> lock(mMutex); mPresentFence = presentFence; } -void TransactionCompletedThread::sendCallbacks() { +void TransactionCallbackInvoker::sendCallbacks() { std::lock_guard lock(mMutex); - if (mRunning) { - mConditionVariable.notify_all(); - } -} -void TransactionCompletedThread::threadMain() { - std::lock_guard lock(mMutex); + // For each listener + auto completedTransactionsItr = mCompletedTransactions.begin(); + while (completedTransactionsItr != mCompletedTransactions.end()) { + auto& [listener, transactionStatsDeque] = *completedTransactionsItr; + ListenerStats listenerStats; + listenerStats.listener = listener; + + // For each transaction + auto transactionStatsItr = transactionStatsDeque.begin(); + while (transactionStatsItr != transactionStatsDeque.end()) { + auto& transactionStats = *transactionStatsItr; + + // If this transaction is still registering, it is not safe to send a callback + // because there could be surface controls that haven't been added to + // transaction stats or mPendingTransactions. + if (isRegisteringTransaction(listener, transactionStats.callbackIds)) { + break; + } - while (mKeepRunning) { - mConditionVariable.wait(mMutex); - std::vector<ListenerStats> completedListenerStats; - - // For each listener - auto completedTransactionsItr = mCompletedTransactions.begin(); - while (completedTransactionsItr != mCompletedTransactions.end()) { - auto& [listener, transactionStatsDeque] = *completedTransactionsItr; - ListenerStats listenerStats; - listenerStats.listener = listener; - - // For each transaction - auto transactionStatsItr = transactionStatsDeque.begin(); - while (transactionStatsItr != transactionStatsDeque.end()) { - auto& transactionStats = *transactionStatsItr; - - // If this transaction is still registering, it is not safe to send a callback - // because there could be surface controls that haven't been added to - // transaction stats or mPendingTransactions. - if (isRegisteringTransaction(listener, transactionStats.callbackIds)) { - break; - } + // If we are still waiting on the callback handles for this transaction, stop + // here because all transaction callbacks for the same listener must come in order + auto pendingTransactions = mPendingTransactions.find(listener); + if (pendingTransactions != mPendingTransactions.end() && + pendingTransactions->second.count(transactionStats.callbackIds) != 0) { + break; + } - // If we are still waiting on the callback handles for this transaction, stop - // here because all transaction callbacks for the same listener must come in order - auto pendingTransactions = mPendingTransactions.find(listener); - if (pendingTransactions != mPendingTransactions.end() && - pendingTransactions->second.count(transactionStats.callbackIds) != 0) { + // If the transaction has been latched + if (transactionStats.latchTime >= 0) { + if (!mPresentFence) { break; } - - // If the transaction has been latched - if (transactionStats.latchTime >= 0) { - if (!mPresentFence) { - break; - } - transactionStats.presentFence = mPresentFence; - } - - // Remove the transaction from completed to the callback - listenerStats.transactionStats.push_back(std::move(transactionStats)); - transactionStatsItr = transactionStatsDeque.erase(transactionStatsItr); + transactionStats.presentFence = mPresentFence; } - // If the listener has completed transactions - if (!listenerStats.transactionStats.empty()) { - // If the listener is still alive - if (listener->isBinderAlive()) { - // Send callback. The listener stored in listenerStats - // comes from the cross-process setTransactionState call to - // SF. This MUST be an ITransactionCompletedListener. We - // keep it as an IBinder due to consistency reasons: if we - // interface_cast at the IPC boundary when reading a Parcel, - // we get pointers that compare unequal in the SF process. - interface_cast<ITransactionCompletedListener>(listenerStats.listener) - ->onTransactionCompleted(listenerStats); - if (transactionStatsDeque.empty()) { - listener->unlinkToDeath(mDeathRecipient); - completedTransactionsItr = - mCompletedTransactions.erase(completedTransactionsItr); - } else { - completedTransactionsItr++; - } - } else { + + // Remove the transaction from completed to the callback + listenerStats.transactionStats.push_back(std::move(transactionStats)); + transactionStatsItr = transactionStatsDeque.erase(transactionStatsItr); + } + // If the listener has completed transactions + if (!listenerStats.transactionStats.empty()) { + // If the listener is still alive + if (listener->isBinderAlive()) { + // Send callback. The listener stored in listenerStats + // comes from the cross-process setTransactionState call to + // SF. This MUST be an ITransactionCompletedListener. We + // keep it as an IBinder due to consistency reasons: if we + // interface_cast at the IPC boundary when reading a Parcel, + // we get pointers that compare unequal in the SF process. + interface_cast<ITransactionCompletedListener>(listenerStats.listener) + ->onTransactionCompleted(listenerStats); + if (transactionStatsDeque.empty()) { + listener->unlinkToDeath(mDeathRecipient); completedTransactionsItr = mCompletedTransactions.erase(completedTransactionsItr); + } else { + completedTransactionsItr++; } } else { - completedTransactionsItr++; + completedTransactionsItr = + mCompletedTransactions.erase(completedTransactionsItr); } - - completedListenerStats.push_back(std::move(listenerStats)); - } - - if (mPresentFence) { - mPresentFence.clear(); + } else { + completedTransactionsItr++; } + } - // If everyone else has dropped their reference to a layer and its listener is dead, - // we are about to cause the layer to be deleted. If this happens at the wrong time and - // we are holding mMutex, we will cause a deadlock. - // - // The deadlock happens because this thread is holding on to mMutex and when we delete - // the layer, it grabs SF's mStateLock. A different SF binder thread grabs mStateLock, - // then call's TransactionCompletedThread::run() which tries to grab mMutex. - // - // To avoid this deadlock, we need to unlock mMutex when dropping our last reference to - // to the layer. - mMutex.unlock(); - completedListenerStats.clear(); - mMutex.lock(); + if (mPresentFence) { + mPresentFence.clear(); } } diff --git a/services/surfaceflinger/TransactionCompletedThread.h b/services/surfaceflinger/TransactionCallbackInvoker.h index c4ba7e49ce..a240c824a1 100644 --- a/services/surfaceflinger/TransactionCompletedThread.h +++ b/services/surfaceflinger/TransactionCallbackInvoker.h @@ -52,11 +52,9 @@ public: uint64_t frameNumber = 0; }; -class TransactionCompletedThread { +class TransactionCallbackInvoker { public: - ~TransactionCompletedThread(); - - void run(); + ~TransactionCallbackInvoker(); // Adds listener and callbackIds in case there are no SurfaceControls that are supposed // to be included in the callback. This functions should be call before attempting to register @@ -66,13 +64,13 @@ public: // It is safe to send a callback if the Transaction doesn't have any Pending callback handles. status_t endRegistration(const ListenerCallbacks& listenerCallbacks); - // Informs the TransactionCompletedThread that there is a Transaction with a CallbackHandle + // Informs the TransactionCallbackInvoker that there is a Transaction with a CallbackHandle // that needs to be latched and presented this frame. This function should be called once the - // layer has received the CallbackHandle so the TransactionCompletedThread knows not to send + // layer has received the CallbackHandle so the TransactionCallbackInvoker knows not to send // a callback for that Listener/Transaction pair until that CallbackHandle has been latched and // presented. status_t registerPendingCallbackHandle(const sp<CallbackHandle>& handle); - // Notifies the TransactionCompletedThread that a pending CallbackHandle has been presented. + // Notifies the TransactionCallbackInvoker that a pending CallbackHandle has been presented. status_t finalizePendingCallbackHandles(const std::deque<sp<CallbackHandle>>& handles, const std::vector<JankData>& jankData); @@ -85,7 +83,6 @@ public: void sendCallbacks(); private: - void threadMain(); bool isRegisteringTransaction(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& callbackIds) REQUIRES(mMutex); @@ -97,7 +94,7 @@ private: status_t addCallbackHandle(const sp<CallbackHandle>& handle, const std::vector<JankData>& jankData) REQUIRES(mMutex); - class ThreadDeathRecipient : public IBinder::DeathRecipient { + class CallbackDeathRecipient : public IBinder::DeathRecipient { public: // This function is a no-op. isBinderAlive needs a linked DeathRecipient to work. // Death recipients needs a binderDied function. @@ -106,12 +103,8 @@ private: // sendObituary is only called if linkToDeath was called with a DeathRecipient.) void binderDied(const wp<IBinder>& /*who*/) override {} }; - sp<ThreadDeathRecipient> mDeathRecipient; - - // Protects the creation and destruction of mThread - std::mutex mThreadMutex; - - std::thread mThread GUARDED_BY(mThreadMutex); + sp<CallbackDeathRecipient> mDeathRecipient = + new CallbackDeathRecipient(); std::mutex mMutex; std::condition_variable_any mConditionVariable; @@ -128,9 +121,6 @@ private: std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash> mCompletedTransactions GUARDED_BY(mMutex); - bool mRunning GUARDED_BY(mMutex) = false; - bool mKeepRunning GUARDED_BY(mMutex) = true; - sp<Fence> mPresentFence GUARDED_BY(mMutex); }; diff --git a/services/surfaceflinger/tests/Credentials_test.cpp b/services/surfaceflinger/tests/Credentials_test.cpp index 9302463190..53e37d874e 100644 --- a/services/surfaceflinger/tests/Credentials_test.cpp +++ b/services/surfaceflinger/tests/Credentials_test.cpp @@ -25,7 +25,7 @@ #include <gui/SurfaceComposerClient.h> #include <private/android_filesystem_config.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <utils/String8.h> #include <functional> #include "utils/ScreenshotUtils.h" @@ -81,14 +81,13 @@ protected: mDisplay = SurfaceComposerClient::getInternalDisplayToken(); ASSERT_FALSE(mDisplay == nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(mDisplay, &config)); + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplay, &mode)); // Background surface - mBGSurfaceControl = - mComposerClient->createSurface(SURFACE_NAME, config.resolution.getWidth(), - config.resolution.getHeight(), - PIXEL_FORMAT_RGBA_8888, 0); + mBGSurfaceControl = mComposerClient->createSurface(SURFACE_NAME, mode.resolution.getWidth(), + mode.resolution.getHeight(), + PIXEL_FORMAT_RGBA_8888, 0); ASSERT_TRUE(mBGSurfaceControl != nullptr); ASSERT_TRUE(mBGSurfaceControl->isValid()); @@ -185,13 +184,13 @@ TEST_F(CredentialsTest, AllowedGetterMethodsTest) { const auto display = SurfaceComposerClient::getInternalDisplayToken(); ASSERT_TRUE(display != nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); - Vector<DisplayConfig> configs; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); + Vector<ui::DisplayMode> modes; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); - ASSERT_TRUE(SurfaceComposerClient::getActiveConfig(display) >= 0); + ASSERT_TRUE(SurfaceComposerClient::getActiveDisplayModeId(display) >= 0); ASSERT_NE(static_cast<ui::ColorMode>(BAD_VALUE), SurfaceComposerClient::getActiveColorMode(display)); @@ -217,25 +216,23 @@ TEST_F(CredentialsTest, GetDisplayNativePrimariesTest) { TEST_F(CredentialsTest, SetDesiredDisplayConfigsTest) { const auto display = SurfaceComposerClient::getInternalDisplayToken(); - int32_t defaultConfig; + size_t defaultMode; bool allowGroupSwitching; float primaryFpsMin; float primaryFpsMax; float appRequestFpsMin; float appRequestFpsMax; status_t res = - SurfaceComposerClient::getDesiredDisplayConfigSpecs(display, &defaultConfig, - &allowGroupSwitching, - &primaryFpsMin, &primaryFpsMax, - &appRequestFpsMin, - &appRequestFpsMax); + SurfaceComposerClient::getDesiredDisplayModeSpecs(display, &defaultMode, + &allowGroupSwitching, &primaryFpsMin, + &primaryFpsMax, &appRequestFpsMin, + &appRequestFpsMax); ASSERT_EQ(res, NO_ERROR); std::function<status_t()> condition = [=]() { - return SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, defaultConfig, - allowGroupSwitching, - primaryFpsMin, primaryFpsMax, - appRequestFpsMin, - appRequestFpsMax); + return SurfaceComposerClient::setDesiredDisplayModeSpecs(display, defaultMode, + allowGroupSwitching, primaryFpsMin, + primaryFpsMax, appRequestFpsMin, + appRequestFpsMax); }; ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); } diff --git a/services/surfaceflinger/tests/DisplayConfigs_test.cpp b/services/surfaceflinger/tests/DisplayConfigs_test.cpp index 55b317382e..9f025a6aaa 100644 --- a/services/surfaceflinger/tests/DisplayConfigs_test.cpp +++ b/services/surfaceflinger/tests/DisplayConfigs_test.cpp @@ -22,7 +22,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/SurfaceComposerClient.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <utils/Errors.h> #include <utils/Vector.h> @@ -38,7 +38,7 @@ namespace android { */ class RefreshRateRangeTest : public ::testing::Test { private: - int32_t initialDefaultConfig; + size_t initialDefaultMode; bool initialAllowGroupSwitching; float initialPrimaryMin; float initialPrimaryMax; @@ -49,25 +49,24 @@ protected: void SetUp() override { mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); status_t res = - SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, - &initialDefaultConfig, - &initialAllowGroupSwitching, - &initialPrimaryMin, - &initialPrimaryMax, - &initialAppRequestMin, - &initialAppRequestMax); + SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, + &initialDefaultMode, + &initialAllowGroupSwitching, + &initialPrimaryMin, + &initialPrimaryMax, + &initialAppRequestMin, + &initialAppRequestMax); ASSERT_EQ(res, NO_ERROR); } void TearDown() override { status_t res = - SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken, - initialDefaultConfig, - initialAllowGroupSwitching, - initialPrimaryMin, - initialPrimaryMax, - initialAppRequestMin, - initialAppRequestMax); + SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode, + initialAllowGroupSwitching, + initialPrimaryMin, + initialPrimaryMax, + initialAppRequestMin, + initialAppRequestMax); ASSERT_EQ(res, NO_ERROR); } @@ -77,60 +76,59 @@ protected: }; TEST_F(RefreshRateRangeTest, setAllConfigs) { - Vector<DisplayConfig> configs; - status_t res = SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &configs); + Vector<ui::DisplayMode> modes; + status_t res = SurfaceComposerClient::getDisplayModes(mDisplayToken, &modes); ASSERT_EQ(res, NO_ERROR); - ASSERT_GT(configs.size(), 0); - - for (size_t i = 0; i < configs.size(); i++) { - res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken, - static_cast<int32_t>(i), false, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate); + ASSERT_GT(modes.size(), 0); + + for (size_t i = 0; i < modes.size(); i++) { + res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, i, false, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate); ASSERT_EQ(res, NO_ERROR); - int defaultConfig; + size_t defaultConfig; bool allowGroupSwitching; float primaryRefreshRateMin; float primaryRefreshRateMax; float appRequestRefreshRateMin; float appRequestRefreshRateMax; - res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, &defaultConfig, - &allowGroupSwitching, - &primaryRefreshRateMin, - &primaryRefreshRateMax, - &appRequestRefreshRateMin, - &appRequestRefreshRateMax); + res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, + &allowGroupSwitching, + &primaryRefreshRateMin, + &primaryRefreshRateMax, + &appRequestRefreshRateMin, + &appRequestRefreshRateMax); ASSERT_EQ(res, NO_ERROR); ASSERT_EQ(defaultConfig, i); ASSERT_EQ(allowGroupSwitching, false); - ASSERT_EQ(primaryRefreshRateMin, configs[i].refreshRate); - ASSERT_EQ(primaryRefreshRateMax, configs[i].refreshRate); - ASSERT_EQ(appRequestRefreshRateMin, configs[i].refreshRate); - ASSERT_EQ(appRequestRefreshRateMax, configs[i].refreshRate); + ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate); + ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate); + ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate); + ASSERT_EQ(appRequestRefreshRateMax, modes[i].refreshRate); } } void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) { - status_t res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken, 0, - allowGroupSwitching, 0.f, - 90.f, 0.f, 90.f); + status_t res = + SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching, + 0.f, 90.f, 0.f, 90.f); ASSERT_EQ(res, NO_ERROR); - int defaultConfig; + size_t defaultConfig; bool newAllowGroupSwitching; float primaryRefreshRateMin; float primaryRefreshRateMax; float appRequestRefreshRateMin; float appRequestRefreshRateMax; - res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, &defaultConfig, - &newAllowGroupSwitching, - &primaryRefreshRateMin, - &primaryRefreshRateMax, - &appRequestRefreshRateMin, - &appRequestRefreshRateMax); + res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, + &newAllowGroupSwitching, + &primaryRefreshRateMin, + &primaryRefreshRateMax, + &appRequestRefreshRateMin, + &appRequestRefreshRateMax); ASSERT_EQ(res, NO_ERROR); ASSERT_EQ(defaultConfig, 0); ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching); diff --git a/services/surfaceflinger/tests/IPC_test.cpp b/services/surfaceflinger/tests/IPC_test.cpp index 4023c66e52..a8647c3e50 100644 --- a/services/surfaceflinger/tests/IPC_test.cpp +++ b/services/surfaceflinger/tests/IPC_test.cpp @@ -23,7 +23,7 @@ #include <gui/LayerState.h> #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <utils/String8.h> #include <limits> @@ -227,10 +227,10 @@ public: ASSERT_EQ(NO_ERROR, mClient->initCheck()); mPrimaryDisplay = mClient->getInternalDisplayToken(); - DisplayConfig config; - mClient->getActiveDisplayConfig(mPrimaryDisplay, &config); - mDisplayWidth = config.resolution.getWidth(); - mDisplayHeight = config.resolution.getHeight(); + ui::DisplayMode mode; + mClient->getActiveDisplayMode(mPrimaryDisplay, &mode); + mDisplayWidth = mode.resolution.getWidth(); + mDisplayHeight = mode.resolution.getHeight(); Transaction setupTransaction; setupTransaction.setDisplayLayerStack(mPrimaryDisplay, 0); diff --git a/services/surfaceflinger/tests/LayerTransactionTest.h b/services/surfaceflinger/tests/LayerTransactionTest.h index 67585185f9..eba2c250a5 100644 --- a/services/surfaceflinger/tests/LayerTransactionTest.h +++ b/services/surfaceflinger/tests/LayerTransactionTest.h @@ -25,7 +25,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/SurfaceComposerClient.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include "BufferGenerator.h" #include "utils/ScreenshotUtils.h" @@ -265,16 +265,16 @@ private: mDisplay = mClient->getInternalDisplayToken(); ASSERT_FALSE(mDisplay == nullptr) << "failed to get display"; - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(mDisplay, &config)); - mDisplayRect = Rect(config.resolution); + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplay, &mode)); + mDisplayRect = Rect(mode.resolution); mDisplayWidth = mDisplayRect.getWidth(); mDisplayHeight = mDisplayRect.getHeight(); // After a new buffer is queued, SurfaceFlinger is notified and will // latch the new buffer on next vsync. Let's heuristically wait for 3 // vsyncs. - mBufferPostDelay = static_cast<int32_t>(1e6 / config.refreshRate) * 3; + mBufferPostDelay = static_cast<int32_t>(1e6 / mode.refreshRate) * 3; mDisplayLayerStack = 0; diff --git a/services/surfaceflinger/tests/LayerUpdate_test.cpp b/services/surfaceflinger/tests/LayerUpdate_test.cpp index 6c56d209d4..ec826aed9c 100644 --- a/services/surfaceflinger/tests/LayerUpdate_test.cpp +++ b/services/surfaceflinger/tests/LayerUpdate_test.cpp @@ -36,9 +36,9 @@ protected: const auto display = SurfaceComposerClient::getInternalDisplayToken(); ASSERT_FALSE(display == nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - const ui::Size& resolution = config.resolution; + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + const ui::Size& resolution = mode.resolution; // Background surface mBGSurfaceControl = createLayer(String8("BG Test Surface"), resolution.getWidth(), diff --git a/services/surfaceflinger/tests/MultiDisplayLayerBounds_test.cpp b/services/surfaceflinger/tests/MultiDisplayLayerBounds_test.cpp index db0c56f6aa..eaf54e38ec 100644 --- a/services/surfaceflinger/tests/MultiDisplayLayerBounds_test.cpp +++ b/services/surfaceflinger/tests/MultiDisplayLayerBounds_test.cpp @@ -37,13 +37,13 @@ protected: mMainDisplay = SurfaceComposerClient::getInternalDisplayToken(); SurfaceComposerClient::getDisplayState(mMainDisplay, &mMainDisplayState); - SurfaceComposerClient::getActiveDisplayConfig(mMainDisplay, &mMainDisplayConfig); + SurfaceComposerClient::getActiveDisplayMode(mMainDisplay, &mMainDisplayMode); sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&mProducer, &consumer); consumer->setConsumerName(String8("Virtual disp consumer")); - consumer->setDefaultBufferSize(mMainDisplayConfig.resolution.getWidth(), - mMainDisplayConfig.resolution.getHeight()); + consumer->setDefaultBufferSize(mMainDisplayMode.resolution.getWidth(), + mMainDisplayMode.resolution.getHeight()); } virtual void TearDown() { @@ -59,7 +59,7 @@ protected: t.setDisplaySurface(mVirtualDisplay, mProducer); t.setDisplayLayerStack(mVirtualDisplay, layerStack); t.setDisplayProjection(mVirtualDisplay, mMainDisplayState.orientation, - Rect(layerStackSize), Rect(mMainDisplayConfig.resolution)); + Rect(layerStackSize), Rect(mMainDisplayMode.resolution)); }); } @@ -81,7 +81,7 @@ protected: } ui::DisplayState mMainDisplayState; - DisplayConfig mMainDisplayConfig; + ui::DisplayMode mMainDisplayMode; sp<IBinder> mMainDisplay; sp<IBinder> mVirtualDisplay; sp<IGraphicBufferProducer> mProducer; diff --git a/services/surfaceflinger/tests/ScreenCapture_test.cpp b/services/surfaceflinger/tests/ScreenCapture_test.cpp index 51ce1d3ff9..4598f9dc84 100644 --- a/services/surfaceflinger/tests/ScreenCapture_test.cpp +++ b/services/surfaceflinger/tests/ScreenCapture_test.cpp @@ -33,9 +33,9 @@ protected: const auto display = SurfaceComposerClient::getInternalDisplayToken(); ASSERT_FALSE(display == nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - const ui::Size& resolution = config.resolution; + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + const ui::Size& resolution = mode.resolution; // Background surface mBGSurfaceControl = createLayer(String8("BG Test Surface"), resolution.getWidth(), diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp index fa88ca5c57..a20d5c62d5 100644 --- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp +++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp @@ -27,7 +27,7 @@ #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <fstream> #include <random> @@ -267,9 +267,9 @@ void SurfaceInterceptorTest::setupBackgroundSurface() { const auto display = SurfaceComposerClient::getInternalDisplayToken(); ASSERT_FALSE(display == nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - const ui::Size& resolution = config.resolution; + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + const ui::Size& resolution = mode.resolution; // Background surface mBGSurfaceControl = diff --git a/services/surfaceflinger/tests/TransactionTestHarnesses.h b/services/surfaceflinger/tests/TransactionTestHarnesses.h index 33823d7057..89f608645d 100644 --- a/services/surfaceflinger/tests/TransactionTestHarnesses.h +++ b/services/surfaceflinger/tests/TransactionTestHarnesses.h @@ -40,9 +40,9 @@ public: ui::DisplayState displayState; SurfaceComposerClient::getDisplayState(displayToken, &displayState); - DisplayConfig displayConfig; - SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); - const ui::Size& resolution = displayConfig.resolution; + ui::DisplayMode displayMode; + SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode); + const ui::Size& resolution = displayMode.resolution; sp<IBinder> vDisplay; sp<IGraphicBufferProducer> producer; diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp index efa15f1f73..56e1ae90c3 100644 --- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp +++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp @@ -43,7 +43,7 @@ #include <hwbinder/ProcessState.h> #include <log/log.h> #include <private/gui/ComposerService.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h> #include <utils/Looper.h> #include <gmock/gmock.h> @@ -243,9 +243,8 @@ protected: mComposerClient = new SurfaceComposerClient; ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); - mReceiver.reset( - new DisplayEventReceiver(ISurfaceComposer::eVsyncSourceApp, - ISurfaceComposer::EventRegistration::configChanged)); + mReceiver.reset(new DisplayEventReceiver(ISurfaceComposer::eVsyncSourceApp, + ISurfaceComposer::EventRegistration::modeChanged)); mLooper = new Looper(false); mLooper->addFd(mReceiver->getFd(), 0, ALOOPER_EVENT_INPUT, processDisplayEvents, this); } @@ -305,7 +304,7 @@ protected: return false; } - bool waitForConfigChangedEvent(Display display, int32_t configId) { + bool waitForModeChangedEvent(Display display, int32_t modeId) { PhysicalDisplayId displayId(display); int waitCount = 20; while (waitCount--) { @@ -313,12 +312,12 @@ protected: auto event = mReceivedDisplayEvents.front(); mReceivedDisplayEvents.pop_front(); - ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, - "event config: displayId %s, configId %d", - to_string(event.header.displayId).c_str(), event.config.configId); + ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE, + "event mode: displayId %s, modeId %d", + to_string(event.header.displayId).c_str(), event.modeChange.modeId); - if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED && - event.header.displayId == displayId && event.config.configId == configId) { + if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE && + event.header.displayId == displayId && event.modeChange.modeId == modeId) { return true; } } @@ -348,11 +347,11 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - const ui::Size& resolution = config.resolution; + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + const ui::Size& resolution = mode.resolution; EXPECT_EQ(ui::Size(200, 400), resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), @@ -380,8 +379,8 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_TRUE(display == nullptr); - DisplayConfig config; - EXPECT_NE(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); + ui::DisplayMode mode; + EXPECT_NE(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); } } @@ -409,14 +408,14 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(200, 400), config.resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(200, 400), mode.resolution); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -433,11 +432,11 @@ protected: } } - Vector<DisplayConfig> configs; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); - EXPECT_EQ(configs.size(), 2); + Vector<ui::DisplayMode> modes; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); + EXPECT_EQ(modes.size(), 2); - // change active config + // change active mode if (mIs2_4Client) { EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 2, _, _)) @@ -447,28 +446,28 @@ protected: .WillOnce(Return(V2_1::Error::NONE)); } - for (int i = 0; i < configs.size(); i++) { - const auto& config = configs[i]; - if (config.resolution.getWidth() == 800) { + for (int i = 0; i < modes.size(); i++) { + const auto& mode = modes[i]; + if (mode.resolution.getWidth() == 800) { EXPECT_EQ(NO_ERROR, - SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, i, false, - config.refreshRate, - config.refreshRate, - config.refreshRate, - config.refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate)); waitForDisplayTransaction(EXTERNAL_DISPLAY); - EXPECT_TRUE(waitForConfigChangedEvent(EXTERNAL_DISPLAY, i)); + EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i)); break; } } - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 11'111'111, config.refreshRate); + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -516,14 +515,14 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -540,11 +539,11 @@ protected: } } - Vector<DisplayConfig> configs; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); - EXPECT_EQ(configs.size(), 2); + Vector<ui::DisplayMode> modes; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); + EXPECT_EQ(modes.size(), 2); - // change active config + // change active mode if (mIs2_4Client) { EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 3, _, _)) .WillOnce(Return(V2_4::Error::NONE)); @@ -553,28 +552,28 @@ protected: .WillOnce(Return(V2_1::Error::NONE)); } - for (int i = 0; i < configs.size(); i++) { - const auto& config = configs[i]; - if (config.refreshRate == 1e9f / 11'111'111) { + for (int i = 0; i < modes.size(); i++) { + const auto& mode = modes[i]; + if (mode.refreshRate == 1e9f / 11'111'111) { EXPECT_EQ(NO_ERROR, - SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, i, false, - config.refreshRate, - config.refreshRate, - config.refreshRate, - config.refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate)); waitForDisplayTransaction(EXTERNAL_DISPLAY); - EXPECT_TRUE(waitForConfigChangedEvent(EXTERNAL_DISPLAY, i)); + EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i)); break; } } - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 11'111'111, config.refreshRate); + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -632,14 +631,14 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -656,11 +655,11 @@ protected: } } - Vector<DisplayConfig> configs; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); - EXPECT_EQ(configs.size(), 4); + Vector<ui::DisplayMode> modes; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); + EXPECT_EQ(modes.size(), 4); - // change active config to 800x1600@90Hz + // change active mode to 800x1600@90Hz if (mIs2_4Client) { EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 3, _, _)) .WillOnce(Return(V2_4::Error::NONE)); @@ -669,29 +668,28 @@ protected: .WillOnce(Return(V2_1::Error::NONE)); } - for (size_t i = 0; i < configs.size(); i++) { - const auto& config = configs[i]; - if (config.resolution.getWidth() == 800 && config.refreshRate == 1e9f / 11'111'111) { + for (size_t i = 0; i < modes.size(); i++) { + const auto& mode = modes[i]; + if (mode.resolution.getWidth() == 800 && mode.refreshRate == 1e9f / 11'111'111) { EXPECT_EQ(NO_ERROR, - SurfaceComposerClient:: - setDesiredDisplayConfigSpecs(display, i, false, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate)); waitForDisplayTransaction(EXTERNAL_DISPLAY); - EXPECT_TRUE(waitForConfigChangedEvent(EXTERNAL_DISPLAY, i)); + EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i)); break; } } - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 11'111'111, config.refreshRate); + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -708,7 +706,7 @@ protected: } } - // change active config to 1600x3200@120Hz + // change active mode to 1600x3200@120Hz if (mIs2_4Client) { EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 4, _, _)) .WillOnce(Return(V2_4::Error::NONE)); @@ -717,28 +715,28 @@ protected: .WillOnce(Return(V2_1::Error::NONE)); } - for (int i = 0; i < configs.size(); i++) { - const auto& config = configs[i]; - if (config.refreshRate == 1e9f / 8'333'333) { + for (int i = 0; i < modes.size(); i++) { + const auto& mode = modes[i]; + if (mode.refreshRate == 1e9f / 8'333'333) { EXPECT_EQ(NO_ERROR, - SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, i, false, - config.refreshRate, - config.refreshRate, - config.refreshRate, - config.refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate)); waitForDisplayTransaction(EXTERNAL_DISPLAY); - EXPECT_TRUE(waitForConfigChangedEvent(EXTERNAL_DISPLAY, i)); + EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i)); break; } } - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(1600, 3200), config.resolution); - EXPECT_EQ(1e9f / 8'333'333, config.refreshRate); + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(1600, 3200), mode.resolution); + EXPECT_EQ(1e9f / 8'333'333, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -755,7 +753,7 @@ protected: } } - // change active config to 1600x3200@90Hz + // change active mode to 1600x3200@90Hz if (mIs2_4Client) { EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 5, _, _)) .WillOnce(Return(V2_4::Error::NONE)); @@ -764,28 +762,28 @@ protected: .WillOnce(Return(V2_1::Error::NONE)); } - for (int i = 0; i < configs.size(); i++) { - const auto& config = configs[i]; - if (config.resolution.getWidth() == 1600 && config.refreshRate == 1e9f / 11'111'111) { + for (int i = 0; i < modes.size(); i++) { + const auto& mode = modes[i]; + if (mode.resolution.getWidth() == 1600 && mode.refreshRate == 1e9f / 11'111'111) { EXPECT_EQ(NO_ERROR, - SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, i, false, - config.refreshRate, - config.refreshRate, - config.refreshRate, - config.refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate, + mode.refreshRate)); waitForDisplayTransaction(EXTERNAL_DISPLAY); - EXPECT_TRUE(waitForConfigChangedEvent(EXTERNAL_DISPLAY, i)); + EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i)); break; } } - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(1600, 3200), config.resolution); - EXPECT_EQ(1e9f / 11'111'111, config.refreshRate); + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(1600, 3200), mode.resolution); + EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate); mFakeComposerClient->clearFrames(); { - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; auto surfaceControl = mComposerClient->createSurface(String8("Display Test Surface Foo"), resolution.getWidth(), resolution.getHeight(), @@ -822,8 +820,8 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); EXPECT_TRUE(display == nullptr); - DisplayConfig config; - auto result = SurfaceComposerClient::getActiveDisplayConfig(display, &config); + ui::DisplayMode mode; + auto result = SurfaceComposerClient::getActiveDisplayMode(display, &mode); EXPECT_NE(NO_ERROR, result); } @@ -848,11 +846,11 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); EXPECT_FALSE(display == nullptr); - DisplayConfig config; - auto result = SurfaceComposerClient::getActiveDisplayConfig(display, &config); + ui::DisplayMode mode; + auto result = SurfaceComposerClient::getActiveDisplayMode(display, &mode); EXPECT_EQ(NO_ERROR, result); - ASSERT_EQ(ui::Size(400, 200), config.resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + ASSERT_EQ(ui::Size(400, 200), mode.resolution); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); } } @@ -881,14 +879,14 @@ protected: // Verify that the active mode and the supported moded are updated { - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 11'111'111, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate); - Vector<DisplayConfig> configs; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); - EXPECT_EQ(configs.size(), 1); + Vector<ui::DisplayMode> modes; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); + EXPECT_EQ(modes.size(), 1); } // Send another hotplug connected event @@ -919,27 +917,27 @@ protected: // Verify that the active mode and the supported moded are updated { - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(1e9f / 16'666'666, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate); } - Vector<DisplayConfig> configs; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayConfigs(display, &configs)); - EXPECT_EQ(configs.size(), 3); + Vector<ui::DisplayMode> modes; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayModes(display, &modes)); + EXPECT_EQ(modes.size(), 3); - EXPECT_EQ(ui::Size(800, 1600), configs[0].resolution); - EXPECT_EQ(1e9f / 16'666'666, configs[0].refreshRate); + EXPECT_EQ(ui::Size(800, 1600), modes[0].resolution); + EXPECT_EQ(1e9f / 16'666'666, modes[0].refreshRate); - EXPECT_EQ(ui::Size(800, 1600), configs[1].resolution); - EXPECT_EQ(1e9f / 11'111'111, configs[1].refreshRate); + EXPECT_EQ(ui::Size(800, 1600), modes[1].resolution); + EXPECT_EQ(1e9f / 11'111'111, modes[1].refreshRate); - EXPECT_EQ(ui::Size(800, 1600), configs[2].resolution); - EXPECT_EQ(1e9f / 8'333'333, configs[2].refreshRate); + EXPECT_EQ(ui::Size(800, 1600), modes[2].resolution); + EXPECT_EQ(1e9f / 8'333'333, modes[2].refreshRate); // Verify that we are able to switch to any of the modes - for (int i = configs.size() - 1; i >= 0; i--) { + for (int i = modes.size() - 1; i >= 0; i--) { const auto hwcId = i + 1; // Set up HWC expectations for the mode change if (mIs2_4Client) { @@ -952,22 +950,22 @@ protected: } EXPECT_EQ(NO_ERROR, - SurfaceComposerClient::setDesiredDisplayConfigSpecs(display, i, false, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate, - configs[i].refreshRate)); + SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate, + modes[i].refreshRate)); // We need to refresh twice - once to apply the pending mode change request, // and once to process the change. waitForDisplayTransaction(hwcDisplayId); waitForDisplayTransaction(hwcDisplayId); - EXPECT_TRUE(waitForConfigChangedEvent(hwcDisplayId, i)) + EXPECT_TRUE(waitForModeChangedEvent(hwcDisplayId, i)) << "Failure while switching to mode " << i; - DisplayConfig config; - EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); - EXPECT_EQ(ui::Size(800, 1600), config.resolution); - EXPECT_EQ(configs[i].refreshRate, config.refreshRate); + ui::DisplayMode mode; + EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); + EXPECT_EQ(ui::Size(800, 1600), mode.resolution); + EXPECT_EQ(modes[i].refreshRate, mode.refreshRate); } } @@ -1168,10 +1166,10 @@ protected: const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); ASSERT_FALSE(display == nullptr); - DisplayConfig config; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayConfig(display, &config)); + ui::DisplayMode mode; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); - const ui::Size& resolution = config.resolution; + const ui::Size& resolution = mode.resolution; mDisplayWidth = resolution.getWidth(); mDisplayHeight = resolution.getHeight(); diff --git a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp index 45bc29cabb..7cc0032bc8 100644 --- a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp +++ b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp @@ -141,10 +141,10 @@ EventThreadTest::EventThreadTest() { createThread(std::move(vsyncSource)); mConnection = createConnection(mConnectionEventCallRecorder, - ISurfaceComposer::EventRegistration::configChanged | + ISurfaceComposer::EventRegistration::modeChanged | ISurfaceComposer::EventRegistration::frameRateOverride); mThrottledConnection = createConnection(mThrottledConnectionEventCallRecorder, - ISurfaceComposer::EventRegistration::configChanged, + ISurfaceComposer::EventRegistration::modeChanged, mThrottledConnectionUid); // A display must be connected for VSYNC events to be delivered. @@ -257,10 +257,10 @@ void EventThreadTest::expectConfigChangedEventReceivedByConnection( auto args = mConnectionEventCallRecorder.waitForCall(); ASSERT_TRUE(args.has_value()); const auto& event = std::get<0>(args.value()); - EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, event.header.type); + EXPECT_EQ(DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE, event.header.type); EXPECT_EQ(expectedDisplayId, event.header.displayId); - EXPECT_EQ(expectedConfigId, event.config.configId); - EXPECT_EQ(expectedVsyncPeriod, event.config.vsyncPeriod); + EXPECT_EQ(expectedConfigId, event.modeChange.modeId); + EXPECT_EQ(expectedVsyncPeriod, event.modeChange.vsyncPeriod); } void EventThreadTest::expectUidFrameRateMappingEventReceivedByConnection( @@ -540,17 +540,17 @@ TEST_F(EventThreadTest, postHotplugExternalConnect) { } TEST_F(EventThreadTest, postConfigChangedPrimary) { - mThread->onConfigChanged(INTERNAL_DISPLAY_ID, DisplayModeId(7), 16666666); + mThread->onModeChanged(INTERNAL_DISPLAY_ID, DisplayModeId(7), 16666666); expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 7, 16666666); } TEST_F(EventThreadTest, postConfigChangedExternal) { - mThread->onConfigChanged(EXTERNAL_DISPLAY_ID, DisplayModeId(5), 16666666); + mThread->onModeChanged(EXTERNAL_DISPLAY_ID, DisplayModeId(5), 16666666); expectConfigChangedEventReceivedByConnection(EXTERNAL_DISPLAY_ID, 5, 16666666); } TEST_F(EventThreadTest, postConfigChangedPrimary64bit) { - mThread->onConfigChanged(DISPLAY_ID_64BIT, DisplayModeId(7), 16666666); + mThread->onModeChanged(DISPLAY_ID_64BIT, DisplayModeId(7), 16666666); expectConfigChangedEventReceivedByConnection(DISPLAY_ID_64BIT, 7, 16666666); } @@ -559,7 +559,7 @@ TEST_F(EventThreadTest, suppressConfigChanged) { sp<MockEventThreadConnection> suppressConnection = createConnection(suppressConnectionEventRecorder); - mThread->onConfigChanged(INTERNAL_DISPLAY_ID, DisplayModeId(9), 16666666); + mThread->onModeChanged(INTERNAL_DISPLAY_ID, DisplayModeId(9), 16666666); expectConfigChangedEventReceivedByConnection(INTERNAL_DISPLAY_ID, 9, 16666666); auto args = suppressConnectionEventRecorder.waitForCall(); diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp index 04cafbca72..fec590ee4c 100644 --- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp @@ -113,12 +113,12 @@ protected: RefreshRateConfigs mConfigs{{DisplayMode::Builder(0) .setId(DisplayModeId(0)) .setVsyncPeriod(int32_t(LO_FPS_PERIOD)) - .setConfigGroup(0) + .setGroup(0) .build(), DisplayMode::Builder(1) .setId(DisplayModeId(1)) .setVsyncPeriod(int32_t(HI_FPS_PERIOD)) - .setConfigGroup(0) + .setGroup(0) .build()}, DisplayModeId(0)}; diff --git a/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp b/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp index d5c9b57c6e..be76e8fd2f 100644 --- a/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp @@ -53,7 +53,7 @@ TEST_F(LayerInfoTest, prefersPresentTime) { for (int i = 1; i <= kNumFrames; i++) { frameTimes.push_back(FrameTimeData{.presentTime = kPeriod * i, .queueTime = 0, - .pendingConfigChange = false}); + .pendingModeChange = false}); } setFrameTimes(frameTimes); const auto averageFrameTime = calculateAverageFrameTime(); @@ -71,7 +71,7 @@ TEST_F(LayerInfoTest, fallbacksToQueueTimeIfNoPresentTime) { for (int i = 1; i <= kNumFrames; i++) { frameTimes.push_back(FrameTimeData{.presentTime = 0, .queueTime = kPeriod * i, - .pendingConfigChange = false}); + .pendingModeChange = false}); } setFrameTimes(frameTimes); setLastRefreshRate(Fps(20.0f)); // Set to some valid value @@ -89,7 +89,7 @@ TEST_F(LayerInfoTest, returnsNulloptIfThereWasConfigChange) { for (int i = 1; i <= kNumFrames; i++) { frameTimesWithoutConfigChange.push_back(FrameTimeData{.presentTime = period * i, .queueTime = period * i, - .pendingConfigChange = false}); + .pendingModeChange = false}); } setFrameTimes(frameTimesWithoutConfigChange); @@ -98,7 +98,7 @@ TEST_F(LayerInfoTest, returnsNulloptIfThereWasConfigChange) { { // Config change in the first record auto frameTimes = frameTimesWithoutConfigChange; - frameTimes[0].pendingConfigChange = true; + frameTimes[0].pendingModeChange = true; setFrameTimes(frameTimes); ASSERT_FALSE(calculateAverageFrameTime().has_value()); } @@ -106,7 +106,7 @@ TEST_F(LayerInfoTest, returnsNulloptIfThereWasConfigChange) { { // Config change in the last record auto frameTimes = frameTimesWithoutConfigChange; - frameTimes[frameTimes.size() - 1].pendingConfigChange = true; + frameTimes[frameTimes.size() - 1].pendingModeChange = true; setFrameTimes(frameTimes); ASSERT_FALSE(calculateAverageFrameTime().has_value()); } @@ -114,7 +114,7 @@ TEST_F(LayerInfoTest, returnsNulloptIfThereWasConfigChange) { { // Config change in the middle auto frameTimes = frameTimesWithoutConfigChange; - frameTimes[frameTimes.size() / 2].pendingConfigChange = true; + frameTimes[frameTimes.size() / 2].pendingModeChange = true; setFrameTimes(frameTimes); ASSERT_FALSE(calculateAverageFrameTime().has_value()); } @@ -131,12 +131,12 @@ TEST_F(LayerInfoTest, ignoresSmallPeriods) { for (int i = 1; i <= kNumIterations; i++) { frameTimes.push_back(FrameTimeData{.presentTime = kExpectedPeriod * i, .queueTime = 0, - .pendingConfigChange = false}); + .pendingModeChange = false}); // A duplicate frame frameTimes.push_back(FrameTimeData{.presentTime = kExpectedPeriod * i + kSmallPeriod, .queueTime = 0, - .pendingConfigChange = false}); + .pendingModeChange = false}); } setFrameTimes(frameTimes); const auto averageFrameTime = calculateAverageFrameTime(); @@ -156,7 +156,7 @@ TEST_F(LayerInfoTest, ignoresLargePeriods) { auto record = [&](nsecs_t time) { frameTimes.push_back( - FrameTimeData{.presentTime = time, .queueTime = 0, .pendingConfigChange = false}); + FrameTimeData{.presentTime = time, .queueTime = 0, .pendingModeChange = false}); }; auto time = kExpectedPeriod; // Start with non-zero time. diff --git a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp index 738ded18ac..376995f79e 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp @@ -81,24 +81,25 @@ protected: static inline const DisplayModeId HWC_CONFIG_ID_50 = DisplayModeId(6); // Test configs - DisplayModePtr mConfig60 = createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs()); - DisplayModePtr mConfig90 = createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs()); + DisplayModePtr mConfig60 = createDisplayMode(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs()); + DisplayModePtr mConfig90 = createDisplayMode(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs()); DisplayModePtr mConfig90DifferentGroup = - createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs()); DisplayModePtr mConfig90DifferentResolution = - createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), ui::Size(111, 222)); - DisplayModePtr mConfig72 = createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), ui::Size(111, 222)); + DisplayModePtr mConfig72 = createDisplayMode(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs()); DisplayModePtr mConfig72DifferentGroup = - createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs()); - DisplayModePtr mConfig120 = createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs()); + DisplayModePtr mConfig120 = + createDisplayMode(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs()); DisplayModePtr mConfig120DifferentGroup = - createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs()); - DisplayModePtr mConfig30 = createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs()); + DisplayModePtr mConfig30 = createDisplayMode(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs()); DisplayModePtr mConfig30DifferentGroup = - createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs()); DisplayModePtr mConfig25DifferentGroup = - createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs()); - DisplayModePtr mConfig50 = createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs()); + createDisplayMode(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs()); + DisplayModePtr mConfig50 = createDisplayMode(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs()); // Test device configurations // The positions of the configs in the arrays below MUST match their IDs. For example, @@ -128,8 +129,8 @@ protected: RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, Fps(60), RefreshRate::ConstructorTag(0)}; RefreshRate mExpectedAlmost60Config = {HWC_CONFIG_ID_60, - createConfig(HWC_CONFIG_ID_60, 0, 16666665), Fps(60), - RefreshRate::ConstructorTag(0)}; + createDisplayMode(HWC_CONFIG_ID_60, 0, 16666665), + Fps(60), RefreshRate::ConstructorTag(0)}; RefreshRate mExpected90Config = {HWC_CONFIG_ID_90, mConfig90, Fps(90), RefreshRate::ConstructorTag(0)}; RefreshRate mExpected90DifferentGroupConfig = {HWC_CONFIG_ID_90, mConfig90DifferentGroup, @@ -144,8 +145,8 @@ protected: RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, Fps(120), RefreshRate::ConstructorTag(0)}; private: - DisplayModePtr createConfig(DisplayModeId configId, int32_t configGroup, int64_t vsyncPeriod, - ui::Size resolution = ui::Size()); + DisplayModePtr createDisplayMode(DisplayModeId modeId, int32_t group, int64_t vsyncPeriod, + ui::Size resolution = ui::Size()); }; using Builder = DisplayMode::Builder; @@ -162,12 +163,12 @@ RefreshRateConfigsTest::~RefreshRateConfigsTest() { ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } -DisplayModePtr RefreshRateConfigsTest::createConfig(DisplayModeId configId, int32_t configGroup, - int64_t vsyncPeriod, ui::Size resolution) { - return DisplayMode::Builder(hal::HWConfigId(configId.value())) - .setId(configId) +DisplayModePtr RefreshRateConfigsTest::createDisplayMode(DisplayModeId modeId, int32_t group, + int64_t vsyncPeriod, ui::Size resolution) { + return DisplayMode::Builder(hal::HWConfigId(modeId.value())) + .setId(modeId) .setVsyncPeriod(int32_t(vsyncPeriod)) - .setConfigGroup(configGroup) + .setGroup(group) .setHeight(resolution.height) .setWidth(resolution.width) .build(); @@ -226,7 +227,7 @@ TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differe ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}), 0); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs); const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy(); @@ -252,7 +253,7 @@ TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differe ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}), 0); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs); const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy(); @@ -288,20 +289,20 @@ TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) { /*currentConfigId=*/HWC_CONFIG_ID_60); { auto current = refreshRateConfigs->getCurrentRefreshRate(); - EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60); + EXPECT_EQ(current.getModeId(), HWC_CONFIG_ID_60); } - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); { auto current = refreshRateConfigs->getCurrentRefreshRate(); - EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90); + EXPECT_EQ(current.getModeId(), HWC_CONFIG_ID_90); } ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}), 0); { auto current = refreshRateConfigs->getCurrentRefreshRate(); - EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90); + EXPECT_EQ(current.getModeId(), HWC_CONFIG_ID_90); } } @@ -1196,30 +1197,30 @@ TEST_F(RefreshRateConfigsTest, groupSwitching) { ASSERT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); RefreshRateConfigs::Policy policy; - policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig; + policy.defaultMode = refreshRateConfigs->getCurrentPolicy().defaultMode; policy.allowGroupSwitching = true; ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0); ASSERT_EQ(HWC_CONFIG_ID_90, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); // Verify that we won't change the group if seamless switch is required. layer.seamlessness = Seamlessness::OnlySeamless; ASSERT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); // Verify that we won't do a seamless switch if we request the same mode as the default - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); layer.desiredRefreshRate = Fps(60.0f); layer.name = "60Hz ExplicitDefault"; layer.seamlessness = Seamlessness::OnlySeamless; ASSERT_EQ(HWC_CONFIG_ID_90, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); // Verify that if the current config is in another group and there are no layers with // seamlessness=SeamedAndSeamless we'll go back to the default group. @@ -1228,11 +1229,11 @@ TEST_F(RefreshRateConfigsTest, groupSwitching) { layer.seamlessness = Seamlessness::Default; ASSERT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); // If there's a layer with seamlessness=SeamedAndSeamless, another layer with - // seamlessness=OnlySeamless can't change the config group. - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + // seamlessness=OnlySeamless can't change the mode group. + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); layer.seamlessness = Seamlessness::OnlySeamless; layers.push_back(LayerRequirement{.weight = 0.5f}); @@ -1245,14 +1246,14 @@ TEST_F(RefreshRateConfigsTest, groupSwitching) { ASSERT_EQ(HWC_CONFIG_ID_90, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); // If there's a layer with seamlessness=SeamedAndSeamless, another layer with - // seamlessness=Default can't change the config group. + // seamlessness=Default can't change the mode group. layers[0].seamlessness = Seamlessness::Default; ASSERT_EQ(HWC_CONFIG_ID_90, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); } TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) { @@ -1262,7 +1263,7 @@ TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) { // Allow group switching. RefreshRateConfigs::Policy policy; - policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig; + policy.defaultMode = refreshRateConfigs->getCurrentPolicy().defaultMode; policy.allowGroupSwitching = true; ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0); @@ -1276,12 +1277,12 @@ TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) { ASSERT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_120); ASSERT_EQ(HWC_CONFIG_ID_120, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); } TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) { @@ -1291,7 +1292,7 @@ TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) { // Allow group switching. RefreshRateConfigs::Policy policy; - policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig; + policy.defaultMode = refreshRateConfigs->getCurrentPolicy().defaultMode; policy.allowGroupSwitching = true; ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0); @@ -1312,14 +1313,14 @@ TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) { ASSERT_EQ(HWC_CONFIG_ID_50, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_30); ASSERT_EQ(HWC_CONFIG_ID_25, refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); } TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) { @@ -1338,7 +1339,7 @@ TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) { layers[0].desiredRefreshRate = fps; layers[0].focused = focused; return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false}) - .getConfigId(); + .getModeId(); }; ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy( @@ -1346,7 +1347,7 @@ TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) { 0); EXPECT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}) - .getConfigId()); + .getModeId()); EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f))); EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f))); EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f))); @@ -1398,7 +1399,7 @@ TEST_F(RefreshRateConfigsTest, idle) { refreshRateConfigs ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true}, &consideredSignals) - .getConfigId(); + .getModeId(); // Refresh rate will be chosen by either touch state or idle state EXPECT_EQ(!touchActive, consideredSignals.idle); return configId; @@ -1421,10 +1422,10 @@ TEST_F(RefreshRateConfigsTest, idle) { // With no layers, idle should still be lower priority than touch boost. EXPECT_EQ(HWC_CONFIG_ID_90, refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true}) - .getConfigId()); + .getModeId()); // Idle should be higher precedence than other layer frame rate considerations. - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false)); EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false)); EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false)); @@ -1437,7 +1438,7 @@ TEST_F(RefreshRateConfigsTest, idle) { // Idle should be applied rather than the current config when there are no layers. EXPECT_EQ(HWC_CONFIG_ID_60, refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true}) - .getConfigId()); + .getModeId()); } TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) { @@ -1628,19 +1629,19 @@ TEST_F(RefreshRateConfigsTest, getRefreshRateDivider) { const auto frameRate = Fps(30.f); EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate)); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_60); EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate)); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_72); EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate)); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate)); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_120); EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate)); - refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); + refreshRateConfigs->setCurrentModeId(HWC_CONFIG_ID_90); EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f))); EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f))); } diff --git a/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp index ceccd81f7a..bf07106afd 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateStatsTest.cpp @@ -53,7 +53,7 @@ protected: mRefreshRateConfigs = std::make_unique<RefreshRateConfigs>(configs, /*currentConfig=*/CONFIG_ID_0); - const auto currFps = mRefreshRateConfigs->getRefreshRateFromConfigId(CONFIG_ID_0).getFps(); + const auto currFps = mRefreshRateConfigs->getRefreshRateFromModeId(CONFIG_ID_0).getFps(); mRefreshRateStats = std::make_unique<RefreshRateStats>(mTimeStats, currFps, /*currentPowerMode=*/PowerMode::OFF); } @@ -62,7 +62,7 @@ protected: std::unique_ptr<RefreshRateConfigs> mRefreshRateConfigs; std::unique_ptr<RefreshRateStats> mRefreshRateStats; - DisplayModePtr createConfig(DisplayModeId configId, int32_t configGroup, int64_t vsyncPeriod); + DisplayModePtr createDisplayMode(DisplayModeId modeId, int32_t group, int64_t vsyncPeriod); }; RefreshRateStatsTest::RefreshRateStatsTest() { @@ -77,12 +77,12 @@ RefreshRateStatsTest::~RefreshRateStatsTest() { ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } -DisplayModePtr RefreshRateStatsTest::createConfig(DisplayModeId configId, int32_t configGroup, - int64_t vsyncPeriod) { - return DisplayMode::Builder(static_cast<hal::HWConfigId>(configId.value())) - .setId(configId) +DisplayModePtr RefreshRateStatsTest::createDisplayMode(DisplayModeId modeId, int32_t group, + int64_t vsyncPeriod) { + return DisplayMode::Builder(static_cast<hal::HWConfigId>(modeId.value())) + .setId(modeId) .setVsyncPeriod(static_cast<int32_t>(vsyncPeriod)) - .setConfigGroup(configGroup) + .setGroup(group) .build(); } @@ -91,7 +91,7 @@ namespace { * Test cases */ TEST_F(RefreshRateStatsTest, oneConfigTest) { - init({createConfig(CONFIG_ID_0, CONFIG_GROUP_0, VSYNC_90)}); + init({createDisplayMode(CONFIG_ID_0, CONFIG_GROUP_0, VSYNC_90)}); EXPECT_CALL(mTimeStats, recordRefreshRate(0, _)).Times(AtLeast(1)); EXPECT_CALL(mTimeStats, recordRefreshRate(90, _)).Times(AtLeast(1)); @@ -110,7 +110,7 @@ TEST_F(RefreshRateStatsTest, oneConfigTest) { EXPECT_LT(screenOff, times["ScreenOff"]); EXPECT_EQ(0u, times.count("90.00fps")); - const auto config0Fps = mRefreshRateConfigs->getRefreshRateFromConfigId(CONFIG_ID_0).getFps(); + const auto config0Fps = mRefreshRateConfigs->getRefreshRateFromModeId(CONFIG_ID_0).getFps(); mRefreshRateStats->setRefreshRate(config0Fps); mRefreshRateStats->setPowerMode(PowerMode::ON); screenOff = mRefreshRateStats->getTotalTimes()["ScreenOff"]; @@ -138,8 +138,8 @@ TEST_F(RefreshRateStatsTest, oneConfigTest) { } TEST_F(RefreshRateStatsTest, twoConfigsTest) { - init({createConfig(CONFIG_ID_0, CONFIG_GROUP_0, VSYNC_90), - createConfig(CONFIG_ID_1, CONFIG_GROUP_0, VSYNC_60)}); + init({createDisplayMode(CONFIG_ID_0, CONFIG_GROUP_0, VSYNC_90), + createDisplayMode(CONFIG_ID_1, CONFIG_GROUP_0, VSYNC_60)}); EXPECT_CALL(mTimeStats, recordRefreshRate(0, _)).Times(AtLeast(1)); EXPECT_CALL(mTimeStats, recordRefreshRate(60, _)).Times(AtLeast(1)); @@ -158,8 +158,8 @@ TEST_F(RefreshRateStatsTest, twoConfigsTest) { times = mRefreshRateStats->getTotalTimes(); EXPECT_LT(screenOff, times["ScreenOff"]); - const auto config0Fps = mRefreshRateConfigs->getRefreshRateFromConfigId(CONFIG_ID_0).getFps(); - const auto config1Fps = mRefreshRateConfigs->getRefreshRateFromConfigId(CONFIG_ID_1).getFps(); + const auto config0Fps = mRefreshRateConfigs->getRefreshRateFromModeId(CONFIG_ID_0).getFps(); + const auto config1Fps = mRefreshRateConfigs->getRefreshRateFromModeId(CONFIG_ID_1).getFps(); mRefreshRateStats->setRefreshRate(config0Fps); mRefreshRateStats->setPowerMode(PowerMode::ON); screenOff = mRefreshRateStats->getTotalTimes()["ScreenOff"]; diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index e688e10e14..e46a270ea8 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -52,7 +52,7 @@ protected: SchedulerTest(); const scheduler::RefreshRateConfigs - mConfigs{{DisplayMode::Builder(0).setVsyncPeriod(16'666'667).setConfigGroup(0).build()}, + mConfigs{{DisplayMode::Builder(0).setVsyncPeriod(16'666'667).setGroup(0).build()}, DisplayModeId(0)}; mock::SchedulerCallback mSchedulerCallback; @@ -69,6 +69,8 @@ protected: Scheduler::ConnectionHandle mConnectionHandle; mock::EventThread* mEventThread; sp<MockEventThreadConnection> mEventThreadConnection; + + TestableSurfaceFlinger mFlinger; }; SchedulerTest::SchedulerTest() { @@ -166,25 +168,35 @@ TEST_F(SchedulerTest, noLayerHistory) { mScheduler.chooseRefreshRateForContent(); } -TEST_F(SchedulerTest, testDispatchCachedReportedConfig) { +TEST_F(SchedulerTest, testDispatchCachedReportedMode) { // If the optional fields are cleared, the function should return before - // onConfigChange is called. + // onModeChange is called. mScheduler.clearOptionalFieldsInFeatures(); - EXPECT_NO_FATAL_FAILURE(mScheduler.dispatchCachedReportedConfig()); - EXPECT_CALL(*mEventThread, onConfigChanged(_, _, _)).Times(0); + EXPECT_NO_FATAL_FAILURE(mScheduler.dispatchCachedReportedMode()); + EXPECT_CALL(*mEventThread, onModeChanged(_, _, _)).Times(0); } -TEST_F(SchedulerTest, onNonPrimaryDisplayConfigChanged_invalidParameters) { - DisplayModeId configId = DisplayModeId(111); +TEST_F(SchedulerTest, onNonPrimaryDisplayModeChanged_invalidParameters) { + DisplayModeId modeId = DisplayModeId(111); nsecs_t vsyncPeriod = 111111; // If the handle is incorrect, the function should return before - // onConfigChange is called. + // onModeChange is called. Scheduler::ConnectionHandle invalidHandle = {.id = 123}; - EXPECT_NO_FATAL_FAILURE(mScheduler.onNonPrimaryDisplayConfigChanged(invalidHandle, - PHYSICAL_DISPLAY_ID, - configId, vsyncPeriod)); - EXPECT_CALL(*mEventThread, onConfigChanged(_, _, _)).Times(0); + EXPECT_NO_FATAL_FAILURE(mScheduler.onNonPrimaryDisplayModeChanged(invalidHandle, + PHYSICAL_DISPLAY_ID, modeId, + vsyncPeriod)); + EXPECT_CALL(*mEventThread, onModeChanged(_, _, _)).Times(0); +} + +TEST_F(SchedulerTest, calculateExtraBufferCount) { + EXPECT_EQ(0, mFlinger.calculateExtraBufferCount(Fps(60), 30ms)); + EXPECT_EQ(1, mFlinger.calculateExtraBufferCount(Fps(90), 30ms)); + EXPECT_EQ(2, mFlinger.calculateExtraBufferCount(Fps(120), 30ms)); + + EXPECT_EQ(1, mFlinger.calculateExtraBufferCount(Fps(60), 40ms)); + + EXPECT_EQ(0, mFlinger.calculateExtraBufferCount(Fps(60), 10ms)); } } // namespace android diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_SetupNewDisplayDeviceInternalTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_SetupNewDisplayDeviceInternalTest.cpp index 2b5cb77b78..e32c4bf145 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_SetupNewDisplayDeviceInternalTest.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_SetupNewDisplayDeviceInternalTest.cpp @@ -246,7 +246,7 @@ void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { .setVsyncPeriod(DEFAULT_VSYNC_PERIOD) .setDpiX(DEFAULT_DPI) .setDpiY(DEFAULT_DPI) - .setConfigGroup(0) + .setGroup(0) .build(); DisplayModes modes{activeMode}; state.physical = {.id = *displayId, diff --git a/services/surfaceflinger/tests/unittests/TestableScheduler.h b/services/surfaceflinger/tests/unittests/TestableScheduler.h index d3e90e39af..3f9dd01588 100644 --- a/services/surfaceflinger/tests/unittests/TestableScheduler.h +++ b/services/surfaceflinger/tests/unittests/TestableScheduler.h @@ -80,20 +80,19 @@ public: return mFeatures.touch == Scheduler::TouchState::Active; } - void dispatchCachedReportedConfig() { + void dispatchCachedReportedMode() { std::lock_guard<std::mutex> lock(mFeatureStateLock); - return Scheduler::dispatchCachedReportedConfig(); + return Scheduler::dispatchCachedReportedMode(); } void clearOptionalFieldsInFeatures() { std::lock_guard<std::mutex> lock(mFeatureStateLock); - mFeatures.cachedConfigChangedParams.reset(); + mFeatures.cachedModeChangedParams.reset(); } - void onNonPrimaryDisplayConfigChanged(ConnectionHandle handle, PhysicalDisplayId displayId, - DisplayModeId configId, nsecs_t vsyncPeriod) { - return Scheduler::onNonPrimaryDisplayConfigChanged(handle, displayId, configId, - vsyncPeriod); + void onNonPrimaryDisplayModeChanged(ConnectionHandle handle, PhysicalDisplayId displayId, + DisplayModeId modeId, nsecs_t vsyncPeriod) { + return Scheduler::onNonPrimaryDisplayModeChanged(handle, displayId, modeId, vsyncPeriod); } ~TestableScheduler() { diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 3787c436a0..ce2bfefc44 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -210,26 +210,26 @@ public: std::unique_ptr<scheduler::VSyncTracker> vsyncTracker, std::unique_ptr<EventThread> appEventThread, std::unique_ptr<EventThread> sfEventThread, - ISchedulerCallback* callback = nullptr, bool hasMultipleConfigs = false) { - DisplayModes configs{DisplayMode::Builder(0) - .setId(DisplayModeId(0)) - .setVsyncPeriod(16'666'667) - .setConfigGroup(0) - .build()}; - - if (hasMultipleConfigs) { - configs.emplace_back(DisplayMode::Builder(1) - .setId(DisplayModeId(1)) - .setVsyncPeriod(11'111'111) - .setConfigGroup(0) - .build()); + ISchedulerCallback* callback = nullptr, bool hasMultipleModes = false) { + DisplayModes modes{DisplayMode::Builder(0) + .setId(DisplayModeId(0)) + .setVsyncPeriod(16'666'667) + .setGroup(0) + .build()}; + + if (hasMultipleModes) { + modes.emplace_back(DisplayMode::Builder(1) + .setId(DisplayModeId(1)) + .setVsyncPeriod(11'111'111) + .setGroup(0) + .build()); } - const auto currConfig = DisplayModeId(0); + const auto currMode = DisplayModeId(0); mFlinger->mRefreshRateConfigs = - std::make_unique<scheduler::RefreshRateConfigs>(configs, currConfig); + std::make_unique<scheduler::RefreshRateConfigs>(modes, currMode); const auto currFps = - mFlinger->mRefreshRateConfigs->getRefreshRateFromConfigId(currConfig).getFps(); + mFlinger->mRefreshRateConfigs->getRefreshRateFromModeId(currMode).getFps(); mFlinger->mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mTimeStats, currFps, /*powerMode=*/hal::PowerMode::OFF); @@ -391,6 +391,11 @@ public: auto getGPUContextPriority() { return mFlinger->getGPUContextPriority(); } + auto calculateExtraBufferCount(Fps maxSupportedRefreshRate, + std::chrono::nanoseconds presentLatency) const { + return SurfaceFlinger::calculateExtraBufferCount(maxSupportedRefreshRate, presentLatency); + } + /* ------------------------------------------------------------------------ * Read-only access to private data to assert post-conditions. */ @@ -643,7 +648,7 @@ public: .setVsyncPeriod(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD) .setDpiX(FakeHwcDisplayInjector::DEFAULT_DPI) .setDpiY(FakeHwcDisplayInjector::DEFAULT_DPI) - .setConfigGroup(0) + .setGroup(0) .build(); DisplayModes modes{activeMode}; @@ -756,7 +761,7 @@ public: private: void setVsyncEnabled(bool) override {} - void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ConfigEvent) override {} + void changeRefreshRate(const Scheduler::RefreshRate&, Scheduler::ModeEvent) override {} void repaintEverythingForHWC() override {} void kernelTimerChanged(bool) override {} void triggerOnFrameRateOverridesChanged() {} diff --git a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h index 40437bfe1d..485b4acdce 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h +++ b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h @@ -33,7 +33,7 @@ public: MOCK_METHOD0(onScreenReleased, void()); MOCK_METHOD0(onScreenAcquired, void()); MOCK_METHOD2(onHotplugReceived, void(PhysicalDisplayId, bool)); - MOCK_METHOD3(onConfigChanged, void(PhysicalDisplayId, DisplayModeId, nsecs_t)); + MOCK_METHOD3(onModeChanged, void(PhysicalDisplayId, DisplayModeId, nsecs_t)); MOCK_METHOD2(onFrameRateOverridesChanged, void(PhysicalDisplayId, std::vector<FrameRateOverride>)); MOCK_CONST_METHOD1(dump, void(std::string&)); |