[PATCH 1/2] d2d1: Move brush creation helpers to common location
Nikolay Sivov
nsivov at codeweavers.com
Thu Mar 31 06:49:31 CDT 2016
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
dlls/d2d1/brush.c | 78 +++++++++++++++++++++++++++++++----------------
dlls/d2d1/d2d1_private.h | 21 ++++++-------
dlls/d2d1/render_target.c | 53 ++++++++++----------------------
3 files changed, 77 insertions(+), 75 deletions(-)
diff --git a/dlls/d2d1/brush.c b/dlls/d2d1/brush.c
index aa92318..1454faf 100644
--- a/dlls/d2d1/brush.c
+++ b/dlls/d2d1/brush.c
@@ -138,20 +138,27 @@ static const struct ID2D1GradientStopCollectionVtbl d2d_gradient_vtbl =
d2d_gradient_GetExtendMode,
};
-HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1Factory *factory,
- const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode)
+HRESULT d2d_gradient_create(ID2D1Factory *factory, const D2D1_GRADIENT_STOP *stops,
+ 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");
- gradient->ID2D1GradientStopCollection_iface.lpVtbl = &d2d_gradient_vtbl;
- gradient->refcount = 1;
- ID2D1Factory_AddRef(gradient->factory = factory);
+ (*gradient)->ID2D1GradientStopCollection_iface.lpVtbl = &d2d_gradient_vtbl;
+ (*gradient)->refcount = 1;
+ ID2D1Factory_AddRef((*gradient)->factory = factory);
- gradient->stop_count = stop_count;
- if (!(gradient->stops = HeapAlloc(GetProcessHeap(), 0, stop_count * sizeof(*stops))))
+ (*gradient)->stop_count = stop_count;
+ if (!((*gradient)->stops = HeapAlloc(GetProcessHeap(), 0, stop_count * sizeof(*stops))))
+ {
+ HeapFree(GetProcessHeap(), 0, *gradient);
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;
}
@@ -308,12 +315,18 @@ static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl =
d2d_solid_color_brush_GetColor,
};
-void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
- const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc)
+HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
+ 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);
- 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)
@@ -464,14 +477,19 @@ static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
d2d_linear_gradient_brush_GetGradientStopCollection,
};
-void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
- const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
- ID2D1GradientStopCollection *gradient)
+HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory, const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc,
+ const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1GradientStopCollection *gradient, struct d2d_brush **brush)
{
+ if (!(*brush = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**brush))))
+ return E_OUTOFMEMORY;
+
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);
+
+ TRACE("Created brush %p.\n", *brush);
+ return S_OK;
}
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,
};
-void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1Factory *factory, ID2D1Bitmap *bitmap,
- const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc)
+HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_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);
- if ((brush->u.bitmap.bitmap = unsafe_impl_from_ID2D1Bitmap(bitmap)))
- ID2D1Bitmap_AddRef(&brush->u.bitmap.bitmap->ID2D1Bitmap_iface);
+ if (((*brush)->u.bitmap.bitmap = unsafe_impl_from_ID2D1Bitmap(bitmap)))
+ ID2D1Bitmap_AddRef(&(*brush)->u.bitmap.bitmap->ID2D1Bitmap_iface);
if (bitmap_brush_desc)
{
- brush->u.bitmap.extend_mode_x = bitmap_brush_desc->extendModeX;
- brush->u.bitmap.extend_mode_y = bitmap_brush_desc->extendModeY;
- brush->u.bitmap.interpolation_mode = bitmap_brush_desc->interpolationMode;
+ (*brush)->u.bitmap.extend_mode_x = bitmap_brush_desc->extendModeX;
+ (*brush)->u.bitmap.extend_mode_y = bitmap_brush_desc->extendModeY;
+ (*brush)->u.bitmap.interpolation_mode = bitmap_brush_desc->interpolationMode;
}
else
{
- brush->u.bitmap.extend_mode_x = 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.extend_mode_x = D2D1_EXTEND_MODE_CLAMP;
+ (*brush)->u.bitmap.extend_mode_y = D2D1_EXTEND_MODE_CLAMP;
+ (*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)
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index 0f9dcc5..bb3f978 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -125,9 +125,9 @@ struct d2d_gradient
UINT32 stop_count;
};
-HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1Factory *factory,
- const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma,
- D2D1_EXTEND_MODE extend_mode) DECLSPEC_HIDDEN;
+HRESULT d2d_gradient_create(ID2D1Factory *factory, const D2D1_GRADIENT_STOP *stops,
+ UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
+ struct d2d_gradient **gradient) DECLSPEC_HIDDEN;
struct d2d_brush
{
@@ -156,14 +156,13 @@ struct d2d_brush
} u;
};
-void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
- const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc) DECLSPEC_HIDDEN;
-void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
- const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
- ID2D1GradientStopCollection *gradient) DECLSPEC_HIDDEN;
-void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
- ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
- const D2D1_BRUSH_PROPERTIES *brush_desc) DECLSPEC_HIDDEN;
+HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
+ const D2D1_BRUSH_PROPERTIES *desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
+HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory, const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc,
+ const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1GradientStopCollection *gradient,
+ struct d2d_brush **brush) DECLSPEC_HIDDEN;
+HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
+ const D2D1_BRUSH_PROPERTIES *brush_desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
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;
HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_brush,
diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c
index 8a3ded7..287d7c3 100644
--- a/dlls/d2d1/render_target.c
+++ b/dlls/d2d1/render_target.c
@@ -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_brush *object;
+ HRESULT hr;
TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
iface, bitmap, bitmap_brush_desc, brush_desc, brush);
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- d2d_bitmap_brush_init(object, render_target->factory, bitmap, bitmap_brush_desc, brush_desc);
+ if (SUCCEEDED(hr = d2d_bitmap_brush_create(render_target->factory, bitmap, bitmap_brush_desc, brush_desc, &object)))
+ *brush = (ID2D1BitmapBrush *)&object->ID2D1Brush_iface;
- TRACE("Created brush %p.\n", object);
- *brush = (ID2D1BitmapBrush *)&object->ID2D1Brush_iface;
-
- return S_OK;
+ return hr;
}
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_brush *object;
+ HRESULT hr;
TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- d2d_solid_color_brush_init(object, render_target->factory, color, desc);
-
- TRACE("Created brush %p.\n", object);
- *brush = (ID2D1SolidColorBrush *)&object->ID2D1Brush_iface;
+ if (SUCCEEDED(hr = d2d_solid_color_brush_create(render_target->factory, color, desc, &object)))
+ *brush = (ID2D1SolidColorBrush *)&object->ID2D1Brush_iface;
- return S_OK;
+ return hr;
}
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",
iface, stops, stop_count, gamma, extend_mode, gradient);
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- if (FAILED(hr = d2d_gradient_init(object, render_target->factory, stops, stop_count, gamma, extend_mode)))
- {
- 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;
+ if (SUCCEEDED(hr = d2d_gradient_create(render_target->factory, stops, stop_count, gamma, extend_mode, &object)))
+ *gradient = &object->ID2D1GradientStopCollection_iface;
- return S_OK;
+ return hr;
}
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_brush *object;
+ HRESULT hr;
TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
iface, gradient_brush_desc, brush_desc, gradient, brush);
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- d2d_linear_gradient_brush_init(object, render_target->factory, gradient_brush_desc, brush_desc, gradient);
+ if (SUCCEEDED(hr = d2d_linear_gradient_brush_create(render_target->factory, gradient_brush_desc, brush_desc,
+ gradient, &object)))
+ *brush = (ID2D1LinearGradientBrush *)&object->ID2D1Brush_iface;
- TRACE("Created brush %p.\n", object);
- *brush = (ID2D1LinearGradientBrush *)&object->ID2D1Brush_iface;
-
- return S_OK;
+ return hr;
}
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateRadialGradientBrush(ID2D1RenderTarget *iface,
--
2.8.0.rc3
More information about the wine-patches
mailing list