/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdlib.h>
#include <string.h>
#include "sun_java2d_opengl_WGLGraphicsConfig.h"
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "WGLGraphicsConfig.h"
#include "WGLSurfaceData.h"
/**
* This is a globally shared context used when creating textures. When any
* new contexts are created, they specify this context as the "share list"
* context, which means any texture objects created when this shared context
* is current will be available to any other context in any other thread.
*/
/**
* Attempts to initialize WGL and the core OpenGL library. For this method
* to return JNI_TRUE, the following must be true:
* - opengl32.dll must be loaded successfully (via LoadLibrary)
* available and loaded properly
* If any of these requirements are not met, this method will return
* GraphicsConfig in the environment.
*/
{
if (!OGLFuncs_OpenLibrary()) {
return JNI_FALSE;
}
if (!OGLFuncs_InitPlatformFuncs() ||
{
return JNI_FALSE;
}
return JNI_TRUE;
}
/**
* Disposes all memory and resources allocated for the given OGLContext.
*/
static void
{
"WGLGC_DestroyOGLContext: context is null");
return;
}
// at this point, this context will be current to its scratch surface,
// so the following operations should be safe...
// release the current context before we continue
}
if (ctxinfo->scratchSurface != 0) {
if (ctxinfo->scratchSurfaceDC != 0) {
}
}
}
}
/**
* Disposes all memory and resources associated with the given
* WGLGraphicsConfigInfo (including its native OGLContext data).
*/
void
{
"OGLGC_DestroyOGLGraphicsConfig: info is null");
return;
}
}
}
/**
* Creates a temporary (non-visible) window that can be used for querying
* the OpenGL capabilities of a given device.
*
* REMIND: should be able to create a window on a specific device...
*/
{
if (firsttime) {
// setup window class information
if (RegisterClass(&wc) == 0) {
"WGLGC_CreateScratchWindow: error registering window class");
return 0;
}
}
// create scratch window
}
/**
* Returns a pixel format identifier that is suitable for Java 2D's needs
* (must have a depth buffer, support for pbuffers, etc). This method will
* iterate through all pixel formats (if any) that match the requested
* attributes and will attempt to find a pixel format with a minimal combined
* depth+stencil buffer. Note that we currently only need depth capabilities
* (for shape clipping purposes), but wglChoosePixelFormatARB() will often
* return a list of pixel formats with the largest depth buffer (and stencil)
* sizes at the top of the list. Therefore, we scan through the whole list
* to find the most VRAM-efficient pixel format. If no appropriate pixel
* format can be found, this method returns 0.
*/
static int
{
int attrs[] = {
0
};
int chosenPixFmt = 0;
int nfmts, i;
// this is the initial minimum value for the combined depth+stencil size
// (we initialize it to some absurdly high value; realistic values will
// be much less than this number)
// find all pixel formats (maximum of 32) with the provided attributes
"WGLGC_GetPixelFormatForDC: error choosing pixel format");
return 0;
}
if (nfmts <= 0) {
"WGLGC_GetPixelFormatForDC: no pixel formats found");
return 0;
}
// iterate through the list of pixel formats, looking for the one that
// meets our requirements while keeping the combined depth+stencil sizes
// to a minimum
for (i = 0; i < nfmts; i++) {
int attrKeys[] = {
};
"[V] pixfmt=%d db=%d alpha=%d depth=%d stencil=%d valid=",
} else {
}
}
if (chosenPixFmt == 0) {
"WGLGC_GetPixelFormatForDC: could not find appropriate pixfmt");
return 0;
}
"WGLGC_GetPixelFormatForDC: chose %d as the best pixel format",
return chosenPixFmt;
}
/**
* Sets a "basic" pixel format for the given HDC. This method is used only
* for initializing a scratch window far enough such that we can load
* differs from the one above in that it does not use wglChoosePixelFormatARB,
* which is a WGL extension function, since we can't use that method without
* first loading the extension functions under a "basic" pixel format.)
*/
static jboolean
{
int pixfmt;
// find pixel format
"WGLGC_SetBasicPixelFormatForDC: error setting pixel format");
return JNI_FALSE;
}
return JNI_TRUE;
}
/**
* Creates a context that is compatible with the given pixel format
* identifier. Returns 0 if the context could not be created properly.
*/
static HGLRC
{
if (hwnd == 0) {
"WGLGC_CreateContext: could not create scratch window");
return 0;
}
// get the HDC for the scratch window
if (hdc == 0) {
"WGLGC_CreateContext: could not get dc for scratch window");
return 0;
}
// set the pixel format for the scratch window
"WGLGC_CreateContext: error setting pixel format");
return 0;
}
// create a context based on the scratch window
// release the temporary resources
return hglrc;
}
/**
* Initializes the extension function pointers for the given device. Note
* that under WGL, extension functions have different entrypoints depending
* on the device, so we must first make a context current for the given
* device before attempting to load the function pointers via
* wglGetProcAddress.
*
* REMIND: ideally the extension function pointers would not be global, but
* rather would be stored in a structure associated with the
* WGLGraphicsConfig, so that we use the correct function entrypoint
* depending on the destination device...
*/
static jboolean
{
// create a scratch window
if (hwnd == 0) {
return JNI_FALSE;
}
// get the HDC for the scratch window
if (hdc == 0) {
return JNI_FALSE;
}
// find and set a basic pixel format for the scratch window
if (!WGLGC_SetBasicPixelFormatForDC(hdc)) {
"WGLGC_InitExtFuncs: could not find appropriate pixfmt");
return JNI_FALSE;
}
// create a temporary context
if (context == 0) {
"WGLGC_InitExtFuncs: could not create temp WGL context");
return JNI_FALSE;
}
// make the context current so that we can load the function pointers
// using wglGetProcAddress
"WGLGC_InitExtFuncs: could not make temp context current");
return JNI_FALSE;
}
if (!OGLFuncs_InitExtFuncs()) {
"WGLGC_InitExtFuncs: could not initialize extension funcs");
return JNI_FALSE;
}
// destroy the temporary resources
return JNI_TRUE;
}
/**
* Initializes a new OGLContext, which includes the native WGL context handle
* and some other important information such as the associated pixel format.
*/
static OGLContext *
{
"WGLGC_InitOGLContext: could not allocate memory for oglc");
return NULL;
}
"WGLGC_InitOGLContext: could not allocate memory for ctxinfo");
return NULL;
}
return oglc;
}
/**
* Determines whether the WGL pipeline can be used for a given GraphicsConfig
* provided its screen number and visual ID. If the minimum requirements are
* met, the native WGLGraphicsConfigInfo structure is initialized for this
* GraphicsConfig with the necessary information (pixel format, etc.)
* and a pointer to this structure is returned as a jlong. If
* initialization fails at any point, zero is returned, indicating that WGL
* cannot be used for this GraphicsConfig (we should fallback on the existing
* DX pipeline).
*/
{
const unsigned char *versionstr;
const char *extstr;
if (!WGLGC_InitExtFuncs(screennum)) {
"WGLGraphicsConfig_getWGLConfigInfo: could not init ext funcs");
return 0L;
}
// create a scratch window
if (hwnd == 0) {
return 0L;
}
// get the HDC for the scratch window
if (hdc == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not get dc for scratch window");
return 0L;
}
if (pixfmt == 0) {
// find an appropriate pixel format
if (pixfmt == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not find appropriate pixfmt");
return 0L;
}
}
if (sharedContext == 0) {
// create the one shared context
if (sharedContext == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not create shared context");
return 0L;
}
}
// set the pixel format for the scratch window
"WGLGraphicsconfig_getWGLConfigInfo: error setting pixel format");
return 0L;
}
// create the HGLRC (context) for this WGLGraphicsConfig
if (context == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not create WGL context");
return 0L;
}
// REMIND: when using wglShareLists, the two contexts must use an
// identical pixel format...
"WGLGraphicsConfig_getWGLConfigInfo: unable to share lists");
}
// make the context current so that we can query the OpenGL version
// and extension strings
"WGLGraphicsConfig_getWGLConfigInfo: could not make temp context current");
return 0L;
}
// get version and extension strings
"WGLGraphicsConfig_getWGLConfigInfo: OpenGL version=%s",
if (!OGLContext_IsVersionSupported(versionstr)) {
"WGLGraphicsConfig_getWGLConfigInfo: OpenGL 1.2 is required");
return 0L;
}
// check for required WGL extensions
{
"WGLGraphicsConfig_getWGLConfigInfo: required ext(s) unavailable");
return 0L;
}
// get config-specific capabilities
if (attrVals[0]) {
}
if (attrVals[1] > 0) {
}
// create the scratch pbuffer
// destroy the temporary resources
if (scratch == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not create scratch surface");
return 0L;
}
// get the HDC for the scratch pbuffer
if (scratchDC == 0) {
"WGLGraphicsConfig_getWGLConfigInfo: could not get hdc for scratch surface");
return 0L;
}
// initialize the OGLContext, which wraps the pixfmt and HGLRC (context)
"WGLGraphicsConfig_getWGLConfigInfo: could not create oglc");
return 0L;
}
"WGLGraphicsConfig_getWGLConfigInfo: finished checking dependencies");
// create the WGLGraphicsConfigInfo record for this config
"WGLGraphicsConfig_getWGLConfigInfo: could not allocate memory for wglinfo");
return 0L;
}
return ptr_to_jlong(wglinfo);
}
{
// REMIND: eventually we should implement this method so that it finds
// the most appropriate default pixel format for the given
// device; for now, we'll just return 0, and then we'll find
// an appropriate pixel format in WGLGC_GetWGLConfigInfo()...
return 0;
}
{
return CAPS_EMPTY;
}
}