Commit d9f43904 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d2d1: Use d2d_array_reserve() in d2d_clip_stack_push().

parent fdaa6d8e
...@@ -62,8 +62,8 @@ extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN; ...@@ -62,8 +62,8 @@ extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN;
struct d2d_clip_stack struct d2d_clip_stack
{ {
D2D1_RECT_F *stack; D2D1_RECT_F *stack;
unsigned int size; size_t size;
unsigned int count; size_t count;
}; };
struct d2d_error_state struct d2d_error_state
...@@ -486,6 +486,32 @@ static inline void *d2d_calloc(size_t count, size_t size) ...@@ -486,6 +486,32 @@ static inline void *d2d_calloc(size_t count, size_t size)
return heap_alloc(s); 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) static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
{ {
D2D_MATRIX_3X2_F tmp = *a; D2D_MATRIX_3X2_F tmp = *a;
......
...@@ -562,33 +562,6 @@ static void d2d_rect_get_bezier_segment_bounds(D2D_RECT_F *bounds, const D2D1_PO ...@@ -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]); 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) 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, if (!d2d_array_reserve((void **)&figure->vertices, &figure->vertices_size,
......
...@@ -95,22 +95,9 @@ static BOOL d2d_clip_stack_push(struct d2d_clip_stack *stack, const D2D1_RECT_F ...@@ -95,22 +95,9 @@ static BOOL d2d_clip_stack_push(struct d2d_clip_stack *stack, const D2D1_RECT_F
{ {
D2D1_RECT_F r; D2D1_RECT_F r;
if (stack->count == stack->size) if (!d2d_array_reserve((void **)&stack->stack, &stack->size, stack->count + 1, sizeof(*stack->stack)))
{
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; return FALSE;
stack->stack = new_stack;
stack->size = new_size;
}
r = *rect; r = *rect;
if (stack->count) if (stack->count)
d2d_rect_intersect(&r, &stack->stack[stack->count - 1]); d2d_rect_intersect(&r, &stack->stack[stack->count - 1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment