From 62a8b15f09f4cb02e8e51319d3f8ed2d3fa02a54 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 12 Aug 2020 10:00:11 +0200 Subject: [PATCH] Move ItemVTable and frieds to corelib::items To avoid ambiguities regarding the use of FieldOffset, the BuiltinItem proc-macro uses fully-qualified type names now. --- .../corelib/abi/datastructures.rs | 85 +----------------- sixtyfps_runtime/corelib/eventloop.rs | 5 +- sixtyfps_runtime/corelib/graphics.rs | 5 +- sixtyfps_runtime/corelib/item_rendering.rs | 2 +- sixtyfps_runtime/corelib/item_tree.rs | 3 +- sixtyfps_runtime/corelib/items.rs | 90 +++++++++++++++++-- sixtyfps_runtime/corelib/rtti.rs | 5 +- sixtyfps_runtime/corelib_macros/lib.rs | 4 +- .../interpreter/dynamic_component.rs | 4 +- sixtyfps_runtime/interpreter/eval.rs | 6 +- sixtyfps_runtime/qt_style/lib.rs | 2 +- 11 files changed, 104 insertions(+), 107 deletions(-) diff --git a/sixtyfps_runtime/corelib/abi/datastructures.rs b/sixtyfps_runtime/corelib/abi/datastructures.rs index 5ae961596..658abf57b 100644 --- a/sixtyfps_runtime/corelib/abi/datastructures.rs +++ b/sixtyfps_runtime/corelib/abi/datastructures.rs @@ -2,11 +2,9 @@ use vtable::*; -use crate::graphics::{HighLevelRenderingPrimitive, Rect, RenderingVariable}; use crate::input::{InputEventResult, MouseEvent}; -use crate::item_rendering::CachedRenderingData; use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult}; -use crate::{layout::LayoutInfo, SharedArray}; +use crate::layout::LayoutInfo; /// A Component is representing an unit that is allocated together #[vtable] @@ -36,84 +34,3 @@ pub struct ComponentVTable { /// Alias for `vtable::VRef` which represent a pointer to a `dyn Component` with /// the associated vtable pub type ComponentRef<'a> = vtable::VRef<'a, ComponentVTable>; - -/// Items are the nodes in the render tree. -#[vtable] -#[repr(C)] -pub struct ItemVTable { - /// Returns the geometry of this item (relative to its parent item) - pub geometry: extern "C" fn(core::pin::Pin>) -> Rect, - - /// offset in bytes fromthe *const ItemImpl. - /// isize::MAX means None - #[allow(non_upper_case_globals)] - #[field_offset(CachedRenderingData)] - pub cached_rendering_data_offset: usize, - - /// Return the rendering primitive used to display this item. This should depend on only - /// rarely changed properties as it typically contains data uploaded to the GPU. - pub rendering_primitive: - extern "C" fn(core::pin::Pin>) -> HighLevelRenderingPrimitive, - - /// Return the variables needed to render the graphical primitives of this item. These - /// are typically variables that do not require uploading any data sets to the GPU and - /// can instead be represented using uniforms. - pub rendering_variables: - extern "C" fn(core::pin::Pin>) -> SharedArray, - - /// We would need max/min/preferred size, and all layout info - pub layouting_info: extern "C" fn(core::pin::Pin>) -> LayoutInfo, - - /// input event - pub input_event: - extern "C" fn(core::pin::Pin>, MouseEvent) -> InputEventResult, -} - -/// Alias for `vtable::VRef` which represent a pointer to a `dyn Item` with -/// the associated vtable -pub type ItemRef<'a> = vtable::VRef<'a, ItemVTable>; - -// This is here because for some reason (rust bug?) the ItemVTable_static is not accessible in the other modules - -ItemVTable_static! { - /// The VTable for `Image` - #[no_mangle] - pub static ImageVTable for crate::items::Image -} -ItemVTable_static! { - /// The VTable for `Rectangle` - #[no_mangle] - pub static RectangleVTable for crate::items::Rectangle -} -ItemVTable_static! { - /// The VTable for `BorderRectangle` - #[no_mangle] - pub static BorderRectangleVTable for crate::items::BorderRectangle -} -ItemVTable_static! { - /// The VTable for `Text` - #[no_mangle] - pub static TextVTable for crate::items::Text -} -ItemVTable_static! { - /// The VTable for `TouchArea` - #[no_mangle] - pub static TouchAreaVTable for crate::items::TouchArea -} -ItemVTable_static! { - /// The VTable for `Path` - #[no_mangle] - pub static PathVTable for crate::items::Path -} - -ItemVTable_static! { - /// The VTable for `Flickable` - #[no_mangle] - pub static FlickableVTable for crate::items::Flickable -} - -ItemVTable_static! { - /// The VTable for `Window` - #[no_mangle] - pub static WindowVTable for crate::items::Window -} diff --git a/sixtyfps_runtime/corelib/eventloop.rs b/sixtyfps_runtime/corelib/eventloop.rs index ab8667fe4..635fa201f 100644 --- a/sixtyfps_runtime/corelib/eventloop.rs +++ b/sixtyfps_runtime/corelib/eventloop.rs @@ -1,4 +1,5 @@ -use crate::abi::datastructures::{ComponentVTable, ItemRef}; +use crate::abi::datastructures::ComponentVTable; +use crate::items::ItemRef; use std::cell::RefCell; use std::{ pin::Pin, @@ -269,7 +270,7 @@ pub mod ffi { #![allow(unsafe_code)] use super::*; - use crate::abi::datastructures::ItemVTable; + use crate::items::ItemVTable; #[allow(non_camel_case_types)] type c_void = (); diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index 22f0d3ada..1399f6cbb 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -1,9 +1,10 @@ extern crate alloc; use crate::input::{MouseEvent, MouseEventType}; +use crate::items::ItemRef; use crate::properties::{InterpolatedPropertyValue, Property}; #[cfg(feature = "rtti")] -use crate::rtti::{BuiltinItem, FieldInfo, FieldOffset, PropertyInfo, ValueType}; -use crate::{abi::datastructures::ItemRef, SharedArray}; +use crate::rtti::{BuiltinItem, FieldInfo, PropertyInfo, ValueType}; +use crate::SharedArray; use cgmath::Matrix4; use const_field_offset::FieldOffsets; diff --git a/sixtyfps_runtime/corelib/item_rendering.rs b/sixtyfps_runtime/corelib/item_rendering.rs index 36dfa6e0a..301551e38 100644 --- a/sixtyfps_runtime/corelib/item_rendering.rs +++ b/sixtyfps_runtime/corelib/item_rendering.rs @@ -1,5 +1,5 @@ -use super::abi::datastructures::ItemRef; use super::graphics::{Frame, GraphicsBackend, RenderingCache, RenderingPrimitivesBuilder}; +use super::items::ItemRef; use crate::item_tree::ItemVisitorResult; use cgmath::{Matrix4, SquareMatrix, Vector3}; use std::cell::Cell; diff --git a/sixtyfps_runtime/corelib/item_tree.rs b/sixtyfps_runtime/corelib/item_tree.rs index bf01a6564..4d16cffd9 100644 --- a/sixtyfps_runtime/corelib/item_tree.rs +++ b/sixtyfps_runtime/corelib/item_tree.rs @@ -1,4 +1,5 @@ -use crate::abi::datastructures::{ComponentVTable, ItemRef, ItemVTable}; +use crate::abi::datastructures::ComponentVTable; +use crate::items::{ItemRef, ItemVTable}; use crate::ComponentRefPin; use core::pin::Pin; use vtable::*; diff --git a/sixtyfps_runtime/corelib/items.rs b/sixtyfps_runtime/corelib/items.rs index 3eba9bb60..02c14d78b 100644 --- a/sixtyfps_runtime/corelib/items.rs +++ b/sixtyfps_runtime/corelib/items.rs @@ -16,7 +16,6 @@ When adding an item or a property, it needs to be kept in sync with different pl #![allow(non_upper_case_globals)] #![allow(missing_docs)] // because documenting each property of items is redundent -use super::abi::datastructures::{Item, ItemConsts}; use super::graphics::{Color, HighLevelRenderingPrimitive, PathData, Rect, Resource}; use super::input::{InputEventResult, MouseEvent, MouseEventType}; use super::item_rendering::CachedRenderingData; @@ -27,6 +26,43 @@ use crate::{Property, SharedString, Signal}; use const_field_offset::FieldOffsets; use core::pin::Pin; use sixtyfps_corelib_macros::*; +use vtable::*; + +/// Items are the nodes in the render tree. +#[vtable] +#[repr(C)] +pub struct ItemVTable { + /// Returns the geometry of this item (relative to its parent item) + pub geometry: extern "C" fn(core::pin::Pin>) -> Rect, + + /// offset in bytes fromthe *const ItemImpl. + /// isize::MAX means None + #[allow(non_upper_case_globals)] + #[field_offset(CachedRenderingData)] + pub cached_rendering_data_offset: usize, + + /// Return the rendering primitive used to display this item. This should depend on only + /// rarely changed properties as it typically contains data uploaded to the GPU. + pub rendering_primitive: + extern "C" fn(core::pin::Pin>) -> HighLevelRenderingPrimitive, + + /// Return the variables needed to render the graphical primitives of this item. These + /// are typically variables that do not require uploading any data sets to the GPU and + /// can instead be represented using uniforms. + pub rendering_variables: + extern "C" fn(core::pin::Pin>) -> SharedArray, + + /// We would need max/min/preferred size, and all layout info + pub layouting_info: extern "C" fn(core::pin::Pin>) -> LayoutInfo, + + /// input event + pub input_event: + extern "C" fn(core::pin::Pin>, MouseEvent) -> InputEventResult, +} + +/// Alias for `vtable::VRef` which represent a pointer to a `dyn Item` with +/// the associated vtable +pub type ItemRef<'a> = vtable::VRef<'a, ItemVTable>; #[repr(C)] #[derive(FieldOffsets, Default, BuiltinItem)] @@ -82,7 +118,11 @@ impl ItemConsts for Rectangle { > = Rectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::RectangleVTable; +ItemVTable_static! { + /// The VTable for `Rectangle` + #[no_mangle] + pub static RectangleVTable for Rectangle +} #[repr(C)] #[derive(FieldOffsets, Default, BuiltinItem)] @@ -147,7 +187,11 @@ impl ItemConsts for BorderRectangle { > = BorderRectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::BorderRectangleVTable; +ItemVTable_static! { + /// The VTable for `BorderRectangle` + #[no_mangle] + pub static BorderRectangleVTable for BorderRectangle +} #[repr(C)] #[derive(FieldOffsets, Default, BuiltinItem)] @@ -210,7 +254,11 @@ impl ItemConsts for Image { > = Image::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::ImageVTable; +ItemVTable_static! { + /// The VTable for `Image` + #[no_mangle] + pub static ImageVTable for Image +} #[derive(Copy, Clone, Debug, PartialEq, strum_macros::EnumString, strum_macros::Display)] #[repr(C)] @@ -328,7 +376,11 @@ impl ItemConsts for Text { Text::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::TextVTable; +ItemVTable_static! { + /// The VTable for `Text` + #[no_mangle] + pub static TextVTable for Text +} /// The implementation of the `TouchArea` element #[repr(C)] @@ -411,7 +463,12 @@ impl ItemConsts for TouchArea { CachedRenderingData, > = TouchArea::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::TouchAreaVTable; + +ItemVTable_static! { + /// The VTable for `TouchArea` + #[no_mangle] + pub static TouchAreaVTable for TouchArea +} /// The implementation of the `Path` element #[repr(C)] @@ -468,7 +525,11 @@ impl ItemConsts for Path { Path::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::abi::datastructures::PathVTable; +ItemVTable_static! { + /// The VTable for `Path` + #[no_mangle] + pub static PathVTable for Path +} /// The implementation of the `Flickable` element #[repr(C)] @@ -518,7 +579,14 @@ impl ItemConsts for Flickable { const cached_rendering_data_offset: const_field_offset::FieldOffset = Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } -pub use crate::{abi::datastructures::FlickableVTable, graphics::RenderingVariable, SharedArray}; + +ItemVTable_static! { + /// The VTable for `Flickable` + #[no_mangle] + pub static FlickableVTable for Flickable +} + +pub use crate::{graphics::RenderingVariable, SharedArray}; #[repr(C)] /// Wraps the internal datastructure for the Flickable @@ -607,3 +675,9 @@ impl ItemConsts for Window { const cached_rendering_data_offset: const_field_offset::FieldOffset = Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); } + +ItemVTable_static! { + /// The VTable for `Window` + #[no_mangle] + pub static WindowVTable for Window +} diff --git a/sixtyfps_runtime/corelib/rtti.rs b/sixtyfps_runtime/corelib/rtti.rs index e4cdbd760..926217a73 100644 --- a/sixtyfps_runtime/corelib/rtti.rs +++ b/sixtyfps_runtime/corelib/rtti.rs @@ -171,5 +171,8 @@ pub trait BuiltinItem: Sized { fn name() -> &'static str; fn properties() -> Vec<(&'static str, &'static dyn PropertyInfo)>; fn fields() -> Vec<(&'static str, &'static dyn FieldInfo)>; - fn signals() -> Vec<(&'static str, FieldOffset>)>; + fn signals() -> Vec<( + &'static str, + const_field_offset::FieldOffset, const_field_offset::PinnedFlag>, + )>; } diff --git a/sixtyfps_runtime/corelib_macros/lib.rs b/sixtyfps_runtime/corelib_macros/lib.rs index 7b5deda38..e38167bca 100644 --- a/sixtyfps_runtime/corelib_macros/lib.rs +++ b/sixtyfps_runtime/corelib_macros/lib.rs @@ -71,12 +71,12 @@ pub fn builtin_item(input: TokenStream) -> TokenStream { } fn fields() -> Vec<(&'static str, &'static dyn FieldInfo)> { vec![#( { - const O : FieldOffset<#item_name, #plain_field_types> = + const O : const_field_offset::FieldOffset<#item_name, #plain_field_types, const_field_offset::PinnedFlag> = #item_name::FIELD_OFFSETS.#plain_field_names; (stringify!(#plain_field_names), &O as &'static dyn FieldInfo ) } ),*] } - fn signals() -> Vec<(&'static str, FieldOffset>)> { + fn signals() -> Vec<(&'static str, const_field_offset::FieldOffset, const_field_offset::PinnedFlag>)> { vec![#( (stringify!(#signal_field_names),#item_name::FIELD_OFFSETS.#signal_field_names) ),*] diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index f76ec86ec..b258f61da 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -7,12 +7,12 @@ use object_tree::{Element, ElementRc}; use sixtyfps_compilerlib::layout::{GridLayout, Layout, LayoutItem, PathLayout}; use sixtyfps_compilerlib::typeregister::Type; use sixtyfps_compilerlib::*; -use sixtyfps_corelib::abi::datastructures::{ComponentVTable, ItemRef, ItemVTable}; +use sixtyfps_corelib::abi::datastructures::ComponentVTable; use sixtyfps_corelib::graphics::Resource; use sixtyfps_corelib::item_tree::{ ItemTreeNode, ItemVisitorRefMut, TraversalOrder, VisitChildrenResult, }; -use sixtyfps_corelib::items::{Flickable, PropertyAnimation, Rectangle}; +use sixtyfps_corelib::items::{Flickable, ItemRef, ItemVTable, PropertyAnimation, Rectangle}; use sixtyfps_corelib::layout::LayoutInfo; use sixtyfps_corelib::properties::{InterpolatedPropertyValue, PropertyListenerScope}; use sixtyfps_corelib::rtti::{self, FieldOffset, PropertyInfo}; diff --git a/sixtyfps_runtime/interpreter/eval.rs b/sixtyfps_runtime/interpreter/eval.rs index 366dad44d..016590574 100644 --- a/sixtyfps_runtime/interpreter/eval.rs +++ b/sixtyfps_runtime/interpreter/eval.rs @@ -8,8 +8,8 @@ use sixtyfps_compilerlib::expression_tree::{ use sixtyfps_compilerlib::{object_tree::ElementRc, typeregister::Type}; use sixtyfps_corelib as corelib; use sixtyfps_corelib::{ - abi::datastructures::ItemRef, graphics::PathElement, items::PropertyAnimation, Color, PathData, - Resource, SharedArray, SharedString, + graphics::PathElement, items::ItemRef, items::PropertyAnimation, Color, PathData, Resource, + SharedArray, SharedString, }; use std::{collections::HashMap, rc::Rc}; @@ -25,7 +25,7 @@ pub trait ErasedPropertyInfo { fn offset(&self) -> usize; } -impl> ErasedPropertyInfo +impl> ErasedPropertyInfo for &'static dyn corelib::rtti::PropertyInfo { fn get(&self, item: Pin) -> Value { diff --git a/sixtyfps_runtime/qt_style/lib.rs b/sixtyfps_runtime/qt_style/lib.rs index 1f501c138..89fc1df78 100644 --- a/sixtyfps_runtime/qt_style/lib.rs +++ b/sixtyfps_runtime/qt_style/lib.rs @@ -5,10 +5,10 @@ use const_field_offset::FieldOffsets; use core::pin::Pin; #[cfg(have_qt)] use cpp::cpp; -use sixtyfps_corelib::abi::datastructures::{Item, ItemConsts, ItemVTable}; use sixtyfps_corelib::graphics::{HighLevelRenderingPrimitive, Rect, RenderingVariable, Resource}; use sixtyfps_corelib::input::{InputEventResult, MouseEvent, MouseEventType}; use sixtyfps_corelib::item_rendering::CachedRenderingData; +use sixtyfps_corelib::items::{Item, ItemConsts, ItemVTable}; use sixtyfps_corelib::layout::LayoutInfo; #[cfg(feature = "rtti")] use sixtyfps_corelib::rtti::*;