From 3a8ef5bcf825bcdcb0b32d3152170a03bd1099cd Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Fri, 6 Oct 2017 19:55:14 -0700 Subject: [PATCH] remove ImageBitmap from flow types to support Safari and IE (#5424) --- flow-typed/window.js | 1 - src/render/texture.js | 14 ++++++-------- src/source/image_source.js | 8 +++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/flow-typed/window.js b/flow-typed/window.js index 7aff81e21c5..6e92197d592 100644 --- a/flow-typed/window.js +++ b/flow-typed/window.js @@ -119,7 +119,6 @@ declare interface Window extends EventTarget, IDBEnvironment { HTMLCanvasElement: typeof HTMLCanvasElement; Image: typeof Image; ImageData: typeof ImageData; - ImageBitmap: typeof ImageBitmap; URL: typeof URL; webkitURL: typeof URL; URLSearchParams: typeof URLSearchParams; diff --git a/src/render/texture.js b/src/render/texture.js index 9db35a4aec3..390ff14c2c2 100644 --- a/src/render/texture.js +++ b/src/render/texture.js @@ -1,7 +1,9 @@ // @flow -const {RGBAImage, AlphaImage} = require('../util/image'); -const {HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageData, ImageBitmap} = require('../util/window'); +const {HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageData} = require('../util/window'); + +import type {RGBAImage, AlphaImage} from '../util/image'; +import type {ImageTextureSource} from '../source/image_source'; export type TextureFormat = | $PropertyType @@ -18,11 +20,7 @@ export type TextureWrap = export type TextureImage = | RGBAImage | AlphaImage - | HTMLImageElement - | HTMLCanvasElement - | HTMLVideoElement - | ImageData - | ImageBitmap; + | ImageTextureSource; class Texture { gl: WebGLRenderingContext; @@ -55,7 +53,7 @@ class Texture { gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, (true: any)); } - if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || image instanceof ImageBitmap) { + if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData) { gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, gl.UNSIGNED_BYTE, image); } else { gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, image.data); diff --git a/src/source/image_source.js b/src/source/image_source.js index 6adefd36c6a..e2250b0c9ec 100644 --- a/src/source/image_source.js +++ b/src/source/image_source.js @@ -20,6 +20,12 @@ import type Dispatcher from '../util/dispatcher'; import type Tile from './tile'; import type Coordinate from '../geo/coordinate'; +export type ImageTextureSource = + ImageData | + HTMLImageElement | + HTMLCanvasElement | + HTMLVideoElement; + /** * A data source containing an image. * (See the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#sources-image) for detailed documentation of options.) @@ -183,7 +189,7 @@ class ImageSource extends Evented implements Source { this._prepareImage(this.map.painter.gl, this.image); } - _prepareImage(gl: WebGLRenderingContext, image: TexImageSource, resize?: boolean) { + _prepareImage(gl: WebGLRenderingContext, image: ImageTextureSource, resize?: boolean) { if (!this.boundsBuffer) { this.boundsBuffer = new VertexBuffer(gl, this._boundsArray); }