jdk/src/share/classes/javax/swing/BufferStrategyPaintManager.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8145 6714ca3d6773
child 10690 4e232ff8b640
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8145
diff changeset
     2
 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
    35
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
    36
import com.sun.java.swing.SwingUtilities3;
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.SubRegionShowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.action.GetPropertyAction;
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
    41
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 888
diff changeset
    42
import sun.awt.SunToolkit;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
    43
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A PaintManager implementation that uses a BufferStrategy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class BufferStrategyPaintManager extends RepaintManager.PaintManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // All drawing is done to a BufferStrategy.  At the end of painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // (endPaint) the region that was painted is flushed to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // (using BufferStrategy.show).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // PaintManager.show is overriden to show directly from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // BufferStrategy (when using blit), if successful true is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // returned and a paint event will not be generated.  To avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // showing from the buffer while painting a locking scheme is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // implemented.  When beginPaint is invoked the field painting is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // set to true.  If painting is true and show is invoked we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // immediately return false.  This is done to avoid blocking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // toolkit thread while painting happens.  In a similar way when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // show is invoked the field showing is set to true, beginPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // will then block until showing is true.  This scheme ensures we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // only ever have one thread using the BufferStrategy and it also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // ensures the toolkit thread remains as responsive as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // If we're using a flip strategy the contents of the backbuffer may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // have changed and so show only attempts to show from the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // if we get a blit strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Methods used to create BufferStrategy for Applets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static Method COMPONENT_CREATE_BUFFER_STRATEGY_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static Method COMPONENT_GET_BUFFER_STRATEGY_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
    81
    private static final PlatformLogger LOGGER = PlatformLogger.getLogger(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                           "javax.swing.BufferStrategyPaintManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * List of BufferInfos.  We don't use a Map primarily because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * there are typically only a handful of top level components making
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * a Map overkill.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private ArrayList<BufferInfo> bufferInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Indicates <code>beginPaint</code> has been invoked.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * set to true for the life of beginPaint/endPaint pair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private boolean painting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Indicates we're in the process of showing.  All painting, on the EDT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * is blocked while this is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private boolean showing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // Region that we need to flush.  When beginPaint is called these are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // reset and any subsequent calls to paint/copyArea then update these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // fields accordingly.  When endPaint is called we then try and show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // the accumulated region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // These fields are in the coordinate system of the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private int accumulatedX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private int accumulatedY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private int accumulatedMaxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private int accumulatedMaxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // The following fields are set by prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Farthest JComponent ancestor for the current paint/copyArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private JComponent rootJ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Parent Applet/Window for the current paint/copyArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private Container root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Location of component being painted relative to root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private int xOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Location of component being painted relative to root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private int yOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Graphics from the BufferStrategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private Graphics bsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * BufferStrategy currently being used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private BufferStrategy bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * BufferInfo corresponding to root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private BufferInfo bufferInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Set to true if the bufferInfo needs to be disposed when current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * paint loop is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private boolean disposeBufferOnEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static Method getGetBufferStrategyMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (COMPONENT_GET_BUFFER_STRATEGY_METHOD == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return COMPONENT_GET_BUFFER_STRATEGY_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static Method getCreateBufferStrategyMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (COMPONENT_CREATE_BUFFER_STRATEGY_METHOD == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return COMPONENT_CREATE_BUFFER_STRATEGY_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static void getMethods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                            new java.security.PrivilegedAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    COMPONENT_CREATE_BUFFER_STRATEGY_METHOD = Component.class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                              getDeclaredMethod("createBufferStrategy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                                new Class[] { int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                BufferCapabilities.class });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    COMPONENT_CREATE_BUFFER_STRATEGY_METHOD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                            setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    COMPONENT_GET_BUFFER_STRATEGY_METHOD = Component.class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                              getDeclaredMethod("getBufferStrategy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    COMPONENT_GET_BUFFER_STRATEGY_METHOD.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                } catch (NoSuchMethodException nsme) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    BufferStrategyPaintManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        bufferInfos = new ArrayList<BufferInfo>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // PaintManager methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Cleans up any created BufferStrategies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    protected void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // dipose can be invoked at any random time. To avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // threading dependancies we do the actual diposing via an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // invokeLater.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                java.util.List<BufferInfo> bufferInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                synchronized(BufferStrategyPaintManager.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    while (showing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        try {
8145
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents: 5506
diff changeset
   212
                            BufferStrategyPaintManager.this.wait();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    bufferInfos = BufferStrategyPaintManager.this.bufferInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    BufferStrategyPaintManager.this.bufferInfos = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                dispose(bufferInfos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private void dispose(java.util.List<BufferInfo> bufferInfos) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   225
        if (LOGGER.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   226
            LOGGER.finer("BufferStrategyPaintManager disposed",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   227
                         new RuntimeException());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (bufferInfos != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            for (BufferInfo bufferInfo : bufferInfos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                bufferInfo.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Shows the specified region of the back buffer.  This will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * true if successful, false otherwise.  This is invoked on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * toolkit thread in response to an expose event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean show(Container c, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (painting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                // Don't show from backbuffer while in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                // painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            showing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            BufferInfo info = getBufferInfo(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            BufferStrategy bufferStrategy;
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   253
            if (info != null && info.isInSync() &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                (bufferStrategy = info.getBufferStrategy(false)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                SubRegionShowable bsSubRegion =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        (SubRegionShowable)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                boolean paintAllOnExpose = info.getPaintAllOnExpose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                info.setPaintAllOnExpose(false);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   259
                if (bsSubRegion.showIfNotLost(x, y, (x + w), (y + h))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    return !paintAllOnExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                // Mark the buffer as needing to be repainted.  We don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                // immediately do a repaint as this method will return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                // indicating a PaintEvent should be generated which will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                // trigger a complete repaint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                bufferInfo.setContentsLostDuringExpose(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                showing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public boolean paint(JComponent paintingComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                         JComponent bufferComponent, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                         int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (prepare(paintingComponent, true, x, y, w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if ((g instanceof SunGraphics2D) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    ((SunGraphics2D)g).getDestination() == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                // BufferStrategy may have already constrained the Graphics. To
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                // account for that we revert the constrain, then apply a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                // constrain for Swing on top of that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                int cx = ((SunGraphics2D)bsg).constrainX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                int cy = ((SunGraphics2D)bsg).constrainY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                if (cx != 0 || cy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    bsg.translate(-cx, -cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                ((SunGraphics2D)bsg).constrain(xOffset + cx, yOffset + cy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                               x + w, y + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                bsg.setClip(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                paintingComponent.paintToOffscreen(bsg, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                                   x + w, y + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                accumulate(xOffset + x, yOffset + y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                // Assume they are going to eventually render to the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                // This disables showing from backbuffer until a complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                // repaint occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                bufferInfo.setInSync(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                // Fall through to old rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // Invalid root, do what Swing has always done.
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   308
        if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            LOGGER.finer("prepare failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return super.paint(paintingComponent, bufferComponent, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void copyArea(JComponent c, Graphics g, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                         int deltaX, int deltaY, boolean clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // Note: this method is only called internally and we know that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        // g is from a heavyweight Component, so no check is necessary as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        // it is in paint() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // If the buffer isn't in sync there is no point in doing a copyArea,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // it has garbage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (prepare(c, false, 0, 0, 0, 0) && bufferInfo.isInSync()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                Rectangle cBounds = c.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                int relX = xOffset + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                int relY = yOffset + y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                bsg.clipRect(xOffset + cBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                             yOffset + cBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                             cBounds.width, cBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                bsg.copyArea(relX, relY, w, h, deltaX, deltaY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                bsg.copyArea(xOffset + x, yOffset + y, w, h, deltaX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                             deltaY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            accumulate(x + xOffset + deltaX, y + yOffset + deltaY, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   338
            if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                LOGGER.finer("copyArea: prepare failed or not in sync");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // Prepare failed, or not in sync. By calling super.copyArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            // we'll copy on screen. We need to flush any pending paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            // the screen otherwise we'll do a copyArea on the wrong thing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (!flushAccumulatedRegion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                // Flush failed, copyArea will be copying garbage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                // force repaint of all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                rootJ.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                super.copyArea(c, g, x, y, w, h, deltaX, deltaY, clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public void beginPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            painting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            // Make sure another thread isn't attempting to show from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            // the back buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            while(showing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   366
        if (LOGGER.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            LOGGER.finest("beginPaint");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // Reset the area that needs to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        resetAccumulated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public void endPaint() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   374
        if (LOGGER.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            LOGGER.finest("endPaint: region " + accumulatedX + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                       accumulatedY + " " +  accumulatedMaxX + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                       accumulatedMaxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (painting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (!flushAccumulatedRegion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                if (!isRepaintingRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    repaintRoot(rootJ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    // Contents lost twice in a row, punt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    resetDoubleBufferPerWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    // In case we've left junk on the screen, force a repaint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    rootJ.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        BufferInfo toDispose = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            painting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (disposeBufferOnEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                disposeBufferOnEnd = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                toDispose = bufferInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                bufferInfos.remove(toDispose);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (toDispose != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            toDispose.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Renders the BufferStrategy to the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @return true if successful, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private boolean flushAccumulatedRegion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        boolean success = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (accumulatedX != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            SubRegionShowable bsSubRegion = (SubRegionShowable)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            boolean contentsLost = bufferStrategy.contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (!contentsLost) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                bsSubRegion.show(accumulatedX, accumulatedY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                 accumulatedMaxX, accumulatedMaxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                contentsLost = bufferStrategy.contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            if (contentsLost) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   423
                if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    LOGGER.finer("endPaint: contents lost");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                // Shown region was bogus, mark buffer as out of sync.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                bufferInfo.setInSync(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        resetAccumulated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private void resetAccumulated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        accumulatedX = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        accumulatedY = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        accumulatedMaxX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        accumulatedMaxY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Invoked when the double buffering or useTrueDoubleBuffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * changes for a JRootPane.  If the rootpane is not double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * buffered, or true double buffering changes we throw out any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * cache we may have.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public void doubleBufferingChanged(final JRootPane rootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if ((!rootPane.isDoubleBuffered() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                !rootPane.getUseTrueDoubleBuffering()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                rootPane.getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if (!SwingUtilities.isEventDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                Runnable updater = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        doubleBufferingChanged0(rootPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                SwingUtilities.invokeLater(updater);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                doubleBufferingChanged0(rootPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Does the work for doubleBufferingChanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    private void doubleBufferingChanged0(JRootPane rootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // This will only happen on the EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        BufferInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // Make sure another thread isn't attempting to show from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            // the back buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            while(showing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            info = getBufferInfo(rootPane.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (painting && bufferInfo == info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                // We're in the process of painting and the user grabbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                // the Graphics. If we dispose now, endPaint will attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                // to show a bogus BufferStrategy. Set a flag so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                // endPaint knows it needs to dispose this buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                disposeBufferOnEnd = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                info = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            } else if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                bufferInfos.remove(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            info.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Calculates information common to paint/copyArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @return true if should use buffering per window in painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private boolean prepare(JComponent c, boolean isPaint, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                            int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (bsg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            bsg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            bsg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (fetchRoot(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            boolean contentsLost = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            BufferInfo bufferInfo = getBufferInfo(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (bufferInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                contentsLost = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                bufferInfo = new BufferInfo(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                bufferInfos.add(bufferInfo);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   517
                if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    LOGGER.finer("prepare: new BufferInfo: " + root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            this.bufferInfo = bufferInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (!bufferInfo.hasBufferStrategyChanged()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                bufferStrategy = bufferInfo.getBufferStrategy(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                if (bufferStrategy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    bsg = bufferStrategy.getDrawGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    if (bufferStrategy.contentsRestored()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        contentsLost = true;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   528
                        if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                            LOGGER.finer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                "prepare: contents restored in prepare");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    // Couldn't create BufferStrategy, fallback to normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    // painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                if (bufferInfo.getContentsLostDuringExpose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    contentsLost = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    bufferInfo.setContentsLostDuringExpose(false);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   542
                    if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        LOGGER.finer("prepare: contents lost on expose");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                if (isPaint && c == rootJ && x == 0 && y == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                      c.getWidth() == w && c.getHeight() == h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    bufferInfo.setInSync(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                else if (contentsLost) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    // We either recreated the BufferStrategy, or the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    // of the buffer strategy were restored.  We need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    // repaint the root pane so that the back buffer is in sync
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    // again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    bufferInfo.setInSync(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    if (!isRepaintingRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        repaintRoot(rootJ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        // Contents lost twice in a row, punt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        resetDoubleBufferPerWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                return (bufferInfos != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    private boolean fetchRoot(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        boolean encounteredHW = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        rootJ = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        root = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        xOffset = yOffset = 0;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 888
diff changeset
   575
        while (root != null &&
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 888
diff changeset
   576
               (!(root instanceof Window) &&
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 888
diff changeset
   577
                !SunToolkit.isInstanceOf(root, "java.applet.Applet"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            xOffset += root.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            yOffset += root.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            root = root.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (root instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    rootJ = (JComponent)root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                else if (!root.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    if (!encounteredHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        encounteredHW = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        // We've encountered two hws now and may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        // a containment hierarchy with lightweights containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        // heavyweights containing other lightweights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        // Heavyweights poke holes in lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        // rendering so that if we call show on the BS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        // (which is associated with the Window) you will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        // not see the contents over any child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        // heavyweights.  If we didn't do this when we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                        // went to show the descendants of the nested hw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        // you would see nothing, so, we bail out here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if ((root instanceof RootPaneContainer) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            (rootJ instanceof JRootPane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            // We're in a Swing heavyeight (JFrame/JWindow...), use double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // buffering if double buffering enabled on the JRootPane and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            // the JRootPane wants true double buffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if (rootJ.isDoubleBuffered() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    ((JRootPane)rootJ).getUseTrueDoubleBuffering()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                // Whether or not a component is double buffered is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                // bit tricky with Swing. This gives a good approximation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                // of the various ways to turn on double buffering for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                // components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // Don't do true double buffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Turns off double buffering per window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    private void resetDoubleBufferPerWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (bufferInfos != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            dispose(bufferInfos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            bufferInfos = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            repaintManager.setPaintManager(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Returns the BufferInfo for the specified root or null if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * hasn't been created yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private BufferInfo getBufferInfo(Container root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        for (int counter = bufferInfos.size() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            BufferInfo bufferInfo = bufferInfos.get(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            Container biRoot = bufferInfo.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if (biRoot == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                // Window gc'ed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                bufferInfos.remove(counter);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   645
                if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    LOGGER.finer("BufferInfo pruned, root null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            else if (biRoot == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                return bufferInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    private void accumulate(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        accumulatedX = Math.min(x, accumulatedX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        accumulatedY = Math.min(y, accumulatedY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        accumulatedMaxX = Math.max(accumulatedMaxX, x + w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        accumulatedMaxY = Math.max(accumulatedMaxY, y + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * BufferInfo is used to track the BufferStrategy being used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * a particular Component.  In addition to tracking the BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * it will install a WindowListener and ComponentListener.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * component is hidden/iconified the buffer is marked as needing to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * completely repainted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    private class BufferInfo extends ComponentAdapter implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                               WindowListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        // NOTE: This class does NOT hold a direct reference to the root, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // did there would be a cycle between the BufferPerWindowPaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // and the Window so that it could never be GC'ed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // Reference to BufferStrategy is referenced via WeakReference for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // same reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        private WeakReference<BufferStrategy> weakBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        private WeakReference<Container> root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        // Indicates whether or not the backbuffer and display are in sync.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        // This is set to true when a full repaint on the rootpane is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        private boolean inSync;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        // Indicates the contents were lost during and expose event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        private boolean contentsLostDuringExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // Indicates we need to generate a paint event on expose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        private boolean paintAllOnExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        public BufferInfo(Container root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            this.root = new WeakReference<Container>(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            root.addComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            if (root instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                ((Window)root).addWindowListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        public void setPaintAllOnExpose(boolean paintAllOnExpose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            this.paintAllOnExpose = paintAllOnExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        public boolean getPaintAllOnExpose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return paintAllOnExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        public void setContentsLostDuringExpose(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            contentsLostDuringExpose = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        public boolean getContentsLostDuringExpose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return contentsLostDuringExpose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        public void setInSync(boolean inSync) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            this.inSync = inSync;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
         * Whether or not the contents of the buffer strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
         * is in sync with the window.  This is set to true when the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         * pane paints all, and false when contents are lost/restored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        public boolean isInSync() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            return inSync;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
         * Returns the Root (Window or Applet) that this BufferInfo references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        public Container getRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            return (root == null) ? null : root.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         * Returns the BufferStartegy.  This will return null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         * the BufferStartegy hasn't been created and <code>create</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         * false, or if there is a problem in creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         * <code>BufferStartegy</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * @param create If true, and the BufferStartegy is currently null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         *               one will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        public BufferStrategy getBufferStrategy(boolean create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            BufferStrategy bs = (weakBS == null) ? null : weakBS.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (bs == null && create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                bs = createBufferStrategy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                if (bs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    weakBS = new WeakReference<BufferStrategy>(bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   751
                if (LOGGER.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    LOGGER.finer("getBufferStrategy: created bs: " + bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            return bs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         * Returns true if the buffer strategy of the component differs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         * from current buffer strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        public boolean hasBufferStrategyChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            Container root = getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                BufferStrategy ourBS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                BufferStrategy componentBS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                ourBS = getBufferStrategy(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                if (root instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    componentBS = ((Window)root).getBufferStrategy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        componentBS = (BufferStrategy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                 getGetBufferStrategyMethod().invoke(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    } catch (IllegalAccessException iae2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                if (componentBS != ourBS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    // Component has a different BS, dispose ours.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    if (ourBS != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        ourBS.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    weakBS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * Creates the BufferStrategy.  If the appropriate system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         * has been set we'll try for flip first and then we'll try for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         * blit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        private BufferStrategy createBufferStrategy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            Container root = getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            if (root == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            BufferStrategy bs = null;
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   807
            if (SwingUtilities3.isVsyncRequested(root)) {
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   808
                bs = createBufferStrategy(root, true);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   809
                if (LOGGER.isLoggable(PlatformLogger.FINER)) {
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   810
                    LOGGER.finer("createBufferStrategy: using vsynced strategy");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            if (bs == null) {
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   814
                bs = createBufferStrategy(root, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            if (!(bs instanceof SubRegionShowable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                // We do this for two reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                // 1. So that we know we can cast to SubRegionShowable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                //    invoke show with the minimal region to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                // 2. To avoid the possibility of invoking client code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                //    on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                bs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            return bs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   827
        // Creates and returns a buffer strategy.  If
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        // there is a problem creating the buffer strategy this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        // eat the exception and return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        private BufferStrategy createBufferStrategy(Container root,
3105
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   831
                boolean isVsynced) {
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   832
            BufferCapabilities caps;
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   833
            if (isVsynced) {
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   834
                caps = new ExtendedBufferCapabilities(
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   835
                    new ImageCapabilities(true), new ImageCapabilities(true),
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   836
                    BufferCapabilities.FlipContents.COPIED,
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   837
                    ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   838
            } else {
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   839
                caps = new BufferCapabilities(
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   840
                    new ImageCapabilities(true), new ImageCapabilities(true),
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   841
                    null);
b5931be76fbc 6679840: provide a way to choose v-synced BufferStrategy
malenkov
parents: 888
diff changeset
   842
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            BufferStrategy bs = null;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 888
diff changeset
   844
            if (SunToolkit.isInstanceOf(root, "java.applet.Applet")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    getCreateBufferStrategyMethod().invoke(root, 2, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    bs = (BufferStrategy)getGetBufferStrategyMethod().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                            invoke(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    // Type is not supported
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   851
                    if (LOGGER.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   852
                        LOGGER.finer("createBufferStratety failed",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   853
                                     ite);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                } catch (IllegalAccessException iae2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    ((Window)root).createBufferStrategy(2, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                    bs = ((Window)root).getBufferStrategy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    // Type not supported
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   867
                    if (LOGGER.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   868
                        LOGGER.finer("createBufferStratety failed",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   869
                                     e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            return bs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         * Cleans up and removes any references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            Container root = getRoot();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   881
            if (LOGGER.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3109
diff changeset
   882
                LOGGER.finer("disposed BufferInfo for: " + root);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                root.removeComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                if (root instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    ((Window)root).removeWindowListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                BufferStrategy bs = getBufferStrategy(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                if (bs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    bs.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            this.root = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            weakBS = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        // We mark the buffer as needing to be painted on a hide/iconify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        // because the developer may have conditionalized painting based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        // visibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        // Ideally we would also move to having the BufferStrategy being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        // a SoftReference in Component here, but that requires changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        // Component and the like.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        public void componentHidden(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            Container root = getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            if (root != null && root.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                // This case will only happen if a developer calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                // hide immediately followed by show.  In this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                // the event is delivered after show and the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                // will still be visible.  If a developer altered the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                // contents of the window between the hide/show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                // invocations we won't recognize we need to paint and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                // the contents would be bogus.  Calling repaint here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                // fixs everything up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                root.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                setPaintAllOnExpose(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        public void windowIconified(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            setPaintAllOnExpose(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        // On a dispose we chuck everything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        public void windowClosed(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            // Make sure we're not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            synchronized(BufferStrategyPaintManager.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                while (showing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                        BufferStrategyPaintManager.this.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                    } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                bufferInfos.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        public void windowOpened(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        public void windowClosing(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        public void windowDeiconified(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        public void windowActivated(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        public void windowDeactivated(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
}