Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 550011e25ec3fc221c99b3ba5f55f8a751bc80f1 1 parent b63c7db
@phipla phipla authored tj committed
Showing with 41 additions and 5 deletions.
  1. +5 −0 .travis.yml
  2. +1 −1  package.json
  3. +29 −4 src/Canvas.cc
  4. +6 −0 src/Canvas.h
View
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
View
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"
}
View
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 {
View
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); }
Please sign in to comment.
Something went wrong with that request. Please try again.