mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
stashed
This commit is contained in:
parent
4939bc06ac
commit
f5acfd0787
5 changed files with 91 additions and 58 deletions
|
@ -109,10 +109,14 @@ fn render_rect(surface: &mut skia::Surface, rect: skia::Rect, color: skia::Color
|
||||||
let mut paint = skia::Paint::default();
|
let mut paint = skia::Paint::default();
|
||||||
paint.set_style(skia::PaintStyle::Fill);
|
paint.set_style(skia::PaintStyle::Fill);
|
||||||
paint.set_color(color);
|
paint.set_color(color);
|
||||||
paint.set_anti_alias(true);
|
// paint.set_anti_alias(true);
|
||||||
surface.canvas().draw_rect(rect, &paint);
|
surface.canvas().draw_rect(rect, &paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_rect_ref(surface: &mut skia::Surface, rect: &skia::Rect, paint: &skia::Paint) {
|
||||||
|
surface.canvas().draw_rect(rect, paint);
|
||||||
|
}
|
||||||
|
|
||||||
/// This is called from JS after the WebGL context has been created.
|
/// This is called from JS after the WebGL context has been created.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn init(width: i32, height: i32) -> Box<State> {
|
pub extern "C" fn init(width: i32, height: i32) -> Box<State> {
|
||||||
|
@ -242,11 +246,11 @@ pub unsafe extern "C" fn draw_shapes(
|
||||||
text_paint.set_style(skia_safe::paint::Style::StrokeAndFill);
|
text_paint.set_style(skia_safe::paint::Style::StrokeAndFill);
|
||||||
text_paint.set_stroke_width(1.0);
|
text_paint.set_stroke_width(1.0);
|
||||||
|
|
||||||
let mut path_paint = skia::Paint::default();
|
// let mut path_paint = skia::Paint::default();
|
||||||
path_paint.set_color(skia_safe::Color::BLACK);
|
// path_paint.set_color(skia_safe::Color::BLACK);
|
||||||
path_paint.set_anti_alias(true);
|
// path_paint.set_anti_alias(true);
|
||||||
path_paint.set_stroke_width(1.0);
|
// path_paint.set_stroke_width(1.0);
|
||||||
path_paint.set_style(PaintStyle::Stroke);
|
// path_paint.set_style(PaintStyle::Stroke);
|
||||||
|
|
||||||
// let svg_canvas = skia_safe::svg::Canvas::new(skia_safe::Rect::from_size((10000, 10000)), None);
|
// let svg_canvas = skia_safe::svg::Canvas::new(skia_safe::Rect::from_size((10000, 10000)), None);
|
||||||
|
|
||||||
|
@ -257,28 +261,48 @@ pub unsafe extern "C" fn draw_shapes(
|
||||||
|
|
||||||
for rect in buf.iter() {
|
for rect in buf.iter() {
|
||||||
let r = skia::Rect::new(rect.left, rect.top, rect.right, rect.bottom);
|
let r = skia::Rect::new(rect.left, rect.top, rect.right, rect.bottom);
|
||||||
|
|
||||||
let color = skia::Color::from_argb(
|
let color = skia::Color::from_argb(
|
||||||
(rect.a * 255.0) as u8,
|
(rect.a * 255.0) as u8,
|
||||||
rect.r as u8,
|
rect.r as u8,
|
||||||
rect.g as u8,
|
rect.g as u8,
|
||||||
rect.b as u8,
|
rect.b as u8,
|
||||||
);
|
);
|
||||||
render_rect(&mut state.surface, r, color);
|
|
||||||
|
|
||||||
let mut paint = skia::Paint::default();
|
let mut paint = skia::Paint::default();
|
||||||
paint.set_style(skia::PaintStyle::Fill);
|
paint.set_style(skia::PaintStyle::Fill);
|
||||||
paint.set_color(color);
|
paint.set_color(color);
|
||||||
paint.set_anti_alias(true);
|
|
||||||
|
// render_rect_ref(&mut state.surface, &r, &paint);
|
||||||
|
state.surface.canvas().draw_rect(&r, &paint);
|
||||||
|
// render_rect(&mut state.surface, r, color);
|
||||||
|
|
||||||
|
// paint.set_anti_alias(true);
|
||||||
|
// state.surface.canvas().draw_rect(r, &paint);
|
||||||
|
state.surface.canvas().draw_text_align(
|
||||||
|
String::from("Lorem ipsum"),
|
||||||
|
(rect.left, rect.top),
|
||||||
|
&state.default_font,
|
||||||
|
&paint,
|
||||||
|
skia::utils::text_utils::Align::Left,
|
||||||
|
);
|
||||||
|
|
||||||
|
// let mut paint = skia::Paint::default();
|
||||||
|
// paint.set_style(skia::PaintStyle::Fill);
|
||||||
|
// paint.set_color(color);
|
||||||
|
// paint.set_anti_alias(true);
|
||||||
|
|
||||||
// svg_canvas.draw_rect(r, &paint);
|
// svg_canvas.draw_rect(r, &paint);
|
||||||
// pdf_canvas.draw_rect(r, &paint);
|
// pdf_canvas.draw_rect(r, &paint);
|
||||||
|
|
||||||
text_paint.set_color(color);
|
// text_paint.set_color(color);
|
||||||
state.surface.canvas().draw_str(
|
// state.surface.canvas().draw_str(
|
||||||
"SKIA TEXT",
|
// "SKIA TEXT",
|
||||||
(rect.left, rect.top),
|
// (rect.left, rect.top),
|
||||||
&state.default_font,
|
// &state.default_font,
|
||||||
&text_paint,
|
// &text_paint,
|
||||||
);
|
// );
|
||||||
|
|
||||||
// svg_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
// svg_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||||
// pdf_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
// pdf_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||||
|
|
||||||
|
|
|
@ -272,9 +272,9 @@
|
||||||
(when (render-v2/is-enabled?)
|
(when (render-v2/is-enabled?)
|
||||||
;; set up canvas and first render
|
;; set up canvas and first render
|
||||||
(mf/with-effect
|
(mf/with-effect
|
||||||
[canvas-ref vbox']
|
[canvas-ref]
|
||||||
(let [canvas (mf/ref-val canvas-ref)]
|
(let [canvas (mf/ref-val canvas-ref)]
|
||||||
(when (and (some? canvas) (some? vbox'))
|
(when (some? canvas)
|
||||||
(-> (p/then (render-v2/init)
|
(-> (p/then (render-v2/init)
|
||||||
(fn []
|
(fn []
|
||||||
(mf/set-ref-val! canvas-init? true)
|
(mf/set-ref-val! canvas-init? true)
|
||||||
|
|
|
@ -35,7 +35,12 @@
|
||||||
|
|
||||||
;; Rust
|
;; Rust
|
||||||
(contains? cf/flags :render-v2-rs)
|
(contains? cf/flags :render-v2-rs)
|
||||||
(render-v2-rs/set-canvas canvas vbox zoom base-objects)))
|
(do
|
||||||
|
(js/performance.mark "rs-set-canvas-start")
|
||||||
|
(render-v2-rs/set-canvas canvas vbox zoom base-objects)
|
||||||
|
(js/performance.mark "rs-set-canvas-end")
|
||||||
|
(let [duration (.-duration (js/performance.measure "rs-set-canvas" "rs-set-canvas-start" "rs-set-canvas-end"))]
|
||||||
|
(js/console.log "Rust set-canvas" duration)))))
|
||||||
|
|
||||||
(defn draw-canvas
|
(defn draw-canvas
|
||||||
[vbox zoom base-objects]
|
[vbox zoom base-objects]
|
||||||
|
@ -46,7 +51,12 @@
|
||||||
|
|
||||||
;; Rust
|
;; Rust
|
||||||
(contains? cf/flags :render-v2-rs)
|
(contains? cf/flags :render-v2-rs)
|
||||||
(render-v2-rs/draw-canvas vbox zoom base-objects)))
|
(do
|
||||||
|
(js/performance.mark "rs-draw-canvas-start")
|
||||||
|
(render-v2-rs/draw-canvas vbox zoom base-objects)
|
||||||
|
(js/performance.mark "rs-draw-canvas-end")
|
||||||
|
(let [duration (.-duration (js/performance.measure "rs-draw-canvas" "rs-draw-canvas-start" "rs-draw-canvas-end"))]
|
||||||
|
(js/console.log "Rust draw-canvas" duration)))))
|
||||||
|
|
||||||
(defn set-objects [vbox zoom base-objects]
|
(defn set-objects [vbox zoom base-objects]
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
[vbox zoom]
|
[vbox zoom]
|
||||||
(let [alloc-rects (gobj/get ^js internal-module "_alloc_rects")
|
(let [alloc-rects (gobj/get ^js internal-module "_alloc_rects")
|
||||||
free_rects (gobj/get ^js internal-module "_free_rects")
|
free_rects (gobj/get ^js internal-module "_free_rects")
|
||||||
shape-count 20000
|
shape-count 5548
|
||||||
heap (gobj/get ^js internal-module "HEAPF32")
|
heap (gobj/get ^js internal-module "HEAPF32")
|
||||||
;; Each F32 are 4 bytes
|
;; Each F32 are 4 bytes
|
||||||
;; Each rect has:
|
;; Each rect has:
|
||||||
|
@ -74,28 +74,27 @@
|
||||||
(free_rects shapes-ptr shape-count))
|
(free_rects shapes-ptr shape-count))
|
||||||
|
|
||||||
(let
|
(let
|
||||||
[ptr (alloc-rects shape-count)
|
[ptr (alloc-rects shape-count)]
|
||||||
padding 16
|
|
||||||
width 64
|
|
||||||
height 64]
|
|
||||||
(doseq [index (take shape-count (iterate inc 0))]
|
(doseq [index (take shape-count (iterate inc 0))]
|
||||||
(let [mem (js/Float32Array. (.-buffer heap) (+ ptr (* rect-bytes index)) rect-bytes)
|
(let [mem (js/Float32Array. (.-buffer heap) (+ ptr (* rect-bytes index)) rect-bytes)
|
||||||
x1 (* index (+ padding width))
|
x1 (rand-int 1024)
|
||||||
x2 (+ x1 width)
|
x2 (+ x1 (rand-int 256))
|
||||||
y1 (+ padding height)
|
y1 (rand-int 1024)
|
||||||
y2 (+ y1 height)]
|
y2 (+ y1 (rand-int 256))]
|
||||||
(set! shapes-ptr ptr)
|
(set! shapes-ptr ptr)
|
||||||
(set! shapes-size shape-count)
|
(set! shapes-size shape-count)
|
||||||
(.set mem (js/Float32Array. (clj->js [x1 y1 x2 y2 255 0 0 1])))
|
(.set mem (js/Float32Array. (clj->js [0 0 64 64 255 0 0 1])))
|
||||||
|
;; (.set mem (js/Float32Array. (clj->js [(* index 72) 0 (+ (* index 72) 64) 64 255 0 0 1])))
|
||||||
|
;; (.set mem (js/Float32Array. (clj->js [x1 y1 x2 y2 (rand-int 255) (rand-int 255) (rand-int 255) 1])))
|
||||||
)))
|
)))
|
||||||
(draw-canvas vbox zoom nil)))
|
(draw-canvas vbox zoom nil)))
|
||||||
|
|
||||||
(defn set-canvas
|
(defn set-canvas
|
||||||
[canvas vbox zoom objects]
|
[canvas vbox zoom objects]
|
||||||
(let [gl (gobj/get ^js internal-module "GL")
|
(let [gl (gobj/get ^js internal-module "GL")
|
||||||
context (.getContext canvas "webgl2" {"antialias" true
|
context (.getContext canvas "webgl2" {;; "antialias" true
|
||||||
"depth" true
|
;; "depth" true
|
||||||
"stencil" true
|
;; "stencil" false
|
||||||
"alpha" true})
|
"alpha" true})
|
||||||
;; Register the context with emscripten
|
;; Register the context with emscripten
|
||||||
handle (.registerContext gl context {"majorVersion" 2})
|
handle (.registerContext gl context {"majorVersion" 2})
|
||||||
|
|
|
@ -8850,7 +8850,7 @@ var wasmImports = {
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_iiii,
|
invoke_iiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_iiiiffii,
|
invoke_iiiiffiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_iiiii,
|
invoke_iiiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
|
@ -8892,7 +8892,7 @@ var wasmImports = {
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_viiii,
|
invoke_viiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_viiiiffii,
|
invoke_viiiiffiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
invoke_viiiii,
|
invoke_viiiii,
|
||||||
/** @export */
|
/** @export */
|
||||||
|
@ -9042,28 +9042,6 @@ function invoke_iii(index,a1,a2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_viffi(index,a1,a2,a3,a4) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3,a4);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_viiiiffii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
|
function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
|
@ -9163,10 +9141,32 @@ function invoke_iif(index,a1,a2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_iiiiffii(index,a1,a2,a3,a4,a5,a6,a7) {
|
function invoke_iiiiffiii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);
|
return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function invoke_viffi(index,a1,a2,a3,a4) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
getWasmTableEntry(index)(a1,a2,a3,a4);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function invoke_viiiiffiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
stackRestore(sp);
|
stackRestore(sp);
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
|
Loading…
Reference in a new issue