aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-08-07 21:28:48 +1000
committernyamatongwe <unknown>2011-08-07 21:28:48 +1000
commita87f9b8b42dc830045972b772d61009f45bbf551 (patch)
tree45a2b329c4117a1b687775d67e251f2b4ee6e166
parentea07369a205b6a273e3c4b0e70ab16a93f6d9d9a (diff)
downloadscintilla-mirror-a87f9b8b42dc830045972b772d61009f45bbf551.tar.gz
Dynamically loading Direct2D and DirectWrite at run time so can run on Windows XP.
-rw-r--r--win32/PlatWin.cxx51
-rw-r--r--win32/PlatWin.h13
-rw-r--r--win32/ScintillaWin.cxx29
3 files changed, 51 insertions, 42 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index b0fbd2543..a1ae68b82 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -197,15 +197,42 @@ void Palette::Allocate(Window &) {
}
}
-static IDWriteFactory *pIDWriteFactory = 0;
-
-static void EnsureDWriteFactory() {
- // Construct
- if (!pIDWriteFactory) {
- DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
- __uuidof(IDWriteFactory),
- reinterpret_cast<IUnknown**>(&pIDWriteFactory));
+IDWriteFactory *pIDWriteFactory = 0;
+ID2D1Factory *pD2DFactory = 0;
+
+bool LoadD2D() {
+ static bool triedLoadingD2D = false;
+ static HMODULE hDLLD2D = 0;
+ static HMODULE hDLLDWrite = 0;
+ if (!triedLoadingD2D) {
+ typedef HRESULT (WINAPI *D2D1CFSig)(D2D1_FACTORY_TYPE factoryType, REFIID riid,
+ CONST D2D1_FACTORY_OPTIONS *pFactoryOptions, IUnknown **factory);
+ typedef HRESULT (WINAPI *DWriteCFSig)(DWRITE_FACTORY_TYPE factoryType, REFIID iid,
+ IUnknown **factory);
+
+ hDLLD2D = ::LoadLibrary(TEXT("D2D1.DLL"));
+ if (hDLLD2D) {
+ D2D1CFSig fnD2DCF = (D2D1CFSig)::GetProcAddress(hDLLD2D, "D2D1CreateFactory");
+ if (fnD2DCF) {
+ // A single threaded factory as Scintilla always draw on the GUI thread
+ fnD2DCF(D2D1_FACTORY_TYPE_SINGLE_THREADED,
+ __uuidof(ID2D1Factory),
+ 0,
+ reinterpret_cast<IUnknown**>(&pD2DFactory));
+ }
+ }
+ hDLLDWrite = ::LoadLibrary(TEXT("DWRITE.DLL"));
+ if (hDLLDWrite) {
+ DWriteCFSig fnDWCF = (DWriteCFSig)::GetProcAddress(hDLLDWrite, "DWriteCreateFactory");
+ if (fnDWCF) {
+ fnDWCF(DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(&pIDWriteFactory));
+ }
+ }
}
+ triedLoadingD2D = true;
+ return pIDWriteFactory && pD2DFactory;
}
struct FormatAndBaseline {
@@ -292,7 +319,6 @@ FontCached::FontCached(const char *faceName_, int characterSet_, float size_, in
SetLogFont(lf, faceName_, characterSet_, size_, weight_, italic_, extraFontFlag_);
hash = HashFont(faceName_, characterSet_, size_, weight_, italic_, extraFontFlag_);
fid = 0;
- EnsureDWriteFactory();
if (pIDWriteFactory) {
#ifdef OLD_CODE
HFONT fontSave = static_cast<HFONT>(::SelectObject(hdc, font_.GetID()));
@@ -508,9 +534,6 @@ public:
} //namespace Scintilla
#endif
-#pragma comment(lib, "d2d1.lib")
-#pragma comment(lib, "dwrite.lib")
-
SurfaceImpl::SurfaceImpl() :
unicodeMode(false),
hdc(0), hdcOwned(false),
@@ -563,11 +586,7 @@ void SurfaceImpl::Release() {
}
}
-// Ensures have pIDWriteFactory, and pRenderTarget
-// If any fail, pRenderTarget will be NULL
void SurfaceImpl::SetDWrite(HDC hdc) {
- // Construct
- EnsureDWriteFactory();
dpiScaleX = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f;
dpiScaleY = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0f;
}
diff --git a/win32/PlatWin.h b/win32/PlatWin.h
new file mode 100644
index 000000000..dc3f8e432
--- /dev/null
+++ b/win32/PlatWin.h
@@ -0,0 +1,13 @@
+// Scintilla source code edit control
+/** @file PlatWin.h
+ ** Implementation of platform facilities on Windows.
+ **/
+// Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+extern bool IsNT();
+extern void Platform_Initialise(void *hInstance);
+extern void Platform_Finalise();
+extern bool LoadD2D();
+extern ID2D1Factory *pD2DFactory;
+extern IDWriteFactory *pIDWriteFactory;
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 6bc770eed..f49b2bace 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -57,6 +57,7 @@
#include "Editor.h"
#include "ScintillaBase.h"
#include "UniConversion.h"
+#include "PlatWin.h"
#ifdef SCI_LEXER
#include "ExternalLexer.h"
@@ -90,11 +91,6 @@
#define SC_WIN_IDLE 5001
-// Functions imported from PlatWin
-extern bool IsNT();
-extern void Platform_Initialise(void *hInstance);
-extern void Platform_Finalise();
-
typedef BOOL (WINAPI *TrackMouseEventSig)(LPTRACKMOUSEEVENT);
// GCC has trouble with the standard COM ABI so do it the old C way with explicit vtables.
@@ -200,8 +196,6 @@ class ScintillaWin :
static HINSTANCE hInstance;
- IDWriteFactory *pIDWriteFactory;
- ID2D1Factory *pD2DFactory;
ID2D1HwndRenderTarget *pRenderTarget;
ScintillaWin(HWND hwnd);
@@ -359,8 +353,6 @@ ScintillaWin::ScintillaWin(HWND hwnd) {
sysCaretWidth = 0;
sysCaretHeight = 0;
- pIDWriteFactory = 0;
- pD2DFactory = 0;
pRenderTarget = 0;
keysAlwaysUnicode = false;
@@ -392,14 +384,7 @@ void ScintillaWin::Initialise() {
}
}
- if (!pIDWriteFactory) {
- DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
- __uuidof(IDWriteFactory),
- reinterpret_cast<IUnknown**>(&pIDWriteFactory));
- }
- if (!pD2DFactory) {
- D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
- }
+ LoadD2D();
}
void ScintillaWin::Finalise() {
@@ -407,14 +392,6 @@ void ScintillaWin::Finalise() {
SetTicking(false);
SetIdle(false);
DropRenderTarget();
- if (pIDWriteFactory) {
- pIDWriteFactory->Release();
- pIDWriteFactory = 0;
- }
- if (pD2DFactory) {
- pD2DFactory->Release();
- pD2DFactory = 0;
- }
::RevokeDragDrop(MainHWND());
if (SUCCEEDED(hrOle)) {
::OleUninitialize();
@@ -2780,7 +2757,7 @@ sptr_t PASCAL ScintillaWin::CTWndProc(
RECT rc;
GetClientRect(hWnd, &rc);
// Create a Direct2D render target.
- sciThis->pD2DFactory->CreateHwndRenderTarget(
+ pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hWnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)),
&pCTRenderTarget);