Skip to content

Commit aaa80ee

Browse files
author
Rachel Lee
committed
Add new ANativeWindow_setFrameRateParams API
The new overload uses same plumbing and same logic as the other setFrameRate-like functions. This plumbing and logic will be upgraded to accommodate new parameters in a future CL. Bug: 362798998 Test: atest SetFrameRateTest Flag: EXEMPT NDK Change-Id: If29c32a92b48c36fe06c70db5505f73cea482637
1 parent fc8ace0 commit aaa80ee

4 files changed

Lines changed: 101 additions & 3 deletions

File tree

libs/nativewindow/ANativeWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, floa
263263
return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy);
264264
}
265265

266+
int32_t ANativeWindow_setFrameRateParams(
267+
ANativeWindow* window, float desiredMinRate, float desiredMaxRate, float fixedSourceRate,
268+
ANativeWindow_ChangeFrameRateStrategy changeFrameRateStrategy) {
269+
if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
270+
return -EINVAL;
271+
}
272+
return native_window_set_frame_rate_params(window, desiredMinRate, desiredMaxRate,
273+
fixedSourceRate, changeFrameRateStrategy);
274+
}
275+
266276
/**************************************************************************************************
267277
* vndk-stable
268278
**************************************************************************************************/

libs/nativewindow/include/android/native_window.h

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#ifndef ANDROID_NATIVE_WINDOW_H
3434
#define ANDROID_NATIVE_WINDOW_H
3535

36-
#include <stdint.h>
3736
#include <stdbool.h>
37+
#include <stdint.h>
3838
#include <sys/cdefs.h>
3939

4040
#include <android/data_space.h>
@@ -282,7 +282,7 @@ int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_
282282
void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) __INTRODUCED_IN(30);
283283

284284
/** Change frame rate strategy value for ANativeWindow_setFrameRate. */
285-
enum ANativeWindow_ChangeFrameRateStrategy {
285+
typedef enum ANativeWindow_ChangeFrameRateStrategy : int8_t {
286286
/**
287287
* Change the frame rate only if the transition is going to be seamless.
288288
*/
@@ -292,7 +292,7 @@ enum ANativeWindow_ChangeFrameRateStrategy {
292292
* i.e. with visual interruptions for the user.
293293
*/
294294
ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS = 1
295-
} __INTRODUCED_IN(31);
295+
} ANativeWindow_ChangeFrameRateStrategy __INTRODUCED_IN(31);
296296

297297
/**
298298
* Sets the intended frame rate for this window.
@@ -344,6 +344,76 @@ int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, floa
344344
int8_t compatibility, int8_t changeFrameRateStrategy)
345345
__INTRODUCED_IN(31);
346346

347+
/**
348+
* Sets the intended frame rate for this window.
349+
*
350+
* On devices that are capable of running the display at different frame rates,
351+
* the system may choose a display refresh rate to better match this surface's frame
352+
* rate. Usage of this API won't introduce frame rate throttling, or affect other
353+
* aspects of the application's frame production pipeline. However, because the system
354+
* may change the display refresh rate, calls to this function may result in changes
355+
* to Choreographer callback timings, and changes to the time interval at which the
356+
* system releases buffers back to the application.
357+
*
358+
* Note that this only has an effect for surfaces presented on the display. If this
359+
* surface is consumed by something other than the system compositor, e.g. a media
360+
* codec, this call has no effect.
361+
*
362+
* You can register for changes in the refresh rate using
363+
* \a AChoreographer_registerRefreshRateCallback.
364+
*
365+
* See ANativeWindow_clearFrameRate().
366+
*
367+
* Available since API level 36.
368+
*
369+
* \param window pointer to an ANativeWindow object.
370+
*
371+
* \param desiredMinRate The desired minimum frame rate (inclusive) for the window, specifying that
372+
* the surface prefers the device render rate to be at least `desiredMinRate`.
373+
*
374+
* <p>Set `desiredMinRate` = `desiredMaxRate` to indicate the surface prefers an exact frame rate.
375+
*
376+
* <p>Set `desiredMinRate` = 0 to indicate the window has no preference
377+
* and any frame rate is acceptable.
378+
*
379+
* <p>The value should be greater than or equal to 0.
380+
*
381+
* \param desiredMaxRate The desired maximum frame rate (inclusive) for the window, specifying that
382+
* the surface prefers the device render rate to be at most `desiredMaxRate`.
383+
*
384+
* <p>Set `desiredMaxRate` = `desiredMinRate` to indicate the surface prefers an exact frame rate.
385+
*
386+
* <p>Set `desiredMaxRate` = positive infinity to indicate the window has no preference
387+
* and any frame rate is acceptable.
388+
*
389+
* <p>The value should be greater than or equal to `desiredMinRate`.
390+
*
391+
* \param fixedSourceRate The "fixed source" frame rate of the window if the content has an
392+
* inherently fixed frame rate, e.g. a video that has a specific frame rate.
393+
*
394+
* <p>When the frame rate chosen for the surface is the `fixedSourceRate` or a
395+
* multiple, the surface can render without frame pulldown, for optimal smoothness. For
396+
* example, a 30 fps video (`fixedSourceRate`=30) renders just as smoothly on 30 fps,
397+
* 60 fps, 90 fps, 120 fps, and so on.
398+
*
399+
* <p>Setting the fixed source rate can also be used together with a desired
400+
* frame rate min and max via setting `desiredMinRate` and `desiredMaxRate`. This still
401+
* means the window's content has a fixed frame rate of `fixedSourceRate`, but additionally
402+
* specifies the preference to be in the range [`desiredMinRate`, `desiredMaxRate`]. For example, an
403+
* app might want to specify there is 30 fps video (`fixedSourceRate`=30) as well as a smooth
404+
* animation on the same window which looks good when drawing within a frame rate range such as
405+
* [`desiredMinRate`, `desiredMaxRate`] = [60,120].
406+
*
407+
* \param changeFrameRateStrategy Whether display refresh rate transitions caused by this surface
408+
* should be seamless. A seamless transition is one that doesn't have any visual interruptions, such
409+
* as a black screen for a second or two.
410+
*
411+
* \return 0 for success, -EINVAL if the arguments are invalid.
412+
*/
413+
int32_t ANativeWindow_setFrameRateParams(
414+
ANativeWindow* window, float desiredMinRate, float desiredMaxRate, float fixedSourceRate,
415+
ANativeWindow_ChangeFrameRateStrategy changeFrameRateStrategy) __INTRODUCED_IN(36);
416+
347417
/**
348418
* Clears the frame rate which is set for this window.
349419
*

libs/nativewindow/include/system/window.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,23 @@ static inline int native_window_set_frame_rate(struct ANativeWindow* window, flo
11561156
(int)compatibility, (int)changeFrameRateStrategy);
11571157
}
11581158

1159+
static inline int native_window_set_frame_rate_params(struct ANativeWindow* window,
1160+
float desiredMinRate, float desiredMaxRate,
1161+
float fixedSourceRate,
1162+
int8_t changeFrameRateStrategy) {
1163+
// TODO(b/362798998): Fix plumbing to send whole params
1164+
int compatibility = fixedSourceRate == 0 ? ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT
1165+
: ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE;
1166+
double frameRate = compatibility == ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE
1167+
? fixedSourceRate
1168+
: desiredMinRate;
1169+
if (desiredMaxRate < desiredMinRate) {
1170+
return -EINVAL;
1171+
}
1172+
return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, frameRate, compatibility,
1173+
changeFrameRateStrategy);
1174+
}
1175+
11591176
struct ANativeWindowFrameTimelineInfo {
11601177
// Frame Id received from ANativeWindow_getNextFrameId.
11611178
uint64_t frameNumber;

libs/nativewindow/libnativewindow.map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ LIBNATIVEWINDOW {
5353
ANativeWindow_setBuffersTransform;
5454
ANativeWindow_setDequeueTimeout; # systemapi introduced=30
5555
ANativeWindow_setFrameRate; # introduced=30
56+
ANativeWindow_setFrameRateParams; # introduced=36
5657
ANativeWindow_setFrameRateWithChangeStrategy; # introduced=31
5758
ANativeWindow_setSharedBufferMode; # llndk
5859
ANativeWindow_setSwapInterval; # llndk

0 commit comments

Comments
 (0)