Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image source performance regression #5845

Merged
merged 3 commits into from
Dec 14, 2017
Merged

Fix image source performance regression #5845

merged 3 commits into from
Dec 14, 2017

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Dec 12, 2017

Fixes #5752. Static image sources were getting the image texture uploaded on every frame. It's unclear to me why the instanceof window.ImageData condition was included in _prepareImage -- gl.texSubImage2D should be needed only for video and animated canvas sources. Does anyone know?

I manually tested:

  • canvas.html debug page
  • "Add an image" example
  • "Add a video" example
  • "Animate a series of images" example

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have context on why window.ImageData was added in there, but these changes look good to me! Thanks for tracking this down.

@@ -207,7 +201,7 @@ class ImageSource extends Evented implements Source {
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
} else if (resize) {
this.texture.update(image);
} else if (image instanceof window.HTMLVideoElement || image instanceof window.ImageData || image instanceof window.HTMLCanvasElement) {
} else if (image instanceof window.HTMLVideoElement || image instanceof window.HTMLCanvasElement) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per your comment, should we also check if animate: true for CanvasSource in this conditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added a fix for that as well.

Copy link
Contributor

@lbud lbud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added window.ImageData at one point when we were copying canvas data into an intermediary image buffer to mitigate a GPU-specific bug, and I would assume I incorrectly guessed that the static image case was covered by HTMLImageElement types 🙊

@@ -135,6 +135,8 @@ class CanvasSource extends ImageSource {

if (Object.keys(this.tiles).length === 0) return; // not enough data for current position

if (!this._playing && this.texture) return; // Already prepared the static image
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, actually, this is wrong -- _prepareImage needs to be called if the coordinates have changed, to re-initialize boundsBuffer.

Static image sources were getting the image texture uploaded on every frame, as were paused canvas and video sources.
@jfirebaugh
Copy link
Contributor Author

Ok, I took a different approach (inlining _prepareImage), and it should now work correctly for paused canvas and video sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants