Debian Codegraph @

third_party/rust/dwrote/src/rendering_params.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::IDWriteRenderingParams;
8 use wio::com::ComPtr;
9
10 use super::DWriteFactory;
11
12 pub struct RenderingParams {
13 native: UnsafeCell<ComPtr<IDWriteRenderingParams>>,
14 }
15
16 impl RenderingParams {
17 pub fn create_for_primary_monitor() -> RenderingParams {
18 unsafe {
19 let mut native: *mut IDWriteRenderingParams = ptr::null_mut();
20 let hr = (*DWriteFactory()).CreateRenderingParams(&mut native);
21 assert!(hr == 0);
22 RenderingParams::take(ComPtr::from_raw(native))
23 }
24 }
25
26 pub fn take(native: ComPtr<IDWriteRenderingParams>) -> RenderingParams {
27 RenderingParams {
28 native: UnsafeCell::new(native),
29 }
30 }
31
32 pub unsafe fn as_ptr(&self) -> *mut IDWriteRenderingParams {
33 (*self.native.get()).as_raw()
34 }
35 }