Merging in the CanvasPool changes to the core.

This commit is contained in:
photonstorm 2015-08-03 14:46:55 +01:00
parent 50516e3d34
commit e901fb80f6
7 changed files with 49 additions and 10 deletions

View file

@ -673,11 +673,11 @@ Phaser.Game.prototype = {
if (this.config['canvasID']) if (this.config['canvasID'])
{ {
this.canvas = Phaser.Canvas.create(this.width, this.height, this.config['canvasID']); this.canvas = Phaser.Canvas.create(this, this.width, this.height, this.config['canvasID']);
} }
else else
{ {
this.canvas = Phaser.Canvas.create(this.width, this.height); this.canvas = Phaser.Canvas.create(this, this.width, this.height);
} }
if (this.config['canvasStyle']) if (this.config['canvasStyle'])

View file

@ -45,7 +45,8 @@ Phaser.BitmapData = function (game, key, width, height) {
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws. * @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
* @default * @default
*/ */
this.canvas = Phaser.Canvas.create(width, height, '', true); // this.canvas = Phaser.Canvas.create(width, height, '', true);
this.canvas = PIXI.CanvasPool.create(this, width, height);
/** /**
* @property {CanvasRenderingContext2D} context - The 2d context of the canvas. * @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
@ -213,7 +214,7 @@ Phaser.BitmapData = function (game, key, width, height) {
* @property {HTMLCanvasElement} _swapCanvas - A swap canvas. * @property {HTMLCanvasElement} _swapCanvas - A swap canvas.
* @private * @private
*/ */
this._swapCanvas = Phaser.Canvas.create(width, height, '', true); this._swapCanvas = PIXI.CanvasPool.create(this, width, height);
}; };
@ -1680,6 +1681,17 @@ Phaser.BitmapData.prototype = {
}, },
/**
* Destroys this BitmapData and puts the canvas it was using back into the canvas pool for re-use.
*
* @method Phaser.BitmapData#destroy
*/
destroy: function () {
PIXI.CanvasPool.remove(this);
},
/** /**
* Resets the blend mode (effectively sets it to 'source-over') * Resets the blend mode (effectively sets it to 'source-over')
* *

View file

@ -135,6 +135,8 @@ Phaser.Component.Destroy.prototype = {
this._currentBounds = null; this._currentBounds = null;
this._mask = null; this._mask = null;
this._destroyCachedSprite(); this._destroyCachedSprite();
this.destroyPhase = false; this.destroyPhase = false;

View file

@ -53,7 +53,8 @@ PIXI.CanvasPool = {
{ {
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
canvas.clearRect(0, 0, width, height); // var context = canvas.getContext('2d');
// context.clearRect(0, 0, width, height);
} }
return canvas; return canvas;

View file

@ -26,7 +26,7 @@ Phaser.Canvas = {
width = width || 256; width = width || 256;
height = height || 256; height = height || 256;
var canvas = document.createElement('canvas'); var canvas = PIXI.CanvasPool.create(this, width, height);
if (typeof id === 'string' && id !== '') if (typeof id === 'string' && id !== '')
{ {

View file

@ -56,7 +56,7 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
* @property {HTMLCanvasElement} canvas * @property {HTMLCanvasElement} canvas
* @protected * @protected
*/ */
this.canvas = Phaser.Canvas.create(width, height); this.canvas = PIXI.CanvasPool.create(this, width, height);
/** /**
* The 2d context of the canvas. * The 2d context of the canvas.
@ -255,6 +255,7 @@ Phaser.TilemapLayer.sharedCopyCanvas = null;
* *
* Code that uses the canvas is responsible to ensure the dimensions and save/restore state as appropriate. * Code that uses the canvas is responsible to ensure the dimensions and save/restore state as appropriate.
* *
* @method Phaser.TilemapLayer#ensureSharedCopyCanvas
* @protected * @protected
* @static * @static
*/ */
@ -272,8 +273,7 @@ Phaser.TilemapLayer.ensureSharedCopyCanvas = function () {
/** /**
* Automatically called by World.preUpdate. * Automatically called by World.preUpdate.
* *
* @method Phaser.Image#preUpdate * @method Phaser.TilemapLayer#preUpdate
* @memberof Phaser.Image
*/ */
Phaser.TilemapLayer.prototype.preUpdate = function() { Phaser.TilemapLayer.prototype.preUpdate = function() {
@ -301,6 +301,19 @@ Phaser.TilemapLayer.prototype.postUpdate = function () {
}; };
/**
* Destroys this TilemapLayer.
*
* @method Phaser.TilemapLayer#destroy
*/
Phaser.TilemapLayer.prototype.destroy = function() {
PIXI.CanvasPool.remove(this);
Phaser.Component.Destroy.prototype.destroy.call(this);
};
/** /**
* Resizes the internal canvas and texture frame used by this TilemapLayer. * Resizes the internal canvas and texture frame used by this TilemapLayer.
* *

View file

@ -108,7 +108,7 @@ Phaser.Utils.Debug.prototype = {
this.sprite = this.game.make.image(0, 0, this.bmd); this.sprite = this.game.make.image(0, 0, this.bmd);
this.game.stage.addChild(this.sprite); this.game.stage.addChild(this.sprite);
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, '', true); this.canvas = PIXI.CanvasPool.create(this, this.game.width, this.game.height);
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
} }
@ -812,6 +812,17 @@ Phaser.Utils.Debug.prototype = {
Phaser.Physics.Box2D.renderBody(this.context, body, color); Phaser.Physics.Box2D.renderBody(this.context, body, color);
this.stop(); this.stop();
},
/**
* Destroy this object.
*
* @method Phaser.Utils.Debug#destroy
*/
destroy: function () {
PIXI.CanvasPool.remove(this);
} }
}; };