2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
var OS = require('./OS');
|
|
|
|
var Browser = require('./Browser');
|
2017-10-11 16:05:59 +00:00
|
|
|
var CanvasPool = require('../display/canvas/CanvasPool');
|
2016-11-26 01:28:53 +00:00
|
|
|
|
2018-01-25 17:03:35 +00:00
|
|
|
/**
|
|
|
|
* Determines the 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.features` from within any Scene.
|
|
|
|
*
|
2018-03-28 14:04:09 +00:00
|
|
|
* @typedef {object} Phaser.Device.Features
|
2018-01-25 17:03:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.
|
|
|
|
* @property {boolean} canvas - Is canvas available?
|
|
|
|
* @property {boolean} file - Is file available?
|
|
|
|
* @property {boolean} fileSystem - Is fileSystem available?
|
|
|
|
* @property {boolean} getUserMedia - Does the device support the getUserMedia API?
|
|
|
|
* @property {boolean} littleEndian - Is the device big or little endian? (only detected if the browser supports TypedArrays)
|
|
|
|
* @property {boolean} localStorage - Is localStorage available?
|
|
|
|
* @property {boolean} pointerLock - Is Pointer Lock available?
|
|
|
|
* @property {boolean} support32bit - Does the device context support 32bit pixel manipulation using array buffer views?
|
|
|
|
* @property {boolean} vibration - Does the device support the Vibration API?
|
|
|
|
* @property {boolean} webGL - Is webGL available?
|
|
|
|
* @property {boolean} worker - Is worker available?
|
|
|
|
*/
|
2016-11-25 04:00:15 +00:00
|
|
|
var Features = {
|
|
|
|
|
|
|
|
canvas: false,
|
|
|
|
canvasBitBltShift: null,
|
|
|
|
file: false,
|
|
|
|
fileSystem: false,
|
2018-01-25 17:03:35 +00:00
|
|
|
getUserMedia: true,
|
|
|
|
littleEndian: false,
|
2016-11-25 04:00:15 +00:00
|
|
|
localStorage: false,
|
|
|
|
pointerLock: false,
|
2018-01-25 17:03:35 +00:00
|
|
|
support32bit: false,
|
2016-11-25 04:00:15 +00:00
|
|
|
vibration: false,
|
2018-01-25 17:03:35 +00:00
|
|
|
webGL: false,
|
|
|
|
worker: false
|
2016-11-25 04:00:15 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-01 12:10:08 +00:00
|
|
|
// Check Little or Big Endian system.
|
|
|
|
// @author Matt DesLauriers (@mattdesl)
|
2016-11-25 04:33:48 +00:00
|
|
|
function checkIsLittleEndian ()
|
|
|
|
{
|
|
|
|
var a = new ArrayBuffer(4);
|
|
|
|
var b = new Uint8Array(a);
|
|
|
|
var c = new Uint32Array(a);
|
|
|
|
|
|
|
|
b[0] = 0xa1;
|
|
|
|
b[1] = 0xb2;
|
|
|
|
b[2] = 0xc3;
|
|
|
|
b[3] = 0xd4;
|
|
|
|
|
|
|
|
if (c[0] === 0xd4c3b2a1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c[0] === 0xa1b2c3d4)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Could not determine endianness
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
function init ()
|
2016-11-25 04:00:15 +00:00
|
|
|
{
|
2019-02-15 10:38:57 +00:00
|
|
|
Features.canvas = !!window['CanvasRenderingContext2D'];
|
2016-11-25 04:00:15 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Features.localStorage = !!localStorage.getItem;
|
|
|
|
}
|
|
|
|
catch (error)
|
|
|
|
{
|
|
|
|
Features.localStorage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Features.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
|
|
|
|
Features.fileSystem = !!window['requestFileSystem'];
|
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
var isUint8 = false;
|
|
|
|
|
2016-11-25 04:00:15 +00:00
|
|
|
var testWebGL = function ()
|
|
|
|
{
|
|
|
|
if (window['WebGLRenderingContext'])
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
var canvas = CanvasPool.createWebGL(this);
|
2016-11-25 04:00:15 +00:00
|
|
|
|
|
|
|
var ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
var canvas2D = CanvasPool.create2D(this);
|
2016-11-25 04:33:48 +00:00
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
var ctx2D = canvas2D.getContext('2d');
|
|
|
|
|
|
|
|
// Can't be done on a webgl context
|
|
|
|
var image = ctx2D.createImageData(1, 1);
|
2018-01-15 10:29:38 +00:00
|
|
|
|
2018-02-22 01:07:30 +00:00
|
|
|
// Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray.
|
|
|
|
// @author Matt DesLauriers (@mattdesl)
|
2016-11-25 04:33:48 +00:00
|
|
|
isUint8 = image.data instanceof Uint8ClampedArray;
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
CanvasPool.remove(canvas);
|
|
|
|
CanvasPool.remove(canvas2D);
|
2016-11-26 01:28:53 +00:00
|
|
|
|
2018-01-15 11:05:11 +00:00
|
|
|
return !!ctx;
|
2016-11-25 04:00:15 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 10:29:38 +00:00
|
|
|
|
2016-11-25 04:00:15 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2018-01-15 10:29:38 +00:00
|
|
|
Features.webGL = testWebGL();
|
2016-11-25 04:00:15 +00:00
|
|
|
|
|
|
|
Features.worker = !!window['Worker'];
|
|
|
|
|
|
|
|
Features.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
|
|
|
|
|
|
|
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
|
|
|
|
|
|
|
|
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
|
|
|
|
|
|
Features.getUserMedia = Features.getUserMedia && !!navigator.getUserMedia && !!window.URL;
|
|
|
|
|
|
|
|
// Older versions of firefox (< 21) apparently claim support but user media does not actually work
|
|
|
|
if (Browser.firefox && Browser.firefoxVersion < 21)
|
|
|
|
{
|
|
|
|
Features.getUserMedia = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it
|
|
|
|
// is safer to not try and use the fast copy-over method.
|
|
|
|
if (!OS.iOS && (Browser.ie || Browser.firefox || Browser.chrome))
|
|
|
|
{
|
|
|
|
Features.canvasBitBltShift = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Known not to work
|
|
|
|
if (Browser.safari || Browser.mobileSafari)
|
|
|
|
{
|
|
|
|
Features.canvasBitBltShift = false;
|
|
|
|
}
|
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
|
|
|
|
|
|
|
|
if (navigator.vibrate)
|
|
|
|
{
|
|
|
|
Features.vibration = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined')
|
|
|
|
{
|
|
|
|
Features.littleEndian = checkIsLittleEndian();
|
|
|
|
}
|
|
|
|
|
|
|
|
Features.support32bit = (
|
|
|
|
typeof ArrayBuffer !== 'undefined' &&
|
|
|
|
typeof Uint8ClampedArray !== 'undefined' &&
|
|
|
|
typeof Int32Array !== 'undefined' &&
|
|
|
|
Features.littleEndian !== null &&
|
|
|
|
isUint8
|
|
|
|
);
|
|
|
|
|
2016-11-25 04:00:15 +00:00
|
|
|
return Features;
|
|
|
|
}
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
module.exports = init();
|