summaryrefslogtreecommitdiff
path: root/libs/gui/FrameRateUtils.cpp
diff options
context:
space:
mode:
author Ady Abraham <adyabr@google.com> 2023-09-07 18:45:58 -0700
committer Ady Abraham <adyabr@google.com> 2023-09-14 15:54:13 -0700
commit6cdd3fd7dab0149041ee8dd7273fe83888d2b1e3 (patch)
treed16cd080fb54219293612a4e97496e02460f6392 /libs/gui/FrameRateUtils.cpp
parent3821b0df36c612755b711d8d5a7b63377d7cf5d9 (diff)
libgui: plumb setFrameRate thru BufferQueue
The current implementation just assumes that the Surface and BLASTBufferQueue lives in the same process and rely on inheritance to handle setFrameRate. This doesn't work for any usecase that the Surface is Parceled to a diffrent process. Bug: 281695725 Test: atest CtsGraphicsTestCases --test-filter SetFrameRateTest* Change-Id: I4e08b92b618fa7b863ca3ef4f7b46d9f1c30c775
Diffstat (limited to 'libs/gui/FrameRateUtils.cpp')
-rw-r--r--libs/gui/FrameRateUtils.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/libs/gui/FrameRateUtils.cpp b/libs/gui/FrameRateUtils.cpp
new file mode 100644
index 0000000000..6993bfab45
--- /dev/null
+++ b/libs/gui/FrameRateUtils.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gui/Flags.h>
+#include <gui/FrameRateUtils.h>
+#include <system/window.h>
+#include <utils/Log.h>
+
+#include <cmath>
+
+namespace android {
+// Returns true if the frameRate is valid.
+//
+// @param frameRate the frame rate in Hz
+// @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_*
+// @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_*
+// @param functionName calling function or nullptr. Used for logging
+// @param privileged whether caller has unscoped surfaceflinger access
+bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
+ const char* inFunctionName, bool privileged) {
+ const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
+ int floatClassification = std::fpclassify(frameRate);
+ if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
+ ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
+ return false;
+ }
+
+ if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
+ compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
+ (!privileged ||
+ (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
+ compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
+ ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
+ compatibility, privileged ? "yes" : "no");
+ return false;
+ }
+
+ if (__builtin_available(android 31, *)) {
+ if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
+ changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
+ ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
+ changeFrameRateStrategy);
+ if (FLAG_BQ_SET_FRAME_RATE) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace android