d2d1: Move brush creation helpers to common location.
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:
parent
a2c5afe61e
commit
27d5d4caf2
|
@ -138,20 +138,27 @@ static const struct ID2D1GradientStopCollectionVtbl d2d_gradient_vtbl =
|
||||||
d2d_gradient_GetExtendMode,
|
d2d_gradient_GetExtendMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1Factory *factory,
|
HRESULT d2d_gradient_create(ID2D1Factory *factory, const D2D1_GRADIENT_STOP *stops,
|
||||||
const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode)
|
UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode, struct d2d_gradient **gradient)
|
||||||
{
|
{
|
||||||
|
if (!(*gradient = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**gradient))))
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
FIXME("Ignoring gradient properties.\n");
|
FIXME("Ignoring gradient properties.\n");
|
||||||
|
|
||||||
gradient->ID2D1GradientStopCollection_iface.lpVtbl = &d2d_gradient_vtbl;
|
(*gradient)->ID2D1GradientStopCollection_iface.lpVtbl = &d2d_gradient_vtbl;
|
||||||
gradient->refcount = 1;
|
(*gradient)->refcount = 1;
|
||||||
ID2D1Factory_AddRef(gradient->factory = factory);
|
ID2D1Factory_AddRef((*gradient)->factory = factory);
|
||||||
|
|
||||||
gradient->stop_count = stop_count;
|
(*gradient)->stop_count = stop_count;
|
||||||
if (!(gradient->stops = HeapAlloc(GetProcessHeap(), 0, stop_count * sizeof(*stops))))
|
if (!((*gradient)->stops = HeapAlloc(GetProcessHeap(), 0, stop_count * sizeof(*stops))))
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, *gradient);
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
memcpy(gradient->stops, stops, stop_count * sizeof(*stops));
|
}
|
||||||
|
memcpy((*gradient)->stops, stops, stop_count * sizeof(*stops));
|
||||||
|
|
||||||
|
TRACE("Created gradient %p.\n", *gradient);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,12 +315,18 @@ static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl =
|
||||||
d2d_solid_color_brush_GetColor,
|
d2d_solid_color_brush_GetColor,
|
||||||
};
|
};
|
||||||
|
|
||||||
void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
|
HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
|
||||||
const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc)
|
const D2D1_BRUSH_PROPERTIES *desc, struct d2d_brush **brush)
|
||||||
{
|
{
|
||||||
d2d_brush_init(brush, factory, D2D_BRUSH_TYPE_SOLID, desc,
|
if (!(*brush = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**brush))))
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
d2d_brush_init(*brush, factory, D2D_BRUSH_TYPE_SOLID, desc,
|
||||||
(ID2D1BrushVtbl *)&d2d_solid_color_brush_vtbl);
|
(ID2D1BrushVtbl *)&d2d_solid_color_brush_vtbl);
|
||||||
brush->u.solid.color = *color;
|
(*brush)->u.solid.color = *color;
|
||||||
|
|
||||||
|
TRACE("Created brush %p.\n", *brush);
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct d2d_brush *impl_from_ID2D1LinearGradientBrush(ID2D1LinearGradientBrush *iface)
|
static inline struct d2d_brush *impl_from_ID2D1LinearGradientBrush(ID2D1LinearGradientBrush *iface)
|
||||||
|
@ -464,14 +477,19 @@ static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
|
||||||
d2d_linear_gradient_brush_GetGradientStopCollection,
|
d2d_linear_gradient_brush_GetGradientStopCollection,
|
||||||
};
|
};
|
||||||
|
|
||||||
void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
|
HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory, const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc,
|
||||||
const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
|
const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1GradientStopCollection *gradient, struct d2d_brush **brush)
|
||||||
ID2D1GradientStopCollection *gradient)
|
|
||||||
{
|
{
|
||||||
|
if (!(*brush = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**brush))))
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
FIXME("Ignoring brush properties.\n");
|
FIXME("Ignoring brush properties.\n");
|
||||||
|
|
||||||
d2d_brush_init(brush, factory, D2D_BRUSH_TYPE_LINEAR, brush_desc,
|
d2d_brush_init(*brush, factory, D2D_BRUSH_TYPE_LINEAR, brush_desc,
|
||||||
(ID2D1BrushVtbl *)&d2d_linear_gradient_brush_vtbl);
|
(ID2D1BrushVtbl *)&d2d_linear_gradient_brush_vtbl);
|
||||||
|
|
||||||
|
TRACE("Created brush %p.\n", *brush);
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct d2d_brush *impl_from_ID2D1BitmapBrush(ID2D1BitmapBrush *iface)
|
static inline struct d2d_brush *impl_from_ID2D1BitmapBrush(ID2D1BitmapBrush *iface)
|
||||||
|
@ -690,25 +708,31 @@ static const struct ID2D1BitmapBrushVtbl d2d_bitmap_brush_vtbl =
|
||||||
d2d_bitmap_brush_GetBitmap,
|
d2d_bitmap_brush_GetBitmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1Factory *factory, ID2D1Bitmap *bitmap,
|
HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
|
||||||
const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc)
|
const D2D1_BRUSH_PROPERTIES *brush_desc, struct d2d_brush **brush)
|
||||||
{
|
{
|
||||||
d2d_brush_init(brush, factory, D2D_BRUSH_TYPE_BITMAP,
|
if (!(*brush = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**brush))))
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
d2d_brush_init(*brush, factory, D2D_BRUSH_TYPE_BITMAP,
|
||||||
brush_desc, (ID2D1BrushVtbl *)&d2d_bitmap_brush_vtbl);
|
brush_desc, (ID2D1BrushVtbl *)&d2d_bitmap_brush_vtbl);
|
||||||
if ((brush->u.bitmap.bitmap = unsafe_impl_from_ID2D1Bitmap(bitmap)))
|
if (((*brush)->u.bitmap.bitmap = unsafe_impl_from_ID2D1Bitmap(bitmap)))
|
||||||
ID2D1Bitmap_AddRef(&brush->u.bitmap.bitmap->ID2D1Bitmap_iface);
|
ID2D1Bitmap_AddRef(&(*brush)->u.bitmap.bitmap->ID2D1Bitmap_iface);
|
||||||
if (bitmap_brush_desc)
|
if (bitmap_brush_desc)
|
||||||
{
|
{
|
||||||
brush->u.bitmap.extend_mode_x = bitmap_brush_desc->extendModeX;
|
(*brush)->u.bitmap.extend_mode_x = bitmap_brush_desc->extendModeX;
|
||||||
brush->u.bitmap.extend_mode_y = bitmap_brush_desc->extendModeY;
|
(*brush)->u.bitmap.extend_mode_y = bitmap_brush_desc->extendModeY;
|
||||||
brush->u.bitmap.interpolation_mode = bitmap_brush_desc->interpolationMode;
|
(*brush)->u.bitmap.interpolation_mode = bitmap_brush_desc->interpolationMode;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
brush->u.bitmap.extend_mode_x = D2D1_EXTEND_MODE_CLAMP;
|
(*brush)->u.bitmap.extend_mode_x = D2D1_EXTEND_MODE_CLAMP;
|
||||||
brush->u.bitmap.extend_mode_y = D2D1_EXTEND_MODE_CLAMP;
|
(*brush)->u.bitmap.extend_mode_y = D2D1_EXTEND_MODE_CLAMP;
|
||||||
brush->u.bitmap.interpolation_mode = D2D1_BITMAP_INTERPOLATION_MODE_LINEAR;
|
(*brush)->u.bitmap.interpolation_mode = D2D1_BITMAP_INTERPOLATION_MODE_LINEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACE("Created brush %p.\n", *brush);
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface)
|
struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface)
|
||||||
|
|
|
@ -125,9 +125,9 @@ struct d2d_gradient
|
||||||
UINT32 stop_count;
|
UINT32 stop_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1Factory *factory,
|
HRESULT d2d_gradient_create(ID2D1Factory *factory, const D2D1_GRADIENT_STOP *stops,
|
||||||
const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma,
|
UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
|
||||||
D2D1_EXTEND_MODE extend_mode) DECLSPEC_HIDDEN;
|
struct d2d_gradient **gradient) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
struct d2d_brush
|
struct d2d_brush
|
||||||
{
|
{
|
||||||
|
@ -156,14 +156,13 @@ struct d2d_brush
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
|
HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
|
||||||
const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc) DECLSPEC_HIDDEN;
|
const D2D1_BRUSH_PROPERTIES *desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
|
||||||
void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
|
HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory, const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc,
|
||||||
const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
|
const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1GradientStopCollection *gradient,
|
||||||
ID2D1GradientStopCollection *gradient) DECLSPEC_HIDDEN;
|
struct d2d_brush **brush) DECLSPEC_HIDDEN;
|
||||||
void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
|
HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
|
||||||
ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
|
const D2D1_BRUSH_PROPERTIES *brush_desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
|
||||||
const D2D1_BRUSH_PROPERTIES *brush_desc) DECLSPEC_HIDDEN;
|
|
||||||
void d2d_brush_bind_resources(struct d2d_brush *brush, struct d2d_brush *opacity_brush,
|
void d2d_brush_bind_resources(struct d2d_brush *brush, struct d2d_brush *opacity_brush,
|
||||||
struct d2d_d3d_render_target *render_target, enum d2d_shape_type shape_type) DECLSPEC_HIDDEN;
|
struct d2d_d3d_render_target *render_target, enum d2d_shape_type shape_type) DECLSPEC_HIDDEN;
|
||||||
HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_brush,
|
HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_brush,
|
||||||
|
|
|
@ -353,19 +353,15 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapBrush(ID2D1Re
|
||||||
{
|
{
|
||||||
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
||||||
struct d2d_brush *object;
|
struct d2d_brush *object;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
|
TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
|
||||||
iface, bitmap, bitmap_brush_desc, brush_desc, brush);
|
iface, bitmap, bitmap_brush_desc, brush_desc, brush);
|
||||||
|
|
||||||
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
if (SUCCEEDED(hr = d2d_bitmap_brush_create(render_target->factory, bitmap, bitmap_brush_desc, brush_desc, &object)))
|
||||||
return E_OUTOFMEMORY;
|
*brush = (ID2D1BitmapBrush *)&object->ID2D1Brush_iface;
|
||||||
|
|
||||||
d2d_bitmap_brush_init(object, render_target->factory, bitmap, bitmap_brush_desc, brush_desc);
|
return hr;
|
||||||
|
|
||||||
TRACE("Created brush %p.\n", object);
|
|
||||||
*brush = (ID2D1BitmapBrush *)&object->ID2D1Brush_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateSolidColorBrush(ID2D1RenderTarget *iface,
|
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateSolidColorBrush(ID2D1RenderTarget *iface,
|
||||||
|
@ -373,18 +369,14 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateSolidColorBrush(ID2
|
||||||
{
|
{
|
||||||
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
||||||
struct d2d_brush *object;
|
struct d2d_brush *object;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
|
TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
|
||||||
|
|
||||||
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
if (SUCCEEDED(hr = d2d_solid_color_brush_create(render_target->factory, color, desc, &object)))
|
||||||
return E_OUTOFMEMORY;
|
*brush = (ID2D1SolidColorBrush *)&object->ID2D1Brush_iface;
|
||||||
|
|
||||||
d2d_solid_color_brush_init(object, render_target->factory, color, desc);
|
return hr;
|
||||||
|
|
||||||
TRACE("Created brush %p.\n", object);
|
|
||||||
*brush = (ID2D1SolidColorBrush *)&object->ID2D1Brush_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateGradientStopCollection(ID2D1RenderTarget *iface,
|
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateGradientStopCollection(ID2D1RenderTarget *iface,
|
||||||
|
@ -398,20 +390,10 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateGradientStopCollect
|
||||||
TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
|
TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
|
||||||
iface, stops, stop_count, gamma, extend_mode, gradient);
|
iface, stops, stop_count, gamma, extend_mode, gradient);
|
||||||
|
|
||||||
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
if (SUCCEEDED(hr = d2d_gradient_create(render_target->factory, stops, stop_count, gamma, extend_mode, &object)))
|
||||||
return E_OUTOFMEMORY;
|
*gradient = &object->ID2D1GradientStopCollection_iface;
|
||||||
|
|
||||||
if (FAILED(hr = d2d_gradient_init(object, render_target->factory, stops, stop_count, gamma, extend_mode)))
|
return hr;
|
||||||
{
|
|
||||||
WARN("Failed to initialize gradient, hr %#x.\n", hr);
|
|
||||||
HeapFree(GetProcessHeap(), 0, object);
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("Created gradient %p.\n", object);
|
|
||||||
*gradient = &object->ID2D1GradientStopCollection_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLinearGradientBrush(ID2D1RenderTarget *iface,
|
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLinearGradientBrush(ID2D1RenderTarget *iface,
|
||||||
|
@ -420,19 +402,16 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLinearGradientBrush
|
||||||
{
|
{
|
||||||
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
||||||
struct d2d_brush *object;
|
struct d2d_brush *object;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
|
TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
|
||||||
iface, gradient_brush_desc, brush_desc, gradient, brush);
|
iface, gradient_brush_desc, brush_desc, gradient, brush);
|
||||||
|
|
||||||
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
if (SUCCEEDED(hr = d2d_linear_gradient_brush_create(render_target->factory, gradient_brush_desc, brush_desc,
|
||||||
return E_OUTOFMEMORY;
|
gradient, &object)))
|
||||||
|
*brush = (ID2D1LinearGradientBrush *)&object->ID2D1Brush_iface;
|
||||||
|
|
||||||
d2d_linear_gradient_brush_init(object, render_target->factory, gradient_brush_desc, brush_desc, gradient);
|
return hr;
|
||||||
|
|
||||||
TRACE("Created brush %p.\n", object);
|
|
||||||
*brush = (ID2D1LinearGradientBrush *)&object->ID2D1Brush_iface;
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateRadialGradientBrush(ID2D1RenderTarget *iface,
|
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateRadialGradientBrush(ID2D1RenderTarget *iface,
|
||||||
|
|
Loading…
Reference in New Issue