jdk/src/windows/native/sun/java2d/opengl/WGLGraphicsConfig.c
author tdv
Tue, 22 Jul 2008 11:24:32 -0700
changeset 888 c7009cf0001f
parent 887 0aab8d3fa11a
child 5506 202f599c92aa
permissions -rw-r--r--
6728492: typo in copyrights in some files touched by the d3d pipeline port Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
888
c7009cf0001f 6728492: typo in copyrights in some files touched by the d3d pipeline port
tdv
parents: 887
diff changeset
     2
 * Copyright 2004-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_java2d_opengl_WGLGraphicsConfig.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "WGLGraphicsConfig.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "WGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This is a globally shared context used when creating textures.  When any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * new contexts are created, they specify this context as the "share list"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * context, which means any texture objects created when this shared context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is current will be available to any other context in any other thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
HGLRC sharedContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Attempts to initialize WGL and the core OpenGL library.  For this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to return JNI_TRUE, the following must be true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     - opengl32.dll must be loaded successfully (via LoadLibrary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     - all core WGL/OGL function symbols from opengl32.dll must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       available and loaded properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * If any of these requirements are not met, this method will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * JNI_FALSE, indicating there is no hope of using WGL/OpenGL for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * GraphicsConfig in the environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
Java_sun_java2d_opengl_WGLGraphicsConfig_initWGL(JNIEnv *env, jclass wglgc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    J2dRlsTraceLn(J2D_TRACE_INFO, "WGLGraphicsConfig_initWGL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (!OGLFuncs_OpenLibrary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (!OGLFuncs_InitPlatformFuncs() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        !OGLFuncs_InitBaseFuncs())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        OGLFuncs_CloseLibrary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Disposes all memory and resources allocated for the given OGLContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
WGLGC_DestroyOGLContext(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    WGLCtxInfo *ctxinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_DestroyOGLContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                      "WGLGC_DestroyOGLContext: context is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // at this point, this context will be current to its scratch surface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // so the following operations should be safe...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    OGLContext_DestroyContextResources(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    ctxinfo = (WGLCtxInfo *)oglc->ctxInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (ctxinfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // release the current context before we continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (ctxinfo->context != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            j2d_wglDeleteContext(ctxinfo->context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (ctxinfo->scratchSurface != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (ctxinfo->scratchSurfaceDC != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                j2d_wglReleasePbufferDCARB(ctxinfo->scratchSurface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                           ctxinfo->scratchSurfaceDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            j2d_wglDestroyPbufferARB(ctxinfo->scratchSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        free(ctxinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    free(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * Disposes all memory and resources associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * WGLGraphicsConfigInfo (including its native OGLContext data).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    WGLGraphicsConfigInfo *wglinfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    J2dTraceLn(J2D_TRACE_INFO, "OGLGC_DestroyOGLGraphicsConfig");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    if (wglinfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                      "OGLGC_DestroyOGLGraphicsConfig: info is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (wglinfo->context != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        WGLGC_DestroyOGLContext(wglinfo->context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    free(wglinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Creates a temporary (non-visible) window that can be used for querying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * the OpenGL capabilities of a given device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * REMIND: should be able to create a window on a specific device...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
HWND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
WGLGC_CreateScratchWindow(jint screennum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static jboolean firsttime = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_CreateScratchWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    if (firsttime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        WNDCLASS wc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // setup window class information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        ZeroMemory(&wc, sizeof(WNDCLASS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        wc.hInstance = GetModuleHandle(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        wc.lpfnWndProc = DefWindowProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        wc.lpszClassName = L"Tmp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (RegisterClass(&wc) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                "WGLGC_CreateScratchWindow: error registering window class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        firsttime = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    // create scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    return CreateWindow(L"Tmp", L"Tmp", 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        CW_USEDEFAULT, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        GetModuleHandle(NULL), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * Returns a pixel format identifier that is suitable for Java 2D's needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * (must have a depth buffer, support for pbuffers, etc).  This method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * iterate through all pixel formats (if any) that match the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * attributes and will attempt to find a pixel format with a minimal combined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * depth+stencil buffer.  Note that we currently only need depth capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * (for shape clipping purposes), but wglChoosePixelFormatARB() will often
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * return a list of pixel formats with the largest depth buffer (and stencil)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * sizes at the top of the list.  Therefore, we scan through the whole list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * to find the most VRAM-efficient pixel format.  If no appropriate pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * format can be found, this method returns 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
WGLGC_GetPixelFormatForDC(HDC hdc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    int attrs[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        WGL_DEPTH_BITS_ARB, 16, // anything >= 16 will work for us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    int pixfmts[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    int chosenPixFmt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    int nfmts, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    // this is the initial minimum value for the combined depth+stencil size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    // (we initialize it to some absurdly high value; realistic values will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // be much less than this number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    int minDepthPlusStencil = 512;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    J2dRlsTraceLn(J2D_TRACE_INFO, "WGLGC_GetPixelFormatForDC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // find all pixel formats (maximum of 32) with the provided attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if (!j2d_wglChoosePixelFormatARB(hdc, attrs, NULL, 32, pixfmts, &nfmts)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            "WGLGC_GetPixelFormatForDC: error choosing pixel format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    if (nfmts <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            "WGLGC_GetPixelFormatForDC: no pixel formats found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    J2dRlsTraceLn(J2D_TRACE_VERBOSE, "  candidate pixel formats:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    // iterate through the list of pixel formats, looking for the one that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // meets our requirements while keeping the combined depth+stencil sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    // to a minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    for (i = 0; i < nfmts; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        int attrKeys[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            WGL_DEPTH_BITS_ARB, WGL_STENCIL_BITS_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            WGL_DOUBLE_BUFFER_ARB, WGL_ALPHA_BITS_ARB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        int attrVals[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        int pixfmt = pixfmts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int depth, stencil, db, alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        j2d_wglGetPixelFormatAttribivARB(hdc, pixfmt, 0, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                         attrKeys, attrVals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        depth   = attrVals[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        stencil = attrVals[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        db      = attrVals[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        alpha   = attrVals[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        J2dRlsTrace5(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            "[V]     pixfmt=%d db=%d alpha=%d depth=%d stencil=%d valid=",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                     pixfmt, db, alpha, depth, stencil);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if ((depth + stencil) < minDepthPlusStencil) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            J2dRlsTrace(J2D_TRACE_VERBOSE, "true\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            minDepthPlusStencil = depth + stencil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            chosenPixFmt = pixfmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            J2dRlsTrace(J2D_TRACE_VERBOSE, "false (large depth)\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (chosenPixFmt == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            "WGLGC_GetPixelFormatForDC: could not find appropriate pixfmt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    J2dRlsTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        "WGLGC_GetPixelFormatForDC: chose %d as the best pixel format",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                   chosenPixFmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return chosenPixFmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * Sets a "basic" pixel format for the given HDC.  This method is used only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * for initializing a scratch window far enough such that we can load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * GL/WGL extension function pointers using wglGetProcAddress.  (This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * differs from the one above in that it does not use wglChoosePixelFormatARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * which is a WGL extension function, since we can't use that method without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * first loading the extension functions under a "basic" pixel format.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
WGLGC_SetBasicPixelFormatForDC(HDC hdc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    PIXELFORMATDESCRIPTOR pfd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    int pixfmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_SetBasicPixelFormatForDC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    // find pixel format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    pfd.nVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    pfd.iPixelType = PFD_TYPE_RGBA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    pixfmt = ChoosePixelFormat(hdc, &pfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    if (!SetPixelFormat(hdc, pixfmt, &pfd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            "WGLGC_SetBasicPixelFormatForDC: error setting pixel format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 * Creates a context that is compatible with the given pixel format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * identifier.  Returns 0 if the context could not be created properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
static HGLRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
WGLGC_CreateContext(jint screennum, jint pixfmt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    PIXELFORMATDESCRIPTOR pfd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    HWND hwnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    HGLRC hglrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_CreateContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    hwnd = WGLGC_CreateScratchWindow(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    if (hwnd == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            "WGLGC_CreateContext: could not create scratch window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // get the HDC for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    hdc = GetDC(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            "WGLGC_CreateContext: could not get dc for scratch window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    // set the pixel format for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    if (!SetPixelFormat(hdc, pixfmt, &pfd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            "WGLGC_CreateContext: error setting pixel format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // create a context based on the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    hglrc = j2d_wglCreateContext(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    // release the temporary resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    return hglrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * Initializes the extension function pointers for the given device.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * that under WGL, extension functions have different entrypoints depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * on the device, so we must first make a context current for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 * device before attempting to load the function pointers via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * wglGetProcAddress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * REMIND: ideally the extension function pointers would not be global, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 *         rather would be stored in a structure associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 *         WGLGraphicsConfig, so that we use the correct function entrypoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 *         depending on the destination device...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
WGLGC_InitExtFuncs(jint screennum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    HWND hwnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    HGLRC context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_InitExtFuncs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    // create a scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    hwnd = WGLGC_CreateScratchWindow(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    if (hwnd == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // get the HDC for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    hdc = GetDC(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    // find and set a basic pixel format for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if (!WGLGC_SetBasicPixelFormatForDC(hdc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            "WGLGC_InitExtFuncs: could not find appropriate pixfmt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    // create a temporary context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    context = j2d_wglCreateContext(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    if (context == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            "WGLGC_InitExtFuncs: could not create temp WGL context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    // make the context current so that we can load the function pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // using wglGetProcAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    if (!j2d_wglMakeCurrent(hdc, context)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            "WGLGC_InitExtFuncs: could not make temp context current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    if (!OGLFuncs_InitExtFuncs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            "WGLGC_InitExtFuncs: could not initialize extension funcs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    // destroy the temporary resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
 * Initializes a new OGLContext, which includes the native WGL context handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 * and some other important information such as the associated pixel format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
static OGLContext *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
WGLGC_InitOGLContext(jint pixfmt, HGLRC context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                     HPBUFFERARB scratch, HDC scratchDC, jint caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    OGLContext *oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    WGLCtxInfo *ctxinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    J2dTraceLn(J2D_TRACE_INFO, "WGLGC_InitOGLContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    oglc = (OGLContext *)malloc(sizeof(OGLContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            "WGLGC_InitOGLContext: could not allocate memory for oglc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    memset(oglc, 0, sizeof(OGLContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    ctxinfo = (WGLCtxInfo *)malloc(sizeof(WGLCtxInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (ctxinfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            "WGLGC_InitOGLContext: could not allocate memory for ctxinfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        free(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    ctxinfo->context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    ctxinfo->scratchSurface = scratch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    ctxinfo->scratchSurfaceDC = scratchDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    oglc->ctxInfo = ctxinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    oglc->caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    return oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
 * Determines whether the WGL pipeline can be used for a given GraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 * provided its screen number and visual ID.  If the minimum requirements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
 * met, the native WGLGraphicsConfigInfo structure is initialized for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
 * GraphicsConfig with the necessary information (pixel format, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
 * and a pointer to this structure is returned as a jlong.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
 * initialization fails at any point, zero is returned, indicating that WGL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
 * cannot be used for this GraphicsConfig (we should fallback on the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
 * DX pipeline).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
Java_sun_java2d_opengl_WGLGraphicsConfig_getWGLConfigInfo(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                          jclass wglgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                          jint screennum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                                          jint pixfmt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    OGLContext *oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    PIXELFORMATDESCRIPTOR pfd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    HWND hwnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    HGLRC context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    HPBUFFERARB scratch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    HDC scratchDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    WGLGraphicsConfigInfo *wglinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    const unsigned char *versionstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    const char *extstr;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   504
    jint caps = CAPS_EMPTY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    int attrKeys[] = { WGL_DOUBLE_BUFFER_ARB, WGL_ALPHA_BITS_ARB };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    int attrVals[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    J2dRlsTraceLn(J2D_TRACE_INFO, "WGLGraphicsConfig_getWGLConfigInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    // initialize GL/WGL extension functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    if (!WGLGC_InitExtFuncs(screennum)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            "WGLGraphicsConfig_getWGLConfigInfo: could not init ext funcs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    // create a scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    hwnd = WGLGC_CreateScratchWindow(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    if (hwnd == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    // get the HDC for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    hdc = GetDC(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            "WGLGraphicsConfig_getWGLConfigInfo: could not get dc for scratch window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    if (pixfmt == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        // find an appropriate pixel format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        pixfmt = WGLGC_GetPixelFormatForDC(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        if (pixfmt == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                "WGLGraphicsConfig_getWGLConfigInfo: could not find appropriate pixfmt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    if (sharedContext == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        // create the one shared context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        sharedContext = WGLGC_CreateContext(screennum, pixfmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (sharedContext == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                "WGLGraphicsConfig_getWGLConfigInfo: could not create shared context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    // set the pixel format for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    if (!SetPixelFormat(hdc, pixfmt, &pfd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            "WGLGraphicsconfig_getWGLConfigInfo: error setting pixel format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    // create the HGLRC (context) for this WGLGraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    context = j2d_wglCreateContext(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    if (context == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            "WGLGraphicsConfig_getWGLConfigInfo: could not create WGL context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    // REMIND: when using wglShareLists, the two contexts must use an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    //         identical pixel format...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    if (!j2d_wglShareLists(sharedContext, context)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        J2dRlsTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            "WGLGraphicsConfig_getWGLConfigInfo: unable to share lists");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    // make the context current so that we can query the OpenGL version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    // and extension strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    if (!j2d_wglMakeCurrent(hdc, context)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            "WGLGraphicsConfig_getWGLConfigInfo: could not make temp context current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    // get version and extension strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    versionstr = j2d_glGetString(GL_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    extstr = j2d_wglGetExtensionsStringARB(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    OGLContext_GetExtensionInfo(env, &caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    J2dRlsTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        "WGLGraphicsConfig_getWGLConfigInfo: OpenGL version=%s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                   (versionstr == NULL) ? "null" : (char *)versionstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    if (!OGLContext_IsVersionSupported(versionstr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            "WGLGraphicsConfig_getWGLConfigInfo: OpenGL 1.2 is required");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    // check for required WGL extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    if (!OGLContext_IsExtensionAvailable(extstr, "WGL_ARB_pbuffer") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        !OGLContext_IsExtensionAvailable(extstr, "WGL_ARB_make_current_read")||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        !OGLContext_IsExtensionAvailable(extstr, "WGL_ARB_pixel_format"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            "WGLGraphicsConfig_getWGLConfigInfo: required ext(s) unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    // get config-specific capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    j2d_wglGetPixelFormatAttribivARB(hdc, pixfmt, 0, 2, attrKeys, attrVals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    if (attrVals[0]) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   629
        caps |= CAPS_DOUBLEBUFFERED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    if (attrVals[1] > 0) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   632
        caps |= CAPS_STORED_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    // create the scratch pbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    scratch = j2d_wglCreatePbufferARB(hdc, pixfmt, 1, 1, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    // destroy the temporary resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    j2d_wglMakeCurrent(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    if (scratch == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            "WGLGraphicsConfig_getWGLConfigInfo: could not create scratch surface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    // get the HDC for the scratch pbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    scratchDC = j2d_wglGetPbufferDCARB(scratch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    if (scratchDC == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            "WGLGraphicsConfig_getWGLConfigInfo: could not get hdc for scratch surface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        j2d_wglDestroyPbufferARB(scratch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    // initialize the OGLContext, which wraps the pixfmt and HGLRC (context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    oglc = WGLGC_InitOGLContext(pixfmt, context, scratch, scratchDC, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            "WGLGraphicsConfig_getWGLConfigInfo: could not create oglc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        j2d_wglDeleteContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        j2d_wglReleasePbufferDCARB(scratch, scratchDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        j2d_wglDestroyPbufferARB(scratch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    J2dTraceLn(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        "WGLGraphicsConfig_getWGLConfigInfo: finished checking dependencies");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    // create the WGLGraphicsConfigInfo record for this config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    wglinfo = (WGLGraphicsConfigInfo *)malloc(sizeof(WGLGraphicsConfigInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    if (wglinfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            "WGLGraphicsConfig_getWGLConfigInfo: could not allocate memory for wglinfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        WGLGC_DestroyOGLContext(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    wglinfo->screen = screennum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    wglinfo->pixfmt = pixfmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    wglinfo->context = oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    return ptr_to_jlong(wglinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
Java_sun_java2d_opengl_WGLGraphicsConfig_getDefaultPixFmt(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                                          jclass wglgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                                          jint screennum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    J2dTraceLn(J2D_TRACE_INFO, "WGLGraphicsConfig_getDefaultPixFmt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // REMIND: eventually we should implement this method so that it finds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    //         the most appropriate default pixel format for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    //         device; for now, we'll just return 0, and then we'll find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    //         an appropriate pixel format in WGLGC_GetWGLConfigInfo()...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
Java_sun_java2d_opengl_WGLGraphicsConfig_getOGLCapabilities(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                                                            jclass wglgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                                                            jlong configInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    WGLGraphicsConfigInfo *wglinfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        (WGLGraphicsConfigInfo *)jlong_to_ptr(configInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    J2dTraceLn(J2D_TRACE_INFO, "WGLGraphicsConfig_getOGLCapabilities");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    if (wglinfo == NULL || wglinfo->context == NULL) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   715
        return CAPS_EMPTY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    return wglinfo->context->caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
}