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