/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use euclid::Angle; use gleam::gl; use std::ffi::CString; use std::sync::mpsc; use webrender::{CompositorSurfaceTransform, Transaction, api::*}; use webrender::api::units::*; use webrender::Device; #[cfg(target_os = "windows")] use compositor_windows as compositor; #[cfg(target_os = "linux")] use compositor_wayland as compositor; use std::{env, f32, process};
// A very hacky integration with DirectComposite. It proxies calls from the compositor // interface to a simple C99 library which does the DirectComposition / D3D11 / ANGLE // interfacing. This is a very unsafe impl due to the way the window pointer is passed // around! struct DirectCompositeInterface {
window: *mut compositor::Window,
}
// Simplisitic implementation of the WR notifier interface to know when a frame // has been prepared and can be rendered. struct Notifier {
tx: mpsc::Sender<()>,
}
let width = args[4].parse().unwrap(); let height = args[5].parse().unwrap(); let device_size = DeviceIntSize::new(width, height);
// Load GL, construct WR and the native compositor interface. let window = compositor::create_window(
device_size.width,
device_size.height,
enable_compositor,
sync_mode as i32,
); let debug_flags = DebugFlags::empty(); let compositor_config = if enable_compositor {
webrender::CompositorConfig::Native {
compositor: Box::new(DirectCompositeInterface::new(window)),
}
} else {
webrender::CompositorConfig::Draw {
max_partial_present_rects: 0,
draw_previous_partial_present_regions: false,
partial_present: None,
}
}; let opts = webrender::WebRenderOptions {
clear_color: ColorF::new(1.0, 1.0, 1.0, 1.0),
debug_flags,
compositor_config,
surface_origin_is_top_left: false,
..webrender::WebRenderOptions::default()
}; let (tx, rx) = mpsc::channel(); let notifier = Box::new(Notifier::new(tx)); let gl = unsafe {
gl::GlesFns::load_with(|symbol| { let symbol = CString::new(symbol).unwrap(); let ptr = compositor::get_proc_address(symbol.as_ptr());
ptr
})
}; let (mut renderer, sender) =
webrender::create_webrender_instance(gl.clone(), notifier, opts, None).unwrap(); letmut api = sender.create_api(); let document_id = api.add_document(device_size); let device_pixel_ratio = 1.0; letmut current_epoch = Epoch(0); let root_pipeline_id = PipelineId(0, 0); let layout_size = device_size.to_f32() / euclid::Scale::new(device_pixel_ratio); letmut time = 0.0; let scroll_id = ExternalScrollId(3, root_pipeline_id);
// Kick off first transaction which will mean we get a notify below to build the DL and render. letmut txn = Transaction::new();
txn.set_root_pipeline(root_pipeline_id);
// Tick the compositor (in this sample, we don't block on UI events) while compositor::tick(window) { // If there is a new frame ready to draw iflet Ok(..) = rx.try_recv() { // Update and render. This will invoke the native compositor interface implemented above // as required.
renderer.update();
renderer.render(device_size, 0).unwrap(); let _ = renderer.flush_pipeline_info();
// Construct a simple display list that can be drawn and composited by DC. letmut txn = Transaction::new();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.