From 5e274cc3e6479b2079be91e3dab5e256b314f4db Mon Sep 17 00:00:00 2001 From: sotaro Date: Wed, 29 May 2019 20:50:13 +0000 Subject: [PATCH] Bug 1554952 - Remove function pointers from WrExternalImageHandler r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D32813 --HG-- extra : moz-landing-system : lando --- gfx/webrender_bindings/RendererOGL.cpp | 12 ++++------ gfx/webrender_bindings/src/bindings.rs | 33 +++++++++++++------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/gfx/webrender_bindings/RendererOGL.cpp b/gfx/webrender_bindings/RendererOGL.cpp index cf8bc1e822ef..33bfd1c05adc 100644 --- a/gfx/webrender_bindings/RendererOGL.cpp +++ b/gfx/webrender_bindings/RendererOGL.cpp @@ -20,9 +20,9 @@ namespace mozilla { namespace wr { -wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, - uint8_t aChannelIndex, - wr::ImageRendering aRendering) { +wr::WrExternalImage wr_renderer_lock_external_image( + void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex, + wr::ImageRendering aRendering) { RendererOGL* renderer = reinterpret_cast(aObj); RenderTextureHost* texture = renderer->GetRenderTexture(aId); MOZ_ASSERT(texture); @@ -34,8 +34,8 @@ wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, return texture->Lock(aChannelIndex, renderer->gl(), aRendering); } -void UnlockExternalImage(void* aObj, wr::WrExternalImageId aId, - uint8_t aChannelIndex) { +void wr_renderer_unlock_external_image(void* aObj, wr::WrExternalImageId aId, + uint8_t aChannelIndex) { RendererOGL* renderer = reinterpret_cast(aObj); RenderTextureHost* texture = renderer->GetRenderTexture(aId); MOZ_ASSERT(texture); @@ -75,8 +75,6 @@ RendererOGL::~RendererOGL() { wr::WrExternalImageHandler RendererOGL::GetExternalImageHandler() { return wr::WrExternalImageHandler{ this, - LockExternalImage, - UnlockExternalImage, }; } diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index 98e59a627183..dc51929ca478 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -405,14 +405,22 @@ struct WrExternalImage { size: usize, } -type LockExternalImageCallback = unsafe extern "C" fn(*mut c_void, WrExternalImageId, u8, ImageRendering) -> WrExternalImage; -type UnlockExternalImageCallback = unsafe extern "C" fn(*mut c_void, WrExternalImageId, u8); +extern "C" { + fn wr_renderer_lock_external_image( + renderer: *mut c_void, + external_image_id: WrExternalImageId, + channel_index: u8, + rendering: ImageRendering) -> WrExternalImage; + fn wr_renderer_unlock_external_image( + renderer: *mut c_void, + external_image_id: WrExternalImageId, + channel_index: u8); +} #[repr(C)] +#[derive(Copy, Clone, Debug)] pub struct WrExternalImageHandler { external_image_obj: *mut c_void, - lock_func: LockExternalImageCallback, - unlock_func: UnlockExternalImageCallback, } impl ExternalImageHandler for WrExternalImageHandler { @@ -422,7 +430,7 @@ impl ExternalImageHandler for WrExternalImageHandler { rendering: ImageRendering) -> ExternalImage { - let image = unsafe { (self.lock_func)(self.external_image_obj, id.into(), channel_index, rendering) }; + let image = unsafe { wr_renderer_lock_external_image(self.external_image_obj, id.into(), channel_index, rendering) }; ExternalImage { uv: TexelRect::new(image.u0, image.v0, image.u1, image.v1), source: match image.image_type { @@ -437,7 +445,7 @@ impl ExternalImageHandler for WrExternalImageHandler { id: ExternalImageId, channel_index: u8) { unsafe { - (self.unlock_func)(self.external_image_obj, id.into(), channel_index); + wr_renderer_unlock_external_image(self.external_image_obj, id.into(), channel_index); } } } @@ -607,17 +615,8 @@ impl RenderNotifier for CppNotifier { #[no_mangle] pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut Renderer, - external_image_handler: *mut WrExternalImageHandler) { - if !external_image_handler.is_null() { - renderer.set_external_image_handler(Box::new(unsafe { - WrExternalImageHandler { - external_image_obj: - (*external_image_handler).external_image_obj, - lock_func: (*external_image_handler).lock_func, - unlock_func: (*external_image_handler).unlock_func, - } - })); - } + external_image_handler: &mut WrExternalImageHandler) { + renderer.set_external_image_handler(Box::new(external_image_handler.clone())); } #[no_mangle]