summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-11-19 00:30:15 +0200
committerخالد حسني <khaled@aliftype.com>2022-11-19 12:43:51 +0100
commit042473d4b162c87a27a55e9b9f076b5fc479a55a (patch)
tree87f1a7ca683638f76360cb95a229cdfaff0e92de /vcl
parent0cf71ca47b463c0b944e31aa7bd66fdaf9097f8e (diff)
vcl: move creating DWriteFactory to a centeral place
We already have code in two places to create it, and I will need it in yet another place. Change-Id: I12dee85347a3894045c345b0ec9d5e02c493c218 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142956 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/skia/win/gdiimpl.hxx2
-rw-r--r--vcl/inc/win/salgdi.h7
-rw-r--r--vcl/skia/win/gdiimpl.cxx11
-rw-r--r--vcl/win/gdi/DWriteTextRenderer.cxx13
-rw-r--r--vcl/win/gdi/salgdi.cxx32
5 files changed, 45 insertions, 20 deletions
diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx
index 1977e7152080..92f873ca7d43 100644
--- a/vcl/inc/skia/win/gdiimpl.hxx
+++ b/vcl/inc/skia/win/gdiimpl.hxx
@@ -65,8 +65,6 @@ protected:
virtual void createWindowSurfaceInternal(bool forceRaster = false) override;
static sk_sp<SkTypeface> createDirectWriteTypeface(HDC hdc, HFONT hfont);
static void initFontInfo();
- inline static sal::systools::COMReference<IDWriteFactory> dwriteFactory;
- inline static sal::systools::COMReference<IDWriteGdiInterop> dwriteGdiInterop;
inline static sal::systools::COMReference<IDWriteFontSetBuilder> dwriteFontSetBuilder;
inline static sal::systools::COMReference<IDWriteFontCollection1> dwritePrivateCollection;
inline static sk_sp<SkFontMgr> dwriteFontMgr;
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 35d723b0bc90..db00ff03455a 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -30,6 +30,7 @@
#include <impfont.hxx>
#include <vcl/fontcapabilities.hxx>
#include <vcl/fontcharmap.hxx>
+#include <systools/win32/comtools.hxx>
#include <memory>
#include <unordered_set>
@@ -161,6 +162,10 @@ private:
RGNDATA* mpStdClipRgnData; // Cache Standard-ClipRegion-Data
int mnPenWidth; // line width
+ inline static sal::systools::COMReference<IDWriteFactory> mxDWriteFactory;
+ inline static sal::systools::COMReference<IDWriteGdiInterop> mxDWriteGdiInterop;
+ inline static bool bDWriteDone = false;
+
// just call both from setHDC!
void InitGraphics();
void DeInitGraphics();
@@ -189,6 +194,8 @@ public:
SCREEN
};
+ static void getDWriteFactory(IDWriteFactory** pFactory, IDWriteGdiInterop** pInterop = nullptr);
+
public:
HWND gethWnd();
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 692ad36b9eb2..74bc3cce5ec5 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -124,13 +124,12 @@ bool WinSkiaSalGraphicsImpl::RenderAndCacheNativeControl(CompatibleDC& rWhite, C
sk_sp<SkTypeface> WinSkiaSalGraphicsImpl::createDirectWriteTypeface(HDC hdc, HFONT hfont) try
{
using sal::systools::ThrowIfFailed;
+ IDWriteFactory* dwriteFactory;
+ IDWriteGdiInterop* dwriteGdiInterop;
+ WinSalGraphics::getDWriteFactory(&dwriteFactory, &dwriteGdiInterop);
if (!dwriteDone)
{
- ThrowIfFailed(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
- reinterpret_cast<IUnknown**>(&dwriteFactory)),
- SAL_WHERE);
- ThrowIfFailed(dwriteFactory->GetGdiInterop(&dwriteGdiInterop), SAL_WHERE);
- dwriteFontMgr = SkFontMgr_New_DirectWrite(dwriteFactory.get());
+ dwriteFontMgr = SkFontMgr_New_DirectWrite(dwriteFactory);
dwriteDone = true;
}
if (!dwriteFontMgr)
@@ -343,8 +342,6 @@ void WinSkiaSalGraphicsImpl::ClearDevFontCache()
dwriteFontMgr.reset();
dwriteFontSetBuilder.clear();
dwritePrivateCollection.clear();
- dwriteFactory.clear();
- dwriteGdiInterop.clear();
dwriteDone = false;
initFontInfo(); // get font info again, just in case
}
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx
index 64d49696b102..1e44d95ad2cb 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -101,8 +101,6 @@ HRESULT checkResult(HRESULT hr, const char* file, size_t line)
D2DWriteTextOutRenderer::D2DWriteTextOutRenderer(bool bRenderingModeNatural)
: mpD2DFactory(nullptr),
- mpDWriteFactory(nullptr),
- mpGdiInterop(nullptr),
mpRT(nullptr),
mRTProps(D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
@@ -110,14 +108,11 @@ D2DWriteTextOutRenderer::D2DWriteTextOutRenderer(bool bRenderingModeNatural)
mbRenderingModeNatural(bRenderingModeNatural),
meTextAntiAliasMode(D2DTextAntiAliasMode::Default)
{
+ WinSalGraphics::getDWriteFactory(&mpDWriteFactory, &mpGdiInterop);
HRESULT hr = S_OK;
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), nullptr, reinterpret_cast<void **>(&mpD2DFactory));
- hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&mpDWriteFactory));
if (SUCCEEDED(hr))
- {
- hr = mpDWriteFactory->GetGdiInterop(&mpGdiInterop);
hr = CreateRenderTarget(bRenderingModeNatural);
- }
meTextAntiAliasMode = lclGetSystemTextAntiAliasMode();
}
@@ -125,10 +120,6 @@ D2DWriteTextOutRenderer::~D2DWriteTextOutRenderer()
{
if (mpRT)
mpRT->Release();
- if (mpGdiInterop)
- mpGdiInterop->Release();
- if (mpDWriteFactory)
- mpDWriteFactory->Release();
if (mpD2DFactory)
mpD2DFactory->Release();
}
@@ -181,7 +172,7 @@ HRESULT D2DWriteTextOutRenderer::CreateRenderTarget(bool bRenderingModeNatural)
bool D2DWriteTextOutRenderer::Ready() const
{
- return mpGdiInterop && mpRT;
+ return mpRT;
}
HRESULT D2DWriteTextOutRenderer::BindDC(HDC hDC, tools::Rectangle const & rRect)
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index ee231f1ac7aa..c723ed1156ba 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -24,6 +24,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <comphelper/windowserrorstring.hxx>
#include <win/wincomp.hxx>
#include <win/saldata.hxx>
#include <win/salgdi.h>
@@ -755,6 +756,37 @@ void WinSalGraphics::GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY )
rDPIX = rDPIY = 600;
}
+void WinSalGraphics::getDWriteFactory(IDWriteFactory** pFactory, IDWriteGdiInterop** pInterop)
+{
+ if (!bDWriteDone)
+ {
+ HRESULT hr = S_OK;
+ hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(&mxDWriteFactory));
+ if (FAILED(hr))
+ {
+ SAL_WARN("vcl.fonts", "HRESULT 0x" << OUString::number(hr, 16) << ": "
+ << WindowsErrorStringFromHRESULT(hr));
+ abort();
+ }
+
+ hr = mxDWriteFactory->GetGdiInterop(&mxDWriteGdiInterop);
+ if (FAILED(hr))
+ {
+ SAL_WARN("vcl.fonts", "HRESULT 0x" << OUString::number(hr, 16) << ": "
+ << WindowsErrorStringFromHRESULT(hr));
+ abort();
+ }
+
+ bDWriteDone = true;
+ }
+
+ if (pFactory)
+ *pFactory = mxDWriteFactory.get();
+ if (pInterop)
+ *pInterop = mxDWriteGdiInterop.get();
+}
+
sal_uInt16 WinSalGraphics::GetBitCount() const
{
return mpImpl->GetBitCount();