summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2023-05-23 20:13:14 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-05-23 22:13:34 +0200
commit2a1e7671795ee6c6350b7d799b9c4742ffb67e78 (patch)
tree9e4f930c620418c1bad52ba3962ce9e3cc50c132 /vcl
parentc43e39a7b7f4b0ed6165af966cce8057a93eb22f (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/+/152173 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/unx/cairotextrender.hxx4
-rw-r--r--vcl/unx/generic/gdi/cairotextrender.cxx68
2 files changed, 45 insertions, 27 deletions
diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx
index 05f15d14ee27..ff0a2117811a 100644
--- a/vcl/inc/unx/cairotextrender.hxx
+++ b/vcl/inc/unx/cairotextrender.hxx
@@ -32,10 +32,6 @@ class VCL_DLLPUBLIC CairoTextRender : public FreeTypeTextRenderImpl
{
private:
CairoCommon& mrCairoCommon;
- // 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:
cairo_t* getCairoContext();
void releaseCairoContext(cairo_t* cr);
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index e7689c1028e1..f962c21d39ed 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -131,35 +131,57 @@ extern "C"
}
#endif
-CairoTextRender::CairoTextRender(CairoCommon& rCairoCommon)
- : mrCairoCommon(rCairoCommon)
-{
- // 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(CairoCommon& rCairoCommon)
+ : mrCairoCommon(rCairoCommon)
+{
}
CairoTextRender::~CairoTextRender()
{
- cairo_font_options_destroy(mpRoundGlyphPosOffOptions);
}
static void ApplyFont(cairo_t* cr, const CairoFontsCache::CacheId& rId, double nWidth, double nHeight, int nGlyphRotation,
@@ -415,7 +437,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))