miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Canvas.FFI

Description

One JavaScript import per straight-line CanvasRenderingContext2D operation: a method call or a property assignment that returns nothing.

Miso.Canvas used to go through the generic # and setField: a method name marshalled to a JavaScript string, a property lookup, an argument array, and a JSVal handle for every argument and the result, on each operation. A direct import does one call with the numbers as numbers. On MicroHs this made the canvas benchmark in sample-app-canvas about 3.5 times faster (78 to 22 ms per frame for 1000 rectangles).

fillStyleRGB, strokeStyleRGB, shadowColorRGB and their RGBA variants take the colour as numbers and build the rgb(…) string in JavaScript, instead of renderColor building it from Haskell (several string operations across the FFI per colour).

Operations that return a value (gradients, patterns, image data) stay on the generic path in Miso.Canvas. The native GHC backend has no JavaScript FFI, so there these are the generic calls as before.

Synopsis

Documentation

jsString :: MisoString -> MisoString Source #

A MisoString as the string the imports take.

rect :: JSVal -> Double -> Double -> Double -> Double -> IO () Source #

fill :: JSVal -> IO () Source #

clip :: JSVal -> IO () Source #

save :: JSVal -> IO () Source #

scale :: JSVal -> Double -> Double -> IO () Source #

arc :: JSVal -> Double -> Double -> Double -> Double -> Double -> IO () Source #

arcTo :: JSVal -> Double -> Double -> Double -> Double -> Double -> IO () Source #

fillStyleRGB :: JSVal -> Int -> Int -> Int -> IO () Source #

fillStyleRGBA :: JSVal -> Int -> Int -> Int -> Double -> IO () Source #

strokeStyleRGB :: JSVal -> Int -> Int -> Int -> IO () Source #

shadowColorRGB :: JSVal -> Int -> Int -> Int -> IO () Source #