src/java.desktop/share/classes/javax/swing/RepaintManager.java
author avu
Thu, 15 Feb 2018 17:20:57 -0800
changeset 49086 96ea4dff640e
parent 47216 71c04702a3d5
child 51911 57fa2c1c98d4
permissions -rw-r--r--
8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution Reviewed-by: serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 4261
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: 4261
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: 4261
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
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
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.VolatileImage;
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
    31
import java.security.AccessControlContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.AccessController;
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
    33
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
    35
import java.util.concurrent.atomic.AtomicInteger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.applet.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 30946
diff changeset
    38
import jdk.internal.misc.JavaSecurityAccess;
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 30946
diff changeset
    39
import jdk.internal.misc.SharedSecrets;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
    40
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.java2d.SunGraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
    47
import com.sun.java.swing.SwingUtilities3;
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
    48
import java.awt.geom.AffineTransform;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
    49
import sun.java2d.SunGraphics2D;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
    50
import sun.java2d.pipe.Region;
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
    51
import sun.swing.SwingAccessor;
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
    52
import sun.swing.SwingUtilities2;
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
    53
import sun.swing.SwingUtilities2.RepaintListener;
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
    54
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This class manages repaint requests, allowing the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * of repaints to be minimized, for example by collapsing multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * requests into a single repaint for members of a component tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * As of 1.6 <code>RepaintManager</code> handles repaint requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * for Swing's top level components (<code>JApplet</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>JWindow</code>, <code>JFrame</code> and <code>JDialog</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Any calls to <code>repaint</code> on one of these will call into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * appropriate <code>addDirtyRegion</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Arnaud Weber
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 24983
diff changeset
    67
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public class RepaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Whether or not the RepaintManager should handle paint requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * for top levels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static final boolean HANDLE_TOP_LEVEL_PAINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final short BUFFER_STRATEGY_NOT_SPECIFIED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final short BUFFER_STRATEGY_SPECIFIED_ON = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final short BUFFER_STRATEGY_SPECIFIED_OFF = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final short BUFFER_STRATEGY_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Maps from GraphicsConfiguration to VolatileImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private Map<GraphicsConfiguration,VolatileImage> volatileMap = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        HashMap<GraphicsConfiguration,VolatileImage>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // As of 1.6 Swing handles scheduling of paint events from native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // That is, SwingPaintEventDispatcher is invoked on the toolkit thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // which in turn invokes nativeAddDirtyRegion.  Because this is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // from the native thread we can not invoke any public methods and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // we introduce these added maps.  So, any time nativeAddDirtyRegion is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // invoked the region is added to hwDirtyComponents and a work request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // is scheduled.  When the work request is processed all entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // this map are pushed to the real map (dirtyComponents) and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // painted with the rest of the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Map<Container,Rectangle> hwDirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private Map<Component,Rectangle> dirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private Map<Component,Rectangle> tmpDirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private java.util.List<Component> invalidComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // List of Runnables that need to be processed before painting from AWT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private java.util.List<Runnable> runnableList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    boolean   doubleBufferingEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private Dimension doubleBufferMaxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
49086
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   113
    private boolean isCustomMaxBufferSizeSet = false;
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   114
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // Support for both the standard and volatile offscreen buffers exists to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // provide backwards compatibility for the [rare] programs which may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // calling getOffScreenBuffer() and not expecting to get a VolatileImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // Swing internally is migrating to use *only* the volatile image buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // Support for standard offscreen buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    DoubleBufferInfo standardDoubleBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Object responsible for hanlding core paint functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private PaintManager paintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final Object repaintManagerKey = RepaintManager.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    // Whether or not a VolatileImage should be used for double-buffered painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    static boolean volatileImageBufferEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   134
     * Type of VolatileImage which should be used for double-buffered
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   135
     * painting.
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   136
     */
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   137
    private static final int volatileBufferType;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   138
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Value of the system property awt.nativeDoubleBuffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static boolean nativeDoubleBuffering;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // The maximum number of times Swing will attempt to use the VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // buffer during a paint operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final int VOLATILE_LOOP_MAX = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Number of <code>beginPaint</code> that have been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private int paintDepth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Type of buffer strategy to use.  Will be one of the BUFFER_STRATEGY_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private short bufferStrategyType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // BufferStrategyPaintManager has the unique characteristic that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    // must deal with the buffer being lost while painting to it.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // example, if we paint a component and show it and the buffer has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    // become lost we must repaint the whole window.  To deal with that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // the PaintManager calls into repaintRoot, and if we're still in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    // the process of painting the repaintRoot field is set to the JRootPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // and after the current JComponent.paintImmediately call finishes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    // paintImmediately will be invoked on the repaintRoot.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // way we don't try to show garbage to the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * True if we're in the process of painting the dirty regions.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * set to true in <code>paintDirtyRegions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private boolean painting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * If the PaintManager calls into repaintRoot during painting this field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * will be set to the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private JComponent repaintRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * The Thread that has initiated painting.  If null it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * indicates painting is not currently in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private Thread paintThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Runnable used to process all repaint/revalidate requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private final ProcessingRunnable processingRunnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   191
    private static final JavaSecurityAccess javaSecurityAccess =
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   192
            SharedSecrets.getJavaSecurityAccess();
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   193
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   194
    /**
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   195
     * Listener installed to detect display changes. When display changes,
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   196
     * schedules a callback to notify all RepaintManagers of the display
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   197
     * changes.
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   198
     */
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   199
    private static final DisplayChangedListener displayChangedHandler =
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   200
            new DisplayChangedHandler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    static {
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   203
        SwingAccessor.setRepaintManagerAccessor(new SwingAccessor.RepaintManagerAccessor() {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   204
            @Override
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   205
            public void addRepaintListener(RepaintManager rm, RepaintListener l) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   206
                rm.addRepaintListener(l);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   207
            }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   208
            @Override
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   209
            public void removeRepaintListener(RepaintManager rm, RepaintListener l) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   210
                rm.removeRepaintListener(l);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   211
            }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   212
        });
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
   213
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        volatileImageBufferEnabled = "true".equals(AccessController.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                doPrivileged(new GetPropertyAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                "swing.volatileImageBufferEnabled", "true")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        boolean headless = GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (volatileImageBufferEnabled && headless) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            volatileImageBufferEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        nativeDoubleBuffering = "true".equals(AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    new GetPropertyAction("awt.nativeDoubleBuffering")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        String bs = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                          new GetPropertyAction("swing.bufferPerWindow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (headless) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        else if (bs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_NOT_SPECIFIED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        else if ("true".equals(bs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        HANDLE_TOP_LEVEL_PAINT = "true".equals(AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
               new GetPropertyAction("swing.handleTopLevelPaint", "true")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        GraphicsEnvironment ge = GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (ge instanceof SunGraphicsEnvironment) {
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   242
            ((SunGraphicsEnvironment) ge).addDisplayChangedListener(
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
   243
                    displayChangedHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   245
        Toolkit tk = Toolkit.getDefaultToolkit();
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   246
        if ((tk instanceof SunToolkit)
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   247
                && ((SunToolkit) tk).isSwingBackbufferTranslucencySupported()) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   248
            volatileBufferType = Transparency.TRANSLUCENT;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   249
        } else {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   250
            volatileBufferType = Transparency.OPAQUE;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
   251
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return the RepaintManager for the calling thread given a Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param c a Component -- unused in the default implementation, but could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *          be used by an overridden version to return a different RepaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          depending on the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return the RepaintManager object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public static RepaintManager currentManager(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // Note: DisplayChangedRunnable passes in null as the component, so if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // component is ever used to determine the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // RepaintManager, DisplayChangedRunnable will need to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return currentManager(AppContext.getAppContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns the RepaintManager for the specified AppContext.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * a RepaintManager has not been created for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * AppContext this will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    static RepaintManager currentManager(AppContext appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        RepaintManager rm = (RepaintManager)appContext.get(repaintManagerKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (rm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            rm = new RepaintManager(BUFFER_STRATEGY_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            appContext.put(repaintManagerKey, rm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Return the RepaintManager for the calling thread given a JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    * Note: This method exists for backward binary compatibility with earlier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * versions of the Swing library. It simply returns the result returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * {@link #currentManager(Component)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param c a JComponent -- unused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return the RepaintManager object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public static RepaintManager currentManager(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return currentManager((Component)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Set the RepaintManager that should be used for the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * thread. <b>aRepaintManager</b> will become the current RepaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * for the calling thread's thread group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param aRepaintManager  the RepaintManager object to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public static void setCurrentManager(RepaintManager aRepaintManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (aRepaintManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            SwingUtilities.appContextPut(repaintManagerKey, aRepaintManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            SwingUtilities.appContextRemove(repaintManagerKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Create a new RepaintManager instance. You rarely call this constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * directly. To get the default RepaintManager, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * RepaintManager.currentManager(JComponent) (normally "this").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public RepaintManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // Because we can't know what a subclass is doing with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // volatile image we immediately punt in subclasses.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // poses a problem we'll need a more sophisticated detection algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        // or API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        this(BUFFER_STRATEGY_SPECIFIED_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private RepaintManager(short bufferStrategyType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // If native doublebuffering is being used, do NOT use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // Swing doublebuffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        doubleBufferingEnabled = !nativeDoubleBuffering;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            dirtyComponents = new IdentityHashMap<Component,Rectangle>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            tmpDirtyComponents = new IdentityHashMap<Component,Rectangle>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            this.bufferStrategyType = bufferStrategyType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            hwDirtyComponents = new IdentityHashMap<Container,Rectangle>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        processingRunnable = new ProcessingRunnable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private void displayChanged() {
49086
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   340
        if (isCustomMaxBufferSizeSet) {
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   341
            clearImages();
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   342
        } else {
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   343
            // Reset buffer maximum size to get valid size from updated graphics
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   344
            // environment in getDoubleBufferMaximumSize()
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   345
            setDoubleBufferMaximumSize(null);
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
   346
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Mark the component as in need of layout and queue a runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * for the event dispatching thread that will validate the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * first isValidateRoot() ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   354
     * @param invalidComponent a component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see JComponent#isValidateRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see #removeInvalidComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public synchronized void addInvalidComponent(JComponent invalidComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   360
        RepaintManager delegate = getDelegate(invalidComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   361
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   362
            delegate.addInvalidComponent(invalidComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   363
            return;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   364
        }
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3237
diff changeset
   365
        Component validateRoot =
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3237
diff changeset
   366
            SwingUtilities.getValidateRoot(invalidComponent, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (validateRoot == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        /* Lazily create the invalidateComponents vector and add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         * validateRoot if it's not there already.  If this validateRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * is already in the vector, we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (invalidComponents == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            invalidComponents = new ArrayList<Component>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            int n = invalidComponents.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            for(int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if(validateRoot == invalidComponents.get(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        invalidComponents.add(validateRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // Queue a Runnable to invoke paintDirtyRegions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // validateInvalidComponents.
18231
2948d734293d 8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents: 16092
diff changeset
   391
        scheduleProcessingRunnable(SunToolkit.targetToAppContext(invalidComponent));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Remove a component from the list of invalid components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   398
     * @param component a component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see #addInvalidComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public synchronized void removeInvalidComponent(JComponent component) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   402
        RepaintManager delegate = getDelegate(component);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   403
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   404
            delegate.removeInvalidComponent(component);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   405
            return;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   406
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if(invalidComponents != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            int index = invalidComponents.indexOf(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if(index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                invalidComponents.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Add a component in the list of components that should be refreshed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * will be unioned with the region that should be redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see JComponent#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
42198
6ff366cc096b 8168316: Suppress deprecation warnings for Applet classes in java.desktop
prr
parents: 32834
diff changeset
   423
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        /* Special cases we don't have to bother with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if ((w <= 0) || (h <= 0) || (c == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (extendDirtyRegion(c, x, y, w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            // Component was already marked as dirty, region has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // extended, no need to continue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        /* Make sure that c and all it ancestors (up to an Applet or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         * Window) are visible.  This loop has the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         * checking c.isShowing() (and note that it's still possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
         * that c is completely obscured by an opaque ancestor in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         * the specified rectangle).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        Component root = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // Note: We can't synchronize around this, Frame.getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // is synchronized so that if we were to synchronize around this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // it could lead to the possibility of getting locks out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // of order and deadlocking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        for (Container p = c; p != null; p = p.getParent()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   454
            if (!p.isVisible() || !p.isDisplayable()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if ((p instanceof Window) || (p instanceof Applet)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                // Iconified frames are still visible!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (p instanceof Frame &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        (((Frame)p).getExtendedState() & Frame.ICONIFIED) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                    Frame.ICONIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                root = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (root == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            if (extendDirtyRegion(c, x, y, w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                // In between last check and this check another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                // queued up runnable, can bail here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            dirtyComponents.put(c, new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        // Queue a Runnable to invoke paintDirtyRegions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // validateInvalidComponents.
18231
2948d734293d 8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents: 16092
diff changeset
   482
        scheduleProcessingRunnable(SunToolkit.targetToAppContext(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Add a component in the list of components that should be refreshed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * will be unioned with the region that should be redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param c Component to repaint, null results in nothing happening.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param x X coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param y Y coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param w Width of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param h Height of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @see JComponent#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public void addDirtyRegion(JComponent c, int x, int y, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   499
        RepaintManager delegate = getDelegate(c);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   500
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   501
            delegate.addDirtyRegion(c, x, y, w, h);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   502
            return;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   503
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        addDirtyRegion0(c, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Adds <code>window</code> to the list of <code>Component</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * need to be repainted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param window Window to repaint, null results in nothing happening.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @param x X coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param y Y coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param w Width of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param h Height of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see JFrame#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @see JWindow#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @see JDialog#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public void addDirtyRegion(Window window, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        addDirtyRegion0(window, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Adds <code>applet</code> to the list of <code>Component</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * need to be repainted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @param applet Applet to repaint, null results in nothing happening.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @param x X coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param y Y coordinate of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @param w Width of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @param h Height of the region to repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see JApplet#repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @since 1.6
43078
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 42746
diff changeset
   536
     *
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 42746
diff changeset
   537
     * @deprecated The Applet API is deprecated. See the
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 42746
diff changeset
   538
     * <a href="../../java/applet/package-summary.html"> java.applet package
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 42746
diff changeset
   539
     * documentation</a> for further information.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
43078
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 42746
diff changeset
   541
    @Deprecated(since = "9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        addDirtyRegion0(applet, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
42198
6ff366cc096b 8168316: Suppress deprecation warnings for Applet classes in java.desktop
prr
parents: 32834
diff changeset
   546
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    void scheduleHeavyWeightPaints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        Map<Container,Rectangle> hws;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (hwDirtyComponents.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            hws = hwDirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            hwDirtyComponents =  new IdentityHashMap<Container,Rectangle>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        for (Container hw : hws.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            Rectangle dirty = hws.get(hw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (hw instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                addDirtyRegion((Window)hw, dirty.x, dirty.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                               dirty.width, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            else if (hw instanceof Applet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                addDirtyRegion((Applet)hw, dirty.x, dirty.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                               dirty.width, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            else { // SwingHeavyWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                addDirtyRegion0(hw, dirty.x, dirty.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                dirty.width, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    // This is called from the toolkit thread when a native expose is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    // received.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    void nativeAddDirtyRegion(AppContext appContext, Container c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                              int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (w > 0 && h > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                Rectangle dirty = hwDirtyComponents.get(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                if (dirty == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    hwDirtyComponents.put(c, new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    hwDirtyComponents.put(c, SwingUtilities.computeUnion(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                              x, y, w, h, dirty));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            scheduleProcessingRunnable(appContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    // This is called from the toolkit thread when awt needs to run a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    // Runnable before we paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    //
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   599
    void nativeQueueSurfaceDataRunnable(AppContext appContext,
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   600
                                        final Component c, final Runnable r)
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   601
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (runnableList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                runnableList = new LinkedList<Runnable>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   606
            runnableList.add(new Runnable() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   607
                public void run() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   608
                    AccessControlContext stack = AccessController.getContext();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   609
                    AccessControlContext acc =
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   610
                        AWTAccessor.getComponentAccessor().getAccessControlContext(c);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   611
                    javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   612
                        public Void run() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   613
                            r.run();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   614
                            return null;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   615
                        }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   616
                    }, stack, acc);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   617
                }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   618
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        scheduleProcessingRunnable(appContext);
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
     * Extends the dirty region for the specified component to include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * the new region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @return false if <code>c</code> is not yet marked dirty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private synchronized boolean extendDirtyRegion(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        Component c, int x, int y, int w, int h) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
   631
        Rectangle r = dirtyComponents.get(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            // A non-null r implies c is already marked as dirty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            // and that the parent is valid. Therefore we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            // just union the rect and bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            SwingUtilities.computeUnion(x, y, w, h, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   642
    /**
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   643
     * Return the current dirty region for a component.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   644
     * Return an empty rectangle if the component is not
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   645
     * dirty.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   646
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   647
     * @param aComponent a component
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   648
     * @return the region
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public Rectangle getDirtyRegion(JComponent aComponent) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   651
        RepaintManager delegate = getDelegate(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   652
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   653
            return delegate.getDirtyRegion(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   654
        }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
   655
        Rectangle r;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        synchronized(this) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
   657
            r = dirtyComponents.get(aComponent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if(r == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            return new Rectangle(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            return new Rectangle(r);
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
     * Mark a component completely dirty. <b>aComponent</b> will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * completely painted during the next paintDirtyRegions() call.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   668
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   669
     * @param aComponent a component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public void markCompletelyDirty(JComponent aComponent) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   672
        RepaintManager delegate = getDelegate(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   673
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   674
            delegate.markCompletelyDirty(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   675
            return;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   676
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        addDirtyRegion(aComponent,0,0,Integer.MAX_VALUE,Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * Mark a component completely clean. <b>aComponent</b> will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * get painted during the next paintDirtyRegions() call.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   683
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   684
     * @param aComponent a component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public void markCompletelyClean(JComponent aComponent) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   687
        RepaintManager delegate = getDelegate(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   688
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   689
            delegate.markCompletelyClean(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   690
            return;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   691
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                dirtyComponents.remove(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * Convenience method that returns true if <b>aComponent</b> will be completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * painted during the next paintDirtyRegions(). If computing dirty regions is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * expensive for your component, use this method and avoid computing dirty region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * if it return true.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   702
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   703
     * @param aComponent a component
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   704
     * @return {@code true} if <b>aComponent</b> will be completely
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
   705
     *         painted during the next paintDirtyRegions().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public boolean isCompletelyDirty(JComponent aComponent) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   708
        RepaintManager delegate = getDelegate(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   709
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   710
            return delegate.isCompletelyDirty(aComponent);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
   711
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        Rectangle r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        r = getDirtyRegion(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if(r.width == Integer.MAX_VALUE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
           r.height == Integer.MAX_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Validate all of the components that have been marked invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @see #addInvalidComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public void validateInvalidComponents() {
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   728
        final java.util.List<Component> ic;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        synchronized(this) {
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   730
            if (invalidComponents == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            ic = invalidComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            invalidComponents = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        int n = ic.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        for(int i = 0; i < n; i++) {
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   738
            final Component c = ic.get(i);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   739
            AccessControlContext stack = AccessController.getContext();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   740
            AccessControlContext acc =
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   741
                AWTAccessor.getComponentAccessor().getAccessControlContext(c);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   742
            javaSecurityAccess.doIntersectionPrivilege(
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   743
                new PrivilegedAction<Void>() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   744
                    public Void run() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   745
                        c.validate();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   746
                        return null;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   747
                    }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   748
                }, stack, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * This is invoked to process paint requests.  It's needed
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18231
diff changeset
   755
     * for backward compatibility in so far as RepaintManager would previously
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * not see paint requests for top levels, so, we have to make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * a subclass correctly paints any dirty top levels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private void prePaintDirtyRegions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        Map<Component,Rectangle> dirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        java.util.List<Runnable> runnableList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            dirtyComponents = this.dirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            runnableList = this.runnableList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            this.runnableList = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if (runnableList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            for (Runnable runnable : runnableList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        paintDirtyRegions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (dirtyComponents.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            // This'll only happen if a subclass isn't correctly dealing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            // with toplevels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            paintDirtyRegions(dirtyComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   780
    private void updateWindows(Map<Component,Rectangle> dirtyComponents) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   781
        Toolkit toolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   782
        if (!(toolkit instanceof SunToolkit &&
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   783
              ((SunToolkit)toolkit).needUpdateWindow()))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   784
        {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   785
            return;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   786
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   787
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   788
        Set<Window> windows = new HashSet<Window>();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   789
        Set<Component> dirtyComps = dirtyComponents.keySet();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   790
        for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   791
            Component dirty = it.next();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   792
            Window window = dirty instanceof Window ?
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   793
                (Window)dirty :
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   794
                SwingUtilities.getWindowAncestor(dirty);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   795
            if (window != null &&
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   796
                !window.isOpaque())
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   797
            {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   798
                windows.add(window);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   799
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   800
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   801
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   802
        for (Window window : windows) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   803
            AWTAccessor.getWindowAccessor().updateWindow(window);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   804
        }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   805
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   806
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   807
    boolean isPainting() {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   808
        return painting;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   809
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1301
diff changeset
   810
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * Paint all of the components that have been marked dirty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see #addDirtyRegion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public void paintDirtyRegions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        synchronized(this) {  // swap for thread safety
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            Map<Component,Rectangle> tmp = tmpDirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            tmpDirtyComponents = dirtyComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            dirtyComponents = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            dirtyComponents.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        paintDirtyRegions(tmpDirtyComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   826
    private void paintDirtyRegions(
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   827
        final Map<Component,Rectangle> tmpDirtyComponents)
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   828
    {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   829
        if (tmpDirtyComponents.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   833
        final java.util.List<Component> roots =
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   834
            new ArrayList<Component>(tmpDirtyComponents.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        for (Component dirty : tmpDirtyComponents.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            collectDirtyComponents(tmpDirtyComponents, dirty, roots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   839
        final AtomicInteger count = new AtomicInteger(roots.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        painting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        try {
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   842
            for (int j=0 ; j < count.get(); j++) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   843
                final int i = j;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   844
                final Component dirtyComponent = roots.get(j);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   845
                AccessControlContext stack = AccessController.getContext();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   846
                AccessControlContext acc =
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   847
                    AWTAccessor.getComponentAccessor().getAccessControlContext(dirtyComponent);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   848
                javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   849
                    public Void run() {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   850
                        Rectangle rect = tmpDirtyComponents.get(dirtyComponent);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   851
                        // Sometimes when RepaintManager is changed during the painting
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   852
                        // we may get null here, see #6995769 for details
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   853
                        if (rect == null) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   854
                            return null;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   855
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   857
                        int localBoundsH = dirtyComponent.getHeight();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   858
                        int localBoundsW = dirtyComponent.getWidth();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   859
                        SwingUtilities.computeIntersection(0,
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   860
                                                           0,
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   861
                                                           localBoundsW,
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   862
                                                           localBoundsH,
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   863
                                                           rect);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   864
                        if (dirtyComponent instanceof JComponent) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   865
                            ((JComponent)dirtyComponent).paintImmediately(
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   866
                                rect.x,rect.y,rect.width, rect.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                        }
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   868
                        else if (dirtyComponent.isShowing()) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   869
                            Graphics g = JComponent.safelyGetGraphics(
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   870
                                    dirtyComponent, dirtyComponent);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   871
                            // If the Graphics goes away, it means someone disposed of
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   872
                            // the window, don't do anything.
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   873
                            if (g != null) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   874
                                g.setClip(rect.x, rect.y, rect.width, rect.height);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   875
                                try {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   876
                                    dirtyComponent.paint(g);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   877
                                } finally {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   878
                                    g.dispose();
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   879
                                }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   880
                            }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   881
                        }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   882
                        // If the repaintRoot has been set, service it now and
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   883
                        // remove any components that are children of repaintRoot.
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   884
                        if (repaintRoot != null) {
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   885
                            adjustRoots(repaintRoot, roots, i + 1);
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   886
                            count.set(roots.size());
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   887
                            paintManager.isRepaintingRoot = true;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   888
                            repaintRoot.paintImmediately(0, 0, repaintRoot.getWidth(),
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   889
                                                         repaintRoot.getHeight());
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   890
                            paintManager.isRepaintingRoot = false;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   891
                            // Only service repaintRoot once.
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   892
                            repaintRoot = null;
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   893
                        }
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   894
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   895
                        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    }
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 13233
diff changeset
   897
                }, stack, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            painting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   902
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   903
        updateWindows(tmpDirtyComponents);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
   904
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        tmpDirtyComponents.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * Removes any components from roots that are children of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    private void adjustRoots(JComponent root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                             java.util.List<Component> roots, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        for (int i = roots.size() - 1; i >= index; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            Component c = roots.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                if (c == root || c == null || !(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            if (c == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                roots.remove(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    Rectangle tmp = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    void collectDirtyComponents(Map<Component,Rectangle> dirtyComponents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                Component dirtyComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                java.util.List<Component> roots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int dx, dy, rootDx, rootDy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        Component component, rootDirtyComponent,parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        Rectangle cBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        // Find the highest parent which is dirty.  When we get out of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        // rootDx and rootDy will contain the translation from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        // rootDirtyComponent's coordinate system to the coordinates of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        // original dirty component.  The tmp Rect is also used to compute the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        // visible portion of the dirtyRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        component = rootDirtyComponent = dirtyComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        int x = dirtyComponent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        int y = dirtyComponent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        int w = dirtyComponent.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        int h = dirtyComponent.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        dx = rootDx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        dy = rootDy = 0;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
   953
        tmp.setBounds(dirtyComponents.get(dirtyComponent));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        // System.out.println("Collect dirty component for bound " + tmp +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        //                                   "component bounds is " + cBounds);;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        SwingUtilities.computeIntersection(0,0,w,h,tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (tmp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // System.out.println("Empty 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if(!(component instanceof JComponent))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            parent = component.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            component = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            dx += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            dy += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            tmp.setLocation(tmp.x + x, tmp.y + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            x = component.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            y = component.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            w = component.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            h = component.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            tmp = SwingUtilities.computeIntersection(0,0,w,h,tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            if (tmp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                // System.out.println("Empty 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            if (dirtyComponents.get(component) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                rootDirtyComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                rootDx = dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                rootDy = dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        if (dirtyComponent != rootDirtyComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            Rectangle r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            tmp.setLocation(tmp.x + rootDx - dx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                            tmp.y + rootDy - dy);
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
  1000
            r = dirtyComponents.get(rootDirtyComponent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        // If we haven't seen this root before, then we need to add it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        // list of root dirty Views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (!roots.contains(rootDirtyComponent))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            roots.add(rootDirtyComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * Returns a string that displays and identifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * object's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @return a String representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    public synchronized String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23328
diff changeset
  1019
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        if(dirtyComponents != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            sb.append("" + dirtyComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1026
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * Return the offscreen buffer that should be used as a double buffer with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * the component <code>c</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * By default there is a double buffer per RepaintManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * The buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * This happens when the maximum double buffer size as been set for the receiving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * repaint manager.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1033
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1034
     * @param c the component
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1035
     * @param proposedWidth the width of the buffer
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1036
     * @param proposedHeight the height of the buffer
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1037
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1038
     * @return the image
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    public Image getOffscreenBuffer(Component c,int proposedWidth,int proposedHeight) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1041
        RepaintManager delegate = getDelegate(c);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1042
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1043
            return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1044
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        return _getOffscreenBuffer(c, proposedWidth, proposedHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1048
    /**
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1049
     * Return a volatile offscreen buffer that should be used as a
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1050
     * double buffer with the specified component <code>c</code>.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1051
     * The image returned will be an instance of VolatileImage, or null
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1052
     * if a VolatileImage object could not be instantiated.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1053
     * This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1054
     * This happens when the maximum double buffer size has been set for this
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1055
     * repaint manager.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1056
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1057
     * @param c the component
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1058
     * @param proposedWidth the width of the buffer
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1059
     * @param proposedHeight the height of the buffer
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1060
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1061
     * @return the volatile image
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1062
     * @see java.awt.image.VolatileImage
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1063
     * @since 1.4
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1064
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public Image getVolatileOffscreenBuffer(Component c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                                            int proposedWidth,int proposedHeight) {
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1067
        RepaintManager delegate = getDelegate(c);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1068
        if (delegate != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1069
            return delegate.getVolatileOffscreenBuffer(c, proposedWidth,
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1070
                                                        proposedHeight);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1071
        }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1072
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1073
        // If the window is non-opaque, it's double-buffered at peer's level
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1074
        Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
  1075
        if (!w.isOpaque()) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1076
            Toolkit tk = Toolkit.getDefaultToolkit();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1077
            if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1078
                return null;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1079
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1080
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1081
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        GraphicsConfiguration config = c.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        if (config == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            config = GraphicsEnvironment.getLocalGraphicsEnvironment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                            getDefaultScreenDevice().getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        Dimension maxSize = getDoubleBufferMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        int width = proposedWidth < 1 ? 1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        int height = proposedHeight < 1 ? 1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        VolatileImage image = volatileMap.get(config);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        if (image == null || image.getWidth() < width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                             image.getHeight() < height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                image.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            }
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1098
            image = config.createCompatibleVolatileImage(width, height,
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1099
                                                         volatileBufferType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            volatileMap.put(config, image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        Dimension maxSize = getDoubleBufferMaximumSize();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
  1107
        DoubleBufferInfo doubleBuffer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        int width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1110
        // If the window is non-opaque, it's double-buffered at peer's level
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1111
        Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
  1112
        if (!w.isOpaque()) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1113
            Toolkit tk = Toolkit.getDefaultToolkit();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1114
            if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1115
                return null;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1116
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1117
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2460
diff changeset
  1118
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        if (standardDoubleBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            standardDoubleBuffer = new DoubleBufferInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        doubleBuffer = standardDoubleBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        width = proposedWidth < 1? 1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                  (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        height = proposedHeight < 1? 1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                  (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        if (doubleBuffer.needsReset || (doubleBuffer.image != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                                        (doubleBuffer.size.width < width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                                         doubleBuffer.size.height < height))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            doubleBuffer.needsReset = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            if (doubleBuffer.image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                doubleBuffer.image.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                doubleBuffer.image = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            width = Math.max(doubleBuffer.size.width, width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            height = Math.max(doubleBuffer.size.height, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        Image result = doubleBuffer.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        if (doubleBuffer.image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            result = c.createImage(width , height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            doubleBuffer.size = new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            if (c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                ((JComponent)c).setCreatedDoubleBuffer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                doubleBuffer.image = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            // JComponent will inform us when it is no longer valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            // (via removeNotify) we have no such hook to other components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            // therefore we don't keep a ref to the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            // (indirectly through the Image) by stashing the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1159
    /**
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1160
     * Set the maximum double buffer size.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1161
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1162
     * @param d the dimension
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24969
diff changeset
  1163
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    public void setDoubleBufferMaximumSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        doubleBufferMaxSize = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        if (doubleBufferMaxSize == null) {
49086
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
  1167
            isCustomMaxBufferSizeSet = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            clearImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        } else {
49086
96ea4dff640e 8197499: RepaintManager does not increase double buffer after attaching a device with higher resolution
avu
parents: 47216
diff changeset
  1170
            isCustomMaxBufferSizeSet = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            clearImages(d.width, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    private void clearImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        clearImages(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    private void clearImages(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        if (standardDoubleBuffer != null && standardDoubleBuffer.image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            if (standardDoubleBuffer.image.getWidth(null) > width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                standardDoubleBuffer.image.getHeight(null) > height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                standardDoubleBuffer.image.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                standardDoubleBuffer.image = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        // Clear out the VolatileImages
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10103
diff changeset
  1188
        Iterator<GraphicsConfiguration> gcs = volatileMap.keySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        while (gcs.hasNext()) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10103
diff changeset
  1190
            GraphicsConfiguration gc = gcs.next();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
  1191
            VolatileImage image = volatileMap.get(gc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            if (image.getWidth() > width || image.getHeight() > height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                image.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                gcs.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * Returns the maximum double buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * @return a Dimension object representing the maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    public Dimension getDoubleBufferMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (doubleBufferMaxSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                Rectangle virtualBounds = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                GraphicsEnvironment ge = GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                                                 getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                for (GraphicsDevice gd : ge.getScreenDevices()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                    virtualBounds = virtualBounds.union(gc.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                doubleBufferMaxSize = new Dimension(virtualBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                                                    virtualBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            } catch (HeadlessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                doubleBufferMaxSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        return doubleBufferMaxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * Enables or disables double buffering in this RepaintManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * CAUTION: The default value for this property is set for optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * paint performance on the given platform and it is not recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * that programs modify this property directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * @param aFlag  true to activate double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * @see #isDoubleBufferingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    public void setDoubleBufferingEnabled(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        doubleBufferingEnabled = aFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        PaintManager paintManager = getPaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        if (!aFlag && paintManager.getClass() != PaintManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            setPaintManager(new PaintManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * Returns true if this RepaintManager is double buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * The default value for this property may vary from platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * to platform.  On platforms where native double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * is supported in the AWT, the default value will be <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * to avoid unnecessary buffering in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * On platforms where native double buffering is not supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * the default value will be <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @return true if this object is double buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public boolean isDoubleBufferingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        return doubleBufferingEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * This resets the double buffer. Actually, it marks the double buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * as invalid, the double buffer will then be recreated on the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * invocation of getOffscreenBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    void resetDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        if (standardDoubleBuffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            standardDoubleBuffer.needsReset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * This resets the volatile double buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    void resetVolatileDoubleBuffer(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        Image image = volatileMap.remove(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            image.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * Returns true if we should use the <code>Image</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * from <code>getVolatileOffscreenBuffer</code> to do double buffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    boolean useVolatileDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        return volatileImageBufferEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * Returns true if the current thread is the thread painting.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * will return false if no threads are painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    private synchronized boolean isPaintingThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        return (Thread.currentThread() == paintThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    // Paint methods.  You very, VERY rarely need to invoke these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    // They are invoked directly from JComponent's painting code and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    // when painting happens outside the normal flow: DefaultDesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    // and JViewport.  If you end up needing these methods in other places be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    // careful that you don't get stuck in a paint loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * Paints a region of a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * @param paintingComponent Component to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * @param bufferComponent Component to obtain buffer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @param x X-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @param y Y-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * @param w Width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * @param h Height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    void paint(JComponent paintingComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
               JComponent bufferComponent, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        PaintManager paintManager = getPaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        if (!isPaintingThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            // We're painting to two threads at once.  PaintManager deals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            // with this a bit better than BufferStrategyPaintManager, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            // it to avoid possible exceptions/corruption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            if (paintManager.getClass() != PaintManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                paintManager = new PaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                paintManager.repaintManager = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        if (!paintManager.paint(paintingComponent, bufferComponent, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                                x, y, w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            g.setClip(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            paintingComponent.paintToOffscreen(g, x, y, w, h, x + w, y + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * Does a copy area on the specified region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * @param clip Whether or not the copyArea needs to be clipped to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     *             Component's bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    void copyArea(JComponent c, Graphics g, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                  int deltaX, int deltaY, boolean clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        getPaintManager().copyArea(c, g, x, y, w, h, deltaX, deltaY, clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1341
    private java.util.List<RepaintListener> repaintListeners = new ArrayList<>(1);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1342
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1343
    private void addRepaintListener(RepaintListener l) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1344
        repaintListeners.add(l);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1345
    }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1346
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1347
    private void removeRepaintListener(RepaintListener l) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1348
        repaintListeners.remove(l);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1349
    }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1350
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1351
    /**
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1352
     * Notify the attached repaint listeners that an area of the {@code c} component
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1353
     * has been immediately repainted, that is without scheduling a repaint runnable,
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1354
     * due to performing a "blit" (via calling the {@code copyArea} method).
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1355
     *
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1356
     * @param c the component
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1357
     * @param x the x coordinate of the area
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1358
     * @param y the y coordinate of the area
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1359
     * @param w the width of the area
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1360
     * @param h the height of the area
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1361
     */
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1362
    void notifyRepaintPerformed(JComponent c, int x, int y, int w, int h) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1363
        for (RepaintListener l : repaintListeners) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1364
            l.repaintPerformed(c, x, y, w, h);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1365
        }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1366
    }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 21278
diff changeset
  1367
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * Invoked prior to any paint/copyArea method calls.  This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * be followed by an invocation of <code>endPaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * <b>WARNING</b>: Callers of this method need to wrap the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * in a <code>try/finally</code>, otherwise if an exception is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * during the course of painting the RepaintManager may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * be left in a state in which the screen is not updated, eg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * repaintManager.beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     *   repaintManager.paint(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     *   repaintManager.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    void beginPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        boolean multiThreadedPaint = false;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 1291
diff changeset
  1386
        int paintDepth;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        Thread currentThread = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            paintDepth = this.paintDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            if (paintThread == null || currentThread == paintThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                paintThread = currentThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                this.paintDepth++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                multiThreadedPaint = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        if (!multiThreadedPaint && paintDepth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            getPaintManager().beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * Invoked after <code>beginPaint</code> has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    void endPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        if (isPaintingThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            PaintManager paintManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                if (--paintDepth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    paintManager = getPaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            if (paintManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                paintManager.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                    paintThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * If possible this will show a previously rendered portion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * a Component.  If successful, this will return true, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * WARNING: This method is invoked from the native toolkit thread, be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * very careful as to what methods this invokes!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    boolean show(Container c, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        return getPaintManager().show(c, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * Invoked when the doubleBuffered or useTrueDoubleBuffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * properties of a JRootPane change.  This may come in on any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    void doubleBufferingChanged(JRootPane rootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        getPaintManager().doubleBufferingChanged(rootPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * Sets the <code>PaintManager</code> that is used to handle all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * double buffered painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * @param paintManager The PaintManager to use.  Passing in null indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     *        the fallback PaintManager should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    void setPaintManager(PaintManager paintManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        if (paintManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            paintManager = new PaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        PaintManager oldPaintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            oldPaintManager = this.paintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            this.paintManager = paintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            paintManager.repaintManager = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        if (oldPaintManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            oldPaintManager.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    private synchronized PaintManager getPaintManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        if (paintManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            PaintManager paintManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            if (doubleBufferingEnabled && !nativeDoubleBuffering) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                switch (bufferStrategyType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                case BUFFER_STRATEGY_NOT_SPECIFIED:
1832
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1469
                    Toolkit tk = Toolkit.getDefaultToolkit();
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1470
                    if (tk instanceof SunToolkit) {
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1471
                        SunToolkit stk = (SunToolkit) tk;
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1472
                        if (stk.useBufferPerWindow()) {
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1473
                            paintManager = new BufferStrategyPaintManager();
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1474
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                case BUFFER_STRATEGY_SPECIFIED_ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                    paintManager = new BufferStrategyPaintManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            // null case handled in setPaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            setPaintManager(paintManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        return paintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    private void scheduleProcessingRunnable(AppContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        if (processingRunnable.markPending()) {
1832
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1492
            Toolkit tk = Toolkit.getDefaultToolkit();
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1493
            if (tk instanceof SunToolkit) {
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1494
                SunToolkit.getSystemEventQueueImplPP(context).
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1495
                  postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(),
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1496
                                                processingRunnable));
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1497
            } else {
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1498
                Toolkit.getDefaultToolkit().getSystemEventQueue().
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1499
                      postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(),
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1500
                                                    processingRunnable));
0a885bee1070 6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents: 1301
diff changeset
  1501
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * PaintManager is used to handle all double buffered painting for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * Swing.  Subclasses should call back into the JComponent method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * <code>paintToOffscreen</code> to handle the actual painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    static class PaintManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         * RepaintManager the PaintManager has been installed on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        protected RepaintManager repaintManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        boolean isRepaintingRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
         * Paints a region of a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * @param paintingComponent Component to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * @param bufferComponent Component to obtain buffer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         * @param x X-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * @param y Y-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         * @param w Width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * @param h Height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * @return true if painting was successful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        public boolean paint(JComponent paintingComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                             JComponent bufferComponent, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                             int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            // First attempt to use VolatileImage buffer for performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            // If this fails (which should rarely occur), fallback to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            // standard Image buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            boolean paintCompleted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            Image offscreen;
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1538
            int sw = w + 1;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1539
            int sh = h + 1;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1540
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            if (repaintManager.useVolatileDoubleBuffer() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                (offscreen = getValidImage(repaintManager.
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1543
                getVolatileOffscreenBuffer(bufferComponent, sw, sh))) != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                VolatileImage vImage = (java.awt.image.VolatileImage)offscreen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                GraphicsConfiguration gc = bufferComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                                            getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                for (int i = 0; !paintCompleted &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                         i < RepaintManager.VOLATILE_LOOP_MAX; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                    if (vImage.validate(gc) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                                   VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                        repaintManager.resetVolatileDoubleBuffer(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                        offscreen = repaintManager.getVolatileOffscreenBuffer(
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1553
                            bufferComponent, sw, sh);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                        vImage = (java.awt.image.VolatileImage)offscreen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                    paintDoubleBuffered(paintingComponent, vImage, g, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                                        w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                    paintCompleted = !vImage.contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            // VolatileImage painting loop failed, fallback to regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            // offscreen buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            if (!paintCompleted && (offscreen = getValidImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                      repaintManager.getOffscreenBuffer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                      bufferComponent, w, h))) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                paintDoubleBuffered(paintingComponent, offscreen, g, x, y, w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                                    h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                paintCompleted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            return paintCompleted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
         * Does a copy area on the specified region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        public void copyArea(JComponent c, Graphics g, int x, int y, int w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                             int h, int deltaX, int deltaY, boolean clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            g.copyArea(x, y, w, h, deltaX, deltaY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
         * Invoked prior to any calls to paint or copyArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        public void beginPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
         * Invoked to indicate painting has been completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        public void endPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
         * Shows a region of a previously rendered component.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
         * will return true if successful, false otherwise.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
         * implementation returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        public boolean show(Container c, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
         * Invoked when the doubleBuffered or useTrueDoubleBuffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
         * properties of a JRootPane change.  This may come in on any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        public void doubleBufferingChanged(JRootPane rootPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         * Paints a portion of a component to an offscreen buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        protected void paintDoubleBuffered(JComponent c, Image image,
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1613
                Graphics g, int clipX, int clipY,
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1614
                int clipW, int clipH) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1615
            if (image instanceof VolatileImage && isPixelsCopying(c, g)) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1616
                paintDoubleBufferedFPScales(c, image, g, clipX, clipY, clipW, clipH);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1617
            } else {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1618
                paintDoubleBufferedImpl(c, image, g, clipX, clipY, clipW, clipH);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1619
            }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1620
        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1621
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1622
        private void paintDoubleBufferedImpl(JComponent c, Image image,
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1623
                                             Graphics g, int clipX, int clipY,
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1624
                                             int clipW, int clipH) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            Graphics osg = image.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            int bw = Math.min(clipW, image.getWidth(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            int bh = Math.min(clipH, image.getHeight(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            int x,y,maxx,maxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                for(x = clipX, maxx = clipX+clipW; x < maxx ;  x += bw ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                    for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        osg.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                        osg.setClip(x,y,bw,bh);
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1635
                        if (volatileBufferType != Transparency.OPAQUE
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1636
                                && osg instanceof Graphics2D) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1637
                            final Graphics2D g2d = (Graphics2D) osg;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1638
                            final Color oldBg = g2d.getBackground();
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1639
                            g2d.setBackground(c.getBackground());
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1640
                            g2d.clearRect(x, y, bw, bh);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1641
                            g2d.setBackground(oldBg);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1642
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                        c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                        g.setClip(x, y, bw, bh);
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1645
                        if (volatileBufferType != Transparency.OPAQUE
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1646
                                && g instanceof Graphics2D) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1647
                            final Graphics2D g2d = (Graphics2D) g;
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1648
                            final Composite oldComposite = g2d.getComposite();
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1649
                            g2d.setComposite(AlphaComposite.Src);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1650
                            g2d.drawImage(image, x, y, c);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1651
                            g2d.setComposite(oldComposite);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1652
                        } else {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1653
                            g.drawImage(image, x, y, c);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 11268
diff changeset
  1654
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                        osg.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                osg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1663
        private void paintDoubleBufferedFPScales(JComponent c, Image image,
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1664
                                                 Graphics g, int clipX, int clipY,
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1665
                                                 int clipW, int clipH) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1666
            Graphics osg = image.getGraphics();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1667
            Graphics2D g2d = (Graphics2D) g;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1668
            Graphics2D osg2d = (Graphics2D) osg;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1669
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1670
            AffineTransform identity = new AffineTransform();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1671
            int bw = Math.min(clipW, image.getWidth(null));
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1672
            int bh = Math.min(clipH, image.getHeight(null));
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1673
            int x, y, maxx, maxy;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1674
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1675
            AffineTransform tx = g2d.getTransform();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1676
            double scaleX = tx.getScaleX();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1677
            double scaleY = tx.getScaleY();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1678
            double trX = tx.getTranslateX();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1679
            double trY = tx.getTranslateY();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1680
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1681
            boolean translucent = volatileBufferType != Transparency.OPAQUE;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1682
            Composite oldComposite = g2d.getComposite();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1683
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1684
            try {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1685
                for (x = clipX, maxx = clipX + clipW; x < maxx; x += bw) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1686
                    for (y = clipY, maxy = clipY + clipH; y < maxy; y += bh) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1687
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1688
                        // draw x, y, bw, bh
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1689
                        int pixelx1 = Region.clipRound(x * scaleX + trX);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1690
                        int pixely1 = Region.clipRound(y * scaleY + trY);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1691
                        int pixelx2 = Region.clipRound((x + bw) * scaleX + trX);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1692
                        int pixely2 = Region.clipRound((y + bh) * scaleY + trY);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1693
                        int pixelw = pixelx2 - pixelx1;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1694
                        int pixelh = pixely2 - pixely1;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1695
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1696
                        osg2d.setTransform(identity);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1697
                        if (translucent) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1698
                            final Color oldBg = g2d.getBackground();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1699
                            g2d.setBackground(c.getBackground());
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1700
                            g2d.clearRect(pixelx1, pixely1, pixelw, pixelh);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1701
                            g2d.setBackground(oldBg);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1702
                        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1703
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1704
                        osg2d.setClip(0, 0, pixelw, pixelh);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1705
                        osg2d.translate(trX - pixelx1, trY - pixely1);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1706
                        osg2d.scale(scaleX, scaleY);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1707
                        c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1708
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1709
                        g2d.setTransform(identity);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1710
                        g2d.setClip(pixelx1, pixely1, pixelw, pixelh);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1711
                        AffineTransform stx = new AffineTransform();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1712
                        stx.translate(pixelx1, pixely1);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1713
                        stx.scale(scaleX, scaleY);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1714
                        g2d.setTransform(stx);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1715
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1716
                        if (translucent) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1717
                            g2d.setComposite(AlphaComposite.Src);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1718
                        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1719
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1720
                        g2d.drawImage(image, 0, 0, c);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1721
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1722
                        if (translucent) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1723
                            g2d.setComposite(oldComposite);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1724
                        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1725
                        g2d.setTransform(tx);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1726
                    }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1727
                }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1728
            } finally {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1729
                osg.dispose();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1730
            }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1731
        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1732
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
         * If <code>image</code> is non-null with a positive size it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
         * is returned, otherwise null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        private Image getValidImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            if (image != null && image.getWidth(null) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                                 image.getHeight(null) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
         * Schedules a repaint for the specified component.  This differs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
         * from <code>root.repaint</code> in that if the RepaintManager is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
         * currently processing paint requests it'll process this request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
         * with the current set of requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        protected void repaintRoot(JComponent root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            assert (repaintManager.repaintRoot == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            if (repaintManager.painting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                repaintManager.repaintRoot = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                root.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
         * Returns true if the component being painted is the root component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
         * that was previously passed to <code>repaintRoot</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        protected boolean isRepaintingRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            return isRepaintingRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
         * Cleans up any state.  After invoked the PaintManager will no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
         * longer be used anymore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        protected void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        }
42746
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1775
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1776
        private boolean isPixelsCopying(JComponent c, Graphics g) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1777
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1778
            AffineTransform tx = getTransform(g);
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1779
            GraphicsConfiguration gc = c.getGraphicsConfiguration();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1780
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1781
            if (tx == null || gc == null
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1782
                    || !SwingUtilities2.isFloatingPointScale(tx)) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1783
                return false;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1784
            }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1785
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1786
            AffineTransform gcTx = gc.getDefaultTransform();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1787
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1788
            return gcTx.getScaleX() == tx.getScaleX()
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1789
                    && gcTx.getScaleY() == tx.getScaleY();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1790
        }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1791
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1792
        private static AffineTransform getTransform(Graphics g) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1793
            if (g instanceof SunGraphics2D) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1794
                return ((SunGraphics2D) g).transform;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1795
            } else if (g instanceof Graphics2D) {
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1796
                return ((Graphics2D) g).getTransform();
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1797
            }
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1798
            return null;
cc51736a710c 8162350: RepaintManager shifts repainted region when the floating point UI scale is used
alexsch
parents: 42198
diff changeset
  1799
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
    private class DoubleBufferInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        public Image image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        public Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        public boolean needsReset = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * Listener installed to detect display changes. When display changes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * schedules a callback to notify all RepaintManagers of the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * changes. Only one DisplayChangedHandler is ever installed. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * singleton instance will schedule notification for all AppContexts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    private static final class DisplayChangedHandler implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                                             DisplayChangedListener {
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1817
        // Empty non private constructor was added because access to this
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1818
        // class shouldn't be generated by the compiler using synthetic
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1819
        // accessor method
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1820
        DisplayChangedHandler() {
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1821
        }
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1822
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            scheduleDisplayChanges();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1830
        private static void scheduleDisplayChanges() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            // To avoid threading problems, we notify each RepaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            // on the thread it was created on.
30946
0e1542fb9cb4 8041654: OutOfMemoryError: RepaintManager doesn't clean up cache of volatile images
serb
parents: 30469
diff changeset
  1833
            for (AppContext context : AppContext.getAppContexts()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                synchronized(context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    if (!context.isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                        EventQueue eventQueue = (EventQueue)context.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                            AppContext.EVENT_QUEUE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                        if (eventQueue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                            eventQueue.postEvent(new InvocationEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                                Toolkit.getDefaultToolkit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                                new DisplayChangedRunnable()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    private static final class DisplayChangedRunnable implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            RepaintManager.currentManager((JComponent)null).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * Runnable used to process all repaint/revalidate requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    private final class ProcessingRunnable implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        // If true, we're wainting on the EventQueue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        private boolean pending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
         * Marks this processing runnable as pending. If this was not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
         * already marked as pending, true is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        public synchronized boolean markPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            if (!pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                pending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                pending = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            // First pass, flush any heavy paint events into real paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            // events.  If there are pending heavy weight requests this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            // result in q'ing this request up one more time.  As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            // long as no other requests come in between now and the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            // the second one is processed nothing will happen.  This is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            // ideal, but the logic needed to suppress the second request is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            // more headache than it's worth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            scheduleHeavyWeightPaints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            // Do the actual validation and painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            validateInvalidComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            prePaintDirtyRegions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    }
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1893
    private RepaintManager getDelegate(Component c) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1894
        RepaintManager delegate = SwingUtilities3.getDelegateRepaintManager(c);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1895
        if (this == delegate) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1896
            delegate = null;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1897
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1898
        return delegate;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents: 2
diff changeset
  1899
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
}