gpui: improve font rendering on Windows
The move to DirectWrite was a substantial change in how the glyph atlas is produced. The initial implementation used ClearType but was downsampling to grayscale during atlas generation, then using the grayscale atlas as an alpha mask. The problem with this approach is that DirectWrite rendering is dependent upon internal gamma correction - i.e. the color of the text and background. As we're producing a colorless atlas we can't tell DirectWrite what colors to target. This change moves to render with grayscale which is a better match for our intended target of an alpha mask atlas. The atlas effectively still contains a gamma bias, in that the render effectively assumes a black on white render, leading to perceptually missing pixels when a final blend is performed in a light on dark render. To address this the shader applies a conditional gamma correction based on the luminance of the text, assuming that most of the time light text implies a light on dark render. The result is a rendering that is perceptually extremely close to the old render target, but still closer to the platform common render behavior - perceptually light on dark renders are now "slightly thinner" than before, but have a "complete" render, that is they are no longer missing light pixels necessary for legibility. Updates #36023
This commit is contained in:
parent
949398cb93
commit
30ade60ee7
4 changed files with 33 additions and 93 deletions
|
@ -14,11 +14,6 @@ use std::{
|
|||
rc::{Rc, Weak},
|
||||
sync::Arc,
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
use windows::Win32::{
|
||||
Graphics::Imaging::{CLSID_WICImagingFactory, IWICImagingFactory},
|
||||
System::Com::{CLSCTX_INPROC_SERVER, CoCreateInstance},
|
||||
};
|
||||
|
||||
/// TestPlatform implements the Platform trait for use in tests.
|
||||
pub(crate) struct TestPlatform {
|
||||
|
@ -35,8 +30,6 @@ pub(crate) struct TestPlatform {
|
|||
screen_capture_sources: RefCell<Vec<TestScreenCaptureSource>>,
|
||||
pub opened_url: RefCell<Option<String>>,
|
||||
pub text_system: Arc<dyn PlatformTextSystem>,
|
||||
#[cfg(target_os = "windows")]
|
||||
bitmap_factory: std::mem::ManuallyDrop<IWICImagingFactory>,
|
||||
weak: Weak<Self>,
|
||||
}
|
||||
|
||||
|
@ -91,16 +84,6 @@ pub(crate) struct TestPrompts {
|
|||
|
||||
impl TestPlatform {
|
||||
pub fn new(executor: BackgroundExecutor, foreground_executor: ForegroundExecutor) -> Rc<Self> {
|
||||
#[cfg(target_os = "windows")]
|
||||
let bitmap_factory = unsafe {
|
||||
windows::Win32::System::Ole::OleInitialize(None)
|
||||
.expect("unable to initialize Windows OLE");
|
||||
std::mem::ManuallyDrop::new(
|
||||
CoCreateInstance(&CLSID_WICImagingFactory, None, CLSCTX_INPROC_SERVER)
|
||||
.expect("Error creating bitmap factory."),
|
||||
)
|
||||
};
|
||||
|
||||
let text_system = Arc::new(NoopTextSystem);
|
||||
|
||||
Rc::new_cyclic(|weak| TestPlatform {
|
||||
|
@ -116,8 +99,6 @@ impl TestPlatform {
|
|||
current_primary_item: Mutex::new(None),
|
||||
weak: weak.clone(),
|
||||
opened_url: Default::default(),
|
||||
#[cfg(target_os = "windows")]
|
||||
bitmap_factory,
|
||||
text_system,
|
||||
})
|
||||
}
|
||||
|
@ -435,16 +416,6 @@ impl TestScreenCaptureSource {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
impl Drop for TestPlatform {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
std::mem::ManuallyDrop::drop(&mut self.bitmap_factory);
|
||||
windows::Win32::System::Ole::OleUninitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TestKeyboardLayout;
|
||||
|
||||
impl PlatformKeyboardLayout for TestKeyboardLayout {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue