diff --git a/CMakeLists.txt b/CMakeLists.txt index 09cf41caa..a8d26a50f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -271,11 +271,8 @@ set (vector_project_headers ) set (gpu_project_sources ${PROJECT_SOURCE_DIR}/src/hb-gpu.cc - ${PROJECT_SOURCE_DIR}/src/hb-gpu-shaders.cc ${PROJECT_SOURCE_DIR}/src/hb-gpu-draw.cc - ${PROJECT_SOURCE_DIR}/src/hb-gpu-draw-shaders.cc ${PROJECT_SOURCE_DIR}/src/hb-gpu-paint.cc - ${PROJECT_SOURCE_DIR}/src/hb-gpu-paint-shaders.cc ) set (gpu_project_headers ${PROJECT_SOURCE_DIR}/src/hb-gpu.h diff --git a/src/harfbuzz-world.cc b/src/harfbuzz-world.cc index 42fe4a933..2def1672e 100644 --- a/src/harfbuzz-world.cc +++ b/src/harfbuzz-world.cc @@ -102,11 +102,8 @@ #endif #ifdef HB_HAS_GPU -#include "hb-gpu-draw-shaders.cc" #include "hb-gpu-draw.cc" -#include "hb-gpu-paint-shaders.cc" #include "hb-gpu-paint.cc" -#include "hb-gpu-shaders.cc" #include "hb-gpu.cc" #include "hb-static.cc" #endif diff --git a/src/hb-gpu-draw-shaders.cc b/src/hb-gpu-draw-shaders.cc deleted file mode 100644 index c1d9d0576..000000000 --- a/src/hb-gpu-draw-shaders.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2026 Behdad Esfahbod - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Author(s): Behdad Esfahbod - */ - -#include "hb.hh" - -#include "hb-gpu.h" - -#include "hb-gpu-draw-fragment-glsl.hh" -#include "hb-gpu-draw-fragment-msl.hh" -#include "hb-gpu-draw-fragment-wgsl.hh" -#include "hb-gpu-draw-fragment-hlsl.hh" - - -/** - * hb_gpu_draw_shader_source: - * @stage: pipeline stage (vertex or fragment) - * @lang: shader language variant - * - * Returns the draw-renderer-specific shader source for the - * specified stage and language. The returned string is static - * and must not be freed. - * - * This source assumes the shared helpers returned by - * hb_gpu_shader_source() are concatenated ahead of it. The - * caller should assemble the full shader as - * `#version`-directive + hb_gpu_shader_source() + - * hb_gpu_draw_shader_source() + caller's `main()`. - * - * The vertex stage currently has no draw-specific helpers; this - * function returns an empty string for that stage so the caller - * can concatenate unconditionally. - * - * Return value: (transfer none): - * A shader source string, or `NULL` if @stage or @lang is - * unsupported. - * - * XSince: REPLACEME - **/ -const char * -hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage, - hb_gpu_shader_lang_t lang) -{ - switch (stage) { - case HB_GPU_SHADER_STAGE_FRAGMENT: - switch (lang) { - case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_draw_fragment_glsl; - case HB_GPU_SHADER_LANG_MSL: return hb_gpu_draw_fragment_msl; - case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_draw_fragment_wgsl; - case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_draw_fragment_hlsl; - default: return nullptr; - } - case HB_GPU_SHADER_STAGE_VERTEX: - switch (lang) { - case HB_GPU_SHADER_LANG_GLSL: - case HB_GPU_SHADER_LANG_MSL: - case HB_GPU_SHADER_LANG_WGSL: - case HB_GPU_SHADER_LANG_HLSL: return ""; - default: return nullptr; - } - default: - return nullptr; - } -} diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index 37026f136..f4c689932 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -1168,3 +1168,60 @@ hb_gpu_draw_recycle_blob (hb_gpu_draw_t *draw, return; draw->recycled_blob = blob; } + + +#include "hb-gpu-draw-fragment-glsl.hh" +#include "hb-gpu-draw-fragment-msl.hh" +#include "hb-gpu-draw-fragment-wgsl.hh" +#include "hb-gpu-draw-fragment-hlsl.hh" + +/** + * hb_gpu_draw_shader_source: + * @stage: pipeline stage (vertex or fragment) + * @lang: shader language variant + * + * Returns the draw-renderer-specific shader source for the + * specified stage and language. The returned string is static + * and must not be freed. + * + * This source assumes the shared helpers returned by + * hb_gpu_shader_source() are concatenated ahead of it. The + * caller should assemble the full shader as + * `#version`-directive + hb_gpu_shader_source() + + * hb_gpu_draw_shader_source() + caller's `main()`. + * + * The vertex stage currently has no draw-specific helpers; this + * function returns an empty string for that stage so the caller + * can concatenate unconditionally. + * + * Return value: (transfer none): + * A shader source string, or `NULL` if @stage or @lang is + * unsupported. + * + * XSince: REPLACEME + **/ +const char * +hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage, + hb_gpu_shader_lang_t lang) +{ + switch (stage) { + case HB_GPU_SHADER_STAGE_FRAGMENT: + switch (lang) { + case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_draw_fragment_glsl; + case HB_GPU_SHADER_LANG_MSL: return hb_gpu_draw_fragment_msl; + case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_draw_fragment_wgsl; + case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_draw_fragment_hlsl; + default: return nullptr; + } + case HB_GPU_SHADER_STAGE_VERTEX: + switch (lang) { + case HB_GPU_SHADER_LANG_GLSL: + case HB_GPU_SHADER_LANG_MSL: + case HB_GPU_SHADER_LANG_WGSL: + case HB_GPU_SHADER_LANG_HLSL: return ""; + default: return nullptr; + } + default: + return nullptr; + } +} diff --git a/src/hb-gpu-paint-shaders.cc b/src/hb-gpu-paint-shaders.cc deleted file mode 100644 index a46ef5ab1..000000000 --- a/src/hb-gpu-paint-shaders.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2026 Behdad Esfahbod - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Author(s): Behdad Esfahbod - */ - -#include "hb.hh" - -#include "hb-gpu.h" - - -/** - * hb_gpu_paint_shader_source: - * @stage: pipeline stage (vertex or fragment) - * @lang: shader language variant - * - * Returns the paint-renderer-specific shader source for the - * specified stage and language. The returned string is static - * and must not be freed. - * - * This source assumes the shared helpers returned by - * hb_gpu_shader_source() are concatenated ahead of it. The - * caller should assemble the full shader as - * `#version`-directive + hb_gpu_shader_source() + - * hb_gpu_paint_shader_source() + caller's `main()`. - * - * The paint-renderer shaders have not yet been implemented; this - * function currently returns an empty string for supported - * @stage / @lang combinations so callers can concatenate - * unconditionally. - * - * Return value: (transfer none): - * A shader source string, or `NULL` if @stage or @lang is - * unsupported. - * - * XSince: REPLACEME - **/ -const char * -hb_gpu_paint_shader_source (hb_gpu_shader_stage_t stage, - hb_gpu_shader_lang_t lang) -{ - switch (stage) { - case HB_GPU_SHADER_STAGE_FRAGMENT: - case HB_GPU_SHADER_STAGE_VERTEX: - switch (lang) { - case HB_GPU_SHADER_LANG_GLSL: - case HB_GPU_SHADER_LANG_MSL: - case HB_GPU_SHADER_LANG_WGSL: - case HB_GPU_SHADER_LANG_HLSL: return ""; - default: return nullptr; - } - default: - return nullptr; - } -} diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 65867f320..5a329ff18 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -122,3 +122,49 @@ hb_gpu_paint_get_user_data (const hb_gpu_paint_t *paint, { return hb_object_get_user_data (paint, key); } + + +/** + * hb_gpu_paint_shader_source: + * @stage: pipeline stage (vertex or fragment) + * @lang: shader language variant + * + * Returns the paint-renderer-specific shader source for the + * specified stage and language. The returned string is static + * and must not be freed. + * + * This source assumes the shared helpers returned by + * hb_gpu_shader_source() are concatenated ahead of it. The + * caller should assemble the full shader as + * `#version`-directive + hb_gpu_shader_source() + + * hb_gpu_paint_shader_source() + caller's `main()`. + * + * The paint-renderer shaders have not yet been implemented; this + * function currently returns an empty string for supported + * @stage / @lang combinations so callers can concatenate + * unconditionally. + * + * Return value: (transfer none): + * A shader source string, or `NULL` if @stage or @lang is + * unsupported. + * + * XSince: REPLACEME + **/ +const char * +hb_gpu_paint_shader_source (hb_gpu_shader_stage_t stage, + hb_gpu_shader_lang_t lang) +{ + switch (stage) { + case HB_GPU_SHADER_STAGE_FRAGMENT: + case HB_GPU_SHADER_STAGE_VERTEX: + switch (lang) { + case HB_GPU_SHADER_LANG_GLSL: + case HB_GPU_SHADER_LANG_MSL: + case HB_GPU_SHADER_LANG_WGSL: + case HB_GPU_SHADER_LANG_HLSL: return ""; + default: return nullptr; + } + default: + return nullptr; + } +} diff --git a/src/hb-gpu-shaders.cc b/src/hb-gpu-shaders.cc deleted file mode 100644 index f2a2b1424..000000000 --- a/src/hb-gpu-shaders.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2026 Behdad Esfahbod - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Author(s): Behdad Esfahbod - */ - -#include "hb.hh" - -#include "hb-gpu.h" - -#include "hb-gpu-fragment-glsl.hh" -#include "hb-gpu-fragment-msl.hh" -#include "hb-gpu-fragment-wgsl.hh" -#include "hb-gpu-fragment-hlsl.hh" -#include "hb-gpu-vertex-glsl.hh" -#include "hb-gpu-vertex-msl.hh" -#include "hb-gpu-vertex-wgsl.hh" -#include "hb-gpu-vertex-hlsl.hh" - - -/** - * hb_gpu_shader_source: - * @stage: pipeline stage (vertex or fragment) - * @lang: shader language variant - * - * Returns the shared helper shader source used by the hb-gpu - * renderers for the specified stage and language. The returned - * string is static and must not be freed. - * - * The shared source defines utilities such as the atlas sampler - * and the `hb_gpu_fetch()` accessor for the fragment stage, and - * the `hb_gpu_dilate()` helper for the vertex stage. Each - * renderer-specific source (for example, - * hb_gpu_draw_shader_source()) assumes these helpers are already - * in scope — callers should concatenate a `#version` directive, - * then this shared source, then the renderer-specific source, - * then their own `main()`. - * - * Return value: (transfer none): - * A shader source string, or `NULL` if @stage or @lang is - * unsupported. - * - * XSince: REPLACEME - **/ -const char * -hb_gpu_shader_source (hb_gpu_shader_stage_t stage, - hb_gpu_shader_lang_t lang) -{ - switch (stage) { - case HB_GPU_SHADER_STAGE_FRAGMENT: - switch (lang) { - case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_fragment_glsl; - case HB_GPU_SHADER_LANG_MSL: return hb_gpu_fragment_msl; - case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_fragment_wgsl; - case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_fragment_hlsl; - default: return nullptr; - } - case HB_GPU_SHADER_STAGE_VERTEX: - switch (lang) { - case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_vertex_glsl; - case HB_GPU_SHADER_LANG_MSL: return hb_gpu_vertex_msl; - case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_vertex_wgsl; - case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_vertex_hlsl; - default: return nullptr; - } - default: - return nullptr; - } -} diff --git a/src/hb-gpu.cc b/src/hb-gpu.cc index bc0543117..ec6adeb53 100644 --- a/src/hb-gpu.cc +++ b/src/hb-gpu.cc @@ -338,3 +338,63 @@ * coverage = hb_gpu_stem_darken (coverage, brightness, ppem); * ]| **/ + + +#include "hb-gpu-fragment-glsl.hh" +#include "hb-gpu-fragment-msl.hh" +#include "hb-gpu-fragment-wgsl.hh" +#include "hb-gpu-fragment-hlsl.hh" +#include "hb-gpu-vertex-glsl.hh" +#include "hb-gpu-vertex-msl.hh" +#include "hb-gpu-vertex-wgsl.hh" +#include "hb-gpu-vertex-hlsl.hh" + +/** + * hb_gpu_shader_source: + * @stage: pipeline stage (vertex or fragment) + * @lang: shader language variant + * + * Returns the shared helper shader source used by the hb-gpu + * renderers for the specified stage and language. The returned + * string is static and must not be freed. + * + * The shared source defines utilities such as the atlas sampler + * and the `hb_gpu_fetch()` accessor for the fragment stage, and + * the `hb_gpu_dilate()` helper for the vertex stage. Each + * renderer-specific source (for example, + * hb_gpu_draw_shader_source()) assumes these helpers are already + * in scope — callers should concatenate a `#version` directive, + * then this shared source, then the renderer-specific source, + * then their own `main()`. + * + * Return value: (transfer none): + * A shader source string, or `NULL` if @stage or @lang is + * unsupported. + * + * XSince: REPLACEME + **/ +const char * +hb_gpu_shader_source (hb_gpu_shader_stage_t stage, + hb_gpu_shader_lang_t lang) +{ + switch (stage) { + case HB_GPU_SHADER_STAGE_FRAGMENT: + switch (lang) { + case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_fragment_glsl; + case HB_GPU_SHADER_LANG_MSL: return hb_gpu_fragment_msl; + case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_fragment_wgsl; + case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_fragment_hlsl; + default: return nullptr; + } + case HB_GPU_SHADER_STAGE_VERTEX: + switch (lang) { + case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_vertex_glsl; + case HB_GPU_SHADER_LANG_MSL: return hb_gpu_vertex_msl; + case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_vertex_wgsl; + case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_vertex_hlsl; + default: return nullptr; + } + default: + return nullptr; + } +} diff --git a/src/meson.build b/src/meson.build index e01e14b97..38744e183 100644 --- a/src/meson.build +++ b/src/meson.build @@ -851,11 +851,8 @@ endforeach hb_gpu_sources = files( 'hb-gpu.cc', - 'hb-gpu-shaders.cc', 'hb-gpu-draw.cc', - 'hb-gpu-draw-shaders.cc', 'hb-gpu-paint.cc', - 'hb-gpu-paint-shaders.cc', 'hb-static.cc', )