Browse Source

Use libuv instead of EIO so that it builds on node.js >= 0.7.0

v1.x
Philippe Plantier 13 years ago
committed by TJ Holowaychuk
parent
commit
550011e25e
  1. 5
      .travis.yml
  2. 2
      package.json
  3. 33
      src/Canvas.cc
  4. 6
      src/Canvas.h

5
.travis.yml

@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.4
- 0.6
- 0.7 # development version of 0.8, may be unstable

2
package.json

@ -14,6 +14,6 @@
, "mocha": "*"
, "should": "*"
}
, "engines": { "node": ">= 0.4.0 && < 0.7.0" }
, "engines": { "node": ">= 0.4.0 && < 0.9.0" }
, "main": "./lib/canvas.js"
}

33
src/Canvas.cc

@ -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 {

6
src/Canvas.h

@ -45,6 +45,10 @@ class Canvas: public node::ObjectWrap {
static Handle<Value> StreamPNGSync(const Arguments &args);
static Handle<Value> StreamJPEGSync(const Arguments &args);
static Local<Value> Error(cairo_status_t status);
#if NODE_VERSION_AT_LEAST(0, 6, 0)
static void ToBufferAsync(uv_work_t *req);
static void ToBufferAsyncAfter(uv_work_t *req);
#else
static
#if NODE_VERSION_AT_LEAST(0, 5, 4)
void
@ -53,6 +57,8 @@ class Canvas: public node::ObjectWrap {
#endif
EIO_ToBuffer(eio_req *req);
static int EIO_AfterToBuffer(eio_req *req);
#endif
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); }

Loading…
Cancel
Save