[cairo] cairo_image_surface_create(), limited width

Uli Schlachter psychon at znc.in
Mon Aug 3 15:23:51 UTC 2020


Hi,

Am 03.08.20 um 16:32 schrieb Stanisław Jeśmanowicz:
> On 03-08-2020 15:36, Uli Schlachter wrote:
>> Am 02.08.20 um 13:25 schrieb Stanisław Jeśmanowicz:
[...]
>>> - Do we really need this conservative  check
>>> (_cairo_image_surface_is_size_valid()) ?
>> Uhm, yes. What use is a large surface if you cannot draw to parts of it?
> I can imagine that large surface can be a problem, although only host
> computer memory is the limit.
> 32767 x 32767 is roughly 1GB.

This is not about "large" as in "uses a lot of memory". This is about
"large" as in "has a large width *OR* a large height", larger than what
we can draw to.

A surface with size 10000000 x 1 does not use much memory (I assume - no
idea which number key repeat ended up producing here).
Let us now try to draw to it. We want the last few pixels to be filled:

cairo_rectangle(cr, 10000000 - 42, 0, 42, 1);
cairo_fill(cr);

This now tries to draw to a coordinate that is larger than 16 bits. This
means that when calling pixman to do the actual drawing, an integer
overflow happens. The rectangle will actually be drawn at the requested
coordinate modulo 2^16.

This is what I mean with "Pixman uses a fixed point format for
specifying coordinates. 16 bits specify the integer part and 16 bits
specify the fractional part."

Cheers,
Uli
-- 
Sent from my Game Boy.


More information about the cairo mailing list