Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force colorbuffer to use the size of the screen, not the scene #2012

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ function CairoScreen(scene::Scene, path::Union{String, IO}, mode::Symbol; device
return CairoScreen(scene, surf, ctx, nothing)
end

GeometryBasics.widths(screen::CairoScreen) = round.(Int, (screen.surface.width, screen.surface.height))


function Base.delete!(screen::CairoScreen, scene::Scene, plot::AbstractPlot)
# Currently, we rerender every time, so nothing needs
Expand Down Expand Up @@ -407,11 +409,18 @@ function Makie.colorbuffer(screen::CairoScreen)
# extract scene
scene = screen.scene
# get resolution
w, h = size(scene)
w, h = GeometryBasics.widths(screen)
scene_w, scene_h = size(scene)
@assert w/scene_w ≈ h/scene_h

device_scaling_factor = w/scene_w
# preallocate an image matrix
img = Matrix{ARGB32}(undef, w, h)
# create an image surface to draw onto the image
surf = Cairo.CairoImageSurface(img)
ccall((:cairo_surface_set_device_scale, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble, Cdouble),
surf.ptr, device_scaling_factor, device_scaling_factor)

# draw the scene onto the image matrix
ctx = Cairo.CairoContext(surf)
ccall((:cairo_set_miter_limit, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble), ctx.ptr, 2.0)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed regression where `Block` alignments could not be specified as numbers anymore [#2108](https:/JuliaPlots/Makie.jl/pull/2108).
- Added the option to show mirrored ticks on the other side of an Axis using the attributes `xticksmirrored` and `yticksmirrored` [#2105](https:/JuliaPlots/Makie.jl/pull/2105).
- Fixed a bug where a set of `Axis` wouldn't be correctly linked together if they were only linked in pairs instead of all at the same time [#2116](https:/JuliaPlots/Makie.jl/pull/2116).
- Recording and colorbuffers use screen size instead of scene size, allowing e.g. the `px_per_unit` argument in CairoMakie to take effect. It is sufficient to set the global `px_per_unit` setting by calling `CairoMakie.activate!(px_per_unit=3)` or whichever scaling factor is desired. GLMakie and WGLMakie are currently unaffected by this. [#2012](https:/JuliaPlots/Makie.jl/pull/2116).

## v0.17.7

Expand Down
2 changes: 2 additions & 0 deletions WGLMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct WebDisplay <: Makie.AbstractScreen
three::Base.RefValue{ThreeDisplay}
display::Any
end

GeometryBasics.widths(screen::WebDisplay) = GeometryBasics.widths(screen.three[])

function Makie.backend_display(::WGLBackend, scene::Scene; kw...)
# Reference to three object which gets set once we serve this to a browser
Expand Down
7 changes: 7 additions & 0 deletions WGLMakie/src/three_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ end

JSServe.session(td::ThreeDisplay) = td.session

function GeometryBasics.widths(screen::ThreeDisplay)
# look at d.qs().clientWidth for displayed width
width, height = Int(WGLMakie.JSServe.evaljs_value(screen.session, WGLMakie.JSServe.js"[document.querySelector('canvas').width, document.querySelector('canvas').height]"; time_out=100))
asinghvi17 marked this conversation as resolved.
Show resolved Hide resolved

return (width, height)
end

# We use objectid to find objects on the js side
js_uuid(object) = string(objectid(object))

Expand Down
5 changes: 4 additions & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ function VideoStream(fig::FigureLike; framerate::Integer=24, visible=false, conn
path = joinpath(dir, "$(gensym(:video)).mkv")
scene = get_scene(fig)
screen = backend_display(scene; start_renderloop=false, visible=visible, connect=connect)
asinghvi17 marked this conversation as resolved.
Show resolved Hide resolved
_xdim, _ydim = size(scene)
push_screen!(scene, screen)

_xdim, _ydim = GeometryBasics.widths(screen)

xdim = iseven(_xdim) ? _xdim : _xdim + 1
ydim = iseven(_ydim) ? _ydim : _ydim + 1
process = @ffmpeg_env open(`$(FFMPEG.ffmpeg) -framerate $(framerate) -loglevel quiet -f rawvideo -pixel_format rgb24 -r $framerate -s:v $(xdim)x$(ydim) -i pipe:0 -vf vflip -y $path`, "w")
Expand Down