Henri Verbeet : d2d1: Implement d2d_bitmap_brush_GetFactory().

Alexandre Julliard julliard at wine.codeweavers.com
Mon Aug 3 14:52:35 CDT 2015


Module: wine
Branch: master
Commit: 414d04e27de1ae8f4eb6bfba28b0221b7431f0db
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=414d04e27de1ae8f4eb6bfba28b0221b7431f0db

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Sun Aug  2 18:56:06 2015 +0200

d2d1: Implement d2d_bitmap_brush_GetFactory().

---

 dlls/d2d1/brush.c         | 33 +++++++++++++++++++++------------
 dlls/d2d1/d2d1_private.h  |  7 ++++---
 dlls/d2d1/render_target.c |  8 +++++---
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/dlls/d2d1/brush.c b/dlls/d2d1/brush.c
index 36d0a51..857ec52 100644
--- a/dlls/d2d1/brush.c
+++ b/dlls/d2d1/brush.c
@@ -144,7 +144,13 @@ HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *rend
     return S_OK;
 }
 
-static void d2d_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
+static void d2d_brush_destroy(struct d2d_brush *brush)
+{
+    ID2D1Factory_Release(brush->factory);
+    HeapFree(GetProcessHeap(), 0, brush);
+}
+
+static void d2d_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
         enum d2d_brush_type type, const D2D1_BRUSH_PROPERTIES *desc, const struct ID2D1BrushVtbl *vtbl)
 {
     static const D2D1_MATRIX_3X2_F identity =
@@ -156,6 +162,7 @@ static void d2d_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_ta
 
     brush->ID2D1Brush_iface.lpVtbl = vtbl;
     brush->refcount = 1;
+    ID2D1Factory_AddRef(brush->factory = factory);
     brush->opacity = desc ? desc->opacity : 1.0f;
     brush->transform = desc ? desc->transform : identity;
     brush->type = type;
@@ -205,7 +212,7 @@ static ULONG STDMETHODCALLTYPE d2d_solid_color_brush_Release(ID2D1SolidColorBrus
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
     if (!refcount)
-        HeapFree(GetProcessHeap(), 0, brush);
+        d2d_brush_destroy(brush);
 
     return refcount;
 }
@@ -288,12 +295,12 @@ static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl =
     d2d_solid_color_brush_GetColor,
 };
 
-void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
+void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1Factory *factory,
         const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc)
 {
     FIXME("Ignoring brush properties.\n");
 
-    d2d_brush_init(brush, render_target, D2D_BRUSH_TYPE_SOLID, desc,
+    d2d_brush_init(brush, factory, D2D_BRUSH_TYPE_SOLID, desc,
             (ID2D1BrushVtbl *)&d2d_solid_color_brush_vtbl);
     brush->u.solid.color = *color;
 }
@@ -342,7 +349,7 @@ static ULONG STDMETHODCALLTYPE d2d_linear_gradient_brush_Release(ID2D1LinearGrad
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
     if (!refcount)
-        HeapFree(GetProcessHeap(), 0, brush);
+        d2d_brush_destroy(brush);
 
     return refcount;
 }
@@ -444,13 +451,13 @@ static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
     d2d_linear_gradient_brush_GetGradientStopCollection,
 };
 
-void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
+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)
 {
     FIXME("Ignoring brush properties.\n");
 
-    d2d_brush_init(brush, render_target, D2D_BRUSH_TYPE_LINEAR, brush_desc,
+    d2d_brush_init(brush, factory, D2D_BRUSH_TYPE_LINEAR, brush_desc,
             (ID2D1BrushVtbl *)&d2d_linear_gradient_brush_vtbl);
 }
 
@@ -503,7 +510,7 @@ static ULONG STDMETHODCALLTYPE d2d_bitmap_brush_Release(ID2D1BitmapBrush *iface)
             ID3D10SamplerState_Release(brush->u.bitmap.sampler_state);
         if (brush->u.bitmap.bitmap)
             ID2D1Bitmap_Release(&brush->u.bitmap.bitmap->ID2D1Bitmap_iface);
-        HeapFree(GetProcessHeap(), 0, brush);
+        d2d_brush_destroy(brush);
     }
 
     return refcount;
@@ -512,9 +519,11 @@ static ULONG STDMETHODCALLTYPE d2d_bitmap_brush_Release(ID2D1BitmapBrush *iface)
 static void STDMETHODCALLTYPE d2d_bitmap_brush_GetFactory(ID2D1BitmapBrush *iface,
         ID2D1Factory **factory)
 {
-    FIXME("iface %p, factory %p stub!\n", iface, factory);
+    struct d2d_brush *brush = impl_from_ID2D1BitmapBrush(iface);
 
-    *factory = NULL;
+    TRACE("iface %p, factory %p.\n", iface, factory);
+
+    ID2D1Factory_AddRef(*factory = brush->factory);
 }
 
 static void STDMETHODCALLTYPE d2d_bitmap_brush_SetOpacity(ID2D1BitmapBrush *iface, float opacity)
@@ -668,13 +677,13 @@ static const struct ID2D1BitmapBrushVtbl d2d_bitmap_brush_vtbl =
     d2d_bitmap_brush_GetBitmap,
 };
 
-HRESULT d2d_bitmap_brush_init(struct d2d_brush *brush, struct d2d_d3d_render_target *render_target, ID2D1Bitmap *bitmap,
+HRESULT 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)
 {
 
     FIXME("Ignoring brush properties.\n");
 
-    d2d_brush_init(brush, &render_target->ID2D1RenderTarget_iface, D2D_BRUSH_TYPE_BITMAP,
+    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);
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index c7744a3..ebc97fc 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -125,6 +125,7 @@ struct d2d_brush
     ID2D1Brush ID2D1Brush_iface;
     LONG refcount;
 
+    ID2D1Factory *factory;
     float opacity;
     D2D1_MATRIX_3X2_F transform;
 
@@ -146,12 +147,12 @@ struct d2d_brush
     } u;
 };
 
-void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
+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, ID2D1RenderTarget *render_target,
+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;
-HRESULT d2d_bitmap_brush_init(struct d2d_brush *brush, struct d2d_d3d_render_target *render_target,
+HRESULT 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;
 void d2d_brush_bind_resources(struct d2d_brush *brush, struct d2d_d3d_render_target *render_target,
diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c
index 438fced..6737948 100644
--- a/dlls/d2d1/render_target.c
+++ b/dlls/d2d1/render_target.c
@@ -426,7 +426,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapBrush(ID2D1Re
     if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    if (FAILED(hr = d2d_bitmap_brush_init(object, render_target, bitmap, bitmap_brush_desc, brush_desc)))
+    if (FAILED(hr = d2d_bitmap_brush_init(object, render_target->factory, bitmap, bitmap_brush_desc, brush_desc)))
     {
         WARN("Failed to initialize brush, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -442,6 +442,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapBrush(ID2D1Re
 static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateSolidColorBrush(ID2D1RenderTarget *iface,
         const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush)
 {
+    struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
     struct d2d_brush *object;
 
     TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
@@ -449,7 +450,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateSolidColorBrush(ID2
     if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    d2d_solid_color_brush_init(object, iface, color, desc);
+    d2d_solid_color_brush_init(object, render_target->factory, color, desc);
 
     TRACE("Created brush %p.\n", object);
     *brush = (ID2D1SolidColorBrush *)&object->ID2D1Brush_iface;
@@ -487,6 +488,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLinearGradientBrush
         const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
         ID2D1GradientStopCollection *gradient, ID2D1LinearGradientBrush **brush)
 {
+    struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
     struct d2d_brush *object;
 
     TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
@@ -495,7 +497,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateLinearGradientBrush
     if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    d2d_linear_gradient_brush_init(object, iface, gradient_brush_desc, brush_desc, gradient);
+    d2d_linear_gradient_brush_init(object, render_target->factory, gradient_brush_desc, brush_desc, gradient);
 
     TRACE("Created brush %p.\n", object);
     *brush = (ID2D1LinearGradientBrush *)&object->ID2D1Brush_iface;




More information about the wine-cvs mailing list