|
|
@ -139,20 +139,24 @@ toBuffer(void *c, const uint8_t *data, unsigned len) { |
|
|
|
/*
|
|
|
|
* EIO toBuffer callback. |
|
|
|
*/ |
|
|
|
|
|
|
|
#if NODE_VERSION_AT_LEAST(0, 5, 4) |
|
|
|
|
|
|
|
#if NODE_VERSION_AT_LEAST(0, 6, 0) |
|
|
|
void |
|
|
|
Canvas::ToBufferAsync(uv_work_t *req) { |
|
|
|
#elif NODE_VERSION_AT_LEAST(0, 5, 4) |
|
|
|
void |
|
|
|
Canvas::EIO_ToBuffer(eio_req *req) { |
|
|
|
#else |
|
|
|
int |
|
|
|
#endif |
|
|
|
Canvas::EIO_ToBuffer(eio_req *req) { |
|
|
|
#endif |
|
|
|
closure_t *closure = (closure_t *) req->data; |
|
|
|
|
|
|
|
closure->status = cairo_surface_write_to_png_stream( |
|
|
|
closure->canvas->surface() |
|
|
|
, toBuffer |
|
|
|
, closure); |
|
|
|
|
|
|
|
|
|
|
|
#if !NODE_VERSION_AT_LEAST(0, 5, 4) |
|
|
|
return 0; |
|
|
|
#endif |
|
|
@ -162,11 +166,21 @@ Canvas::EIO_ToBuffer(eio_req *req) { |
|
|
|
* EIO after toBuffer callback. |
|
|
|
*/ |
|
|
|
|
|
|
|
#if NODE_VERSION_AT_LEAST(0, 6, 0) |
|
|
|
void |
|
|
|
Canvas::ToBufferAsyncAfter(uv_work_t *req) { |
|
|
|
#else |
|
|
|
int |
|
|
|
Canvas::EIO_AfterToBuffer(eio_req *req) { |
|
|
|
#endif |
|
|
|
|
|
|
|
HandleScope scope; |
|
|
|
closure_t *closure = (closure_t *) req->data; |
|
|
|
#if NODE_VERSION_AT_LEAST(0, 6, 0) |
|
|
|
delete req; |
|
|
|
#else |
|
|
|
ev_unref(EV_DEFAULT_UC); |
|
|
|
#endif |
|
|
|
|
|
|
|
if (closure->status) { |
|
|
|
Local<Value> argv[1] = { Canvas::Error(closure->status) }; |
|
|
@ -182,7 +196,10 @@ Canvas::EIO_AfterToBuffer(eio_req *req) { |
|
|
|
closure->pfn.Dispose(); |
|
|
|
closure_destroy(closure); |
|
|
|
free(closure); |
|
|
|
|
|
|
|
#if !NODE_VERSION_AT_LEAST(0, 6, 0) |
|
|
|
return 0; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -211,8 +228,16 @@ Canvas::ToBuffer(const Arguments &args) { |
|
|
|
// TODO: only one callback fn in closure
|
|
|
|
canvas->Ref(); |
|
|
|
closure->pfn = Persistent<Function>::New(Handle<Function>::Cast(args[0])); |
|
|
|
|
|
|
|
#if NODE_VERSION_AT_LEAST(0, 6, 0) |
|
|
|
uv_work_t* req = new uv_work_t; |
|
|
|
req->data = closure; |
|
|
|
uv_queue_work(uv_default_loop(), req, ToBufferAsync, ToBufferAsyncAfter); |
|
|
|
#else |
|
|
|
eio_custom(EIO_ToBuffer, EIO_PRI_DEFAULT, EIO_AfterToBuffer, closure); |
|
|
|
ev_ref(EV_DEFAULT_UC); |
|
|
|
#endif |
|
|
|
|
|
|
|
return Undefined(); |
|
|
|
// Sync
|
|
|
|
} else { |
|
|
|