/* 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/. */
usecrate::blob; use crossbeam::sync::chase_lev; #[cfg(windows)] use dwrote; #[cfg(all(unix, not(target_os = "android")))] use font_loader::system_fonts; use winit::event_loop::EventLoopProxy; use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::sync::mpsc::Receiver; use std::time::Instant; use webrender::{api::*, CompositorConfig}; use webrender::render_api::*; use webrender::api::units::*; use webrender::{DebugFlags, RenderResults, ShaderPrecacheFlags, LayerCompositor}; usecrate::{WindowWrapper, NotifierEvent};
#[derive(Clone)] pubstruct DisplayList { pub pipeline: PipelineId, pub payload: BuiltDisplayList, /// Whether to request that the transaction is presented to the window. /// /// The transaction will be presented if it contains at least one display list /// with present set to true. pub present: bool, /// If set to true, send the transaction after adding this display list to it. pub send_transaction: bool, /// If set to true, the pipeline will be rendered off-screen. Only snapshotted /// stacking contexts will be kept. pub render_offscreen: bool,
}
// TODO(gw): This descriptor matches what we currently support for fonts // but is quite a mess. We should at least document and // use better types for things like the style and stretch. #[derive(Debug, Clone, Hash, PartialEq, Eq)] pubenum FontDescriptor {
Path { path: PathBuf, font_index: u32 },
Family { name: String },
Properties {
family: String,
weight: u32,
style: u32,
stretch: u32,
},
}
let precache_flags = if precache_shaders {
ShaderPrecacheFlags::FULL_COMPILE
} else {
ShaderPrecacheFlags::empty()
};
let compositor_config = match layer_compositor {
Some(compositor) => CompositorConfig::Layer { compositor },
None => CompositorConfig::default(),
};
let opts = webrender::WebRenderOptions {
resource_override_path: shader_override_path,
use_optimized_shaders,
enable_subpixel_aa: !no_subpixel_aa,
debug_flags,
enable_clear_scissor: no_scissor.then_some(false),
max_recorded_profiles: 16,
precache_flags,
blob_image_handler: Some(Box::new(blob::CheckerboardRenderer::new(callbacks.clone()))),
testing: true,
max_internal_texture_size: Some(8196), // Needed for rawtest::test_resize_image.
allow_advanced_blend_equation: window.is_software(),
dump_shader_source, // SWGL doesn't support the GL_ALWAYS depth comparison function used by // `clear_caches_with_quads`, but scissored clears work well.
clear_caches_with_quads: !window.is_software(),
compositor_config,
enable_debugger: true,
..Default::default()
};
// put an Awakened event into the queue to kick off the first frame iflet Some(ref _elp) = proxy { #[cfg(not(target_os = "android"))] let _ = _elp.send_event(());
}
let (timing_sender, timing_receiver) = chase_lev::deque(); let notifier = notifier.unwrap_or_else(|| { let data = Arc::new(Mutex::new(NotifierData::new(proxy, timing_receiver, verbose))); Box::new(Notifier(data))
});
let (renderer, sender) = webrender::create_webrender_instance(
window.clone_gl(),
notifier,
opts,
None,
).unwrap();
let api = sender.create_api(); let document_id = api.add_document(size);
let graphics_api = renderer.get_graphics_api_info();
pubfn layout_simple_ascii(
&mutself,
font_key: FontKey,
instance_key: FontInstanceKey,
text: &str,
size: f32,
origin: LayoutPoint,
flags: FontInstanceFlags,
) -> (Vec<u32>, Vec<LayoutPoint>, LayoutRect) { // Map the string codepoints to glyph indices in this font. // Just drop any glyph that isn't present in this font. let indices: Vec<u32> = self.api
.get_glyph_indices(font_key, text)
.iter()
.filter_map(|idx| *idx)
.collect();
// Retrieve the metrics for each glyph. let metrics = self.api.get_glyph_dimensions(instance_key, indices.clone());
letmut cursor = origin; let direction = if flags.contains(FontInstanceFlags::TRANSPOSE) {
LayoutVector2D::new( 0.0, if flags.contains(FontInstanceFlags::FLIP_Y) { -1.0 } else { 1.0 },
)
} else {
LayoutVector2D::new( if flags.contains(FontInstanceFlags::FLIP_X) { -1.0 } else { 1.0 }, 0.0,
)
}; for metric in metrics {
positions.push(cursor);
iflet Some(GlyphDimensions { left, top, width, height, advance }) = metric { let glyph_rect = LayoutRect::from_origin_and_size(
LayoutPoint::new(cursor.x + left as f32, cursor.y - top as f32),
LayoutSize::new(width as f32, height as f32)
);
bounding_rect = bounding_rect.union(&glyph_rect);
cursor += direction * advance;
} else { // Extract the advances from the metrics. The get_glyph_dimensions API // has a limitation that it can't currently get dimensions for non-renderable // glyphs (e.g. spaces), so just use a rough estimate in that case. let space_advance = size / 3.0;
cursor += direction * space_advance;
}
}
// The platform font implementations don't always handle // the exact dimensions used when subpixel AA is enabled // on glyphs. As a workaround, inflate the bounds by // 2 pixels on either side, to give a slightly less // tight fitting bounding rect. let bounding_rect = bounding_rect.inflate(2.0, 2.0);
pubfn show_onscreen_help(&mutself) { let help_lines = [ "Esc - Quit", "H - Toggle help", "R - Toggle recreating display items each frame", "P - Toggle profiler", "O - Toggle showing intermediate targets", "I - Toggle showing texture caches", "B - Toggle showing alpha primitive rects", "V - Toggle showing overdraw", "G - Toggle showing gpu cache updates", "S - Toggle compact profiler", "Q - Toggle GPU queries for time and samples", "M - Trigger memory pressure event", "T - Save CPU profile to a file", "C - Save a capture to captures/wrench/", "X - Do a hit test at the current cursor position", "Y - Clear all caches",
];
let color_and_offset = [(ColorF::BLACK, 2.0), (ColorF::WHITE, 0.0)]; self.renderer.device.begin_frame(); // next line might compile shaders: let dr = self.renderer.debug_renderer().unwrap();
for co in &color_and_offset { let x = 15.0 + co.1; letmut y = 15.0 + co.1 + dr.line_height(); for line in &help_lines {
dr.add_text(x, y, line, co.0.into(), None);
y += dr.line_height();
}
} self.renderer.device.end_frame();
}
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.