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 --
 include/vcl/cairo.hxx                     |   16 ++++++++----
 libreofficekit/qa/tilebench/tilebench.cxx |   38 ++++++++++++++++--------------
 vcl/headless/CairoCommon.cxx              |    2 -
 10 files changed, 68 insertions(+), 26 deletions(-)

New commits:
commit 22ab4f30ac2125579c43ad889f7b8b45b1dda3e3
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Jun 26 16:56:21 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Jun 27 10:04:36 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/+/153628
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/config_host.mk.in b/config_host.mk.in
index 0ab0e2f747c4..233e2247816c 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -145,6 +145,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 04dcacc85a66..ece7c7d40db8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2482,6 +2482,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.]))
@@ -13610,6 +13614,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 ===================================================================
@@ -13618,7 +13636,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])
 
@@ -14924,6 +14942,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 074a5b81b1ad..4311b501ad16 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>
@@ -4229,7 +4230,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 5873d12a2522..f545bb4b8199 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 a3598f0d5150..f1697c6d0cc9 100644
--- a/external/cairo/UnpackedTarball_cairo.mk
+++ b/external/cairo/UnpackedTarball_cairo.mk
@@ -40,8 +40,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/include/vcl/cairo.hxx b/include/vcl/cairo.hxx
index c3c5e5ac5ee6..8a6042517534 100644
--- a/include/vcl/cairo.hxx
+++ b/include/vcl/cairo.hxx
@@ -24,14 +24,20 @@
 #include <vcl/Scanline.hxx>
 #include <vcl/vclptr.hxx>
 #include <config_features.h>
+#include <config_cairo_rgba.h>
 #include <memory>
 
-//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
diff --git a/libreofficekit/qa/tilebench/tilebench.cxx 
b/libreofficekit/qa/tilebench/tilebench.cxx
index 382003e9ec5a..3464c589f542 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 a0a0a05b89bc..15b8cebfb261 100644
--- a/vcl/headless/CairoCommon.cxx
+++ b/vcl/headless/CairoCommon.cxx
@@ -2037,7 +2037,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");

Reply via email to