Skip to content

Conversation

@dastels
Copy link

@dastels dastels commented Jul 31, 2019

No description provided.

@ladyada ladyada requested a review from tannewt August 1, 2019 17:51
@tannewt tannewt added this to the 5.x milestone Aug 2, 2019
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.

Thank you for adding this! Just a couple comments on memory allocation.


displayio_display_fill_area(self, &area, mask, buffer);

mp_obj_array_t *result = array_new(BYTEARRAY_TYPECODE, buffer_size * 4);
Copy link
Member

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.

/* .proxy = {(mp_obj_t)&displayio_display_get_screenshot_obj, */
/* (mp_obj_t)&mp_const_none_obj, */
/* (mp_obj_t)&mp_const_none_obj}, */
/* }; */
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this attribute.

@dastels
Copy link
Author

dastels commented Aug 7, 2019

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.

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'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.

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);
Copy link

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.

Copy link

Choose a reason for hiding this comment

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

Since this was the usecase, doing so simplifies the function significantly.
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.

Thanks for the simplification of the API! I added a couple of comments to further simplify the implementation too.


//| .. method:: fill_row(y, buffer)
//|
//| Extract the pixels fro a single row
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//| Extract the pixels fro a single row
//| Extract the pixels from a single row

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, {} },
Copy link
Member

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.


displayio_display_fill_area(self, &area, mask, buffer);

if ((result->len + result->free) >= (buffer_size * 4)) {
Copy link
Member

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.

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.

Looking better! Just one more re-arrangement.

}

mp_buffer_info_t bufinfo;
mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE);
Copy link
Member

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.

@dastels
Copy link
Author

dastels commented Aug 21, 2019

@tannewt

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.

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.

mp_buffer_info_t bufinfo;
mp_get_buffer_raise(result, &bufinfo, MP_BUFFER_WRITE);

if (result->typecode != BYTEARRAY_TYPECODE) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (result->typecode != BYTEARRAY_TYPECODE) {
if (bufinfo.typecode != BYTEARRAY_TYPECODE) {

@dastels
Copy link
Author

dastels commented Aug 22, 2019

OK, @tannewt , travis is green.

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.

Thank you for adding this and your patience with my feedback!

@tannewt tannewt merged commit 6aa311a into adafruit:master Aug 22, 2019
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.

3 participants