5
5
#include "shared-bindings/vectorio/VectorShape.h"
6
6
7
7
#include "py/runtime.h"
8
+ #include "shared-bindings/time/__init__.h"
8
9
#include "shared-bindings/displayio/ColorConverter.h"
9
10
#include "shared-bindings/displayio/Palette.h"
10
11
17
18
// #define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
18
19
19
20
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
+
20
25
// Really verbose.
21
26
#define VECTORIO_SHAPE_PIXEL_DEBUG (...) (void)0
22
27
// #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
167
172
// To make it relative to the VectorShape position, we must shift it.
168
173
// Pixels are drawn on the screen_area (shifted) coordinate space, while pixels are _determined_ from
169
174
// 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
170
179
displayio_area_t overlap ;
171
180
VECTORIO_SHAPE_DEBUG ("%p fill_area dirty:%d fill: {(%5d,%5d), (%5d,%5d)} dirty: {(%5d,%5d), (%5d,%5d)}" ,
172
181
self , self -> dirty ,
@@ -186,7 +195,8 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
186
195
uint32_t linestride_px = displayio_area_width (area );
187
196
uint32_t line_dirty_offset_px = (overlap .y1 - area -> y1 ) * linestride_px ;
188
197
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 ));
190
200
191
201
displayio_input_pixel_t input_pixel ;
192
202
displayio_output_pixel_t output_pixel ;
@@ -217,7 +227,14 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
217
227
pixel_to_get_y = (input_pixel .y - self -> absolute_transform -> dy * self -> y ) / self -> absolute_transform -> dy ;
218
228
}
219
229
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
220
233
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
221
238
VECTORIO_SHAPE_PIXEL_DEBUG (" -> %d" , input_pixel .pixel );
222
239
223
240
output_pixel .opaque = true;
@@ -259,6 +276,19 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
259
276
}
260
277
mask_start_px += linestride_px - column_dirty_offset_px ;
261
278
}
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" );
262
292
return full_coverage ;
263
293
}
264
294
0 commit comments