Skip to content

Conversation

@ledvinap
Copy link
Contributor

@ledvinap ledvinap commented Nov 1, 2022

(For discussion)

  • Refactor python bindings a bit, fixing various problems leading to SEGFAULT
  • class passed to SwapOnVSync is returned on second call unmodified
  • FrameCanvas is recycled when python object is freed

Add support for FrameCanvas::Serialize:

  • Python class with Buffer Protocol is returned
  • It can be easily used to write to file etc. (and no copy is necessary)
  • Now read-only, but read-write should be safe and it will allow zero-copy writing to framebuffer
    • another option is to export Deserialize, possibly with Buffer Protocol interface, but performance will be slightly smaller

Solves problem when installing package directly from git (pipenv install
-e )
- Except NULL for cdefs (slightly optimizes performance)
- Handle reading NULLs from Options (caused segfault)
- Improve handling of parameters for char* options
  - accepts string-like objects, returns bytes()
- Use cython magic for __options
- Handle None as NULL in SwapOnVSync (allows wait for sync usage)
- Use C++ Canvas object to handle common operations
- Use @Property decorator syntax
- prevent creation of uninitialized objects from Python code (__new__)
- prevent cython classes without corresponding C++ class (raise
   exception on all paths that can cause it)
- Trace displayed FrameCanvas in SwapOnVSync
  - class passed to SwapOnVSync is returned on second call
- Recycle FrameCanvas when python object is freed
- FrameCanvas class keeps RGBMatrix alive (RGBMatrix is not deleted
   before FrameCanvas)
Export Serialize using Python Buffer Protocol

Currently only read-only view is supported
```
green = Color(0, 255, 0)
rgbmatrix.Fill(*green())
generated using:
python3 -m cython -3 --cplus *.pyx
@marcmerlin
Copy link
Collaborator

is this still needed after @chrisgilldc and @ty-porter 's changes?

@marcmerlin
Copy link
Collaborator

@ledvinap please look at #1753
I'd like to get all the python updates/fixes in sync and get the best merge of everything.

@ty-porter
Copy link
Contributor

This looks great, supporting canvas serialization would be a welcome addition to the Python bindings! This PR might need to be rebased, looks like it is touching the same code as #1817 but I believe it should be compatible.

def SetPixel(self, int x, int y, uint8_t red, uint8_t green, uint8_t blue):
self.__matrix.SetPixel(x, y, red, green, blue)
cdef cppinc.Canvas* __getCanvas(self) except NULL:
assert self.__matrix != NULL
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally: Are these assertions required? If so, can we at least add an error message?

@marcmerlin
Copy link
Collaborator

yeah, this needs a rebase now, but if you're good with it on principle, happy to merge after that (please test the full code after rebase to make sure nothing broke)

@marcmerlin
Copy link
Collaborator

@ledvinap and @ty-porter I'm not able to tag or add you to the master bug to keep track of python stuff. Can you add yourselves as assignees to #1749 or just reply to the issue, and then I'll probably be able to add you so you have the option to review and vet new python changes?

@marcmerlin
Copy link
Collaborator

Is this PR still being worked on? If not, I'll close it. It's not that I don't want to to see this get in, but we don't want stale/abandoned PRs to stay around forever either.

@chrisgilldc
Copy link
Contributor

I'd defer to @ty-porter, I don't think my changes would have intersected here and I don't have Cython expertise.

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.

4 participants