Merge "Move swapchain GetPhysicalDeviceSurfaceCapabilities2KHR to switch-case" into main
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index 27ae8f6..a447cda 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -422,7 +422,8 @@
bool IsAotCompilation() const {
if (std::find(std::begin(kAotCompilerFilters), std::end(kAotCompilerFilters),
- parameters_.compiler_filter) == std::end(kAotCompilerFilters)) {
+ std::string_view(parameters_.compiler_filter)) ==
+ std::end(kAotCompilerFilters)) {
return false;
}
diff --git a/cmds/servicemanager/OWNERS b/cmds/servicemanager/OWNERS
new file mode 100644
index 0000000..7f5a811
--- /dev/null
+++ b/cmds/servicemanager/OWNERS
@@ -0,0 +1,3 @@
+# Bug component: 32456
+
+smoreland@google.com
diff --git a/cmds/servicemanager/main.cpp b/cmds/servicemanager/main.cpp
index 86a45e61..ae56cb0 100644
--- a/cmds/servicemanager/main.cpp
+++ b/cmds/servicemanager/main.cpp
@@ -125,6 +125,8 @@
ps->setThreadPoolMaxThreadCount(0);
ps->setCallRestriction(ProcessState::CallRestriction::FATAL_IF_NOT_ONEWAY);
+ IPCThreadState::self()->disableBackgroundScheduling(true);
+
sp<ServiceManager> manager = sp<ServiceManager>::make(std::make_unique<Access>());
if (!manager->addService("manager", manager, false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()) {
LOG(ERROR) << "Could not self register servicemanager";
diff --git a/libs/binder/rust/tests/parcel_fuzzer/read_utils.rs b/libs/binder/rust/tests/parcel_fuzzer/read_utils.rs
index a2d48b6..2c8d05f 100644
--- a/libs/binder/rust/tests/parcel_fuzzer/read_utils.rs
+++ b/libs/binder/rust/tests/parcel_fuzzer/read_utils.rs
@@ -89,14 +89,17 @@
read_parcel_interface!(Option<Vec<u64>>),
read_parcel_interface!(Option<Vec<String>>),
read_parcel_interface!(ParcelFileDescriptor),
+ read_parcel_interface!(Vec<ParcelFileDescriptor>),
read_parcel_interface!(Vec<Option<ParcelFileDescriptor>>),
read_parcel_interface!(Option<Vec<ParcelFileDescriptor>>),
read_parcel_interface!(Option<Vec<Option<ParcelFileDescriptor>>>),
read_parcel_interface!(SpIBinder),
+ read_parcel_interface!(Vec<SpIBinder>),
read_parcel_interface!(Vec<Option<SpIBinder>>),
read_parcel_interface!(Option<Vec<SpIBinder>>),
read_parcel_interface!(Option<Vec<Option<SpIBinder>>>),
read_parcel_interface!(SomeParcelable),
+ read_parcel_interface!(Vec<SomeParcelable>),
read_parcel_interface!(Vec<Option<SomeParcelable>>),
read_parcel_interface!(Option<Vec<SomeParcelable>>),
read_parcel_interface!(Option<Vec<Option<SomeParcelable>>>),
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index 10f5899..920b83d 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -508,13 +508,13 @@
{
if (CC_UNLIKELY(ATRACE_ENABLED())) {
if (buffer == nullptr) {
- ATRACE_FORMAT_INSTANT("%s buffer reallocation: null", mConsumerName.string());
+ ATRACE_FORMAT_INSTANT("%s buffer reallocation: null", mConsumerName.c_str());
} else {
ATRACE_FORMAT_INSTANT("%s buffer reallocation actual %dx%d format:%d "
"layerCount:%d "
"usage:%d requested: %dx%d format:%d layerCount:%d "
"usage:%d ",
- mConsumerName.string(), width, height, format,
+ mConsumerName.c_str(), width, height, format,
BQ_LAYER_COUNT, usage, buffer->getWidth(),
buffer->getHeight(), buffer->getPixelFormat(),
buffer->getLayerCount(), buffer->getUsage());
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 92589c5..4db960e 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -2431,7 +2431,7 @@
if (mStatus == NO_ERROR) {
gui::CreateSurfaceResult result;
- binder::Status status = mClient->createSurface(std::string(name.string()), flags,
+ binder::Status status = mClient->createSurface(std::string(name.c_str()), flags,
parentHandle, std::move(metadata), &result);
err = statusTFromBinderStatus(status);
if (outTransformHint) {
@@ -2768,6 +2768,20 @@
return statusTFromBinderStatus(status);
}
+status_t SurfaceComposerClient::updateSmallAreaDetection(std::vector<int32_t>& uids,
+ std::vector<float>& thresholds) {
+ binder::Status status =
+ ComposerServiceAIDL::getComposerService()->updateSmallAreaDetection(uids, thresholds);
+ return statusTFromBinderStatus(status);
+}
+
+status_t SurfaceComposerClient::setSmallAreaDetectionThreshold(uid_t uid, float threshold) {
+ binder::Status status =
+ ComposerServiceAIDL::getComposerService()->setSmallAreaDetectionThreshold(uid,
+ threshold);
+ return statusTFromBinderStatus(status);
+}
+
void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
ComposerServiceAIDL::getComposerService()->setAutoLowLatencyMode(display, on);
}
diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
index c2f47fc..1c604a1 100644
--- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
+++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
@@ -479,6 +479,15 @@
*/
void setOverrideFrameRate(int uid, float frameRate);
+ oneway void updateSmallAreaDetection(in int[] uids, in float[] thresholds);
+
+ /**
+ * Set the small area detection threshold for a specified uid by SmallAreaDetectionController.
+ * Passing the threshold and uid to SurfaceFlinger to update the uid-threshold mapping
+ * in the scheduler.
+ */
+ oneway void setSmallAreaDetectionThreshold(int uid, float threshold);
+
/**
* Enables or disables the frame rate overlay in the top left corner.
* Requires root or android.permission.HARDWARE_TEST
diff --git a/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp b/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp
index f684874..fd8ffe1 100644
--- a/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp
+++ b/libs/gui/bufferqueue/1.0/H2BGraphicBufferProducer.cpp
@@ -1172,9 +1172,12 @@
String8 H2BGraphicBufferProducer::getConsumerName() const {
String8 lName;
- mBase->getConsumerName([&lName] (hidl_string const& name) {
- lName = name.c_str();
- });
+ status_t transStatus = toStatusT(
+ mBase->getConsumerName([&lName](hidl_string const& name) { lName = name.c_str(); }));
+ if (transStatus != NO_ERROR) {
+ ALOGE("getConsumerName failed to transact: %d", transStatus);
+ return String8("TransactFailed");
+ }
return lName;
}
diff --git a/libs/gui/bufferqueue/2.0/H2BGraphicBufferProducer.cpp b/libs/gui/bufferqueue/2.0/H2BGraphicBufferProducer.cpp
index 2f5b73c..ae00a26 100644
--- a/libs/gui/bufferqueue/2.0/H2BGraphicBufferProducer.cpp
+++ b/libs/gui/bufferqueue/2.0/H2BGraphicBufferProducer.cpp
@@ -437,6 +437,10 @@
[&bName](hidl_string const& name) {
bName = name.c_str();
});
+ if (!transResult.isOk()) {
+ LOG(ERROR) << "getConsumerName: corrupted transaction.";
+ return String8("TransactFailed");
+ }
return bName;
}
diff --git a/libs/gui/fuzzer/libgui_fuzzer_utils.h b/libs/gui/fuzzer/libgui_fuzzer_utils.h
index 2643fa7..177d5f8 100644
--- a/libs/gui/fuzzer/libgui_fuzzer_utils.h
+++ b/libs/gui/fuzzer/libgui_fuzzer_utils.h
@@ -154,6 +154,9 @@
MOCK_METHOD(binder::Status, setDebugFlash, (int), (override));
MOCK_METHOD(binder::Status, scheduleComposite, (), (override));
MOCK_METHOD(binder::Status, scheduleCommit, (), (override));
+ MOCK_METHOD(binder::Status, updateSmallAreaDetection,
+ (const std::vector<int32_t>&, const std::vector<float>&), (override));
+ MOCK_METHOD(binder::Status, setSmallAreaDetectionThreshold, (int32_t, float), (override));
MOCK_METHOD(binder::Status, getGpuContextPriority, (int32_t*), (override));
MOCK_METHOD(binder::Status, getMaxAcquiredBufferCount, (int32_t*), (override));
MOCK_METHOD(binder::Status, addWindowInfosListener,
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index fd9f186..6fef5d2 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -203,6 +203,16 @@
// by GameManager.
static status_t setOverrideFrameRate(uid_t uid, float frameRate);
+ // Update the small area detection whole uid-threshold mappings by same size uid and threshold
+ // vector.
+ // Ref:setSmallAreaDetectionThreshold.
+ static status_t updateSmallAreaDetection(std::vector<int32_t>& uids,
+ std::vector<float>& thresholds);
+
+ // Sets the small area detection threshold to particular apps (uid). Passing value 0 means
+ // to disable small area detection to the app.
+ static status_t setSmallAreaDetectionThreshold(uid_t uid, float threshold);
+
// Switches on/off Auto Low Latency Mode on the connected display. This should only be
// called if the connected display supports Auto Low Latency Mode as reported by
// #getAutoLowLatencyModeSupport
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index ffb8622..daed764 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -999,6 +999,15 @@
binder::Status scheduleCommit() override { return binder::Status::ok(); }
+ binder::Status updateSmallAreaDetection(const std::vector<int32_t>& /*uids*/,
+ const std::vector<float>& /*thresholds*/) {
+ return binder::Status::ok();
+ }
+
+ binder::Status setSmallAreaDetectionThreshold(int32_t /*uid*/, float /*threshold*/) {
+ return binder::Status::ok();
+ }
+
binder::Status getGpuContextPriority(int32_t* /*outPriority*/) override {
return binder::Status::ok();
}
diff --git a/libs/input/PropertyMap.cpp b/libs/input/PropertyMap.cpp
index db0c98f..5f6f9e2 100644
--- a/libs/input/PropertyMap.cpp
+++ b/libs/input/PropertyMap.cpp
@@ -200,13 +200,13 @@
return BAD_VALUE;
}
- if (mMap->hasProperty(keyToken.string())) {
+ if (mMap->hasProperty(keyToken.c_str())) {
ALOGE("%s: Duplicate property value for key '%s'.",
mTokenizer->getLocation().c_str(), keyToken.c_str());
return BAD_VALUE;
}
- mMap->addProperty(keyToken.string(), valueToken.string());
+ mMap->addProperty(keyToken.c_str(), valueToken.c_str());
}
mTokenizer->nextLine();
diff --git a/libs/renderengine/skia/AutoBackendTexture.cpp b/libs/renderengine/skia/AutoBackendTexture.cpp
index 02d1e1e..cd1ac2b 100644
--- a/libs/renderengine/skia/AutoBackendTexture.cpp
+++ b/libs/renderengine/skia/AutoBackendTexture.cpp
@@ -24,6 +24,7 @@
#include <include/gpu/ganesh/SkImageGanesh.h>
#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <include/gpu/ganesh/gl/GrGLBackendSurface.h>
+#include <include/gpu/ganesh/vk/GrVkBackendSurface.h>
#include <include/gpu/vk/GrVkTypes.h>
#include <android/hardware_buffer.h>
#include "ColorSpaces.h"
@@ -139,7 +140,7 @@
}
case GrBackendApi::kVulkan: {
GrVkImageInfo imageInfo;
- bool retrievedImageInfo = tex.getVkImageInfo(&imageInfo);
+ bool retrievedImageInfo = GrBackendTextures::GetVkImageInfo(tex, &imageInfo);
LOG_ALWAYS_FATAL("%s isTextureValid:%d dataspace:%d"
"\n\tGrBackendTexture: (%i x %i) hasMipmaps: %i isProtected: %i "
"texType: %i\n\t\tVkImageInfo: success: %i fFormat: %i "
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index d469ff4..dc86577 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -854,7 +854,7 @@
}
if (!mService->isAllowListedPackage(mPackageName)) {
ALOGE("App not allowed to inject data, dropping event"
- "package=%s uid=%d", mPackageName.string(), mUid);
+ "package=%s uid=%d", mPackageName.c_str(), mUid);
return 0;
}
sensors_event_t sensor_event;
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index a286ccb..9c51fd9 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -584,7 +584,7 @@
}
if (args.size() > 0) {
Mode targetOperatingMode = NORMAL;
- std::string inputStringMode = String8(args[0]).string();
+ std::string inputStringMode = String8(args[0]).c_str();
if (getTargetOperatingMode(inputStringMode, &targetOperatingMode)) {
status_t error = changeOperatingMode(args, targetOperatingMode);
// Dump the latest state only if no error was encountered.
@@ -1495,7 +1495,7 @@
accessibleSensorList.add(sensor);
} else if (sensor.getType() != SENSOR_TYPE_HEAD_TRACKER) {
ALOGI("Skipped sensor %s because it requires permission %s and app op %" PRId32,
- sensor.getName().string(), sensor.getRequiredPermission().string(),
+ sensor.getName().c_str(), sensor.getRequiredPermission().c_str(),
sensor.getRequiredAppOp());
}
}
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index 0101c17..eda52bf 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -187,6 +187,7 @@
"Scheduler/MessageQueue.cpp",
"Scheduler/RefreshRateSelector.cpp",
"Scheduler/Scheduler.cpp",
+ "Scheduler/SmallAreaDetectionAllowMappings.cpp",
"Scheduler/VSyncDispatchTimerQueue.cpp",
"Scheduler/VSyncPredictor.cpp",
"Scheduler/VSyncReactor.cpp",
diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
index 453b51e..57ebee9 100644
--- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
+++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
@@ -150,6 +150,8 @@
? ui::Size(externalTexture->getWidth(), externalTexture->getHeight())
: ui::Size();
const uint64_t oldUsageFlags = hadBuffer ? externalTexture->getUsage() : 0;
+ const bool oldBufferFormatOpaque = LayerSnapshot::isOpaqueFormat(
+ externalTexture ? externalTexture->getPixelFormat() : PIXEL_FORMAT_NONE);
const bool hadSideStream = sidebandStream != nullptr;
const layer_state_t& clientState = resolvedComposerState.state;
@@ -160,7 +162,7 @@
LLOGV(layerId, "requested=%" PRIu64 "flags=%" PRIu64, clientState.what, clientChanges);
if (clientState.what & layer_state_t::eFlagsChanged) {
- if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) {
+ if ((oldFlags ^ flags) & (layer_state_t::eLayerHidden | layer_state_t::eLayerOpaque)) {
changes |= RequestedLayerState::Changes::Visibility |
RequestedLayerState::Changes::VisibleRegion;
}
@@ -214,6 +216,13 @@
barrierProducerId = std::max(bufferData->producerId, barrierProducerId);
barrierFrameNumber = std::max(bufferData->frameNumber, barrierFrameNumber);
}
+
+ const bool newBufferFormatOpaque = LayerSnapshot::isOpaqueFormat(
+ externalTexture ? externalTexture->getPixelFormat() : PIXEL_FORMAT_NONE);
+ if (newBufferFormatOpaque != oldBufferFormatOpaque) {
+ changes |= RequestedLayerState::Changes::Visibility |
+ RequestedLayerState::Changes::VisibleRegion;
+ }
}
if (clientState.what & layer_state_t::eSidebandStreamChanged) {
@@ -482,6 +491,9 @@
if (flags & layer_state_t::eLayerIsDisplayDecoration) {
return Composition::DISPLAY_DECORATION;
}
+ if (flags & layer_state_t::eLayerIsRefreshRateIndicator) {
+ return Composition::REFRESH_RATE_INDICATOR;
+ }
if (potentialCursor) {
return Composition::CURSOR;
}
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 50f24a7..cdf7cff 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -3212,6 +3212,14 @@
}
mDrawingState.releaseBufferEndpoint = bufferData.releaseBufferEndpoint;
+
+ // If the layer had been updated a TextureView, this would make sure the present time could be
+ // same to TextureView update when it's a small dirty, and get the correct heuristic rate.
+ if (mFlinger->mScheduler->supportSmallDirtyDetection()) {
+ if (mDrawingState.useVsyncIdForRefreshRateSelection) {
+ mUsedVsyncIdForRefreshRateSelection = true;
+ }
+ }
return true;
}
@@ -3234,10 +3242,38 @@
mDrawingState.latchedVsyncId);
if (prediction.has_value()) {
ATRACE_FORMAT_INSTANT("predictedPresentTime");
+ mMaxTimeForUseVsyncId = prediction->presentTime +
+ scheduler::LayerHistory::kMaxPeriodForHistory.count();
return prediction->presentTime;
}
}
+ if (!mFlinger->mScheduler->supportSmallDirtyDetection()) {
+ return static_cast<nsecs_t>(0);
+ }
+
+ // If the layer is not an application and didn't set an explicit rate or desiredPresentTime,
+ // return "0" to tell the layer history that it will use the max refresh rate without
+ // calculating the adaptive rate.
+ if (mWindowType != WindowInfo::Type::APPLICATION &&
+ mWindowType != WindowInfo::Type::BASE_APPLICATION) {
+ return static_cast<nsecs_t>(0);
+ }
+
+ // Return the valid present time only when the layer potentially updated a TextureView so
+ // LayerHistory could heuristically calculate the rate if the UI is continually updating.
+ if (mUsedVsyncIdForRefreshRateSelection) {
+ const auto prediction =
+ mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(
+ mDrawingState.latchedVsyncId);
+ if (prediction.has_value()) {
+ if (mMaxTimeForUseVsyncId >= prediction->presentTime) {
+ return prediction->presentTime;
+ }
+ mUsedVsyncIdForRefreshRateSelection = false;
+ }
+ }
+
return static_cast<nsecs_t>(0);
}();
@@ -3297,6 +3333,7 @@
mDrawingState.surfaceDamageRegion = surfaceDamage;
mDrawingState.modified = true;
setTransactionFlags(eTransactionNeeded);
+ setIsSmallDirty();
return true;
}
@@ -3997,7 +4034,7 @@
const std::optional<Fps> renderRate =
mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
- const auto vote = frameRateToSetFrameRateVotePayload(mDrawingState.frameRate);
+ const auto vote = frameRateToSetFrameRateVotePayload(getFrameRateForLayerTree());
const auto gameMode = getGameMode();
if (presentFence->isValid()) {
@@ -4335,6 +4372,26 @@
mLastLatchTime = latchTime;
}
+void Layer::setIsSmallDirty() {
+ if (!mFlinger->mScheduler->supportSmallDirtyDetection()) {
+ return;
+ }
+
+ if (mWindowType != WindowInfo::Type::APPLICATION &&
+ mWindowType != WindowInfo::Type::BASE_APPLICATION) {
+ return;
+ }
+ Rect bounds = mDrawingState.surfaceDamageRegion.getBounds();
+ if (!bounds.isValid()) {
+ return;
+ }
+
+ // If the damage region is a small dirty, this could give the hint for the layer history that
+ // it could suppress the heuristic rate when calculating.
+ mSmallDirty = mFlinger->mScheduler->isSmallDirtyArea(mOwnerUid,
+ bounds.getWidth() * bounds.getHeight());
+}
+
} // namespace android
#if defined(__gl_h_)
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 1f2485f..7b6c56b 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -841,6 +841,14 @@
mutable bool contentDirty{false};
Region surfaceDamageRegion;
+ // True when the surfaceDamageRegion is recognized as a small area update.
+ bool mSmallDirty{false};
+ // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating.
+ nsecs_t mMaxTimeForUseVsyncId = 0;
+ // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating
+ // buffer.
+ bool mUsedVsyncIdForRefreshRateSelection{false};
+
// Layer serial number. This gives layers an explicit ordering, so we
// have a stable sort order when their layer stack and Z-order are
// the same.
@@ -903,6 +911,7 @@
.transform = getTransform(),
.setFrameRateVote = getFrameRateForLayerTree(),
.frameRateSelectionPriority = getFrameRateSelectionPriority(),
+ .isSmallDirty = mSmallDirty,
};
};
bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
@@ -917,6 +926,9 @@
// Exposed so SurfaceFlinger can assert that it's held
const sp<SurfaceFlinger> mFlinger;
+ // Check if the damage region is a small dirty.
+ void setIsSmallDirty();
+
protected:
// For unit tests
friend class TestableSurfaceFlinger;
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index 565a490..c92e670 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -306,4 +306,11 @@
return {LayerStatus::NotFound, nullptr};
}
+bool LayerHistory::isSmallDirtyArea(uint32_t dirtyArea, float threshold) const {
+ const float ratio = (float)dirtyArea / mDisplayArea;
+ const bool isSmallDirty = ratio <= threshold;
+ ATRACE_FORMAT_INSTANT("small dirty=%s, ratio=%.3f", isSmallDirty ? "true" : "false", ratio);
+ return isSmallDirty;
+}
+
} // namespace android::scheduler
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.h b/services/surfaceflinger/Scheduler/LayerHistory.h
index d083fa2..5750ea7 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.h
+++ b/services/surfaceflinger/Scheduler/LayerHistory.h
@@ -43,6 +43,7 @@
class LayerHistory {
public:
using LayerVoteType = RefreshRateSelector::LayerVoteType;
+ static constexpr std::chrono::nanoseconds kMaxPeriodForHistory = 1s;
LayerHistory();
~LayerHistory();
@@ -84,6 +85,8 @@
// return the frames per second of the layer with the given sequence id.
float getLayerFramerate(nsecs_t now, int32_t id) const;
+ bool isSmallDirtyArea(uint32_t dirtyArea, float threshold) const;
+
private:
friend class LayerHistoryTest;
friend class TestableScheduler;
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp
index 750803b..e4df494 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.cpp
+++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp
@@ -65,7 +65,8 @@
case LayerUpdateType::Buffer:
FrameTimeData frameTime = {.presentTime = lastPresentTime,
.queueTime = mLastUpdatedTime,
- .pendingModeChange = pendingModeChange};
+ .pendingModeChange = pendingModeChange,
+ .isSmallDirty = props.isSmallDirty};
mFrameTimes.push_back(frameTime);
if (mFrameTimes.size() > HISTORY_SIZE) {
mFrameTimes.pop_front();
@@ -101,11 +102,15 @@
// classification.
bool isFrequent = true;
bool isInfrequent = true;
+ int32_t smallDirtyCount = 0;
const auto n = mFrameTimes.size() - 1;
for (size_t i = 0; i < kFrequentLayerWindowSize - 1; i++) {
if (mFrameTimes[n - i].queueTime - mFrameTimes[n - i - 1].queueTime <
kMaxPeriodForFrequentLayerNs.count()) {
isInfrequent = false;
+ if (mFrameTimes[n - i].presentTime == 0 && mFrameTimes[n - i].isSmallDirty) {
+ smallDirtyCount++;
+ }
} else {
isFrequent = false;
}
@@ -115,7 +120,8 @@
// If the layer was previously inconclusive, we clear
// the history as indeterminate layers changed to frequent,
// and we should not look at the stale data.
- return {isFrequent, isFrequent && !mIsFrequencyConclusive, /* isConclusive */ true};
+ return {isFrequent, isFrequent && !mIsFrequencyConclusive, /* isConclusive */ true,
+ /* isSmallDirty */ smallDirtyCount >= kNumSmallDirtyThreshold};
}
// If we can't determine whether the layer is frequent or not, we return
@@ -204,6 +210,7 @@
nsecs_t totalDeltas = 0;
int numDeltas = 0;
+ int32_t smallDirtyCount = 0;
auto prevFrame = mFrameTimes.begin();
for (auto it = mFrameTimes.begin() + 1; it != mFrameTimes.end(); ++it) {
const auto currDelta = getFrameTime(*it) - getFrameTime(*prevFrame);
@@ -212,6 +219,13 @@
continue;
}
+ // If this is a small area update, we don't want to consider it for calculating the average
+ // frame time. Instead, we let the bigger frame updates to drive the calculation.
+ if (it->isSmallDirty && currDelta < kMinPeriodBetweenSmallDirtyFrames) {
+ smallDirtyCount++;
+ continue;
+ }
+
prevFrame = it;
if (currDelta > kMaxPeriodBetweenFrames) {
@@ -223,6 +237,10 @@
numDeltas++;
}
+ if (smallDirtyCount > 0) {
+ ATRACE_FORMAT_INSTANT("small dirty = %" PRIu32, smallDirtyCount);
+ }
+
if (numDeltas == 0) {
return std::nullopt;
}
@@ -313,6 +331,14 @@
clearHistory(now);
}
+ // Return no vote if the latest frames are small dirty.
+ if (frequent.isSmallDirty && !mLastRefreshRate.reported.isValid()) {
+ ATRACE_FORMAT_INSTANT("NoVote (small dirty)");
+ ALOGV("%s is small dirty", mName.c_str());
+ votes.push_back({LayerHistory::LayerVoteType::NoVote, Fps()});
+ return votes;
+ }
+
auto refreshRate = calculateRefreshRateIfPossible(selector, now);
if (refreshRate.has_value()) {
ALOGV("%s calculated refresh rate: %s", mName.c_str(), to_string(*refreshRate).c_str());
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.h b/services/surfaceflinger/Scheduler/LayerInfo.h
index 7d2444c..1e08ec8 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.h
+++ b/services/surfaceflinger/Scheduler/LayerInfo.h
@@ -58,6 +58,7 @@
static constexpr Fps kMinFpsForFrequentLayer = 10_Hz;
static constexpr auto kMaxPeriodForFrequentLayerNs =
std::chrono::nanoseconds(kMinFpsForFrequentLayer.getPeriodNsecs()) + 1ms;
+ static constexpr size_t kNumSmallDirtyThreshold = 2;
friend class LayerHistoryTest;
friend class LayerInfoTest;
@@ -235,6 +236,7 @@
nsecs_t presentTime; // desiredPresentTime, if provided
nsecs_t queueTime; // buffer queue time
bool pendingModeChange;
+ bool isSmallDirty;
};
// Holds information about the calculated and reported refresh rate
@@ -299,6 +301,8 @@
bool clearHistory;
// Represents whether we were able to determine isFrequent conclusively
bool isConclusive;
+ // Represents whether the latest frames are small dirty.
+ bool isSmallDirty = false;
};
Frequent isFrequent(nsecs_t now) const;
bool isAnimating(nsecs_t now) const;
@@ -317,6 +321,11 @@
// this period apart from each other, the interval between them won't be
// taken into account when calculating average frame rate.
static constexpr nsecs_t kMaxPeriodBetweenFrames = kMinFpsForFrequentLayer.getPeriodNsecs();
+ // Used for sanitizing the heuristic data. If frames are small dirty updating and are less
+ // than this period apart from each other, the interval between them won't be
+ // taken into account when calculating average frame rate.
+ static constexpr nsecs_t kMinPeriodBetweenSmallDirtyFrames = (60_Hz).getPeriodNsecs();
+
LayerHistory::LayerVoteType mDefaultVote;
LayerVote mLayerVote;
@@ -331,7 +340,7 @@
std::chrono::time_point<std::chrono::steady_clock> mFrameTimeValidSince =
std::chrono::steady_clock::now();
static constexpr size_t HISTORY_SIZE = RefreshRateHistory::HISTORY_SIZE;
- static constexpr std::chrono::nanoseconds HISTORY_DURATION = 1s;
+ static constexpr std::chrono::nanoseconds HISTORY_DURATION = LayerHistory::kMaxPeriodForHistory;
std::unique_ptr<LayerProps> mLayerProps;
@@ -349,6 +358,7 @@
ui::Transform transform;
LayerInfo::FrameRate setFrameRateVote;
int32_t frameRateSelectionPriority = -1;
+ bool isSmallDirty = false;
};
} // namespace scheduler
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 5a19ec5..27c96f7 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -1179,4 +1179,20 @@
mFrameRateOverrideMappings.setPreferredRefreshRateForUid(frameRateOverride);
}
+void Scheduler::updateSmallAreaDetection(
+ std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
+ mSmallAreaDetectionAllowMappings.update(uidThresholdMappings);
+}
+
+void Scheduler::setSmallAreaDetectionThreshold(uid_t uid, float threshold) {
+ mSmallAreaDetectionAllowMappings.setThesholdForUid(uid, threshold);
+}
+
+bool Scheduler::isSmallDirtyArea(uid_t uid, uint32_t dirtyArea) {
+ std::optional<float> oThreshold = mSmallAreaDetectionAllowMappings.getThresholdForUid(uid);
+ if (oThreshold) return mLayerHistory.isSmallDirtyArea(dirtyArea, oThreshold.value());
+
+ return false;
+}
+
} // namespace android::scheduler
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 85d0f9a..d65df2a 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -49,6 +49,7 @@
#include "MessageQueue.h"
#include "OneShotTimer.h"
#include "RefreshRateSelector.h"
+#include "SmallAreaDetectionAllowMappings.h"
#include "Utils/Dumper.h"
#include "VsyncModulator.h"
@@ -291,6 +292,13 @@
void setGameModeRefreshRateForUid(FrameRateOverride);
+ void updateSmallAreaDetection(std::vector<std::pair<uid_t, float>>& uidThresholdMappings);
+
+ void setSmallAreaDetectionThreshold(uid_t uid, float threshold);
+
+ // Returns true if the dirty area is less than threshold.
+ bool isSmallDirtyArea(uid_t uid, uint32_t dirtyArea);
+
// Retrieves the overridden refresh rate for a given uid.
std::optional<Fps> getFrameRateOverride(uid_t) const EXCLUDES(mDisplayLock);
@@ -309,6 +317,11 @@
bool updateFrameRateOverrides(GlobalSignals, Fps displayRefreshRate) EXCLUDES(mPolicyLock);
+ // Returns true if the small dirty detection is enabled.
+ bool supportSmallDirtyDetection() const {
+ return mFeatures.test(Feature::kSmallDirtyContentDetection);
+ }
+
private:
friend class TestableScheduler;
@@ -547,6 +560,7 @@
static constexpr std::chrono::nanoseconds MAX_VSYNC_APPLIED_TIME = 200ms;
FrameRateOverrideMappings mFrameRateOverrideMappings;
+ SmallAreaDetectionAllowMappings mSmallAreaDetectionAllowMappings;
};
} // namespace scheduler
diff --git a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp
new file mode 100644
index 0000000..95cd5d1
--- /dev/null
+++ b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <sys/types.h>
+
+#include "SmallAreaDetectionAllowMappings.h"
+
+namespace android::scheduler {
+void SmallAreaDetectionAllowMappings::update(
+ std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
+ std::lock_guard lock(mLock);
+ mMap.clear();
+ for (std::pair<uid_t, float> row : uidThresholdMappings) {
+ if (!isValidThreshold(row.second)) continue;
+
+ mMap.emplace(row.first, row.second);
+ }
+}
+
+void SmallAreaDetectionAllowMappings::setThesholdForUid(uid_t uid, float threshold) {
+ if (!isValidThreshold(threshold)) return;
+
+ std::lock_guard lock(mLock);
+ mMap.emplace(uid, threshold);
+}
+
+std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForUid(uid_t uid) {
+ std::lock_guard lock(mLock);
+ const auto iter = mMap.find(uid);
+ if (iter != mMap.end()) {
+ return iter->second;
+ }
+ return std::nullopt;
+}
+} // namespace android::scheduler
diff --git a/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h
new file mode 100644
index 0000000..cbab690
--- /dev/null
+++ b/services/surfaceflinger/Scheduler/SmallAreaDetectionAllowMappings.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android-base/thread_annotations.h>
+#include <sys/types.h>
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace android::scheduler {
+class SmallAreaDetectionAllowMappings {
+ using UidThresholdMap = std::unordered_map<uid_t, float>;
+
+public:
+ void update(std::vector<std::pair<uid_t, float>>& uidThresholdMappings);
+ void setThesholdForUid(uid_t uid, float threshold) EXCLUDES(mLock);
+ std::optional<float> getThresholdForUid(uid_t uid) EXCLUDES(mLock);
+
+private:
+ static bool isValidThreshold(float threshold) { return threshold >= 0.0f && threshold <= 1.0f; }
+ mutable std::mutex mLock;
+ UidThresholdMap mMap GUARDED_BY(mLock);
+};
+} // namespace android::scheduler
diff --git a/services/surfaceflinger/Scheduler/include/scheduler/Features.h b/services/surfaceflinger/Scheduler/include/scheduler/Features.h
index 200407d..7c72ac6 100644
--- a/services/surfaceflinger/Scheduler/include/scheduler/Features.h
+++ b/services/surfaceflinger/Scheduler/include/scheduler/Features.h
@@ -28,6 +28,7 @@
kContentDetection = 1 << 2,
kTracePredictedVsync = 1 << 3,
kBackpressureGpuComposition = 1 << 4,
+ kSmallDirtyContentDetection = 1 << 5,
};
using FeatureFlags = ftl::Flags<Feature>;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index cb8edc3..bc626f3 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3989,6 +3989,9 @@
if (sysprop::use_content_detection_for_refresh_rate(false)) {
features |= Feature::kContentDetection;
+ if (base::GetBoolProperty("debug.sf.enable_small_dirty_detection"s, false)) {
+ features |= Feature::kSmallDirtyContentDetection;
+ }
}
if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) {
features |= Feature::kTracePredictedVsync;
@@ -8197,6 +8200,17 @@
return NO_ERROR;
}
+status_t SurfaceFlinger::updateSmallAreaDetection(
+ std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
+ mScheduler->updateSmallAreaDetection(uidThresholdMappings);
+ return NO_ERROR;
+}
+
+status_t SurfaceFlinger::setSmallAreaDetectionThreshold(uid_t uid, float threshold) {
+ mScheduler->setSmallAreaDetectionThreshold(uid, threshold);
+ return NO_ERROR;
+}
+
void SurfaceFlinger::enableRefreshRateOverlay(bool enable) {
bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG);
for (const auto& [id, display] : mPhysicalDisplays) {
@@ -8334,6 +8348,15 @@
void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) {
mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight());
getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize());
+
+ // Notify layers to update small dirty flag.
+ if (mScheduler->supportSmallDirtyDetection()) {
+ mCurrentState.traverse([&](Layer* layer) {
+ if (layer->getLayerStack() == activeDisplay.getLayerStack()) {
+ layer->setIsSmallDirty();
+ }
+ });
+ }
}
sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const {
@@ -9520,6 +9543,40 @@
return binder::Status::ok();
}
+binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& uids,
+ const std::vector<float>& thresholds) {
+ status_t status;
+ const int c_uid = IPCThreadState::self()->getCallingUid();
+ if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) {
+ if (uids.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE);
+
+ std::vector<std::pair<uid_t, float>> mappings;
+ const size_t size = uids.size();
+ mappings.reserve(size);
+ for (int i = 0; i < size; i++) {
+ auto row = std::make_pair(static_cast<uid_t>(uids[i]), thresholds[i]);
+ mappings.push_back(row);
+ }
+ status = mFlinger->updateSmallAreaDetection(mappings);
+ } else {
+ ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid);
+ status = PERMISSION_DENIED;
+ }
+ return binderStatusFromStatusT(status);
+}
+
+binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t uid, float threshold) {
+ status_t status;
+ const int c_uid = IPCThreadState::self()->getCallingUid();
+ if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) {
+ status = mFlinger->setSmallAreaDetectionThreshold(uid, threshold);
+ } else {
+ ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid);
+ status = PERMISSION_DENIED;
+ }
+ return binderStatusFromStatusT(status);
+}
+
binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) {
*outPriority = mFlinger->getGpuContextPriority();
return binder::Status::ok();
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6ff9fd1..79dcd0d 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -607,6 +607,10 @@
status_t setOverrideFrameRate(uid_t uid, float frameRate);
+ status_t updateSmallAreaDetection(std::vector<std::pair<uid_t, float>>& uidThresholdMappings);
+
+ status_t setSmallAreaDetectionThreshold(uid_t uid, float threshold);
+
int getGpuContextPriority();
status_t getMaxAcquiredBufferCount(int* buffers) const;
@@ -1557,6 +1561,9 @@
binder::Status setDebugFlash(int delay) override;
binder::Status scheduleComposite() override;
binder::Status scheduleCommit() override;
+ binder::Status updateSmallAreaDetection(const std::vector<int32_t>& uids,
+ const std::vector<float>& thresholds) override;
+ binder::Status setSmallAreaDetectionThreshold(int32_t uid, float threshold) override;
binder::Status getGpuContextPriority(int32_t* outPriority) override;
binder::Status getMaxAcquiredBufferCount(int32_t* buffers) override;
binder::Status addWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener,
diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp
index 7d8796f..8deff85 100644
--- a/services/surfaceflinger/tests/unittests/Android.bp
+++ b/services/surfaceflinger/tests/unittests/Android.bp
@@ -101,6 +101,7 @@
"LayerTestUtils.cpp",
"MessageQueueTest.cpp",
"PowerAdvisorTest.cpp",
+ "SmallAreaDetectionAllowMappingsTest.cpp",
"SurfaceFlinger_CreateDisplayTest.cpp",
"SurfaceFlinger_DestroyDisplayTest.cpp",
"SurfaceFlinger_DisplayModeSwitching.cpp",
diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
index 51b5b05..b67494f 100644
--- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
@@ -1070,6 +1070,77 @@
recordFramesAndExpect(layer, time, 27.1_Hz, 30_Hz, PRESENT_TIME_HISTORY_SIZE);
}
+TEST_F(LayerHistoryTest, smallDirtyLayer) {
+ auto layer = createLayer();
+
+ EXPECT_CALL(*layer, isVisible()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*layer, getFrameRateForLayerTree()).WillRepeatedly(Return(Layer::FrameRate()));
+
+ nsecs_t time = systemTime();
+
+ EXPECT_EQ(1, layerCount());
+ EXPECT_EQ(0, activeLayerCount());
+ EXPECT_EQ(0, frequentLayerCount(time));
+
+ LayerHistory::Summary summary;
+
+ // layer is active but infrequent.
+ for (int i = 0; i < PRESENT_TIME_HISTORY_SIZE; i++) {
+ auto props = layer->getLayerProps();
+ if (i % 3 == 0) {
+ props.isSmallDirty = false;
+ } else {
+ props.isSmallDirty = true;
+ }
+
+ history().record(layer->getSequence(), props, time, time,
+ LayerHistory::LayerUpdateType::Buffer);
+ time += HI_FPS_PERIOD;
+ summary = summarizeLayerHistory(time);
+ }
+
+ ASSERT_EQ(1, summary.size());
+ ASSERT_EQ(LayerHistory::LayerVoteType::Heuristic, summary[0].vote);
+ EXPECT_GE(HI_FPS, summary[0].desiredRefreshRate);
+}
+
+TEST_F(LayerHistoryTest, smallDirtyInMultiLayer) {
+ auto layer1 = createLayer("UI");
+ auto layer2 = createLayer("Video");
+
+ EXPECT_CALL(*layer1, isVisible()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*layer1, getFrameRateForLayerTree()).WillRepeatedly(Return(Layer::FrameRate()));
+
+ EXPECT_CALL(*layer2, isVisible()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*layer2, getFrameRateForLayerTree())
+ .WillRepeatedly(
+ Return(Layer::FrameRate(30_Hz, Layer::FrameRateCompatibility::Default)));
+
+ nsecs_t time = systemTime();
+
+ EXPECT_EQ(2, layerCount());
+ EXPECT_EQ(0, activeLayerCount());
+ EXPECT_EQ(0, frequentLayerCount(time));
+
+ LayerHistory::Summary summary;
+
+ // layer1 is active but infrequent.
+ for (int i = 0; i < PRESENT_TIME_HISTORY_SIZE; i++) {
+ auto props = layer1->getLayerProps();
+ props.isSmallDirty = true;
+ history().record(layer1->getSequence(), props, 0 /*presentTime*/, time,
+ LayerHistory::LayerUpdateType::Buffer);
+ history().record(layer2->getSequence(), layer2->getLayerProps(), time, time,
+ LayerHistory::LayerUpdateType::Buffer);
+ time += HI_FPS_PERIOD;
+ summary = summarizeLayerHistory(time);
+ }
+
+ ASSERT_EQ(1, summary.size());
+ ASSERT_EQ(LayerHistory::LayerVoteType::ExplicitDefault, summary[0].vote);
+ ASSERT_EQ(30_Hz, summary[0].desiredRefreshRate);
+}
+
class LayerHistoryTestParameterized : public LayerHistoryTest,
public testing::WithParamInterface<std::chrono::nanoseconds> {
};
diff --git a/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp b/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
index d65277a..1fde9b8 100644
--- a/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
@@ -17,6 +17,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <renderengine/mock/FakeExternalTexture.h>
+
#include "FrontEnd/LayerLifecycleManager.h"
#include "LayerHierarchyTest.h"
#include "TransactionState.h"
@@ -25,6 +27,8 @@
namespace android::surfaceflinger::frontend {
+using namespace ftl::flag_operators;
+
// To run test:
/**
mp :libsurfaceflinger_unittest && adb sync; adb shell \
@@ -437,4 +441,88 @@
mLifecycleManager.commitChanges();
}
+TEST_F(LayerLifecycleManagerTest, layerOpacityChangesSetsVisibilityChangeFlag) {
+ // add a default buffer and make the layer opaque
+ setFlags(1, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
+ setBuffer(1,
+ std::make_shared<
+ renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 1ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ GRALLOC_USAGE_PROTECTED /*usage*/));
+
+ mLifecycleManager.commitChanges();
+
+ // set new buffer but layer opacity doesn't change
+ setBuffer(1,
+ std::make_shared<
+ renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 2ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ GRALLOC_USAGE_PROTECTED /*usage*/));
+ EXPECT_EQ(mLifecycleManager.getGlobalChanges().get(),
+ ftl::Flags<RequestedLayerState::Changes>(RequestedLayerState::Changes::Buffer |
+ RequestedLayerState::Changes::Content)
+ .get());
+ mLifecycleManager.commitChanges();
+
+ // change layer flags and confirm visibility flag is set
+ setFlags(1, layer_state_t::eLayerOpaque, 0);
+ EXPECT_TRUE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+}
+
+TEST_F(LayerLifecycleManagerTest, bufferFormatChangesSetsVisibilityChangeFlag) {
+ // add a default buffer and make the layer opaque
+ setFlags(1, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
+ setBuffer(1,
+ std::make_shared<
+ renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 1ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ GRALLOC_USAGE_PROTECTED /*usage*/));
+
+ mLifecycleManager.commitChanges();
+
+ // set new buffer with an opaque buffer format
+ setBuffer(1,
+ std::make_shared<
+ renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 2ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGB_888,
+ GRALLOC_USAGE_PROTECTED /*usage*/));
+ EXPECT_EQ(mLifecycleManager.getGlobalChanges().get(),
+ ftl::Flags<RequestedLayerState::Changes>(RequestedLayerState::Changes::Buffer |
+ RequestedLayerState::Changes::Content |
+ RequestedLayerState::Changes::VisibleRegion |
+ RequestedLayerState::Changes::Visibility)
+ .get());
+ mLifecycleManager.commitChanges();
+}
+
+TEST_F(LayerLifecycleManagerTest, roundedCornerChangesSetsVisibilityChangeFlag) {
+ // add a default buffer and make the layer opaque
+ setFlags(1, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
+ setBuffer(1,
+ std::make_shared<
+ renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 1ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ GRALLOC_USAGE_PROTECTED /*usage*/));
+
+ mLifecycleManager.commitChanges();
+
+ // add rounded corners which should make the layer translucent
+ setRoundedCorners(1, 5.f);
+ EXPECT_EQ(mLifecycleManager.getGlobalChanges().get(),
+ ftl::Flags<RequestedLayerState::Changes>(
+ RequestedLayerState::Changes::AffectsChildren |
+ RequestedLayerState::Changes::Content |
+ RequestedLayerState::Changes::Geometry |
+ RequestedLayerState::Changes::VisibleRegion)
+ .get());
+ mLifecycleManager.commitChanges();
+}
+
} // namespace android::surfaceflinger::frontend
diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
index 80d913c..72ed4c8 100644
--- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
@@ -770,4 +770,17 @@
EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
}
+TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
+ setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
+ layer_state_t::eLayerIsRefreshRateIndicator);
+ setBuffer(1,
+ std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
+ 42ULL /* bufferId */,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ 0 /*usage*/));
+ UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
+ EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
+ aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
+}
+
} // namespace android::surfaceflinger::frontend
diff --git a/services/surfaceflinger/tests/unittests/SmallAreaDetectionAllowMappingsTest.cpp b/services/surfaceflinger/tests/unittests/SmallAreaDetectionAllowMappingsTest.cpp
new file mode 100644
index 0000000..b910485
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/SmallAreaDetectionAllowMappingsTest.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "SmallAreaDetectionAllowMappingsTest"
+
+#include <gtest/gtest.h>
+
+#include "Scheduler/SmallAreaDetectionAllowMappings.h"
+
+namespace android::scheduler {
+
+class SmallAreaDetectionMappingsAllowTest : public testing::Test {
+protected:
+ SmallAreaDetectionAllowMappings mMappings;
+};
+
+namespace {
+TEST_F(SmallAreaDetectionMappingsAllowTest, testUpdate) {
+ const uid_t uid1 = 10100;
+ const uid_t uid2 = 10101;
+ const float threshold1 = 0.05f;
+ const float threshold2 = 0.07f;
+ std::vector<std::pair<uid_t, float>> mappings;
+ mappings.reserve(2);
+ mappings.push_back(std::make_pair(uid1, threshold1));
+ mappings.push_back(std::make_pair(uid2, threshold2));
+
+ mMappings.update(mappings);
+ ASSERT_EQ(mMappings.getThresholdForUid(uid1).value(), threshold1);
+ ASSERT_EQ(mMappings.getThresholdForUid(uid2).value(), threshold2);
+}
+
+TEST_F(SmallAreaDetectionMappingsAllowTest, testSetThesholdForUid) {
+ const uid_t uid = 10111;
+ const float threshold = 0.05f;
+
+ mMappings.setThesholdForUid(uid, threshold);
+ ASSERT_EQ(mMappings.getThresholdForUid(uid), threshold);
+}
+
+TEST_F(SmallAreaDetectionMappingsAllowTest, testUidNotInTheMappings) {
+ const uid_t uid = 10222;
+ ASSERT_EQ(mMappings.getThresholdForUid(uid), std::nullopt);
+}
+
+} // namespace
+} // namespace android::scheduler
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
index dbf0cd8..28162f4 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
@@ -47,7 +47,7 @@
const auto& display = getCurrentDisplayState(displayToken);
EXPECT_TRUE(display.isVirtual());
EXPECT_EQ(display.requestedRefreshRate, Fps::fromValue(requestedRefreshRate));
- EXPECT_EQ(name.string(), display.displayName);
+ EXPECT_EQ(name.c_str(), display.displayName);
std::optional<VirtualDisplayId> vid =
DisplayId::fromValue<VirtualDisplayId>(displayId | DisplayId::FLAG_VIRTUAL);