Commit graph

7458 commits

Author SHA1 Message Date
Bryce Harrington
c6e12d33bf win32: Copyedit recent comments 2018-05-31 18:31:12 -07:00
Vasily Galkin
d4355ecee2 win32: Allow GDI operations for argb32 surfaces (allowed by surface flags)
This finishes a patch series to speed up CAIRO_OPERATOR_SOURCE when used
to copy data to a argb32 cairo surface corresponding to a win32 dc from
a "backbuffer" - DibSection-based cairo surface created with
cairo_surface_create_similar().

This final patch allows the GDI compositor to be used on argb32
surfaces.  For display surfaces, only copying is allowed with gdi (by
BitBlt), since other operations are filtered by flags in
implementations.

But since copying pixels is the only operation used in the most common
scenario (prepare an offscreen image and send it to the screen) - this
is important for presenting argb32 windows with Cairo directly or with
gtk+gdk (which nowadays always creates argb32 windows).

Before this patch pixel copy worked by:
1. mapping image to memory (by copying data from window dc to system
   memory which is very slow on windows maybe due to gpu or interprocess
   access)
2. copying new data over that image.
3. copying updated image from system memory back to window dc.

After this patch there is only one step:

2+3. Copying new data over window dc.

Completely eliminating step 1 gives a very huge speedup and allows
argb32 cairo drawing be as fast as typical dibsection-buffered gdi
drawing.

There is quick & dirty cairo-vs-gdi perf test made for this patch set:
https://gitlab.gnome.org/galkinvv/cairo/snippets/109
See the Cairo mailing list for April 2018 for data and discussion of
performance improvements.

End-user visible speedup does present too - it relates to the following bug

https://gitlab.gnome.org/GNOME/meld/issues/133

This Cairo speedup allows more simultaneous meld windows
without eating 100% of cpu core time on spinner rendering.
2018-05-31 17:34:17 -07:00
Vasily Galkin
0cb7aad2a3 win32: CAIRO_WIN32_SURFACE_CAN_RGB_BRUSH and other argb32 flags set+check
This belongs to a patch series that speeds up CAIRO_OPERATOR_SOURCE when
used to copy data to an argb32 cairo surface corresponding to a win32 dc
from a "backbuffer" - DibSection-based cairo surface created with
cairo_surface_create_similar().

This patch introduces checks to ensure that no solid brush GDI operations
are attempted when using argb32 surfaces.  Doing this allows enabling
usage of the GDI compositor when these surfaces are in use.

To make these checks work, _cairo_win32_flags_for_dc disables
STRETCHBLT, STRETCHDIB and RGB_BRUSH in the argb32 flag.

_cairo_win32_flags_for_dc() is also refactored to make the distinction
between rgb24 and argb32 more readable.  All logic & flags for rgb24
surfaces are retained, except for the addition of
CAIRO_WIN32_SURFACE_CAN_RGB_BRUSH.

The logic of forbidding AlphaBlend on display surfaces is also
kept as is without investigation.
2018-05-31 17:29:26 -07:00
Vasily Galkin
884275c3ab win32: Introduce new flag to mark surfaces that support solid brush drawing
This is part of a patch series to speed up CAIRO_OPERATOR_SOURCE when
used to copy data to an argb32 cairo surface corresponding to a win32 dc
from a "backbuffer" - DibSection-based cairo surface created with
cairo_surface_create_similar().

This initial patch presents only private header changes without changing
any implementation logic.

The big problem with argb32 surfaces and GDI is that GDI is unable to
correctly set the alpha channel when using operations other than BitBlt
and AlphaBlend.

To solve this, a CAIRO_WIN32_SURFACE_CAN_RGB_BRUSH flag is introduced in
this commit to be mark surfaces that correctly handle such brushes
- essentially all surface types except argb32.
The _cairo_win32_flags_for_dc() call receives a new argument that is
used to calculate the flag.
2018-05-31 17:24:50 -07:00
Bryce Harrington
85fe4deee4 gl: Whitespace cleanup 2018-05-29 12:15:47 -07:00
Bryce Harrington
4b9333acf5 Drop stray patch from prior commit 2018-05-07 16:50:42 -07:00
Adrian Johnson
1998239387 Use _cairo_malloc instead of malloc
_cairo_malloc(0) always returns NULL, but has not been used
consistently.  This patch replaces many calls to malloc() with
_cairo_malloc().

Fixes:  fdo# 101547
CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-05-07 16:35:51 -07:00
Uli Schlachter
7554822dd0 Fix assertion failure in the freetype backend
Fonts are kept in a hash table, so when creating a new font, the code
first checks the hash table for an already-existing entry and only then
is a new instance really created. There is an assert that checks that
the key used for the hash table lookup is the same as the instance that
is created later has, because otherwise the hash table was checked
incorrectly.

This assert failed in some conditions.

Fix this by fixing some places that initialised ft hash keys in a wrong
way.

Patch by Behdad Esfahbod and submitted via bugzilla.

Source: https://bugs.freedesktop.org/show_bug.cgi?id=105746#c4
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=105746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-04-21 09:37:06 +02:00
Bryce Harrington
38806bc3c0 Disable skia from configure
Implement suggestion by Adrian Johnson to comment out skia in
configure.ac to avoid presenting it as an option to users.  This was
discussed on the Cairo mailing list in September 2017.

Skia is not API stable and is not available in packaged+versioned forms,
resulting in it being a continually moving target.  I.e. it's pretty
much always unusably out of date.  The last update to the skia backend
was in 2014, and had not been updated very regularly prior to that.

We'll simply disable it for now.  If no one complains by the next Cairo
snapshot release, we'll assume no one is needing it and will drop the
code entirely.

Meanwhile, if anyone does need it, it can be uncommented and used.

(The changes to the win32 build config appear to be automatically
generated as a result of disabling the feature in configure.  I'm
committing them to avoid confusion.)
2018-04-02 20:20:00 -07:00
Bryce Harrington
dcafd9e684 cairo-version: Fix version references in docs
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=82741
2018-04-02 17:51:08 -07:00
Unknown
12cb59be7d Cairo trivial typos
Found using `codespell -q 3 -I cairo-whitelist.txt`
whereby whitelist contained:
```
amin
iff
lod
writen
```

Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-04-02 17:46:58 -07:00
Uli Schlachter
1ed124ace2 Fix a 'memory leak' in the image compositor
There is a global pixman_glyph_cache_t instance that is initialized on
first use and shows up in valgrind output as a relatively large leak (I
think it was about 200 KiB). The reason for this is that this cache is
not freed by cairo_debug_reset_static_data().

This commit wires up freeing the cache to
cairo_debug_reset_static_data().

This cache was introduced in commit 615205cf07 from 2012.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-03-15 21:43:03 +01:00
Massimo
5454b85d4b bfo#91271 - Fix access of uninitialized memory
Valgrind reports that xlib-render-compositor's composite_traps()
accesses uninitialized memory when traps->num_traps == 0.

This happens in the line that says

      if (xtraps[0].left.p1.y < xtraps[0].left.p2.y) {

after the 'for' loop.  We can actually return early if there are no
trapezoids to render.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=91271
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-03-08 13:30:17 -08:00
Federico Mena Quintero
45e3b8f271 bfo#105084 - Initialize memory properly in _cairo_ft_font_face_create_for_pattern()
The font_face->ft_options field was not being initialized, leading to
an invalid free().

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=105084
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-03-08 13:30:11 -08:00
Bryce Harrington
14404ada80 compiler-private: Define what PLT stands for 2018-02-28 15:19:06 -08:00
Bryce Harrington
62b724ac84 win32: Fix a few typos in comments 2018-02-06 15:13:00 -08:00
Bryce Harrington
dbe3d9ea51 win32: Whitespace cleanup 2018-02-06 15:13:00 -08:00
Eric Hoffman
4d07b57c16 win32: Fix multi-monitor virtual desktop with negative monitor coords
Under Win32, when you have a multiple-monitor setup, Windows creates a
'virtual desktop', which is a rectangle surface that extends across all
monitors.

The primary monitor always starts with the top-left corner at coordinate
(0,0).  If you have any other monitors which extend to the left or
above the primary monitor, the virtual desktop's top-left corner will
actually have coordinates which are negative.

This creates an issue in Cairo with the desktop DC, i.e. when you use a
DC from the function GetDC(NULL).  The same thing can occur with other
third party libraries like GTK, when you access the Cairo surface from
the root window.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=100793
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-02-06 15:12:33 -08:00
Bryce Harrington
a8571a3030 xml: Typo in comment 2018-02-06 12:06:48 -08:00
Bryce Harrington
1cbebafe89 font: Check return value from _cairo_ft_unscaled_font_lock_face
cairo-ft-font.c: In function ‘_cairo_ft_has_color_glyphs’:
cairo-ft-font.c:3011:9: warning: ignoring return value of ‘_cairo_ft_unscaled_font_lock_face’, declared with attribute warn_unused_result [-Wunused-result]
         _cairo_ft_unscaled_font_lock_face (unscaled);
         ^
2018-01-23 19:58:35 -08:00
Bryce Harrington
bc335a741f Fix two type casting warnings in get_C_locale()
cairo-misc.c:806:43: warning: passing argument 1 of ‘_cairo_atomic_ptr_get’ from incompatible pointer type
     C = (locale_t) _cairo_atomic_ptr_get (&C_locale);
                                           ^

cairo-misc.c:811:45: warning: passing argument 1 of ‘_cairo_atomic_ptr_cmpxchg_impl’ from incompatible pointer type
         if (!_cairo_atomic_ptr_cmpxchg (&C_locale, NULL, C)) {
                                             ^

Routines are expecting a void** so cast.
2018-01-23 19:20:08 -08:00
Behdad Esfahbod
5795ac9d90 Fix compile with older FreeType without FT_Get_Var_Design_Coordinates 2018-01-15 19:28:56 -05:00
Uli Schlachter
b7f313a8d2 fix warning: variable X might be clobbered by 'longjmp'
According to "man setjmp", one possible way to avoid variable clobbering
is to declare them as volatile. Thus, this commit turns the variables
that are changed between setjmp() and longjmp() and whose values are
still needed after setjmp() returned the second time into volatile
variables.

The warning in cairo-bentley-ottmann-rectangular.c is worked around by
not initializing the variable before setjmp(). To be honest, I don't
understand why the compiler warns here at all since the value of update
is clearly not used after setjmp()'s second return.

This commit re-fixes the warnings that were reintroduced in commit
82f40285 which reverted b092b63.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Acked-by: Bryce Harrington <bryce@osg.samsung.com>
2018-01-13 11:30:50 +01:00
Uli Schlachter
62f2037bc0 Fix warning: '*' in boolean context
The full message is:

  warning: ‘*’ in boolean context, suggest ‘&&’ instead
      _cairo_malloc((unsigned) (a) * (unsigned) (size)))
                                   ^
  note: in definition of macro ‘_cairo_malloc’
      ((size) ? malloc((unsigned) (size)) : NULL)
        ^~~~

Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-01-13 11:30:26 +01:00
Behdad Esfahbod
c3659d7ef6 Use FT_Done_MM_Var() if available 2018-01-08 10:07:25 +00:00
Matthias Clasen
37f9a5525d Don't leak memory in font options
The cairo_font_options_t struct may now contain allocated
memory, so call fini whenever we are about to let go of an
embedded cairo_font_options_t struct.
2018-01-05 09:10:32 -05:00
Matthias Clasen
1f0b6707ea Add a _cairo_font_options_fini function
The variations member of cairo_font_options_t is allocated,
so we need to have a method to free it for cases where
the struct is embedded in larger structs, such as cairo_ft_options_t.
2018-01-05 09:09:01 -05:00
Matthias Clasen
17871c52ef Don't leak patterns when compositing color glyphs
We were forgetting to free the pattern here.
2018-01-04 23:25:09 -05:00
Matthias Clasen
616fb7a9f2 Fix a memory leak
cairo_ft_apply_variations was leaking the FT_MM_Var struct.
2018-01-04 20:56:59 -05:00
Behdad Esfahbod
a7a0085713 Merge branch 'font-variations' 2018-01-03 12:35:12 +00:00
Behdad Esfahbod
a18c0decda [ft] Remember variations set on FT_Face and apply them
For this to work correctly with hb-view, needs a patch that went
into FreeType today.
2018-01-02 19:25:18 -05:00
Uli Schlachter
82f4028532 Revert "fix warning: variable X might be clobbered by 'longjmp'"
This reverts commit b092b63119 which
introduced a wrapper function around setjmp(). To quote from man setjmp:

  If the function which called setjmp() returns before longjmp() is
  called, the behavior is undefined.  Some kind of subtle or unsubtle
  chaos is sure to result.

Since after the above commit setjmp() is called from the wrapper
function, the result might or might not work, depending on compiler
settings. If the setjmp() wrapper is not inlined, then the state of the
stack after longjmp() will likely be garbage.
2017-12-23 13:04:59 +01:00
Bryce Harrington
3e07efd21e makefile: Fix sorting of source files 2017-12-20 17:09:05 -08:00
Behdad Esfahbod
e8ddc505b3 [ft] Fix warnings 2017-12-19 18:04:04 -05:00
Matthias Clasen
c32a5c741f Shortcut FT_Set_Var_Design_Coordinates
We currently (have to) apply font variations for every glyph.
Calling FT_Set_Var_Design_Coordinates has expensive side-effects,
like resetting the autohinter, so we should avoid doing it
fht he coordinates don't actually change.
2017-12-19 17:36:36 -05:00
Behdad Esfahbod
d8ddadc5c3 [ft] When merging font options, order variations correctly
Later wins, and we want "options" to win over "other".
2017-12-19 15:29:13 -05:00
Behdad Esfahbod
82107467f0 [ft] Use variations from ft_options, not scaled-font
Otherwise the variations from FcPattern won't be applied.
2017-12-19 15:18:57 -05:00
Matthias Clasen
976b34c31c fixup
We were passing a face index to cairo_ft_apply_variations,
but that function was expecting an instance id, which is
the face index shifted by 16.
2017-12-19 15:18:57 -05:00
Matthias Clasen
5c7f07d4ea fixup: remove a hack
This bug that this hack is working around has been
fixed in freetype now.
2017-12-19 15:18:57 -05:00
Matthias Clasen
1b5677ad6d Apply font variations when loading glyphs
So far, we only call cairo_ft_apply_variations() in
cairo_ft_scaled_font_lock_face(), but this function is not
used internally. We need to apply it also when loading
glyphs.

This makes pango-view show font variations correctly.
2017-12-19 15:18:57 -05:00
Matthias Clasen
f2b6fac43f Trivial: code movement
Move cairo_ft_apply_font_variations() earlier in the code
since we will be using it in another place soon.
2017-12-19 15:18:57 -05:00
Matthias Clasen
42f07ef903 Always save the origin face index
Save the original face_index also for the from_face case,
so we can always rely on it when applying font variations.
This prevents us from running into the same trap we've seen
before where ft_face->face_index changes underneath us as
font variations are applied.
2017-12-19 15:18:57 -05:00
Matthias Clasen
1735fc41d3 Apply font variation options consistently
We must not look at the instance_id field of the cached ft_face,
since freetype changes it underneath us (if we set the axis values
to match a named instance, the instance_id gets changed to reflect
that). Thankfully, we have the original instance_id stashed away
in the cairo_unscaled_font, so we can just use that to decide if
we are dealing with a named instance or not.

This makes the font variations tests pass.
2017-12-19 15:18:57 -05:00
Behdad Esfahbod
db946d1788 [varfonts] Correctly (re)set variations of named instances 2017-12-19 15:18:57 -05:00
Behdad Esfahbod
7125c4bf5e [varfonts] Use blend, not design, coordinates to check for non-base variation
If all blend coordinates are zero, we are at base font.  This is more robust.
2017-12-19 15:18:57 -05:00
Behdad Esfahbod
374ee5a2fd [variations] Merge variations in cairo-ft font option merging
This function should be rewritten to call cairo_font_options_merge(), but
currently it doesn't.

Speculative. Untested.
2017-12-19 15:17:01 -05:00
Matthias Clasen
7cc07f184b Work around a freetype bug
The first call to FT_Get_MM_Var on a newly created FT_Face
fails. So just repeat the call.
2017-12-19 15:17:01 -05:00
Matthias Clasen
721b7ea0a7 Apply font variations when loading fonts
Parse font variation settings and pass them on to
freetype when loading fonts.
2017-12-19 15:17:01 -05:00
Matthias Clasen
a8ae2eafc8 Use strtod_l when available
Using strtod_l and newlocale is a nicer way to have provide
a C-locale-only strtod. Since these APIs are not available
everywhere, keep the old code as a fallback.
2017-12-19 15:17:01 -05:00
Matthias Clasen
ac5acc4538 Load font variations from fontconfig too
When extracting font options from a fontconfig pattern,
also extract font variation information if present.
2017-12-19 15:16:20 -05:00