Skip to content

Commit ee8f04c

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 # Conflicts: # terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/TextLineRenderer.java
1 parent 3750de9 commit ee8f04c

2 files changed

Lines changed: 12 additions & 18 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: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.eclipse.swt.graphics.Color;
2222
import org.eclipse.swt.graphics.Font;
2323
import org.eclipse.swt.graphics.GC;
24-
import org.eclipse.swt.graphics.Image;
2524
import org.eclipse.swt.graphics.Point;
2625
import org.eclipse.swt.graphics.RGB;
2726
import org.eclipse.terminal.connector.Logger;
@@ -61,21 +60,19 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
6160
if (width <= 0 || height <= 0) {
6261
return;
6362
}
64-
Image buffer = new Image(gc.getDevice(), width, height);
65-
GC doubleBufferGC = new GC(buffer);
6663
if (line < 0 || line >= getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth()
6764
|| colFirst - colLast == 0) {
68-
fillBackground(doubleBufferGC, 0, 0, width, height);
65+
fillBackground(gc, x, y, width, height);
6966
} else {
7067
colLast = Math.min(colLast, getTerminalText().getWidth());
7168
LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst);
7269
for (int i = 0; i < segments.length; i++) {
7370
LineSegment segment = segments[i];
7471
TerminalStyle style = segment.getStyle();
75-
setupGC(doubleBufferGC, style);
72+
setupGC(gc, style);
7673
String text = segment.getText();
77-
drawText(doubleBufferGC, 0, 0, colFirst, segment.getColumn(), text);
78-
drawCursor(model, doubleBufferGC, line, 0, 0, colFirst);
74+
drawText(gc, x, y, colFirst, segment.getColumn(), text);
75+
drawCursor(model, gc, line, x, y, colFirst);
7976
}
8077
if (fModel.hasHoverSelection(line)) {
8178
if (DEBUG_HOVER) {
@@ -87,14 +84,14 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
8784
int colEnd = line == hsEnd.y ? hsEnd.x : getTerminalText().getWidth();
8885
if (colStart < colEnd) {
8986
RGB defaultFg = fStyleMap.getForegrondRGB(null);
90-
doubleBufferGC.setForeground(new Color(doubleBufferGC.getDevice(), defaultFg));
91-
drawUnderline(doubleBufferGC, colStart, colEnd);
87+
gc.setForeground(new Color(gc.getDevice(), defaultFg));
88+
drawUnderline(gc, x, y, colStart, colEnd);
9289
}
9390
}
9491
if (fModel.hasLineSelection(line)) {
9592
TerminalStyle style = TerminalStyle.getStyle(TerminalColor.SELECTION_FOREGROUND,
9693
TerminalColor.SELECTION_BACKGROUND);
97-
setupGC(doubleBufferGC, style);
94+
setupGC(gc, style);
9895
Point start = model.getSelectionStart();
9996
Point end = model.getSelectionEnd();
10097
char[] chars = model.getTerminalText().getChars(line);
@@ -113,14 +110,11 @@ public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int
113110
len = Math.min(len, chars.length - offset);
114111
if (len > 0) {
115112
String text = new String(chars, offset, len);
116-
drawText(doubleBufferGC, 0, 0, colFirst, offset, text);
113+
drawText(gc, x, y, colFirst, offset, text);
117114
}
118115
}
119116
}
120117
}
121-
gc.drawImage(buffer, x, y);
122-
doubleBufferGC.dispose();
123-
buffer.dispose();
124118
}
125119

126120
private void fillBackground(GC gc, int x, int y, int width, int height) {
@@ -186,9 +180,9 @@ private void drawText(GC gc, int x, int y, int colFirst, int col, String text) {
186180
* @param colStart Starting text column to underline (inclusive)
187181
* @param colEnd Ending text column to underline (inclusive)
188182
*/
189-
private void drawUnderline(GC gc, int colStart, int colEnd) {
190-
int y = getCellHeight() - 1;
191-
int x = getCellWidth() * colStart;
183+
private void drawUnderline(GC gc, int xOffset, int yOffset, int colStart, int colEnd) {
184+
int y = yOffset + getCellHeight() - 1;
185+
int x = xOffset + getCellWidth() * colStart;
192186

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

0 commit comments

Comments
 (0)