2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-11 16:05:59 +00:00
|
|
|
var CanvasPool = require('../display/canvas/CanvasPool');
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2018-01-25 17:03:35 +00:00
|
|
|
/**
|
|
|
|
* Determines the canvas features of the browser running this Phaser Game instance.
|
|
|
|
* These values are read-only and populated during the boot sequence of the game.
|
|
|
|
* They are then referenced by internal game systems and are available for you to access
|
|
|
|
* via `this.sys.game.device.canvasFeatures` from within any Scene.
|
2021-01-19 09:40:59 +00:00
|
|
|
*
|
2018-03-28 14:04:09 +00:00
|
|
|
* @typedef {object} Phaser.Device.CanvasFeatures
|
2018-01-25 17:03:35 +00:00
|
|
|
* @since 3.0.0
|
2021-01-19 09:40:59 +00:00
|
|
|
*
|
2018-01-25 17:03:35 +00:00
|
|
|
* @property {boolean} supportInverseAlpha - Set to true if the browser supports inversed alpha.
|
|
|
|
* @property {boolean} supportNewBlendModes - Set to true if the browser supports new canvas blend modes.
|
|
|
|
*/
|
2017-01-18 14:09:26 +00:00
|
|
|
var CanvasFeatures = {
|
|
|
|
|
2018-01-25 17:03:35 +00:00
|
|
|
supportInverseAlpha: false,
|
|
|
|
supportNewBlendModes: false
|
2017-01-18 14:09:26 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
function checkBlendMode ()
|
|
|
|
{
|
|
|
|
var pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/';
|
|
|
|
var pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
|
|
|
|
|
|
|
|
var magenta = new Image();
|
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
magenta.onload = function ()
|
|
|
|
{
|
|
|
|
var yellow = new Image();
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
yellow.onload = function ()
|
|
|
|
{
|
2022-08-18 17:01:28 +00:00
|
|
|
var canvas = CanvasPool.create2D(yellow, 6);
|
|
|
|
var context = canvas.getContext('2d', { willReadFrequently: true });
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
context.globalCompositeOperation = 'multiply';
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
context.drawImage(magenta, 0, 0);
|
|
|
|
context.drawImage(yellow, 2, 0);
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
if (!context.getImageData(2, 0, 1, 1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
var data = context.getImageData(2, 0, 1, 1).data;
|
|
|
|
|
|
|
|
CanvasPool.remove(yellow);
|
|
|
|
|
|
|
|
CanvasFeatures.supportNewBlendModes = (data[0] === 255 && data[1] === 0 && data[2] === 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
yellow.src = pngHead + '/wCKxvRF' + pngEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
magenta.src = pngHead + 'AP804Oa6' + pngEnd;
|
2017-01-18 14:09:26 +00:00
|
|
|
|
2017-08-02 16:43:01 +00:00
|
|
|
return false;
|
2017-01-18 14:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkInverseAlpha ()
|
|
|
|
{
|
2022-08-18 17:01:28 +00:00
|
|
|
var canvas = CanvasPool.create2D(this, 2);
|
|
|
|
var context = canvas.getContext('2d', { willReadFrequently: true });
|
2017-01-18 14:09:26 +00:00
|
|
|
|
|
|
|
context.fillStyle = 'rgba(10, 20, 30, 0.5)';
|
|
|
|
|
|
|
|
// Draw a single pixel
|
|
|
|
context.fillRect(0, 0, 1, 1);
|
|
|
|
|
|
|
|
// Get the color values
|
|
|
|
var s1 = context.getImageData(0, 0, 1, 1);
|
|
|
|
|
|
|
|
if (s1 === null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plot them to x2
|
|
|
|
context.putImageData(s1, 1, 0);
|
|
|
|
|
|
|
|
// Get those values
|
|
|
|
var s2 = context.getImageData(1, 0, 1, 1);
|
|
|
|
|
2022-08-18 17:01:28 +00:00
|
|
|
var result = (s2.data[0] === s1.data[0] && s2.data[1] === s1.data[1] && s2.data[2] === s1.data[2] && s2.data[3] === s1.data[3]);
|
|
|
|
|
|
|
|
CanvasPool.remove(this);
|
|
|
|
|
2017-01-18 14:09:26 +00:00
|
|
|
// Compare and return
|
2022-08-18 17:01:28 +00:00
|
|
|
return result;
|
2017-01-18 14:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function init ()
|
|
|
|
{
|
2021-01-19 09:40:59 +00:00
|
|
|
if (typeof importScripts !== 'function' && document !== undefined)
|
2017-01-18 14:09:26 +00:00
|
|
|
{
|
|
|
|
CanvasFeatures.supportNewBlendModes = checkBlendMode();
|
|
|
|
CanvasFeatures.supportInverseAlpha = checkInverseAlpha();
|
|
|
|
}
|
|
|
|
|
|
|
|
return CanvasFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = init();
|