src/java.desktop/share/classes/sun/java2d/SurfaceManagerFactory.java
author aghaisas
Wed, 20 Feb 2019 17:00:40 +0530
branchmetal-prototype-branch
changeset 57196 a95707a39ff5
parent 47216 71c04702a3d5
permissions -rw-r--r--
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering Contributed-by: jdv, aghaisas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 557
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
     4
 *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
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: 557
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 557
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    10
 *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    15
 * accompanied this code).
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    16
 *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 557
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 557
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 557
diff changeset
    23
 * questions.
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    24
 */
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    25
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    26
package sun.java2d;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    27
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    28
import sun.awt.image.SunVolatileImage;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    29
import sun.awt.image.VolatileSurfaceManager;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    30
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    31
/**
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    32
 * This factory creates platform specific VolatileSurfaceManager
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    33
 * implementations.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    34
 *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    35
 * There are two platform specific SurfaceManagerFactories in OpenJDK,
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    36
 * UnixSurfaceManagerFactory and WindowsSurfaceManagerFactory.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    37
 * The actually used SurfaceManagerFactory is set by the respective platform
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    38
 * GraphicsEnvironment implementations in the static initializer.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    39
 */
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    40
public abstract class SurfaceManagerFactory {
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    41
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    42
    /**
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    43
     * The single shared instance.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    44
     */
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    45
    private static SurfaceManagerFactory instance;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    46
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    47
    /**
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    48
     * Returns the surface manager factory instance. This returns a factory
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    49
     * that has been set by {@link #setInstance(SurfaceManagerFactory)}.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    50
     *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    51
     * @return the surface manager factory
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    52
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    53
    public static synchronized SurfaceManagerFactory getInstance() {
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    54
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    55
        if (instance == null) {
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    56
            throw new IllegalStateException("No SurfaceManagerFactory set.");
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    57
        }
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    58
        return instance;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    59
    }
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    60
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    61
    /**
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    62
     * Sets the surface manager factory. This may only be called once, and it
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    63
     * may not be set back to {@code null} when the factory is already
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    64
     * instantiated.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    65
     *
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    66
     * @param factory the factory to set
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    67
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    68
    public static synchronized void setInstance(SurfaceManagerFactory factory) {
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    69
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    70
        if (factory == null) {
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    71
            // We don't want to allow setting this to null at any time.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    72
            throw new IllegalArgumentException("factory must be non-null");
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    73
        }
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    74
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    75
        if (instance != null) {
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    76
            // We don't want to re-set the instance at any time.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    77
            throw new IllegalStateException("The surface manager factory is already initialized");
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    78
        }
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    79
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    80
        instance = factory;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    81
    }
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    82
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    83
    /**
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    84
     * Creates a new instance of a VolatileSurfaceManager given any
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    85
     * arbitrary SunVolatileImage.  An optional context Object can be supplied
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    86
     * as a way for the caller to pass pipeline-specific context data to
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    87
     * the VolatileSurfaceManager (such as a backbuffer handle, for example).
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    88
     */
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    89
     public abstract VolatileSurfaceManager
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    90
         createVolatileManager(SunVolatileImage image, Object context);
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
diff changeset
    91
}