mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
WIP
This commit is contained in:
@@ -79,6 +79,19 @@ function getHeapU32() {
|
|||||||
return Module.HEAPU32;
|
return Module.HEAPU32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearShapeFills() {
|
||||||
|
Module._clear_shape_fills();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addShapeSolidFill(argb) {
|
||||||
|
const ptr = allocBytes(176);
|
||||||
|
const heap = getHeapU32();
|
||||||
|
const dv = new DataView(heap.buffer);
|
||||||
|
dv.setUint8(ptr, 0x00, true);
|
||||||
|
dv.setUint32(ptr + 4, argb, true);
|
||||||
|
Module._add_shape_fill();
|
||||||
|
}
|
||||||
|
|
||||||
export function setShapeChildren(shapeIds) {
|
export function setShapeChildren(shapeIds) {
|
||||||
const offset = allocBytes(shapeIds.length * 16);
|
const offset = allocBytes(shapeIds.length * 16);
|
||||||
const heap = getHeapU32();
|
const heap = getHeapU32();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import initWasmModule from '/js/render_wasm.js';
|
import initWasmModule from '/js/render_wasm.js';
|
||||||
import {
|
import {
|
||||||
init, assignCanvas, hexToU32ARGB, getRandomInt, getRandomColor,
|
init, addShapeSolidFill, assignCanvas, hexToU32ARGB, getRandomInt, getRandomColor,
|
||||||
getRandomFloat, useShape, setShapeChildren, setupInteraction
|
getRandomFloat, useShape, setShapeChildren, setupInteraction
|
||||||
} from './js/lib.js';
|
} from './js/lib.js';
|
||||||
|
|
||||||
@@ -41,13 +41,14 @@
|
|||||||
setupInteraction(canvas);
|
setupInteraction(canvas);
|
||||||
|
|
||||||
const children = [];
|
const children = [];
|
||||||
for (let i = 0; i < 1000; i++) {
|
for (let i = 0; i < 10_000; i++) {
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = crypto.randomUUID();
|
||||||
children.push(uuid);
|
children.push(uuid);
|
||||||
|
|
||||||
useShape(uuid);
|
useShape(uuid);
|
||||||
Module._set_parent(0, 0, 0, 0);
|
Module._set_parent(0, 0, 0, 0);
|
||||||
Module._set_shape_type(3);
|
Module._set_shape_type(3);
|
||||||
|
|
||||||
const x1 = getRandomInt(0, canvas.width);
|
const x1 = getRandomInt(0, canvas.width);
|
||||||
const y1 = getRandomInt(0, canvas.height);
|
const y1 = getRandomInt(0, canvas.height);
|
||||||
const width = getRandomInt(20, 100);
|
const width = getRandomInt(20, 100);
|
||||||
@@ -56,14 +57,20 @@
|
|||||||
|
|
||||||
const color = getRandomColor();
|
const color = getRandomColor();
|
||||||
const argb = hexToU32ARGB(color, getRandomFloat(0.1, 1.0));
|
const argb = hexToU32ARGB(color, getRandomFloat(0.1, 1.0));
|
||||||
Module._add_shape_solid_fill(argb);
|
addShapeSolidFill(argb)
|
||||||
|
|
||||||
|
// Module._add_shape_solid_fill(argb);
|
||||||
}
|
}
|
||||||
|
|
||||||
useShape("00000000-0000-0000-0000-000000000000");
|
useShape("00000000-0000-0000-0000-000000000000");
|
||||||
setShapeChildren(children);
|
setShapeChildren(children);
|
||||||
|
performance.mark('render:begin');
|
||||||
Module._render(Date.now());
|
Module._render(Date.now());
|
||||||
|
performance.mark('render:end');
|
||||||
|
const { duration } = performance.measure('render', 'render:begin', 'render:end');
|
||||||
|
alert(`render time: ${duration.toFixed(2)}ms`);
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
108
render-wasm/Cargo.lock
generated
108
render-wasm/Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler2"
|
name = "adler2"
|
||||||
@@ -781,7 +781,19 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi 0.14.2+wasi-0.2.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1337,7 +1349,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_shared",
|
"phf_shared",
|
||||||
"rand",
|
"rand 0.8.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1393,6 +1405,15 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.24"
|
version = "0.2.24"
|
||||||
@@ -1439,13 +1460,39 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core 0.9.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1454,6 +1501,15 @@ version = "0.6.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.3.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.7"
|
version = "0.5.7"
|
||||||
@@ -1469,7 +1525,7 @@ version = "0.4.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom 0.2.15",
|
||||||
"libredox",
|
"libredox",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
@@ -1511,6 +1567,8 @@ dependencies = [
|
|||||||
"cargo-watch",
|
"cargo-watch",
|
||||||
"gl",
|
"gl",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
"rand 0.9.1",
|
||||||
|
"rustc-hash",
|
||||||
"skia-safe",
|
"skia-safe",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
@@ -1955,7 +2013,7 @@ version = "1.11.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
|
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom 0.2.15",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1986,6 +2044,15 @@ version = "0.11.0+wasi-snapshot-preview1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.100"
|
version = "0.2.100"
|
||||||
@@ -2344,6 +2411,15 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.6.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ws2_32-sys"
|
name = "ws2_32-sys"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -2444,6 +2520,26 @@ dependencies = [
|
|||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.82",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zvariant"
|
name = "zvariant"
|
||||||
version = "5.2.0"
|
version = "5.2.0"
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ path = "src/main.rs"
|
|||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
gl = "0.14.0"
|
gl = "0.14.0"
|
||||||
indexmap = "2.7.1"
|
indexmap = "2.7.1"
|
||||||
|
rand = "0.9.1"
|
||||||
|
rustc-hash = "2.1.1"
|
||||||
skia-safe = { version = "0.81.0", default-features = false, features = ["gl", "svg", "textlayout", "binary-cache"]}
|
skia-safe = { version = "0.81.0", default-features = false, features = ["gl", "svg", "textlayout", "binary-cache"]}
|
||||||
uuid = { version = "1.11.0", features = ["v4"] }
|
uuid = { version = "1.11.0", features = ["v4"] }
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use rustc_hash::FxBuildHasher;
|
||||||
use skia_safe::{self as skia, Matrix, RRect, Rect};
|
use skia_safe::{self as skia, Matrix, RRect, Rect};
|
||||||
|
|
||||||
use crate::uuid::Uuid;
|
use crate::uuid::Uuid;
|
||||||
@@ -20,10 +21,11 @@ mod surfaces;
|
|||||||
mod text;
|
mod text;
|
||||||
mod tiles;
|
mod tiles;
|
||||||
|
|
||||||
use crate::shapes::{modified_children_ids, Corners, Shape, StructureEntry, Type};
|
use crate::shapes::{modified_children_ids, Corners, Fill, Shape, SolidColor, StructureEntry, Type};
|
||||||
use gpu_state::GpuState;
|
use gpu_state::GpuState;
|
||||||
use options::RenderOptions;
|
use options::RenderOptions;
|
||||||
use surfaces::{SurfaceId, Surfaces};
|
use surfaces::{SurfaceId, Surfaces};
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
pub use blend::BlendMode;
|
pub use blend::BlendMode;
|
||||||
pub use fonts::*;
|
pub use fonts::*;
|
||||||
@@ -429,7 +431,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn start_render_loop(
|
pub fn start_render_loop(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
timestamp: i32,
|
timestamp: i32,
|
||||||
@@ -496,7 +498,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn process_animation_frame(
|
pub fn process_animation_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
timestamp: i32,
|
timestamp: i32,
|
||||||
@@ -595,7 +597,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn render_shape_tree(
|
pub fn render_shape_tree(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
timestamp: i32,
|
timestamp: i32,
|
||||||
@@ -643,6 +645,24 @@ impl RenderState {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// let element = &mut Shape::new(node_id);
|
||||||
|
// element.parent_id = Some(Uuid::nil());
|
||||||
|
// // element.shape_type = Type::Rect(CustomRect::Rect::default());
|
||||||
|
// let mut rng = rand::thread_rng();
|
||||||
|
// element.selrect = Rect::from_xywh(
|
||||||
|
// rng.gen_range(0..=2498) as f32,
|
||||||
|
// rng.gen_range(0..=1321) as f32,
|
||||||
|
// rng.gen_range(20..=100) as f32,
|
||||||
|
// rng.gen_range(20..=100) as f32,
|
||||||
|
// );
|
||||||
|
// let mut rng = rand::thread_rng();
|
||||||
|
// let a = rng.gen_range(16..=255);
|
||||||
|
// let r = rng.gen_range(0..=255);
|
||||||
|
// let g = rng.gen_range(0..=255);
|
||||||
|
// let b = rng.gen_range(0..=255);
|
||||||
|
// let c = skia::Color::from_argb(a, r, g, b);
|
||||||
|
// element.add_fill(Fill::Solid(SolidColor(c)));
|
||||||
|
|
||||||
// If the shape is not in the tile set, then we update
|
// If the shape is not in the tile set, then we update
|
||||||
// it.
|
// it.
|
||||||
if let None = self.tiles.get_tiles_of(node_id) {
|
if let None = self.tiles.get_tiles_of(node_id) {
|
||||||
@@ -745,12 +765,12 @@ impl RenderState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We try to avoid doing too many calls to get_time
|
// We try to avoid doing too many calls to get_time
|
||||||
if i % NODE_BATCH_THRESHOLD == 0
|
// if i % NODE_BATCH_THRESHOLD == 0
|
||||||
&& performance::get_time() - timestamp > MAX_BLOCKING_TIME_MS
|
// && performance::get_time() - timestamp > MAX_BLOCKING_TIME_MS
|
||||||
{
|
// {
|
||||||
return Ok(());
|
// return Ok(());
|
||||||
}
|
// }
|
||||||
i += 1;
|
// i += 1;
|
||||||
}
|
}
|
||||||
performance::end_measure!("render_shape_tree::uncached");
|
performance::end_measure!("render_shape_tree::uncached");
|
||||||
let tile_rect = self.get_current_tile_bounds();
|
let tile_rect = self.get_current_tile_bounds();
|
||||||
@@ -850,7 +870,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn rebuild_tiles_shallow(
|
pub fn rebuild_tiles_shallow(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) {
|
) {
|
||||||
@@ -880,7 +900,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn rebuild_tiles(
|
pub fn rebuild_tiles(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) {
|
) {
|
||||||
@@ -909,7 +929,7 @@ impl RenderState {
|
|||||||
|
|
||||||
pub fn rebuild_modifier_tiles(
|
pub fn rebuild_modifier_tiles(
|
||||||
&mut self,
|
&mut self,
|
||||||
tree: &mut HashMap<Uuid, Shape>,
|
tree: &mut HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
) {
|
) {
|
||||||
for (uuid, matrix) in modifiers {
|
for (uuid, matrix) in modifiers {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ mod flex_layout;
|
|||||||
mod grid_layout;
|
mod grid_layout;
|
||||||
|
|
||||||
use common::GetBounds;
|
use common::GetBounds;
|
||||||
|
use rustc_hash::FxBuildHasher;
|
||||||
|
|
||||||
use crate::math::{identitish, Bounds, Matrix, Point};
|
use crate::math::{identitish, Bounds, Matrix, Point};
|
||||||
use crate::shapes::{
|
use crate::shapes::{
|
||||||
@@ -16,7 +17,7 @@ use crate::uuid::Uuid;
|
|||||||
|
|
||||||
fn propagate_children(
|
fn propagate_children(
|
||||||
shape: &Shape,
|
shape: &Shape,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
parent_bounds_before: &Bounds,
|
parent_bounds_before: &Bounds,
|
||||||
parent_bounds_after: &Bounds,
|
parent_bounds_after: &Bounds,
|
||||||
transform: Matrix,
|
transform: Matrix,
|
||||||
@@ -83,7 +84,7 @@ fn propagate_children(
|
|||||||
|
|
||||||
fn calculate_group_bounds(
|
fn calculate_group_bounds(
|
||||||
shape: &Shape,
|
shape: &Shape,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) -> Option<Bounds> {
|
) -> Option<Bounds> {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
use rustc_hash::FxBuildHasher;
|
||||||
|
|
||||||
use crate::math::{self as math, Bounds, Matrix, Point, Vector, VectorExt};
|
use crate::math::{self as math, Bounds, Matrix, Point, Vector, VectorExt};
|
||||||
use crate::shapes::{
|
use crate::shapes::{
|
||||||
modified_children_ids, AlignContent, AlignItems, AlignSelf, FlexData, JustifyContent,
|
modified_children_ids, AlignContent, AlignItems, AlignSelf, FlexData, JustifyContent,
|
||||||
@@ -178,7 +180,7 @@ fn initialize_tracks(
|
|||||||
layout_bounds: &Bounds,
|
layout_bounds: &Bounds,
|
||||||
layout_axis: &LayoutAxis,
|
layout_axis: &LayoutAxis,
|
||||||
flex_data: &FlexData,
|
flex_data: &FlexData,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) -> Vec<TrackData> {
|
) -> Vec<TrackData> {
|
||||||
@@ -420,7 +422,7 @@ fn calculate_track_data(
|
|||||||
layout_data: &LayoutData,
|
layout_data: &LayoutData,
|
||||||
flex_data: &FlexData,
|
flex_data: &FlexData,
|
||||||
layout_bounds: &Bounds,
|
layout_bounds: &Bounds,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) -> Vec<TrackData> {
|
) -> Vec<TrackData> {
|
||||||
@@ -551,7 +553,7 @@ pub fn reflow_flex_layout(
|
|||||||
shape: &Shape,
|
shape: &Shape,
|
||||||
layout_data: &LayoutData,
|
layout_data: &LayoutData,
|
||||||
flex_data: &FlexData,
|
flex_data: &FlexData,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &mut HashMap<Uuid, Bounds>,
|
bounds: &mut HashMap<Uuid, Bounds>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) -> VecDeque<Modifier> {
|
) -> VecDeque<Modifier> {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::shapes::{
|
|||||||
};
|
};
|
||||||
use crate::uuid::Uuid;
|
use crate::uuid::Uuid;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
use rustc_hash::FxBuildHasher;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
|
||||||
use super::common::GetBounds;
|
use super::common::GetBounds;
|
||||||
@@ -40,7 +41,7 @@ fn calculate_tracks(
|
|||||||
grid_data: &GridData,
|
grid_data: &GridData,
|
||||||
layout_bounds: &Bounds,
|
layout_bounds: &Bounds,
|
||||||
cells: &Vec<GridCell>,
|
cells: &Vec<GridCell>,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
) -> Vec<TrackData> {
|
) -> Vec<TrackData> {
|
||||||
let layout_size = if is_column {
|
let layout_size = if is_column {
|
||||||
@@ -105,7 +106,7 @@ fn set_auto_base_size(
|
|||||||
column: bool,
|
column: bool,
|
||||||
tracks: &mut Vec<TrackData>,
|
tracks: &mut Vec<TrackData>,
|
||||||
cells: &Vec<GridCell>,
|
cells: &Vec<GridCell>,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
) {
|
) {
|
||||||
for cell in cells {
|
for cell in cells {
|
||||||
@@ -156,7 +157,7 @@ fn set_auto_multi_span(
|
|||||||
column: bool,
|
column: bool,
|
||||||
tracks: &mut Vec<TrackData>,
|
tracks: &mut Vec<TrackData>,
|
||||||
cells: &Vec<GridCell>,
|
cells: &Vec<GridCell>,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
) {
|
) {
|
||||||
// Remove groups with flex (will be set in flex_multi_span)
|
// Remove groups with flex (will be set in flex_multi_span)
|
||||||
@@ -230,7 +231,7 @@ fn set_flex_multi_span(
|
|||||||
column: bool,
|
column: bool,
|
||||||
tracks: &mut Vec<TrackData>,
|
tracks: &mut Vec<TrackData>,
|
||||||
cells: &Vec<GridCell>,
|
cells: &Vec<GridCell>,
|
||||||
shapes: &HashMap<Uuid, Shape>,
|
shapes: &HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &HashMap<Uuid, Bounds>,
|
bounds: &HashMap<Uuid, Bounds>,
|
||||||
) {
|
) {
|
||||||
// Remove groups without flex
|
// Remove groups without flex
|
||||||
@@ -509,7 +510,7 @@ fn cell_bounds(
|
|||||||
fn create_cell_data<'a>(
|
fn create_cell_data<'a>(
|
||||||
layout_bounds: &Bounds,
|
layout_bounds: &Bounds,
|
||||||
children: &IndexSet<Uuid>,
|
children: &IndexSet<Uuid>,
|
||||||
shapes: &'a HashMap<Uuid, Shape>,
|
shapes: &'a HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
cells: &Vec<GridCell>,
|
cells: &Vec<GridCell>,
|
||||||
column_tracks: &Vec<TrackData>,
|
column_tracks: &Vec<TrackData>,
|
||||||
row_tracks: &Vec<TrackData>,
|
row_tracks: &Vec<TrackData>,
|
||||||
@@ -618,7 +619,7 @@ pub fn reflow_grid_layout<'a>(
|
|||||||
shape: &Shape,
|
shape: &Shape,
|
||||||
layout_data: &LayoutData,
|
layout_data: &LayoutData,
|
||||||
grid_data: &GridData,
|
grid_data: &GridData,
|
||||||
shapes: &'a HashMap<Uuid, Shape>,
|
shapes: &'a HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
bounds: &mut HashMap<Uuid, Bounds>,
|
bounds: &mut HashMap<Uuid, Bounds>,
|
||||||
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
structure: &HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
) -> VecDeque<Modifier> {
|
) -> VecDeque<Modifier> {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::hash::RandomState;
|
||||||
|
use rustc_hash::FxBuildHasher;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use skia_safe as skia;
|
use skia_safe as skia;
|
||||||
|
|
||||||
@@ -16,18 +19,19 @@ pub(crate) struct State<'a> {
|
|||||||
pub render_state: RenderState,
|
pub render_state: RenderState,
|
||||||
pub current_id: Option<Uuid>,
|
pub current_id: Option<Uuid>,
|
||||||
pub current_shape: Option<&'a mut Shape>,
|
pub current_shape: Option<&'a mut Shape>,
|
||||||
pub shapes: HashMap<Uuid, Shape>,
|
pub shapes: HashMap<Uuid, Shape, FxBuildHasher>,
|
||||||
pub modifiers: HashMap<Uuid, skia::Matrix>,
|
pub modifiers: HashMap<Uuid, skia::Matrix>,
|
||||||
pub structure: HashMap<Uuid, Vec<StructureEntry>>,
|
pub structure: HashMap<Uuid, Vec<StructureEntry>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new(width: i32, height: i32, capacity: usize) -> Self {
|
pub fn new(width: i32, height: i32, capacity: usize) -> Self {
|
||||||
|
let s = FxBuildHasher::default();
|
||||||
State {
|
State {
|
||||||
render_state: RenderState::new(width, height),
|
render_state: RenderState::new(width, height),
|
||||||
current_id: None,
|
current_id: None,
|
||||||
current_shape: None,
|
current_shape: None,
|
||||||
shapes: HashMap::with_capacity(capacity),
|
shapes: HashMap::with_capacity_and_hasher(capacity, s),
|
||||||
modifiers: HashMap::new(),
|
modifiers: HashMap::new(),
|
||||||
structure: HashMap::new(),
|
structure: HashMap::new(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user