Nikolay Sivov : dwrite: Make IDWriteGdiInterop1 a part of a factory.

Alexandre Julliard julliard at wine.codeweavers.com
Tue May 3 11:15:34 CDT 2016


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue May  3 12:56:57 2016 +0300

dwrite: Make IDWriteGdiInterop1 a part of a factory.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/dwrite_private.h |  9 +++++++--
 dlls/dwrite/gdiinterop.c     | 31 ++++++-------------------------
 dlls/dwrite/main.c           | 17 +++--------------
 3 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index b852d3c..3dc29a1 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -111,6 +111,12 @@ static inline FLOAT get_scaled_advance_width(INT32 advance, FLOAT emSize, const
     return (FLOAT)advance * emSize / (FLOAT)metrics->designUnitsPerEm;
 }
 
+struct gdiinterop
+{
+    IDWriteGdiInterop1 IDWriteGdiInterop1_iface;
+    IDWriteFactory3 *factory;
+};
+
 struct textlayout_desc
 {
     IDWriteFactory3 *factory;
@@ -146,8 +152,7 @@ extern HRESULT create_textformat(const WCHAR*,IDWriteFontCollection*,DWRITE_FONT
 extern HRESULT create_textlayout(const struct textlayout_desc*,IDWriteTextLayout**) DECLSPEC_HIDDEN;
 extern HRESULT create_trimmingsign(IDWriteFactory3*,IDWriteTextFormat*,IDWriteInlineObject**) DECLSPEC_HIDDEN;
 extern HRESULT create_typography(IDWriteTypography**) DECLSPEC_HIDDEN;
-extern HRESULT create_gdiinterop(IDWriteFactory3*,IDWriteGdiInterop1**) DECLSPEC_HIDDEN;
-extern void    release_gdiinterop(IDWriteGdiInterop1*) DECLSPEC_HIDDEN;
+extern void    gdiinterop_init(struct gdiinterop*,IDWriteFactory3*) DECLSPEC_HIDDEN;
 extern HRESULT create_localizedstrings(IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
 extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
 extern HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **strings) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c
index ede1a12..e14dfa8 100644
--- a/dlls/dwrite/gdiinterop.c
+++ b/dlls/dwrite/gdiinterop.c
@@ -2,7 +2,7 @@
  *    GDI Interop
  *
  * Copyright 2011 Huw Davies
- * Copyright 2012, 2014 Nikolay Sivov for CodeWeavers
+ * Copyright 2012, 2014-2016 Nikolay Sivov for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -32,11 +32,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
 
-struct gdiinterop {
-    IDWriteGdiInterop1 IDWriteGdiInterop1_iface;
-    IDWriteFactory3 *factory;
-};
-
 struct dib_data {
     DWORD *ptr;
     int stride;
@@ -929,24 +924,10 @@ static const struct IDWriteGdiInterop1Vtbl gdiinteropvtbl = {
     gdiinterop1_GetMatchingFontsByLOGFONT
 };
 
-HRESULT create_gdiinterop(IDWriteFactory3 *factory, IDWriteGdiInterop1 **ret)
-{
-    struct gdiinterop *This;
-
-    *ret = NULL;
-
-    This = heap_alloc(sizeof(struct gdiinterop));
-    if (!This) return E_OUTOFMEMORY;
-
-    This->IDWriteGdiInterop1_iface.lpVtbl = &gdiinteropvtbl;
-    This->factory = factory;
-
-    *ret= &This->IDWriteGdiInterop1_iface;
-    return S_OK;
-}
-
-void release_gdiinterop(IDWriteGdiInterop1 *iface)
+void gdiinterop_init(struct gdiinterop *interop, IDWriteFactory3 *factory)
 {
-    struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
-    heap_free(interop);
+    interop->IDWriteGdiInterop1_iface.lpVtbl = &gdiinteropvtbl;
+    /* Interop is a part of a factory, sharing its refcount.
+       GetGdiInterop() will AddRef() on every call. */
+    interop->factory = factory;
 }
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c
index 12d8c72..0ecda11 100644
--- a/dlls/dwrite/main.c
+++ b/dlls/dwrite/main.c
@@ -525,7 +525,7 @@ struct dwritefactory {
 
     IDWriteFontCollection *system_collection;
     IDWriteFontCollection *eudc_collection;
-    IDWriteGdiInterop1 *gdiinterop;
+    struct gdiinterop interop;
     IDWriteFontFallback *fallback;
 
     IDWriteLocalFontFileLoader* localfontfileloader;
@@ -586,8 +586,6 @@ static void release_dwritefactory(struct dwritefactory *factory)
         IDWriteFontCollection_Release(factory->system_collection);
     if (factory->eudc_collection)
         IDWriteFontCollection_Release(factory->eudc_collection);
-    if (factory->gdiinterop)
-        release_gdiinterop(factory->gdiinterop);
     if (factory->fallback)
         release_system_fontfallback(factory->fallback);
     heap_free(factory);
@@ -1057,17 +1055,8 @@ static HRESULT WINAPI dwritefactory_GetGdiInterop(IDWriteFactory3 *iface, IDWrit
 
     TRACE("(%p)->(%p)\n", This, gdi_interop);
 
-    *gdi_interop = NULL;
-
-    if (!This->gdiinterop) {
-        HRESULT hr = create_gdiinterop(iface, &This->gdiinterop);
-        if (FAILED(hr))
-            return hr;
-    }
-
-    *gdi_interop = (IDWriteGdiInterop*)This->gdiinterop;
+    *gdi_interop = (IDWriteGdiInterop*)&This->interop.IDWriteGdiInterop1_iface;
     IDWriteGdiInterop_AddRef(*gdi_interop);
-
     return S_OK;
 }
 
@@ -1489,7 +1478,7 @@ static void init_dwritefactory(struct dwritefactory *factory, DWRITE_FACTORY_TYP
     factory->localfontfileloader = NULL;
     factory->system_collection = NULL;
     factory->eudc_collection = NULL;
-    factory->gdiinterop = NULL;
+    gdiinterop_init(&factory->interop, &factory->IDWriteFactory3_iface);
     factory->fallback = NULL;
 
     list_init(&factory->collection_loaders);




More information about the wine-cvs mailing list