Skip to content

Commit

Permalink
Fix the methods and get them working
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Jun 16, 2022
1 parent e2bd7f1 commit 8c8441c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions CairoMakie/src/glmakie_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ function alpha_colorbuffer(Backend, scene::Scene)
return img
end

alpha_colorbuffer(scene::Scene)


function infer_alphacolor(rgb1, rgb2)
rgb1 == rgb2 && return RGBAf(rgb1.r, rgb1.g, rgb1.b, 1)
c1 = Float64.((rgb1.r, rgb1.g, rgb1.b))
Expand Down Expand Up @@ -118,17 +115,18 @@ purge_render_cache!(fig::Figure) = purge_render_cache!(fig.scene)
# which we set in the previous step to contain the scene.
# This retrieval

function draw_plot_as_image_with_backend(Backend, scene::Scene, screen::CairoScreen, plot; scale = 1)

function CairoMakie.draw_atomic(scene::Scene, screen::CairoMakie.CairoScreen, primitive::Volume)
draw_plot_as_image_with_backend(GLMakie, scene, screen, primitive)
end


function draw_plot_as_image_with_backend(Backend, scene::Scene, screen::CairoScreen, plot)
# special case if CairoMakie is the backend, since
# we don't want an infinite loop.
if Backend == @__MODULE__
draw_plot_as_image(scene, screen, plot, scale)
return
end

w, h = Int.(scene.px_area[].widths)

img = plot2img(Backend, primitive; scale = scale, use_backgroundcolor = false)
img = plot2img(Backend, plot; scale = scale, use_backgroundcolor = false)
Makie.save("hi.png", img) # cache for debugging

surf = Cairo.CairoARGBSurface(to_uint32_color.(img))
Expand All @@ -155,7 +153,7 @@ function draw_scene_as_image(Backend, scene::Scene, screen::CairoScreen; scale =
push!.(Ref(render_scene), scene.plots[(begin+1):end])
end

img = if Makie.to_color(scene.backgroundcolor[]) == RGBAf(0,0,0,0)
img = if RGBAf(Makie.to_color(scene.backgroundcolor[])) == RGBAf(0,0,0,0)
alpha_colorbuffer(Backend, scene)
else
Makie.colorbuffer(scene)
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function cairo_draw(screen::CairoScreen, scene::Scene)
elseif p.rasterize[] isa Union{<: Module, Tuple{<: Module, Int}}
backend = p.rasterize[] isa Module ? p.rasterize[] : p.rasterize[][1]
scale = p.rasterize[] isa Module ? 1 : p.rasterize[][2]
draw_plot_as_image_with_backend(backend, pparent, screen, p; scale = scale, use_backgroundcolor = false)
draw_plot_as_image_with_backend(backend, pparent, screen, p; scale = scale)
else # rasterization option was not recognized, or should_rasterize
# was false and backend was not selected.
draw_plot(pparent, screen, p)
Expand Down Expand Up @@ -401,7 +401,7 @@ function Makie.backend_show(x::CairoBackend, io::IO, ::MIME"image/png", scene::S
# while relative line and font sizes are unaffected
px_per_unit = get(io, :px_per_unit, x.px_per_unit)
antialias = get(io, :antialias, x.antialias)

# create an ARGB surface, to speed up drawing ops.
screen = CairoScreen(scene; device_scaling_factor = px_per_unit, antialias = antialias)
cairo_draw(screen, scene)
Expand Down

0 comments on commit 8c8441c

Please sign in to comment.