jdk/src/windows/native/sun/java2d/opengl/WGLSurfaceData.c
author igor
Mon, 12 Jul 2010 13:16:28 -0700
changeset 5938 c93e51904f68
parent 5506 202f599c92aa
child 7668 d4a77089c587
permissions -rw-r--r--
6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these) Reviewed-by: prr Contributed-by: ohair <kelly.ohair@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
     2
 * Copyright (c) 2004, 2009, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2451
diff changeset
    23
 * questions.
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "sun_java2d_opengl_WGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "OGLRenderQueue.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
 * The methods in this file implement the native windowing system specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * layer (WGL) for the OpenGL-based Java 2D pipeline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern LockFunc                     OGLSD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
extern GetRasInfoFunc               OGLSD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
extern UnlockFunc                   OGLSD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern DisposeFunc                  OGLSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    47
extern OGLPixelFormat PixelFormats[];
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    48
extern void AwtWindow_UpdateWindow(JNIEnv *env, jobject peer,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    49
                                   jint w, jint h, HBITMAP hBitmap);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    50
extern HBITMAP BitmapUtil_CreateBitmapFromARGBPre(int width, int height,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    51
                                                  int srcStride,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    52
                                                  int* imageData);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    53
extern void AwtComponent_GetInsets(JNIEnv *env, jobject peer, RECT *insets);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    54
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    55
extern void
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    56
    OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    57
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
Java_sun_java2d_opengl_WGLSurfaceData_initOps(JNIEnv *env, jobject wglsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                              jlong pConfigInfo,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    61
                                              jobject peer, jlong hwnd)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, wglsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                                       sizeof(OGLSDOps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    WGLSDOps *wglsdo = (WGLSDOps *)malloc(sizeof(WGLSDOps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_initOps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
5938
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5506
diff changeset
    69
    if (oglsdo == NULL) {
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5506
diff changeset
    70
        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5506
diff changeset
    71
        return;
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5506
diff changeset
    72
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    if (wglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        JNU_ThrowOutOfMemoryError(env, "creating native wgl ops");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    oglsdo->privOps = wglsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    oglsdo->sdOps.Lock               = OGLSD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    oglsdo->sdOps.GetRasInfo         = OGLSD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    oglsdo->sdOps.Unlock             = OGLSD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    oglsdo->sdOps.Dispose            = OGLSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    oglsdo->drawableType = OGLSD_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    oglsdo->activeBuffer = GL_FRONT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    oglsdo->needsInit = JNI_TRUE;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    88
    if (peer != NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    89
        RECT insets;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    90
        AwtComponent_GetInsets(env, peer, &insets);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    91
        oglsdo->xOffset = -insets.left;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    92
        oglsdo->yOffset = -insets.bottom;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    93
    } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    94
        oglsdo->xOffset = 0;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    95
        oglsdo->yOffset = 0;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    96
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    98
    wglsdo->window = (HWND)jlong_to_ptr(hwnd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    wglsdo->configInfo = (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    if (wglsdo->configInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        free(wglsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        JNU_ThrowNullPointerException(env, "Config info is null in initOps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * This function disposes of any native windowing system resources associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * with this surface.  For instance, if the given OGLSDOps is of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * OGLSD_PBUFFER, this method implementation will destroy the actual pbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    WGLSDOps *wglsdo = (WGLSDOps *)oglsdo->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (oglsdo->drawableType == OGLSD_PBUFFER) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   120
        if (wglsdo->pbuffer != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (wglsdo->pbufferDC != 0) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   122
                j2d_wglReleasePbufferDCARB(wglsdo->pbuffer,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                           wglsdo->pbufferDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                wglsdo->pbufferDC = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   126
            j2d_wglDestroyPbufferARB(wglsdo->pbuffer);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   127
            wglsdo->pbuffer = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * Makes the given context current to its associated "scratch" surface.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * the operation is successful, this method will return JNI_TRUE; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * returns JNI_FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
WGLSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    WGLCtxInfo *ctxInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    J2dTraceLn(J2D_TRACE_INFO, "WGLSD_MakeCurrentToScratch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                      "WGLSD_MakeCurrentToScratch: context is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    ctxInfo = (WGLCtxInfo *)oglc->ctxInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    if (!j2d_wglMakeCurrent(ctxInfo->scratchSurfaceDC, ctxInfo->context)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                      "WGLSD_MakeCurrentToScratch: could not make current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * Returns a pointer (as a jlong) to the native WGLGraphicsConfigInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * associated with the given OGLSDOps.  This method can be called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * shared code to retrieve the native GraphicsConfig data in a platform-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * independent manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    WGLSDOps *wglsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    if (oglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                      "OGLSD_GetNativeConfigInfo: ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    wglsdo = (WGLSDOps *)oglsdo->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (wglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                      "OGLSD_GetNativeConfigInfo: wgl ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    return ptr_to_jlong(wglsdo->configInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * Makes the given GraphicsConfig's context current to its associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * "scratch" surface.  If there is a problem making the context current,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * this method will return NULL; otherwise, returns a pointer to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * OGLContext that is associated with the given GraphicsConfig.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
OGLContext *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    WGLGraphicsConfigInfo *wglInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    OGLContext *oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    if (wglInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                      "OGLSD_SetScratchContext: wgl config info is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    oglc = wglInfo->context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if (!WGLSD_MakeCurrentToScratch(env, oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // the GL_EXT_framebuffer_object extension is present, so this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // will ensure that we are bound to the scratch pbuffer (and not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // some other framebuffer object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 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
    return oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * Makes a context current to the given source and destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * surfaces.  If there is a problem making the context current, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * will return NULL; otherwise, returns a pointer to the OGLContext that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * associated with the destination surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
OGLContext *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    WGLSDOps *srcWGLOps = (WGLSDOps *)srcOps->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    WGLSDOps *dstWGLOps = (WGLSDOps *)dstOps->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    OGLContext *oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    WGLCtxInfo *ctxinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    HDC srcHDC, dstHDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    BOOL success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    J2dTraceLn4(J2D_TRACE_VERBOSE, "  src: %d %p dst: %d %p",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                srcOps->drawableType, srcOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                dstOps->drawableType, dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    oglc = dstWGLOps->configInfo->context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (oglc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                      "OGLSD_MakeOGLContextCurrent: context is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (dstOps->drawableType == OGLSD_FBOBJECT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        // first make sure we have a current context (if the context isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // already current to some drawable, we will make it current to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // its scratch surface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (oglc != currentContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (!WGLSD_MakeCurrentToScratch(env, oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // now bind to the fbobject associated with the destination surface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // this means that all rendering will go into the fbobject destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // (note that we unbind the currently bound texture first; this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // recommended procedure when binding an fbobject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        j2d_glBindTexture(dstOps->textureTarget, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    ctxinfo = (WGLCtxInfo *)oglc->ctxInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    // get the hdc for the destination surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    if (dstOps->drawableType == OGLSD_PBUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        dstHDC = dstWGLOps->pbufferDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    } else {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   280
        dstHDC = GetDC(dstWGLOps->window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    // get the hdc for the source surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    if (srcOps->drawableType == OGLSD_PBUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        srcHDC = srcWGLOps->pbufferDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // the source will always be equal to the destination in this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        srcHDC = dstHDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // REMIND: in theory we should be able to use wglMakeContextCurrentARB()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    // even when the src/dst surfaces are the same, but this causes problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    // on ATI's drivers (see 6525997); for now we will only use it when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    // surfaces are different, otherwise we will use the old
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    // wglMakeCurrent() approach...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    if (srcHDC != dstHDC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // use WGL_ARB_make_current_read extension to make context current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        success =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            j2d_wglMakeContextCurrentARB(dstHDC, srcHDC, ctxinfo->context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // use the old approach for making current to the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        success = j2d_wglMakeCurrent(dstHDC, ctxinfo->context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                      "OGLSD_MakeOGLContextCurrent: could not make current");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (dstOps->drawableType != OGLSD_PBUFFER) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   308
            ReleaseDC(dstWGLOps->window, dstHDC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        // the GL_EXT_framebuffer_object extension is present, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // must bind to the default (windowing system provided)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // framebuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    if (dstOps->drawableType != OGLSD_PBUFFER) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   321
        ReleaseDC(dstWGLOps->window, dstHDC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    return oglc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * This function initializes a native window surface and caches the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * bounds in the given OGLSDOps.  Returns JNI_TRUE if the operation was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * successful; JNI_FALSE otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    PIXELFORMATDESCRIPTOR pfd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    WGLSDOps *wglsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    WGLGraphicsConfigInfo *wglInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    HWND window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    RECT wbounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_InitOGLWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    if (oglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                      "OGLSD_InitOGLWindow: ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    wglsdo = (WGLSDOps *)oglsdo->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    if (wglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                      "OGLSD_InitOGLWindow: wgl ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    wglInfo = wglsdo->configInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (wglInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                      "OGLSD_InitOGLWindow: graphics config info is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   364
    window = wglsdo->window;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    if (!IsWindow(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                      "OGLSD_InitOGLWindow: disposed component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    GetWindowRect(window, &wbounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    hdc = GetDC(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                      "OGLSD_InitOGLWindow: invalid hdc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    if (!SetPixelFormat(hdc, wglInfo->pixfmt, &pfd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                      "OGLSD_InitOGLWindow: error setting pixel format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        ReleaseDC(window, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    ReleaseDC(window, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    oglsdo->drawableType = OGLSD_WINDOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    oglsdo->isOpaque = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    oglsdo->width = wbounds.right - wbounds.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    oglsdo->height = wbounds.bottom - wbounds.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    wglsdo->pbufferDC = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                oglsdo->width, oglsdo->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
Java_sun_java2d_opengl_WGLSurfaceData_initPbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    (JNIEnv *env, jobject wglsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     jlong pData, jlong pConfigInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     jboolean isOpaque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    int attrKeys[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        WGL_MAX_PBUFFER_WIDTH_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        WGL_MAX_PBUFFER_HEIGHT_ARB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    int attrVals[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    int pbAttrList[] = { 0 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    WGLGraphicsConfigInfo *wglInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    WGLSDOps *wglsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    HWND hwnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    HDC hdc, pbufferDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    HPBUFFERARB pbuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    int maxWidth, maxHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    int actualWidth, actualHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    J2dTraceLn3(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                "WGLSurfaceData_initPbuffer: w=%d h=%d opq=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                width, height, isOpaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    if (oglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            "WGLSurfaceData_initPbuffer: ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    wglsdo = (WGLSDOps *)oglsdo->privOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    if (wglsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            "WGLSurfaceData_initPbuffer: wgl ops are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    if (wglInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            "WGLSurfaceData_initPbuffer: wgl config info is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // create a scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    hwnd = WGLGC_CreateScratchWindow(wglInfo->screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    if (hwnd == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            "WGLSurfaceData_initPbuffer: could not create scratch window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    // get the HDC for the scratch window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    hdc = GetDC(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            "WGLSurfaceData_initPbuffer: could not get dc for scratch window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    // get the maximum allowable pbuffer dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    j2d_wglGetPixelFormatAttribivARB(hdc, wglInfo->pixfmt, 0, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                     attrKeys, attrVals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    maxWidth  = attrVals[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    maxHeight = attrVals[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    J2dTraceLn4(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                "  desired pbuffer dimensions: w=%d h=%d maxw=%d maxh=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                width, height, maxWidth, maxHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    // if either dimension is 0 or larger than the maximum, we cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    // allocate a pbuffer with the requested dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    if (width  == 0 || width  > maxWidth ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        height == 0 || height > maxHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            "WGLSurfaceData_initPbuffer: invalid dimensions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    pbuffer = j2d_wglCreatePbufferARB(hdc, wglInfo->pixfmt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                      width, height, pbAttrList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    ReleaseDC(hwnd, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    DestroyWindow(hwnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    if (pbuffer == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            "WGLSurfaceData_initPbuffer: could not create wgl pbuffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    // note that we get the DC for the pbuffer at creation time, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    // release the DC when the pbuffer is disposed; the WGL_ARB_pbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    // spec is vague about such things, but from past experience we know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    // this approach to be more robust than, for example, doing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    // Get/ReleasePbufferDC() everytime we make a context current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    pbufferDC = j2d_wglGetPbufferDCARB(pbuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if (pbufferDC == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            "WGLSurfaceData_initPbuffer: could not get dc for pbuffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        j2d_wglDestroyPbufferARB(pbuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    // make sure the actual dimensions match those that we requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    j2d_wglQueryPbufferARB(pbuffer, WGL_PBUFFER_WIDTH_ARB, &actualWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    j2d_wglQueryPbufferARB(pbuffer, WGL_PBUFFER_HEIGHT_ARB, &actualHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    if (width != actualWidth || height != actualHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        J2dRlsTraceLn2(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            "WGLSurfaceData_initPbuffer: actual (w=%d h=%d) != requested",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                       actualWidth, actualHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        j2d_wglReleasePbufferDCARB(pbuffer, pbufferDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        j2d_wglDestroyPbufferARB(pbuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    oglsdo->drawableType = OGLSD_PBUFFER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    oglsdo->isOpaque = isOpaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    oglsdo->width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    oglsdo->height = height;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   528
    wglsdo->pbuffer = pbuffer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    wglsdo->pbufferDC = pbufferDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   531
    OGLSD_SetNativeDimensions(env, oglsdo, width, height);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   532
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
OGLSD_SwapBuffers(JNIEnv *env, jlong pPeerData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    HWND window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    window = AwtComponent_GetHWnd(env, pPeerData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    if (!IsWindow(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                      "OGLSD_SwapBuffers: disposed component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    hdc = GetDC(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    if (hdc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                      "OGLSD_SwapBuffers: invalid hdc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    if (!SwapBuffers(hdc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                      "OGLSD_SwapBuffers: error in SwapBuffers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    if (!ReleaseDC(window, hdc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                      "OGLSD_SwapBuffers: error while releasing dc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
}
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   568
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   569
/*
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   570
 * Class:     sun_java2d_opengl_WGLSurfaceData
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   571
 * Method:    updateWindowAccelImpl
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   572
 * Signature: (JJII)Z
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   573
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   574
JNIEXPORT jboolean JNICALL
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   575
    Java_sun_java2d_opengl_WGLSurfaceData_updateWindowAccelImpl
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   576
  (JNIEnv *env, jclass clazz, jlong pData, jobject peer, jint w, jint h)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   577
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   578
    OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   579
    OGLPixelFormat pf = PixelFormats[0/*PF_INT_ARGB_PRE*/];
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   580
    HBITMAP hBitmap = NULL;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   581
    void *pDst;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   582
    jint srcx, srcy, dstx, dsty, width, height;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   583
    jint pixelStride = 4;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   584
    jint scanStride = pixelStride * w;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   585
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   586
    J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_updateWindowAccelImpl");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   587
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   588
    if (w <= 0 || h <= 0) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   589
        return JNI_TRUE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   590
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   591
    if (oglsdo == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   592
        return JNI_FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   593
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   594
    RESET_PREVIOUS_OP();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   595
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   596
    width = w;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   597
    height = h;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   598
    srcx = srcy = dstx = dsty = 0;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   599
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   600
    pDst = malloc(height * scanStride);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   601
    if (pDst == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   602
        return JNI_FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   603
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   604
    ZeroMemory(pDst, height * scanStride);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   605
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   606
    // the code below is mostly copied from OGLBlitLoops_SurfaceToSwBlit
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   607
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   608
    j2d_glPixelStorei(GL_PACK_SKIP_PIXELS, dstx);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   609
    j2d_glPixelStorei(GL_PACK_ROW_LENGTH, scanStride / pixelStride);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   610
    j2d_glPixelStorei(GL_PACK_ALIGNMENT, pf.alignment);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   611
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   612
    // this accounts for lower-left origin of the source region
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   613
    srcx = oglsdo->xOffset + srcx;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   614
    srcy = oglsdo->yOffset + oglsdo->height - (srcy + 1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   615
    // we must read one scanline at a time because there is no way
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   616
    // to read starting at the top-left corner of the source region
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   617
    while (height > 0) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   618
        j2d_glPixelStorei(GL_PACK_SKIP_ROWS, dsty);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   619
        j2d_glReadPixels(srcx, srcy, width, 1,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   620
                         pf.format, pf.type, pDst);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   621
        srcy--;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   622
        dsty++;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   623
        height--;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   624
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   625
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   626
    j2d_glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   627
    j2d_glPixelStorei(GL_PACK_SKIP_ROWS, 0);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   628
    j2d_glPixelStorei(GL_PACK_ROW_LENGTH, 0);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   629
    j2d_glPixelStorei(GL_PACK_ALIGNMENT, 4);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   630
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   631
    // the pixels read from the surface are already premultiplied
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   632
    hBitmap = BitmapUtil_CreateBitmapFromARGBPre(w, h, scanStride,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   633
                                                 (int*)pDst);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   634
    free(pDst);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   635
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   636
    if (hBitmap == NULL) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   637
        return JNI_FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   638
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   639
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   640
    AwtWindow_UpdateWindow(env, peer, w, h, hBitmap);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   641
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   642
    // hBitmap is released in UpdateWindow
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   643
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   644
    return JNI_TRUE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   645
}