-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
There was a problem hiding this 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.
src/source/image_source.js
Outdated
@@ -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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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 🙊
src/source/canvas_source.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
Ok, I took a different approach (inlining |
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: