setFrameRate: Make shouldBeSeamless an enum
Change the shouldBeSeamless parameter to an enum
in order to make the API easier to understand.
This changes
- SurfaceControl.setFrameRate
- Surface.setFrameRate
- ANativeWindow_setFrameRateWithChangeStrategy
- ASurfaceTransaction_setFrameRateWithChangeStrategy
Bug: 179116474
Test: atest SetFrameRateTest
Change-Id: I28a8863ea77101f90b878fbda5f00d98e075b7cc
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index 82c9268..3f545b2 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -544,11 +544,13 @@
}).detach();
}
- status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless) override {
- if (!ValidateFrameRate(frameRate, compatibility, "BBQSurface::setFrameRate")) {
+ status_t setFrameRate(float frameRate, int8_t compatibility,
+ int8_t changeFrameRateStrategy) override {
+ if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy,
+ "BBQSurface::setFrameRate")) {
return BAD_VALUE;
}
- return mBbq->setFrameRate(frameRate, compatibility, shouldBeSeamless);
+ return mBbq->setFrameRate(frameRate, compatibility, changeFrameRateStrategy);
}
status_t setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInfo) override {
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index f44f10a..71215fe 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -1012,39 +1012,15 @@
}
status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
- int8_t compatibility, bool shouldBeSeamless) override {
+ int8_t compatibility, int8_t changeFrameRateStrategy) override {
Parcel data, reply;
- status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
- return err;
- }
+ SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
+ SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(surface));
+ SAFE_PARCEL(data.writeFloat, frameRate);
+ SAFE_PARCEL(data.writeByte, compatibility);
+ SAFE_PARCEL(data.writeByte, changeFrameRateStrategy);
- err = data.writeStrongBinder(IInterface::asBinder(surface));
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
- return err;
- }
-
- err = data.writeFloat(frameRate);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
- return err;
- }
-
- err = data.writeByte(compatibility);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
- return err;
- }
-
- err = data.writeBool(shouldBeSeamless);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed writing bool: %s (%d)", strerror(-err), -err);
- return err;
- }
-
- err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
+ status_t err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
if (err != NO_ERROR) {
ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
return err;
@@ -1873,36 +1849,24 @@
case SET_FRAME_RATE: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
sp<IBinder> binder;
- status_t err = data.readStrongBinder(&binder);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
- return err;
- }
+ SAFE_PARCEL(data.readStrongBinder, &binder);
+
sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
if (!surface) {
- ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
- strerror(-err), -err);
- return err;
+ ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer");
+ return BAD_VALUE;
}
float frameRate;
- err = data.readFloat(&frameRate);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
- return err;
- }
+ SAFE_PARCEL(data.readFloat, &frameRate);
+
int8_t compatibility;
- err = data.readByte(&compatibility);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
- return err;
- }
- bool shouldBeSeamless;
- err = data.readBool(&shouldBeSeamless);
- if (err != NO_ERROR) {
- ALOGE("setFrameRate: failed to read bool: %s (%d)", strerror(-err), -err);
- return err;
- }
- status_t result = setFrameRate(surface, frameRate, compatibility, shouldBeSeamless);
+ SAFE_PARCEL(data.readByte, &compatibility);
+
+ int8_t changeFrameRateStrategy;
+ SAFE_PARCEL(data.readByte, &changeFrameRateStrategy);
+
+ status_t result =
+ setFrameRate(surface, frameRate, compatibility, changeFrameRateStrategy);
reply->writeInt32(result);
return NO_ERROR;
}
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 04a8785..2c4dfc5 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -19,6 +19,7 @@
#include <apex/window.h>
#include <inttypes.h>
+#include <android/native_window.h>
#include <binder/Parcel.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/ISurfaceComposerClient.h>
@@ -60,7 +61,7 @@
frameRateSelectionPriority(-1),
frameRate(0.0f),
frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
- shouldBeSeamless(true),
+ changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
fixedTransformHint(ui::Transform::ROT_INVALID),
frameNumber(0),
frameTimelineInfo(),
@@ -148,7 +149,7 @@
SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
SAFE_PARCEL(output.writeFloat, frameRate);
SAFE_PARCEL(output.writeByte, frameRateCompatibility);
- SAFE_PARCEL(output.writeBool, shouldBeSeamless);
+ SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
SAFE_PARCEL(output.writeUint32, fixedTransformHint);
SAFE_PARCEL(output.writeUint64, frameNumber);
SAFE_PARCEL(frameTimelineInfo.write, output);
@@ -269,7 +270,7 @@
SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
SAFE_PARCEL(input.readFloat, &frameRate);
SAFE_PARCEL(input.readByte, &frameRateCompatibility);
- SAFE_PARCEL(input.readBool, &shouldBeSeamless);
+ SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
SAFE_PARCEL(input.readUint32, &tmpUint32);
fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
SAFE_PARCEL(input.readUint64, &frameNumber);
@@ -526,7 +527,7 @@
what |= eFrameRateChanged;
frameRate = other.frameRate;
frameRateCompatibility = other.frameRateCompatibility;
- shouldBeSeamless = other.shouldBeSeamless;
+ changeFrameRateStrategy = other.changeFrameRateStrategy;
}
if (other.what & eFixedTransformHintChanged) {
what |= eFixedTransformHintChanged;
@@ -616,8 +617,8 @@
return NO_ERROR;
}
-bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName,
- bool privileged) {
+bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
+ const char* inFunctionName, bool privileged) {
const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
int floatClassification = std::fpclassify(frameRate);
if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
@@ -633,6 +634,12 @@
return false;
}
+ if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
+ changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
+ ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
+ changeFrameRateStrategy);
+ }
+
return true;
}
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 6de3e97..2fc9d47 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1729,8 +1729,8 @@
int Surface::dispatchSetFrameRate(va_list args) {
float frameRate = static_cast<float>(va_arg(args, double));
int8_t compatibility = static_cast<int8_t>(va_arg(args, int));
- bool shouldBeSeamless = static_cast<bool>(va_arg(args, int));
- return setFrameRate(frameRate, compatibility, shouldBeSeamless);
+ int8_t changeFrameRateStrategy = static_cast<int8_t>(va_arg(args, int));
+ return setFrameRate(frameRate, compatibility, changeFrameRateStrategy);
}
int Surface::dispatchAddCancelInterceptor(va_list args) {
@@ -2575,16 +2575,18 @@
mSurfaceListener->onBuffersDiscarded(discardedBufs);
}
-status_t Surface::setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless) {
+status_t Surface::setFrameRate(float frameRate, int8_t compatibility,
+ int8_t changeFrameRateStrategy) {
ATRACE_CALL();
ALOGV("Surface::setFrameRate");
- if (!ValidateFrameRate(frameRate, compatibility, "Surface::setFrameRate")) {
+ if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy,
+ "Surface::setFrameRate")) {
return BAD_VALUE;
}
return composerService()->setFrameRate(mGraphicBufferProducer, frameRate, compatibility,
- shouldBeSeamless);
+ changeFrameRateStrategy);
}
status_t Surface::setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInfo) {
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 18a0cbd..3c10858 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1511,7 +1511,7 @@
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility,
- bool shouldBeSeamless) {
+ int8_t changeFrameRateStrategy) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
@@ -1519,7 +1519,8 @@
}
// Allow privileged values as well here, those will be ignored by SF if
// the caller is not privileged
- if (!ValidateFrameRate(frameRate, compatibility, "Transaction::setFrameRate",
+ if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy,
+ "Transaction::setFrameRate",
/*privileged=*/true)) {
mStatus = BAD_VALUE;
return *this;
@@ -1527,7 +1528,7 @@
s->what |= layer_state_t::eFrameRateChanged;
s->frameRate = frameRate;
s->frameRateCompatibility = compatibility;
- s->shouldBeSeamless = shouldBeSeamless;
+ s->changeFrameRateStrategy = changeFrameRateStrategy;
return *this;
}
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 88cfe4b..3cf9a73 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -461,7 +461,7 @@
* Sets the intended frame rate for a surface. See ANativeWindow_setFrameRate() for more info.
*/
virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
- int8_t compatibility, bool shouldBeSeamless) = 0;
+ int8_t compatibility, int8_t changeFrameRateStrategy) = 0;
/*
* Acquire a frame rate flexibility token from SurfaceFlinger. While this token is acquired,
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index f7a6698..cc8cc0d 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -208,7 +208,7 @@
// Layer frame rate and compatibility. See ANativeWindow_setFrameRate().
float frameRate;
int8_t frameRateCompatibility;
- bool shouldBeSeamless;
+ int8_t changeFrameRateStrategy;
// Set by window manager indicating the layer and all its children are
// in a different orientation than the display. The hint suggests that
@@ -305,10 +305,11 @@
//
// @param frameRate the frame rate in Hz
// @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_*
+// @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_*
// @param functionName calling function or nullptr. Used for logging
// @param privileged whether caller has unscoped surfaceflinger access
-bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* functionName,
- bool privileged = false);
+bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
+ const char* functionName, bool privileged = false);
struct CaptureArgs {
const static int32_t UNSET_UID = -1;
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index 5881221..d22bdaa 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -187,7 +187,8 @@
status_t getUniqueId(uint64_t* outId) const;
status_t getConsumerUsage(uint64_t* outUsage) const;
- virtual status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless);
+ virtual status_t setFrameRate(float frameRate, int8_t compatibility,
+ int8_t changeFrameRateStrategy);
virtual status_t setFrameTimelineInfo(const FrameTimelineInfo& info);
virtual status_t getExtraBufferCount(int* extraBuffers) const;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 40c4135..4997e36 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -509,7 +509,7 @@
Transaction& setShadowRadius(const sp<SurfaceControl>& sc, float cornerRadius);
Transaction& setFrameRate(const sp<SurfaceControl>& sc, float frameRate,
- int8_t compatibility, bool shouldBeSeamless);
+ int8_t compatibility, int8_t changeFrameRateStrategy);
// Set by window manager indicating the layer and all its children are
// in a different orientation than the display. The hint suggests that
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index e8fb71d..68c834d 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -855,7 +855,7 @@
}
status_t setFrameRate(const sp<IGraphicBufferProducer>& /*surface*/, float /*frameRate*/,
- int8_t /*compatibility*/, bool /*shouldBeSeamless*/) override {
+ int8_t /*compatibility*/, int8_t /*changeFrameRateStrategy*/) override {
return NO_ERROR;
}