d2d1: Introduce a helper function to allocate arrays.

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:40 +03:30 committed by Alexandre Julliard
parent 15e466690a
commit fdaa6d8e2a
6 changed files with 21 additions and 10 deletions

View File

@ -509,9 +509,11 @@ HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *d
}
pitch = ((bpp * size.width) + 15) & ~15;
data_size = pitch * size.height;
if (!(data = heap_alloc(data_size)))
if (pitch / bpp < size.width)
return E_OUTOFMEMORY;
if (!(data = d2d_calloc(size.height, pitch)))
return E_OUTOFMEMORY;
data_size = size.height * pitch;
rect.X = 0;
rect.Y = 0;

View File

@ -142,7 +142,7 @@ HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D
unsigned int i;
HRESULT hr;
if (!(data = heap_alloc_zero(2 * stop_count * sizeof(*data))))
if (!(data = d2d_calloc(stop_count, 2 * sizeof(*data))))
{
ERR("Failed to allocate data.\n");
return E_OUTOFMEMORY;
@ -205,7 +205,7 @@ HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D
(*gradient)->view = view;
(*gradient)->stop_count = stop_count;
if (!((*gradient)->stops = heap_alloc(stop_count * sizeof(*stops))))
if (!((*gradient)->stops = d2d_calloc(stop_count, sizeof(*stops))))
{
ID3D10ShaderResourceView_Release(view);
heap_free(*gradient);

View File

@ -477,6 +477,15 @@ void d2d_transformed_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *
ID2D1Geometry *src_geometry, const D2D_MATRIX_3X2_F *transform) DECLSPEC_HIDDEN;
struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface) DECLSPEC_HIDDEN;
static inline void *d2d_calloc(size_t count, size_t size)
{
SIZE_T s = count * size;
if (size && s / size != count)
return NULL;
return heap_alloc(s);
}
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

@ -2052,7 +2052,7 @@ static HRESULT d2d_path_geometry_triangulate(struct d2d_geometry *geometry)
return S_OK;
}
if (!(vertices = heap_alloc(vertex_count * sizeof(*vertices))))
if (!(vertices = d2d_calloc(vertex_count, sizeof(*vertices))))
return E_OUTOFMEMORY;
for (i = 0, j = 0; i < geometry->u.path.figure_count; ++i)
@ -2819,8 +2819,8 @@ static HRESULT d2d_geometry_resolve_beziers(struct d2d_geometry *geometry)
geometry->fill.bezier_vertex_count += 3 * geometry->u.path.figures[i].bezier_control_count;
}
if (!(geometry->fill.bezier_vertices = heap_alloc(geometry->fill.bezier_vertex_count
* sizeof(*geometry->fill.bezier_vertices))))
if (!(geometry->fill.bezier_vertices = d2d_calloc(geometry->fill.bezier_vertex_count,
sizeof(*geometry->fill.bezier_vertices))))
{
ERR("Failed to allocate bezier vertices array.\n");
geometry->fill.bezier_vertex_count = 0;

View File

@ -1175,12 +1175,12 @@ static void d2d_rt_draw_glyph_run_bitmap(struct d2d_d3d_render_target *render_ta
if (texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1)
bitmap_size.width *= 3;
opacity_values_size = bitmap_size.width * bitmap_size.height;
if (!(opacity_values = heap_alloc(opacity_values_size)))
if (!(opacity_values = d2d_calloc(bitmap_size.height, bitmap_size.width)))
{
ERR("Failed to allocate opacity values.\n");
goto done;
}
opacity_values_size = bitmap_size.height * bitmap_size.width;
if (FAILED(hr = IDWriteGlyphRunAnalysis_CreateAlphaTexture(analysis,
texture_type, &bounds, opacity_values, opacity_values_size)))

View File

@ -212,7 +212,7 @@ HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *fact
if (!dashes || !dash_count)
return E_INVALIDARG;
if (!(style->dashes = heap_alloc(dash_count * sizeof(*style->dashes))))
if (!(style->dashes = d2d_calloc(dash_count, sizeof(*style->dashes))))
return E_OUTOFMEMORY;
memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
style->dash_count = dash_count;