Browse Source

Async image loading again

v1.x
Tj Holowaychuk 14 years ago
parent
commit
9b12da2599
  1. 21
      src/Image.cc
  2. 2
      src/Image.h

21
src/Image.cc

@ -167,14 +167,12 @@ Image::~Image() {
if (filename) free(filename);
}
#if 0
/*
* Load callback.
*/
static int
EIO_Load(eio_req *req) {
int
Image::EIO_load(eio_req *req) {
Image *img = (Image *) req->data;
req->result = img->loadSurface();
return 0;
@ -184,8 +182,8 @@ EIO_Load(eio_req *req) {
* After load callback.
*/
static int
EIO_AfterLoad(eio_req *req) {
int
Image::EIO_afterLoad(eio_req *req) {
HandleScope scope;
Image *img = (Image *) req->data;
@ -195,12 +193,11 @@ EIO_AfterLoad(eio_req *req) {
img->loaded();
}
img->Unref();
ev_unref(EV_DEFAULT_UC);
return 0;
}
#endif
/*
* Initiate image loading.
*/
@ -208,12 +205,10 @@ EIO_AfterLoad(eio_req *req) {
void
Image::load() {
if (LOADING != state) {
// TODO: use node IO
// Ref();
Ref();
state = LOADING;
loadSync();
// eio_custom(EIO_Load, EIO_PRI_DEFAULT, EIO_AfterLoad, this);
// ev_ref(EV_DEFAULT_UC);
eio_custom(EIO_load, EIO_PRI_DEFAULT, EIO_afterLoad, this);
ev_ref(EV_DEFAULT_UC);
}
}

2
src/Image.h

@ -31,6 +31,8 @@ class Image: public node::ObjectWrap {
inline cairo_surface_t *surface(){ return _surface; }
inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); }
inline int stride(){ return cairo_image_surface_get_stride(_surface); }
static int EIO_load(eio_req *req);
static int EIO_afterLoad(eio_req *req);
cairo_status_t loadSurface();
cairo_status_t loadPNG();
#ifdef HAVE_JPEG

Loading…
Cancel
Save