jdk/src/windows/native/sun/java2d/d3d/D3DSurfaceData.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 887 0aab8d3fa11a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "D3DSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "D3DContext.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "ddrawUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "Devices.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "Win32SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "sun_java2d_d3d_D3DBackBufferSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
extern LockFunc Win32OSSD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
extern GetRasInfoFunc Win32OSSD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
extern UnlockFunc Win32OSSD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
extern DisposeFunc Win32OSSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
extern GetDCFunc Win32OSSD_GetDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern ReleaseDCFunc Win32OSSD_ReleaseDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
extern InvalidateSDFunc Win32OSSD_InvalidateSD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
extern RestoreSurfaceFunc Win32OSSD_RestoreSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern DisposeFunc Win32BBSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
RestoreSurfaceFunc D3DSD_RestoreSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * D3D-surface specific restore function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * We need to make sure the D3DContext is notified if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * surface is lost (only if this surface is the current target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * otherwise it's possible that it'll get restored (along with its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * depth buffer), and the context will still think that the clipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * that's set for this surface is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Consider this scenario:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     vi.validate(gc); // validated, vi's surface is restored, clipping is lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *     // render stuff using d3d, clipping is reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     // -> surface loss event happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     // do a DD blit of the VI to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *     // at this point the VI surface will be marked lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     // and will be restored in validate() next time around,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *     // losing the clipping w/o notifying the D3D context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * } while (vi.surfaceLost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
void D3DSD_RestoreSurface(JNIEnv *env, Win32SDOps *wsdo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    J2dTraceLn(J2D_TRACE_INFO, "D3DSD_RestoreSurface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    D3DSDOps *d3dsdo = (D3DSDOps *)wsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // This is needed only for non-textures, since textures can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // lose their surfaces, as they're managed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (!(d3dsdo->d3dType & D3D_TEXTURE_SURFACE) && wsdo->lpSurface != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (wsdo->ddInstance != NULL && wsdo->ddInstance->ddObject != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            D3DContext *d3dContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                wsdo->ddInstance->ddObject->GetD3dContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if (d3dContext != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                d3dContext->InvalidateIfTarget(env, wsdo->lpSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    Win32OSSD_RestoreSurface(env, wsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Class:     sun_java2d_d3d_D3DSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * Method:    initOps
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * Signature: (Ljava/lang/Object;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
Java_sun_java2d_d3d_D3DSurfaceData_initOps(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                           jobject wsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                           jint depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                           jint transparency)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    Win32SDOps *wsdo = (Win32SDOps *)SurfaceData_InitOps(env, wsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                                         sizeof(D3DSDOps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    wsdo->sdOps.Lock = Win32OSSD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    wsdo->sdOps.GetRasInfo = Win32OSSD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    wsdo->sdOps.Unlock = Win32OSSD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    wsdo->sdOps.Dispose = Win32OSSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    wsdo->RestoreSurface = D3DSD_RestoreSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    wsdo->GetDC = Win32OSSD_GetDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    wsdo->ReleaseDC = Win32OSSD_ReleaseDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    wsdo->InvalidateSD = Win32OSSD_InvalidateSD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    wsdo->invalid = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    wsdo->lockType = WIN32SD_LOCK_UNLOCKED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    wsdo->window = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    wsdo->backBufferCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    wsdo->depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    switch (depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            wsdo->pixelStride = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        case 15: //555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            wsdo->pixelStride = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            wsdo->pixelMasks[0] = 0x1f << 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            wsdo->pixelMasks[1] = 0x1f << 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            wsdo->pixelMasks[2] = 0x1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        case 16: //565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            wsdo->pixelStride = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            wsdo->pixelMasks[0] = 0x1f << 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            wsdo->pixelMasks[1] = 0x3f << 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            wsdo->pixelMasks[2] = 0x1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        case 24:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            wsdo->pixelStride = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        case 32: //x888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            wsdo->pixelStride = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            wsdo->pixelMasks[0] = 0xff0000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            wsdo->pixelMasks[1] = 0x00ff00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            wsdo->pixelMasks[2] = 0x0000ff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    wsdo->surfaceLock = new CriticalSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    wsdo->surfaceLost = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    wsdo->transparency = transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    wsdo->surfacePuntData.usingDDSystem = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    wsdo->surfacePuntData.lpSurfaceSystem = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    wsdo->surfacePuntData.lpSurfaceVram = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    wsdo->surfacePuntData.numBltsSinceRead = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    wsdo->surfacePuntData.pixelsReadSinceBlt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    wsdo->surfacePuntData.numBltsThreshold = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    wsdo->gdiOpPending = 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
jboolean init_D3DSDO(JNIEnv* env, Win32SDOps* wsdo, jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                     jint d3dSurfaceType, jint screen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    // default in case of an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    wsdo->lpSurface = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    wsdo->ddInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Devices::InstanceAccess devices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        wsdo->device = devices->GetDeviceReference(screen, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    if (wsdo->device == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        J2dTraceLn1(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    "init_D3DSDO: Incorrect "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    "screen number (screen=%d)", screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        wsdo->invalid = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    wsdo->w = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    wsdo->h = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    wsdo->surfacePuntData.disablePunts = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * Class:     sun_java2d_d3d_D3DSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * Method:    initOffScreenSurface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * Signature: (JJJIIII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
Java_sun_java2d_d3d_D3DSurfaceData_initOffScreenSurface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    (JNIEnv *env, jobject sData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     jlong pCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     jlong pData, jlong parentPdata,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     jint d3dSurfaceType, jint screen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    Win32SDOps *wsdo = (Win32SDOps *)jlong_to_ptr(pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    D3DContext *pd3dc = (D3DContext *)jlong_to_ptr(pCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOffScreenSurface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    J2dTraceLn4(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                "  width=%-4d height=%-4d type=%-3d scr=%-3d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                width, height, d3dSurfaceType, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // REMIND: ideally this should be done in initOps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    if (d3dSurfaceType == D3D_ATTACHED_SURFACE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        wsdo->sdOps.Dispose = Win32BBSD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    if (init_D3DSDO(env, wsdo, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    d3dSurfaceType, screen) == JNI_FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        SurfaceData_ThrowInvalidPipeException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            "Can't create offscreen surface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return PF_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    HMONITOR hMon = (HMONITOR)wsdo->device->GetMonitor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    DDrawObjectStruct *ddInstance = GetDDInstanceForDevice(hMon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if (!ddInstance || !ddInstance->valid || !pd3dc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return PF_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    if (d3dSurfaceType == D3D_ATTACHED_SURFACE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // REMIND: still using the old path. ideally the creation of attached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // surface shoudld be done in the same way as other types of surfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // that is, in D3DContext::CreateSurface, but we really don't use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // anything from D3DContext to get an attached surface, so this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // was left here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        Win32SDOps *wsdo_parent = (Win32SDOps *)jlong_to_ptr(parentPdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // we're being explicit here: requesting backbuffer, and render target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        DDrawSurface* pNew = wsdo_parent->lpSurface == NULL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            NULL :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            wsdo_parent->lpSurface->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                GetDDAttachedSurface(DDSCAPS_BACKBUFFER|DDSCAPS_3DDEVICE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (pNew == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            FAILED(pd3dc->AttachDepthBuffer(pNew->GetDXSurface())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                           "D3DSD_initSurface: GetAttachedSurface for parent"\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                           " wsdo_parent->lpSurface=0x%x failed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                           wsdo_parent->lpSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (pNew != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                delete pNew;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            SurfaceData_ThrowInvalidPipeException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                "Can't create attached offscreen surface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return PF_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        wsdo->lpSurface = pNew;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        wsdo->ddInstance = ddInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        J2dTraceLn2(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    "D3DSD_initSurface: created attached surface: "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    "wsdo->lpSurface=0x%x for parent "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    "wsdo_parent->lpSurface=0x%x",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    wsdo->lpSurface, wsdo_parent->lpSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        // we don't care about pixel format for non-texture surfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return PF_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    DXSurface *dxSurface = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    jint pf = PF_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    HRESULT res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if (SUCCEEDED(res = pd3dc->CreateSurface(env, wsdo->w, wsdo->h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                             wsdo->depth, wsdo->transparency,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                             d3dSurfaceType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                             &dxSurface, &pf)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // REMIND: put all the error-handling stuff here from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // DDCreateOffScreenSurface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        wsdo->lpSurface = new DDrawSurface(ddInstance->ddObject, dxSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        wsdo->surfacePuntData.lpSurfaceVram = wsdo->lpSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        wsdo->ddInstance = ddInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // the dimensions of the surface may be adjusted in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // textures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        wsdo->w = dxSurface->GetWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        wsdo->h = dxSurface->GetHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        J2dTraceLn1(J2D_TRACE_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    "D3DSurfaceData_initSurface: created surface: "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    "wsdo->lpSurface=0x%x", wsdo->lpSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        DebugPrintDirectDrawError(res,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                  "D3DSurfaceData_initSurface: "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                  "CreateSurface failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // REMIND: should use some other way to signal that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // surface creation was unsuccessful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        SurfaceData_ThrowInvalidPipeException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                              "Can't create offscreen surf");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    return pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * Class:     sun_java2d_d3d_D3DBackBufferSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * Method:    restoreDepthBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
Java_sun_java2d_d3d_D3DBackBufferSurfaceData_restoreDepthBuffer(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                                                jobject sData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    Win32SDOps *wsdo = Win32SurfaceData_GetOpsNoSetup(env, sData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    J2dTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                "D3DBBSD_restoreDepthBuffer: wsdo=0x%x", wsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    if (wsdo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (!DDRestoreSurface(wsdo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // Failure - throw exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                          "D3DBBSD_restoreDepthBuffer: failed to "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                          "restore depth buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            SurfaceData_ThrowInvalidPipeException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                                  "RestoreDepthBuffer failure");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}