author | JerryShih <hshih@mozilla.com> |
Fri, 10 Feb 2017 10:16:47 -0500 | |
changeset 342224 | 2c0dc842fe93908d5953d12ac40b334d0730566d |
parent 342223 | 020ec1ae24f5f797a4e429c4cafbba6cb81bc129 |
child 342225 | 764e2c0ad987b10be5714f317d67228269358726 |
push id | 31345 |
push user | kwierso@gmail.com |
push date | Fri, 10 Feb 2017 20:35:09 +0000 |
treeherder | mozilla-central@a288fe35e494 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | nical |
bugs | 1338274 |
milestone | 54.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
gfx/webrender_bindings/src/bindings.rs | file | annotate | diff | comparison | revisions | |
gfx/webrender_bindings/webrender_ffi.h | file | annotate | diff | comparison | revisions |
--- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -1,25 +1,21 @@ -use fnv::FnvHasher; -use std::collections::HashMap; use std::ffi::CString; -use std::hash::BuildHasherDefault; use std::{mem, slice}; use std::os::raw::{c_void, c_char}; use gleam::gl; use webrender_traits::{BorderSide, BorderStyle, BorderRadius}; use webrender_traits::{PipelineId, ClipRegion}; use webrender_traits::{Epoch, ColorF, GlyphInstance, ImageDescriptor}; use webrender_traits::{FilterOp, ImageData, ImageFormat, ImageKey, ImageMask, ImageRendering, RendererKind, MixBlendMode}; use webrender_traits::{ExternalImageId, RenderApi, FontKey}; use webrender_traits::{DeviceUintSize, ExternalEvent}; use webrender_traits::{LayoutPoint, LayoutRect, LayoutSize, LayoutTransform}; use webrender::renderer::{Renderer, RendererOptions}; use webrender::renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource}; -use std::sync::{Arc, Mutex, Condvar}; use app_units::Au; extern crate webrender_traits; fn pipeline_id_to_u64(id: PipelineId) -> u64 { ((id.0 as u64) << 32) + id.1 as u64 } fn u64_to_pipeline_id(id: u64) -> PipelineId { PipelineId((id >> 32) as u32, id as u32) } fn font_key_to_u64(key: FontKey) -> u64 { unsafe { mem::transmute(key) } } @@ -318,49 +314,16 @@ impl WebRenderFrameBuilder { pub fn new(root_pipeline_id: PipelineId) -> WebRenderFrameBuilder { WebRenderFrameBuilder { root_pipeline_id: root_pipeline_id, dl_builder: webrender_traits::DisplayListBuilder::new(root_pipeline_id), } } } -// XXX (bug 1328602) - This will be removed soon-ish. -struct Notifier { - render_notifier: Arc<(Mutex<bool>, Condvar)>, -} - -impl webrender_traits::RenderNotifier for Notifier { - fn new_frame_ready(&mut self) { - assert!( unsafe { !is_in_compositor_thread() }); - let &(ref lock, ref cvar) = &*self.render_notifier; - let mut finished = lock.lock().unwrap(); - *finished = true; - cvar.notify_one(); - } - fn new_scroll_frame_ready(&mut self, _: bool) { - } - - fn pipeline_size_changed(&mut self, - _: PipelineId, - _: Option<LayoutSize>) { - } -} - -// XXX (bug 1328602) - This will be removed soon-ish. -pub struct WrWindowState { - renderer: Renderer, - api: RenderApi, - root_pipeline_id: PipelineId, - size: DeviceUintSize, - render_notifier_lock: Arc<(Mutex<bool>, Condvar)>, - pipeline_epoch_map: HashMap<PipelineId, Epoch, BuildHasherDefault<FnvHasher>>, - pipeline_sync_list: Vec<PipelineId>, -} - pub struct WrState { size: (u32, u32), pipeline_id: PipelineId, z_index: i32, frame_builder: WebRenderFrameBuilder, } #[repr(C)] @@ -468,103 +431,16 @@ impl WrMixBlendMode WrMixBlendMode::Hue => MixBlendMode::Hue, WrMixBlendMode::Saturation => MixBlendMode::Saturation, WrMixBlendMode::Color => MixBlendMode::Color, WrMixBlendMode::Luminosity => MixBlendMode::Luminosity, } } } -// TODO: Remove. -#[no_mangle] -pub extern fn wr_init_window(root_pipeline_id: u64, - glcontext_ptr: *mut c_void, - enable_profiler: bool, - external_image_handler: *mut WrExternalImageHandler) -> *mut WrWindowState { - assert!( unsafe { is_in_compositor_thread() }); - gl::load_with(|symbol| get_proc_address(glcontext_ptr, symbol)); - gl::clear_color(0.3, 0.0, 0.0, 1.0); - - let version = gl::get_string(gl::VERSION); - - println!("OpenGL version new {}", version); - - let opts = RendererOptions { - device_pixel_ratio: 1.0, - resource_override_path: None, - enable_aa: true, - enable_subpixel_aa: true, - enable_profiler: enable_profiler, - enable_recording: false, - enable_scrollbars: false, - precache_shaders: false, - renderer_kind: RendererKind::Native, - debug: false, - clear_framebuffer: true, - render_target_debug: false, - clear_color: ColorF::new(1.0, 1.0, 1.0, 1.0), - }; - - let (mut renderer, sender) = Renderer::new(opts); - let api = sender.create_api(); - - let notification_lock = Arc::new((Mutex::new(false), Condvar::new())); - let notification_lock_clone = notification_lock.clone(); - let notifier = Box::new(Notifier{render_notifier: notification_lock}); - renderer.set_render_notifier(notifier); - - 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, - release_func: (*external_image_handler).release_func, - } - })); - } - - let pipeline_id = u64_to_pipeline_id(root_pipeline_id); - api.set_root_pipeline(pipeline_id); - api.generate_frame(); - - let state = Box::new(WrWindowState { - renderer: renderer, - api: api, - root_pipeline_id: pipeline_id, - size: DeviceUintSize::new(0, 0), - render_notifier_lock: notification_lock_clone, - pipeline_epoch_map: HashMap::with_hasher(Default::default()), - pipeline_sync_list: Vec::new(), - }); - Box::into_raw(state) -} - -// TODO: Remove. -// This is the code specific to WrWindowState that was taken out of wr_create. -#[no_mangle] -pub extern fn wr_window_init_pipeline_epoch(window: &mut WrWindowState, pipeline: u64, width: u32, height: u32,) { - let pipeline_id = u64_to_pipeline_id(pipeline); - if pipeline_id == window.root_pipeline_id { - window.size = DeviceUintSize::new(width, height); - } - window.pipeline_epoch_map.insert(pipeline_id, Epoch(0)); -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_window_dp_begin(window: &mut WrWindowState, state: &mut WrState, width: u32, height: u32) { - if state.pipeline_id == window.root_pipeline_id { - window.size = DeviceUintSize::new(width, height); - } - - wr_dp_begin(state, width, height); -} - #[no_mangle] pub extern fn wr_dp_push_stacking_context(state:&mut WrState, bounds: WrRect, overflow: WrRect, mask: *const WrImageMask, opacity: f32, transform: &LayoutTransform, mix_blend_mode: WrMixBlendMode) { assert!( unsafe { is_in_compositor_thread() }); state.z_index += 1; let bounds = bounds.to_rect(); let overflow = overflow.to_rect(); @@ -592,119 +468,16 @@ pub extern fn wr_dp_push_stacking_contex #[no_mangle] pub extern fn wr_dp_pop_stacking_context(state: &mut WrState) { assert!( unsafe { is_in_compositor_thread() }); state.frame_builder.dl_builder.pop_stacking_context() } -// TODO: Remove. -fn wait_for_epoch(window: &mut WrWindowState) { - let &(ref lock, ref cvar) = &*window.render_notifier_lock; - let mut finished = lock.lock().unwrap(); - - window.pipeline_sync_list.push(window.root_pipeline_id); - - 'outer: for pipeline_id in window.pipeline_sync_list.iter() { - let epoch = window.pipeline_epoch_map.get(pipeline_id); - if epoch.is_none() { - // We could only push a pipeline_id for iframe without setting its root_display_list data. - continue; - } - - if epoch.unwrap().0 == 0 { - // This pipeline_id is not set the display_list yet, so skip the waiting. - continue; - } - - loop { - // Update all epochs. - window.renderer.update(); - - if let Some(rendered_epoch) = window.renderer.current_epoch(*pipeline_id) { - if *(epoch.unwrap()) == rendered_epoch { - continue 'outer; - } - } - - // If the epoch is not matched, starts to wait for next frame updating. - while !*finished { - finished = cvar.wait(finished).unwrap(); - } - // For the next sync one - *finished = false; - } - } - window.pipeline_sync_list.clear(); -} - -// TODO: Remove. -#[no_mangle] -pub fn wr_composite_window(window: &mut WrWindowState) { - assert!(unsafe { is_in_compositor_thread() }); - - gl::clear(gl::COLOR_BUFFER_BIT); - - wait_for_epoch(window); - window.renderer.render(window.size); -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_window_dp_end(window: &mut WrWindowState, state: &mut WrState) { - assert!( unsafe { is_in_compositor_thread() }); - let root_background_color = ColorF::new(0.3, 0.0, 0.0, 1.0); - let pipeline_id = state.pipeline_id; - let (width, height) = state.size; - - if let Some(epoch) = window.pipeline_epoch_map.get_mut(&pipeline_id) { - (*epoch).0 += 1; - - state.frame_builder.dl_builder.pop_stacking_context(); - - let fb = mem::replace(&mut state.frame_builder, WebRenderFrameBuilder::new(pipeline_id)); - - //let (dl_builder, aux_builder) = fb.dl_builder.finalize(); - window.api.set_root_display_list(Some(root_background_color), - *epoch, - LayoutSize::new(width as f32, height as f32), - fb.dl_builder); - window.api.generate_frame(); - - return; - } - - panic!("Could not find epoch for pipeline_id:({},{})", pipeline_id.0, pipeline_id.1); -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_add_image(window: &mut WrWindowState, width: u32, height: u32, stride: u32, format: ImageFormat, bytes: * const u8, size: usize) -> ImageKey { - wr_api_add_image(&mut window.api, width, height, stride, format, bytes, size) -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_add_external_image_texture(window: &mut WrWindowState, width: u32, height: u32, format: ImageFormat, external_image_id: u64) -> ImageKey { - wr_api_add_external_image_texture(&mut window.api, width, height, format, external_image_id) -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_update_image(window: &mut WrWindowState, key: ImageKey, width: u32, height: u32, format: ImageFormat, bytes: * const u8, size: usize) { - wr_api_update_image(&mut window.api, key, width, height, format, bytes, size); -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_delete_image(window: &mut WrWindowState, key: ImageKey) { - wr_api_delete_image(&mut window.api, key); -} - #[no_mangle] pub extern fn wr_api_set_root_pipeline(api: &mut RenderApi, pipeline_id: u64) { api.set_root_pipeline(u64_to_pipeline_id(pipeline_id)); api.generate_frame(); } #[no_mangle] pub extern fn wr_api_add_image(api: &mut RenderApi, width: u32, height: u32, stride: u32, format: ImageFormat, bytes: * const u8, size: usize) -> ImageKey { @@ -767,30 +540,16 @@ pub extern fn wr_dp_push_border(state: & left.to_border_side(), top.to_border_side(), right.to_border_side(), bottom.to_border_side(), radius.to_border_radius()); } #[no_mangle] -pub extern fn wr_window_dp_push_iframe(window: &mut WrWindowState, state: &mut WrState, rect: WrRect, clip: WrRect, layers_id: u64) { - assert!( unsafe { is_in_compositor_thread() }); - - let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip.to_rect(), - Vec::new(), - None); - let pipeline_id = PipelineId((layers_id >> 32) as u32, layers_id as u32); - window.pipeline_sync_list.push(pipeline_id); - state.frame_builder.dl_builder.push_iframe(rect.to_rect(), - clip_region, - pipeline_id); -} - -#[no_mangle] pub extern fn wr_dp_push_iframe(state: &mut WrState, rect: WrRect, clip: WrRect, layers_id: u64) { assert!( unsafe { is_in_compositor_thread() }); let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip.to_rect(), Vec::new(), None); let pipeline_id = u64_to_pipeline_id(layers_id); state.frame_builder.dl_builder.push_iframe(rect.to_rect(), @@ -949,25 +708,16 @@ pub extern fn wr_api_add_raw_font(api: & slice::from_raw_parts(font_buffer, buffer_size as usize) }; let mut font_vector = Vec::new(); font_vector.extend_from_slice(font_slice); return font_key_to_u64(api.add_raw_font(font_vector)); } -// TODO: Remove. -#[no_mangle] -pub extern fn wr_window_add_raw_font(window: &mut WrWindowState, - font_buffer: *mut u8, - buffer_size: usize) -> u64 -{ - return wr_api_add_raw_font(&mut window.api, font_buffer, buffer_size); -} - #[no_mangle] pub extern fn wr_dp_push_text(state: &mut WrState, bounds: WrRect, clip: WrRect, color: WrColor, font_key: u64, glyphs: *mut GlyphInstance, glyph_count: u32, @@ -991,35 +741,8 @@ pub extern fn wr_dp_push_text(state: &mu clip_region, glyph_vector, font_key, colorf, Au::from_f32_px(glyph_size), Au::from_px(0)); } -#[no_mangle] -pub extern fn wr_window_remove_pipeline(window: &mut WrWindowState, state: &WrState) { - window.pipeline_epoch_map.remove(&state.pipeline_id); -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_readback_into_buffer(width: u32, height: u32, - dst_buffer: *mut u8, buffer_size: usize) { - unsafe { - let mut slice = slice::from_raw_parts_mut(dst_buffer, buffer_size); - gl::read_pixels_into_buffer(0, 0, - width as gl::GLsizei, - height as gl::GLsizei, - gl::BGRA, - gl::UNSIGNED_BYTE, - slice); - } -} - -// TODO: Remove. -#[no_mangle] -pub extern fn wr_profiler_set_enabled(window: &mut WrWindowState, enabled: bool) -{ - assert!( unsafe { is_in_compositor_thread() }); - window.renderer.set_profiler_enabled(enabled); -}
--- a/gfx/webrender_bindings/webrender_ffi.h +++ b/gfx/webrender_bindings/webrender_ffi.h @@ -293,17 +293,16 @@ struct WrExternalImageIdHandler #else # define WR_INLINE inline # define WR_FUNC { MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("WebRender disabled"); } # define WR_DESTRUCTOR_SAFE_FUNC {} #endif // Structs defined in Rust, but opaque to C++ code. struct WrRenderedEpochs; -struct WrWindowState; struct WrRenderer; struct WrState; struct WrAPI; WR_INLINE void wr_renderer_update(WrRenderer* renderer) WR_FUNC; @@ -340,34 +339,36 @@ wr_gl_init(void* aGLContext) WR_FUNC; WR_INLINE void wr_window_new(WrWindowId window_id, bool enable_profiler, WrAPI** out_api, WrRenderer** out_renderer) WR_FUNC; WR_INLINE void -wr_window_remove_pipeline(WrWindowState* window, WrState* state) -WR_FUNC; - -WR_INLINE void wr_api_delete(WrAPI* api) WR_DESTRUCTOR_SAFE_FUNC; WR_INLINE WrImageKey wr_api_add_image(WrAPI* api, uint32_t width, uint32_t height, uint32_t stride, WrImageFormat format, uint8_t *bytes, size_t size) WR_FUNC; WR_INLINE WrImageKey wr_api_add_external_image_texture(WrAPI* api, uint32_t width, uint32_t height, WrImageFormat format, uint64_t external_image_id) WR_FUNC; +//TODO(Jerry): handle shmem in WR +//// WR_INLINE WrImageKey +//// wr_api_add_external_image_buffer(WrAPI* api, uint32_t width, uint32_t height, uint32_t stride, +//// WrImageFormat format, uint8_t *bytes, size_t size) +//// WR_FUNC; + WR_INLINE void wr_api_update_image(WrAPI* api, WrImageKey key, uint32_t width, uint32_t height, WrImageFormat format, uint8_t *bytes, size_t size) WR_FUNC; WR_INLINE void wr_api_delete_image(WrAPI* api, WrImageKey key) WR_FUNC; @@ -379,106 +380,49 @@ WR_FUNC; WR_INLINE void wr_api_set_root_display_list(WrAPI* api, WrState* state, uint32_t epoch, float w, float h) WR_FUNC; WR_INLINE void wr_api_send_external_event(WrAPI* api, uintptr_t evt) WR_DESTRUCTOR_SAFE_FUNC; -WR_INLINE void -wr_window_init_pipeline_epoch(WrWindowState* window, WrPipelineId pipeline, uint32_t width, uint32_t height) -WR_FUNC; - WR_INLINE WrFontKey wr_api_add_raw_font(WrAPI* api, uint8_t* font_buffer, size_t buffer_size) WR_FUNC; -WR_INLINE WrFontKey -wr_window_add_raw_font(WrWindowState* window, uint8_t* font_buffer, size_t buffer_size) -WR_FUNC; - -WR_INLINE WrWindowState* -wr_init_window(WrPipelineId root_pipeline_id, - void* webrender_bridge_ptr, - bool enable_profiler, - WrExternalImageIdHandler* handler = nullptr) -WR_FUNC; - WR_INLINE WrState* wr_state_new(uint32_t width, uint32_t height, WrPipelineId pipeline_id) WR_FUNC; WR_INLINE void wr_state_delete(WrState* state) WR_DESTRUCTOR_SAFE_FUNC; WR_INLINE void -wr_destroy(WrWindowState* wrWindow, WrState* WrState) -WR_FUNC; - -WR_INLINE WrImageKey -wr_add_image(WrWindowState* wrWindow, uint32_t width, uint32_t height, - uint32_t stride, WrImageFormat format, uint8_t *bytes, size_t size) -WR_FUNC; - -WR_INLINE WrImageKey -wr_add_external_image_texture(WrWindowState* wrWindow, uint32_t width, uint32_t height, - WrImageFormat format, uint64_t external_image_id) -WR_FUNC; - -//TODO(Jerry): handle shmem in WR -//// WR_INLINE WrImageKey -//// wr_add_external_image_buffer(WrWindowState* wrWindow, uint32_t width, uint32_t height, -//// uint32_t stride, WrImageFormat format, uint8_t *bytes, size_t size) -//// WR_FUNC; - -WR_INLINE void -wr_update_image(WrWindowState* wrWindow, WrImageKey key, - uint32_t width, uint32_t height, - WrImageFormat format, uint8_t *bytes, size_t size) -WR_FUNC; - -WR_INLINE void -wr_delete_image(WrWindowState* wrWindow, WrImageKey key) -WR_FUNC; - -WR_INLINE void wr_dp_push_stacking_context(WrState *wrState, WrRect bounds, WrRect overflow, const WrImageMask *mask, float opacity, const float* matrix, WrMixBlendMode mixBlendMode) WR_FUNC; //XXX: matrix should use a proper type WR_INLINE void wr_dp_pop_stacking_context(WrState *wrState) WR_FUNC; WR_INLINE void wr_dp_begin(WrState* wrState, uint32_t width, uint32_t height) WR_FUNC; WR_INLINE void -wr_window_dp_begin(WrWindowState* wrWindow, WrState* wrState, uint32_t width, uint32_t height) -WR_FUNC; - -WR_INLINE void -wr_window_dp_end(WrWindowState* wrWindow, WrState* wrState) -WR_FUNC; - -WR_INLINE void wr_dp_end(WrState* builder, WrAPI* api, uint32_t epoch) WR_FUNC; WR_INLINE void -wr_composite_window(WrWindowState* wrWindow) -WR_FUNC; - -WR_INLINE void wr_dp_push_rect(WrState* wrState, WrRect bounds, WrRect clip, WrColor color) WR_FUNC; WR_INLINE void wr_dp_push_text(WrState* wrState, WrRect bounds, WrRect clip, WrColor color, WrFontKey font_Key, const WrGlyphInstance* glyphs, uint32_t glyph_count, float glyph_size) @@ -490,43 +434,24 @@ wr_dp_push_border(WrState* wrState, WrRe WrBorderRadius radius) WR_FUNC; WR_INLINE void wr_dp_push_image(WrState* wrState, WrRect bounds, WrRect clip, const WrImageMask* mask, WrTextureFilter filter, WrImageKey key) WR_FUNC; -// TODO: Remove. -WR_INLINE void -wr_window_dp_push_iframe(WrWindowState* wrWindow, WrState* wrState, WrRect bounds, WrRect clip, - WrPipelineId layers_id) -WR_FUNC; - WR_INLINE void wr_dp_push_iframe(WrState* wrState, WrRect bounds, WrRect clip, WrPipelineId layers_id) WR_FUNC; -// TODO: Remove. -// It is the responsibility of the caller to manage the dst_buffer memory -// and also free it at the proper time. -WR_INLINE const uint8_t* -wr_readback_into_buffer(uint32_t width, uint32_t height, - uint8_t* dst_buffer, size_t buffer_length) -WR_FUNC; - // It is the responsibility of the caller to manage the dst_buffer memory // and also free it at the proper time. WR_INLINE const uint8_t* wr_renderer_readback(uint32_t width, uint32_t height, uint8_t* dst_buffer, size_t buffer_length) WR_FUNC; -// TODO: Remove. -WR_INLINE void -wr_profiler_set_enabled(WrWindowState* wrWindow, bool enabled) -WR_FUNC; - #undef WR_FUNC #undef WR_DESTRUCTOR_SAFE_FUNC } // extern "C" #endif // WR_h