diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-10-25 16:43:16 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-12-30 11:46:43 +0100 |
commit | 70a1f26a5ebb839279f1c7d58ffd9f085bfb1f0b (patch) | |
tree | b3ad4d03d02b06eefd5f8af2595923b0db4b62ad /vcl | |
parent | 1c26cfdd8a7137cb6db29b1f88e5023e43f9d6e4 (diff) |
vcl: Introduce CairoCommon to manage the cairo functions
CairoCommon is needed so that SvpSalGraphics and SvpGraphicBackend
can both access the same cairo constructs. Currently the common
one is the cairo surface.
Change-Id: Ia23c30489c9df889a348da5720ee84c82c792374
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127703
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 22 | ||||
-rw-r--r-- | vcl/headless/svpgdi.cxx | 43 | ||||
-rw-r--r-- | vcl/inc/headless/CairoCommon.hxx | 75 | ||||
-rw-r--r-- | vcl/inc/headless/svpgdi.hxx | 41 |
5 files changed, 124 insertions, 58 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 02eadd06805a..c7c03a52f44f 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -527,6 +527,7 @@ vcl_headless_code= \ vcl/headless/svpbmp \ vcl/headless/svpgdi \ vcl/headless/SvpGraphicsBackend \ + vcl/headless/CairoCommon \ $(if $(ENABLE_HEADLESS),vcl/headless/svpdata) \ ) \ vcl/headless/svpdummies \ diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx new file mode 100644 index 000000000000..3db6f14f8417 --- /dev/null +++ b/vcl/headless/CairoCommon.cxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <headless/CairoCommon.hxx> + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 223956076471..1e6a6edf7100 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -913,8 +913,7 @@ bool SvpSalGraphics::drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long n } SvpSalGraphics::SvpSalGraphics() - : m_pSurface(nullptr) - , m_fScale(1.0) + : m_fScale(1.0) , m_aLineColor(Color(0x00, 0x00, 0x00)) , m_aFillColor(Color(0xFF, 0xFF, 0XFF)) , m_ePaintMode(PaintMode::Over) @@ -932,7 +931,7 @@ SvpSalGraphics::~SvpSalGraphics() void SvpSalGraphics::setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize) { - m_pSurface = pSurface; + m_aCairoCommon.m_pSurface = pSurface; m_aFrameSize = rSize; dl_cairo_surface_get_device_scale(pSurface, &m_fScale, nullptr); ResetClipRegion(); @@ -945,14 +944,14 @@ void SvpSalGraphics::GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) sal_uInt16 SvpSalGraphics::GetBitCount() const { - if (cairo_surface_get_content(m_pSurface) != CAIRO_CONTENT_COLOR_ALPHA) + if (cairo_surface_get_content(m_aCairoCommon.m_pSurface) != CAIRO_CONTENT_COLOR_ALPHA) return 1; return 32; } tools::Long SvpSalGraphics::GetGraphicsWidth() const { - return m_pSurface ? m_aFrameSize.getX() : 0; + return m_aCairoCommon.m_pSurface ? m_aFrameSize.getX() : 0; } void SvpSalGraphics::ResetClipRegion() @@ -2027,7 +2026,7 @@ bool SvpSalGraphics::implDrawGradient(basegfx::B2DPolyPolygon const & rPolyPolyg void SvpSalGraphics::applyColor(cairo_t *cr, Color aColor, double fTransparency) { - if (cairo_surface_get_content(m_pSurface) == CAIRO_CONTENT_COLOR_ALPHA) + if (cairo_surface_get_content(m_aCairoCommon.m_pSurface) == CAIRO_CONTENT_COLOR_ALPHA) { cairo_set_source_rgba(cr, aColor.GetRed()/255.0, aColor.GetGreen()/255.0, @@ -2117,14 +2116,14 @@ void SvpSalGraphics::copyBits( const SalTwoRect& rTR, SvpSalGraphics* pSrc = pSrcGraphics ? static_cast<SvpSalGraphics*>(pSrcGraphics) : this; - cairo_surface_t* source = pSrc->m_pSurface; + cairo_surface_t* source = pSrc->m_aCairoCommon.m_pSurface; cairo_surface_t *pCopy = nullptr; if (pSrc == this) { //self copy is a problem, so dup source in that case pCopy = cairo_surface_create_similar(source, - cairo_surface_get_content(m_pSurface), + cairo_surface_get_content(m_aCairoCommon.m_pSurface), aTR.mnSrcWidth * m_fScale, aTR.mnSrcHeight * m_fScale); dl_cairo_surface_set_device_scale(pCopy, m_fScale, m_fScale); @@ -2288,7 +2287,7 @@ std::shared_ptr<SalBitmap> SvpSalGraphics::getBitmap( tools::Long nX, tools::Lon cairo_t* cr = cairo_create(target); SalTwoRect aTR(nX, nY, nWidth, nHeight, 0, 0, nWidth, nHeight); - renderSource(cr, aTR, m_pSurface); + renderSource(cr, aTR, m_aCairoCommon.m_pSurface); cairo_destroy(cr); cairo_surface_destroy(target); @@ -2301,7 +2300,7 @@ std::shared_ptr<SalBitmap> SvpSalGraphics::getBitmap( tools::Long nX, tools::Lon Color SvpSalGraphics::getPixel( tools::Long nX, tools::Long nY ) { #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0) - cairo_surface_t *target = cairo_surface_create_similar_image(m_pSurface, CAIRO_FORMAT_ARGB32, 1, 1); + cairo_surface_t *target = cairo_surface_create_similar_image(m_aCairoCommon.m_pSurface, CAIRO_FORMAT_ARGB32, 1, 1); #else cairo_surface_t *target = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); #endif @@ -2309,7 +2308,7 @@ Color SvpSalGraphics::getPixel( tools::Long nX, tools::Long nY ) cairo_t* cr = cairo_create(target); cairo_rectangle(cr, 0, 0, 1, 1); - cairo_set_source_surface(cr, m_pSurface, -nX, -nY); + cairo_set_source_surface(cr, m_aCairoCommon.m_pSurface, -nX, -nY); cairo_paint(cr); cairo_destroy(cr); @@ -2395,8 +2394,8 @@ void SvpSalGraphics::invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags) if (nFlags & SalInvert::N50) { cairo_pattern_t *pattern = create_stipple(); - cairo_surface_t* surface = cairo_surface_create_similar(m_pSurface, - cairo_surface_get_content(m_pSurface), + cairo_surface_t* surface = cairo_surface_create_similar(m_aCairoCommon.m_pSurface, + cairo_surface_get_content(m_aCairoCommon.m_pSurface), extents.getWidth() * m_fScale, extents.getHeight() * m_fScale); @@ -2483,7 +2482,7 @@ cairo_surface_t* SvpSalGraphics::createCairoSurface(const BitmapBuffer *pBuffer) cairo_t* SvpSalGraphics::createTmpCompatibleCairoContext() const { #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0) - cairo_surface_t *target = cairo_surface_create_similar_image(m_pSurface, + cairo_surface_t *target = cairo_surface_create_similar_image(m_aCairoCommon.m_pSurface, #else cairo_surface_t *target = cairo_image_surface_create( #endif @@ -2502,7 +2501,7 @@ cairo_t* SvpSalGraphics::getCairoContext(bool bXorModeAllowed) const if (m_ePaintMode == PaintMode::Xor && bXorModeAllowed) cr = createTmpCompatibleCairoContext(); else - cr = cairo_create(m_pSurface); + cr = cairo_create(m_aCairoCommon.m_pSurface); cairo_set_line_width(cr, 1); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_antialias(cr, getAntiAlias() ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE); @@ -2555,16 +2554,16 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons //emulate it (slowly) here. if (bXoring) { - cairo_surface_t* target_surface = m_pSurface; + cairo_surface_t* target_surface = m_aCairoCommon.m_pSurface; if (cairo_surface_get_type(target_surface) != CAIRO_SURFACE_TYPE_IMAGE) { - //in the unlikely case we can't use m_pSurface directly, copy contents + //in the unlikely case we can't use m_aCairoCommon.m_pSurface directly, copy contents //to another temp image surface cairo_t* copycr = createTmpCompatibleCairoContext(); cairo_rectangle(copycr, nExtentsLeft, nExtentsTop, nExtentsRight - nExtentsLeft, nExtentsBottom - nExtentsTop); - cairo_set_source_surface(copycr, m_pSurface, 0, 0); + cairo_set_source_surface(copycr, m_aCairoCommon.m_pSurface, 0, 0); cairo_paint(copycr); target_surface = cairo_get_target(copycr); cairo_destroy(copycr); @@ -2622,10 +2621,10 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons } cairo_surface_mark_dirty(target_surface); - if (target_surface != m_pSurface) + if (target_surface != m_aCairoCommon.m_pSurface) { - cairo_t* copycr = cairo_create(m_pSurface); - //unlikely case we couldn't use m_pSurface directly, copy contents + cairo_t* copycr = cairo_create(m_aCairoCommon.m_pSurface); + //unlikely case we couldn't use m_aCairoCommon.m_pSurface directly, copy contents //back from image surface cairo_rectangle(copycr, nExtentsLeft, nExtentsTop, nExtentsRight - nExtentsLeft, @@ -2641,7 +2640,7 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons cairo_destroy(cr); // unref - DamageHandler* pDamage = static_cast<DamageHandler*>(cairo_surface_get_user_data(m_pSurface, getDamageKey())); + DamageHandler* pDamage = static_cast<DamageHandler*>(cairo_surface_get_user_data(m_aCairoCommon.m_pSurface, getDamageKey())); if (pDamage) { diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx new file mode 100644 index 000000000000..3e00c0a41cff --- /dev/null +++ b/vcl/inc/headless/CairoCommon.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> +#include <config_features.h> + +#include <cairo.h> + +#include <vcl/dllapi.h> +#include <vcl/region.hxx> +#include <vcl/salgtype.hxx> + +//Using formats that match cairo's formats. For android we patch cairo, +//which is internal in that case, to swap the rgb components so that +//cairo then matches the OpenGL GL_RGBA format so we can use it there +//where we don't have GL_BGRA support. +// SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory. +#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK +#define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) +#define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown) +#define SVP_CAIRO_BLUE 1 +#define SVP_CAIRO_GREEN 2 +#define SVP_CAIRO_RED 0 +#define SVP_CAIRO_ALPHA 3 +#elif defined OSL_BIGENDIAN +#define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) +#define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown) +#define SVP_CAIRO_BLUE 3 +#define SVP_CAIRO_GREEN 2 +#define SVP_CAIRO_RED 1 +#define SVP_CAIRO_ALPHA 0 +#else +#define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown) +#define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown) +#define SVP_CAIRO_BLUE 0 +#define SVP_CAIRO_GREEN 1 +#define SVP_CAIRO_RED 2 +#define SVP_CAIRO_ALPHA 3 +#endif + +typedef struct _cairo cairo_t; +typedef struct _cairo_surface cairo_surface_t; +typedef struct _cairo_user_data_key cairo_user_data_key_t; + +struct VCL_DLLPUBLIC CairoCommon +{ + cairo_surface_t* m_pSurface; + + CairoCommon() + : m_pSurface(nullptr) + { + } + + cairo_surface_t* getSurface() const { return m_pSurface; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index 44aba3587276..dac0c62ed4dc 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -35,43 +35,12 @@ #include <sallayout.hxx> #include "svpcairotextrender.hxx" #include <impfontmetricdata.hxx> -#include "SvpGraphicsBackend.hxx" - -#include <cairo.h> - -//Using formats that match cairo's formats. For android we patch cairo, -//which is internal in that case, to swap the rgb components so that -//cairo then matches the OpenGL GL_RGBA format so we can use it there -//where we don't have GL_BGRA support. -// SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory. -#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK -# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) -# define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown) -# define SVP_CAIRO_BLUE 1 -# define SVP_CAIRO_GREEN 2 -# define SVP_CAIRO_RED 0 -# define SVP_CAIRO_ALPHA 3 -#elif defined OSL_BIGENDIAN -# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) -# define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown) -# define SVP_CAIRO_BLUE 3 -# define SVP_CAIRO_GREEN 2 -# define SVP_CAIRO_RED 1 -# define SVP_CAIRO_ALPHA 0 -#else -# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown) -# define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown) -# define SVP_CAIRO_BLUE 0 -# define SVP_CAIRO_GREEN 1 -# define SVP_CAIRO_RED 2 -# define SVP_CAIRO_ALPHA 3 -#endif + +#include <headless/SvpGraphicsBackend.hxx> +#include <headless/CairoCommon.hxx> struct BitmapBuffer; class FreetypeFont; -typedef struct _cairo cairo_t; -typedef struct _cairo_surface cairo_surface_t; -typedef struct _cairo_user_data_key cairo_user_data_key_t; VCL_DLLPUBLIC void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale); VCL_DLLPUBLIC void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double *x_scale, double *y_scale); @@ -90,7 +59,7 @@ struct VCL_DLLPUBLIC DamageHandler class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphicsAutoDelegateToImpl { - cairo_surface_t* m_pSurface; + CairoCommon m_aCairoCommon; basegfx::B2IVector m_aFrameSize; double m_fScale; Color m_aLineColor; @@ -99,7 +68,7 @@ class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphicsAutoDelegateToImpl public: void setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize); - cairo_surface_t* getSurface() const { return m_pSurface; } + cairo_surface_t* getSurface() const { return m_aCairoCommon.m_pSurface; } static cairo_user_data_key_t* getDamageKey(); static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion); |