diff --git a/src/Image.cc b/src/Image.cc index ca21095..35206b8 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -198,10 +198,26 @@ EIO_AfterLoad(eio_req *req) { void Image::load() { if (LOADING != state) { - Ref(); + // TODO: use node IO + // Ref(); state = LOADING; - eio_custom(EIO_Load, EIO_PRI_DEFAULT, EIO_AfterLoad, this); - ev_ref(EV_DEFAULT_UC); + loadSync(); + // eio_custom(EIO_Load, EIO_PRI_DEFAULT, EIO_AfterLoad, this); + // ev_ref(EV_DEFAULT_UC); + } +} + +/* + * Load image synchronously. + */ + +void +Image::loadSync() { + cairo_status_t status = loadSurface(); + if (status) { + error(Canvas::Error(status)); + } else { + loaded(); } } diff --git a/src/Image.h b/src/Image.h index 654a467..d35ed58 100644 --- a/src/Image.h +++ b/src/Image.h @@ -34,6 +34,7 @@ class Image: public node::ObjectWrap { inline int stride(){ return cairo_image_surface_get_stride(_surface); } cairo_status_t loadSurface(); void error(Local); + void loadSync(); void loaded(); void load(); Image();