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 (filename) free(filename);
} }
#if 0
/* /*
* Load callback. * Load callback.
*/ */
static int int
EIO_Load(eio_req *req) { Image::EIO_load(eio_req *req) {
Image *img = (Image *) req->data; Image *img = (Image *) req->data;
req->result = img->loadSurface(); req->result = img->loadSurface();
return 0; return 0;
@ -184,8 +182,8 @@ EIO_Load(eio_req *req) {
* After load callback. * After load callback.
*/ */
static int int
EIO_AfterLoad(eio_req *req) { Image::EIO_afterLoad(eio_req *req) {
HandleScope scope; HandleScope scope;
Image *img = (Image *) req->data; Image *img = (Image *) req->data;
@ -195,12 +193,11 @@ EIO_AfterLoad(eio_req *req) {
img->loaded(); img->loaded();
} }
img->Unref();
ev_unref(EV_DEFAULT_UC); ev_unref(EV_DEFAULT_UC);
return 0; return 0;
} }
#endif
/* /*
* Initiate image loading. * Initiate image loading.
*/ */
@ -208,12 +205,10 @@ EIO_AfterLoad(eio_req *req) {
void void
Image::load() { Image::load() {
if (LOADING != state) { if (LOADING != state) {
// TODO: use node IO Ref();
// Ref();
state = LOADING; state = LOADING;
loadSync(); eio_custom(EIO_load, EIO_PRI_DEFAULT, EIO_afterLoad, this);
// eio_custom(EIO_Load, EIO_PRI_DEFAULT, EIO_AfterLoad, this); ev_ref(EV_DEFAULT_UC);
// 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 cairo_surface_t *surface(){ return _surface; }
inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); } inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); }
inline int stride(){ return cairo_image_surface_get_stride(_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 loadSurface();
cairo_status_t loadPNG(); cairo_status_t loadPNG();
#ifdef HAVE_JPEG #ifdef HAVE_JPEG

Loading…
Cancel
Save