Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dummy display #396

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ OPTIONS:
If no hz value is given, the highest possible refreshrate
will be used.

--dummy-display Simulate a display. Useful for running apps
without a display attached.
--dummy-display-size "width,height" The width & height of the dummy display
in pixels.

-h, --help Show this help and exit.

EXAMPLES:
Expand Down
113 changes: 80 additions & 33 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ OPTIONS:\n\
--videomode widthxheight@hz Uses an output videomode that satisfies the argument.\n\
If no hz value is given, the highest possible refreshrate\n\
will be used.\n\
\n\
--dummy-display Simulate a display. Useful for running apps\n\
without a display attached.\n\
--dummy-display-size \"width,height\" The width & height of the dummy display\n\
in pixels.\n\
\n\
-h, --help Show this help and exit.\n\
\n\
Expand Down Expand Up @@ -1848,7 +1853,7 @@ struct cmd_args {
int rotation;

bool has_physical_dimensions;
int width_mm, height_mm;
struct vec2i physical_dimensions;

bool has_pixel_format;
enum pixfmt pixel_format;
Expand All @@ -1864,6 +1869,9 @@ struct cmd_args {
bool use_vulkan;

char *desired_videomode;

bool dummy_display;
struct vec2i dummy_display_size;
};

static struct flutter_paths *setup_paths(enum flutter_runtime_mode runtime_mode, const char *app_bundle_path) {
Expand All @@ -1877,10 +1885,22 @@ static struct flutter_paths *setup_paths(enum flutter_runtime_mode runtime_mode,
#endif
}

static bool parse_vec2i(const char *str, struct vec2i *out) {
int ok;

ok = sscanf(str, "%d,%d", &out->x, &out->y);
if (ok != 2) {
return false;
}

return true;
}

static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
bool finished_parsing_options;
int runtime_mode_int = FLUTTER_RUNTIME_MODE_DEBUG;
int vulkan_int = false;
int dummy_display_int = 0;
int longopt_index = 0;
int opt, ok;

Expand All @@ -1894,6 +1914,8 @@ static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
{ "pixelformat", required_argument, NULL, 'p' },
{ "vulkan", no_argument, &vulkan_int, true },
{ "videomode", required_argument, NULL, 'v' },
{ "dummy-display", no_argument, &dummy_display_int, 1 },
{ "dummy-display-size", required_argument, NULL, 's' },
{ 0, 0, 0, 0 },
};

Expand Down Expand Up @@ -1960,18 +1982,12 @@ static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
break;

case 'd':;
unsigned int width_mm, height_mm;

ok = sscanf(optarg, "%u,%u", &width_mm, &height_mm);
if (ok != 2) {
LOG_ERROR("ERROR: Invalid argument for --dimensions passed.\n%s", usage);
ok = parse_vec2i(optarg, &result_out->physical_dimensions);
if (!ok) {
LOG_ERROR("ERROR: Invalid argument for --dimensions passed.\n");
return false;
}

result_out->width_mm = width_mm;
result_out->height_mm = height_mm;
result_out->has_physical_dimensions = true;

break;

case 'p':
Expand Down Expand Up @@ -2004,6 +2020,15 @@ static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
result_out->desired_videomode = vmode_dup;
break;

case 's':; // --dummy-display-size
ok = parse_vec2i(optarg, &result_out->dummy_display_size);
if (!ok) {
LOG_ERROR("ERROR: Invalid argument for --dummy-display-size passed.\n");
return false;
}

break;

case 'h': printf("%s", usage); return false;

case '?':
Expand Down Expand Up @@ -2038,6 +2063,8 @@ static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
#endif
result_out->use_vulkan = vulkan_int;

result_out->dummy_display = !!dummy_display_int;

return true;
}

Expand Down Expand Up @@ -2311,6 +2338,11 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {

desired_videomode = cmd_args.desired_videomode;

if (bundle_path == NULL) {
LOG_ERROR("ERROR: Bundle path does not exist.\n");
goto fail_free_cmd_args;
}

paths = setup_paths(runtime_mode, bundle_path);
if (paths == NULL) {
goto fail_free_cmd_args;
Expand Down Expand Up @@ -2449,29 +2481,44 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
goto fail_unref_scheduler;
}

window = kms_window_new(
// clang-format off
tracer,
scheduler,
renderer_type,
gl_renderer,
vk_renderer,
cmd_args.has_rotation,
cmd_args.rotation == 0 ? PLANE_TRANSFORM_ROTATE_0 :
cmd_args.rotation == 90 ? PLANE_TRANSFORM_ROTATE_90 :
cmd_args.rotation == 180 ? PLANE_TRANSFORM_ROTATE_180 :
cmd_args.rotation == 270 ? PLANE_TRANSFORM_ROTATE_270 :
(assert(0 && "invalid rotation"), PLANE_TRANSFORM_ROTATE_0),
cmd_args.has_orientation, cmd_args.orientation,
cmd_args.has_physical_dimensions, cmd_args.width_mm, cmd_args.height_mm,
cmd_args.has_pixel_format, cmd_args.pixel_format,
drmdev,
desired_videomode
// clang-format on
);
if (window == NULL) {
LOG_ERROR("Couldn't create KMS window.\n");
goto fail_unref_renderer;
if (cmd_args.dummy_display) {
window = dummy_window_new(
tracer,
scheduler,
renderer_type,
gl_renderer,
vk_renderer,
cmd_args.dummy_display_size,
cmd_args.has_physical_dimensions,
cmd_args.physical_dimensions.x,
cmd_args.physical_dimensions.y,
60.0
);
} else {
window = kms_window_new(
// clang-format off
tracer,
scheduler,
renderer_type,
gl_renderer,
vk_renderer,
cmd_args.has_rotation,
cmd_args.rotation == 0 ? PLANE_TRANSFORM_ROTATE_0 :
cmd_args.rotation == 90 ? PLANE_TRANSFORM_ROTATE_90 :
cmd_args.rotation == 180 ? PLANE_TRANSFORM_ROTATE_180 :
cmd_args.rotation == 270 ? PLANE_TRANSFORM_ROTATE_270 :
(assert(0 && "invalid rotation"), PLANE_TRANSFORM_ROTATE_0),
cmd_args.has_orientation, cmd_args.orientation,
cmd_args.has_physical_dimensions, cmd_args.physical_dimensions.x, cmd_args.physical_dimensions.y,
cmd_args.has_pixel_format, cmd_args.pixel_format,
drmdev,
desired_videomode
// clang-format on
);
if (window == NULL) {
LOG_ERROR("Couldn't create KMS window.\n");
goto fail_unref_renderer;
}
}

compositor = compositor_new(tracer, window);
Expand Down
10 changes: 6 additions & 4 deletions src/util/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct vec2i {

#define VEC2I(_x, _y) ((struct vec2i){ .x = (_x), .y = (_y) })

ATTR_CONST static inline struct vec2i vec2f_round_to_integer(struct vec2f a) {
return VEC2I((int) round(a.x), (int) round(a.y));
}

ATTR_CONST static inline struct vec2i vec2i_add(struct vec2i a, struct vec2i b) {
return VEC2I(a.x + b.x, a.y + b.y);
}
Expand Down Expand Up @@ -130,10 +134,8 @@ ATTR_CONST static inline struct quad get_quad(const struct aa_rect rect) {
ATTR_CONST static inline bool quad_is_axis_aligned(const struct quad quad) {
struct aa_rect aa = quad_get_aa_bounding_rect(quad);

return vec2f_equals(quad.top_left, aa_rect_top_left(aa)) &&
vec2f_equals(quad.top_right, aa_rect_top_right(aa)) &&
vec2f_equals(quad.bottom_left, aa_rect_bottom_left(aa)) &&
vec2f_equals(quad.bottom_right, aa_rect_bottom_right(aa));
return vec2f_equals(quad.top_left, aa_rect_top_left(aa)) && vec2f_equals(quad.top_right, aa_rect_top_right(aa)) &&
vec2f_equals(quad.bottom_left, aa_rect_bottom_left(aa)) && vec2f_equals(quad.bottom_right, aa_rect_bottom_right(aa));
}

struct mat3f {
Expand Down
Loading
Loading