mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
Run the C++ generated component through the GL backend
... which in turn forward to the corelib, but with the GL renderer attached.
This commit is contained in:
parent
5b4966f652
commit
83eb00b080
6 changed files with 87 additions and 2 deletions
|
@ -4,6 +4,7 @@ using str = char; // FIXME: this is just required because of something wrong
|
|||
namespace sixtyfps::internal {
|
||||
struct ComponentType;
|
||||
} // namespace sixtyfps::internal
|
||||
#include "sixtyfps_gl_internal.h"
|
||||
#include "sixtyfps_internal.h"
|
||||
|
||||
namespace sixtyfps {
|
||||
|
@ -16,7 +17,7 @@ template <typename Component> void run(Component *c) {
|
|||
// FIXME! some static assert that the component is indeed a generated
|
||||
// component matching the vtable. In fact, i think the VTable should be a
|
||||
// static member of the Component
|
||||
internal::sixtyfps_runtime_run_component(
|
||||
internal::sixtyfps_runtime_run_component_with_gl_renderer(
|
||||
&Component::component_type,
|
||||
reinterpret_cast<internal::ComponentImpl *>(c));
|
||||
}
|
||||
|
|
|
@ -45,8 +45,19 @@ add_custom_target(ensure_sixtyfps_runtime_up_to_date
|
|||
)
|
||||
add_dependencies(sixtyfps ensure_sixtyfps_runtime_up_to_date)
|
||||
|
||||
file(GLOB _SIXTYFPS_GL_INTERNAL_HEADER "${_SIXTYFPS_TARGET_DIR}/build/gl-*/out")
|
||||
|
||||
add_library(sixtyfps_gl SHARED IMPORTED)
|
||||
set_target_properties(sixtyfps_gl PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${_SIXTYFPS_GL_INTERNAL_HEADER}"
|
||||
IMPORTED_LOCATION
|
||||
"${_SIXTYFPS_TARGET_DIR}/libgl${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
|
||||
target_link_libraries(sixtyfps_gl INTERFACE sixtyfps)
|
||||
|
||||
### END This should be moce in some file in api/sixtyfps-cpp/cmake
|
||||
|
||||
add_executable(hello)
|
||||
target_link_libraries(hello sixtyfps)
|
||||
target_link_libraries(hello sixtyfps_gl)
|
||||
sixtyfps_target_60_sources(hello hello.60)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use core::ptr::NonNull;
|
||||
|
||||
pub mod graphics;
|
||||
|
||||
pub mod abi {
|
||||
|
@ -57,6 +59,31 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run_component<GraphicsBackend, GraphicsFactoryFunc>(
|
||||
component_type: *const abi::datastructures::ComponentType,
|
||||
component: NonNull<abi::datastructures::ComponentImpl>,
|
||||
graphics_backend_factory: GraphicsFactoryFunc,
|
||||
) where
|
||||
GraphicsBackend: graphics::GraphicsBackend + 'static,
|
||||
GraphicsFactoryFunc:
|
||||
FnOnce(&winit::event_loop::EventLoop<()>, winit::window::WindowBuilder) -> GraphicsBackend,
|
||||
{
|
||||
let component = unsafe {
|
||||
abi::datastructures::ComponentUniquePtr::new(
|
||||
NonNull::new_unchecked(component_type as *mut _),
|
||||
component,
|
||||
)
|
||||
};
|
||||
|
||||
let main_window = MainWindow::new(graphics_backend_factory);
|
||||
|
||||
main_window.run_event_loop(move |_width, _height, mut _renderer| {
|
||||
component.visit_items(|item| {
|
||||
println!("Rendering... {:?}", item.rendering_info());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
|
|
@ -10,6 +10,9 @@ crate-type = ["lib", "cdylib"]
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = "0.14.2"
|
||||
|
||||
[dependencies]
|
||||
sixtyfps_corelib = { package = "corelib", path = "../../corelib" }
|
||||
lyon = { version = "0.15.8" }
|
||||
|
|
28
sixtyfps_runtime/rendering_backends/gl/build.rs
Normal file
28
sixtyfps_runtime/rendering_backends/gl/build.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
extern crate cbindgen;
|
||||
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let config = cbindgen::Config {
|
||||
pragma_once: true,
|
||||
include_version: true,
|
||||
namespaces: Some(vec!["sixtyfps".into(), "internal".into()]),
|
||||
line_length: 100,
|
||||
tab_width: 4,
|
||||
// Note: we might need to switch to C if we need to generate bindings for language that needs C headers
|
||||
language: cbindgen::Language::Cxx,
|
||||
cpp_compat: true,
|
||||
documentation: true,
|
||||
export: cbindgen::ExportConfig { ..Default::default() },
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
cbindgen::Builder::new()
|
||||
.with_config(config)
|
||||
.with_crate(crate_dir)
|
||||
.with_header("#include <sixtyfps_internal.h>")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings")
|
||||
.write_to_file(env::var("OUT_DIR").unwrap() + "/sixtyfps_gl_internal.h");
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
use cgmath::Matrix4;
|
||||
use core::ptr::NonNull;
|
||||
use glow::{Context as GLContext, HasContext};
|
||||
use kurbo::{BezPath, PathEl, Point, Rect};
|
||||
use lyon::path::PathEvent;
|
||||
use lyon::tessellation::geometry_builder::{BuffersBuilder, VertexBuffers};
|
||||
use lyon::tessellation::{FillAttributes, FillOptions, FillTessellator};
|
||||
use sixtyfps_corelib::abi::datastructures::{ComponentImpl, ComponentType};
|
||||
use sixtyfps_corelib::graphics::{Color, FillStyle, Frame as GraphicsFrame, GraphicsBackend};
|
||||
use std::marker;
|
||||
use std::mem;
|
||||
|
@ -679,6 +681,19 @@ impl Drop for GLRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Run the given component
|
||||
/// Both pointer must be valid until the call to vtable.destroy
|
||||
/// vtable will is a *const, and inner like a *mut
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sixtyfps_runtime_run_component_with_gl_renderer(
|
||||
component_type: *const ComponentType,
|
||||
component: NonNull<ComponentImpl>,
|
||||
) {
|
||||
sixtyfps_corelib::run_component(component_type, component, |event_loop, window_builder| {
|
||||
GLRenderer::new(&event_loop, window_builder)
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue