Skip to content

Commit

Permalink
config: remove experimental linear and merge into text-blending
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 13, 2025
1 parent fca336c commit a8b9c5b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
24 changes: 12 additions & 12 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,16 @@ const c = @cImport({
/// This is also sometimes known as "gamma correction".
/// (Currently only supported on macOS. Has no effect on Linux.)
///
/// To prevent the uneven thickness caused by linear blending, you can use
/// the `experimental-linear-correction` option which applies a correction
/// curve to the text alpha depending on its brightness, which compensates
/// for the thinning and makes the weight of most text appear very similar
/// to when it's blendeded non-linearly.
/// * `linear-corrected` - Corrects the thinning/thickening effect of linear
/// by applying a correction curve to the text alpha depending on its
/// brightness. This compensates for the thinning and makes the weight of
/// most text appear very similar to when it's blended non-linearly.
///
/// Note: This setting affects more than just text, images will also be blended
/// in the selected color space, and custom shaders will receive colors in that
/// color space as well.
@"text-blending": TextBlending = .native,

/// Apply a correction curve to text alpha to compensate for uneven apparent
/// thickness of different colors of text, roughly matching the appearance of
/// text rendered with non-linear blending.
///
/// Has no effect if not using linear `text-blending`.
@"experimental-linear-correction": bool = false,

/// All of the configurations behavior adjust various metrics determined by the
/// font. The values can be integers (1, -1, etc.) or a percentage (20%, -15%,
/// etc.). In each case, the values represent the amount to change the original
Expand Down Expand Up @@ -5787,6 +5779,14 @@ pub const GraphemeWidthMethod = enum {
pub const TextBlending = enum {
native,
linear,
@"linear-corrected",

pub fn isLinear(self: TextBlending) bool {
return switch (self) {
.native => false,
.linear, .@"linear-corrected" => true,
};
}
};

/// See freetype-load-flag
Expand Down
22 changes: 9 additions & 13 deletions src/renderer/Metal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ pub const DerivedConfig = struct {
vsync: bool,
colorspace: configpkg.Config.WindowColorspace,
blending: configpkg.Config.TextBlending,
experimental_linear_correction: bool,

pub fn init(
alloc_gpa: Allocator,
Expand Down Expand Up @@ -462,8 +461,6 @@ pub const DerivedConfig = struct {
.vsync = config.@"window-vsync",
.colorspace = config.@"window-colorspace",
.blending = config.@"text-blending",
.experimental_linear_correction = config.@"text-blending" == .linear and config.@"experimental-linear-correction",

.arena = arena,
};
}
Expand Down Expand Up @@ -559,7 +556,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
// the pixels written to it *after* blending, which means
// we get linear alpha blending rather than gamma-incorrect
// blending.
if (options.config.blending == .linear)
if (options.config.blending.isLinear())
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm_srgb)
else
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm),
Expand Down Expand Up @@ -655,8 +652,8 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
},
.cursor_wide = false,
.use_display_p3 = options.config.colorspace == .@"display-p3",
.use_linear_blending = options.config.blending == .linear,
.use_experimental_linear_correction = options.config.experimental_linear_correction,
.use_linear_blending = options.config.blending.isLinear(),
.use_experimental_linear_correction = options.config.blending == .@"linear-corrected",
},

// Fonts
Expand Down Expand Up @@ -774,7 +771,7 @@ fn initShaders(self: *Metal) !void {
// the pixels written to it *after* blending, which means
// we get linear alpha blending rather than gamma-incorrect
// blending.
if (self.config.blending == .linear)
if (self.config.blending.isLinear())
mtl.MTLPixelFormat.bgra8unorm_srgb
else
mtl.MTLPixelFormat.bgra8unorm,
Expand Down Expand Up @@ -2071,9 +2068,8 @@ pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void {

// Set our new color space and blending
self.uniforms.use_display_p3 = config.colorspace == .@"display-p3";
self.uniforms.use_linear_blending = config.blending == .linear;

self.uniforms.use_experimental_linear_correction = config.experimental_linear_correction;
self.uniforms.use_linear_blending = config.blending.isLinear();
self.uniforms.use_experimental_linear_correction = config.blending == .@"linear-corrected";

// Set our new colors
self.default_background_color = config.background;
Expand Down Expand Up @@ -2105,7 +2101,7 @@ pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void {
// And we update our layer's pixel format appropriately.
self.layer.setProperty(
"pixelFormat",
if (config.blending == .linear)
if (config.blending.isLinear())
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm_srgb)
else
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm),
Expand Down Expand Up @@ -2231,7 +2227,7 @@ pub fn setScreenSize(
// the pixels written to it *after* blending, which means
// we get linear alpha blending rather than gamma-incorrect
// blending.
if (self.config.blending == .linear)
if (self.config.blending.isLinear())
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm_srgb)
else
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm),
Expand Down Expand Up @@ -2271,7 +2267,7 @@ pub fn setScreenSize(
// the pixels written to it *after* blending, which means
// we get linear alpha blending rather than gamma-incorrect
// blending.
if (self.config.blending == .linear)
if (self.config.blending.isLinear())
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm_srgb)
else
@intFromEnum(mtl.MTLPixelFormat.bgra8unorm),
Expand Down

0 comments on commit a8b9c5b

Please sign in to comment.