From eb118c24dee7694535bca8ee0dd3d557738b2ca7 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 13 Aug 2019 17:30:57 -0400 Subject: [PATCH] overlay renderer: reduce graphics properties copying --- .../client/ui/overlay/OverlayRenderer.java | 65 +++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index dc794066d1..af92163b79 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -203,6 +203,15 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition(); final Point mouse = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY()); + // Save graphics2d properties so we can restore them later + final AffineTransform transform = graphics.getTransform(); + final Stroke stroke = graphics.getStroke(); + final Composite composite = graphics.getComposite(); + final Paint paint = graphics.getPaint(); + final Color color = graphics.getColor(); + final RenderingHints renderingHints = graphics.getRenderingHints(); + final Color background = graphics.getBackground(); + for (Overlay overlay : overlays) { OverlayPosition overlayPosition = overlay.getPosition(); @@ -267,26 +276,34 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener } safeRender(client, overlay, layer, graphics, location); + final Rectangle bounds = overlay.getBounds(); - if (bounds.isEmpty()) + if (!bounds.isEmpty()) { - continue; - } + if (inOverlayDraggingMode) + { + final Color previous = graphics.getColor(); + graphics.setColor(movedOverlay == overlay ? MOVING_OVERLAY_ACTIVE_COLOR : MOVING_OVERLAY_COLOR); + graphics.draw(bounds); + graphics.setColor(previous); + } - if (inOverlayDraggingMode) - { - final Color previous = graphics.getColor(); - graphics.setColor(movedOverlay == overlay ? MOVING_OVERLAY_ACTIVE_COLOR : MOVING_OVERLAY_COLOR); - graphics.draw(bounds); - graphics.setColor(previous); - } - - if (menuEntries == null && !client.isMenuOpen() && bounds.contains(mouse)) - { - menuEntries = createRightClickMenuEntries(overlay); + if (menuEntries == null && !client.isMenuOpen() && bounds.contains(mouse)) + { + menuEntries = createRightClickMenuEntries(overlay); + } } } + + // Restore graphics2d properties + graphics.setTransform(transform); + graphics.setStroke(stroke); + graphics.setComposite(composite); + graphics.setPaint(paint); + graphics.setColor(color); + graphics.setRenderingHints(renderingHints); + graphics.setBackground(background); } } @@ -466,15 +483,6 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener graphics.setFont(runeLiteConfig.interfaceFontType().getFont()); } - // Save graphics2d properties so we can restore them later - final AffineTransform transform = graphics.getTransform(); - final Stroke stroke = graphics.getStroke(); - final Composite composite = graphics.getComposite(); - final Paint paint = graphics.getPaint(); - final Color color = graphics.getColor(); - final RenderingHints renderingHints = graphics.getRenderingHints(); - final Color background = graphics.getBackground(); - graphics.translate(point.x, point.y); final Dimension overlayDimension; @@ -487,17 +495,6 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener log.warn("Error during overlay rendering", ex); return; } - finally - { - // Restore graphics2d properties - graphics.setTransform(transform); - graphics.setStroke(stroke); - graphics.setComposite(composite); - graphics.setPaint(paint); - graphics.setColor(color); - graphics.setRenderingHints(renderingHints); - graphics.setBackground(background); - } final Dimension dimension = MoreObjects.firstNonNull(overlayDimension, new Dimension()); overlay.setBounds(new Rectangle(point, dimension));