Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/ScreenUpdateManager.java
32287 views
/*1* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627import java.awt.Color;28import java.awt.Font;29import java.awt.Graphics2D;30import sun.awt.Win32GraphicsConfig;31import sun.awt.windows.WComponentPeer;32import sun.java2d.d3d.D3DScreenUpdateManager;33import sun.java2d.windows.WindowsFlags;3435/**36* This class handles the creation of on-screen surfaces and37* corresponding graphics objects.38*39* By default it delegates the surface creation to the40* particular GraphicsConfiguration classes.41*/42public class ScreenUpdateManager {43private static ScreenUpdateManager theInstance;4445protected ScreenUpdateManager() {46}4748/**49* Creates a SunGraphics2D object for the surface,50* given the parameters.51*52* @param sd surface data for which a graphics is to be created53* @param peer peer which owns the surface54* @param fgColor fg color to be used in the graphics55* @param bgColor bg color to be used in the graphics56* @param font font to be used in the graphics57* @return a SunGraphics2D object for rendering to the passed surface58*/59public synchronized Graphics2D createGraphics(SurfaceData sd,60WComponentPeer peer, Color fgColor, Color bgColor, Font font)61{62return new SunGraphics2D(sd, fgColor, bgColor, font);63}6465/**66* Creates and returns the surface for the peer. This surface becomes67* managed by this manager. To remove the surface from the managed list68* {@code}dropScreenSurface(SurfaceData){@code} will need to be called.69*70* The default implementation delegates surface creation71* to the passed in GraphicsConfiguration object.72*73* @param gc graphics configuration for which the surface is to be created74* @param peer peer for which the onscreen surface is to be created75* @param bbNum number of back-buffers requested for this peer76* @param isResize whether this surface is being created in response to77* a component resize event78* @return a SurfaceData to be used for on-screen rendering for this peer.79* @see #dropScreenSurface(SurfaceData)80*/81public SurfaceData createScreenSurface(Win32GraphicsConfig gc,82WComponentPeer peer, int bbNum,83boolean isResize)84{85return gc.createSurfaceData(peer, bbNum);86}8788/**89* Drops the passed surface from the list of managed surfaces.90*91* Nothing happens if the surface wasn't managed by this manager.92*93* @param sd SurfaceData to be removed from the list of managed surfaces94*/95public void dropScreenSurface(SurfaceData sd) {}9697/**98* Returns a replacement SurfaceData for the invalid passed one.99*100* This method should be used by SurfaceData's created by101* the ScreenUpdateManager for providing replacement surfaces.102*103* @param peer to which the old surface belongs104* @param oldsd the old (invalid) surface to get replaced105* @return a replacement surface106* @see sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData#getReplacement()107* @see sun.java2d.windows.GDIWindowSurfaceData#getReplacement()108*/109public SurfaceData getReplacementScreenSurface(WComponentPeer peer,110SurfaceData oldsd)111{112SurfaceData surfaceData = peer.getSurfaceData();113if (surfaceData == null || surfaceData.isValid()) {114return surfaceData;115}116peer.replaceSurfaceData();117return peer.getSurfaceData();118}119120/**121* Returns an (singleton) instance of the screen surfaces122* manager class.123* @return instance of onscreen surfaces manager124*/125public static synchronized ScreenUpdateManager getInstance() {126if (theInstance == null) {127if (WindowsFlags.isD3DEnabled()) {128theInstance = new D3DScreenUpdateManager();129} else {130theInstance = new ScreenUpdateManager();131}132}133return theInstance;134}135}136137138