Auto merge of #356 - linkmauve:c-resources-path, r=pcwalton

Expose creating a resource loader from a path to C

This is useful when Pathfinder is shipped by a Linux distribution, and not with everything bundled.
This commit is contained in:
bors-servo 2020-06-16 12:11:35 -04:00 committed by GitHub
commit 5e3fb5fed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -34,6 +34,7 @@ use pathfinder_renderer::scene::Scene;
use pathfinder_simd::default::F32x4;
use std::ffi::CString;
use std::os::raw::{c_char, c_void};
use std::path::PathBuf;
use std::slice;
use std::str;
@ -488,6 +489,14 @@ pub unsafe extern "C" fn PFFilesystemResourceLoaderLocate() -> PFResourceLoaderR
Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box<dyn ResourceLoader>)))
}
#[no_mangle]
pub unsafe extern "C" fn PFFilesystemResourceLoaderFromPath(path: *const c_char) -> PFResourceLoaderRef {
let string = to_rust_string(&path, 0);
let directory = PathBuf::from(string);
let loader = Box::new(FilesystemResourceLoader { directory });
Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box<dyn ResourceLoader>)))
}
#[no_mangle]
pub unsafe extern "C" fn PFGLLoadWith(loader: PFGLFunctionLoader, userdata: *mut c_void) {
gl::load_with(|name| {