Skip to content

Integrate TilePaletteMapper and TileGrid further #10318

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

FoamyGuy
Copy link
Collaborator

@FoamyGuy FoamyGuy commented May 7, 2025

This makes the following functional changes:

  • TilePaletteMapper now has tilegrid as an argument instead of width, and height
  • TileGrid now allows pixel_shader argument to be None or omitted. But _add_layer() now validates that it it isn't None before it can be added to a Group to be shown on the display.
  • TileGrid is refactored to have a displayio_tilegrid_mark_tile_dirty() function that gets called by set_tile
  • TilePaletteMapper makes use of the new displayio_tilegrid_mark_tile_dirty() to mark individual tiles as dirty when the mapping for that tile is updated, rather than causing the whole TileGrid to be refreshed
  • TilePaletteMapper no longer has needs_refresh or finish_refresh concepts

I have tested the updated TPM functionality with the Matrix CircuitPython code (updated to use the new API), and with the text editor that I am working on for Fruit Jam OS, it uses TPM to highlight the bottom bar with hotkeys in it. All functionality appears to work as expected.

I have not specifically tested / validated the smaller dirty area refresh by ensuring that it speeds up refresh rate when single mappings are updated. That will confirm that it isn't updating the full TileGrid any longer, I will do that once I get the cursor changed to use TPM in the text editor.

I noticed that this change is showing some edits to the .pot file that I did not knowingly make. I ran pre-commit locally and it seems to have made some of those changes even though they appear unrelated to TileGrid or TilePaletteMapper. I'm not sure if that is a git or update / merge issue or something else. Let me know if I need to do anything further in that file though.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

I understand there is a circularity to this that needs to be broken. I'd do it the other way so TG always has a pixel_shader. Allow TPM to be constructed without allocating the mapping memory and "bind" the two when the TG is created. This can also check that multiple TG aren't given the TPM. (Or it could track multiple TG to mark dirty.)

@@ -21,33 +22,38 @@
//| bitmap with a wider array of colors."""
//|
//| def __init__(
//| self, palette: displayio.Palette, input_color_count: int, width: int, height: int
//| self, palette: displayio.Palette, input_color_count: int, tilegrid: displayio.TileGrid
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes more sense to reverse this and make TPM not take width, height or tilegrid. That way you could create the TPM and pass it to a TG. The TG can then init it. That makes it fit better within the pixel_shader model I think.

Comment on lines +261 to +263
if (tilegrid->pixel_shader == mp_const_none) {
mp_raise_ValueError(MP_ERROR_TEXT("TileGrid must have a pixel_shader"));
}
Copy link
Member

Choose a reason for hiding this comment

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

We wouldn't need this if TPM could be constructed without a TG.

@tannewt
Copy link
Member

tannewt commented May 8, 2025

I noticed that this change is showing some edits to the .pot file that I did not knowingly make. I ran pre-commit locally and it seems to have made some of those changes even though they appear unrelated to TileGrid or TilePaletteMapper. I'm not sure if that is a git or update / merge issue or something else. Let me know if I need to do anything further in that file though.

It looks fine to me. I'm not sure why Weblate didn't do it but it seems to be active. Updating these here is fine.

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

Successfully merging this pull request may close these issues.

2 participants