Skip to content

Commit

Permalink
show rendering time per each frame
Browse files Browse the repository at this point in the history
  • Loading branch information
wavewave committed Jun 25, 2023
1 parent ab14330 commit b55610a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions grid/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import Data.IORef (newIORef, modifyIORef', readIORef)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time.Clock (
diffUTCTime,
getCurrentTime,
nominalDiffTimeToSeconds,
)
import Data.Traversable (for)
import GI.Cairo.Render qualified as R
import GI.Cairo.Render.Connector as RC
import GI.Gdk qualified as Gdk
import GI.Gtk qualified as Gtk
import GI.Pango qualified as P
import GI.PangoCairo qualified as PC
import System.IO (hFlush, stdout)
import Text.Printf (printf)

data ViewPort = ViewPort (Double, Double) (Double, Double)
deriving (Show)
Expand Down Expand Up @@ -195,9 +202,17 @@ main = do
]
_ <- drawingArea `on` #draw $
RC.renderWithContext $ do
start <- R.liftIO $ getCurrentTime
s <- R.liftIO $ readIORef ref
R.liftIO $ print s
-- R.liftIO $ print s
myDraw (pangoCtxt, descSans, descMono) s
end <- R.liftIO getCurrentTime
let diff :: Double
diff = realToFrac $ nominalDiffTimeToSeconds (diffUTCTime end start)
R.liftIO $ do
printf "Rendering time: %.5f seconds\n" diff
hFlush stdout

pure True
_ <- drawingArea
`after` #scrollEvent
Expand All @@ -207,7 +222,7 @@ main = do
dx <- get ev #deltaX
dy <- get ev #deltaY
dir <- get ev #direction
print (dir, x, y , dx, dy)
-- print (dir, x, y , dx, dy)
modifyIORef' ref $ \s ->
let cx0 = 0
cx1 = 640
Expand Down
3 changes: 2 additions & 1 deletion grid/hoodle-grid.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Executable grid
gi-pango,
gi-pangocairo,
haskell-gi-base,
text
text,
time

0 comments on commit b55610a

Please sign in to comment.