@@ -6,14 +6,6 @@ ImageBackend::ImageBackend(int width, int height)
66 : Backend(" image" , width, height)
77 {}
88
9- ImageBackend::~ImageBackend ()
10- {
11- if (surface) {
12- destroySurface ();
13- Nan::AdjustExternalMemory (-approxBytesPerPixel () * width * height);
14- }
15- }
16-
179Backend *ImageBackend::construct (int width, int height){
1810 return new ImageBackend (width, height);
1911}
@@ -39,27 +31,20 @@ int32_t ImageBackend::approxBytesPerPixel() {
3931 }
4032}
4133
42- cairo_surface_t * ImageBackend::createSurface ()
43- {
44- assert (!this ->surface );
45- this ->surface = cairo_image_surface_create (this ->format , width, height);
46- assert (this ->surface );
34+ cairo_surface_t * ImageBackend::createSurface () {
35+ assert (!surface);
36+ surface = cairo_image_surface_create (format, width, height);
37+ assert (surface);
4738 Nan::AdjustExternalMemory (approxBytesPerPixel () * width * height);
48-
49- return this ->surface ;
39+ return surface;
5040}
5141
52- cairo_surface_t * ImageBackend::recreateSurface ()
53- {
54- // Re-surface
55- if (this ->surface ) {
56- int old_width = cairo_image_surface_get_width (this ->surface );
57- int old_height = cairo_image_surface_get_height (this ->surface );
58- this ->destroySurface ();
59- Nan::AdjustExternalMemory (-approxBytesPerPixel () * old_width * old_height);
60- }
61-
62- return createSurface ();
42+ void ImageBackend::destroySurface () {
43+ if (surface) {
44+ cairo_surface_destroy (surface);
45+ surface = nullptr ;
46+ Nan::AdjustExternalMemory (-approxBytesPerPixel () * width * height);
47+ }
6348}
6449
6550cairo_format_t ImageBackend::getFormat () {
@@ -72,8 +57,7 @@ void ImageBackend::setFormat(cairo_format_t _format) {
7257
7358Nan::Persistent<FunctionTemplate> ImageBackend::constructor;
7459
75- void ImageBackend::Initialize (Handle<Object> target)
76- {
60+ void ImageBackend::Initialize (Handle<Object> target) {
7761 Nan::HandleScope scope;
7862
7963 Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(ImageBackend::New);
0 commit comments