Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
cairo-quartz-surface.c File Reference
#include "cairoint.h"
#include "cairo-private.h"
#include "cairo-quartz.h"

Go to the source code of this file.

Classes

struct  cairo_quartz_surface

Typedefs

typedef struct cairo_quartz_surface cairo_quartz_surface_t

Functions

static void ImageDataReleaseFunc (void *info, const void *data, size_t size)
static cairo_status_t _cairo_quartz_surface_finish (void *abstract_surface)
static cairo_status_t _cairo_quartz_surface_acquire_source_image (void *abstract_surface, cairo_image_surface_t **image_out, void **image_extra)
static cairo_status_t _cairo_quartz_surface_acquire_dest_image (void *abstract_surface, cairo_rectangle_t *interest_rect, cairo_image_surface_t **image_out, cairo_rectangle_t *image_rect, void **image_extra)
static void _cairo_quartz_surface_release_dest_image (void *abstract_surface, cairo_rectangle_t *intersect_rect, cairo_image_surface_t *image, cairo_rectangle_t *image_rect, void *image_extra)
static cairo_int_status_t _cairo_quartz_surface_set_clip_region (void *abstract_surface, pixman_region16_t *region)
static cairo_int_status_t _cairo_quartz_surface_get_extents (void *abstract_surface, cairo_rectangle_t *rectangle)
cairo_surface_t * cairo_quartz_surface_create (CGContextRef context, int width, int height)

Variables

static struct _cairo_surface_backend

Class Documentation

struct cairo_quartz_surface

Definition at line 40 of file cairo-quartz-surface.c.

Collaboration diagram for cairo_quartz_surface:
Class Members
cairo_surface_t base
CGImageRef cgImage
CGContextRef context
int height
cairo_image_surface_t * image
int width

Typedef Documentation


Function Documentation

static cairo_status_t _cairo_quartz_surface_acquire_dest_image ( void abstract_surface,
cairo_rectangle_t interest_rect,
cairo_image_surface_t **  image_out,
cairo_rectangle_t image_rect,
void **  image_extra 
) [static]

Definition at line 141 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;

    image_rect->x = 0;
    image_rect->y = 0;
    image_rect->width = surface->image->width;
    image_rect->height = surface->image->height;

    *image_out = surface->image;
    if (image_extra)
       *image_extra = NULL;

    return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t _cairo_quartz_surface_acquire_source_image ( void abstract_surface,
cairo_image_surface_t **  image_out,
void **  image_extra 
) [static]

Definition at line 76 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;
    CGColorSpaceRef colorSpace;
    void *imageData;
    UInt32 imageDataSize, rowBytes;
    CGDataProviderRef dataProvider;

    // We keep a cached (cairo_image_surface_t *) in the cairo_quartz_surface_t
    // struct. If the window is ever drawn to without going through Cairo, then
    // we would need to refetch the pixel data from the window into the cached
    // image surface. 
    if (surface->image) {
        cairo_surface_reference(&surface->image->base);

       *image_out = surface->image;
       return CAIRO_STATUS_SUCCESS;
    }

    colorSpace = CGColorSpaceCreateDeviceRGB();


    rowBytes = surface->width * 4;
    imageDataSize = rowBytes * surface->height;
    imageData = malloc(imageDataSize);

    dataProvider =
        CGDataProviderCreateWithData(NULL, imageData, imageDataSize,
                                     ImageDataReleaseFunc);

    surface->cgImage = CGImageCreate(surface->width,
                                     surface->height,
                                     8,
                                     32,
                                     rowBytes,
                                     colorSpace,
                                     kCGImageAlphaPremultipliedFirst |
                                      kCGBitmapByteOrder32Host,
                                     dataProvider,
                                     NULL,
                                     false, kCGRenderingIntentDefault);

    CGColorSpaceRelease(colorSpace);
    CGDataProviderRelease(dataProvider);

    surface->image = (cairo_image_surface_t *)
        cairo_image_surface_create_for_data(imageData,
                                            CAIRO_FORMAT_ARGB32,
                                            surface->width,
                                            surface->height, rowBytes);
    if (surface->image->base.status) {
       if (surface->cgImage)
           CGImageRelease(surface->cgImage);
       return CAIRO_STATUS_NO_MEMORY;
    }

    *image_out = surface->image;
    *image_extra = NULL;

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cairo_quartz_surface_finish ( void abstract_surface) [static]

Definition at line 62 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;

    if (surface->image)
        cairo_surface_destroy(&surface->image->base);

    if (surface->cgImage)
        CGImageRelease(surface->cgImage);

    return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t _cairo_quartz_surface_get_extents ( void abstract_surface,
cairo_rectangle_t rectangle 
) [static]

Definition at line 197 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;

    rectangle->x = 0;
    rectangle->y = 0;
    rectangle->width = surface->width;
    rectangle->height = surface->height;

    return CAIRO_STATUS_SUCCESS;
}
static void _cairo_quartz_surface_release_dest_image ( void abstract_surface,
cairo_rectangle_t intersect_rect,
cairo_image_surface_t *  image,
cairo_rectangle_t image_rect,
void image_extra 
) [static]

Definition at line 164 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;

    if (surface->image == image) {
        CGRect rect;

        rect = CGRectMake(0, 0, surface->width, surface->height);

        CGContextDrawImage(surface->context, rect, surface->cgImage);

       memset(surface->image->data, 0, surface->width * surface->height * 4);
    }
}

Here is the call graph for this function:

static cairo_int_status_t _cairo_quartz_surface_set_clip_region ( void abstract_surface,
pixman_region16_t *  region 
) [static]

Definition at line 185 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface = abstract_surface;
    unsigned int serial;

    serial = _cairo_surface_allocate_clip_serial (&surface->image->base);
    return _cairo_surface_set_clip_region(&surface->image->base,
                                     region, serial);
}

Here is the call graph for this function:

cairo_surface_t* cairo_quartz_surface_create ( CGContextRef  context,
int  width,
int  height 
)

Definition at line 230 of file cairo-quartz-surface.c.

{
    cairo_quartz_surface_t *surface;

    surface = malloc(sizeof(cairo_quartz_surface_t));
    if (surface == NULL) {
       _cairo_error (CAIRO_STATUS_NO_MEMORY);
        return (cairo_surface_t*) &_cairo_surface_nil;
    }

    _cairo_surface_init(&surface->base, &cairo_quartz_surface_backend);

    surface->context = context;
    surface->width = width;
    surface->height = height;
    surface->image = NULL;
    surface->cgImage = NULL;

    // Set up the image surface which Cairo draws into and we blit to & from.
    void *foo;
    _cairo_quartz_surface_acquire_source_image(surface, &surface->image, &foo);

    return (cairo_surface_t *) surface;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ImageDataReleaseFunc ( void info,
const void data,
size_t  size 
) [static]

Definition at line 54 of file cairo-quartz-surface.c.

{
    if (data != NULL) {
        free((void *) data);
    }
}

Here is the caller graph for this function:


Variable Documentation

struct _cairo_surface_backend [static]