src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 41398 jdk/src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java@1f7d85a74c12
child 52248 2e330da7cbf4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
41398
1f7d85a74c12 8155753: Removing a monitor in the OS dispaly configuration causes assertion fails under Windows if D3D is on
ssadetsky
parents: 31661
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.java2d.opengl;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import java.awt.AWTException;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.awt.BufferCapabilities;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.awt.Component;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.awt.Graphics;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.awt.Graphics2D;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.awt.Image;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.awt.ImageCapabilities;
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
    35
import java.awt.Rectangle;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import java.awt.Transparency;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import java.awt.color.ColorSpace;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import java.awt.image.BufferedImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import java.awt.image.ColorModel;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
import java.awt.image.DataBuffer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import java.awt.image.DirectColorModel;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
import java.awt.image.VolatileImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
import java.awt.image.WritableRaster;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
import sun.awt.CGraphicsConfig;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
import sun.awt.CGraphicsDevice;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
import sun.awt.image.OffScreenImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
import sun.awt.image.SunVolatileImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
import sun.java2d.Disposer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
import sun.java2d.DisposerRecord;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
import sun.java2d.Surface;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
import sun.java2d.SurfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
import sun.java2d.opengl.OGLContext.OGLContextCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
import sun.java2d.pipe.hw.AccelSurface;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
import sun.java2d.pipe.hw.AccelTypedVolatileImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
import sun.java2d.pipe.hw.ContextCapabilities;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
import static sun.java2d.opengl.OGLSurfaceData.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    60
import sun.lwawt.LWComponentPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
import sun.lwawt.macosx.CPlatformView;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    63
public final class CGLGraphicsConfig extends CGraphicsConfig
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    64
    implements OGLGraphicsConfig
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
{
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    66
    //private static final int kOpenGLSwapInterval =
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    67
    // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    private static final int kOpenGLSwapInterval = 0; // TODO
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    69
    private static boolean cglAvailable;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    private static ImageCapabilities imageCaps = new CGLImageCaps();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
    private int pixfmt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    private BufferCapabilities bufferCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    private long pConfigInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    private ContextCapabilities oglCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    private OGLContext context;
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    77
    private final Object disposerReferent = new Object();
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    78
    private final int maxTextureSize;
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    79
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    private static native boolean initCGL();
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
    81
    private static native long getCGLConfigInfo(int displayID, int visualnum,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
                                                int swapInterval);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    private static native int getOGLCapabilities(long configInfo);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    85
    /**
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    86
     * Returns GL_MAX_TEXTURE_SIZE from the shared opengl context. Must be
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    87
     * called under OGLRQ lock, because this method change current context.
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    88
     *
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    89
     * @return GL_MAX_TEXTURE_SIZE
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    90
     */
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    91
    private static native int nativeGetMaxTextureSize();
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    92
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    static {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        cglAvailable = initCGL();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
    97
    private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    98
                              long configInfo, int maxTextureSize,
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
    99
                              ContextCapabilities oglCaps) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
        super(device);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
        this.pixfmt = pixfmt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
        this.pConfigInfo = configInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
        this.oglCaps = oglCaps;
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   105
        this.maxTextureSize = maxTextureSize;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
        context = new OGLContext(OGLRenderQueue.getInstance(), this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
        // add a record to the Disposer so that we destroy the native
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
        // CGLGraphicsConfigInfo data when this object goes away
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
        Disposer.addRecord(disposerReferent,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
                           new CGLGCDisposerRecord(pConfigInfo));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    public Object getProxyKey() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        return this;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    public SurfaceData createManagedSurface(int w, int h, int transparency) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
        return CGLSurfaceData.createData(this, w, h,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
                                         getColorModel(transparency),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
                                         null,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
                                         OGLSurfaceData.TEXTURE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    public static CGLGraphicsConfig getConfig(CGraphicsDevice device,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
                                              int pixfmt)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
        if (!cglAvailable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
        long cfginfo = 0;
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   135
        int textureSize = 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
        final String ids[] = new String[1];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
        OGLRenderQueue rq = OGLRenderQueue.getInstance();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        rq.lock();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
        try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
            // getCGLConfigInfo() creates and destroys temporary
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
            // surfaces/contexts, so we should first invalidate the current
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
            // Java-level context and flush the queue...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
            OGLContext.invalidateCurrentContext();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   145
            cfginfo = getCGLConfigInfo(device.getCGDisplayID(), pixfmt,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
                                       kOpenGLSwapInterval);
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   147
            if (cfginfo != 0L) {
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   148
                textureSize = nativeGetMaxTextureSize();
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   149
                // 7160609: GL still fails to create a square texture of this
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   150
                // size. Half should be safe enough.
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   151
                // Explicitly not support a texture more than 2^14, see 8010999.
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   152
                textureSize = textureSize <= 16384 ? textureSize / 2 : 8192;
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   153
                OGLContext.setScratchSurface(cfginfo);
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   154
                rq.flushAndInvokeNow(() -> {
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   155
                    ids[0] = OGLContext.getOGLIdString();
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   156
                });
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   157
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
        } finally {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
            rq.unlock();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        if (cfginfo == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
        int oglCaps = getOGLCapabilities(cfginfo);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
        ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]);
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   167
        return new CGLGraphicsConfig(device, pixfmt, cfginfo, textureSize, caps);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
    public static boolean isCGLAvailable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
        return cglAvailable;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
     * Returns true if the provided capability bit is present for this config.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
     * See OGLContext.java for a list of supported capabilities.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
     */
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   178
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   179
    public boolean isCapPresent(int cap) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        return ((oglCaps.getCaps() & cap) != 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   183
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   184
    public long getNativeConfigInfo() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
        return pConfigInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
     * {@inheritDoc}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
     * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
     */
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   193
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   194
    public OGLContext getContext() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        return context;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    public BufferedImage createCompatibleImage(int width, int height) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
        WritableRaster
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
            raster = model.createCompatibleWritableRaster(width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
        return new BufferedImage(model, raster, model.isAlphaPremultiplied(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
                                 null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    public ColorModel getColorModel(int transparency) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
        switch (transparency) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
        case Transparency.OPAQUE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
            // REMIND: once the ColorModel spec is changed, this should be
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
            //         an opaque premultiplied DCM...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
            return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
        case Transparency.BITMASK:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
            return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
        case Transparency.TRANSLUCENT:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
            ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
            return new DirectColorModel(cs, 32,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
                                        0xff0000, 0xff00, 0xff, 0xff000000,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
                                        true, DataBuffer.TYPE_INT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    public boolean isDoubleBuffered() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
        return isCapPresent(CAPS_DOUBLEBUFFERED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
    private static class CGLGCDisposerRecord implements DisposerRecord {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
        private long pCfgInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
        public CGLGCDisposerRecord(long pCfgInfo) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
            this.pCfgInfo = pCfgInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
        public void dispose() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
            if (pCfgInfo != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
                OGLRenderQueue.disposeGraphicsConfig(pCfgInfo);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
                pCfgInfo = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    // TODO: CGraphicsConfig doesn't implement displayChanged() yet
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    //@Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    public synchronized void displayChanged() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
        //super.displayChanged();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
        // the context could hold a reference to a CGLSurfaceData, which in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
        // turn has a reference back to this CGLGraphicsConfig, so in order
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
        // for this instance to be disposed we need to break the connection
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
        OGLRenderQueue rq = OGLRenderQueue.getInstance();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
        rq.lock();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
        try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
            OGLContext.invalidateCurrentContext();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
        } finally {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
            rq.unlock();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
    public String toString() {
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   262
        int displayID = getDevice().getCGDisplayID();
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 14647
diff changeset
   263
        return ("CGLGraphicsConfig[dev="+displayID+",pixfmt="+pixfmt+"]");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    public SurfaceData createSurfaceData(CPlatformView pView) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        return CGLSurfaceData.createData(pView);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    public SurfaceData createSurfaceData(CGLLayer layer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
        return CGLSurfaceData.createData(layer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    public Image createAcceleratedImage(Component target,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
                                        int width, int height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        ColorModel model = getColorModel(Transparency.OPAQUE);
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   281
        WritableRaster wr = model.createCompatibleWritableRaster(width, height);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
        return new OffScreenImage(target, model, wr,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
                                  model.isAlphaPremultiplied());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   287
    public void assertOperationSupported(final int numBuffers,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   288
                                         final BufferCapabilities caps)
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   289
            throws AWTException {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   290
        // Assume this method is never called with numBuffers != 2, as 0 is
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   291
        // unsupported, and 1 corresponds to a SingleBufferStrategy which
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   292
        // doesn't depend on the peer. Screen is considered as a separate
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   293
        // "buffer".
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   294
        if (numBuffers != 2) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   295
            throw new AWTException("Only double buffering is supported");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        }
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   297
        final BufferCapabilities configCaps = getBufferCapabilities();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        if (!configCaps.isPageFlipping()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
            throw new AWTException("Page flipping is not supported");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
        if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
            throw new AWTException("FlipContents.PRIOR is not supported");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   307
    public Image createBackBuffer(final LWComponentPeer<?, ?> peer) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   308
        final Rectangle r = peer.getBounds();
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   309
        // It is possible for the component to have size 0x0, adjust it to
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   310
        // be at least 1x1 to avoid IAE
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   311
        final int w = Math.max(1, r.width);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   312
        final int h = Math.max(1, r.height);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   313
        final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   314
                                                      : Transparency.OPAQUE;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   315
        return new SunVolatileImage(this, w, h, transparency, null);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   319
    public void destroyBackBuffer(final Image backBuffer) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   320
        if (backBuffer != null) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   321
            backBuffer.flush();
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   322
        }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   323
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   325
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   326
    public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   327
                     final int x1, final int y1, final int x2, final int y2,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   328
                     final BufferCapabilities.FlipContents flipAction) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   329
        final Graphics g = peer.getGraphics();
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   330
        try {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   331
            g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   332
        } finally {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   333
            g.dispose();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
        if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   336
            final Graphics2D bg = (Graphics2D) backBuffer.getGraphics();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
            try {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   338
                bg.setBackground(peer.getBackground());
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   339
                bg.clearRect(0, 0, backBuffer.getWidth(null),
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   340
                             backBuffer.getHeight(null));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
            } finally {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   342
                bg.dispose();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
    private static class CGLBufferCaps extends BufferCapabilities {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
        public CGLBufferCaps(boolean dblBuf) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
            super(imageCaps, imageCaps,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
                  dblBuf ? FlipContents.UNDEFINED : null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
    public BufferCapabilities getBufferCapabilities() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
        if (bufferCaps == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
            bufferCaps = new CGLBufferCaps(isDoubleBuffered());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
        return bufferCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
    private static class CGLImageCaps extends ImageCapabilities {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
        private CGLImageCaps() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
            super(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
        public boolean isTrueVolatile() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
            return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
    public ImageCapabilities getImageCapabilities() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
        return imageCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   376
    @Override
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   377
    public VolatileImage createCompatibleVolatileImage(int width, int height,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   378
                                                       int transparency,
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   379
                                                       int type) {
31661
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents: 25859
diff changeset
   380
        if ((type != FBOBJECT && type != TEXTURE)
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents: 25859
diff changeset
   381
                || transparency == Transparency.BITMASK
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents: 25859
diff changeset
   382
                || type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
        SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
                                                          transparency, type);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
        Surface sd = vi.getDestSurface();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
        if (!(sd instanceof AccelSurface) ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
            ((AccelSurface)sd).getType() != type)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
            vi.flush();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
            vi = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
        return vi;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
     * {@inheritDoc}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
     * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
     */
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   403
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
    public ContextCapabilities getContextCapabilities() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
        return oglCaps;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 13550
diff changeset
   408
    @Override
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   409
    public int getMaxTextureWidth() {
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   410
        return Math.max(maxTextureSize / getDevice().getScaleFactor(),
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   411
                        getBounds().width);
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   412
    }
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   413
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   414
    @Override
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   415
    public int getMaxTextureHeight() {
23325
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   416
        return Math.max(maxTextureSize / getDevice().getScaleFactor(),
4c3942938b0d 8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents: 16840
diff changeset
   417
                        getBounds().height);
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 12047
diff changeset
   418
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
}