From 1564facc1e8d5504cabe786a5332c965ebabfdab Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 20 Sep 2016 22:08:37 +0300 Subject: [PATCH] fix painting of text effects on retina with test --- .../src/com/intellij/ui/paint/EffectPainter.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/paint/EffectPainter.java b/platform/platform-api/src/com/intellij/ui/paint/EffectPainter.java index 03526f7f591c..0b48426310c6 100644 --- a/platform/platform-api/src/com/intellij/ui/paint/EffectPainter.java +++ b/platform/platform-api/src/com/intellij/ui/paint/EffectPainter.java @@ -245,7 +245,9 @@ public enum EffectPainter implements RegionPainter { } }; - private final ConcurrentHashMap myCache = new ConcurrentHashMap<>(); + // we should not recalculate caches when IDEA is on Retina and non-Retina + private final ConcurrentHashMap myNormalCache = new ConcurrentHashMap<>(); + private final ConcurrentHashMap myRetinaCache = new ConcurrentHashMap<>(); abstract int getPeriod(int height); @@ -263,12 +265,8 @@ public enum EffectPainter implements RegionPainter { BufferedImage getImage(Graphics2D g, Color color, int height) { Long key = color.getRGB() ^ ((long)height << 32); - BufferedImage image = myCache.get(key); - if (image == null || UIUtil.isRetina(g) != (image instanceof JBHiDPIScaledImage)) { - image = createImage(g, color, height); - myCache.put(key, image); - } - return image; + ConcurrentHashMap cache = UIUtil.isRetina(g) ? myRetinaCache : myNormalCache; + return cache.computeIfAbsent(key, k -> createImage(g, color, height)); } BufferedImage createImage(Graphics2D g, Paint paint, int height) { @@ -286,6 +284,7 @@ public enum EffectPainter implements RegionPainter { g.setComposite(AlphaComposite.SrcOver); BufferedImage image = paint instanceof Color ? getImage(g, (Color)paint, height) : createImage(g, paint, height); int period = image.getWidth(null); + if (image instanceof JBHiDPIScaledImage) period /= 2; int offset = (x % period + period) % period; // normalize for (int dx = -offset; dx < width; dx += period) { UIUtil.drawImage(g, image, dx, 0, null);