third_party/cairo/src/cairo-os2-surface.c
int
cairo_os2_surface_set_size (cairo_surface_t *surface,
                            int              new_width,
                            int              new_height,
                            int              timeout)
{
    cairo_os2_surface_t *local_os2_surface;
    unsigned char *pchNewPixels;
    int rc;
    cairo_image_surface_t *pNewImageSurface;

    local_os2_surface = (cairo_os2_surface_t *) surface;
    if ((!local_os2_surface) ||
        (local_os2_surface->base.backend != &cairo_os2_surface_backend))
    {
        /* Invalid parameter (wrong surface)! */
        return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
    }

    if ((new_width <= 0) ||
        (new_height <= 0))
    {
        /* Invalid size! */
        return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
    }

    /* Allocate memory for new stuffs */
    pchNewPixels = (unsigned char *) _buffer_alloc (new_height, new_width, 4);
    if (!pchNewPixels) {
        /* Not enough memory for the pixels!
         * Everything remains the same!
         */
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }

    /* Create image surface from new pixel array */
    pNewImageSurface = (cairo_image_surface_t *)
        cairo_image_surface_create_for_data (pchNewPixels,
                                             CAIRO_FORMAT_ARGB32,
                                             new_width,      /* Width */
                                             new_height,     /* Height */
                                             new_width * 4); /* Rowstride */

    if (pNewImageSurface->base.status) {
        /* Could not create image surface!
         * Everything remains the same!
         */
        _buffer_free (pchNewPixels);
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }

    /* Okay, new memory allocated, so it's time to swap old buffers
     * to new ones!
     */
    if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)!=NO_ERROR) {
        /* Could not get mutex!
         * Everything remains the same!
         */
        cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
        _buffer_free (pchNewPixels);
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }

    /* We have to make sure that we won't destroy a surface which
     * is lent to some other code (Cairo is drawing into it)!
     */
    while (local_os2_surface->pixel_array_lend_count > 0) {
        ULONG ulPostCount;
        DosResetEventSem (local_os2_surface->hev_pixel_array_came_back, &ulPostCount);
        DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
        /* Wait for somebody to return the pixels! */
        rc = DosWaitEventSem (local_os2_surface->hev_pixel_array_came_back, timeout);
        if (rc != NO_ERROR) {
            /* Either timeout or something wrong... Exit. */
            cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
            _buffer_free (pchNewPixels);
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
        }
        /* Okay, grab mutex and check counter again! */
        if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)
            != NO_ERROR)
        {
            /* Could not get mutex!
             * Everything remains the same!
             */
            cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
            _buffer_free (pchNewPixels);
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
        }
    }

    /* Destroy old image surface */
    cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface));
    /* Destroy old pixel buffer */
    _buffer_free (local_os2_surface->pixels);
    /* Set new image surface */
    local_os2_surface->image_surface = pNewImageSurface;
    /* Set new pixel buffer */
    local_os2_surface->pixels = pchNewPixels;
    /* Change bitmap2 structure */
    local_os2_surface->bitmap_info.cx = new_width;
    local_os2_surface->bitmap_info.cy = new_height;

    DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
    return CAIRO_STATUS_SUCCESS;
}
/**
 * cairo_os2_surface_set_size:
 * @surface: the cairo surface to resize
 * @new_width: the new width of the surface
 * @new_height: the new height of the surface
 * @timeout: timeout value in milliseconds
 *
 * When the client window is resized, call this API to set the new size in the
 * underlying surface accordingly. This function will reallocate everything,
 * so you'll have to redraw everything in the surface after this call.
 * The surface will contain garbage after the resizing. So the notes of
 * cairo_os2_surface_create() apply here, too.
 *
 * The timeout value specifies how long the function should wait on other parts
 * of the program to release the buffers. It is necessary, because it can happen
 * that Cairo is just drawing something into the surface while we want to
 * destroy and recreate it.
 *
 * Return value: %CAIRO_STATUS_SUCCESS if the surface could be resized,
 * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface,
 * %CAIRO_STATUS_INVALID_SIZE for invalid sizes
 * %CAIRO_STATUS_NO_MEMORY if the new size could not be allocated, or if the
 * timeout happened before all the buffers were released
 *
 * Since: 1.4
 **/
@surface: the cairo surface to resize
@new_width: the new width of the surface
@new_height: the new height of the surface
@timeout: timeout value in milliseconds

When the client window is resized, call this API to set the new size in the
underlying surface accordingly. This function will reallocate everything,
so you'll have to redraw everything in the surface after this call.
The surface will contain garbage after the resizing. So the notes of
cairo_os2_surface_create() apply here, too.

The timeout value specifies how long the function should wait on other parts
of the program to release the buffers. It is necessary, because it can happen
that Cairo is just drawing something into the surface while we want to
destroy and recreate it.

Return value: %CAIRO_STATUS_SUCCESS if the surface could be resized,
%CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface,
%CAIRO_STATUS_INVALID_SIZE for invalid sizes
%CAIRO_STATUS_NO_MEMORY if the new size could not be allocated, or if the
timeout happened before all the buffers were released


@surface : the cairo surface to resize @new_width : the new width of the surface @new_height : the new height of the surface @timeout : timeout value in milliseconds When the client window is resized call this API to set the new size in the underlying surface accordingly . This function will reallocate everything so you ' ll have to redraw everything in the surface after this call . The surface will contain garbage after the resizing . So the notes of cairo_os2_surface_create () apply here too . The timeout value specifies how long the function should wait on other parts of the program to release the buffers . It is necessary because it can happen that Cairo is just drawing something into the surface while we want to destroy and recreate it . Return value : %CAIRO_STATUS_SUCCESS if the surface could be resized %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS / 2 surface %CAIRO_STATUS_INVALID_SIZE for invalid sizes %CAIRO_STATUS_NO_MEMORY if the new size could not be allocated or if the timeout happened before all the buffers were released
int
cairo_os2_surface_set_size (cairo_surface_t *surface,
                            int              new_width,
                            int              new_height,
                            int              timeout)
{
    cairo_os2_surface_t *local_os2_surface;
    unsigned char *pchNewPixels;
    int rc;
    cairo_image_surface_t *pNewImageSurface;
    local_os2_surface = (cairo_os2_surface_t *) surface;
    if ((!local_os2_surface) ||
        (local_os2_surface->base.backend != &cairo_os2_surface_backend))
    {
        return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
    }
    if ((new_width <= 0) ||
        (new_height <= 0))
    {
        return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
    }
    pchNewPixels = (unsigned char *) _buffer_alloc (new_height, new_width, 4);
    if (!pchNewPixels) {
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }
    pNewImageSurface = (cairo_image_surface_t *)
        cairo_image_surface_create_for_data (pchNewPixels,
                                             CAIRO_FORMAT_ARGB32,
                                             new_width,      
                                             new_height,     
                                             new_width * 4); 
    if (pNewImageSurface->base.status) {
        _buffer_free (pchNewPixels);
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }
    if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)!=NO_ERROR) {
        cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
        _buffer_free (pchNewPixels);
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    }
    while (local_os2_surface->pixel_array_lend_count > 0) {
        ULONG ulPostCount;
        DosResetEventSem (local_os2_surface->hev_pixel_array_came_back, &ulPostCount);
        DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
        rc = DosWaitEventSem (local_os2_surface->hev_pixel_array_came_back, timeout);
        if (rc != NO_ERROR) {
            cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
            _buffer_free (pchNewPixels);
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
        }
        if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)
            != NO_ERROR)
        {
            cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface);
            _buffer_free (pchNewPixels);
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
        }
    }
    cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface));
    _buffer_free (local_os2_surface->pixels);
    local_os2_surface->image_surface = pNewImageSurface;
    local_os2_surface->pixels = pchNewPixels;
    local_os2_surface->bitmap_info.cx = new_width;
    local_os2_surface->bitmap_info.cy = new_height;
    DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
    return CAIRO_STATUS_SUCCESS;
}
int cairo_os2_surface_set_size ( cairo_surface_t * surface , int new_width , int new_height , int timeout ) { cairo_os2_surface_t * local_os2_surface ; unsigned char * pchNewPixels ; int rc ; cairo_image_surface_t * pNewImageSurface ; local_os2_surface = ( cairo_os2_surface_t * ) surface ; if ( ( ! local_os2_surface ) || ( local_os2_surface -> base . backend != & cairo_os2_surface_backend ) ) { return _cairo_error ( CAIRO_STATUS_SURFACE_TYPE_MISMATCH ) ; } if ( ( new_width <= 0 ) || ( new_height <= 0 ) ) { return _cairo_error ( CAIRO_STATUS_INVALID_SIZE ) ; } pchNewPixels = ( unsigned char * ) _buffer_alloc ( new_height , new_width , 4 ) ; if ( ! pchNewPixels ) { return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; } pNewImageSurface = ( cairo_image_surface_t * ) cairo_image_surface_create_for_data ( pchNewPixels , CAIRO_FORMAT_ARGB32 , new_width , new_height , new_width * 4 ) ; if ( pNewImageSurface -> base . status ) { _buffer_free ( pchNewPixels ) ; return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; } if ( DosRequestMutexSem ( local_os2_surface -> hmtx_use_private_fields , SEM_INDEFINITE_WAIT ) != NO_ERROR ) { cairo_surface_destroy ( ( cairo_surface_t * ) pNewImageSurface ) ; _buffer_free ( pchNewPixels ) ; return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; } while ( local_os2_surface -> pixel_array_lend_count > 0 ) { ULONG ulPostCount ; DosResetEventSem ( local_os2_surface -> hev_pixel_array_came_back , & ulPostCount ) ; DosReleaseMutexSem ( local_os2_surface -> hmtx_use_private_fields ) ; rc = DosWaitEventSem ( local_os2_surface -> hev_pixel_array_came_back , timeout ) ; if ( rc != NO_ERROR ) { cairo_surface_destroy ( ( cairo_surface_t * ) pNewImageSurface ) ; _buffer_free ( pchNewPixels ) ; return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; } if ( DosRequestMutexSem ( local_os2_surface -> hmtx_use_private_fields , SEM_INDEFINITE_WAIT ) != NO_ERROR ) { cairo_surface_destroy ( ( cairo_surface_t * ) pNewImageSurface ) ; _buffer_free ( pchNewPixels ) ; return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; } } cairo_surface_destroy ( ( cairo_surface_t * ) ( local_os2_surface -> image_surface ) ) ; _buffer_free ( local_os2_surface -> pixels ) ; local_os2_surface -> image_surface = pNewImageSurface ; local_os2_surface -> pixels = pchNewPixels ; local_os2_surface -> bitmap_info . cx = new_width ; local_os2_surface -> bitmap_info . cy = new_height ; DosReleaseMutexSem ( local_os2_surface -> hmtx_use_private_fields ) ; return CAIRO_STATUS_SUCCESS ; }
cairo_os2_surface_set_size:
 @surface: the cairo surface to resize
 @new_width: the new width of the surface
 @new_height: the new height of the surface
 @timeout: timeout value in milliseconds
cairo_os2_surface_set_size : @surface : the cairo surface to resize @new_width : the new width of the surface @new_height : the new height of the surface @timeout : timeout value in milliseconds
/* Invalid parameter (wrong surface)! */ /* Invalid size! */ /* Allocate memory for new stuffs */ /* Not enough memory for the pixels!
         * Everything remains the same!
         */ /* Create image surface from new pixel array */ /* Width */ /* Height */ /* Rowstride */ /* Could not create image surface!
         * Everything remains the same!
         */ /* Okay, new memory allocated, so it's time to swap old buffers
     * to new ones!
     */ /* Could not get mutex!
         * Everything remains the same!
         */ /* We have to make sure that we won't destroy a surface which
     * is lent to some other code (Cairo is drawing into it)!
     */ /* Wait for somebody to return the pixels! */ /* Either timeout or something wrong... Exit. */ /* Okay, grab mutex and check counter again! */ /* Could not get mutex!
             * Everything remains the same!
             */ /* Destroy old image surface */ /* Destroy old pixel buffer */ /* Set new image surface */ /* Set new pixel buffer */ /* Change bitmap2 structure */