windows: Refactor clipboard implementation (#14347)

This PR provides a similar implementation to the macOS clipboard
implementation, adds support for metadata and includes tests.

Release Notes:

- N/A
This commit is contained in:
张小白 2024-07-15 10:40:41 +08:00 committed by GitHub
parent ba09eabfba
commit 315692d112
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 180 additions and 35 deletions

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, sync::Arc};
use std::{borrow::Cow, mem::ManuallyDrop, sync::Arc};
use ::util::ResultExt;
use anyhow::{anyhow, Result};
@ -39,7 +39,7 @@ pub(crate) struct DirectWriteTextSystem(RwLock<DirectWriteState>);
struct DirectWriteComponent {
locale: String,
factory: IDWriteFactory5,
bitmap_factory: IWICImagingFactory2,
bitmap_factory: ManuallyDrop<IWICImagingFactory2>,
d2d1_factory: ID2D1Factory,
in_memory_loader: IDWriteInMemoryFontFileLoader,
builder: IDWriteFontSetBuilder1,
@ -79,6 +79,7 @@ impl DirectWriteComponent {
let factory: IDWriteFactory5 = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED)?;
let bitmap_factory: IWICImagingFactory2 =
CoCreateInstance(&CLSID_WICImagingFactory2, None, CLSCTX_INPROC_SERVER)?;
let bitmap_factory = ManuallyDrop::new(bitmap_factory);
let d2d1_factory: ID2D1Factory =
D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, None)?;
// The `IDWriteInMemoryFontFileLoader` here is supported starting from
@ -238,6 +239,11 @@ impl PlatformTextSystem for DirectWriteTextSystem {
..Default::default()
})
}
fn destroy(&self) {
let mut lock = self.0.write();
unsafe { ManuallyDrop::drop(&mut lock.components.bitmap_factory) };
}
}
impl DirectWriteState {