Bug 1354951 - Add some typedefs in bindings.rs to make the rust function signatures better match the signatures in webrender_ffi.h. r=rhunt

MozReview-Commit-ID: 8JZDNMwLDpN
This commit is contained in:
Kartikaya Gupta 2017-04-10 10:28:45 -04:00
Родитель 18bf4caba2
Коммит 8c1aeb1cb3
1 изменённых файлов: 106 добавлений и 89 удалений

Просмотреть файл

@ -15,6 +15,23 @@ use euclid::{TypedPoint2D, SideOffsets2D};
extern crate webrender_traits;
type WrAPI = RenderApi;
type WrAuxiliaryListsDescriptor = AuxiliaryListsDescriptor;
type WrBorderStyle = BorderStyle;
type WrBoxShadowClipMode = BoxShadowClipMode;
type WrBuiltDisplayListDescriptor = BuiltDisplayListDescriptor;
type WrEpoch = Epoch;
type WrFontKey = FontKey;
type WrGlyphInstance = GlyphInstance;
type WrIdNamespace = IdNamespace;
type WrImageFormat = ImageFormat;
type WrImageRendering = ImageRendering;
type WrImageKey = ImageKey;
type WrMixBlendMode = MixBlendMode;
type WrPipelineId = PipelineId;
type WrRenderedEpochs = Vec<(WrPipelineId, WrEpoch)>;
type WrRenderer = Renderer;
static ENABLE_RECORDING: bool = false;
// This macro adds some checks to make sure we notice when the memory representation of
@ -37,16 +54,16 @@ macro_rules! check_ffi_type {
);
}
check_ffi_type!(_pipeline_id_repr struct PipelineId as (u32, u32));
check_ffi_type!(_image_key_repr struct ImageKey as (u32, u32));
check_ffi_type!(_font_key_repr struct FontKey as (u32, u32));
check_ffi_type!(_epoch_repr struct Epoch as (u32));
check_ffi_type!(_image_format_repr enum ImageFormat as u32);
check_ffi_type!(_border_style_repr enum BorderStyle as u32);
check_ffi_type!(_image_rendering_repr enum ImageRendering as u32);
check_ffi_type!(_mix_blend_mode_repr enum MixBlendMode as u32);
check_ffi_type!(_box_shadow_clip_mode_repr enum BoxShadowClipMode as u32);
check_ffi_type!(_namespace_id_repr struct IdNamespace as (u32));
check_ffi_type!(_pipeline_id_repr struct WrPipelineId as (u32, u32));
check_ffi_type!(_image_key_repr struct WrImageKey as (u32, u32));
check_ffi_type!(_font_key_repr struct WrFontKey as (u32, u32));
check_ffi_type!(_epoch_repr struct WrEpoch as (u32));
check_ffi_type!(_image_format_repr enum WrImageFormat as u32);
check_ffi_type!(_border_style_repr enum WrBorderStyle as u32);
check_ffi_type!(_image_rendering_repr enum WrImageRendering as u32);
check_ffi_type!(_mix_blend_mode_repr enum WrMixBlendMode as u32);
check_ffi_type!(_box_shadow_clip_mode_repr enum WrBoxShadowClipMode as u32);
check_ffi_type!(_namespace_id_repr struct WrIdNamespace as (u32));
const GL_FORMAT_BGRA_GL: gl::GLuint = gl::BGRA;
const GL_FORMAT_BGRA_GLES: gl::GLuint = gl::BGRA_EXT;
@ -63,14 +80,14 @@ fn get_gl_format_bgra(gl: &gl::Gl) -> gl::GLuint {
}
#[repr(C)]
pub struct ByteSlice {
pub struct WrByteSlice {
buffer: *const u8,
len: usize,
}
impl ByteSlice {
pub fn new(slice: &[u8]) -> ByteSlice {
ByteSlice { buffer: &slice[0], len: slice.len() }
impl WrByteSlice {
pub fn new(slice: &[u8]) -> WrByteSlice {
WrByteSlice { buffer: &slice[0], len: slice.len() }
}
pub fn as_slice(&self) -> &[u8] {
@ -219,7 +236,7 @@ impl WrGradientStop {
#[repr(C)]
pub struct WrBorderSide {
color: WrColor,
style: BorderStyle,
style: WrBorderStyle,
}
impl WrBorderSide {
@ -329,7 +346,7 @@ impl WrRepeatMode
#[repr(C)]
pub struct WrImageMask {
image: ImageKey,
image: WrImageKey,
rect: WrRect,
repeat: bool,
}
@ -504,7 +521,7 @@ pub struct WrWindowId(u64);
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct WrImageDescriptor {
pub format: ImageFormat,
pub format: WrImageFormat,
pub width: u32,
pub height: u32,
pub stride: u32,
@ -616,7 +633,7 @@ impl webrender_traits::RenderNotifier for CppNotifier {
}
#[no_mangle]
pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut Renderer,
pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut WrRenderer,
external_image_handler: *mut WrExternalImageHandler) {
if !external_image_handler.is_null() {
renderer.set_external_image_handler(Box::new(
@ -632,18 +649,18 @@ pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut Renderer
}
#[no_mangle]
pub extern "C" fn wr_renderer_update(renderer: &mut Renderer) {
pub extern "C" fn wr_renderer_update(renderer: &mut WrRenderer) {
renderer.update();
}
#[no_mangle]
pub extern "C" fn wr_renderer_render(renderer: &mut Renderer, width: u32, height: u32) {
pub extern "C" fn wr_renderer_render(renderer: &mut WrRenderer, width: u32, height: u32) {
renderer.render(DeviceUintSize::new(width, height));
}
// Call wr_renderer_render() before calling this function.
#[no_mangle]
pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut Renderer,
pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut WrRenderer,
width: u32,
height: u32,
dst_buffer: *mut u8,
@ -663,14 +680,14 @@ pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut Renderer,
}
#[no_mangle]
pub extern "C" fn wr_renderer_set_profiler_enabled(renderer: &mut Renderer, enabled: bool) {
pub extern "C" fn wr_renderer_set_profiler_enabled(renderer: &mut WrRenderer, enabled: bool) {
renderer.set_profiler_enabled(enabled);
}
#[no_mangle]
pub extern "C" fn wr_renderer_current_epoch(renderer: &mut Renderer,
pipeline_id: PipelineId,
out_epoch: &mut Epoch)
pub extern "C" fn wr_renderer_current_epoch(renderer: &mut WrRenderer,
pipeline_id: WrPipelineId,
out_epoch: &mut WrEpoch)
-> bool {
if let Some(epoch) = renderer.current_epoch(pipeline_id) {
*out_epoch = epoch;
@ -680,22 +697,22 @@ pub extern "C" fn wr_renderer_current_epoch(renderer: &mut Renderer,
}
#[no_mangle]
pub unsafe extern "C" fn wr_renderer_delete(renderer: *mut Renderer) {
pub unsafe extern "C" fn wr_renderer_delete(renderer: *mut WrRenderer) {
Box::from_raw(renderer);
}
#[no_mangle]
pub unsafe extern "C" fn wr_renderer_flush_rendered_epochs(renderer: &mut Renderer)
-> *mut Vec<(PipelineId, Epoch)> {
pub unsafe extern "C" fn wr_renderer_flush_rendered_epochs(renderer: &mut WrRenderer)
-> *mut WrRenderedEpochs {
let map = renderer.flush_rendered_epochs();
let pipeline_epochs = Box::new(map.into_iter().collect());
return Box::into_raw(pipeline_epochs);
}
#[no_mangle]
pub unsafe extern "C" fn wr_rendered_epochs_next(pipeline_epochs: &mut Vec<(PipelineId, Epoch)>,
out_pipeline: &mut PipelineId,
out_epoch: &mut Epoch)
pub unsafe extern "C" fn wr_rendered_epochs_next(pipeline_epochs: &mut WrRenderedEpochs,
out_pipeline: &mut WrPipelineId,
out_epoch: &mut WrEpoch)
-> bool {
if let Some((pipeline, epoch)) = pipeline_epochs.pop() {
*out_pipeline = pipeline;
@ -706,7 +723,7 @@ pub unsafe extern "C" fn wr_rendered_epochs_next(pipeline_epochs: &mut Vec<(Pipe
}
#[no_mangle]
pub unsafe extern "C" fn wr_rendered_epochs_delete(pipeline_epochs: *mut Vec<(PipelineId, Epoch)>) {
pub unsafe extern "C" fn wr_rendered_epochs_delete(pipeline_epochs: *mut WrRenderedEpochs) {
Box::from_raw(pipeline_epochs);
}
@ -717,8 +734,8 @@ pub extern "C" fn wr_window_new(window_id: WrWindowId,
window_height: u32,
gl_context: *mut c_void,
enable_profiler: bool,
out_api: &mut *mut RenderApi,
out_renderer: &mut *mut Renderer)
out_api: &mut *mut WrAPI,
out_renderer: &mut *mut WrRenderer)
-> bool {
assert!(unsafe { is_in_render_thread() });
@ -751,10 +768,10 @@ pub extern "C" fn wr_window_new(window_id: WrWindowId,
};
let window_size = DeviceUintSize::new(window_width, window_height);
let (renderer, sender) = match Renderer::new(gl, opts, window_size) {
let (renderer, sender) = match WrRenderer::new(gl, opts, window_size) {
Ok((renderer, sender)) => (renderer, sender),
Err(e) => {
println!(" Failed to create a Renderer: {:?}", e);
println!(" Failed to create a WrRenderer: {:?}", e);
let msg = CString::new(format!("wr_window_new: {:?}", e)).unwrap();
unsafe { gfx_critical_note(msg.as_ptr()); }
return false;
@ -770,16 +787,16 @@ pub extern "C" fn wr_window_new(window_id: WrWindowId,
}
#[no_mangle]
pub unsafe extern "C" fn wr_api_delete(api: *mut RenderApi) {
pub unsafe extern "C" fn wr_api_delete(api: *mut WrAPI) {
let api = Box::from_raw(api);
api.shut_down();
}
#[no_mangle]
pub extern "C" fn wr_api_add_image(api: &mut RenderApi,
image_key: ImageKey,
pub extern "C" fn wr_api_add_image(api: &mut WrAPI,
image_key: WrImageKey,
descriptor: &WrImageDescriptor,
bytes: ByteSlice) {
bytes: WrByteSlice) {
assert!(unsafe { is_in_compositor_thread() });
let copied_bytes = bytes.as_slice().to_owned();
api.add_image(image_key,
@ -789,10 +806,10 @@ pub extern "C" fn wr_api_add_image(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_add_blob_image(api: &mut RenderApi,
image_key: ImageKey,
pub extern "C" fn wr_api_add_blob_image(api: &mut WrAPI,
image_key: WrImageKey,
descriptor: &WrImageDescriptor,
bytes: ByteSlice) {
bytes: WrByteSlice) {
assert!(unsafe { is_in_compositor_thread() });
let copied_bytes = bytes.as_slice().to_owned();
api.add_image(image_key,
@ -802,8 +819,8 @@ pub extern "C" fn wr_api_add_blob_image(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_add_external_image_handle(api: &mut RenderApi,
image_key: ImageKey,
pub extern "C" fn wr_api_add_external_image_handle(api: &mut WrAPI,
image_key: WrImageKey,
descriptor: &WrImageDescriptor,
external_image_id: u64) {
assert!(unsafe { is_in_compositor_thread() });
@ -817,8 +834,8 @@ pub extern "C" fn wr_api_add_external_image_handle(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_add_external_image_buffer(api: &mut RenderApi,
image_key: ImageKey,
pub extern "C" fn wr_api_add_external_image_buffer(api: &mut WrAPI,
image_key: WrImageKey,
descriptor: &WrImageDescriptor,
external_image_id: u64) {
assert!(unsafe { is_in_compositor_thread() });
@ -832,10 +849,10 @@ pub extern "C" fn wr_api_add_external_image_buffer(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_update_image(api: &mut RenderApi,
key: ImageKey,
pub extern "C" fn wr_api_update_image(api: &mut WrAPI,
key: WrImageKey,
descriptor: &WrImageDescriptor,
bytes: ByteSlice) {
bytes: WrByteSlice) {
assert!(unsafe { is_in_compositor_thread() });
let copied_bytes = bytes.as_slice().to_owned();
@ -846,33 +863,33 @@ pub extern "C" fn wr_api_update_image(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_delete_image(api: &mut RenderApi, key: ImageKey) {
pub extern "C" fn wr_api_delete_image(api: &mut WrAPI, key: WrImageKey) {
assert!(unsafe { is_in_compositor_thread() });
api.delete_image(key)
}
#[no_mangle]
pub extern "C" fn wr_api_set_root_pipeline(api: &mut RenderApi, pipeline_id: PipelineId) {
pub extern "C" fn wr_api_set_root_pipeline(api: &mut WrAPI, pipeline_id: WrPipelineId) {
api.set_root_pipeline(pipeline_id);
api.generate_frame(None);
}
#[no_mangle]
pub extern "C" fn wr_api_set_window_parameters(api: &mut RenderApi, width: i32, height: i32) {
pub extern "C" fn wr_api_set_window_parameters(api: &mut WrAPI, width: i32, height: i32) {
let size = DeviceUintSize::new(width as u32, height as u32);
api.set_window_parameters(size, DeviceUintRect::new(DeviceUintPoint::new(0, 0), size));
}
#[no_mangle]
pub unsafe extern "C" fn wr_api_set_root_display_list(api: &mut RenderApi,
epoch: Epoch,
pub unsafe extern "C" fn wr_api_set_root_display_list(api: &mut WrAPI,
epoch: WrEpoch,
viewport_width: f32,
viewport_height: f32,
pipeline_id: PipelineId,
dl_descriptor: BuiltDisplayListDescriptor,
pipeline_id: WrPipelineId,
dl_descriptor: WrBuiltDisplayListDescriptor,
dl_data: *mut u8,
dl_size: usize,
aux_descriptor: AuxiliaryListsDescriptor,
aux_descriptor: WrAuxiliaryListsDescriptor,
aux_data: *mut u8,
aux_size: usize) {
let root_background_color = ColorF::new(0.3, 0.0, 0.0, 1.0);
@ -901,9 +918,9 @@ pub unsafe extern "C" fn wr_api_set_root_display_list(api: &mut RenderApi,
}
#[no_mangle]
pub unsafe extern "C" fn wr_api_clear_root_display_list(api: &mut RenderApi,
epoch: Epoch,
pipeline_id: PipelineId) {
pub unsafe extern "C" fn wr_api_clear_root_display_list(api: &mut WrAPI,
epoch: WrEpoch,
pipeline_id: WrPipelineId) {
let root_background_color = ColorF::new(0.3, 0.0, 0.0, 1.0);
let preserve_frame_state = true;
let frame_builder = WebRenderFrameBuilder::new(pipeline_id);
@ -916,20 +933,20 @@ pub unsafe extern "C" fn wr_api_clear_root_display_list(api: &mut RenderApi,
}
#[no_mangle]
pub extern "C" fn wr_api_generate_frame(api: &mut RenderApi) {
pub extern "C" fn wr_api_generate_frame(api: &mut WrAPI) {
api.generate_frame(None);
}
#[no_mangle]
pub extern "C" fn wr_api_send_external_event(api: &mut RenderApi, evt: usize) {
pub extern "C" fn wr_api_send_external_event(api: &mut WrAPI, evt: usize) {
assert!(unsafe { !is_in_render_thread() });
api.send_external_event(ExternalEvent::from_raw(evt));
}
#[no_mangle]
pub extern "C" fn wr_api_add_raw_font(api: &mut RenderApi,
key: FontKey,
pub extern "C" fn wr_api_add_raw_font(api: &mut WrAPI,
key: WrFontKey,
font_buffer: *mut u8,
buffer_size: usize) {
assert!(unsafe { is_in_compositor_thread() });
@ -949,7 +966,7 @@ pub extern "C" fn wr_api_delete_font(api: &mut RenderApi, key: FontKey)
}
#[no_mangle]
pub unsafe extern "C" fn wr_api_get_namespace(api: &mut RenderApi) -> IdNamespace {
pub unsafe extern "C" fn wr_api_get_namespace(api: &mut WrAPI) -> WrIdNamespace {
api.id_namespace
}
@ -965,12 +982,12 @@ pub unsafe extern "C" fn wr_api_get_namespace(api: &mut RenderApi) -> IdNamespac
// See RenderThread.h for some notes about how the pieces fit together.
pub struct WebRenderFrameBuilder {
pub root_pipeline_id: PipelineId,
pub root_pipeline_id: WrPipelineId,
pub dl_builder: webrender_traits::DisplayListBuilder,
}
impl WebRenderFrameBuilder {
pub fn new(root_pipeline_id: PipelineId) -> WebRenderFrameBuilder {
pub fn new(root_pipeline_id: WrPipelineId) -> WebRenderFrameBuilder {
WebRenderFrameBuilder {
root_pipeline_id: root_pipeline_id,
dl_builder: webrender_traits::DisplayListBuilder::new(root_pipeline_id),
@ -979,13 +996,13 @@ impl WebRenderFrameBuilder {
}
pub struct WrState {
pipeline_id: PipelineId,
pipeline_id: WrPipelineId,
z_index: i32,
frame_builder: WebRenderFrameBuilder,
}
#[no_mangle]
pub extern "C" fn wr_state_new(pipeline_id: PipelineId) -> *mut WrState {
pub extern "C" fn wr_state_new(pipeline_id: WrPipelineId) -> *mut WrState {
assert!(unsafe { is_in_main_thread() });
let state = Box::new(WrState {
@ -1025,7 +1042,7 @@ pub extern "C" fn wr_dp_begin(state: &mut WrState, width: u32, height: u32) {
0,
None,
None,
webrender_traits::MixBlendMode::Normal,
MixBlendMode::Normal,
Vec::new());
}
@ -1064,7 +1081,7 @@ pub extern "C" fn wr_dp_push_stacking_context(state: &mut WrState,
mask: *const WrImageMask,
opacity: f32,
transform: &LayoutTransform,
mix_blend_mode: MixBlendMode) {
mix_blend_mode: WrMixBlendMode) {
assert!(unsafe { is_in_main_thread() });
state.z_index += 1;
@ -1137,7 +1154,7 @@ pub extern "C" fn wr_dp_pop_scroll_layer(state: &mut WrState) {
pub extern "C" fn wr_dp_push_iframe(state: &mut WrState,
rect: WrRect,
clip: WrClipRegion,
pipeline_id: PipelineId) {
pipeline_id: WrPipelineId) {
assert!(unsafe { is_in_main_thread() });
state.frame_builder.dl_builder.push_iframe(rect.to_rect(), clip.to_clip_region(), pipeline_id);
@ -1161,8 +1178,8 @@ pub extern "C" fn wr_dp_push_image(state: &mut WrState,
clip: WrClipRegion,
stretch_size: WrSize,
tile_spacing: WrSize,
image_rendering: ImageRendering,
key: ImageKey) {
image_rendering: WrImageRendering,
key: WrImageKey) {
assert!(unsafe { is_in_main_thread() });
let bounds = bounds.to_rect();
@ -1180,8 +1197,8 @@ pub extern "C" fn wr_dp_push_text(state: &mut WrState,
bounds: WrRect,
clip: WrClipRegion,
color: WrColor,
font_key: FontKey,
glyphs: *mut GlyphInstance,
font_key: WrFontKey,
glyphs: *mut WrGlyphInstance,
glyph_count: u32,
glyph_size: f32) {
assert!(unsafe { is_in_main_thread() });
@ -1234,7 +1251,7 @@ pub extern "C" fn wr_dp_push_border_image(state: &mut WrState,
rect: WrRect,
clip: WrClipRegion,
widths: WrBorderWidths,
image: ImageKey,
image: WrImageKey,
patch: WrNinePatchDescriptor,
outset: WrSideOffsets2D<f32>,
repeat_horizontal: WrRepeatMode,
@ -1358,7 +1375,7 @@ pub extern "C" fn wr_dp_push_box_shadow(state: &mut WrState,
blur_radius: f32,
spread_radius: f32,
border_radius: f32,
clip_mode: BoxShadowClipMode) {
clip_mode: WrBoxShadowClipMode) {
assert!(unsafe { is_in_main_thread() });
state.frame_builder.dl_builder.push_box_shadow(rect.to_rect(),
@ -1374,9 +1391,9 @@ pub extern "C" fn wr_dp_push_box_shadow(state: &mut WrState,
#[no_mangle]
pub unsafe extern "C" fn wr_api_finalize_builder(state: &mut WrState,
dl_descriptor: &mut BuiltDisplayListDescriptor,
dl_descriptor: &mut WrBuiltDisplayListDescriptor,
dl_data: &mut WrVecU8,
aux_descriptor: &mut AuxiliaryListsDescriptor,
aux_descriptor: &mut WrAuxiliaryListsDescriptor,
aux_data: &mut WrVecU8) {
let frame_builder = mem::replace(&mut state.frame_builder,
WebRenderFrameBuilder::new(state.pipeline_id));
@ -1392,9 +1409,9 @@ pub unsafe extern "C" fn wr_api_finalize_builder(state: &mut WrState,
#[no_mangle]
pub unsafe extern "C" fn wr_dp_push_built_display_list(state: &mut WrState,
dl_descriptor: BuiltDisplayListDescriptor,
dl_descriptor: WrBuiltDisplayListDescriptor,
dl_data: WrVecU8,
aux_descriptor: AuxiliaryListsDescriptor,
aux_descriptor: WrAuxiliaryListsDescriptor,
aux_data: WrVecU8) {
let dl_vec = dl_data.to_vec();
let aux_vec = aux_data.to_vec();
@ -1406,12 +1423,12 @@ pub unsafe extern "C" fn wr_dp_push_built_display_list(state: &mut WrState,
}
struct Moz2dImageRenderer {
images: HashMap<ImageKey, BlobImageResult>
images: HashMap<WrImageKey, BlobImageResult>
}
impl BlobImageRenderer for Moz2dImageRenderer {
fn request_blob_image(&mut self,
key: ImageKey,
key: WrImageKey,
data: Arc<BlobImageData>,
descriptor: &BlobImageDescriptor,
_dirty_rect: Option<DeviceUintRect>) {
@ -1419,7 +1436,7 @@ impl BlobImageRenderer for Moz2dImageRenderer {
self.images.insert(key, result);
}
fn resolve_blob_image(&mut self, key: ImageKey) -> BlobImageResult {
fn resolve_blob_image(&mut self, key: WrImageKey) -> BlobImageResult {
return match self.images.remove(&key) {
Some(result) => result,
None => Err(BlobImageError::InvalidKey),
@ -1440,7 +1457,7 @@ impl Moz2dImageRenderer {
);
unsafe {
if wr_moz2d_render_cb(ByteSlice::new(&data[..]),
if wr_moz2d_render_cb(WrByteSlice::new(&data[..]),
descriptor.width,
descriptor.height,
descriptor.format,
@ -1459,9 +1476,9 @@ impl Moz2dImageRenderer {
extern "C" {
// TODO: figure out the API for tiled blob images.
fn wr_moz2d_render_cb(blob: ByteSlice,
fn wr_moz2d_render_cb(blob: WrByteSlice,
width: u32,
height: u32,
format: ImageFormat,
format: WrImageFormat,
output: MutByteSlice) -> bool;
}