config_host.mk.in | 1 config_host/config_cairo_rgba.h.in | 6 ++++ configure.ac | 21 +++++++++++++++- desktop/source/lib/init.cxx | 5 +++ distro-configs/CPLinux-LOKit.conf | 1 distro-configs/LibreOfficeOnline.conf | 1 external/cairo/UnpackedTarball_cairo.mk | 3 -- libreofficekit/qa/tilebench/tilebench.cxx | 38 ++++++++++++++++-------------- vcl/headless/CairoCommon.cxx | 2 - vcl/inc/headless/CairoCommon.hxx | 16 ++++++++---- 10 files changed, 68 insertions(+), 26 deletions(-)
New commits: commit ad65368380f49d8cfd111ea393243fa4d4888afb Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Mon Jun 26 16:56:21 2023 +0100 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Wed Jul 5 12:56:03 2023 +0200 add an --enable-cairo-rgba to set the order of pixels for internal cairo Change-Id: Ieab2ef59f63a7722bffea3273d2eeefadef47b56 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153633 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> diff --git a/config_host.mk.in b/config_host.mk.in index addccaeeb44f..92c8a2f99c3b 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -142,6 +142,7 @@ export ENABLE_AVAHI=@ENABLE_AVAHI@ export ENABLE_BREAKPAD=@ENABLE_BREAKPAD@ export DEFAULT_CRASHDUMP_VALUE=@DEFAULT_CRASHDUMP_VALUE@ export ENABLE_CAIRO_CANVAS=@ENABLE_CAIRO_CANVAS@ +export ENABLE_CAIRO_RGBA=@ENABLE_CAIRO_RGBA@ export ENABLE_CIPHER_OPENSSL_BACKEND=@ENABLE_CIPHER_OPENSSL_BACKEND@ export ENABLE_CLUCENE=@ENABLE_CLUCENE@ export ENABLE_LIBCMIS=@ENABLE_LIBCMIS@ diff --git a/config_host/config_cairo_rgba.h.in b/config_host/config_cairo_rgba.h.in new file mode 100644 index 000000000000..bdbecfbbc0e1 --- /dev/null +++ b/config_host/config_cairo_rgba.h.in @@ -0,0 +1,6 @@ +#ifndef CONFIG_CAIRO_RGBA_H +#define CONFIG_CAIRO_RGBA_H + +#define ENABLE_CAIRO_RGBA 0 + +#endif diff --git a/configure.ac b/configure.ac index 26ec32a1eb13..b8f596fafdcc 100644 --- a/configure.ac +++ b/configure.ac @@ -2472,6 +2472,10 @@ AC_ARG_WITH(system-hunspell, [Use libhunspell already on system.]),, [with_system_hunspell="$with_system_libs"]) +libo_FUZZ_ARG_ENABLE(cairo-rgba, + AS_HELP_STRING([--enable-cairo-rgba], + [Use RGBA order, instead of default BRGA. Not possible with --with-system-cairo])) + libo_FUZZ_ARG_ENABLE(zxing, AS_HELP_STRING([--disable-zxing], [Disable use of zxing external library.])) @@ -13520,6 +13524,20 @@ fi AC_SUBST(USE_XINERAMA) AC_SUBST(XINERAMA_LINK) +AC_MSG_CHECKING([whether to use non-standard RGBA32 cairo pixel order]) +if test -z "$enable_cairo_rgba" -a "$_os" = "Android"; then + enable_cairo_rgba=yes +fi +if test "$enable_cairo_rgba" = yes; then + AC_DEFINE(ENABLE_CAIRO_RGBA) + ENABLE_CAIRO_RGBA=TRUE + AC_MSG_RESULT([yes]) +else + ENABLE_CAIRO_RGBA= + AC_MSG_RESULT([no]) +fi +AC_SUBST(ENABLE_CAIRO_RGBA) + dnl =================================================================== dnl Test whether to build cairo or rely on the system version dnl =================================================================== @@ -13528,7 +13546,7 @@ if test "$test_cairo" = "yes"; then AC_MSG_CHECKING([whether to use the system cairo]) : ${with_system_cairo:=$with_system_libs} - if test "$with_system_cairo" = "yes"; then + if test "$with_system_cairo" = "yes" -a "$enable_cairo_rgba" != "yes"; then SYSTEM_CAIRO=TRUE AC_MSG_RESULT([yes]) @@ -14778,6 +14796,7 @@ AC_CONFIG_HEADERS([config_host/config_dconf.h]) AC_CONFIG_HEADERS([config_host/config_eot.h]) AC_CONFIG_HEADERS([config_host/config_extensions.h]) AC_CONFIG_HEADERS([config_host/config_cairo_canvas.h]) +AC_CONFIG_HEADERS([config_host/config_cairo_rgba.h]) AC_CONFIG_HEADERS([config_host/config_cxxabi.h]) AC_CONFIG_HEADERS([config_host/config_dbus.h]) AC_CONFIG_HEADERS([config_host/config_features.h]) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 8448209e87b5..e8586fb5af7e 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -9,6 +9,7 @@ #include "sfx2/lokhelper.hxx" #include <config_buildconfig.h> +#include <config_cairo_rgba.h> #include <config_features.h> #include <stdio.h> @@ -4213,7 +4214,11 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis, static int doc_getTileMode(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/) { SetLastExceptionMsg(); +#if ENABLE_CAIRO_RGBA + return LOK_TILEMODE_RGBA; +#else return LOK_TILEMODE_BGRA; +#endif } static void doc_getDocumentSize(LibreOfficeKitDocument* pThis, diff --git a/distro-configs/CPLinux-LOKit.conf b/distro-configs/CPLinux-LOKit.conf index 180a23d63d89..271c0f43173b 100644 --- a/distro-configs/CPLinux-LOKit.conf +++ b/distro-configs/CPLinux-LOKit.conf @@ -6,6 +6,7 @@ --with-myspell-dicts --with-system-zlib --disable-poppler +--enable-cairo-rgba --without-system-cairo --without-system-fontconfig --without-system-freetype diff --git a/distro-configs/LibreOfficeOnline.conf b/distro-configs/LibreOfficeOnline.conf index 338fd7ac43a8..b22639232b71 100644 --- a/distro-configs/LibreOfficeOnline.conf +++ b/distro-configs/LibreOfficeOnline.conf @@ -15,6 +15,7 @@ --disable-odk --disable-online-update --disable-skia +--enable-cairo-rgba --enable-pdfimport --disable-postgresql-sdbc --disable-report-builder diff --git a/external/cairo/UnpackedTarball_cairo.mk b/external/cairo/UnpackedTarball_cairo.mk index de1d9296434d..3dfeefad6711 100644 --- a/external/cairo/UnpackedTarball_cairo.mk +++ b/external/cairo/UnpackedTarball_cairo.mk @@ -39,8 +39,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,cairo,\ )) endif -# To be applied only when ENABLE_ANDROID_LOK is not defined -ifeq ($(OS)$(ENABLE_ANDROID_LOK),ANDROID) +ifeq ($(ENABLE_CAIRO_RGBA),TRUE) $(eval $(call gb_UnpackedTarball_add_patches,cairo,\ external/cairo/cairo/cairo.GL_RGBA.patch \ )) diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx index 6b6dcf4056a4..73757acc9b1c 100644 --- a/libreofficekit/qa/tilebench/tilebench.cxx +++ b/libreofficekit/qa/tilebench/tilebench.cxx @@ -110,29 +110,33 @@ static void dumpTile(const char *pNameStem, for (int x = 0; x < nWidth; ++x) { const char* pixel = row + x * 4; - if (mode == LOK_TILEMODE_RGBA) + + const int alpha = *(pixel + 3); + char buf[3]; + if (alpha == 0) { - ofs.write(pixel, 3); // Skip alpha + buf[0] = 0; + buf[1] = 0; + buf[2] = 0; } - else if (mode == LOK_TILEMODE_BGRA) + else { - const int alpha = *(pixel + 3); - char buf[3]; - if (alpha == 0) - { - buf[0] = 0; - buf[1] = 0; - buf[2] = 0; - } - else + switch (mode) { - buf[0] = (*(pixel + 2) * 255 + alpha / 2) / alpha; - buf[1] = (*(pixel + 1) * 255 + alpha / 2) / alpha; - buf[2] = (*(pixel + 0) * 255 + alpha / 2) / alpha; + case LOK_TILEMODE_RGBA: + buf[0] = (*(pixel + 0) * 255 + alpha / 2) / alpha; + buf[1] = (*(pixel + 1) * 255 + alpha / 2) / alpha; + buf[2] = (*(pixel + 2) * 255 + alpha / 2) / alpha; + break; + case LOK_TILEMODE_BGRA: + buf[0] = (*(pixel + 2) * 255 + alpha / 2) / alpha; + buf[1] = (*(pixel + 1) * 255 + alpha / 2) / alpha; + buf[2] = (*(pixel + 0) * 255 + alpha / 2) / alpha; + break; } - - ofs.write(buf, 3); } + + ofs.write(buf, 3); if (dumpText) { int lowResI = (pixel[0] + pixel[1] + pixel[2])/(3*16); diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index 4f3a4e869746..8f74978b7fc6 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -1164,7 +1164,7 @@ std::unique_ptr<BitmapBuffer> FastConvert24BitRgbTo32BitCairo(const BitmapBuffer sal_uInt8* pD = pDst->mpBits + y * pDst->mnScanlineSize; for (tools::Long x = 0; x < nWidth; ++x) { -#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK +#if ENABLE_CAIRO_RGBA static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcRgba, "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra"); diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx index 3fc0144ef34a..7d66e4a15e73 100644 --- a/vcl/inc/headless/CairoCommon.hxx +++ b/vcl/inc/headless/CairoCommon.hxx @@ -21,6 +21,7 @@ #include <sal/config.h> #include <config_features.h> +#include <config_cairo_rgba.h> #include <cairo.h> @@ -40,12 +41,17 @@ #include <unordered_map> -//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. +// Using formats that match cairo's formats. // SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory. -#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK + +/* + For internal cairo we have the option --enable-cairo-rgba which is potentially + useful for Andoid or Online to switch the rgb components. For Android cairo then + matches the OpenGL GL_RGBA format so we can use it there where we don't have + GL_BGRA support. Similarly for Online we can then use cairo's pixel data + without needing to swizzle it for use as a canvas ImageData. +*/ +#if ENABLE_CAIRO_RGBA #define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) #define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown) #define SVP_CAIRO_BLUE 1