Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Support blitting in webagg backend#19059
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -118,7 +118,7 @@ def _handle_key(key): | ||
class FigureCanvasWebAggCore(backend_agg.FigureCanvasAgg): | ||
supports_blit =True | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
@@ -153,6 +153,10 @@ def draw(self): | ||
finally: | ||
self.manager.refresh_all() # Swap the frames. | ||
def blit(self, bbox=None): | ||
self._png_is_old = True | ||
self.manager.refresh_all() | ||
Comment on lines +156 to +158 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I copied this from#4290 so I assume it was done correctly by@tacaswell, but I find it odd that this accepts a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. That's to match the super class; it should blit only the section in the bbox if it's not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. makes sense. Should a docstring be added explaining something to that effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think I see how to implement more selective blitting for the ipympl frontend, but would/can the backend Agg renderer also needing blitting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The other consideration is that if any part of the image is transparent it will be forced to be a full image. That could also be optimized a bit with frontend blitting. Discussed far in the past here:#5419 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm sure it could be possible, but would require sending a different message probably. Doesn't have to be done in this PR though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Indeed I'm happy with this PR as is. Better blitting seems like a good 2021 goal. | ||
def draw_idle(self): | ||
self.send_event("draw") | ||
@@ -189,18 +193,14 @@ def get_diff_image(self): | ||
output = buff | ||
else: | ||
self.set_image_mode('diff') | ||
diff = buff != self._last_buff | ||
output = np.where(diff, buff, 0) | ||
buf = BytesIO() | ||
| ||
data = output.view(dtype=np.uint8).reshape((*output.shape, 4)) | ||
Image.fromarray(data).save(buf, format="png") | ||
# store the current buffer so we can compute the next diff | ||
np.copyto(self._last_buff, buff) | ||
self._force_full = False | ||
self._png_is_old = False | ||
return buf.getvalue() | ||
@@ -220,9 +220,10 @@ def get_renderer(self, cleared=None): | ||
if need_new_renderer: | ||
self._renderer = backend_agg.RendererAgg( | ||
w, h, self.figure.dpi) | ||
self._lastKey = key | ||
self._last_buff = np.copy(np.frombuffer( | ||
self._renderer.buffer_rgba(), dtype=np.uint32 | ||
).reshape((self._renderer.height, self._renderer.width))) | ||
elif cleared: | ||
self._renderer.clear() | ||
Uh oh!
There was an error while loading.Please reload this page.