Update method name and partially document platform crate
co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
7a299e966a
commit
9eecda2dae
10 changed files with 38 additions and 32 deletions
|
@ -249,7 +249,7 @@ async fn test_basic_following(
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
cx_c.cx.update(|_| {});
|
cx_c.cx.update(|_| {});
|
||||||
|
|
||||||
weak_workspace_c.assert_dropped();
|
weak_workspace_c.assert_released();
|
||||||
|
|
||||||
// Clients A and B see that client B is following A, and client C is not present in the followers.
|
// Clients A and B see that client B is following A, and client C is not present in the followers.
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
|
|
|
@ -281,7 +281,7 @@ impl Drop for AnyModel {
|
||||||
entity_map
|
entity_map
|
||||||
.write()
|
.write()
|
||||||
.leak_detector
|
.leak_detector
|
||||||
.handle_dropped(self.entity_id, self.handle_id)
|
.handle_released(self.entity_id, self.handle_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,15 +500,15 @@ impl AnyWeakModel {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assert that model referenced by this weak handle has been dropped.
|
/// Assert that model referenced by this weak handle has been released.
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn assert_dropped(&self) {
|
pub fn assert_released(&self) {
|
||||||
self.entity_ref_counts
|
self.entity_ref_counts
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.write()
|
.write()
|
||||||
.leak_detector
|
.leak_detector
|
||||||
.assert_dropped(self.entity_id);
|
.assert_released(self.entity_id);
|
||||||
|
|
||||||
if self
|
if self
|
||||||
.entity_ref_counts
|
.entity_ref_counts
|
||||||
|
@ -658,12 +658,12 @@ impl LeakDetector {
|
||||||
handle_id
|
handle_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_dropped(&mut self, entity_id: EntityId, handle_id: HandleId) {
|
pub fn handle_released(&mut self, entity_id: EntityId, handle_id: HandleId) {
|
||||||
let handles = self.entity_handles.entry(entity_id).or_default();
|
let handles = self.entity_handles.entry(entity_id).or_default();
|
||||||
handles.remove(&handle_id);
|
handles.remove(&handle_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_dropped(&mut self, entity_id: EntityId) {
|
pub fn assert_released(&mut self, entity_id: EntityId) {
|
||||||
let handles = self.entity_handles.entry(entity_id).or_default();
|
let handles = self.entity_handles.entry(entity_id).or_default();
|
||||||
if !handles.is_empty() {
|
if !handles.is_empty() {
|
||||||
for (_, backtrace) in handles {
|
for (_, backtrace) in handles {
|
||||||
|
|
|
@ -109,9 +109,10 @@ type AnyFuture<R> = Pin<Box<dyn 'static + Send + Future<Output = R>>>;
|
||||||
|
|
||||||
/// BackgroundExecutor lets you run things on background threads.
|
/// BackgroundExecutor lets you run things on background threads.
|
||||||
/// In production this is a thread pool with no ordering guarantees.
|
/// In production this is a thread pool with no ordering guarantees.
|
||||||
/// In tests this is simalated by running tasks one by one in a deterministic
|
/// In tests this is simulated by running tasks one by one in a deterministic
|
||||||
/// (but arbitrary) order controlled by the `SEED` environment variable.
|
/// (but arbitrary) order controlled by the `SEED` environment variable.
|
||||||
impl BackgroundExecutor {
|
impl BackgroundExecutor {
|
||||||
|
#[doc(hidden)]
|
||||||
pub fn new(dispatcher: Arc<dyn PlatformDispatcher>) -> Self {
|
pub fn new(dispatcher: Arc<dyn PlatformDispatcher>) -> Self {
|
||||||
Self { dispatcher }
|
Self { dispatcher }
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,15 +114,20 @@ pub(crate) trait Platform: 'static {
|
||||||
fn delete_credentials(&self, url: &str) -> Result<()>;
|
fn delete_credentials(&self, url: &str) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A handle to a platform's display, e.g. a monitor or laptop screen.
|
||||||
pub trait PlatformDisplay: Send + Sync + Debug {
|
pub trait PlatformDisplay: Send + Sync + Debug {
|
||||||
|
/// Get the ID for this display
|
||||||
fn id(&self) -> DisplayId;
|
fn id(&self) -> DisplayId;
|
||||||
|
|
||||||
/// Returns a stable identifier for this display that can be persisted and used
|
/// Returns a stable identifier for this display that can be persisted and used
|
||||||
/// across system restarts.
|
/// across system restarts.
|
||||||
fn uuid(&self) -> Result<Uuid>;
|
fn uuid(&self) -> Result<Uuid>;
|
||||||
fn as_any(&self) -> &dyn Any;
|
|
||||||
|
/// Get the bounds for this display
|
||||||
fn bounds(&self) -> Bounds<GlobalPixels>;
|
fn bounds(&self) -> Bounds<GlobalPixels>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An opaque identifier for a hardware display
|
||||||
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
|
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
|
||||||
pub struct DisplayId(pub(crate) u32);
|
pub struct DisplayId(pub(crate) u32);
|
||||||
|
|
||||||
|
@ -134,7 +139,7 @@ impl Debug for DisplayId {
|
||||||
|
|
||||||
unsafe impl Send for DisplayId {}
|
unsafe impl Send for DisplayId {}
|
||||||
|
|
||||||
pub trait PlatformWindow {
|
pub(crate) trait PlatformWindow {
|
||||||
fn bounds(&self) -> WindowBounds;
|
fn bounds(&self) -> WindowBounds;
|
||||||
fn content_size(&self) -> Size<Pixels>;
|
fn content_size(&self) -> Size<Pixels>;
|
||||||
fn scale_factor(&self) -> f32;
|
fn scale_factor(&self) -> f32;
|
||||||
|
@ -175,6 +180,9 @@ pub trait PlatformWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This type is public so that our test macro can generate and use it, but it should not
|
||||||
|
/// be considered part of our public API.
|
||||||
|
#[doc(hidden)]
|
||||||
pub trait PlatformDispatcher: Send + Sync {
|
pub trait PlatformDispatcher: Send + Sync {
|
||||||
fn is_main_thread(&self) -> bool;
|
fn is_main_thread(&self) -> bool;
|
||||||
fn dispatch(&self, runnable: Runnable, label: Option<TaskLabel>);
|
fn dispatch(&self, runnable: Runnable, label: Option<TaskLabel>);
|
||||||
|
@ -190,7 +198,7 @@ pub trait PlatformDispatcher: Send + Sync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PlatformTextSystem: Send + Sync {
|
pub(crate) trait PlatformTextSystem: Send + Sync {
|
||||||
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
|
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
|
||||||
fn all_font_names(&self) -> Vec<String>;
|
fn all_font_names(&self) -> Vec<String>;
|
||||||
fn font_id(&self, descriptor: &Font) -> Result<FontId>;
|
fn font_id(&self, descriptor: &Font) -> Result<FontId>;
|
||||||
|
@ -214,15 +222,21 @@ pub trait PlatformTextSystem: Send + Sync {
|
||||||
) -> Vec<usize>;
|
) -> Vec<usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Basic metadata about the current application and operating system.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AppMetadata {
|
pub struct AppMetadata {
|
||||||
|
/// The name of the current operating system
|
||||||
pub os_name: &'static str,
|
pub os_name: &'static str,
|
||||||
|
|
||||||
|
/// The operating system's version
|
||||||
pub os_version: Option<SemanticVersion>,
|
pub os_version: Option<SemanticVersion>,
|
||||||
|
|
||||||
|
/// The current version of the application
|
||||||
pub app_version: Option<SemanticVersion>,
|
pub app_version: Option<SemanticVersion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||||
pub enum AtlasKey {
|
pub(crate) enum AtlasKey {
|
||||||
Glyph(RenderGlyphParams),
|
Glyph(RenderGlyphParams),
|
||||||
Svg(RenderSvgParams),
|
Svg(RenderSvgParams),
|
||||||
Image(RenderImageParams),
|
Image(RenderImageParams),
|
||||||
|
@ -262,7 +276,7 @@ impl From<RenderImageParams> for AtlasKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PlatformAtlas: Send + Sync {
|
pub(crate) trait PlatformAtlas: Send + Sync {
|
||||||
fn get_or_insert_with<'a>(
|
fn get_or_insert_with<'a>(
|
||||||
&self,
|
&self,
|
||||||
key: &AtlasKey,
|
key: &AtlasKey,
|
||||||
|
@ -274,7 +288,7 @@ pub trait PlatformAtlas: Send + Sync {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct AtlasTile {
|
pub(crate) struct AtlasTile {
|
||||||
pub(crate) texture_id: AtlasTextureId,
|
pub(crate) texture_id: AtlasTextureId,
|
||||||
pub(crate) tile_id: TileId,
|
pub(crate) tile_id: TileId,
|
||||||
pub(crate) bounds: Bounds<DevicePixels>,
|
pub(crate) bounds: Bounds<DevicePixels>,
|
||||||
|
|
|
@ -11,7 +11,6 @@ use core_graphics::{
|
||||||
geometry::{CGPoint, CGRect, CGSize},
|
geometry::{CGPoint, CGRect, CGSize},
|
||||||
};
|
};
|
||||||
use objc::{msg_send, sel, sel_impl};
|
use objc::{msg_send, sel, sel_impl};
|
||||||
use std::any::Any;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -154,10 +153,6 @@ impl PlatformDisplay for MacDisplay {
|
||||||
]))
|
]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bounds(&self) -> Bounds<GlobalPixels> {
|
fn bounds(&self) -> Bounds<GlobalPixels> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let native_bounds = CGDisplayBounds(self.0);
|
let native_bounds = CGDisplayBounds(self.0);
|
||||||
|
|
|
@ -31,10 +31,6 @@ impl PlatformDisplay for TestDisplay {
|
||||||
Ok(self.uuid)
|
Ok(self.uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bounds(&self) -> crate::Bounds<crate::GlobalPixels> {
|
fn bounds(&self) -> crate::Bounds<crate::GlobalPixels> {
|
||||||
self.bounds
|
self.bounds
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, order: &StackingOrder, primitive: impl Into<Primitive>) {
|
pub(crate) fn insert(&mut self, order: &StackingOrder, primitive: impl Into<Primitive>) {
|
||||||
let primitive = primitive.into();
|
let primitive = primitive.into();
|
||||||
let clipped_bounds = primitive
|
let clipped_bounds = primitive
|
||||||
.bounds()
|
.bounds()
|
||||||
|
@ -440,7 +440,7 @@ pub enum PrimitiveKind {
|
||||||
Surface,
|
Surface,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Primitive {
|
pub(crate) enum Primitive {
|
||||||
Shadow(Shadow),
|
Shadow(Shadow),
|
||||||
Quad(Quad),
|
Quad(Quad),
|
||||||
Path(Path<ScaledPixels>),
|
Path(Path<ScaledPixels>),
|
||||||
|
@ -589,7 +589,7 @@ impl From<Shadow> for Primitive {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct MonochromeSprite {
|
pub(crate) struct MonochromeSprite {
|
||||||
pub view_id: ViewId,
|
pub view_id: ViewId,
|
||||||
pub layer_id: LayerId,
|
pub layer_id: LayerId,
|
||||||
pub order: DrawOrder,
|
pub order: DrawOrder,
|
||||||
|
@ -622,7 +622,7 @@ impl From<MonochromeSprite> for Primitive {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct PolychromeSprite {
|
pub(crate) struct PolychromeSprite {
|
||||||
pub view_id: ViewId,
|
pub view_id: ViewId,
|
||||||
pub layer_id: LayerId,
|
pub layer_id: LayerId,
|
||||||
pub order: DrawOrder,
|
pub order: DrawOrder,
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub struct TextSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextSystem {
|
impl TextSystem {
|
||||||
pub fn new(platform_text_system: Arc<dyn PlatformTextSystem>) -> Self {
|
pub(crate) fn new(platform_text_system: Arc<dyn PlatformTextSystem>) -> Self {
|
||||||
TextSystem {
|
TextSystem {
|
||||||
line_layout_cache: Arc::new(LineLayoutCache::new(platform_text_system.clone())),
|
line_layout_cache: Arc::new(LineLayoutCache::new(platform_text_system.clone())),
|
||||||
platform_text_system,
|
platform_text_system,
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct LineWrapper {
|
||||||
impl LineWrapper {
|
impl LineWrapper {
|
||||||
pub const MAX_INDENT: u32 = 256;
|
pub const MAX_INDENT: u32 = 256;
|
||||||
|
|
||||||
pub fn new(
|
pub(crate) fn new(
|
||||||
font_id: FontId,
|
font_id: FontId,
|
||||||
font_size: Pixels,
|
font_size: Pixels,
|
||||||
text_system: Arc<dyn PlatformTextSystem>,
|
text_system: Arc<dyn PlatformTextSystem>,
|
||||||
|
|
|
@ -1809,9 +1809,9 @@ mod tests {
|
||||||
assert!(workspace.active_item(cx).is_none());
|
assert!(workspace.active_item(cx).is_none());
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
editor_1.assert_dropped();
|
editor_1.assert_released();
|
||||||
editor_2.assert_dropped();
|
editor_2.assert_released();
|
||||||
buffer.assert_dropped();
|
buffer.assert_released();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue