d3drm: Use existing helper to manage visuals array.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2017-07-10 13:40:48 +03:00 committed by Alexandre Julliard
parent 0459a3273d
commit 671ac168e2
2 changed files with 9 additions and 28 deletions

View File

@ -68,8 +68,8 @@ struct d3drm_frame
SIZE_T nb_children; SIZE_T nb_children;
SIZE_T children_size; SIZE_T children_size;
IDirect3DRMFrame3 **children; IDirect3DRMFrame3 **children;
ULONG nb_visuals; SIZE_T nb_visuals;
ULONG visuals_capacity; SIZE_T visuals_size;
IDirect3DRMVisual **visuals; IDirect3DRMVisual **visuals;
SIZE_T nb_lights; SIZE_T nb_lights;
SIZE_T lights_size; SIZE_T lights_size;

View File

@ -1064,9 +1064,8 @@ static HRESULT WINAPI d3drm_frame1_AddRotation(IDirect3DRMFrame *iface,
static HRESULT WINAPI d3drm_frame3_AddVisual(IDirect3DRMFrame3 *iface, IUnknown *visual) static HRESULT WINAPI d3drm_frame3_AddVisual(IDirect3DRMFrame3 *iface, IUnknown *visual)
{ {
struct d3drm_frame *This = impl_from_IDirect3DRMFrame3(iface); struct d3drm_frame *frame = impl_from_IDirect3DRMFrame3(iface);
ULONG i; ULONG i;
IDirect3DRMVisual** visuals;
TRACE("iface %p, visual %p.\n", iface, visual); TRACE("iface %p, visual %p.\n", iface, visual);
@ -1074,33 +1073,15 @@ static HRESULT WINAPI d3drm_frame3_AddVisual(IDirect3DRMFrame3 *iface, IUnknown
return D3DRMERR_BADOBJECT; return D3DRMERR_BADOBJECT;
/* Check if already existing and return gracefully without increasing ref count */ /* Check if already existing and return gracefully without increasing ref count */
for (i = 0; i < This->nb_visuals; i++) for (i = 0; i < frame->nb_visuals; i++)
if (This->visuals[i] == (IDirect3DRMVisual *)visual) if (frame->visuals[i] == (IDirect3DRMVisual *)visual)
return D3DRM_OK; return D3DRM_OK;
if ((This->nb_visuals + 1) > This->visuals_capacity) if (!d3drm_array_reserve((void **)&frame->visuals, &frame->visuals_size,
{ frame->nb_visuals + 1, sizeof(*frame->visuals)))
ULONG new_capacity; return E_OUTOFMEMORY;
if (!This->visuals_capacity) frame->visuals[frame->nb_visuals++] = (IDirect3DRMVisual *)visual;
{
new_capacity = 16;
visuals = HeapAlloc(GetProcessHeap(), 0, new_capacity * sizeof(IDirect3DRMVisual*));
}
else
{
new_capacity = This->visuals_capacity * 2;
visuals = HeapReAlloc(GetProcessHeap(), 0, This->visuals, new_capacity * sizeof(IDirect3DRMVisual*));
}
if (!visuals)
return E_OUTOFMEMORY;
This->visuals_capacity = new_capacity;
This->visuals = visuals;
}
This->visuals[This->nb_visuals++] = (IDirect3DRMVisual *)visual;
IDirect3DRMVisual_AddRef(visual); IDirect3DRMVisual_AddRef(visual);
return D3DRM_OK; return D3DRM_OK;