/* * Class: sun_java2d_d3d_D3DSurfaceData * Method: initOffScreenSurface * Signature: (JJJIIII)I */ JNIEXPORT jint JNICALL Java_sun_java2d_d3d_D3DSurfaceData_initOffScreenSurface (JNIEnv *env, jobject sData, jlong pCtx, jlong pData, jlong parentPdata, jint width, jint height, jint d3dSurfaceType, jint screen) { Win32SDOps *wsdo = (Win32SDOps *)jlong_to_ptr(pData); D3DContext *pd3dc = (D3DContext *)jlong_to_ptr(pCtx); J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOffScreenSurface"); J2dTraceLn4(J2D_TRACE_VERBOSE, " width=%-4d height=%-4d type=%-3d scr=%-3d", width, height, d3dSurfaceType, screen); // REMIND: ideally this should be done in initOps if (d3dSurfaceType == D3D_ATTACHED_SURFACE) { wsdo->sdOps.Dispose = Win32BBSD_Dispose; } if (init_D3DSDO(env, wsdo, width, height, d3dSurfaceType, screen) == JNI_FALSE) { SurfaceData_ThrowInvalidPipeException(env, "Can't create offscreen surface"); return PF_INVALID; } HMONITOR hMon = (HMONITOR)wsdo->device->GetMonitor(); DDrawObjectStruct *ddInstance = GetDDInstanceForDevice(hMon); if (!ddInstance || !ddInstance->valid || !pd3dc) { return PF_INVALID; } if (d3dSurfaceType == D3D_ATTACHED_SURFACE) { // REMIND: still using the old path. ideally the creation of attached // surface shoudld be done in the same way as other types of surfaces, // that is, in D3DContext::CreateSurface, but we really don't use // anything from D3DContext to get an attached surface, so this // was left here. Win32SDOps *wsdo_parent = (Win32SDOps *)jlong_to_ptr(parentPdata); // we're being explicit here: requesting backbuffer, and render target DDrawSurface* pNew = wsdo_parent->lpSurface == NULL ? NULL : wsdo_parent->lpSurface-> GetDDAttachedSurface(DDSCAPS_BACKBUFFER|DDSCAPS_3DDEVICE); if (pNew == NULL || FAILED(pd3dc->AttachDepthBuffer(pNew->GetDXSurface()))) { J2dRlsTraceLn1(J2D_TRACE_ERROR, "D3DSD_initSurface: GetAttachedSurface for parent"\ " wsdo_parent->lpSurface=0x%x failed", wsdo_parent->lpSurface); if (pNew != NULL) { delete pNew; } SurfaceData_ThrowInvalidPipeException(env, "Can't create attached offscreen surface"); return PF_INVALID; } wsdo->lpSurface = pNew; wsdo->ddInstance = ddInstance; J2dTraceLn2(J2D_TRACE_VERBOSE, "D3DSD_initSurface: created attached surface: "\ "wsdo->lpSurface=0x%x for parent "\ "wsdo_parent->lpSurface=0x%x", wsdo->lpSurface, wsdo_parent->lpSurface); // we don't care about pixel format for non-texture surfaces return PF_INVALID; } DXSurface *dxSurface = NULL; jint pf = PF_INVALID; HRESULT res; if (SUCCEEDED(res = pd3dc->CreateSurface(env, wsdo->w, wsdo->h, wsdo->depth, wsdo->transparency, d3dSurfaceType, &dxSurface, &pf))) { // REMIND: put all the error-handling stuff here from // DDCreateOffScreenSurface wsdo->lpSurface = new DDrawSurface(ddInstance->ddObject, dxSurface); wsdo->surfacePuntData.lpSurfaceVram = wsdo->lpSurface; wsdo->ddInstance = ddInstance; // the dimensions of the surface may be adjusted in case of // textures wsdo->w = dxSurface->GetWidth(); wsdo->h = dxSurface->GetHeight(); J2dTraceLn1(J2D_TRACE_VERBOSE, "D3DSurfaceData_initSurface: created surface: "\ "wsdo->lpSurface=0x%x", wsdo->lpSurface); } else { DebugPrintDirectDrawError(res, "D3DSurfaceData_initSurface: "\ "CreateSurface failed"); // REMIND: should use some other way to signal that // surface creation was unsuccessful SurfaceData_ThrowInvalidPipeException(env, "Can't create offscreen surf"); } return pf; }
int TestTextureMappingQuality(JNIEnv *env, DDraw *ddObject, D3DContext *d3dContext, DDrawSurface *lpPlainSurface) { static J2DLVERTEX quadVerts[4] = { { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f } }; int testRes = TestTextureFormats(d3dContext); if (testRes & J2D_D3D_PIXEL_FORMATS_OK) { DDrawSurface *lpTexture = D3DUtils_CreateTexture(env, ddObject, d3dContext, TR_TRANSLUCENT, D3D_TEXTURE_RASTER_W, D3D_TEXTURE_RASTER_H); if (lpTexture) { D3DUtils_UploadIntImageToXRGBTexture(lpTexture, (int *)srcImageArray, D3D_TEXTURE_RASTER_W, D3D_TEXTURE_RASTER_H); float u2 = ((float)D3D_TEXTURE_RASTER_W) / (float)lpTexture->GetDXSurface()->GetWidth(); float v2 = ((float)D3D_TEXTURE_RASTER_H) / (float)lpTexture->GetDXSurface()->GetHeight(); D3DU_INIT_VERTEX_QUAD_UV(quadVerts, 0.0f, 0.0f, u2, v2); IDirect3DDevice7 *d3dDevice = d3dContext->Get3DDevice(); d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0, 0); d3dContext->SetAlphaComposite(3/*SrcOver*/, 1.0f, D3DC_NO_CONTEXT_FLAGS); d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT); d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFG_POINT); HRESULT res; if (SUCCEEDED(res = d3dContext->BeginScene(STATE_BLITOP))) { DXSurface *dxSurface = lpTexture->GetDXSurface(); if (SUCCEEDED(d3dContext->SetTexture(dxSurface))) { for (int i = 0; i < d3dNumTextureRects * 4; i += 4) { float x1 = d3dTextureRects[i + 0]; float y1 = d3dTextureRects[i + 1]; float x2 = d3dTextureRects[i + 2]; float y2 = d3dTextureRects[i + 3]; D3DU_INIT_VERTEX_QUAD_XY(quadVerts, x1, y1, x2, y2); d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_J2DLVERTEX, quadVerts, 4, 0); } } res = d3dContext->ForceEndScene(); d3dContext->SetTexture(NULL); } // REMIND: at this point we ignore the results of // the test. TestRenderingResults(lpPlainSurface, linInterpArray); if (SUCCEEDED(res)) { testRes |= (J2D_D3D_TR_TEXTURE_SURFACE_OK | J2D_D3D_TEXTURE_BLIT_OK | J2D_D3D_TEXTURE_TRANSFORM_OK); // REMIND: add tests for opaque and bitmask textures testRes |= (J2D_D3D_OP_TEXTURE_SURFACE_OK | J2D_D3D_BM_TEXTURE_SURFACE_OK); } delete lpTexture; } else { J2dRlsTraceLn(J2D_TRACE_ERROR, "TestTextureMappingQuality: "\ "CreateTexture(TRANSLUCENT) FAILED"); } } return testRes; }