diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-10-03 17:04:10 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-10-03 20:58:21 +0200 |
commit | 730f50a86d9521c8d3793b40ce14c484d3e3c2f7 (patch) | |
tree | 6b24c47c68b3874632e93a00c23ebf317e4755d4 /vcl | |
parent | 2483c98fe7a843ea5b7d258ac76f48433a3758ca (diff) |
factor out the actual surface creation
Change-Id: I77520b67b988f583dfd277e69d8181b9acdbd904
Reviewed-on: https://gerrit.libreoffice.org/80153
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/headless/svpvd.cxx | 77 | ||||
-rw-r--r-- | vcl/inc/headless/svpvd.hxx | 2 |
2 files changed, 44 insertions, 35 deletions
diff --git a/vcl/headless/svpvd.cxx b/vcl/headless/svpvd.cxx index a1e415739d6b..686587f9deab 100644 --- a/vcl/headless/svpvd.cxx +++ b/vcl/headless/svpvd.cxx @@ -68,6 +68,46 @@ bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY ) return SetSizeUsingBuffer(nNewDX, nNewDY, nullptr); } +void SvpSalVirtualDevice::CreateSurface(long nNewDX, long nNewDY, sal_uInt8 *const pBuffer) +{ + m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY); + + if (m_pSurface) + { + cairo_surface_destroy(m_pSurface); + } + + if (m_eFormat == DeviceFormat::BITMASK) + { + m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_ALPHA, + nNewDX, nNewDY); + } + else if (pBuffer) + { + double fXScale, fYScale; + if (comphelper::LibreOfficeKit::isActive()) + { + // Force scaling of the painting + fXScale = fYScale = comphelper::LibreOfficeKit::getDPIScale(); + } + else + { + dl_cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale); + nNewDX *= fXScale; + nNewDY *= fYScale; + } + + m_pSurface = cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32, + nNewDX, nNewDY, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX)); + + dl_cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale); + } + else + { + m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_COLOR_ALPHA, nNewDX, nNewDY); + } +} + bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY, sal_uInt8 *const pBuffer) { @@ -77,44 +117,11 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY, nNewDY = 1; if (!m_pSurface || m_aFrameSize.getX() != nNewDX || - m_aFrameSize.getY() != nNewDY ) + m_aFrameSize.getY() != nNewDY) { m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY); - if (m_pSurface) - { - cairo_surface_destroy(m_pSurface); - } - - if (m_eFormat == DeviceFormat::BITMASK) - { - m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_ALPHA, - nNewDX, nNewDY); - } - else if (pBuffer) - { - double fXScale, fYScale; - if (comphelper::LibreOfficeKit::isActive()) - { - // Force scaling of the painting - fXScale = fYScale = comphelper::LibreOfficeKit::getDPIScale(); - } - else - { - dl_cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale); - nNewDX *= fXScale; - nNewDY *= fYScale; - } - - m_pSurface = cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32, - nNewDX, nNewDY, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX)); - - dl_cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale); - } - else - { - m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_COLOR_ALPHA, nNewDX, nNewDY); - } + CreateSurface(nNewDX, nNewDY, pBuffer); // update device in existing graphics for (auto const& graphic : m_aGraphics) diff --git a/vcl/inc/headless/svpvd.hxx b/vcl/inc/headless/svpvd.hxx index 3da74b5e1ba8..b069c63286d1 100644 --- a/vcl/inc/headless/svpvd.hxx +++ b/vcl/inc/headless/svpvd.hxx @@ -37,6 +37,8 @@ class VCL_DLLPUBLIC SvpSalVirtualDevice : public SalVirtualDevice basegfx::B2IVector m_aFrameSize; std::vector< SvpSalGraphics* > m_aGraphics; + void CreateSurface(long nNewDX, long nNewDY, sal_uInt8 *const pBuffer); + protected: SvpSalGraphics* AddGraphics(SvpSalGraphics* aGraphics); |