Auto merge of #377 - NickSpag:feature/expose-embeddedresourceloader-to-c-api, r=pcwalton
Expose EmbeddedResourceLoader to c api ### Background This PR exposes the c api to the EmbeddedResourceLoader, to prevent some of the issues mentioned [here](https://github.com/servo/pathfinder/issues/234). ### Approach - Followed `PFFilesystemResourceLoaderLocate` and simply exposed the ERL's new and boxed it in the ResourceLoaderWrapper - Used the `Create` terminology in the signature to match the rest of the api where a new() is called ### Notes - I successfully tested it in a little .NET binding project I'm working on. - Moved the \`gl\` section comment down with the GL methods, as it seemed a little out of place. added a \`resources\` one. then moved the destroy fn in to the new section. Let me know if I misinterpreted anything or if there are any changes, stylistic or otherwise, that you'd prefer. Thanks!
This commit is contained in:
commit
a51176a3ba
21
c/src/lib.rs
21
c/src/lib.rs
|
@ -26,6 +26,7 @@ use pathfinder_gl::{GLDevice, GLVersion};
|
||||||
use pathfinder_gpu::Device;
|
use pathfinder_gpu::Device;
|
||||||
use pathfinder_resources::ResourceLoader;
|
use pathfinder_resources::ResourceLoader;
|
||||||
use pathfinder_resources::fs::FilesystemResourceLoader;
|
use pathfinder_resources::fs::FilesystemResourceLoader;
|
||||||
|
use pathfinder_resources::embedded::EmbeddedResourceLoader;
|
||||||
use pathfinder_renderer::concurrent::rayon::RayonExecutor;
|
use pathfinder_renderer::concurrent::rayon::RayonExecutor;
|
||||||
use pathfinder_renderer::concurrent::scene_proxy::SceneProxy;
|
use pathfinder_renderer::concurrent::scene_proxy::SceneProxy;
|
||||||
use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererLevel};
|
use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererLevel};
|
||||||
|
@ -507,7 +508,13 @@ pub unsafe extern "C" fn PFFillStyleDestroy(fill_style: PFFillStyleRef) {
|
||||||
drop(Box::from_raw(fill_style))
|
drop(Box::from_raw(fill_style))
|
||||||
}
|
}
|
||||||
|
|
||||||
// `gl`
|
// `resources`
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFEmbeddedResourceLoaderCreate() -> PFResourceLoaderRef {
|
||||||
|
let loader = Box::new(EmbeddedResourceLoader::new());
|
||||||
|
Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box<dyn ResourceLoader>)))
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn PFFilesystemResourceLoaderLocate() -> PFResourceLoaderRef {
|
pub unsafe extern "C" fn PFFilesystemResourceLoaderLocate() -> PFResourceLoaderRef {
|
||||||
|
@ -523,6 +530,13 @@ pub unsafe extern "C" fn PFFilesystemResourceLoaderFromPath(path: *const c_char)
|
||||||
Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box<dyn ResourceLoader>)))
|
Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box<dyn ResourceLoader>)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFResourceLoaderDestroy(loader: PFResourceLoaderRef) {
|
||||||
|
drop(Box::from_raw(loader))
|
||||||
|
}
|
||||||
|
|
||||||
|
// `gl`
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn PFGLLoadWith(loader: PFGLFunctionLoader, userdata: *mut c_void) {
|
pub unsafe extern "C" fn PFGLLoadWith(loader: PFGLFunctionLoader, userdata: *mut c_void) {
|
||||||
gl::load_with(|name| {
|
gl::load_with(|name| {
|
||||||
|
@ -548,11 +562,6 @@ pub unsafe extern "C" fn PFGLDeviceDestroy(device: PFGLDeviceRef) {
|
||||||
drop(Box::from_raw(device))
|
drop(Box::from_raw(device))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn PFResourceLoaderDestroy(loader: PFResourceLoaderRef) {
|
|
||||||
drop(Box::from_raw(loader))
|
|
||||||
}
|
|
||||||
|
|
||||||
// `gpu`
|
// `gpu`
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Reference in New Issue