jdk/src/windows/native/sun/java2d/d3d/D3DRuntimeTest.cpp
author ohair
Fri, 08 Aug 2008 08:52:18 -0700
changeset 921 85b4d3bded64
parent 2 90ce3da70b43
permissions -rw-r--r--
Merge
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 "dxInit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "ddrawUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "RegistryKey.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "D3DTestRaster.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "WindowsFlags.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "D3DRuntimeTest.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "D3DSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "D3DUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
void TestRasterOutput(byte *rasPtr, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                      int scanStride, int pixelStride,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                      TIntTestRaster goldenArray = NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#endif // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
void PrintD3DCaps(int caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Test whether we should enable d3d rendering on this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This includes checking whether there were problems creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the necessary offscreen surface, problems during any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * rendering calls (Blts and d3d lines) and any rendering artifacts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * caused by d3d lines.  The rendering artifact tests are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * performed by checking a pre-rendered test pattern (produced
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * by our software renderer) against that same pattern rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * on this device.  If there are any pixels which differ between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the two patterns we disable d3d line rendering on the device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Differences in the test pattern rendering can be caused
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * by different rendering algorithms used by our software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * renderer and the driver or hardware on this device.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * some Intel cards (e.g., i815) are known to use polygon renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * for their lines, which sometimes result in wide lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The test pattern is stored in d3dTestRaster.h, which is generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * by a Java test program
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * (src/share/test/java2d/VolatileImage/D3DTestPattern/D3DTestPattern.java).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
int TestForBadHardware(DxCapabilities *dxCaps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Check this device against a list of bad d3d devices and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // disable as necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static WCHAR *badDeviceStrings[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        L"Trident Video Accelerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        L"RAGE PRO",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        L"RAGE XL",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        L"Rage Fury",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static int numBadDevices = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    WCHAR *dxDeviceName = dxCaps->GetDeviceName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    for (int i = 0; i < numBadDevices; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (wcsstr(dxDeviceName, badDeviceStrings[i]) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            // REMIND: For now, we disable d3d for all operations because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            // of one bad d3d device in the system.  This is because we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            // should avoid registering the d3d rendering loops at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            // Java level since we cannot use d3d at the native level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            // A real fix would instead understand the difference between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            // a surface that could handle d3d native rendering and one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // that could not and would use the appropriate rendering loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // so that disabling d3d on simply one device would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            // sufficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            // Note that this disable-all approach is okay for now because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            // the single bad device (Trident) that triggers this error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // is generally found on laptops, where multiple graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // devices are not even possible, so disabling d3d for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            // devices is equivalent to disabling d3d for this single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                           "TestForBadHardware: Found match: %S. Test FAILED",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                           badDeviceStrings[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    return J2D_D3D_HW_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
int TestTextureFormats(D3DContext *d3dContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int testRes = J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    D3DTextureTable &table = d3dContext->GetTextureTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    int pfExists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // Check that there's at least one valid pixel format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // for each transparency type (opaque, bitmask, translucent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    for (int t = TR_OPAQUE_IDX; t < TR_MAX_IDX; t++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        pfExists = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (int d = DEPTH16_IDX; d < DEPTH_MAX_IDX; d++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (table[t][d].pfType != PF_INVALID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                pfExists = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (pfExists == FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            // couldn't find a pixel formap for this transparency type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                           "D3DTest::TestTextureFormats no texture formats"\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                           " for %d transparency", t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // we must have ARGB texture format (may be used for text rendering)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if (pfExists == TRUE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        table[TR_TRANSLUCENT_IDX][DEPTH32_IDX].pfType == PF_INT_ARGB)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        testRes |= J2D_D3D_PIXEL_FORMATS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                       "D3DTest::TestTextureFormats: FAILED pfType=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                       table[TR_TRANSLUCENT_IDX][DEPTH32_IDX].pfType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
int TestSetClip(JNIEnv *env, D3DContext *d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                DDrawSurface *lpPlainSurface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    int testRes = J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    if (SUCCEEDED(d3dContext->SetRenderTarget(lpPlainSurface))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        jobject clip =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            JNU_CallStaticMethodByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                       "sun/java2d/pipe/Region",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                       "getInstanceXYWH",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                       "(IIII)Lsun/java2d/pipe/Region;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                       0, 0, D3D_TEST_RASTER_W, D3D_TEST_RASTER_H).l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (!JNU_IsNull(env, clip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (SUCCEEDED(d3dContext->SetClip(env, clip, JNI_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                              0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                              D3D_TEST_RASTER_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                              D3D_TEST_RASTER_H)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                testRes |= J2D_D3D_DEPTH_SURFACE_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            env->DeleteLocalRef(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
int TestRenderingResults(DDrawSurface *lpPlainSurface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                         TIntTestRaster goldenArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // Now, check the results of the test raster against our d3d drawing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    SurfaceDataRasInfo rasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (FAILED(lpPlainSurface->Lock(NULL, &rasInfo, DDLOCK_WAIT, NULL))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    byte *rasPtr = (byte*)rasInfo.rasBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    int pixelStride = rasInfo.pixelStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    int scanStride = rasInfo.scanStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    for (int row = 0; row < D3D_TEST_RASTER_H; ++row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        byte *tmpRasPtr = rasPtr + row * scanStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        for (int col = 0; col < D3D_TEST_RASTER_W; ++col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            DWORD pixelVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            switch (pixelStride) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                pixelVal = *tmpRasPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                pixelVal = *((unsigned short*)tmpRasPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                pixelVal = *((unsigned int*)tmpRasPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            tmpRasPtr += pixelStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // The test is simple: if the test raster pixel has value 0, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            // we expect 0 in the d3d surface.  If the test raster has a nonzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            // value, then we expect the d3d surface to also have non-zero value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // All other results represent failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            int goldenValue = (goldenArray[row][col] & 0x00ffffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if ((goldenValue == 0 && pixelVal != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                (goldenValue != 0 && pixelVal == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                J2dRlsTraceLn3(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                               "TestRenderingResults: Quality test failed due "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                               "to value %x at (%d, %d)", pixelVal, col, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                // This section is not necessary, but it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                // nice to know why we are failing D3DTest on some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                // systems.  If tracing is enabled, this section will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                // produce an ascii representation of the test pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                // the result on this device, and the pixels that were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                // in error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                J2dTraceLn(J2D_TRACE_VERBOSE, "TestRaster:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                TestRasterOutput((byte*)goldenArray, 0, 0, D3D_TEST_RASTER_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                 D3D_TEST_RASTER_H, D3D_TEST_RASTER_W*4, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                J2dTraceLn(J2D_TRACE_VERBOSE, "D3D Raster:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                TestRasterOutput(rasPtr, 0, 0, D3D_TEST_RASTER_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                 D3D_TEST_RASTER_H, scanStride, pixelStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                J2dTraceLn(J2D_TRACE_VERBOSE, "Deltas (x indicates problem pixel):");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                TestRasterOutput(rasPtr, 0, 0, D3D_TEST_RASTER_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                 D3D_TEST_RASTER_H, scanStride, pixelStride,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                 goldenArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#endif // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                lpPlainSurface->Unlock(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                return  J2D_D3D_FAILURE;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    lpPlainSurface->Unlock(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    return (J2D_D3D_LINES_OK | J2D_D3D_LINE_CLIPPING_OK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
int TestLineRenderingQuality(JNIEnv *env, D3DContext *d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                             DDrawSurface *lpPlainSurface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    static J2D_XY_C_VERTEX lineVerts[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#ifdef USE_SINGLE_VERTEX_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        { 0, 0, 0, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        { 0, 0, 0, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        { 0, 0, 0, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        { 0, 0, 0, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        { 0, 0, 0, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        { 0, 0, 0, 0xffffffff }, // x, y, z, color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        { 0, 0, 0, 0xffffffff },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        { 0, 0, 0, 0xffffffff },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        { 0, 0, 0, 0xffffffff },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        { 0, 0, 0, 0xffffffff },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
#endif // USE_SINGLE_VERTEX_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    IDirect3DDevice7 *d3dDevice = d3dContext->Get3DDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    HRESULT res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0.0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (FAILED(d3dContext->BeginScene(STATE_RENDEROP))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    for (i = 0; i < d3dNumTestLines * 4; i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        lineVerts[0].x = d3dTestLines[i + 0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        lineVerts[0].y = d3dTestLines[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        lineVerts[1].x = d3dTestLines[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        lineVerts[1].y = d3dTestLines[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (FAILED(res = d3dDevice->DrawPrimitive(D3DPT_LINESTRIP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                                  D3DFVF_J2D_XY_C,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                                  lineVerts, 2, 0)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            d3dContext->ForceEndScene();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // REMIND: needed for the test to pass on ATI some boards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        d3dDevice->DrawPrimitive(D3DPT_POINTLIST, D3DFVF_J2D_XY_C,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                 &(lineVerts[1]), 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    for (i = 0; i < d3dNumTestRects * 4; i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        float x1 = d3dTestRects[i + 0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        float y1 = d3dTestRects[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        float x2 = d3dTestRects[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        float y2 = d3dTestRects[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        D3DU_INIT_VERTEX_PENT_XY(lineVerts, x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (FAILED(res = d3dDevice->DrawPrimitive(D3DPT_LINESTRIP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                  D3DFVF_J2D_XY_C,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                                  lineVerts, 5, 0)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            d3dContext->ForceEndScene();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return J2D_D3D_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    d3dContext->ForceEndScene();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    // REMIND: add rendering of clipped lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    return TestRenderingResults(lpPlainSurface, d3dTestRaster);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
int TestTextureMappingQuality(JNIEnv *env, DDraw *ddObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                              D3DContext *d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                              DDrawSurface *lpPlainSurface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    static J2DLVERTEX quadVerts[4] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    int testRes = TestTextureFormats(d3dContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (testRes & J2D_D3D_PIXEL_FORMATS_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        DDrawSurface *lpTexture =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            D3DUtils_CreateTexture(env, ddObject, d3dContext, TR_TRANSLUCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                   D3D_TEXTURE_RASTER_W, D3D_TEXTURE_RASTER_H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (lpTexture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            D3DUtils_UploadIntImageToXRGBTexture(lpTexture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                 (int *)srcImageArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                 D3D_TEXTURE_RASTER_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                                 D3D_TEXTURE_RASTER_H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            float u2 = ((float)D3D_TEXTURE_RASTER_W) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                       (float)lpTexture->GetDXSurface()->GetWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            float v2 = ((float)D3D_TEXTURE_RASTER_H) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                       (float)lpTexture->GetDXSurface()->GetHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            D3DU_INIT_VERTEX_QUAD_UV(quadVerts, 0.0f, 0.0f, u2, v2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            IDirect3DDevice7 *d3dDevice = d3dContext->Get3DDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            d3dContext->SetAlphaComposite(3/*SrcOver*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                          1.0f, D3DC_NO_CONTEXT_FLAGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFG_POINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            HRESULT res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (SUCCEEDED(res = d3dContext->BeginScene(STATE_BLITOP))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                DXSurface *dxSurface = lpTexture->GetDXSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                if (SUCCEEDED(d3dContext->SetTexture(dxSurface))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    for (int i = 0; i < d3dNumTextureRects * 4; i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        float x1 = d3dTextureRects[i + 0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        float y1 = d3dTextureRects[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        float x2 = d3dTextureRects[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        float y2 = d3dTextureRects[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        D3DU_INIT_VERTEX_QUAD_XY(quadVerts, x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                                 D3DFVF_J2DLVERTEX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                                 quadVerts, 4, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                res = d3dContext->ForceEndScene();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                d3dContext->SetTexture(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            // REMIND: at this point we ignore the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            TestRenderingResults(lpPlainSurface, linInterpArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (SUCCEEDED(res)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                testRes |= (J2D_D3D_TR_TEXTURE_SURFACE_OK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            J2D_D3D_TEXTURE_BLIT_OK       |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                            J2D_D3D_TEXTURE_TRANSFORM_OK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                // REMIND: add tests for opaque and bitmask textures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                testRes |= (J2D_D3D_OP_TEXTURE_SURFACE_OK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                            J2D_D3D_BM_TEXTURE_SURFACE_OK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            delete lpTexture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                          "TestTextureMappingQuality: "\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                          "CreateTexture(TRANSLUCENT) FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
int TestD3DDevice(DDraw *ddObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                  D3DContext *d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                  DxCapabilities *dxCaps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    int testRes = TestForBadHardware(dxCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    if (!(testRes & J2D_D3D_HW_OK) || !d3dContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    D3DDEVICEDESC7 d3dDevDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    IDirect3DDevice7 *d3dDevice = d3dContext->Get3DDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (d3dDevice == NULL  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        FAILED(d3dDevice->GetCaps(&d3dDevDesc)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        FAILED(D3DUtils_CheckDeviceCaps(&d3dDevDesc)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                      "TestD3DDevice: device caps testing FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    testRes |= J2D_D3D_DEVICE_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    DDrawSurface *lpPlainSurface =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        D3DUtils_CreatePlainSurface(env, ddObject, d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                    D3D_TEST_RASTER_W, D3D_TEST_RASTER_H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    if (!lpPlainSurface) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                      "TestD3DDevice: CreatePlainSurface FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    testRes |= J2D_D3D_PLAIN_SURFACE_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    // Set identity transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (FAILED(d3dContext->SetTransform(NULL, 0, 0, 0, 0, 0, 0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                      "TestD3DDevice: SetTransform FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        delete lpPlainSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    testRes |= J2D_D3D_SET_TRANSFORM_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    // Test setting the target surface, create depth buffer, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    testRes |= TestSetClip(env, d3dContext, lpPlainSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    if (!(testRes & J2D_D3D_DEPTH_SURFACE_OK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        J2dRlsTraceLn(J2D_TRACE_ERROR, "TestD3DDevice: SetClip FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        delete lpPlainSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    // Test drawLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    testRes |= TestLineRenderingQuality(env, d3dContext, lpPlainSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    // Test texture mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    testRes |= TestTextureMappingQuality(env, ddObject, d3dContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                         lpPlainSurface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    d3dContext->SetRenderTarget(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    delete lpPlainSurface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    return testRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 * Output test raster (produced in D3DTest function).  Utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 * used in debugging only.  Enable by setting J2D_TRACE_LEVEL=J2D_VERBOSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 * prior to running application with debug java.  The output from this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 * be seen only if D3DTest fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
void TestRasterOutput(byte *rasPtr, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                      int scanStride, int pixelStride,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                      TIntTestRaster goldenArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    int goldenValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    for (int traceRow = y; traceRow < h; ++traceRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        byte *tmpRasPtr = rasPtr + traceRow * scanStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        for (int traceCol = x; traceCol < w; ++traceCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            DWORD pixelVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            switch (pixelStride) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                pixelVal = *tmpRasPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                pixelVal = *((unsigned short*)tmpRasPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                pixelVal = *((unsigned int*)tmpRasPtr) & 0x00ffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            tmpRasPtr += pixelStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (goldenArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if (pixelVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    J2dTrace(J2D_TRACE_VERBOSE, "1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    J2dTrace(J2D_TRACE_VERBOSE, "0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                goldenValue = (goldenArray[traceRow][traceCol] & 0x00ffffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                if ((goldenValue == 0 && pixelVal != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    (goldenValue != 0 && pixelVal == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    J2dTrace(J2D_TRACE_VERBOSE, "x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    J2dTrace(J2D_TRACE_VERBOSE, "-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        J2dTrace(J2D_TRACE_VERBOSE, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
#endif // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
void PrintD3DCaps(int caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    J2dTraceLn(J2D_TRACE_VERBOSE, "{")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    if (caps == J2D_D3D_FAILURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_FAILURE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (caps & J2D_D3D_DEPTH_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_DEPTH_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (caps & J2D_D3D_PLAIN_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_PLAIN_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (caps & J2D_D3D_OP_TEXTURE_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_OP_TEXTURE_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (caps & J2D_D3D_BM_TEXTURE_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_BM_TEXTURE_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (caps & J2D_D3D_TR_TEXTURE_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_TR_TEXTURE_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (caps & J2D_D3D_OP_RTT_SURFACE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_OP_RTT_SURFACE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (caps & J2D_D3D_LINE_CLIPPING_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_LINE_CLIPPING_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (caps & J2D_D3D_LINES_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_LINES_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (caps & J2D_D3D_TEXTURE_BLIT_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_TEXTURE_BLIT_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (caps & J2D_D3D_TEXTURE_TRANSFORM_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_TEXTURE_TRANSFORM_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (caps & J2D_D3D_DEVICE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_DEVICE_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        if (caps & J2D_D3D_PIXEL_FORMATS_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_SET_TRANSFORM_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (caps & J2D_D3D_HW_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            J2dTraceLn(J2D_TRACE_VERBOSE, "  J2D_D3D_HW_OK,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    J2dTraceLn(J2D_TRACE_VERBOSE, "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
}