Changeset 3136 in josm


Ignore:
Timestamp:
2010-03-15T08:14:29+01:00 (15 years ago)
Author:
jttt
Message:

Fix #4729 josm >= 3116 extremely slow and laggy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r3128 r3136  
    181181    private LinkedList<MapViewPaintable> temporaryLayers = new LinkedList<MapViewPaintable>();
    182182
     183    private BufferedImage nonChangedLayersBuffer;
    183184    private BufferedImage offscreenBuffer;
    184185    // Layers that wasn't changed since last paint
     
    486487        }
    487488
    488         Graphics2D tempG = (Graphics2D) g;
     489        if (null == offscreenBuffer || offscreenBuffer.getWidth() != getWidth() || offscreenBuffer.getHeight() != getHeight()) {
     490            offscreenBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
     491        }
     492
     493        Graphics2D tempG = offscreenBuffer.createGraphics();
     494        tempG.setClip(g.getClip());
    489495        Bounds box = getLatLonBounds(g.getClipBounds());
    490496
    491         if (!canUseBuffer || offscreenBuffer == null) {
    492             if (null == offscreenBuffer || offscreenBuffer.getWidth() != getWidth() || offscreenBuffer.getHeight() != getHeight()) {
    493                 offscreenBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
    494             }
    495             Graphics2D g2 = offscreenBuffer.createGraphics();
     497        if (!canUseBuffer || nonChangedLayersBuffer == null) {
     498            if (null == nonChangedLayersBuffer || nonChangedLayersBuffer.getWidth() != getWidth() || nonChangedLayersBuffer.getHeight() != getHeight()) {
     499                nonChangedLayersBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
     500            }
     501            Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
    496502            g2.setClip(g.getClip());
    497503            g2.setColor(PaintColors.BACKGROUND.get());
     
    504510            // Maybe there were more unchanged layers then last time - draw them to buffer
    505511            if (nonChangedLayers.size() != nonChangedLayersCount) {
    506                 Graphics2D g2 = offscreenBuffer.createGraphics();
     512                Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
    507513                g2.setClip(g.getClip());
    508514                for (int i=nonChangedLayers.size(); i<nonChangedLayersCount; i++) {
     
    519525        paintPreferencesChanged = false;
    520526
    521         tempG.drawImage(offscreenBuffer, 0, 0, null);
     527        tempG.drawImage(nonChangedLayersBuffer, 0, 0, null);
    522528
    523529        for (int i=nonChangedLayersCount; i<visibleLayers.size(); i++) {
     
    580586        }
    581587
     588        g.drawImage(offscreenBuffer, 0, 0, null);
    582589        super.paint(g);
    583590    }
Note: See TracChangeset for help on using the changeset viewer.