From 69ac0fbbbf25ecbc77330628fceed360f77f9193 Mon Sep 17 00:00:00 2001
From: Neil
Date: Mon, 24 Nov 2014 18:01:03 +1100
Subject: SC_TECHNOLOGY_DIRECTWRITEDC is another provisional mode for
DirectWrite drawing which may fix problems with sibling windows.
---
doc/ScintillaDoc.html | 19 +++++++++------
doc/ScintillaHistory.html | 5 ++++
include/Scintilla.h | 1 +
include/Scintilla.iface | 1 +
win32/ScintillaWin.cxx | 59 ++++++++++++++++++++++++++++++++++++-----------
5 files changed, 65 insertions(+), 20 deletions(-)
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 068dbdf9d..8b9ecb1b2 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -82,7 +82,7 @@
Scintilla Documentation
- Last edited 16 November 2014 NH
+ Last edited 24 November 2014 NH
There is an overview of the internal design of
Scintilla.
@@ -3270,16 +3270,20 @@ struct Sci_TextToFind {
SCI_GETTECHNOLOGY
The technology property allows choosing between different drawing APIs and options.
On most platforms, the only choice is SC_TECHNOLOGY_DEFAULT (0).
- On Windows Vista or later, SC_TECHNOLOGY_DIRECTWRITE (1) or
- SC_TECHNOLOGY_DIRECTWRITERETAIN (2)
+ On Windows Vista or later, SC_TECHNOLOGY_DIRECTWRITE (1),
+ SC_TECHNOLOGY_DIRECTWRITERETAIN (2), or
+ SC_TECHNOLOGY_DIRECTWRITEDC (3)
can be chosen to use the Direct2D and DirectWrite APIs for higher quality antialiased drawing.
SC_TECHNOLOGY_DIRECTWRITERETAIN differs from
SC_TECHNOLOGY_DIRECTWRITE by requesting that the frame
is retained after being presented which may prevent drawing failures on some cards and drivers.
+ SC_TECHNOLOGY_DIRECTWRITEDC differs from
+ SC_TECHNOLOGY_DIRECTWRITE by using DirectWrite to draw into a GDI DC.
Since Direct2D buffers drawing, Scintilla's buffering can be turned off with
SCI_SETBUFFEREDDRAW(0).
- Since SC_TECHNOLOGY_DIRECTWRITERETAIN
- is provisional, it may be changed or removed in a future release if a better solution is found.
+ Since SC_TECHNOLOGY_DIRECTWRITERETAIN and
+ SC_TECHNOLOGY_DIRECTWRITEDC
+ are provisional, they may be changed or removed in a future release if a better solution is found.
SCI_SETFONTQUALITY(int fontQuality)
SCI_GETFONTQUALITY
@@ -7459,8 +7463,9 @@ for line = lineStart to lineEnd do SCI_ENSUREVISIBLE(line) next
Provisional features are displayed in this document with a distinctive background colour.
There are currently no provisional messages.
- The SC_TECHNOLOGY_DIRECTWRITERETAIN value for
- SCI_SETTECHNOLOGY is provisional.
+ The SC_TECHNOLOGY_DIRECTWRITERETAIN and
+ SC_TECHNOLOGY_DIRECTWRITEDC values for
+ SCI_SETTECHNOLOGY are provisional.
Using C++11 <regex> is provisional.
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index ddd3c78a6..58c02178c 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -521,6 +521,11 @@
Bug #1643.
+ On Windows another DirectWrite mode SC_TECHNOLOGY_DIRECTWRITEDC added
+ which may avoid drawing failures in some circumstances by drawing into a GDI DC.
+ This feature is provisional and may be changed or removed if a better solution is found.
+
+
On Windows, avoid processing mouse move events where the mouse has not moved as these can
cause unexpected dwell start notifications.
Bug #1670.
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 9779cfee6..deaede845 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -899,6 +899,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SC_TECHNOLOGY_DEFAULT 0
#define SC_TECHNOLOGY_DIRECTWRITE 1
#define SC_TECHNOLOGY_DIRECTWRITERETAIN 2
+#define SC_TECHNOLOGY_DIRECTWRITEDC 3
#define SCI_SETTECHNOLOGY 2630
#define SCI_GETTECHNOLOGY 2631
#define SCI_CREATELOADER 2632
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index e8c96591b..ca54c65ee 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2366,6 +2366,7 @@ fun void ScrollToEnd=2629(,)
val SC_TECHNOLOGY_DEFAULT=0
val SC_TECHNOLOGY_DIRECTWRITE=1
val SC_TECHNOLOGY_DIRECTWRITERETAIN=2
+val SC_TECHNOLOGY_DIRECTWRITEDC=3
# Set the technology used.
set void SetTechnology=2630(int technology,)
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 237f8e17a..bd205e370 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -210,7 +210,7 @@ class ScintillaWin :
static ATOM callClassAtom;
#if defined(USE_D2D)
- ID2D1HwndRenderTarget *pRenderTarget;
+ ID2D1RenderTarget *pRenderTarget;
bool renderTargetValid;
#endif
@@ -222,7 +222,7 @@ class ScintillaWin :
virtual void Initialise();
virtual void Finalise();
#if defined(USE_D2D)
- void EnsureRenderTarget();
+ void EnsureRenderTarget(HDC hdc);
void DropRenderTarget();
#endif
HWND MainHWND();
@@ -441,7 +441,7 @@ void ScintillaWin::Finalise() {
#if defined(USE_D2D)
-void ScintillaWin::EnsureRenderTarget() {
+void ScintillaWin::EnsureRenderTarget(HDC hdc) {
if (!renderTargetValid) {
DropRenderTarget();
renderTargetValid = true;
@@ -455,12 +455,6 @@ void ScintillaWin::EnsureRenderTarget() {
// Create a Direct2D render target.
#if 1
- D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
- dhrtp.hwnd = hw;
- dhrtp.pixelSize = size;
- dhrtp.presentOptions = (technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
- D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
-
D2D1_RENDER_TARGET_PROPERTIES drtp;
drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
@@ -470,7 +464,32 @@ void ScintillaWin::EnsureRenderTarget() {
drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
- pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pRenderTarget);
+ if (technology == SC_TECHNOLOGY_DIRECTWRITEDC) {
+ // Explicit pixel format needed.
+ drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
+ D2D1_ALPHA_MODE_IGNORE);
+
+ ID2D1DCRenderTarget *pDCRT = NULL;
+ HRESULT hr = pD2DFactory->CreateDCRenderTarget(&drtp, &pDCRT);
+ if (FAILED(hr)) {
+ Platform::DebugPrintf("Failed CreateDCRenderTarget 0x%x\n", hr);
+ }
+ pRenderTarget = pDCRT;
+
+ } else {
+ D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
+ dhrtp.hwnd = hw;
+ dhrtp.pixelSize = size;
+ dhrtp.presentOptions = (technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
+ D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
+
+ ID2D1HwndRenderTarget *pHwndRenderTarget = NULL;
+ HRESULT hr = pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pHwndRenderTarget);
+ if (FAILED(hr)) {
+ Platform::DebugPrintf("Failed CreateHwndRenderTarget 0x%x\n", hr);
+ }
+ pRenderTarget = pHwndRenderTarget;
+ }
#else
pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(
@@ -484,6 +503,16 @@ void ScintillaWin::EnsureRenderTarget() {
// need to be recreated.
DropGraphics(false);
}
+
+ if (technology == SC_TECHNOLOGY_DIRECTWRITEDC) {
+ RECT rcWindow;
+ GetClientRect(MainHWND(), &rcWindow);
+ HRESULT hr = static_cast(pRenderTarget)->BindDC(hdc, &rcWindow);
+ if (FAILED(hr)) {
+ Platform::DebugPrintf("BindDC failed 0x%x\n", hr);
+ DropRenderTarget();
+ }
+ }
}
void ScintillaWin::DropRenderTarget() {
@@ -638,7 +667,7 @@ LRESULT ScintillaWin::WndPaint(uptr_t wParam) {
}
} else {
#if defined(USE_D2D)
- EnsureRenderTarget();
+ EnsureRenderTarget(pps->hdc);
AutoSurface surfaceWindow(pRenderTarget, this);
if (surfaceWindow) {
pRenderTarget->BeginDraw();
@@ -1413,6 +1442,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
case SCI_SETTECHNOLOGY:
if ((wParam == SC_TECHNOLOGY_DEFAULT) ||
(wParam == SC_TECHNOLOGY_DIRECTWRITERETAIN) ||
+ (wParam == SC_TECHNOLOGY_DIRECTWRITEDC) ||
(wParam == SC_TECHNOLOGY_DIRECTWRITE)) {
if (technology != static_cast(wParam)) {
if (static_cast(wParam) > SC_TECHNOLOGY_DEFAULT) {
@@ -1424,6 +1454,9 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
return 0;
#endif
}
+#if defined(USE_D2D)
+ DropRenderTarget();
+#endif
technology = static_cast(wParam);
// Invalidate all cached information including layout.
DropGraphics(true);
@@ -2549,7 +2582,7 @@ void ScintillaWin::HorizontalScrollMessage(WPARAM wParam) {
* This paint will not be abandoned.
*/
void ScintillaWin::FullPaint() {
- if (technology == SC_TECHNOLOGY_DEFAULT) {
+ if ((technology == SC_TECHNOLOGY_DEFAULT) || (technology == SC_TECHNOLOGY_DIRECTWRITEDC)) {
HDC hdc = ::GetDC(MainHWND());
FullPaintDC(hdc);
::ReleaseDC(MainHWND(), hdc);
@@ -2574,7 +2607,7 @@ void ScintillaWin::FullPaintDC(HDC hdc) {
}
} else {
#if defined(USE_D2D)
- EnsureRenderTarget();
+ EnsureRenderTarget(hdc);
AutoSurface surfaceWindow(pRenderTarget, this);
if (surfaceWindow) {
pRenderTarget->BeginDraw();
--
cgit v1.2.3