true smooth scrolling: newly added getGraphics calls substituted for safelyGetGraphics

This commit is contained in:
Pavel Fatin
2016-12-15 23:44:56 +01:00
parent 153e9f3940
commit ac591b7db1
6 changed files with 11 additions and 9 deletions
@@ -157,7 +157,9 @@ public class JBViewport extends JViewport implements ZoomableViewport {
frame buffer content without the usual repainting, even when the EDT is blocked.
Generally, this requires default RepaintManager, swing.bufferPerWindow = true and
no prior direct invocations of JComponent.getGraphics() within JRootPane. */
no prior direct invocations of JComponent.getGraphics() within JRootPane.
Use a breakpoint in JRootPane.disableTrueDoubleBuffering() to detect direct getGraphics() calls. */
@Nullable
private static Boolean isTrueDoubleBufferingAvailableFor(JComponent component) {
if (ourGetPaintManagerMethod.isAvailable()) {
@@ -1082,8 +1082,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
DataContext context = getDataContext();
Graphics graphics = SystemProperties.isTrueSmoothScrollingEnabled() ?
GraphicsUtil.safelyGetGraphics(myEditorComponent) : myEditorComponent.getGraphics();
Graphics graphics = GraphicsUtil.safelyGetGraphics(myEditorComponent);
if (graphics != null) { // editor component is not showing
processKeyTypedImmediately(c, graphics, context);
graphics.dispose();
@@ -39,8 +39,8 @@ import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame;
import com.intellij.ui.ScreenUtil;
import com.intellij.util.EventDispatcher;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import com.sun.jna.platform.WindowUtils;
import org.jdom.Element;
@@ -736,7 +736,7 @@ public final class WindowManagerImpl extends WindowManagerEx implements NamedCom
int extendedState = updateFrameBounds(frame);
Rectangle rectangle = ScreenUtil.boundsToDeviceSpace((Graphics2D)frame.getGraphics(), myFrameBounds);
Rectangle rectangle = ScreenUtil.boundsToDeviceSpace((Graphics2D)GraphicsUtil.safelyGetGraphics(frame), myFrameBounds);
final Element frameElement = new Element(FRAME_ELEMENT);
frameElement.setAttribute(X_ATTR, Integer.toString(rectangle.x));
@@ -17,6 +17,7 @@ package com.intellij.util.ui;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.util.MethodInvocator;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -110,8 +111,8 @@ public class GraphicsUtil {
True double buffering is needed to eliminate tearing on blit-accelerated scrolling and to restore
frame buffer content without the usual repainting, even when the EDT is blocked. */
public static Graphics safelyGetGraphics(JComponent c) {
return ourSafelyGetGraphicsMethod.isAvailable()
public static Graphics safelyGetGraphics(Component c) {
return SystemProperties.isTrueSmoothScrollingEnabled() && ourSafelyGetGraphicsMethod.isAvailable()
? (Graphics)ourSafelyGetGraphicsMethod.invoke(null, c)
: c.getGraphics();
}
@@ -1940,7 +1940,7 @@ public class UIUtil {
@NotNull
public static BufferedImage createImage(Component comp, int width, int height, int type) {
return comp != null ?
createImage(comp.getGraphics(), width, height, type) :
createImage(GraphicsUtil.safelyGetGraphics(comp), width, height, type) :
createImage(width, height, type);
}
@@ -343,7 +343,7 @@ public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent
@Override
public Dimension getPreferredSize() {
Graphics2D g2 = (Graphics2D) (SystemProperties.isTrueSmoothScrollingEnabled() ? GraphicsUtil.safelyGetGraphics(this) : getGraphics());
Graphics2D g2 = (Graphics2D) GraphicsUtil.safelyGetGraphics(this);
Dimension dim = new Dimension(Integer.MAX_VALUE, g2 != null ? DEFAULT_PAINTER.getSize("DUMMY", g2.getFontMetrics(), Integer.MAX_VALUE).height + 1 : 1);
JBInsets.addTo(dim, getInsets());
return dim;