d2d1: Use d2d_array_reserve() in d2d_clip_stack_push().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2018-01-31 18:49:41 +03:30 committed by Alexandre Julliard
parent fdaa6d8e2a
commit d9f4390488
3 changed files with 30 additions and 44 deletions

View File

@ -62,8 +62,8 @@ extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN;
struct d2d_clip_stack
{
D2D1_RECT_F *stack;
unsigned int size;
unsigned int count;
size_t size;
size_t count;
};
struct d2d_error_state
@ -486,6 +486,32 @@ static inline void *d2d_calloc(size_t count, size_t size)
return heap_alloc(s);
}
static inline BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t count, size_t size)
{
size_t new_capacity, max_capacity;
void *new_elements;
if (count <= *capacity)
return TRUE;
max_capacity = ~(SIZE_T)0 / size;
if (count > max_capacity)
return FALSE;
new_capacity = max(4, *capacity);
while (new_capacity < count && new_capacity <= max_capacity / 2)
new_capacity *= 2;
if (new_capacity < count)
new_capacity = max_capacity;
if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
return FALSE;
*elements = new_elements;
*capacity = new_capacity;
return TRUE;
}
static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
{
D2D_MATRIX_3X2_F tmp = *a;

View File

@ -562,33 +562,6 @@ static void d2d_rect_get_bezier_segment_bounds(D2D_RECT_F *bounds, const D2D1_PO
d2d_rect_get_bezier_bounds(bounds, &q[0], &q[1], &q[2]);
}
static BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size)
{
size_t new_capacity, max_capacity;
void *new_elements;
if (element_count <= *capacity)
return TRUE;
max_capacity = ~(size_t)0 / element_size;
if (max_capacity < element_count)
return FALSE;
new_capacity = max(*capacity, 4);
while (new_capacity < element_count && new_capacity <= max_capacity / 2)
new_capacity *= 2;
if (new_capacity < element_count)
new_capacity = max_capacity;
if (!(new_elements = heap_realloc(*elements, new_capacity * element_size)))
return FALSE;
*elements = new_elements;
*capacity = new_capacity;
return TRUE;
}
static BOOL d2d_figure_insert_vertex(struct d2d_figure *figure, size_t idx, D2D1_POINT_2F vertex)
{
if (!d2d_array_reserve((void **)&figure->vertices, &figure->vertices_size,

View File

@ -95,21 +95,8 @@ static BOOL d2d_clip_stack_push(struct d2d_clip_stack *stack, const D2D1_RECT_F
{
D2D1_RECT_F r;
if (stack->count == stack->size)
{
D2D1_RECT_F *new_stack;
unsigned int new_size;
if (stack->size > UINT_MAX / 2)
return FALSE;
new_size = stack->size * 2;
if (!(new_stack = heap_realloc(stack->stack, new_size * sizeof(*stack->stack))))
return FALSE;
stack->stack = new_stack;
stack->size = new_size;
}
if (!d2d_array_reserve((void **)&stack->stack, &stack->size, stack->count + 1, sizeof(*stack->stack)))
return FALSE;
r = *rect;
if (stack->count)