From 0774025e1a280d3833e340f6a368a3692cdca2c5 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 10 Jan 2023 09:17:00 +0000 Subject: cairo_surface_map_to_image giving poor results under gen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for some unknown reason Change-Id: I6a44b739b7126465e9cf54e31ad4b362badea85d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145254 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/headless/CairoCommon.cxx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index f347cf47f930..fb25d6a2c391 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -479,7 +479,20 @@ void CairoCommon::doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, { //in the unlikely case we can't use m_pSurface directly, copy contents //to another temp image surface - target_surface = cairo_surface_map_to_image(target_surface, nullptr); + if (cairo_surface_get_content(m_pSurface) == CAIRO_CONTENT_COLOR_ALPHA) + target_surface = cairo_surface_map_to_image(target_surface, nullptr); + else + { + // for gen, which is CAIRO_FORMAT_RGB24/CAIRO_CONTENT_COLOR I'm getting + // visual corruption in vcldemo with cairo_surface_map_to_image + cairo_t* copycr = createTmpCompatibleCairoContext(); + cairo_rectangle(copycr, nExtentsLeft, nExtentsTop, nExtentsRight - nExtentsLeft, + nExtentsBottom - nExtentsTop); + cairo_set_source_surface(copycr, m_pSurface, 0, 0); + cairo_fill(copycr); + target_surface = cairo_get_target(copycr); + cairo_destroy(copycr); + } } cairo_surface_flush(target_surface); @@ -549,7 +562,19 @@ void CairoCommon::doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, if (target_surface != m_pSurface) { - cairo_surface_unmap_image(m_pSurface, target_surface); + if (cairo_surface_get_content(m_pSurface) == CAIRO_CONTENT_COLOR_ALPHA) + cairo_surface_unmap_image(m_pSurface, target_surface); + else + { + cairo_t* copycr = cairo_create(m_pSurface); + //copy contents back from image surface + cairo_rectangle(copycr, nExtentsLeft, nExtentsTop, nExtentsRight - nExtentsLeft, + nExtentsBottom - nExtentsTop); + cairo_set_source_surface(copycr, target_surface, 0, 0); + cairo_fill(copycr); + cairo_destroy(copycr); + cairo_surface_destroy(target_surface); + } } cairo_surface_destroy(surface); -- cgit