Skip to content

Commit

Permalink
Add --print-fps to enable FPS counter on start
Browse files Browse the repository at this point in the history
The FPS counter could be enabled/disabled via MOD+i.

Add a command line option to enable it on start. This is consistent with
other features like --turn-screen-off or --fullscreen).

Fixes #468 <#468>
  • Loading branch information
rom1v committed Feb 17, 2022
1 parent d221a67 commit 97ea47f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ scrcpy --max-fps 15

This is officially supported since Android 10, but may work on earlier versions.

The actual capture framerate may be printed to the console:

```
scrcpy --print-fps
```

It may also be enabled or disabled at any time with <kbd>MOD</kbd>+<kbd>i</kbd>.


#### Crop

The device screen may be cropped to mirror only part of the screen.
Expand Down
4 changes: 4 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ Inject alpha characters and space as text events instead of key events.
This avoids issues when combining multiple keys to enter special characters,
but breaks the expected behavior of alpha keys in games (typically WASD).

.TP
.B "\-\-print\-fps
Start FPS counter, to print framerate logs to the console. It can be started or stopped at any time with MOD+i.

.TP
.BI "\-\-push\-target " path
Set the target directory for pushing files to the device by drag & drop. It is passed as\-is to "adb push".
Expand Down
10 changes: 10 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#define OPT_NO_DOWNSIZE_ON_ERROR 1035
#define OPT_OTG 1036
#define OPT_NO_CLEANUP 1037
#define OPT_PRINT_FPS 1038

struct sc_option {
char shortopt;
Expand Down Expand Up @@ -336,6 +337,12 @@ static const struct sc_option options[] = {
"special character, but breaks the expected behavior of alpha "
"keys in games (typically WASD).",
},
{
.longopt_id = OPT_PRINT_FPS,
.longopt = "print-fps",
.text = "Start FPS counter, to print framerate logs to the console. "
"It can be started or stopped at any time with MOD+i.",
},
{
.longopt_id = OPT_PUSH_TARGET,
.longopt = "push-target",
Expand Down Expand Up @@ -1547,6 +1554,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
case OPT_NO_CLEANUP:
opts->cleanup = false;
break;
case OPT_PRINT_FPS:
opts->start_fps_counter = true;
break;
case OPT_OTG:
#ifdef HAVE_USB
opts->otg = true;
Expand Down
1 change: 1 addition & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ const struct scrcpy_options scrcpy_options_default = {
.select_tcpip = false,
.select_usb = false,
.cleanup = true,
.start_fps_counter = false,
};
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct scrcpy_options {
bool select_usb;
bool select_tcpip;
bool cleanup;
bool start_fps_counter;
};

extern const struct scrcpy_options scrcpy_options_default;
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ scrcpy(struct scrcpy_options *options) {
.rotation = options->rotation,
.mipmaps = options->mipmaps,
.fullscreen = options->fullscreen,
.start_fps_counter = options->start_fps_counter,
.buffering_time = options->display_buffer,
};

Expand Down
5 changes: 5 additions & 0 deletions app/src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ sc_screen_init(struct sc_screen *screen,
screen->req.width = params->window_width;
screen->req.height = params->window_height;
screen->req.fullscreen = params->fullscreen;
screen->req.start_fps_counter = params->start_fps_counter;

static const struct sc_video_buffer_callbacks cbs = {
.on_new_frame = sc_video_buffer_on_new_frame,
Expand Down Expand Up @@ -562,6 +563,10 @@ sc_screen_show_initial_window(struct sc_screen *screen) {
sc_screen_switch_fullscreen(screen);
}

if (screen->req.start_fps_counter) {
sc_fps_counter_start(&screen->fps_counter);
}

SDL_ShowWindow(screen->window);
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct sc_screen {
uint16_t width;
uint16_t height;
bool fullscreen;
bool start_fps_counter;
} req;

SDL_Window *window;
Expand Down Expand Up @@ -93,6 +94,7 @@ struct sc_screen_params {
bool mipmaps;

bool fullscreen;
bool start_fps_counter;

sc_tick buffering_time;
};
Expand Down

0 comments on commit 97ea47f

Please sign in to comment.