Changeset 19701 in josm for trunk/src/org/openstreetmap/josm/gui/MapView.java
- Timestamp:
- 2026-11-22T16:16:43+01:00 (less than one hour ago)
- File:
-
- 1 edited
-
trunk/src/org/openstreetmap/josm/gui/MapView.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r19592 r19701 54 54 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 55 55 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 56 import org.openstreetmap.josm.data.projection.Projection; 56 57 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 57 58 import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle; 58 59 import org.openstreetmap.josm.gui.autofilter.AutoFilterManager; 59 60 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler; 61 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 60 62 import org.openstreetmap.josm.gui.layer.Layer; 61 63 import org.openstreetmap.josm.gui.layer.LayerManager; … … 237 239 private transient BufferedImage nonChangedLayersBuffer; 238 240 private transient BufferedImage offscreenBuffer; 239 // Layers that wasn't changed since last paint240 private final transient List<Layer> nonChangedLayers = new ArrayList<>();241 241 private int lastViewID; 242 private double lastPaintedScale; 243 private EastNorth lastPaintedCenter; 244 private Projection lastPaintedProjection; 245 private List<Layer> lastPaintedLayers; 246 // Composite baked without labels during a pan. 247 private transient boolean panLabelsHidden; 242 248 private final AtomicBoolean paintPreferencesChanged = new AtomicBoolean(true); 243 249 private Rectangle lastClipBounds = new Rectangle(); … … 490 496 BugReport.intercept(t).put("layer", layer).warn(); 491 497 } 498 } 499 500 /** 501 * Determines if a pan is in progress. 502 * @return {@code true} if a pan is in progress 503 * @since 19701 504 */ 505 public boolean isPanning() { 506 return mapMover != null && mapMover.movementInProgress(); 492 507 } 493 508 … … 552 567 } 553 568 554 boolean canUseBuffer = !paintPreferencesChanged.getAndSet(false) 555 && nonChangedLayers.size() <= nonChangedLayersCount 556 && lastViewID == getViewID() 557 && lastClipBounds.contains(g.getClipBounds()) 558 && nonChangedLayers.equals(visibleLayers.subList(0, nonChangedLayers.size())); 559 569 boolean paintPrefsChanged = paintPreferencesChanged.getAndSet(false); 570 boolean sameLayerSet = lastPaintedLayers != null && lastPaintedLayers.equals(visibleLayers); 571 int viewID = getViewID(); 572 boolean viewMoved = lastViewID != viewID; 573 boolean panning = isPanning(); 574 boolean hideLabels = OsmDataLayer.PROPERTY_HIDE_LABELS_WHILE_DRAGGING.get(); 575 EastNorth center = getCenter(); 576 double scale = getScale(); 577 Rectangle clip = g.getClipBounds(); 578 boolean fullClip = clip.contains(0, 0, getWidth(), getHeight()); 579 // Partial clips must not rebuild the buffer or clear the label flag 580 boolean needLabelRefresh = panLabelsHidden && !viewMoved && fullClip && !panning; 581 if (needLabelRefresh) { 582 panLabelsHidden = false; 583 } 584 boolean canUseBuffer = !paintPrefsChanged 585 && !needLabelRefresh 586 && !viewMoved 587 && sameLayerSet 588 && nonChangedLayersCount == visibleLayers.size() 589 && lastClipBounds.contains(clip); 590 591 boolean canReusePan = !paintPrefsChanged 592 && viewMoved 593 && sameLayerSet 594 && Utils.equalsEpsilon(scale, lastPaintedScale) 595 && lastPaintedProjection == getProjection() 596 && lastClipBounds.contains(0, 0, getWidth(), getHeight()) 597 && hideLabels 598 && nonChangedLayersBuffer != null 599 && nonChangedLayersBuffer.getWidth() == width && nonChangedLayersBuffer.getHeight() == height; 600 int blitDX = 0; 601 int blitDY = 0; 602 if (canReusePan) { 603 blitDX = (int) Math.round((lastPaintedCenter.east() - center.east()) / lastPaintedScale * uiScaleX); 604 blitDY = (int) Math.round((center.north() - lastPaintedCenter.north()) / lastPaintedScale * uiScaleY); 605 // Zero or off-screen blits must fall back to full paint 606 canReusePan = (blitDX != 0 || blitDY != 0) && Math.abs(blitDX) < width && Math.abs(blitDY) < height; 607 } 608 if (hideLabels && (canReusePan || panning)) { 609 panLabelsHidden = true; 610 } 560 611 if (null == offscreenBuffer || offscreenBuffer.getWidth() != width || offscreenBuffer.getHeight() != height) { 561 612 offscreenBuffer = getAcceleratedImage(this, width, height); 562 613 } 563 614 564 if (!canUseBuffer || nonChangedLayersBuffer == null) { 615 if (!canReusePan && (!canUseBuffer || nonChangedLayersBuffer == null)) { 565 616 if (null == nonChangedLayersBuffer 566 617 || nonChangedLayersBuffer.getWidth() != width || nonChangedLayersBuffer.getHeight() != height) { 567 618 nonChangedLayersBuffer = getAcceleratedImage(this, width, height); 568 619 } 569 Graphics2D g2 = nonChangedLayersBuffer.createGraphics(); 570 g2.setClip(scaledClip); 571 g2.setTransform(trDef); 572 g2.setColor(PaintColors.getBackgroundColor()); 573 g2.fillRect(0, 0, width, height); 574 575 for (int i = 0; i < nonChangedLayersCount; i++) { 576 paintLayer(visibleLayers.get(i), g2); 577 } 578 } else { 579 // Maybe there were more unchanged layers then last time - draw them to buffer 580 if (nonChangedLayers.size() != nonChangedLayersCount) { 620 if (fullClip) { 581 621 Graphics2D g2 = nonChangedLayersBuffer.createGraphics(); 582 622 g2.setClip(scaledClip); 583 623 g2.setTransform(trDef); 584 for (int i = nonChangedLayers.size(); i < nonChangedLayersCount; i++) { 624 g2.setColor(PaintColors.getBackgroundColor()); 625 g2.fillRect(0, 0, width, height); 626 627 for (int i = 0; i < nonChangedLayersCount; i++) { 585 628 paintLayer(visibleLayers.get(i), g2); 586 629 } 587 } 588 } 589 590 nonChangedLayers.clear(); 591 if (nonChangedLayersCount > 0) 592 nonChangedLayers.addAll(visibleLayers.subList(0, nonChangedLayersCount)); 593 lastViewID = getViewID(); 594 lastClipBounds = g.getClipBounds(); 630 g2.dispose(); 631 } 632 } 633 634 lastViewID = viewID; 635 lastClipBounds = clip; 636 lastPaintedScale = scale; 637 lastPaintedCenter = center; 638 lastPaintedProjection = getProjection(); 639 lastPaintedLayers = new ArrayList<>(visibleLayers); 595 640 596 641 Graphics2D tempG = offscreenBuffer.createGraphics(); 597 642 tempG.setClip(scaledClip); 598 643 tempG.setTransform(new AffineTransform()); 599 tempG.drawImage(nonChangedLayersBuffer, 0, 0, null); 644 if (canReusePan) { 645 tempG.drawImage(nonChangedLayersBuffer, blitDX, blitDY, null); 646 if (blitDX != 0) { 647 paintPanStrip(tempG, blitDX > 0 ? 0 : width + blitDX, 0, 648 Math.abs(blitDX), height, visibleLayers, trDef); 649 } 650 if (blitDY != 0) { 651 paintPanStrip(tempG, 0, blitDY > 0 ? 0 : height + blitDY, 652 width, Math.abs(blitDY), visibleLayers, trDef); 653 } 654 tempG.setClip(scaledClip); 655 } else { 656 tempG.drawImage(nonChangedLayersBuffer, 0, 0, null); 657 } 600 658 tempG.setTransform(trDef); 601 659 602 for (int i = nonChangedLayersCount; i < visibleLayers.size(); i++) { 603 paintLayer(visibleLayers.get(i), tempG); 660 // Skip during a pan: repainting over the shifted composite would 661 // duplicate and stack translucent layers. Changes appear after pan stops 662 if (!canReusePan) { 663 for (int i = nonChangedLayersCount; i < visibleLayers.size(); i++) { 664 paintLayer(visibleLayers.get(i), tempG); 665 } 666 } 667 if (fullClip && !canUseBuffer) { 668 Graphics2D g2 = nonChangedLayersBuffer.createGraphics(); 669 g2.drawImage(offscreenBuffer, 0, 0, null); 670 g2.dispose(); 671 } 672 673 // Viewport-fixed overlay which must not go into the reused composite 674 for (Layer layer : visibleLayers) { 675 if (layer instanceof AbstractTileSourceLayer) { 676 ((AbstractTileSourceLayer<?>) layer).paintAttribution(tempG, this); 677 } 604 678 } 605 679 606 680 try { 607 681 drawTemporaryLayers(tempG, getLatLonBounds(new Rectangle( 608 (int) Math.round( g.getClipBounds().x * uiScaleX),609 (int) Math.round( g.getClipBounds().y * uiScaleY))));682 (int) Math.round(clip.x * uiScaleX), 683 (int) Math.round(clip.y * uiScaleY)))); 610 684 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { 611 685 BugReport.intercept(e).put("temporaryLayers", temporaryLayers).warn(); … … 630 704 playHeadMarker.paint(tempG, this); 631 705 } 706 tempG.dispose(); 632 707 633 708 try { … … 664 739 } 665 740 741 /** Icon overhang covered by the pan-strip band in logical pixels */ 742 private static final int PAN_STRIP_MARGIN = 16; 743 744 private void paintPanStrip(Graphics2D g, int x, int y, int w, int h, List<Layer> layers, AffineTransform trDef) { 745 // Fill first so translucent content does not double stack 746 int mx = (int) Math.ceil(PAN_STRIP_MARGIN * trDef.getScaleX()); 747 int my = (int) Math.ceil(PAN_STRIP_MARGIN * trDef.getScaleY()); 748 Rectangle band = new Rectangle(x - mx, y - my, w + 2 * mx, h + 2 * my); 749 g.setTransform(new AffineTransform()); 750 g.setClip(band); 751 g.setColor(PaintColors.getBackgroundColor()); 752 g.fillRect(band.x, band.y, band.width, band.height); 753 g.setTransform(trDef); 754 for (Layer layer : layers) { 755 paintLayer(layer, g); 756 } 757 } 758 666 759 private void drawTemporaryLayers(Graphics2D tempG, Bounds box) { 667 760 synchronized (temporaryLayers) { … … 824 917 mapMover.destroy(); 825 918 } 826 nonChangedLayers.clear();827 919 synchronized (temporaryLayers) { 828 920 temporaryLayers.clear(); … … 830 922 nonChangedLayersBuffer = null; 831 923 offscreenBuffer = null; 924 lastPaintedLayers = null; 925 lastPaintedCenter = null; 926 lastPaintedProjection = null; 832 927 setTransferHandler(null); 833 928 GuiHelper.destroyComponents(this, false);
Note:
See TracChangeset
for help on using the changeset viewer.
