third_party/cairo/src/cairo-os2-surface.c
cairo_surface_t *
cairo_os2_surface_create (HPS hps_client_window,
                          int width,
                          int height)
{
    cairo_os2_surface_t *local_os2_surface = 0;
    cairo_status_t status;
    int rc;

    /* Check the size of the window */
    if ((width <= 0) || (height <= 0)) {
        status = _cairo_error (CAIRO_STATUS_INVALID_SIZE);
        goto error_exit;
    }

    /* Allocate an OS/2 surface structure. */
    local_os2_surface = (cairo_os2_surface_t *) _cairo_malloc (sizeof (cairo_os2_surface_t));
    if (!local_os2_surface) {
        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
        goto error_exit;
    }

    memset(local_os2_surface, 0, sizeof(cairo_os2_surface_t));

    /* Allocate resources:  mutex & event semaphores and the pixel buffer */
    if (DosCreateMutexSem (NULL,
                           &(local_os2_surface->hmtx_use_private_fields),
                           0,
                           FALSE))
    {
        status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
        goto error_exit;
    }

    if (DosCreateEventSem (NULL,
                           &(local_os2_surface->hev_pixel_array_came_back),
                           0,
                           FALSE))
    {
        status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
        goto error_exit;
    }

    local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4);
    if (!local_os2_surface->pixels) {
        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
        goto error_exit;
    }

    /* Create image surface from pixel array */
    local_os2_surface->image_surface = (cairo_image_surface_t *)
        cairo_image_surface_create_for_data (local_os2_surface->pixels,
                                             CAIRO_FORMAT_ARGB32,
                                             width,      /* Width */
                                             height,     /* Height */
                                             width * 4); /* Rowstride */
    status = local_os2_surface->image_surface->base.status;
    if (status)
        goto error_exit;

    /* Set values for OS/2-specific data that aren't zero/NULL/FALSE.
     * Note: hps_client_window may be null if this was called by
     * cairo_os2_surface_create_for_window().
     */
    local_os2_surface->hps_client_window = hps_client_window;
    local_os2_surface->blit_as_changes = TRUE;

    /* Prepare BITMAPINFO2 structure for our buffer */
    local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2);
    local_os2_surface->bitmap_info.cx = width;
    local_os2_surface->bitmap_info.cy = height;
    local_os2_surface->bitmap_info.cPlanes = 1;
    local_os2_surface->bitmap_info.cBitCount = 32;

    /* Initialize base surface */
    _cairo_surface_init (&local_os2_surface->base,
                         &cairo_os2_surface_backend,
                         NULL, /* device */
                         _cairo_content_from_format (CAIRO_FORMAT_ARGB32),
			 FALSE); /* is_vector */

    /* Successful exit */
    return (cairo_surface_t *)local_os2_surface;

 error_exit:

    /* This point will only be reached if an error occurred */

    if (local_os2_surface) {
        if (local_os2_surface->pixels)
            _buffer_free (local_os2_surface->pixels);
        if (local_os2_surface->hev_pixel_array_came_back)
            DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back);
        if (local_os2_surface->hmtx_use_private_fields)
            DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields);
        free (local_os2_surface);
    }

    return _cairo_surface_create_in_error (status);
}
/**
 * cairo_os2_surface_create:
 * @hps_client_window: the presentation handle to bind the surface to
 * @width: the width of the surface
 * @height: the height of the surface
 *
 * Create a Cairo surface which is bound to a given presentation space (HPS).
 * The caller retains ownership of the HPS and must dispose of it after the
 * the surface has been destroyed.  The surface will be created to have the
 * given size. By default every change to the surface will be made visible
 * immediately by blitting it into the window. This can be changed with
 * cairo_os2_surface_set_manual_window_refresh().
 * Note that the surface will contain garbage when created, so the pixels
 * have to be initialized by hand first. You can use the Cairo functions to
 * fill it with black, or use cairo_surface_mark_dirty() to fill the surface
 * with pixels from the window/HPS.
 *
 * Return value: the newly created surface
 *
 * Since: 1.4
 **/
@hps_client_window: the presentation handle to bind the surface to
@width: the width of the surface
@height: the height of the surface

Create a Cairo surface which is bound to a given presentation space (HPS).
The caller retains ownership of the HPS and must dispose of it after the
the surface has been destroyed.  The surface will be created to have the
given size. By default every change to the surface will be made visible
immediately by blitting it into the window. This can be changed with
cairo_os2_surface_set_manual_window_refresh().
Note that the surface will contain garbage when created, so the pixels
have to be initialized by hand first. You can use the Cairo functions to
fill it with black, or use cairo_surface_mark_dirty() to fill the surface
with pixels from the window/HPS.

Return value: the newly created surface


@hps_client_window : the presentation handle to bind the surface to @width : the width of the surface @height : the height of the surface Create a Cairo surface which is bound to a given presentation space ( HPS ) . The caller retains ownership of the HPS and must dispose of it after the the surface has been destroyed . The surface will be created to have the given size . By default every change to the surface will be made visible immediately by blitting it into the window . This can be changed with cairo_os2_surface_set_manual_window_refresh () . Note that the surface will contain garbage when created so the pixels have to be initialized by hand first . You can use the Cairo functions to fill it with black or use cairo_surface_mark_dirty () to fill the surface with pixels from the window / HPS . Return value : the newly created surface
cairo_surface_t *
cairo_os2_surface_create (HPS hps_client_window,
                          int width,
                          int height)
{
    cairo_os2_surface_t *local_os2_surface = 0;
    cairo_status_t status;
    int rc;
    if ((width <= 0) || (height <= 0)) {
        status = _cairo_error (CAIRO_STATUS_INVALID_SIZE);
        goto error_exit;
    }
    local_os2_surface = (cairo_os2_surface_t *) _cairo_malloc (sizeof (cairo_os2_surface_t));
    if (!local_os2_surface) {
        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
        goto error_exit;
    }
    memset(local_os2_surface, 0, sizeof(cairo_os2_surface_t));
    if (DosCreateMutexSem (NULL,
                           &(local_os2_surface->hmtx_use_private_fields),
                           0,
                           FALSE))
    {
        status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
        goto error_exit;
    }
    if (DosCreateEventSem (NULL,
                           &(local_os2_surface->hev_pixel_array_came_back),
                           0,
                           FALSE))
    {
        status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
        goto error_exit;
    }
    local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4);
    if (!local_os2_surface->pixels) {
        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
        goto error_exit;
    }
    local_os2_surface->image_surface = (cairo_image_surface_t *)
        cairo_image_surface_create_for_data (local_os2_surface->pixels,
                                             CAIRO_FORMAT_ARGB32,
                                             width,      
                                             height,     
                                             width * 4); 
    status = local_os2_surface->image_surface->base.status;
    if (status)
        goto error_exit;
    local_os2_surface->hps_client_window = hps_client_window;
    local_os2_surface->blit_as_changes = TRUE;
    local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2);
    local_os2_surface->bitmap_info.cx = width;
    local_os2_surface->bitmap_info.cy = height;
    local_os2_surface->bitmap_info.cPlanes = 1;
    local_os2_surface->bitmap_info.cBitCount = 32;
    _cairo_surface_init (&local_os2_surface->base,
                         &cairo_os2_surface_backend,
                         NULL, 
                         _cairo_content_from_format (CAIRO_FORMAT_ARGB32),
			 FALSE); 
    return (cairo_surface_t *)local_os2_surface;
 error_exit:
    if (local_os2_surface) {
        if (local_os2_surface->pixels)
            _buffer_free (local_os2_surface->pixels);
        if (local_os2_surface->hev_pixel_array_came_back)
            DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back);
        if (local_os2_surface->hmtx_use_private_fields)
            DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields);
        free (local_os2_surface);
    }
    return _cairo_surface_create_in_error (status);
}
cairo_surface_t * cairo_os2_surface_create ( HPS hps_client_window , int width , int height ) { cairo_os2_surface_t * local_os2_surface = 0 ; cairo_status_t status ; int rc ; if ( ( width <= 0 ) || ( height <= 0 ) ) { status = _cairo_error ( CAIRO_STATUS_INVALID_SIZE ) ; goto error_exit ; } local_os2_surface = ( cairo_os2_surface_t * ) _cairo_malloc ( sizeof ( cairo_os2_surface_t ) ) ; if ( ! local_os2_surface ) { status = _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; goto error_exit ; } memset ( local_os2_surface , 0 , sizeof ( cairo_os2_surface_t ) ) ; if ( DosCreateMutexSem ( NULL , & ( local_os2_surface -> hmtx_use_private_fields ) , 0 , FALSE ) ) { status = _cairo_error ( CAIRO_STATUS_DEVICE_ERROR ) ; goto error_exit ; } if ( DosCreateEventSem ( NULL , & ( local_os2_surface -> hev_pixel_array_came_back ) , 0 , FALSE ) ) { status = _cairo_error ( CAIRO_STATUS_DEVICE_ERROR ) ; goto error_exit ; } local_os2_surface -> pixels = ( unsigned char * ) _buffer_alloc ( height , width , 4 ) ; if ( ! local_os2_surface -> pixels ) { status = _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; goto error_exit ; } local_os2_surface -> image_surface = ( cairo_image_surface_t * ) cairo_image_surface_create_for_data ( local_os2_surface -> pixels , CAIRO_FORMAT_ARGB32 , width , height , width * 4 ) ; status = local_os2_surface -> image_surface -> base . status ; if ( status ) goto error_exit ; local_os2_surface -> hps_client_window = hps_client_window ; local_os2_surface -> blit_as_changes = TRUE ; local_os2_surface -> bitmap_info . cbFix = sizeof ( BITMAPINFOHEADER2 ) ; local_os2_surface -> bitmap_info . cx = width ; local_os2_surface -> bitmap_info . cy = height ; local_os2_surface -> bitmap_info . cPlanes = 1 ; local_os2_surface -> bitmap_info . cBitCount = 32 ; _cairo_surface_init ( & local_os2_surface -> base , & cairo_os2_surface_backend , NULL , _cairo_content_from_format ( CAIRO_FORMAT_ARGB32 ) , FALSE ) ; return ( cairo_surface_t * ) local_os2_surface ; error_exit : if ( local_os2_surface ) { if ( local_os2_surface -> pixels ) _buffer_free ( local_os2_surface -> pixels ) ; if ( local_os2_surface -> hev_pixel_array_came_back ) DosCloseEventSem ( local_os2_surface -> hev_pixel_array_came_back ) ; if ( local_os2_surface -> hmtx_use_private_fields ) DosCloseMutexSem ( local_os2_surface -> hmtx_use_private_fields ) ; free ( local_os2_surface ) ; } return _cairo_surface_create_in_error ( status ) ; }
cairo_os2_surface_create:
 @hps_client_window: the presentation handle to bind the surface to
 @width: the width of the surface
 @height: the height of the surface
cairo_os2_surface_create : @hps_client_window : the presentation handle to bind the surface to @width : the width of the surface @height : the height of the surface
/* Check the size of the window */ /* Allocate an OS/2 surface structure. */ /* Allocate resources:  mutex & event semaphores and the pixel buffer */ /* Create image surface from pixel array */ /* Width */ /* Height */ /* Rowstride */ /* Set values for OS/2-specific data that aren't zero/NULL/FALSE.
     * Note: hps_client_window may be null if this was called by
     * cairo_os2_surface_create_for_window().
     */ /* Prepare BITMAPINFO2 structure for our buffer */ /* Initialize base surface */ /* device */ /* is_vector */ /* Successful exit */ /* This point will only be reached if an error occurred */