зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1338274 - clean up webrender_binding. r=nical
MozReview-Commit-ID: 4TdnTXjzo52
This commit is contained in:
Родитель
3b7a69366c
Коммит
972b7db4ff
|
@ -1,7 +1,4 @@
|
|||
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;
|
||||
|
@ -14,7 +11,6 @@ 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;
|
||||
|
@ -323,39 +319,6 @@ impl WebRenderFrameBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
|
@ -473,93 +436,6 @@ impl WrMixBlendMode
|
|||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -597,109 +473,6 @@ pub extern fn wr_dp_pop_stacking_context(state: &mut WrState)
|
|||
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));
|
||||
|
@ -771,20 +544,6 @@ pub extern fn wr_dp_push_border(state: &mut WrState, rect: WrRect, clip: WrRect,
|
|||
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() });
|
||||
|
@ -954,15 +713,6 @@ pub extern fn wr_api_add_raw_font(api: &mut RenderApi,
|
|||
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,
|
||||
|
@ -996,30 +746,3 @@ pub extern fn wr_dp_push_text(state: &mut WrState,
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -298,7 +298,6 @@ struct WrExternalImageIdHandler
|
|||
|
||||
// Structs defined in Rust, but opaque to C++ code.
|
||||
struct WrRenderedEpochs;
|
||||
struct WrWindowState;
|
||||
struct WrRenderer;
|
||||
struct WrState;
|
||||
struct WrAPI;
|
||||
|
@ -344,10 +343,6 @@ 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;
|
||||
|
@ -363,6 +358,12 @@ 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)
|
||||
|
@ -384,25 +385,10 @@ 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;
|
||||
|
@ -411,36 +397,6 @@ 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,
|
||||
|
@ -457,22 +413,10 @@ 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)
|
||||
|
@ -495,24 +439,10 @@ 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*
|
||||
|
@ -520,11 +450,6 @@ 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"
|
||||
|
|
Загрузка…
Ссылка в новой задаче