Skip to content

Commit f400247

Browse files
committed
Updated context lost / restored handlers
1 parent 7d1f818 commit f400247

6 files changed

Lines changed: 36 additions & 90 deletions

File tree

src/display/mask/BitmapMask.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Class = require('../../utils/Class');
8+
var GameEvents = require('../../core/events');
89

910
/**
1011
* @classdesc
@@ -159,7 +160,7 @@ var BitmapMask = new Class({
159160
this.mainFramebuffer = renderer.createFramebuffer(width, height, this.mainTexture, true);
160161
this.maskFramebuffer = renderer.createFramebuffer(width, height, this.maskTexture, true);
161162

162-
renderer.onContextRestored(function (renderer)
163+
scene.sys.game.events.on(GameEvents.CONTEXT_RESTORED, function (renderer)
163164
{
164165
var width = renderer.width;
165166
var height = renderer.height;

src/gameobjects/text/static/Text.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var AddToDOM = require('../../../dom/AddToDOM');
88
var CanvasPool = require('../../../display/canvas/CanvasPool');
99
var Class = require('../../../utils/Class');
1010
var Components = require('../../components');
11-
var CONST = require('../../../const');
11+
var GameEvents = require('../../../core/events');
1212
var GameObject = require('../../GameObject');
1313
var GetTextSize = require('../GetTextSize');
1414
var GetValue = require('../../../utils/object/GetValue');
@@ -288,13 +288,10 @@ var Text = new Class({
288288
this.lineSpacing = style.lineSpacing;
289289
}
290290

291-
if (scene.sys.game.config.renderType === CONST.WEBGL)
291+
scene.sys.game.events.on(GameEvents.CONTEXT_RESTORED, function ()
292292
{
293-
scene.sys.game.renderer.onContextRestored(function ()
294-
{
295-
this.dirty = true;
296-
}, this);
297-
}
293+
this.dirty = true;
294+
}, this);
298295
},
299296

300297
/**

src/gameobjects/tilesprite/TileSprite.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
var CanvasPool = require('../../display/canvas/CanvasPool');
88
var Class = require('../../utils/Class');
99
var Components = require('../components');
10-
var CONST = require('../../const');
10+
var GameEvents = require('../../core/events');
1111
var GameObject = require('../GameObject');
1212
var GetPowerOfTwo = require('../../math/pow2/GetPowerOfTwo');
1313
var Smoothing = require('../../display/canvas/Smoothing');
@@ -275,17 +275,15 @@ var TileSprite = new Class({
275275
this.setOriginFromFrame();
276276
this.initPipeline();
277277

278-
if (scene.sys.game.config.renderType === CONST.WEBGL)
278+
scene.sys.game.events.on(GameEvents.CONTEXT_RESTORED, function (renderer)
279279
{
280-
scene.sys.game.renderer.onContextRestored(function (renderer)
281-
{
282-
var gl = renderer.gl;
283-
284-
this.dirty = true;
285-
this.fillPattern = null;
286-
this.fillPattern = renderer.createTexture2D(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.fillCanvas, this.potWidth, this.potHeight);
287-
}, this);
288-
}
280+
var gl = renderer.gl;
281+
282+
this.dirty = true;
283+
this.fillPattern = null;
284+
this.fillPattern = renderer.createTexture2D(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.fillCanvas, this.potWidth, this.potHeight);
285+
286+
}, this);
289287
},
290288

291289
/**

src/renderer/canvas/CanvasRenderer.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,6 @@ var CanvasRenderer = new Class({
277277
}
278278
},
279279

280-
/**
281-
* A NOOP method for handling lost context. Intentionally empty.
282-
*
283-
* @method Phaser.Renderer.Canvas.CanvasRenderer#onContextLost
284-
* @since 3.0.0
285-
*
286-
* @param {function} callback - Ignored parameter.
287-
*/
288-
onContextLost: function ()
289-
{
290-
},
291-
292-
/**
293-
* A NOOP method for handling restored context. Intentionally empty.
294-
*
295-
* @method Phaser.Renderer.Canvas.CanvasRenderer#onContextRestored
296-
* @since 3.0.0
297-
*
298-
* @param {function} callback - Ignored parameter.
299-
*/
300-
onContextRestored: function ()
301-
{
302-
},
303-
304280
/**
305281
* Resets the transformation matrix of the current context to the identity matrix, thus resetting any transformation.
306282
*

src/renderer/webgl/WebGLRenderer.js

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,25 @@ var WebGLRenderer = new Class({
305305
*/
306306
this.scissorStack = [];
307307

308+
/**
309+
* The handler to invoke when the context is lost.
310+
* This should not be changed and is set in the boot method.
311+
*
312+
* @name Phaser.Renderer.WebGL.WebGLRenderer#contextLostHandler
313+
* @type {function}
314+
* @since 3.19.0
315+
*/
308316
this.contextLostHandler = NOOP;
309-
this.contextRestoredHandler = NOOP;
310317

311-
// These are initialized post context creation
318+
/**
319+
* The handler to invoke when the context is restored.
320+
* This should not be changed and is set in the boot method.
321+
*
322+
* @name Phaser.Renderer.WebGL.WebGLRenderer#contextRestoredHandler
323+
* @type {function}
324+
* @since 3.19.0
325+
*/
326+
this.contextRestoredHandler = NOOP;
312327

313328
/**
314329
* The underlying WebGL context of the renderer.
@@ -552,8 +567,6 @@ var WebGLRenderer = new Class({
552567

553568
this.contextLostHandler = function (event)
554569
{
555-
console.log('ctx lost handler');
556-
557570
_this.contextLost = true;
558571

559572
_this.game.events.emit(GameEvents.CONTEXT_LOST, _this);
@@ -771,42 +784,6 @@ var WebGLRenderer = new Class({
771784
return this;
772785
},
773786

774-
/**
775-
* Adds a callback to be invoked when the WebGL context has been restored by the browser.
776-
*
777-
* @method Phaser.Renderer.WebGL.WebGLRenderer#onContextRestored
778-
* @since 3.0.0
779-
*
780-
* @param {WebGLContextCallback} callback - The callback to be invoked on context restoration.
781-
* @param {object} target - The context of the callback.
782-
*
783-
* @return {this} This WebGLRenderer instance.
784-
*/
785-
onContextRestored: function (callback, target)
786-
{
787-
this.restoredContextCallbacks.push([ callback, target ]);
788-
789-
return this;
790-
},
791-
792-
/**
793-
* Adds a callback to be invoked when the WebGL context has been lost by the browser.
794-
*
795-
* @method Phaser.Renderer.WebGL.WebGLRenderer#onContextLost
796-
* @since 3.0.0
797-
*
798-
* @param {WebGLContextCallback} callback - The callback to be invoked on context loss.
799-
* @param {object} target - The context of the callback.
800-
*
801-
* @return {this} This WebGLRenderer instance.
802-
*/
803-
onContextLost: function (callback, target)
804-
{
805-
this.lostContextCallbacks.push([ callback, target ]);
806-
807-
return this;
808-
},
809-
810787
/**
811788
* Checks if a WebGL extension is supported
812789
*

src/tilemaps/staticlayer/StaticTilemapLayer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var Class = require('../../utils/Class');
88
var Components = require('../../gameobjects/components');
9-
var CONST = require('../../const');
9+
var GameEvents = require('../../core/events');
1010
var GameObject = require('../../gameobjects/GameObject');
1111
var StaticTilemapLayerRender = require('./StaticTilemapLayerRender');
1212
var TilemapComponents = require('../components');
@@ -359,13 +359,10 @@ var StaticTilemapLayer = new Class({
359359

360360
this.initPipeline('TextureTintPipeline');
361361

362-
if (scene.sys.game.config.renderType === CONST.WEBGL)
362+
scene.sys.game.events.on(GameEvents.CONTEXT_RESTORED, function ()
363363
{
364-
scene.sys.game.renderer.onContextRestored(function ()
365-
{
366-
this.updateVBOData();
367-
}, this);
368-
}
364+
this.updateVBOData();
365+
}, this);
369366
},
370367

371368
/**

0 commit comments

Comments
 (0)