summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2023-05-23 18:19:45 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-05-23 21:15:29 +0200
commit28615c7c048151820b44beddf444690403ee55e6 (patch)
tree611ba7eb0b2b2b17d90968f99f3fbd42d5bcf419 /vcl
parent56298afb797b7406d1d3b4d6cf6fdb23e4284679 (diff)
perf: surprising to see PDF being vsprintf'd during JSDialog rendering.
Avoid some hundreds of these: _cairo_pdf_surface_show_page ... cairo_surface_destroy CairoTextRender::CairoTextRender via. SvpCairoTextRender: :SvpCairoTextRender(SvpSalGraphics&) SvpSalGraphics: :SvpSalGraphics() Change-Id: Ieefb65138f7e685f09dbf4c36a2fccd39b4b05cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152168 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/unx/cairotextrender.hxx5
-rw-r--r--vcl/unx/generic/gdi/cairotextrender.cxx66
2 files changed, 44 insertions, 27 deletions
diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx
index e9a85739827b..70ae0dceccc4 100644
--- a/vcl/inc/unx/cairotextrender.hxx
+++ b/vcl/inc/unx/cairotextrender.hxx
@@ -29,11 +29,6 @@ typedef struct _cairo_font_options cairo_font_options_t;
class VCL_DLLPUBLIC CairoTextRender : public FreeTypeTextRenderImpl
{
-private:
- // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235
- // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo
- // surfaces font_options, but that's private, so tricky to achieve
- cairo_font_options_t* mpRoundGlyphPosOffOptions;
protected:
virtual cairo_t* getCairoContext() = 0;
virtual void getSurfaceOffset(double& nDX, double& nDY) = 0;
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 612bf49ff6d0..0a10f6708faf 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -131,34 +131,56 @@ extern "C"
}
#endif
-CairoTextRender::CairoTextRender()
-{
- // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235
- // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo surfaces
- // font_options when trying subpixel rendering, but that's a private
- // feature of cairo_font_options_t, so tricky to achieve. Hack this by
- // getting the font options of a backend known to set this private feature
- // to CAIRO_ROUND_GLYPH_POS_OFF and then set to defaults the public
- // features and the result can be merged with new font options to set
- // CAIRO_ROUND_GLYPH_POS_OFF in those
- mpRoundGlyphPosOffOptions = cairo_font_options_create();
+namespace {
+ struct CairoFontOptions
+ {
+ // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235
+ // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo
+ // surfaces font_options, but that's private, so tricky to achieve
+ cairo_font_options_t* mpRoundGlyphPosOffOptions;
+
+ CairoFontOptions()
+ {
+ // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235
+ // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo surfaces
+ // font_options when trying subpixel rendering, but that's a private
+ // feature of cairo_font_options_t, so tricky to achieve. Hack this by
+ // getting the font options of a backend known to set this private feature
+ // to CAIRO_ROUND_GLYPH_POS_OFF and then set to defaults the public
+ // features and the result can be merged with new font options to set
+ // CAIRO_ROUND_GLYPH_POS_OFF in those
+ mpRoundGlyphPosOffOptions = cairo_font_options_create();
#if defined(CAIRO_HAS_SVG_SURFACE)
- // svg, pdf and ps backends have CAIRO_ROUND_GLYPH_POS_OFF by default
- cairo_surface_t* hack = cairo_svg_surface_create(nullptr, 1, 1);
+ // svg, pdf and ps backends have CAIRO_ROUND_GLYPH_POS_OFF by default
+ cairo_surface_t* hack = cairo_svg_surface_create(nullptr, 1, 1);
#elif defined(CAIRO_HAS_PDF_SURFACE)
- cairo_surface_t* hack = cairo_pdf_surface_create(nullptr, 1, 1);
+ cairo_surface_t* hack = cairo_pdf_surface_create(nullptr, 1, 1);
#endif
- cairo_surface_get_font_options(hack, mpRoundGlyphPosOffOptions);
- cairo_surface_destroy(hack);
- cairo_font_options_set_antialias(mpRoundGlyphPosOffOptions, CAIRO_ANTIALIAS_DEFAULT);
- cairo_font_options_set_subpixel_order(mpRoundGlyphPosOffOptions, CAIRO_SUBPIXEL_ORDER_DEFAULT);
- cairo_font_options_set_hint_style(mpRoundGlyphPosOffOptions, CAIRO_HINT_STYLE_DEFAULT);
- cairo_font_options_set_hint_metrics(mpRoundGlyphPosOffOptions, CAIRO_HINT_METRICS_DEFAULT);
+ cairo_surface_get_font_options(hack, mpRoundGlyphPosOffOptions);
+ cairo_surface_destroy(hack);
+ cairo_font_options_set_antialias(mpRoundGlyphPosOffOptions, CAIRO_ANTIALIAS_DEFAULT);
+ cairo_font_options_set_subpixel_order(mpRoundGlyphPosOffOptions, CAIRO_SUBPIXEL_ORDER_DEFAULT);
+ cairo_font_options_set_hint_style(mpRoundGlyphPosOffOptions, CAIRO_HINT_STYLE_DEFAULT);
+ cairo_font_options_set_hint_metrics(mpRoundGlyphPosOffOptions, CAIRO_HINT_METRICS_DEFAULT);
+ }
+ ~CairoFontOptions()
+ {
+ cairo_font_options_destroy(mpRoundGlyphPosOffOptions);
+ }
+ static const cairo_font_options_t *get()
+ {
+ static CairoFontOptions opts;
+ return opts.mpRoundGlyphPosOffOptions;
+ }
+ };
+}
+
+CairoTextRender::CairoTextRender()
+{
}
CairoTextRender::~CairoTextRender()
{
- cairo_font_options_destroy(mpRoundGlyphPosOffOptions);
}
void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGraphics& rGraphics)
@@ -293,7 +315,7 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG
// CAIRO_ROUND_GLYPH_POS_OFF
if (bResolutionIndependentLayoutEnabled)
{
- cairo_font_options_merge(pOptions, mpRoundGlyphPosOffOptions);
+ cairo_font_options_merge(pOptions, CairoFontOptions::get());
// tdf#153699 skip this with cairo 1.17.8 as it has a problem
// See: https://gitlab.freedesktop.org/cairo/cairo/-/issues/643
if (cairo_version() != CAIRO_VERSION_ENCODE(1,17,8))