Skip to content

Commit

Permalink
Capture browser GL mocking in the window module
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Sep 2, 2016
1 parent 83d9609 commit 6cbd5d0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
8 changes: 5 additions & 3 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var browser = require('../util/browser');
var window = require('../util/window');
var Evented = require('../util/evented');
var DOM = require('../util/dom');
var webGLContext = require('../util/webgl_context');

var Style = require('../style/style');
var AnimationLoop = require('../style/animation_loop');
Expand Down Expand Up @@ -952,10 +951,13 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
},

_setupPainter: function() {
var gl = webGLContext(this._canvas, util.extend({
var attributes = util.extend({
failIfMajorPerformanceCaveat: this._failIfMajorPerformanceCaveat,
preserveDrawingBuffer: this._preserveDrawingBuffer
}, isSupported.webGLContextAttributes));
}, isSupported.webGLContextAttributes);

var gl = this._canvas.getContext('webgl', attributes) ||
this._canvas.getContext('experimental-webgl', attributes);

if (!gl) {
this.fire('error', { error: new Error('Failed to initialize WebGL') });
Expand Down
6 changes: 0 additions & 6 deletions js/util/browser/webgl_context.js

This file was deleted.

10 changes: 0 additions & 10 deletions js/util/webgl_context.js

This file was deleted.

8 changes: 8 additions & 0 deletions js/util/window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var jsdom = require('jsdom');
var gl = require('gl');

var window = jsdom.jsdom().defaultView;

Expand All @@ -9,4 +10,11 @@ window.cancelAnimationFrame = clearImmediate;

window.devicePixelRatio = 1;

window.HTMLCanvasElement.prototype.getContext = function(type, attributes) {
if (!this._webGLContext) {
this._webGLContext = gl(this.width, this.height, attributes);
}
return this._webGLContext;
};

module.exports = window;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"browser": {
"./js/util/ajax.js": "./js/util/browser/ajax.js",
"./js/util/window.js": "./js/util/browser/window.js",
"./js/util/webgl_context.js": "./js/util/browser/webgl_context.js",
"./js/util/web_worker.js": "./js/util/browser/web_worker.js"
},
"scripts": {
Expand Down

0 comments on commit 6cbd5d0

Please sign in to comment.