Debian Codegraph @

third_party/rust/dwrote/src/gdi_interop.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 use std::cell::UnsafeCell;
6 use std::ptr;
7 use winapi::um::dwrite::IDWriteBitmapRenderTarget;
8 use winapi::um::dwrite::IDWriteGdiInterop;
9 use wio::com::ComPtr;
10
11 use super::{BitmapRenderTarget, DWriteFactory};
12
13 pub struct GdiInterop {
14 native: UnsafeCell<ComPtr<IDWriteGdiInterop>>,
15 }
16
17 impl GdiInterop {
18 pub fn create() -> GdiInterop {
19 unsafe {
20 let mut native: *mut IDWriteGdiInterop = ptr::null_mut();
21 let hr = (*DWriteFactory()).GetGdiInterop(&mut native);
22 assert!(hr == 0);
23 GdiInterop::take(ComPtr::from_raw(native))
24 }
25 }
26
27 pub fn take(native: ComPtr<IDWriteGdiInterop>) -> GdiInterop {
28 GdiInterop {
29 native: UnsafeCell::new(native),
30 }
31 }
32
33 pub fn create_bitmap_render_target(&self, width: u32, height: u32) -> BitmapRenderTarget {
34 unsafe {
35 let mut native: *mut IDWriteBitmapRenderTarget = ptr::null_mut();
36 let hr = (*self.native.get()).CreateBitmapRenderTarget(
37 ptr::null_mut(),
38 width,
39 height,
40 &mut native,
41 );
42 assert!(hr == 0);
43 BitmapRenderTarget::take(ComPtr::from_raw(native))
44 }
45 }
46 }