[cairo] _cairo_win32_display_surface_map_to_image issue

Fred bca21 fredbca21 at gmail.com
Tue Nov 13 08:27:01 PST 2012


Hi,

while trying to fix a cairo crash on win32 (already posted on this
list), I am trying to understand the function below, and I can't
figure out how it works regarding coordinates (it looks inconsistent
to me):

- The first call to  _cairo_win32_display_surface_create_for_dc
creates a surface with the appropriate with and height regarding the
extent rectangle.
- then why does the BitBlt call uses 0.0 as the origin for the source
surface and not the origin of the extent since the newly created
surface is supposed to represent the extent rectangle?
- Also, why does the _cairo_image_surface_map_to_image using our newly
created image does not use (0,0) as the origin, since our newly
created image's origin corresponds to (extents.x,extents.y) in the
original surface?

There is probaby something that I am missing, but this seems to be the
origin of the crash that I am chasing (this functions returns a
pointer outside of the image boundaries due to a wrong offset).

Thanks for your help.

(If it is not the right list to discuss such implementation details,
please forgive me and tell me where I should post)

Fred.


-----------
static cairo_surface_t *
_cairo_win32_display_surface_map_to_image (void
*abstract_surface,
					   const cairo_rectangle_int_t   *extents)
{
    cairo_win32_display_surface_t *surface = abstract_surface;
    cairo_status_t status;

    TRACE ((stderr, "%s (surface=%d)\n",
	    __FUNCTION__, surface->win32.base.unique_id));

    if (surface->image)
	goto done;

    if (surface->fallback == NULL) {
	surface->fallback =
	    _cairo_win32_display_surface_create_for_dc (surface->win32.dc,
							surface->win32.format,
							surface->win32.extents.width,
							surface->win32.extents.height);
	if (unlikely (status = surface->fallback->status))
	    goto err;

	if (!BitBlt (to_win32_surface(surface->fallback)->dc,
		     0, 0,
		     surface->win32.extents.width,
		     surface->win32.extents.height,
		     surface->win32.dc,
		     0, 0,
		     SRCCOPY)) {
	    status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
	    goto err;
	}
    }

    surface = to_win32_display_surface (surface->fallback);
done:
    GdiFlush();
    return _cairo_image_surface_map_to_image (surface->image, extents);


More information about the cairo mailing list