From 789ee1b8a8a938472f2a17a46d34820660df6ba2 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 25 Oct 2017 21:16:37 +0300 Subject: [PATCH] background-aware painting in editor dumb mode (2) --- .../openapi/editor/impl/EditorImpl.java | 21 ++++++++++++------- .../openapi/wm/impl/IdeBackgroundUtil.java | 6 ++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 8fae7b8aaaf6..18cd4b24ef49 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -1670,8 +1670,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi */ public void startDumb() { if (ApplicationManager.getApplication().isUnitTestMode()) return; + if (!Registry.is("editor.dumb.mode.available")) return; + putUserData(BUFFER, null); Rectangle rect = ((JViewport)myEditorComponent.getParent()).getViewRect(); - BufferedImage image = UIUtil.createImage(myEditorComponent, rect.width, rect.height, BufferedImage.TYPE_INT_ARGB); + // The LCD text loop is enabled only for opaque images + BufferedImage image = UIUtil.createImage(myEditorComponent, rect.width, rect.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = JBSwingUtilities.runGlobalCGTransform(myEditorComponent, image.createGraphics()); graphics.translate(-rect.x, -rect.y); graphics.setClip(rect.x, rect.y, rect.width, rect.height); @@ -1680,6 +1683,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi putUserData(BUFFER, image); } + public boolean isDumb() { + return getUserData(BUFFER) != null; + } + void paint(@NotNull Graphics2D g) { Rectangle clip = g.getClipBounds(); @@ -1687,13 +1694,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return; } - if (Registry.is("editor.dumb.mode.available")) { - final BufferedImage buffer = getUserData(BUFFER); - if (buffer != null) { - final Rectangle rect = getContentComponent().getVisibleRect(); - UIUtil.drawImage(g, buffer, null, rect.x, rect.y); - return; - } + BufferedImage buffer = Registry.is("editor.dumb.mode.available") ? getUserData(BUFFER) : null; + if (buffer != null) { + Rectangle rect = getContentComponent().getVisibleRect(); + UIUtil.drawImage(g, buffer, null, rect.x, rect.y); + return; } if (isReleased) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java index 3322dc6c6a09..f98f5d97053d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeBackgroundUtil.java @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.ex.EditorGutterComponentEx; import com.intellij.openapi.editor.impl.EditorComponentImpl; +import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter; import com.intellij.openapi.fileEditor.impl.EditorsSplitters; @@ -209,6 +210,10 @@ public class IdeBackgroundUtil { return new MyGraphics(gg != null ? gg.myDelegate : g, helper, helper.computeOffsets(g, component), gg != null ? gg.preserved : null); } + static Graphics2D unwrap(Graphics g) { + return g instanceof MyGraphics ? ((MyGraphics)g).getDelegate() : (Graphics2D)g; + } + MyGraphics(Graphics g, PaintersHelper helper, int[] offsets, Set preserved) { super((Graphics2D)g); this.helper = helper; @@ -352,6 +357,7 @@ public class IdeBackgroundUtil { c instanceof EditorGutterComponentEx ? CommonDataKeys.EDITOR.getData((DataProvider)c) : null; if (editor != null) { if (!(g instanceof MyGraphics) && Boolean.TRUE.equals(EditorTextField.SUPPLEMENTARY_KEY.get(editor))) return g; + if (c instanceof EditorComponentImpl && ((EditorImpl)editor).isDumb()) return MyGraphics.unwrap(g); Graphics2D gg = withEditorBackground(g, c); if (gg instanceof MyGraphics) { EditorColorsScheme scheme = editor.getColorsScheme();