356 TRY; 357 358 JNI_CHECK_NULL_RETURN(intRasterData, "intRasterData argument"); 359 360 if (nW != ::GetSystemMetrics(SM_CXCURSOR) || 361 nH != ::GetSystemMetrics(SM_CYCURSOR)) { 362 JNU_ThrowArrayIndexOutOfBoundsException(env, 363 "bad width and/or height"); 364 return; 365 } 366 367 jsize length = env->GetArrayLength(andMask); 368 jbyte *andMaskPtr = new jbyte[length]; // safe because sizeof(jbyte)==1 369 env->GetByteArrayRegion(andMask, 0, length, andMaskPtr); 370 371 HBITMAP hMask = ::CreateBitmap(nW, nH, 1, 1, (BYTE *)andMaskPtr); 372 ::GdiFlush(); 373 374 int *cols = SAFE_SIZE_NEW_ARRAY2(int, nW, nH); 375 376 jint *intRasterDataPtr = NULL; 377 HBITMAP hColor = NULL; 378 try { 379 intRasterDataPtr = 380 (jint *)env->GetPrimitiveArrayCritical(intRasterData, 0); 381 hColor = create_BMP(NULL, (int *)intRasterDataPtr, nSS, nW, nH); 382 memcpy(cols, intRasterDataPtr, nW*nH*sizeof(int)); 383 } catch (...) { 384 if (intRasterDataPtr != NULL) { 385 env->ReleasePrimitiveArrayCritical(intRasterData, 386 intRasterDataPtr, 0); 387 } 388 throw; 389 } 390 391 env->ReleasePrimitiveArrayCritical(intRasterData, intRasterDataPtr, 0); 392 intRasterDataPtr = NULL; 393 394 HCURSOR hCursor = NULL; 395 396 if (hMask && hColor) { 397 ICONINFO icnInfo; 398 memset(&icnInfo, 0, sizeof(ICONINFO)); 399 icnInfo.hbmMask = hMask; 400 icnInfo.hbmColor = hColor; 401 icnInfo.fIcon = FALSE; 402 icnInfo.xHotspot = xHotSpot; 403 icnInfo.yHotspot = yHotSpot; 404 405 hCursor = ::CreateIconIndirect(&icnInfo); 406 407 destroy_BMP(hColor); 408 destroy_BMP(hMask); 409 } 410 411 DASSERT(hCursor); 412 | 356 TRY; 357 358 JNI_CHECK_NULL_RETURN(intRasterData, "intRasterData argument"); 359 360 if (nW != ::GetSystemMetrics(SM_CXCURSOR) || 361 nH != ::GetSystemMetrics(SM_CYCURSOR)) { 362 JNU_ThrowArrayIndexOutOfBoundsException(env, 363 "bad width and/or height"); 364 return; 365 } 366 367 jsize length = env->GetArrayLength(andMask); 368 jbyte *andMaskPtr = new jbyte[length]; // safe because sizeof(jbyte)==1 369 env->GetByteArrayRegion(andMask, 0, length, andMaskPtr); 370 371 HBITMAP hMask = ::CreateBitmap(nW, nH, 1, 1, (BYTE *)andMaskPtr); 372 ::GdiFlush(); 373 374 int *cols = SAFE_SIZE_NEW_ARRAY2(int, nW, nH); 375 376 /* Copy the raster data because GDI may fail on some Java heap 377 * allocated memory. 378 */ 379 length = env->GetArrayLength(intRasterData); 380 jint *intRasterDataPtr = new jint[length]; 381 HBITMAP hColor = NULL; 382 try { 383 env->GetIntArrayRegion(intRasterData, 0, length, intRasterDataPtr); 384 hColor = create_BMP(NULL, (int *)intRasterDataPtr, nSS, nW, nH); 385 memcpy(cols, intRasterDataPtr, nW*nH*sizeof(int)); 386 } catch (...) { 387 delete[] intRasterDataPtr; 388 throw; 389 } 390 delete[] intRasterDataPtr; 391 392 HCURSOR hCursor = NULL; 393 394 if (hMask && hColor) { 395 ICONINFO icnInfo; 396 memset(&icnInfo, 0, sizeof(ICONINFO)); 397 icnInfo.hbmMask = hMask; 398 icnInfo.hbmColor = hColor; 399 icnInfo.fIcon = FALSE; 400 icnInfo.xHotspot = xHotSpot; 401 icnInfo.yHotspot = yHotSpot; 402 403 hCursor = ::CreateIconIndirect(&icnInfo); 404 405 destroy_BMP(hColor); 406 destroy_BMP(hMask); 407 } 408 409 DASSERT(hCursor); 410 |