aboutsummaryrefslogtreecommitdiff
path: root/src/windows/classes/sun/java2d/ScreenUpdateManager.java
blob: ab09a972fa0c7f6226487e27217df1bac95fe242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

package sun.java2d;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import sun.awt.Win32GraphicsConfig;
import sun.awt.windows.WComponentPeer;
import sun.java2d.d3d.D3DScreenUpdateManager;
import sun.java2d.windows.WindowsFlags;

/**
 * This class handles the creation of on-screen surfaces and
 * corresponding graphics objects.
 *
 * By default it delegates the surface creation to the
 * particular GraphicsConfiguration classes.
 */
public class ScreenUpdateManager {
    private static ScreenUpdateManager theInstance;

    protected ScreenUpdateManager() {
    }

    /**
     * Creates a SunGraphics2D object for the surface,
     * given the parameters.
     *
     * @param sd surface data for which a graphics is to be created
     * @param peer peer which owns the surface
     * @param fgColor fg color to be used in the graphics
     * @param bgColor bg color to be used in the graphics
     * @param font font to be used in the graphics
     * @return a SunGraphics2D object for rendering to the passed surface
     */
    public synchronized Graphics2D createGraphics(SurfaceData sd,
            WComponentPeer peer, Color fgColor, Color bgColor, Font font)
    {
        return new SunGraphics2D(sd, fgColor, bgColor, font);
    }

    /**
     * Creates and returns the surface for the peer. This surface becomes
     * managed by this manager. To remove the surface from the managed list
     * {@code}dropScreenSurface(SurfaceData){@code} will need to be called.
     *
     * The default implementation delegates surface creation
     * to the passed in GraphicsConfiguration object.
     *
     * @param gc graphics configuration for which the surface is to be created
     * @param peer peer for which the onscreen surface is to be created
     * @param bbNum number of back-buffers requested for this peer
     * @param isResize whether this surface is being created in response to
     * a component resize event
     * @return a SurfaceData to be used for on-screen rendering for this peer.
     * @see #dropScreenSurface(SurfaceData)
     */
    public SurfaceData createScreenSurface(Win32GraphicsConfig gc,
                                           WComponentPeer peer, int bbNum,
                                           boolean isResize)
    {
        return gc.createSurfaceData(peer, bbNum);
    }

    /**
     * Drops the passed surface from the list of managed surfaces.
     *
     * Nothing happens if the surface wasn't managed by this manager.
     *
     * @param sd SurfaceData to be removed from the list of managed surfaces
     */
    public void dropScreenSurface(SurfaceData sd) {}

    /**
     * Returns a replacement SurfaceData for the invalid passed one.
     *
     * This method should be used by SurfaceData's created by
     * the ScreenUpdateManager for providing replacement surfaces.
     *
     * @param peer to which the old surface belongs
     * @param oldsd the old (invalid) surface to get replaced
     * @return a replacement surface
     * @see sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData#getReplacement()
     * @see sun.java2d.windows.GDIWindowSurfaceData#getReplacement()
     */
    public SurfaceData getReplacementScreenSurface(WComponentPeer peer,
                                                   SurfaceData oldsd)
    {
        return peer.getSurfaceData();
    }

    /**
     * Returns an (singleton) instance of the screen surfaces
     * manager class.
     * @return instance of onscreen surfaces manager
     */
    public static synchronized ScreenUpdateManager getInstance() {
        if (theInstance == null) {
            if (WindowsFlags.isD3DEnabled()) {
                theInstance = new D3DScreenUpdateManager();
            } else {
                theInstance = new ScreenUpdateManager();
            }
        }
        return theInstance;
    }
}