mirror of
https://github.com/photonstorm/phaser
synced 2025-01-09 03:38:50 +00:00
140 lines
3.4 KiB
JavaScript
140 lines
3.4 KiB
JavaScript
|
var Features = {
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} canvas - Is canvas available?
|
||
|
* @default
|
||
|
*/
|
||
|
canvas: false,
|
||
|
|
||
|
/**
|
||
|
* @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.
|
||
|
* @default
|
||
|
*/
|
||
|
canvasBitBltShift: null,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} webGL - Is webGL available?
|
||
|
* @default
|
||
|
*/
|
||
|
webGL: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} file - Is file available?
|
||
|
* @default
|
||
|
*/
|
||
|
file: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} fileSystem - Is fileSystem available?
|
||
|
* @default
|
||
|
*/
|
||
|
fileSystem: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} localStorage - Is localStorage available?
|
||
|
* @default
|
||
|
*/
|
||
|
localStorage: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} worker - Is worker available?
|
||
|
* @default
|
||
|
*/
|
||
|
worker: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} pointerLock - Is Pointer Lock available?
|
||
|
* @default
|
||
|
*/
|
||
|
pointerLock: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} vibration - Does the device support the Vibration API?
|
||
|
* @default
|
||
|
*/
|
||
|
vibration: false,
|
||
|
|
||
|
/**
|
||
|
* @property {boolean} getUserMedia - Does the device support the getUserMedia API?
|
||
|
* @default
|
||
|
*/
|
||
|
getUserMedia: true
|
||
|
|
||
|
};
|
||
|
|
||
|
function init (OS, Browser)
|
||
|
{
|
||
|
Features.canvas = !!window['CanvasRenderingContext2D'] || OS.cocoonJS;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
Features.localStorage = !!localStorage.getItem;
|
||
|
}
|
||
|
catch (error)
|
||
|
{
|
||
|
Features.localStorage = false;
|
||
|
}
|
||
|
|
||
|
Features.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
|
||
|
Features.fileSystem = !!window['requestFileSystem'];
|
||
|
|
||
|
var testWebGL = function ()
|
||
|
{
|
||
|
if (window['WebGLRenderingContext'])
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var canvas = document.createElement('canvas');
|
||
|
|
||
|
// cocoon ...
|
||
|
canvas.screencanvas = false;
|
||
|
|
||
|
var ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
||
|
|
||
|
return (ctx !== null);
|
||
|
}
|
||
|
catch (e)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
Features.webGL = testWebGL();
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
return Features;
|
||
|
}
|
||
|
|
||
|
module.exports = init;
|