/* The only way to create a context is from a surface. To express the dependency of the context on the surface (and avoid the context to be in bad shape if the surface is garbage collected -- thus destroyed by the finalizer), the ref count of the surface will be increased. This however requires that the context finalizer decreases it. FIXME: a context can also be created from a GdkDrawable object whose ref count needs to be handled too. */ static void caml_cairo_cairo_finalize(value v) { cairo_surface_t *surface = cairo_get_target(CAIRO_VAL(v)); /* fprintf(stderr, "DESTROY cairo\n"); fflush(stderr); */ cairo_destroy(CAIRO_VAL(v)); cairo_surface_destroy(surface); }
CAMLexport value caml_gdk_cairo_create(value vdrawable) { CAMLparam1(vdrawable); CAMLlocal1(vcontext); cairo_t *cr = gdk_cairo_create(GdkDrawable_val(vdrawable)); caml_cairo_raise_Error(cairo_status(cr)); /* caml_check_status not exported */ vcontext = alloc_custom(&caml_cairo_ops, sizeof(void*), 1, 50); CAIRO_VAL(vcontext) = cr; CAMLreturn(vcontext); }