[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) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-03-30 14:55:53 -06:00
1 parent f776a25657
commit 5cd2461db9
4 files changed
+35 -29

No files matched your search

+5 -5
View File
@@ -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 ()
+21 -4
View File
@@ -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 <typename app_t>
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");
+6 -17
View File
@@ -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. */
+3 -3
View File
@@ -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