J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <jni.h> |
| 28 | #include "jlong.h" |
| 29 | #include <sun_java2d_d3d_D3DBlitLoops.h> |
| 30 | #include "ddrawUtils.h" |
| 31 | #include "GraphicsPrimitiveMgr.h" |
| 32 | #include "Region.h" |
| 33 | |
| 34 | #include "D3DUtils.h" |
| 35 | #include "D3DContext.h" |
| 36 | #include "D3DSurfaceData.h" |
| 37 | |
| 38 | extern CriticalSection windowMoveLock; |
| 39 | |
| 40 | extern "C" { |
| 41 | |
| 42 | JNIEXPORT void JNICALL |
| 43 | Java_sun_java2d_d3d_D3DBlitLoops_doTransform |
| 44 | (JNIEnv *env, jclass d3dbl, |
| 45 | jlong pSrcData, jlong pDstData, |
| 46 | jlong pCtx, |
| 47 | jint hint, |
| 48 | jint sx1, jint sy1, jint sx2, jint sy2, |
| 49 | jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) |
| 50 | { |
| 51 | static J2DLVERTEX quadVerts[4] = { |
| 52 | { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f }, |
| 53 | { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f }, |
| 54 | { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f }, |
| 55 | { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f } |
| 56 | }; |
| 57 | |
| 58 | J2dTraceLn(J2D_TRACE_INFO, "D3DBlitLoops_doTransform"); |
| 59 | J2dTraceLn4(J2D_TRACE_VERBOSE, " sx1=%-4d sy1=%-4d sx2=%-4d sy2=%-4d ", |
| 60 | sx1, sy1, sx2, sy2); |
| 61 | J2dTraceLn4(J2D_TRACE_VERBOSE, |
| 62 | " dx1=%4f dy1=%4f dx2=%4f dy2=%4f", dx1, dy1, dx2, dy2); |
| 63 | |
| 64 | if (sx2 <= sx1 || sy2 <= sy1 || dx2 <= dx1 || dy2 <= dy1) { |
| 65 | J2dTraceLn(J2D_TRACE_WARNING, |
| 66 | "D3DBlitLoops_doTransform: invalid dimensions"); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | D3DContext *d3dc = (D3DContext *)jlong_to_ptr(pCtx); |
| 71 | if (d3dc == NULL) { |
| 72 | J2dTraceLn(J2D_TRACE_WARNING, |
| 73 | "D3DBlitLoops_doTransform: null device context"); |
| 74 | return; |
| 75 | } |
| 76 | Win32SDOps *srcOps = (Win32SDOps *)jlong_to_ptr(pSrcData); |
| 77 | Win32SDOps *dstOps = (Win32SDOps *)jlong_to_ptr(pDstData); |
| 78 | |
| 79 | if (!srcOps->ddInstance || !dstOps->ddInstance) { |
| 80 | // Some situations can cause us to fail on primary |
| 81 | // creation, resulting in null lpSurface and null ddInstance |
| 82 | // for a Win32Surface object.. Just noop this call in that case. |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | DDrawSurface *ddTargetSurface = d3dc->GetTargetSurface(); |
| 87 | DDrawSurface *ddSrcSurface = srcOps->lpSurface; |
| 88 | if (ddTargetSurface == NULL || ddSrcSurface == NULL) { |
| 89 | return; |
| 90 | } |
| 91 | ddTargetSurface->GetExclusiveAccess(); |
| 92 | d3dc->GetExclusiveAccess(); |
| 93 | |
| 94 | IDirect3DDevice7 *d3dDevice = d3dc->Get3DDevice(); |
| 95 | if (d3dDevice == NULL) { |
| 96 | d3dc->ReleaseExclusiveAccess(); |
| 97 | ddTargetSurface->ReleaseExclusiveAccess(); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | float tw = (float)ddSrcSurface->GetDXSurface()->GetWidth(); |
| 102 | float th = (float)ddSrcSurface->GetDXSurface()->GetHeight(); |
| 103 | float tx1 = ((float)sx1) / tw; |
| 104 | float ty1 = ((float)sy1) / th; |
| 105 | float tx2 = ((float)sx2) / tw; |
| 106 | float ty2 = ((float)sy2) / th; |
| 107 | |
| 108 | D3DU_INIT_VERTEX_QUAD(quadVerts, dx1, dy1, dx2, dy2, |
| 109 | d3dc->blitPolygonPixel, |
| 110 | tx1, ty1, tx2, ty2); |
| 111 | |
| 112 | if (hint == D3DSD_XFORM_BILINEAR) { |
| 113 | d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR); |
| 114 | d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFG_LINEAR); |
| 115 | } else if (hint == D3DSD_XFORM_NEAREST_NEIGHBOR) { |
| 116 | d3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT); |
| 117 | d3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFG_POINT); |
| 118 | } |
| 119 | |
| 120 | HRESULT res; |
| 121 | D3DU_PRIM2_LOOP_BEGIN(res, srcOps, dstOps); |
| 122 | if (SUCCEEDED(res = d3dc->BeginScene(STATE_BLITOP))) { |
| 123 | DXSurface *dxSurface = ddSrcSurface->GetDXSurface(); |
| 124 | if (SUCCEEDED(res = d3dc->SetTexture(dxSurface))) |
| 125 | { |
| 126 | res = d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_J2DLVERTEX, |
| 127 | quadVerts, 4, 0); |
| 128 | } |
| 129 | d3dc->EndScene(res); |
| 130 | } |
| 131 | D3DU_PRIM2_LOOP_END(env, res, srcOps, dstOps, |
| 132 | "DrawPrimitive(D3DPT_TRIANGLEFAN)"); |
| 133 | |
| 134 | d3dc->ReleaseExclusiveAccess(); |
| 135 | ddTargetSurface->ReleaseExclusiveAccess(); |
| 136 | } |
| 137 | |
| 138 | } |