diff options
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_utils.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_utils.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 065c133bf97..ac8196f5ed0 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -1740,7 +1740,7 @@ static void gp_brush_cursor_draw(bContext *C, int x, int y, void *customdata) } /* while drawing hide */ - if ((gpd->runtime.sbuffer_size > 0) && + if ((gpd->runtime.sbuffer_used > 0) && ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0)) { return; @@ -2525,3 +2525,37 @@ void ED_gpencil_select_toggle_all(bContext *C, int action) CTX_DATA_END; } } + +/* Ensure the SBuffer (while drawing stroke) size is enough to save all points of the stroke */ +tGPspoint *ED_gpencil_sbuffer_ensure(tGPspoint *buffer_array, + short *buffer_size, + short *buffer_used, + const bool clear) +{ + tGPspoint *p = NULL; + + /* By default a buffer is created with one block with a predefined number of free points, + * if the size is not enough, the cache is reallocated adding a new block of free points. + * This is done in order to keep cache small and improve speed. */ + if (*buffer_used + 1 > *buffer_size) { + if ((*buffer_size == 0) || (buffer_array == NULL)) { + p = MEM_callocN(sizeof(struct tGPspoint) * GP_STROKE_BUFFER_CHUNK, "GPencil Sbuffer"); + *buffer_size = GP_STROKE_BUFFER_CHUNK; + } + else { + *buffer_size += GP_STROKE_BUFFER_CHUNK; + p = MEM_recallocN(buffer_array, sizeof(struct tGPspoint) * *buffer_size); + } + buffer_array = p; + } + + /* clear old data */ + if (clear) { + *buffer_used = 0; + if (buffer_array != NULL) { + memset(buffer_array, 0, sizeof(tGPspoint) * *buffer_size); + } + } + + return buffer_array; +} |