From 5cd2461db9c6ca232f66cda5b49422d5397f2c82 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 30 Mar 2026 14:55:53 -0600 Subject: [PATCH] [gpu] Rename hb-gpu-demo to hb-gpu, make installable The tool now requires a font file argument by default, like other hb-* tools. Pass --demo to use the built-in demo font and text. --metal is now a proper GLib option instead of manual argv parsing. Window title changed to "HarfBuzz GPU". Co-Authored-By: Claude Opus 4.6 (1M context) --- CMakeLists.txt | 10 +++++----- util/gpu-output.hh | 25 +++++++++++++++++++++---- util/{hb-gpu-demo.cc => hb-gpu.cc} | 23 ++++++----------------- util/meson.build | 6 +++--- 4 files changed, 35 insertions(+), 29 deletions(-) rename util/{hb-gpu-demo.cc => hb-gpu.cc} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf8224a9a..8ae6aa06e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1063,8 +1063,8 @@ if (HB_BUILD_UTILS) find_package(GLEW QUIET) find_package(glfw3 QUIET) if (OpenGL_FOUND AND GLEW_FOUND AND glfw3_FOUND) - add_executable(hb-gpu-demo - ${PROJECT_SOURCE_DIR}/util/hb-gpu-demo.cc + add_executable(hb-gpu + ${PROJECT_SOURCE_DIR}/util/hb-gpu.cc ${PROJECT_SOURCE_DIR}/util/gpu-output.hh ${PROJECT_SOURCE_DIR}/util/gpu/demo-atlas.cc ${PROJECT_SOURCE_DIR}/util/gpu/demo-buffer.cc @@ -1074,12 +1074,12 @@ if (HB_BUILD_UTILS) ${PROJECT_SOURCE_DIR}/util/gpu/demo-shader.cc ${PROJECT_SOURCE_DIR}/util/gpu/demo-view.cc ) - target_link_libraries(hb-gpu-demo harfbuzz-gpu harfbuzz + target_link_libraries(hb-gpu harfbuzz-gpu harfbuzz OpenGL::GL GLEW::GLEW glfw) if (APPLE) - target_sources(hb-gpu-demo PRIVATE + target_sources(hb-gpu PRIVATE ${PROJECT_SOURCE_DIR}/util/gpu/demo-metal.mm) - target_link_libraries(hb-gpu-demo + target_link_libraries(hb-gpu "-framework Metal" "-framework QuartzCore" "-framework Foundation" "-framework AppKit") endif () diff --git a/util/gpu-output.hh b/util/gpu-output.hh index 986e64865..415033a0b 100644 --- a/util/gpu-output.hh +++ b/util/gpu-output.hh @@ -43,9 +43,26 @@ struct gpu_output_t { static constexpr bool repeat_shape = false; - void add_options (option_parser_t *parser HB_UNUSED) {} + hb_bool_t use_metal = false; + hb_bool_t demo = false; - bool use_metal = false; + void add_options (option_parser_t *parser) + { + GOptionEntry entries[] = + { + {"demo", 0, 0, G_OPTION_ARG_NONE, &this->demo, "Use built-in demo font and text", nullptr}, +#ifdef __APPLE__ + {"metal", 0, 0, G_OPTION_ARG_NONE, &this->use_metal, "Use Metal renderer", nullptr}, +#endif + {nullptr} + }; + parser->add_group (entries, + "gpu", + "GPU options:", + "Options for GPU rendering", + this, + false); + } template void init (hb_buffer_t *buffer_ HB_UNUSED, const app_t *app) @@ -114,7 +131,7 @@ struct gpu_output_t #endif glfwWindowHint (GLFW_SRGB_CAPABLE, GLFW_TRUE); - window = glfwCreateWindow (WINDOW_W, WINDOW_H, "HarfBuzz GPU Demo", NULL, NULL); + window = glfwCreateWindow (WINDOW_W, WINDOW_H, "HarfBuzz GPU", NULL, NULL); if (!window) { glfwTerminate (); fail (false, "Failed to create GLFW window"); @@ -142,7 +159,7 @@ struct gpu_output_t #ifdef __APPLE__ glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API); - window = glfwCreateWindow (WINDOW_W, WINDOW_H, "HarfBuzz GPU Demo (Metal)", NULL, NULL); + window = glfwCreateWindow (WINDOW_W, WINDOW_H, "HarfBuzz GPU (Metal)", NULL, NULL); if (!window) { glfwTerminate (); fail (false, "Failed to create GLFW window"); diff --git a/util/hb-gpu-demo.cc b/util/hb-gpu.cc similarity index 92% rename from util/hb-gpu-demo.cc rename to util/hb-gpu.cc index 80aa1c1f0..d73666844 100644 --- a/util/hb-gpu-demo.cc +++ b/util/hb-gpu.cc @@ -117,12 +117,13 @@ build_default_text (hb_face_t *face) } static const char *gpu_default_text_sentinel = ""; +static hb_bool_t *gpu_demo_flag = nullptr; struct gpu_text_options_t : shape_text_options_t { const char *default_text () override { - return gpu_default_text_sentinel; + return (gpu_demo_flag && *gpu_demo_flag) ? gpu_default_text_sentinel : nullptr; } }; @@ -130,9 +131,8 @@ struct gpu_font_options_t : font_options_t { hb_face_t *default_face () override { -#ifdef _WIN32 - return nullptr; -#else + if (!gpu_demo_flag || !*gpu_demo_flag) + return nullptr; #include "gpu/default-font.hh" hb_blob_t *blob = hb_blob_create ((const char *) default_font, sizeof (default_font), @@ -141,7 +141,6 @@ struct gpu_font_options_t : font_options_t hb_face_t *face_ = hb_face_create (blob, 0); hb_blob_destroy (blob); return face_; -#endif } }; @@ -153,21 +152,11 @@ struct gpu_main_t : base_t { int operator () (int argc, char **argv) { + gpu_demo_flag = &this->output.demo; + add_options (); add_exit_code (RETURN_VALUE_OPERATION_FAILED, "Operation failed."); - /* Check for --metal before GLib eats the options. */ - for (int i = 1; i < argc; i++) - if (!strcmp (argv[i], "--metal")) - { - this->output.use_metal = true; - /* Remove from argv so GLib doesn't complain. */ - for (int j = i; j < argc - 1; j++) - argv[j] = argv[j + 1]; - argc--; - i--; - } - parse (&argc, &argv); /* If no text was provided, build from font's supported scripts. */ diff --git a/util/meson.build b/util/meson.build index 4d7677869..0c0144346 100644 --- a/util/meson.build +++ b/util/meson.build @@ -225,13 +225,13 @@ if not get_option('gpu').disabled() if host_machine.system() == 'darwin' gpu_demo_deps += metal_dep endif - hb_gpu_util = executable('hb-gpu-demo', - ['hb-gpu-demo.cc'] + gpu_demo_sources, + hb_gpu_util = executable('hb-gpu', + ['hb-gpu.cc'] + gpu_demo_sources, cpp_args: cpp_args, include_directories: [incconfig, incsrc], dependencies: gpu_demo_deps, link_with: [libharfbuzz, libharfbuzz_gpu], - install: false, + install: true, ) endif