Skip to content

Commit

Permalink
Remove rayon from azul-core
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 21, 2024
1 parent 8b71bef commit 80aecda
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 96 deletions.
18 changes: 5 additions & 13 deletions azul-core/src/app_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ impl RendererResources {
/// This function should be called after the StyledDom has been
/// exchanged for the next frame and AFTER all OpenGL textures
/// and image callbacks have been resolved.
#[cfg(feature = "multithreading")]
pub fn do_gc(
&mut self,
all_resource_updates: &mut Vec<ResourceUpdate>,
Expand All @@ -699,8 +698,6 @@ impl RendererResources {
// initialized texture cache of the NEXT frame
gl_texture_cache: &GlTextureCache,
) {
use crate::rayon::iter::IntoParallelRefIterator;
use crate::rayon::iter::ParallelIterator;
use alloc::collections::btree_set::BTreeSet;

// Get all fonts / images that are in the DOM for the next frame
Expand Down Expand Up @@ -754,7 +751,7 @@ impl RendererResources {
// If the current frame contains an image, but the next frame does not, delete it
let delete_image_resources = self
.currently_registered_images
.par_iter()
.iter()
.filter(|(image_ref_hash, _)| !next_frame_image_keys.contains(image_ref_hash))
.map(|(image_ref_hash, resolved_image)| {
(
Expand Down Expand Up @@ -782,7 +779,7 @@ impl RendererResources {

self.last_frame_registered_fonts = self
.currently_registered_fonts
.par_iter()
.iter()
.map(|(fk, (_, fi))| (fk.clone(), fi.clone()))
.collect();

Expand Down Expand Up @@ -2191,15 +2188,13 @@ pub struct GlyphInfo {
pub placement: Placement,
}

#[cfg(feature = "multithreading")]
pub fn get_inline_text(
words: &Words,
shaped_words: &ShapedWords,
word_positions: &WordPositions,
inline_text_layout: &InlineTextLayout,
) -> InlineText {
use crate::callbacks::{InlineGlyph, InlineLine, InlineTextContents, InlineWord};
use rayon::prelude::*;

// check the range so that in the worst case there isn't a random crash here
fn get_range_checked_inclusive_end(
Expand Down Expand Up @@ -2227,14 +2222,14 @@ pub fn get_inline_text(
let inline_lines = inline_text_layout
.lines
.as_ref()
.par_iter()
.iter()
.filter_map(|line| {
let word_items = words.items.as_ref();
let word_start = line.word_start.min(line.word_end);
let word_end = line.word_end.max(line.word_start);

let words = get_range_checked_inclusive_end(word_items, word_start, word_end)?
.par_iter()
.iter()
.enumerate()
.filter_map(|(word_idx, word)| {
let word_idx = word_start + word_idx;
Expand Down Expand Up @@ -2507,7 +2502,6 @@ pub struct LayoutedGlyphs {
/// Scans the `StyledDom` for new images and fonts. After this call,
/// the `all_resource_updates` contains all the `AddFont` / `AddImage`
/// / `AddFontInstance` messages.
#[cfg(feature = "multithreading")]
pub fn add_fonts_and_images(
image_cache: &ImageCache,
renderer_resources: &mut RendererResources,
Expand Down Expand Up @@ -3123,7 +3117,6 @@ pub fn build_add_font_resource_updates(
/// add-and-remove images after every IFrameCallback, which would cause a lot of
/// I/O waiting.
#[allow(unused_variables)]
#[cfg(feature = "multithreading")]
pub fn build_add_image_resource_updates(
renderer_resources: &RendererResources,
id_namespace: IdNamespace,
Expand All @@ -3132,10 +3125,9 @@ pub fn build_add_image_resource_updates(
images_in_dom: &FastBTreeSet<ImageRef>,
insert_into_active_gl_textures: GlStoreImageFn,
) -> Vec<(ImageRefHash, AddImageMsg)> {
use rayon::prelude::*;

images_in_dom
.par_iter()
.iter()
.filter_map(|image_ref| {
let image_ref_hash = image_ref.get_hash();

Expand Down
2 changes: 0 additions & 2 deletions azul-core/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,6 @@ impl CallbackInfo {
}
}

#[cfg(feature = "multithreading")]
pub fn get_inline_text(&self, node_id: DomNodeId) -> Option<InlineText> {
let nid = node_id.node.into_crate_internal()?;
let layout_result = self.internal_get_layout_results().get(node_id.dom.inner)?;
Expand Down Expand Up @@ -2191,7 +2190,6 @@ impl RenderImageCallbackInfo {
// fn get_font()
// fn get_image()

#[cfg(feature = "multithreading")]
pub fn get_inline_text(&self, node_id: DomNodeId) -> Option<InlineText> {
if node_id.dom != self.get_callback_node_id().dom {
return None;
Expand Down
6 changes: 1 addition & 5 deletions azul-core/src/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,6 @@ pub struct RenderCallbacks {

impl SolvedLayout {
/// Does the layout, updates the image + font resources for the RenderAPI
#[cfg(feature = "multithreading")]
pub fn new(
styled_dom: StyledDom,
epoch: Epoch,
Expand Down Expand Up @@ -851,12 +850,10 @@ impl SolvedLayout {
}
}

#[cfg(feature = "multithreading")]
pub fn push_rectangles_into_displaylist<'a>(
root_content_group: &ContentGroup,
referenced_content: &DisplayListParametersRef<'a>,
) -> Option<DisplayListMsg> {
use rayon::prelude::*;

let mut content = displaylist_handle_rect(
root_content_group.root.into_crate_internal().unwrap(),
Expand All @@ -866,7 +863,7 @@ pub fn push_rectangles_into_displaylist<'a>(
let children = root_content_group
.children
.as_ref()
.par_iter()
.iter()
.filter_map(|child_content_group| {
push_rectangles_into_displaylist(child_content_group, referenced_content)
})
Expand All @@ -878,7 +875,6 @@ pub fn push_rectangles_into_displaylist<'a>(
}

/// Push a single rectangle into the display list builder
#[cfg(feature = "multithreading")]
pub fn displaylist_handle_rect<'a>(
rect_idx: NodeId,
referenced_content: &DisplayListParametersRef<'a>,
Expand Down
2 changes: 1 addition & 1 deletion azul-core/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ impl Dom {
self.estimated_total_children + 1
}

#[cfg(all(feature = "multithreading", feature = "css_parser"))]
#[cfg(feature = "css_parser")]
pub fn style(&mut self, css: azul_css_parser::CssApiWrapper) -> StyledDom {
StyledDom::new(self, css)
}
Expand Down
24 changes: 6 additions & 18 deletions azul-core/src/id_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,73 +385,61 @@ impl<'a, T: 'a> NodeDataContainerRefMut<'a, T> {
}

impl<'a, T: Send + 'a> NodeDataContainerRefMut<'a, T> {
#[cfg(feature = "multithreading")]
pub fn transform_multithread<U: Send, F: Send + Sync>(
&mut self,
closure: F,
) -> NodeDataContainer<U>
where
F: Fn(&mut T, NodeId) -> U,
{
use rayon::iter::IndexedParallelIterator;
use rayon::iter::IntoParallelRefMutIterator;
use rayon::iter::ParallelIterator;
NodeDataContainer {
internal: self
.internal
.par_iter_mut()
.iter_mut()
.enumerate()
.map(|(node_id, node)| closure(node, NodeId::new(node_id)))
.collect::<Vec<U>>(),
}
}
#[cfg(feature = "multithreading")]

pub fn transform_multithread_optional<U: Send, F: Send + Sync>(&mut self, closure: F) -> Vec<U>
where
F: Fn(&mut T, NodeId) -> Option<U>,
{
use rayon::iter::IndexedParallelIterator;
use rayon::iter::IntoParallelRefMutIterator;
use rayon::iter::ParallelIterator;
self.internal
.par_iter_mut()
.iter_mut()
.enumerate()
.filter_map(|(node_id, node)| closure(node, NodeId::new(node_id)))
.collect::<Vec<U>>()
}
}

impl<'a, T: Send + 'a> NodeDataContainerRef<'a, T> {
#[cfg(feature = "multithreading")]

pub fn transform_nodeid<U: Send, F: Send + Sync>(&self, closure: F) -> NodeDataContainer<U>
where
F: Fn(NodeId) -> U,
{
use crate::rayon::iter::ParallelIterator;
use rayon::iter::IntoParallelIterator;
let len = self.len();
NodeDataContainer {
internal: (0..len)
.into_par_iter()
.into_iter()
.map(|node_id| closure(NodeId::new(node_id)))
.collect::<Vec<U>>(),
}
}

#[cfg(feature = "multithreading")]
pub fn transform_nodeid_multithreaded_optional<U: Send, F: Send + Sync>(
&self,
closure: F,
) -> NodeDataContainer<U>
where
F: Fn(NodeId) -> Option<U>,
{
use crate::rayon::iter::ParallelIterator;
use rayon::iter::IntoParallelIterator;
let len = self.len();
NodeDataContainer {
internal: (0..len)
.into_par_iter()
.into_iter()
.filter_map(|node_id| closure(NodeId::new(node_id)))
.collect::<Vec<U>>(),
}
Expand Down
2 changes: 0 additions & 2 deletions azul-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ extern crate alloc;

extern crate libm;

#[cfg(feature = "multithreading")]
extern crate rayon;
#[macro_use]
extern crate azul_css;
#[cfg(feature = "css_parser")]
Expand Down
Loading

0 comments on commit 80aecda

Please sign in to comment.