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::ptr; 6 use std::cell::UnsafeCell; 7 8 use comptr::ComPtr; 9 use winapi; 10 use super::{DWriteFactory, BitmapRenderTarget}; 11 12 #[derive(Debug)] 13 pub struct GdiInterop { 14 native: UnsafeCell<ComPtr<winapi::IDWriteGdiInterop>>, 15 } 16 17 impl GdiInterop { create() -> GdiInterop18 pub fn create() -> GdiInterop { 19 unsafe { 20 let mut native: ComPtr<winapi::IDWriteGdiInterop> = ComPtr::new(); 21 let hr = (*DWriteFactory()).GetGdiInterop(native.getter_addrefs()); 22 assert!(hr == 0); 23 GdiInterop::take(native) 24 } 25 } 26 take(native: ComPtr<winapi::IDWriteGdiInterop>) -> GdiInterop27 pub fn take(native: ComPtr<winapi::IDWriteGdiInterop>) -> GdiInterop { 28 GdiInterop { 29 native: UnsafeCell::new(native), 30 } 31 } 32 create_bitmap_render_target(&self, width: u32, height: u32) -> BitmapRenderTarget33 pub fn create_bitmap_render_target(&self, width: u32, height: u32) -> BitmapRenderTarget { 34 unsafe { 35 let mut native: ComPtr<winapi::IDWriteBitmapRenderTarget> = ComPtr::new(); 36 let hr = (*self.native.get()).CreateBitmapRenderTarget(ptr::null_mut(), 37 width, height, 38 native.getter_addrefs()); 39 assert!(hr == 0); 40 BitmapRenderTarget::take(native) 41 } 42 } 43 } 44