-
Notifications
You must be signed in to change notification settings - Fork 1.4k
To displayio.Display: expose fill_area and add a property for rotation #2027
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
Conversation
tannewt
left a comment
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.
Thank you for adding this! Just a couple comments on memory allocation.
shared-bindings/displayio/Display.c
Outdated
|
|
||
| displayio_display_fill_area(self, &area, mask, buffer); | ||
|
|
||
| mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size * 4); |
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.
Instead of allocating an array, please accept a bytearray or array in as an argument so that the buffer can be reused. Reusing the buffer will make it easier to allocate and reduce fragmentation.
shared-bindings/displayio/Display.c
Outdated
| /* .proxy = {(mp_obj_t)&displayio_display_get_screenshot_obj, */ | ||
| /* (mp_obj_t)&mp_const_none_obj, */ | ||
| /* (mp_obj_t)&mp_const_none_obj}, */ | ||
| /* }; */ |
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.
Please remove this attribute.
|
OK, Scott. I addressed the issues above. You now pass in an adequately large bytearray. Exceptions raised if it's not a bytearray or if it's not big enough. |
tannewt
left a comment
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've looked at this more closely and am worried it won't work for any arbitrary area. I looked at your Python library on top and it's going row by row to output to a bitmap.
Let's embrace that specific scenario and reduce the api down to fill_row where it's given a y and an array of 16bit values that is width long. Also check that the display has a 16 bit colorspace and raise an exception otherwise.
The rows_per_buffer section can all be simplified away because we're only doing one row at a time then and we know it is aligned well. The given buffer can then be passed into fill_area directly instead of having to do a copy afterwards.
Thanks and let me know if you have any questions.
shared-bindings/displayio/Display.c
Outdated
| mp_int_t y = args[ARG_y].u_int; | ||
| mp_int_t w = args[ARG_width].u_int; | ||
| mp_int_t h = args[ARG_height].u_int; | ||
| mp_obj_array_t *result = (mp_obj_array_t *)(args[ARG_buffer].u_obj); |
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 would recommend using mp_get_buffer_raise to get the buffer and its size, then you don't need all those functions for accessing the array elements, etc.
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.
You can see an example at https://github.com/adafruit/circuitpython/pull/2032/files#diff-28511b511b1f39aef03beef1a21a603eR82-R87
Since this was the usecase, doing so simplifies the function significantly.
tannewt
left a comment
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.
Thanks for the simplification of the API! I added a couple of comments to further simplify the implementation too.
shared-bindings/displayio/Display.c
Outdated
|
|
||
| //| .. method:: fill_row(y, buffer) | ||
| //| | ||
| //| Extract the pixels fro a single row |
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.
| //| Extract the pixels fro a single row | |
| //| Extract the pixels from a single row |
shared-bindings/displayio/Display.c
Outdated
| enum { ARG_y, ARG_buffer }; | ||
| static const mp_arg_t allowed_args[] = { | ||
| { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, | ||
| { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_KW_ONLY, {} }, |
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'd remove both MP_ARG_KW_ONLYs and make them required positional arguments.
shared-bindings/displayio/Display.c
Outdated
|
|
||
| displayio_display_fill_area(self, &area, mask, buffer); | ||
|
|
||
| if ((result->len + result->free) >= (buffer_size * 4)) { |
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.
Please do this check before fill_area and then pass the given buffer straight into fill_area. That will simplify this implementation further.
tannewt
left a comment
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.
Looking better! Just one more re-arrangement.
shared-bindings/displayio/Display.c
Outdated
| } | ||
|
|
||
| mp_buffer_info_t bufinfo; | ||
| mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); |
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.
Do this above where you have the array cast before the typecode check otherwise you are testing against memory that may not be what you think it is.
tannewt
left a comment
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.
Please get the first CI job green by fixing the test unix build. Once it's down to the itsy m0 build and space then I'll fix it for you.
shared-bindings/displayio/Display.c
Outdated
| mp_buffer_info_t bufinfo; | ||
| mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE); | ||
|
|
||
| if (result->typecode != BYTEARRAY_TYPECODE) { |
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.
| if (result->typecode != BYTEARRAY_TYPECODE) { | |
| if (bufinfo.typecode != BYTEARRAY_TYPECODE) { |
|
OK, @tannewt , travis is green. |
tannewt
left a comment
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.
Thank you for adding this and your patience with my feedback!
No description provided.