From 6fcdb86e1c7ca29420b6bc3ffb3e0abc9b696703 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 21 Feb 2011 03:17:09 +0100 Subject: [PATCH] Implement CanvasProvider that provides reusable canvas elements. --- src/util/CanvasProvider.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/util/CanvasProvider.js diff --git a/src/util/CanvasProvider.js b/src/util/CanvasProvider.js new file mode 100644 index 00000000..bcced6d7 --- /dev/null +++ b/src/util/CanvasProvider.js @@ -0,0 +1,16 @@ +CanvasProvider = { + canvases: [], + getCanvas: function(width, height) { + var canvas = this.canvases.length + ? this.canvases.pop() + : document.createElement('canvas'); + var cleared; + canvas.width = width; + canvas.height = height; + return canvas; + }, + + returnCanvas: function(canvas) { + this.canvases.push(canvas); + } +};