diff --git a/CairoMakie/test/runtests.jl b/CairoMakie/test/runtests.jl index dd0c200495a..dad68916489 100644 --- a/CairoMakie/test/runtests.jl +++ b/CairoMakie/test/runtests.jl @@ -232,3 +232,20 @@ end @test_throws ArgumentError save(filename, Figure(), pdf_version="foo") end + +@testset "Tick Events" begin + f, a, p = scatter(rand(10)); + @test events(f).tick[] == Makie.Tick() + + filename = "$(tempname()).pdf" + try + save(filename, f) + tick = events(f).tick[] + @test tick.state == Makie.OneTimeRenderTick + @test tick.count == 1 + @test tick.time > 1e-9 + @test tick.delta_time > 1e-9 + finally + rm(filename) + end +end \ No newline at end of file diff --git a/GLMakie/test/runtests.jl b/GLMakie/test/runtests.jl index 98e30bc505c..10b98d63764 100644 --- a/GLMakie/test/runtests.jl +++ b/GLMakie/test/runtests.jl @@ -37,3 +37,44 @@ include("unit_tests.jl") GLMakie.closeall() GC.gc(true) # make sure no finalizers act up! end + +@testset "Tick Events" begin + function check_tick(tick, state, count) + @test tick.state == state + @test tick.count == count + @test tick.time > 1e-9 + @test tick.delta_time > 1e-9 + end + + f, a, p = scatter(rand(10)); + @test events(f).tick[] == Makie.Tick() + + filename = "$(tempname()).png" + try + Makie.save(filename, f) + tick = events(f).tick[] + check_tick(tick, Makie.OneTimeRenderTick, 1) + finally + rm(filename) + end + + f, a, p = scatter(rand(10)); + tick_record = Makie.Tick[] + on(t -> push!(tick_record, t), events(f).tick) + screen = GLMakie.Screen(render_on_demand = true, framerate = 30.0, pause_rendering = false, visible = false) + display(screen, f.scene) + sleep(0.15) + GLMakie.pause_renderloop!(screen) + sleep(0.1) + GLMakie.closeall() + + # Why does it start with a skipped tick? + check_tick(tick_record[1], Makie.SkippedRenderTick, 1) + check_tick(tick_record[2], Makie.RegularRenderTick, 2) + i = 3 + while (tick_record[i].state == Makie.SkippedRenderTick) + check_tick(tick_record[i], Makie.SkippedRenderTick, i) + i += 1 + end + check_tick(tick_record[i], Makie.PausedRenderTick, i) +end \ No newline at end of file diff --git a/WGLMakie/src/display.jl b/WGLMakie/src/display.jl index ec96ea39a27..551aef2012a 100644 --- a/WGLMakie/src/display.jl +++ b/WGLMakie/src/display.jl @@ -280,7 +280,7 @@ function Makie.colorbuffer(screen::Screen) end session = get_screen_session(screen; error="Not able to show scene in a browser") screen.last_time = Makie.next_tick!( - screen.scene.events.tick, Makie.RegularRenderTick, screen.start_time, screen.last_time) + screen.scene.events.tick, Makie.OneTimeRenderTick, screen.start_time, screen.last_time) return session2image(session, screen.scene) end diff --git a/WGLMakie/test/runtests.jl b/WGLMakie/test/runtests.jl index f7e4bd786b6..747e5fc1f9d 100644 --- a/WGLMakie/test/runtests.jl +++ b/WGLMakie/test/runtests.jl @@ -70,3 +70,47 @@ end # we used Retain for global_obs, so it should stay as long as root session is open @test keys(js_objects) == Set([WGLMakie.TEXTURE_ATLAS.id]) end + +@testset "Tick Events" begin + function check_tick(tick, state, count) + @test tick.state == state + @test tick.count == count + @test tick.time > 1e-9 + @test tick.delta_time > 1e-9 + end + + f, a, p = scatter(rand(10)); + @test events(f).tick[] == Makie.Tick() + tick_record = Makie.Tick[] + on(t -> push!(tick_record, t), events(f).tick) + + filename = "$(tempname()).png" + try + save(filename, f) + # WGLMakie produces a running renderloop when calling colorbuffer so + # we have multiple ticks to deal with + idx = findfirst(tick -> tick.state == Makie.OneTimeRenderTick, tick_record) + @test idx !== nothing + check_tick(tick_record[idx], Makie.OneTimeRenderTick, idx) + finally + rm(filename) + end + + # This produces a lot of pre-render ticks claiming to be normal render ticks + f, a, p = scatter(rand(10)); + tick_record = Makie.Tick[] + on(t -> push!(tick_record, t), events(f).tick) + screen = display(f) + sleep(0.1) + close(screen) + + # May have preceeding ticks from previous renderloop + start = 1 + while tick_record[start].count > 1 + start += 1 + end + + for i in start:length(tick_record) + check_tick(tick_record[i], Makie.RegularRenderTick, i-start+1) + end +end \ No newline at end of file