|
@ -107,31 +107,21 @@ Canvas::SetHeight(Local<String> prop, Local<Value> val, const AccessorInfo &info |
|
|
|
|
|
|
|
|
static cairo_status_t |
|
|
static cairo_status_t |
|
|
toBuffer(void *c, const uint8_t *data, unsigned len) { |
|
|
toBuffer(void *c, const uint8_t *data, unsigned len) { |
|
|
closure_t *closure = (closure_t *) c; |
|
|
closure_t *closure = (closure_t *) c; |
|
|
|
|
|
|
|
|
// Olaf (2011-02-21): Store more data, but don't call realloc() on every chunk.
|
|
|
if (closure->len) { |
|
|
// Also, keep track of how much memory is used
|
|
|
closure->data = (uint8_t *) realloc(closure->data, closure->len + len); |
|
|
if (closure->len + len > closure->max_len) { |
|
|
if (!closure->data) return CAIRO_STATUS_NO_MEMORY; |
|
|
uint8_t * new_data; |
|
|
memcpy(closure->data + closure->len, data, len); |
|
|
unsigned new_max_len = closure->max_len; |
|
|
closure->len += len; |
|
|
|
|
|
} else { |
|
|
// Round up the buffer size to be a multiple of 1024 bytes.
|
|
|
closure->data = (uint8_t *) malloc(len); |
|
|
new_max_len = (closure->max_len + len + 1023) & ~1023; |
|
|
if (!closure->data) return CAIRO_STATUS_NO_MEMORY; |
|
|
|
|
|
memcpy(closure->data, data, len); |
|
|
new_data = (uint8_t *) realloc(closure->data, new_max_len); |
|
|
closure->len += len; |
|
|
if (new_data == NULL) return CAIRO_STATUS_NO_MEMORY; |
|
|
} |
|
|
|
|
|
|
|
|
// Keep track of how much more memory we just allocated.
|
|
|
return CAIRO_STATUS_SUCCESS; |
|
|
V8::AdjustAmountOfExternalAllocatedMemory(new_max_len - closure->max_len); |
|
|
|
|
|
|
|
|
|
|
|
closure->data = new_data; |
|
|
|
|
|
closure->max_len = new_max_len; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy(closure->data + closure->len, data, len); |
|
|
|
|
|
closure->len += len; |
|
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|