Skip to content

Commit

Permalink
Async image loading again
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 19, 2010
1 parent 9422ef0 commit 9b12da2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -195,25 +193,22 @@ EIO_AfterLoad(eio_req *req) {
img->loaded();
}

img->Unref();
ev_unref(EV_DEFAULT_UC);
return 0;
}

#endif

/*
* Initiate image loading.
*/

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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b12da2

Please sign in to comment.