< prev index next >

src/java.desktop/windows/native/libawt/java2d/d3d/D3DVertexCacher.cpp

Print this page




 194     lpD3DDevice = pCtx->Get3DDevice();
 195     RETURN_STATUS_IF_NULL(lpD3DDevice, E_FAIL);
 196 
 197     ZeroMemory(&caps, sizeof(caps));
 198     lpD3DDevice->GetDeviceCaps(&caps);
 199 
 200     D3DPOOL pool = (caps.DeviceType == D3DDEVTYPE_HAL) ?
 201             D3DPOOL_DEFAULT : D3DPOOL_SYSTEMMEM;
 202     // usage depends on whether we use hw or sw vertex processing
 203     HRESULT res =
 204         lpD3DDevice->CreateVertexBuffer(MAX_BATCH_SIZE*sizeof(J2DLVERTEX),
 205             D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, D3DFVF_J2DLVERTEX,
 206             pool, &lpD3DVertexBuffer, NULL);
 207     RETURN_STATUS_IF_FAILED(res);
 208 
 209     res = lpD3DDevice->SetStreamSource(0, lpD3DVertexBuffer, 0,
 210                                        sizeof(J2DLVERTEX));
 211     RETURN_STATUS_IF_FAILED(res);
 212 
 213     lpD3DDevice->SetFVF(D3DFVF_J2DLVERTEX);










 214     return res;
 215 }
 216 
 217 void
 218 D3DVertexCacher::ReleaseDefPoolResources()
 219 {
 220     SAFE_RELEASE(lpD3DVertexBuffer);
 221     pCtx = NULL;
 222 }
 223 
 224 HRESULT D3DVertexCacher::DrawLine(int x1, int y1, int x2, int y2)
 225 {
 226     HRESULT res;
 227     if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, 1*2))) {
 228         float fx1, fy1, fx2, fy2;
 229         if (y1 == y2) {
 230             // horizontal
 231             fy1  = (float)y1+HV_FF1;
 232             fy2  = fy1;
 233 
 234             if (x1 > x2) {
 235                 fx1 = (float)x2+HV_FF3;
 236                 fx2 = (float)x1+HV_FF2;
 237             } else if (x1 < x2) {
 238                 fx1 = (float)x1+HV_FF3;
 239                 fx2 = (float)x2+HV_FF2;
 240             } else {
 241                 // single point, offset a little so that a single
 242                 // pixel is rendered
 243                 fx1 = (float)x1-SP_FF4;
 244                 fy1 = (float)y1-SP_FF4;
 245                 fx2 = (float)x2+SP_FF4;
 246                 fy2 = (float)y2+SP_FF4;
 247             }
 248         } else if (x1 == x2) {
 249             // vertical
 250             fx1  = (float)x1+HV_FF1;
 251             fx2  = fx1;
 252             if (y1 > y2) {
 253                 fy1 = (float)y2+HV_FF3;
 254                 fy2 = (float)y1+HV_FF2;
 255             } else {
 256                 fy1 = (float)y1+HV_FF3;
 257                 fy2 = (float)y2+HV_FF2;
 258             }
 259         } else {
 260             // diagonal
 261             if (x1 > x2 && y1 > y2) {
 262                 // ^
 263                 //  \ case -> inverse
 264                 fx1 = (float)x2;
 265                 fy1 = (float)y2;
 266                 fx2 = (float)x1;
 267                 fy2 = (float)y1;
 268             } else if (x1 > x2 && y2 > y1) {
 269                 //  /
 270                 // v  case - inverse
 271                 fx1 = (float)x2;
 272                 fy1 = (float)y2;
 273                 fx2 = (float)x1;
 274                 fy2 = (float)y1;
 275             } else {
 276                 // \      ^
 277                 //  v or /  - leave as is


 370     return res;
 371 }
 372 
 373 HRESULT
 374 D3DVertexCacher::DrawScanlines(jint scanlineCount, jint *scanlines)
 375 {
 376     HRESULT res;
 377     float x1, x2, y;
 378     UINT reqVerts = scanlineCount*2/*vertices per line*/;
 379 
 380     if (scanlineCount == 0) {
 381         return S_OK;
 382     }
 383 
 384     do {
 385         UINT vertsInBatch = min(2*(MAX_BATCH_SIZE/2), reqVerts);
 386         if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, vertsInBatch))) {
 387             reqVerts -= vertsInBatch;
 388             do {
 389                 x1 = ((float)*(scanlines++)) +HV_FF3;
 390                 x2 = ((float)*(scanlines++)) +HV_FF2;
 391                 y  = ((float)*(scanlines++)) +HV_FF1;
 392                 ADD_LINE_XYC(x1, y, x2, y, color);
 393                 vertsInBatch -= 2;
 394             } while (vertsInBatch > 0);
 395         }
 396     } while (reqVerts > 0 && SUCCEEDED(res));
 397     return res;
 398 }
 399 
 400 HRESULT
 401 D3DVertexCacher::FillSpans(jint spanCount, jint *spans)
 402 {
 403     HRESULT res;
 404     float x1, y1, x2, y2;
 405     UINT reqVerts = spanCount*2*3/*vertices per span: two triangles*/;
 406 
 407     if (spanCount == 0) {
 408         return S_OK;
 409     }
 410 


 426     } while (reqVerts > 0 && SUCCEEDED(res));
 427 
 428     return res;
 429 }
 430 
 431 HRESULT D3DVertexCacher::DrawRect(int x1, int y1, int x2, int y2)
 432 {
 433     HRESULT res;
 434 
 435     if ((x2 - x1) < 2 || (y2 - y1) < 2) {
 436         return FillRect(x1, y1, x2+1, y2+1);
 437     }
 438     if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, 4*2))) {
 439 
 440         float fx1 = (float)x1;
 441         float fy1 = (float)y1;
 442         float fx2 = (float)x2;
 443         float fy2 = (float)y2;
 444 
 445         // horiz: top left - top right
 446         ADD_LINE_XYC(fx1+HV_FF3, fy1+HV_FF1, fx2-1.0f+HV_FF2, fy1+HV_FF1,color);
 447         // horiz: bottom left - bottom right
 448         ADD_LINE_XYC(fx1+1.0f+HV_FF3, fy2+HV_FF1, fx2+HV_FF2, fy2+HV_FF1,color);
 449         // vert : top right - bottom right
 450         ADD_LINE_XYC(fx2+HV_FF1, fy1+HV_FF3, fx2+HV_FF1, fy2-1.0f+HV_FF2,color);
 451         // vert : top left - bottom left
 452         ADD_LINE_XYC(fx1+HV_FF1, fy1+1.0f+HV_FF3, fx1+HV_FF1, fy2+HV_FF2,color);
 453     }
 454     return res;
 455 }
 456 
 457 HRESULT D3DVertexCacher::FillRect(int x1, int y1, int x2, int y2)
 458 {
 459     HRESULT res;
 460     if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) {
 461         float fx1 = (float)x1;
 462         float fy1 = (float)y1;
 463         float fx2 = (float)x2;
 464         float fy2 = (float)y2;
 465         ADD_TRIANGLE_XYUVC(fx1, fy1, fx2, fy1, fx1, fy2,
 466                            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
 467                            color);
 468         ADD_TRIANGLE_XYUVC(fx1, fy2, fx2, fy1, fx2, fy2,
 469                            0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
 470                            color);
 471     }
 472     return res;




 194     lpD3DDevice = pCtx->Get3DDevice();
 195     RETURN_STATUS_IF_NULL(lpD3DDevice, E_FAIL);
 196 
 197     ZeroMemory(&caps, sizeof(caps));
 198     lpD3DDevice->GetDeviceCaps(&caps);
 199 
 200     D3DPOOL pool = (caps.DeviceType == D3DDEVTYPE_HAL) ?
 201             D3DPOOL_DEFAULT : D3DPOOL_SYSTEMMEM;
 202     // usage depends on whether we use hw or sw vertex processing
 203     HRESULT res =
 204         lpD3DDevice->CreateVertexBuffer(MAX_BATCH_SIZE*sizeof(J2DLVERTEX),
 205             D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, D3DFVF_J2DLVERTEX,
 206             pool, &lpD3DVertexBuffer, NULL);
 207     RETURN_STATUS_IF_FAILED(res);
 208 
 209     res = lpD3DDevice->SetStreamSource(0, lpD3DVertexBuffer, 0,
 210                                        sizeof(J2DLVERTEX));
 211     RETURN_STATUS_IF_FAILED(res);
 212 
 213     lpD3DDevice->SetFVF(D3DFVF_J2DLVERTEX);
 214 
 215     fudge2 = HV_FF2;
 216     if (fudge2 > 0) {
 217         D3DADAPTER_IDENTIFIER9 aid;
 218         if (SUCCEEDED(pCtx->Get3DObject()->GetAdapterIdentifier(pCtx->
 219                      getAdapterOrdinal(), 0, &aid)) && aid.VendorId == 0x8086) {
 220             // Intel
 221             fudge2 -= 0.09f;
 222         }
 223     }
 224     return res;
 225 }
 226 
 227 void
 228 D3DVertexCacher::ReleaseDefPoolResources()
 229 {
 230     SAFE_RELEASE(lpD3DVertexBuffer);
 231     pCtx = NULL;
 232 }
 233 
 234 HRESULT D3DVertexCacher::DrawLine(int x1, int y1, int x2, int y2)
 235 {
 236     HRESULT res;
 237     if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, 1*2))) {
 238         float fx1, fy1, fx2, fy2;
 239         if (y1 == y2) {
 240             // horizontal
 241             fy1  = (float)y1+HV_FF1;
 242             fy2  = fy1;
 243 
 244             if (x1 > x2) {
 245                 fx1 = (float)x2+HV_FF3;
 246                 fx2 = (float)x1+fudge2;
 247             } else if (x1 < x2) {
 248                 fx1 = (float)x1+HV_FF3;
 249                 fx2 = (float)x2+fudge2;
 250             } else {
 251                 // single point, offset a little so that a single
 252                 // pixel is rendered
 253                 fx1 = (float)x1-SP_FF4;
 254                 fy1 = (float)y1-SP_FF4;
 255                 fx2 = (float)x2+SP_FF4;
 256                 fy2 = (float)y2+SP_FF4;
 257             }
 258         } else if (x1 == x2) {
 259             // vertical
 260             fx1  = (float)x1+HV_FF1;
 261             fx2  = fx1;
 262             if (y1 > y2) {
 263                 fy1 = (float)y2+HV_FF3;
 264                 fy2 = (float)y1+fudge2;
 265             } else {
 266                 fy1 = (float)y1+HV_FF3;
 267                 fy2 = (float)y2+fudge2;
 268             }
 269         } else {
 270             // diagonal
 271             if (x1 > x2 && y1 > y2) {
 272                 // ^
 273                 //  \ case -> inverse
 274                 fx1 = (float)x2;
 275                 fy1 = (float)y2;
 276                 fx2 = (float)x1;
 277                 fy2 = (float)y1;
 278             } else if (x1 > x2 && y2 > y1) {
 279                 //  /
 280                 // v  case - inverse
 281                 fx1 = (float)x2;
 282                 fy1 = (float)y2;
 283                 fx2 = (float)x1;
 284                 fy2 = (float)y1;
 285             } else {
 286                 // \      ^
 287                 //  v or /  - leave as is


 380     return res;
 381 }
 382 
 383 HRESULT
 384 D3DVertexCacher::DrawScanlines(jint scanlineCount, jint *scanlines)
 385 {
 386     HRESULT res;
 387     float x1, x2, y;
 388     UINT reqVerts = scanlineCount*2/*vertices per line*/;
 389 
 390     if (scanlineCount == 0) {
 391         return S_OK;
 392     }
 393 
 394     do {
 395         UINT vertsInBatch = min(2*(MAX_BATCH_SIZE/2), reqVerts);
 396         if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, vertsInBatch))) {
 397             reqVerts -= vertsInBatch;
 398             do {
 399                 x1 = ((float)*(scanlines++)) +HV_FF3;
 400                 x2 = ((float)*(scanlines++)) +fudge2;
 401                 y  = ((float)*(scanlines++)) +HV_FF1;
 402                 ADD_LINE_XYC(x1, y, x2, y, color);
 403                 vertsInBatch -= 2;
 404             } while (vertsInBatch > 0);
 405         }
 406     } while (reqVerts > 0 && SUCCEEDED(res));
 407     return res;
 408 }
 409 
 410 HRESULT
 411 D3DVertexCacher::FillSpans(jint spanCount, jint *spans)
 412 {
 413     HRESULT res;
 414     float x1, y1, x2, y2;
 415     UINT reqVerts = spanCount*2*3/*vertices per span: two triangles*/;
 416 
 417     if (spanCount == 0) {
 418         return S_OK;
 419     }
 420 


 436     } while (reqVerts > 0 && SUCCEEDED(res));
 437 
 438     return res;
 439 }
 440 
 441 HRESULT D3DVertexCacher::DrawRect(int x1, int y1, int x2, int y2)
 442 {
 443     HRESULT res;
 444 
 445     if ((x2 - x1) < 2 || (y2 - y1) < 2) {
 446         return FillRect(x1, y1, x2+1, y2+1);
 447     }
 448     if (SUCCEEDED(res = EnsureCapacity(D3DPT_LINELIST, 4*2))) {
 449 
 450         float fx1 = (float)x1;
 451         float fy1 = (float)y1;
 452         float fx2 = (float)x2;
 453         float fy2 = (float)y2;
 454 
 455         // horiz: top left - top right
 456         ADD_LINE_XYC(fx1+HV_FF3, fy1+HV_FF1, fx2-1.0f+fudge2, fy1+HV_FF1,color);
 457         // horiz: bottom left - bottom right
 458         ADD_LINE_XYC(fx1+1.0f+HV_FF3, fy2+HV_FF1, fx2+fudge2, fy2+HV_FF1,color);
 459         // vert : top right - bottom right
 460         ADD_LINE_XYC(fx2+HV_FF1, fy1+HV_FF3, fx2+HV_FF1, fy2-1.0f+fudge2,color);
 461         // vert : top left - bottom left
 462         ADD_LINE_XYC(fx1+HV_FF1, fy1+1.0f+HV_FF3, fx1+HV_FF1, fy2+fudge2,color);
 463     }
 464     return res;
 465 }
 466 
 467 HRESULT D3DVertexCacher::FillRect(int x1, int y1, int x2, int y2)
 468 {
 469     HRESULT res;
 470     if (SUCCEEDED(res = EnsureCapacity(D3DPT_TRIANGLELIST, 2*3))) {
 471         float fx1 = (float)x1;
 472         float fy1 = (float)y1;
 473         float fx2 = (float)x2;
 474         float fy2 = (float)y2;
 475         ADD_TRIANGLE_XYUVC(fx1, fy1, fx2, fy1, fx1, fy2,
 476                            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
 477                            color);
 478         ADD_TRIANGLE_XYUVC(fx1, fy2, fx2, fy1, fx2, fy2,
 479                            0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
 480                            color);
 481     }
 482     return res;


< prev index next >