Skip to content

Commit

Permalink
remove ImageBitmap from flow types to support Safari and IE (#5424)
Browse files Browse the repository at this point in the history
  • Loading branch information
mollymerp authored Oct 7, 2017
1 parent de6399f commit 3a8ef5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion flow-typed/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/render/texture.js
Original file line number Diff line number Diff line change
@@ -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<WebGLRenderingContext, 'RGBA'>
Expand All @@ -18,11 +20,7 @@ export type TextureWrap =
export type TextureImage =
| RGBAImage
| AlphaImage
| HTMLImageElement
| HTMLCanvasElement
| HTMLVideoElement
| ImageData
| ImageBitmap;
| ImageTextureSource;

class Texture {
gl: WebGLRenderingContext;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/source/image_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 3a8ef5b

Please sign in to comment.