Resolves tdf#155070 - Easy access to skia.log

Change-Id: I2aac7a060bbb1d31510da67120728c8a24f0de88
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151699
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/cui/inc/bitmaps.hlst b/cui/inc/bitmaps.hlst
index 5e10e01..db0a6ae9 100644
--- a/cui/inc/bitmaps.hlst
+++ b/cui/inc/bitmaps.hlst
@@ -71,6 +71,7 @@ inline constexpr OUStringLiteral RID_SVXBMP_LEGTYP3 = u"svx/res/legtyp3.png";

inline constexpr OUStringLiteral RID_SVXBMP_COMPONENT = u"res/component_16.png";
inline constexpr OUStringLiteral RID_SVXBMP_MACRO = u"svx/res/id018.png";
inline constexpr OUStringLiteral RID_SVXBMP_COPY = u"cmd/sc_copy.png";

inline constexpr OUStringLiteral RID_SVXBMP_STARS_FULL = u"cmd/sc_stars-full.png";

diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index 04de401..369e48a 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -81,11 +81,15 @@
#include <vcl/window.hxx>
#include <vcl/IconThemeInfo.hxx>
#include <vcl/skia/SkiaHelper.hxx>
#include <bitmaps.hlst>

#include "optgdlg.hxx"
#include <svtools/apearcfg.hxx>
#include <svtools/optionsdrawinglayer.hxx>
#include <svtools/restartdialog.hxx>
#include <svtools/imgdef.hxx>
#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
#include <vcl/unohelp2.hxx>

#if defined(_WIN32)
#include <systools/win32/winstoreutil.hxx>
@@ -537,6 +541,7 @@ OfaViewTabPage::OfaViewTabPage(weld::Container* pPage, weld::DialogController* p
    , m_xForceSkiaRaster(m_xBuilder->weld_check_button("forceskiaraster"))
    , m_xSkiaStatusEnabled(m_xBuilder->weld_label("skiaenabled"))
    , m_xSkiaStatusDisabled(m_xBuilder->weld_label("skiadisabled"))
    , m_xSkiaLog(m_xBuilder->weld_button("btnSkialog"))
    , m_xMouseMiddleLB(m_xBuilder->weld_combo_box("mousemiddle"))
    , m_xMoreIcons(m_xBuilder->weld_button("btnMoreIcons"))
    , m_xRunGPTests(m_xBuilder->weld_button("btn_rungptest"))
@@ -550,6 +555,7 @@ OfaViewTabPage::OfaViewTabPage(weld::Container* pPage, weld::DialogController* p
    m_xFontAntiAliasing->connect_toggled( LINK( this, OfaViewTabPage, OnAntialiasingToggled ) );

    m_xUseSkia->connect_toggled(LINK(this, OfaViewTabPage, OnUseSkiaToggled));
    m_xSkiaLog->connect_clicked(LINK(this, OfaViewTabPage, OnCopySkiaLog));

    UpdateIconThemes();

@@ -611,12 +617,25 @@ IMPL_LINK_NOARG(OfaViewTabPage, OnUseSkiaToggled, weld::Toggleable&, void)
    UpdateSkiaStatus();
}

IMPL_LINK_NOARG(OfaViewTabPage, OnCopySkiaLog, weld::Button&, void)
{
#if HAVE_FEATURE_SKIA
    css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
        css::datatransfer::clipboard::SystemClipboard::create(
            comphelper::getProcessComponentContext());
    OUString sInfo = SkiaHelper::readLog();
    vcl::unohelper::TextDataObject::CopyStringTo(sInfo, xClipboard);
    m_xSkiaLog->set_from_icon_name(RID_SVXBMP_COPY);
#endif
}

void OfaViewTabPage::HideSkiaWidgets()
{
    m_xUseSkia->hide();
    m_xForceSkiaRaster->hide();
    m_xSkiaStatusEnabled->hide();
    m_xSkiaStatusDisabled->hide();
    m_xSkiaLog->hide();
}

void OfaViewTabPage::UpdateSkiaStatus()
diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx
index 9b22c0b..c0d2439 100644
--- a/cui/source/options/optgdlg.hxx
+++ b/cui/source/options/optgdlg.hxx
@@ -104,6 +104,7 @@ private:

    std::unique_ptr<weld::Label> m_xSkiaStatusEnabled;
    std::unique_ptr<weld::Label> m_xSkiaStatusDisabled;
    std::unique_ptr<weld::Button> m_xSkiaLog;

    std::unique_ptr<weld::ComboBox> m_xMouseMiddleLB;
    std::unique_ptr<weld::Button> m_xMoreIcons;
@@ -113,6 +114,7 @@ private:

    DECL_LINK(OnAntialiasingToggled, weld::Toggleable&, void);
    DECL_LINK(OnUseSkiaToggled, weld::Toggleable&, void);
    DECL_LINK(OnCopySkiaLog, weld::Button&, void);
    DECL_STATIC_LINK(OfaViewTabPage, OnMoreIconsClick, weld::Button&, void);
    DECL_LINK(OnRunGPTestClick, weld::Button&, void);
    void UpdateSkiaStatus();
diff --git a/cui/uiconfig/ui/optviewpage.ui b/cui/uiconfig/ui/optviewpage.ui
index a063a4f..d24f7ef 100644
--- a/cui/uiconfig/ui/optviewpage.ui
+++ b/cui/uiconfig/ui/optviewpage.ui
@@ -412,7 +412,7 @@
            <property name="label-xalign">0</property>
            <property name="shadow-type">none</property>
            <child>
              <!-- n-columns=1 n-rows=6 -->
              <!-- n-columns=1 n-rows=7 -->
              <object class="GtkGrid" id="grid3">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
@@ -520,6 +520,18 @@
                    <property name="top-attach">5</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="btnSkialog">
                    <property name="label" translatable="yes" context="optviewpage|btnSkialog">Copy skia.log</property>
                    <property name="visible">True</property>
                    <property name="can-focus">True</property>
                    <property name="receives-default">True</property>
                  </object>
                  <packing>
                    <property name="left-attach">0</property>
                    <property name="top-attach">6</property>
                  </packing>
                </child>
              </object>
            </child>
            <child type="label">
diff --git a/include/vcl/skia/SkiaHelper.hxx b/include/vcl/skia/SkiaHelper.hxx
index 128c758..37fed7f 100644
--- a/include/vcl/skia/SkiaHelper.hxx
+++ b/include/vcl/skia/SkiaHelper.hxx
@@ -11,12 +11,14 @@
#define INCLUDED_VCL_SKIA_SKIAHELPER_HXX

#include <vcl/dllapi.h>
#include <rtl/ustring.hxx>

#include <config_features.h>

namespace SkiaHelper
{
VCL_DLLPUBLIC bool isVCLSkiaEnabled();
VCL_DLLPUBLIC OUString readLog();

#if HAVE_FEATURE_SKIA

diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index a6189a3..16cbdd3 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -72,6 +72,18 @@ static void writeToLog(SvStream& stream, const char* key, const char* value)
    stream.WriteChar('\n');
}

OUString readLog()
{
    SvFileStream logFile(getCacheFolder() + "/skia.log", StreamMode::READ);

    OUString sResult;
    OString sLine;
    while (logFile.ReadLine(sLine))
        sResult += OStringToOUString(sLine, RTL_TEXTENCODING_UTF8) + "\n";

    return sResult;
}

uint32_t vendorId = 0;

#ifdef SK_VULKAN