55#include "shared-bindings/vectorio/VectorShape.h"
66
77#include "py/runtime.h"
8+ #include "shared-bindings/time/__init__.h"
89#include "shared-bindings/displayio/ColorConverter.h"
910#include "shared-bindings/displayio/Palette.h"
1011
1718// #define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
1819
1920
21+ // Used in both logging and ifdefs, for extra variables
22+ // #define VECTORIO_PERF(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
23+
24+
2025// Really verbose.
2126#define VECTORIO_SHAPE_PIXEL_DEBUG (...) (void)0
2227// #define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
@@ -167,6 +172,10 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
167172 // To make it relative to the VectorShape position, we must shift it.
168173 // Pixels are drawn on the screen_area (shifted) coordinate space, while pixels are _determined_ from
169174 // the shape_area (unshifted) space.
175+ #ifdef VECTORIO_PERF
176+ uint64_t start = common_hal_time_monotonic_ns ();
177+ uint64_t pixel_time = 0 ;
178+ #endif
170179 displayio_area_t overlap ;
171180 VECTORIO_SHAPE_DEBUG ("%p fill_area dirty:%d fill: {(%5d,%5d), (%5d,%5d)} dirty: {(%5d,%5d), (%5d,%5d)}" ,
172181 self , self -> dirty ,
@@ -186,7 +195,8 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
186195 uint32_t linestride_px = displayio_area_width (area );
187196 uint32_t line_dirty_offset_px = (overlap .y1 - area -> y1 ) * linestride_px ;
188197 uint32_t column_dirty_offset_px = overlap .x1 - area -> x1 ;
189- VECTORIO_SHAPE_DEBUG (", linestride:%3d line_offset:%3d col_offset:%3d depth:%2d ppb:%2d\n" , linestride_px , line_dirty_offset_px , column_dirty_offset_px , colorspace -> depth , pixels_per_byte );
198+ VECTORIO_SHAPE_DEBUG (", linestride:%3d line_offset:%3d col_offset:%3d depth:%2d ppb:%2d shape:%s" ,
199+ linestride_px , line_dirty_offset_px , column_dirty_offset_px , colorspace -> depth , pixels_per_byte , mp_obj_get_type_str (self -> ishape .shape ));
190200
191201 displayio_input_pixel_t input_pixel ;
192202 displayio_output_pixel_t output_pixel ;
@@ -217,7 +227,14 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
217227 pixel_to_get_y = (input_pixel .y - self -> absolute_transform -> dy * self -> y ) / self -> absolute_transform -> dy ;
218228 }
219229 VECTORIO_SHAPE_PIXEL_DEBUG (" get_pixel %p (%3d, %3d) -> ( %3d, %3d )" , self -> ishape .shape , input_pixel .x , input_pixel .y , pixel_to_get_x , pixel_to_get_y );
230+ #ifdef VECTORIO_PERF
231+ uint64_t pre_pixel = common_hal_time_monotonic_ns ();
232+ #endif
220233 input_pixel .pixel = self -> ishape .get_pixel (self -> ishape .shape , pixel_to_get_x , pixel_to_get_y );
234+ #ifdef VECTORIO_PERF
235+ uint64_t post_pixel = common_hal_time_monotonic_ns ();
236+ pixel_time += post_pixel - pre_pixel ;
237+ #endif
221238 VECTORIO_SHAPE_PIXEL_DEBUG (" -> %d" , input_pixel .pixel );
222239
223240 output_pixel .opaque = true;
@@ -259,6 +276,19 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
259276 }
260277 mask_start_px += linestride_px - column_dirty_offset_px ;
261278 }
279+ #ifdef VECTORIO_PERF
280+ uint64_t end = common_hal_time_monotonic_ns ();
281+ uint32_t pixels = (overlap .x2 - overlap .x1 ) * (overlap .y2 - overlap .y1 );
282+ VECTORIO_PERF ("draw %16s -> shape:{%4dpx, %4.1fms,%9.1fpps fill} shape_pixels:{%6.1fus total, %4.1fus/px}\n" ,
283+ mp_obj_get_type_str (self -> ishape .shape ),
284+ (overlap .x2 - overlap .x1 ) * (overlap .y2 - overlap .y1 ),
285+ (double )((end - start ) / 1000000.0 ),
286+ (double )(max (1 , pixels * (1000000000.0 / (end - start )))),
287+ (double )(pixel_time / 1000.0 ),
288+ (double )(pixel_time / 1000.0 / pixels )
289+ );
290+ #endif
291+ VECTORIO_SHAPE_DEBUG (" -> pixels:%4d\n" );
262292 return full_coverage ;
263293}
264294
0 commit comments