Skip to content

Commit 7f88b65

Browse files
committed
patch 8.0.1390: DirectX scrolling can be slow, vertical positioning is off
Problem: DirectX scrolling can be slow, vertical positioning is off. Solution: Make scroll slightly faster when using "scrlines:1". Fix y position of displayed text. Fix DirectX with non-utf8 encoding. (Ken Takata, closes #2440)
1 parent a6d4849 commit 7f88b65

6 files changed

Lines changed: 89 additions & 28 deletions

File tree

src/INSTALLpc.txt

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ Contents:
3434
11. Building with Ruby support
3535
12. Building with Tcl support
3636
13. Building with Terminal support
37-
14. Windows 3.1
38-
15. MS-DOS
37+
14. Building with DirectX (DirectWrite) support
38+
15. Windows 3.1
39+
16. MS-DOS
3940

40-
16. Installing after building from sources
41+
17. Installing after building from sources
4142

4243

4344
The currently recommended way (that means it has been verified to work) is
@@ -787,25 +788,59 @@ E.g. When using MSVC:
787788

788789
nmake -f Make_mvc.mak TERMINAL=yes
789790

790-
Or when using MinGW (as one line):
791+
Or when using MinGW:
791792

792793
mingw32-make -f Make_ming.mak TERMINAL=yes
793794

794795

795-
14. Windows 3.1x
796+
14. Building with DirectX (DirectWrite) support
797+
===============================================
798+
799+
Vim with DirectX (DirectWrite) support can be built with either MSVC or MinGW.
800+
This requires dwrite_2.h and some other header files which come with Windows
801+
SDK 8.1 or later (or MinGW-w64), if you want to enable color emoji support.
802+
This also requires MBYTE=yes which is enabled by default.
803+
804+
A) Using MSVC
805+
806+
If you use MSVC 2013 or later, Windows SDK 8.1 or later is used by default.
807+
You just need to specify DIRECTX=yes:
808+
809+
nmake -f Make_mvc.mak DIRECTX=yes
810+
811+
If you use MSVC 2012 or earlier, the required header files are not available
812+
by default. However, you can use the header files from newer SDKs with older
813+
compilers. E.g.:
814+
815+
set "INCLUDE=%INCLUDE%;C:\Program Files (x86)\Windows Kits\8.1\Include\um"
816+
nmake -f Make_mvc.mak DIRECTX=yes
817+
818+
If you don't need color emoji support, only dwrite.h is required. You can use
819+
older compilers (e.g. VC2010) without Windows SDK 8.1. E.g.:
820+
821+
nmake -f Make_mvc.mak DIRECTX=yes COLOR_EMOJI=no
822+
823+
B) Using MinGW-w64
824+
825+
Just set DIRECTX to yes:
826+
827+
mingw32-make -f Make_ming.mak DIRECTX=yes
828+
829+
830+
15. Windows 3.1x
796831
================
797832

798833
The Windows 3.1x support was removed in patch 7.4.1364.
799834

800835

801-
15. MS-DOS
836+
16. MS-DOS
802837
==========
803838

804839
The MS-DOS support was removed in patch 7.4.1399. Only very old Vim versions
805840
work on MS-DOS because of the limited amount of memory available.
806841

807842

808-
16. Installing after building from sources
843+
17. Installing after building from sources
809844
==========================================
810845

811846
[provided by Michael Soyka, updated by Ken Takata]

src/Make_cyg_ming.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ endif
588588
ifeq ($(DIRECTX),yes)
589589
# Only allow DirectWrite for a GUI build.
590590
ifeq (yes, $(GUI))
591-
DEFINES += -DFEAT_DIRECTX -DDYNAMIC_DIRECTX
591+
DEFINES += -DFEAT_DIRECTX -DDYNAMIC_DIRECTX -DFEAT_DIRECTX_COLOR_EMOJI
592592
endif
593593
endif
594594

src/Make_mvc.mak

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
#
2626
# GUI interface: GUI=yes (default is no)
2727
#
28-
# GUI with DirectWrite(DirectX): DIRECTX=yes
29-
# (default is no, requires GUI=yes)
28+
# GUI with DirectWrite (DirectX): DIRECTX=yes
29+
# (default is no, requires GUI=yes and MBYTE=yes)
30+
#
31+
# Color emoji support: COLOR_EMOJI=yes
32+
# (default is yes if DIRECTX=yes, requires WinSDK 8.1 or later.)
3033
#
3134
# OLE interface: OLE=yes (usually with GUI=yes)
3235
#
33-
# Multibyte support: MBYTE=yes (default is no)
36+
# Multibyte support: MBYTE=yes (default is yes for NORMAL, BIG, HUGE)
3437
#
3538
# IME support: IME=yes (requires GUI=yes)
3639
# DYNAMIC_IME=[yes or no] (to load the imm32.dll dynamically, default
@@ -419,9 +422,12 @@ NBDEBUG_SRC = nbdebug.c
419422
NETBEANS_LIB = WSock32.lib
420423
!endif
421424

422-
# DirectWrite(DirectX)
425+
# DirectWrite (DirectX)
423426
!if "$(DIRECTX)" == "yes"
424427
DIRECTX_DEFS = -DFEAT_DIRECTX -DDYNAMIC_DIRECTX
428+
!if "$(COLOR_EMOJI)" != "no"
429+
DIRECTX_DEFS = $(DIRECTX_DEFS) -DFEAT_DIRECTX_COLOR_EMOJI
430+
!endif
425431
DIRECTX_INCL = gui_dwrite.h
426432
DIRECTX_OBJ = $(OUTDIR)\gui_dwrite.obj
427433
!endif

src/gui_dwrite.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
# define _Outptr_
3939
#endif
4040

41-
#include <dwrite_2.h>
41+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
42+
# include <dwrite_2.h>
43+
#else
44+
# include <dwrite.h>
45+
#endif
4246

4347
#include "gui_dwrite.h"
4448

@@ -284,7 +288,9 @@ struct DWriteContext {
284288
ID2D1SolidColorBrush *mBrush;
285289

286290
IDWriteFactory *mDWriteFactory;
291+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
287292
IDWriteFactory2 *mDWriteFactory2;
293+
#endif
288294

289295
IDWriteGdiInterop *mGdiInterop;
290296
IDWriteRenderingParams *mRenderingParams;
@@ -481,6 +487,7 @@ class TextRenderer FINAL : public IDWriteTextRenderer
481487
AdjustedGlyphRun adjustedGlyphRun(glyphRun, context->cellWidth,
482488
context->offsetX);
483489

490+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
484491
if (pDWC_->mDWriteFactory2 != NULL)
485492
{
486493
IDWriteColorGlyphRunEnumerator *enumerator = NULL;
@@ -517,6 +524,7 @@ class TextRenderer FINAL : public IDWriteTextRenderer
517524
return S_OK;
518525
}
519526
}
527+
#endif
520528

521529
// Draw by IDWriteFactory (without color emoji)
522530
pDWC_->mRT->DrawGlyphRun(
@@ -589,7 +597,9 @@ DWriteContext::DWriteContext() :
589597
mGDIRT(NULL),
590598
mBrush(NULL),
591599
mDWriteFactory(NULL),
600+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
592601
mDWriteFactory2(NULL),
602+
#endif
593603
mGdiInterop(NULL),
594604
mRenderingParams(NULL),
595605
mFontCache(8),
@@ -618,6 +628,7 @@ DWriteContext::DWriteContext() :
618628
mDWriteFactory);
619629
}
620630

631+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
621632
if (SUCCEEDED(hr))
622633
{
623634
DWriteCreateFactory(
@@ -626,6 +637,7 @@ DWriteContext::DWriteContext() :
626637
reinterpret_cast<IUnknown**>(&mDWriteFactory2));
627638
_RPT1(_CRT_WARN, "IDWriteFactory2: %s\n", SUCCEEDED(hr) ? "available" : "not available");
628639
}
640+
#endif
629641

630642
if (SUCCEEDED(hr))
631643
{
@@ -647,7 +659,9 @@ DWriteContext::~DWriteContext()
647659
SafeRelease(&mRenderingParams);
648660
SafeRelease(&mGdiInterop);
649661
SafeRelease(&mDWriteFactory);
662+
#ifdef FEAT_DIRECTX_COLOR_EMOJI
650663
SafeRelease(&mDWriteFactory2);
664+
#endif
651665
SafeRelease(&mBrush);
652666
SafeRelease(&mGDIRT);
653667
SafeRelease(&mRT);
@@ -995,7 +1009,7 @@ DWriteContext::DrawText(const WCHAR *text, int len,
9951009

9961010
TextRenderer renderer(this);
9971011
TextRendererContext context = { color, FLOAT(cellWidth), 0.0f };
998-
textLayout->Draw(&context, &renderer, FLOAT(x), FLOAT(y));
1012+
textLayout->Draw(&context, &renderer, FLOAT(x), FLOAT(y) - 0.5f);
9991013
}
10001014

10011015
SafeRelease(&textLayout);

src/gui_w32.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
#endif
3131

3232
#if defined(FEAT_DIRECTX)
33+
# ifndef FEAT_MBYTE
34+
# error FEAT_MBYTE is required for FEAT_DIRECTX.
35+
# endif
3336
static DWriteContext *s_dwc = NULL;
3437
static int s_directx_enabled = 0;
3538
static int s_directx_load_attempted = 0;
3639
static int s_directx_scrlines = 0;
37-
# define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL)
40+
# define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL && enc_utf8)
3841
static int directx_enabled(void);
3942
static void directx_binddc(void);
4043
#endif
@@ -47,7 +50,7 @@ static int gui_mswin_get_menu_height(int fix_window);
4750
int
4851
gui_mch_set_rendering_options(char_u *s)
4952
{
50-
#ifdef FEAT_DIRECTX
53+
# ifdef FEAT_DIRECTX
5154
char_u *p, *q;
5255

5356
int dx_enable = 0;
@@ -159,9 +162,9 @@ gui_mch_set_rendering_options(char_u *s)
159162
s_directx_scrlines = dx_scrlines;
160163

161164
return OK;
162-
#else
165+
# else
163166
return FAIL;
164-
#endif
167+
# endif
165168
}
166169
#endif
167170

@@ -3140,7 +3143,8 @@ gui_mch_delete_lines(
31403143
{
31413144
if (s_directx_scrlines > 0 && s_directx_scrlines <= num_lines)
31423145
{
3143-
RedrawWindow(s_textArea, &rc, NULL, RDW_INVALIDATE);
3146+
gui_redraw(rc.left, rc.top,
3147+
rc.right - rc.left + 1, rc.bottom - rc.top + 1);
31443148
use_redraw = 1;
31453149
}
31463150
else
@@ -3152,9 +3156,9 @@ gui_mch_delete_lines(
31523156
intel_gpu_workaround();
31533157
ScrollWindowEx(s_textArea, 0, -num_lines * gui.char_height,
31543158
&rc, &rc, NULL, NULL, get_scroll_flags());
3159+
UpdateWindow(s_textArea);
31553160
}
31563161

3157-
UpdateWindow(s_textArea);
31583162
/* This seems to be required to avoid the cursor disappearing when
31593163
* scrolling such that the cursor ends up in the top-left character on
31603164
* the screen... But why? (Webb) */
@@ -3190,7 +3194,8 @@ gui_mch_insert_lines(
31903194
{
31913195
if (s_directx_scrlines > 0 && s_directx_scrlines <= num_lines)
31923196
{
3193-
RedrawWindow(s_textArea, &rc, NULL, RDW_INVALIDATE);
3197+
gui_redraw(rc.left, rc.top,
3198+
rc.right - rc.left + 1, rc.bottom - rc.top + 1);
31943199
use_redraw = 1;
31953200
}
31963201
else
@@ -3204,10 +3209,9 @@ gui_mch_insert_lines(
32043209
* off-screen. How do we avoid it when it's not needed? */
32053210
ScrollWindowEx(s_textArea, 0, num_lines * gui.char_height,
32063211
&rc, &rc, NULL, NULL, get_scroll_flags());
3212+
UpdateWindow(s_textArea);
32073213
}
32083214

3209-
UpdateWindow(s_textArea);
3210-
32113215
gui_clear_block(row, gui.scroll_region_left,
32123216
row + num_lines - 1, gui.scroll_region_right);
32133217
}
@@ -6401,13 +6405,13 @@ gui_mch_draw_string(
64016405
if (text[n] >= 0x80)
64026406
break;
64036407

6404-
#if defined(FEAT_DIRECTX)
6408+
# if defined(FEAT_DIRECTX)
64056409
/* Quick hack to enable DirectWrite. To use DirectWrite (antialias), it is
64066410
* required that unicode drawing routine, currently. So this forces it
64076411
* enabled. */
6408-
if (enc_utf8 && IS_ENABLE_DIRECTX())
6412+
if (IS_ENABLE_DIRECTX())
64096413
n = 0; /* Keep n < len, to enter block for unicode. */
6410-
#endif
6414+
# endif
64116415

64126416
/* Check if the Unicode buffer exists and is big enough. Create it
64136417
* with the same length as the multi-byte string, the number of wide
@@ -6480,7 +6484,7 @@ gui_mch_draw_string(
64806484
i += utf_ptr2len_len(text + i, len - i);
64816485
++clen;
64826486
}
6483-
#if defined(FEAT_DIRECTX)
6487+
# if defined(FEAT_DIRECTX)
64846488
if (IS_ENABLE_DIRECTX())
64856489
{
64866490
/* Add one to "cells" for italics. */
@@ -6490,7 +6494,7 @@ gui_mch_draw_string(
64906494
foptions, pcliprect, unicodepdy);
64916495
}
64926496
else
6493-
#endif
6497+
# endif
64946498
ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row),
64956499
foptions, pcliprect, unicodebuf, wlen, unicodepdy);
64966500
len = cells; /* used for underlining */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1390,
774776
/**/
775777
1389,
776778
/**/

0 commit comments

Comments
 (0)