mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Put everything in Context behind the same Mutex (#1050)
* Move all interior mutability from Context to CtxRef and make it a handle * Rename `CtxRef` to `Context` * The old `Context` is now `ContextImpl` and is non-pub * Add benchmark Painter::rect Co-authored-by: Daniel Keller <dklr433@gmail.com>
This commit is contained in:
@@ -114,10 +114,10 @@ mod mutex_impl {
|
||||
#[cfg(feature = "multi_threaded")]
|
||||
mod rw_lock_impl {
|
||||
/// The lock you get from [`RwLock::read`].
|
||||
pub use parking_lot::RwLockReadGuard;
|
||||
pub use parking_lot::MappedRwLockReadGuard as RwLockReadGuard;
|
||||
|
||||
/// The lock you get from [`RwLock::write`].
|
||||
pub use parking_lot::RwLockWriteGuard;
|
||||
pub use parking_lot::MappedRwLockWriteGuard as RwLockWriteGuard;
|
||||
|
||||
/// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled.
|
||||
#[derive(Default)]
|
||||
@@ -131,16 +131,21 @@ mod rw_lock_impl {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn read(&self) -> RwLockReadGuard<'_, T> {
|
||||
self.0.read()
|
||||
parking_lot::RwLockReadGuard::map(self.0.read(), |v| v)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn write(&self) -> RwLockWriteGuard<'_, T> {
|
||||
self.0.write()
|
||||
parking_lot::RwLockWriteGuard::map(self.0.write(), |v| v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "multi_threaded")]
|
||||
mod arc_impl {
|
||||
pub use std::sync::Arc;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[cfg(not(feature = "multi_threaded"))]
|
||||
@@ -201,8 +206,15 @@ mod rw_lock_impl {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "multi_threaded"))]
|
||||
mod arc_impl {
|
||||
// pub use std::rc::Rc as Arc; // TODO(emilk): optimize single threaded code by using `Rc` instead of `Arc`.
|
||||
pub use std::sync::Arc;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
pub use arc_impl::Arc;
|
||||
pub use mutex_impl::{Mutex, MutexGuard};
|
||||
pub use rw_lock_impl::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Shape {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn galley(pos: Pos2, galley: std::sync::Arc<Galley>) -> Self {
|
||||
pub fn galley(pos: Pos2, galley: crate::mutex::Arc<Galley>) -> Self {
|
||||
TextShape::new(pos, galley).into()
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ pub struct TextShape {
|
||||
pub pos: Pos2,
|
||||
|
||||
/// The layed out text, from [`Fonts::layout_job`].
|
||||
pub galley: std::sync::Arc<Galley>,
|
||||
pub galley: crate::mutex::Arc<Galley>,
|
||||
|
||||
/// Add this underline to the whole text.
|
||||
/// You can also set an underline when creating the galley.
|
||||
@@ -373,7 +373,7 @@ pub struct TextShape {
|
||||
|
||||
impl TextShape {
|
||||
#[inline]
|
||||
pub fn new(pos: Pos2, galley: std::sync::Arc<Galley>) -> Self {
|
||||
pub fn new(pos: Pos2, galley: crate::mutex::Arc<Galley>) -> Self {
|
||||
Self {
|
||||
pos,
|
||||
galley,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use crate::{
|
||||
mutex::{Mutex, RwLock},
|
||||
mutex::{Arc, Mutex, RwLock},
|
||||
text::TextStyle,
|
||||
TextureAtlas,
|
||||
};
|
||||
use ahash::AHashMap;
|
||||
use emath::{vec2, Vec2};
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{
|
||||
mutex::Mutex,
|
||||
mutex::{Arc, Mutex},
|
||||
text::{
|
||||
font::{Font, FontImpl},
|
||||
Galley, LayoutJob,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::ops::RangeInclusive;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{Fonts, Galley, Glyph, LayoutJob, LayoutSection, Row, RowVisuals};
|
||||
use crate::{Color32, Mesh, Stroke, Vertex};
|
||||
use crate::{mutex::Arc, Color32, Mesh, Stroke, Vertex};
|
||||
use emath::*;
|
||||
|
||||
/// Temporary storage before line-wrapping.
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#![allow(clippy::derive_hash_xor_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
|
||||
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{cursor::*, font::UvRect};
|
||||
use crate::{Color32, Mesh, Stroke, TextStyle};
|
||||
use crate::{mutex::Arc, Color32, Mesh, Stroke, TextStyle};
|
||||
use emath::*;
|
||||
|
||||
/// Describes the task of laying out text.
|
||||
|
||||
Reference in New Issue
Block a user