Skip to content

Commit 0e4de06

Browse files
committed
Make double buffering of Terminal adopt to higher monitor zooms
The terminal implementation uses a custom double buffering implementation for rendering the current line. On most Platforms (Linux and MacOS) the current implementation will always render the double-buffered image at 100% zoom, even if the target zoom is higher. This change adapts the implementation to directly render into the actual control and enable native double buffering for the control instead. This ensures that the contents are rendered at the actual target zoom, producing sharper results on HiDPI monitors when using MacOS or Linux. Fixes #2295 Fixes #2191
1 parent c02addc commit 0e4de06

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/TextCanvas.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private enum SelectionMode {
101101
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
102102
*/
103103
public TextCanvas(Composite parent, ITextCanvasModel model, int style, ILinelRenderer cellRenderer) {
104-
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL);
104+
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED);
105105
fCellRenderer = cellRenderer;
106106
setCellWidth(fCellRenderer.getCellWidth());
107107
setCellHeight(fCellRenderer.getCellHeight());

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/TextLineRenderer.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.eclipse.swt.graphics.Color;
2323
import org.eclipse.swt.graphics.Font;
2424
import org.eclipse.swt.graphics.GC;
25-
import org.eclipse.swt.graphics.Image;
2625
import org.eclipse.swt.graphics.Point;
2726
import org.eclipse.swt.graphics.RGB;
2827
import org.eclipse.terminal.connector.Logger;
@@ -57,27 +56,25 @@ public int getCellHeight() {
5756

5857
@Override
5958
public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast) {
59+
gc.setAntialias(SWT.ON);
6060
int width = getCellWidth() * (colLast - colFirst);
6161
int height = getCellHeight();
6262
if (width <= 0 || height <= 0) {
6363
return;
6464
}
65-
Image buffer = new Image(gc.getDevice(), width, height);
66-
GC doubleBufferGC = new GC(buffer);
67-
doubleBufferGC.setAntialias(SWT.ON);
6865
if (line < 0 || line >= getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth()
6966
|| colFirst - colLast == 0) {
70-
fillBackground(doubleBufferGC, 0, 0, width, height);
67+
fillBackground(gc, x, y, width, height);
7168
} else {
7269
colLast = Math.min(colLast, getTerminalText().getWidth());
7370
LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst);
7471
for (int i = 0; i < segments.length; i++) {
7572
LineSegment segment = segments[i];
7673
TerminalStyle style = segment.getStyle();
77-
setupGC(doubleBufferGC, style);
74+
setupGC(gc, style);
7875
String text = segment.getText();
79-
drawText(doubleBufferGC, 0, 0, colFirst, segment.getColumn(), text);
80-
drawCursor(model, doubleBufferGC, line, 0, 0, colFirst);
76+
drawText(gc, x, y, colFirst, segment.getColumn(), text);
77+
drawCursor(model, gc, line, x, y, colFirst);
8178
}
8279
if (fModel.hasHoverSelection(line)) {
8380
if (DEBUG_HOVER) {
@@ -89,14 +86,14 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
8986
int colEnd = line == hsEnd.y ? hsEnd.x : getTerminalText().getWidth();
9087
if (colStart < colEnd) {
9188
RGB defaultFg = fStyleMap.getForegrondRGB(null);
92-
doubleBufferGC.setForeground(new Color(doubleBufferGC.getDevice(), defaultFg));
93-
drawUnderline(doubleBufferGC, colStart, colEnd);
89+
gc.setForeground(new Color(gc.getDevice(), defaultFg));
90+
drawUnderline(gc, x, y, colStart, colEnd);
9491
}
9592
}
9693
if (fModel.hasLineSelection(line)) {
9794
TerminalStyle style = TerminalStyle.getStyle(TerminalColor.SELECTION_FOREGROUND,
9895
TerminalColor.SELECTION_BACKGROUND);
99-
setupGC(doubleBufferGC, style);
96+
setupGC(gc, style);
10097
Point start = model.getSelectionStart();
10198
Point end = model.getSelectionEnd();
10299
char[] chars = model.getTerminalText().getChars(line);
@@ -115,14 +112,11 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
115112
len = Math.min(len, chars.length - offset);
116113
if (len > 0) {
117114
String text = new String(chars, offset, len);
118-
drawText(doubleBufferGC, 0, 0, colFirst, offset, text);
115+
drawText(gc, x, y, colFirst, offset, text);
119116
}
120117
}
121118
}
122119
}
123-
gc.drawImage(buffer, x, y);
124-
doubleBufferGC.dispose();
125-
buffer.dispose();
126120
}
127121

128122
private void fillBackground(GC gc, int x, int y, int width, int height) {
@@ -188,9 +182,9 @@ private void drawText(GC gc, int x, int y, int colFirst, int col, String text) {
188182
* @param colStart Starting text column to underline (inclusive)
189183
* @param colEnd Ending text column to underline (inclusive)
190184
*/
191-
private void drawUnderline(GC gc, int colStart, int colEnd) {
192-
int y = getCellHeight() - 1;
193-
int x = getCellWidth() * colStart;
185+
private void drawUnderline(GC gc, int xOffset, int yOffset, int colStart, int colEnd) {
186+
int y = yOffset + getCellHeight() - 1;
187+
int x = xOffset + getCellWidth() * colStart;
194188

195189
// x2 is the right side of last column being underlined.
196190
int x2 = (colEnd + 1) * getCellWidth() - 1;

0 commit comments

Comments
 (0)