VOID FASTCALL co_IntDrawCaret(PWND pWnd, PTHRDCARETINFO CaretInfo) { HDC hdc, hdcMem; HBITMAP hbmOld; BOOL bDone = FALSE; hdc = UserGetDCEx(pWnd, 0, DCX_USESTYLE | DCX_WINDOW); if (!hdc) { ERR("GetDC failed\n"); return; } if (pWnd->hrgnUpdate) { NtGdiSaveDC(hdc); } if(CaretInfo->Bitmap && NtGdiGetBitmapDimension(CaretInfo->Bitmap, &CaretInfo->Size)) { hdcMem = NtGdiCreateCompatibleDC(hdc); if (hdcMem) { hbmOld = NtGdiSelectBitmap(hdcMem, CaretInfo->Bitmap); bDone = NtGdiBitBlt(hdc, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, hdcMem, 0, 0, SRCINVERT, 0, 0); NtGdiSelectBitmap(hdcMem, hbmOld); GreDeleteObject(hdcMem); } } if (!bDone) { NtGdiPatBlt(hdc, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, DSTINVERT); } if (pWnd->hrgnUpdate) { NtGdiRestoreDC(hdc, -1); } UserReleaseDC(pWnd, hdc, FALSE); }
INT Test_NtGdiCreateCompatibleDC(PTESTINFO pti) { HDC hDC; HGDIOBJ hObj; /* Test if aa NULL DC is accepted */ hDC = NtGdiCreateCompatibleDC(NULL); TEST(hDC != NULL); /* We select a nwe palette. Note: SelectObject doesn't work with palettes! */ hObj = SelectPalette(hDC, GetStockObject(DEFAULT_PALETTE), 0); /* The old palette should be GetStockObject(DEFAULT_PALETTE) */ TEST(hObj == GetStockObject(DEFAULT_PALETTE)); /* The default bitmap should be GetStockObject(21) */ hObj = SelectObject(hDC, GetStockObject(21)); TEST(hObj == GetStockObject(21)); /* The default pen should be GetStockObject(BLACK_PEN) */ hObj = SelectObject(hDC, GetStockObject(WHITE_PEN)); TEST(hObj == GetStockObject(BLACK_PEN)); TEST(NtGdiDeleteObjectApp(hDC) != 0); return APISTATUS_NORMAL; }
BOOL FASTCALL co_IntInitializeDesktopGraphics(VOID) { TEXTMETRICW tmw; UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY"); PDESKTOP pdesk; ScreenDeviceContext = IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE); if (NULL == ScreenDeviceContext) { IntDestroyPrimarySurface(); return FALSE; } GreSetDCOwner(ScreenDeviceContext, GDI_OBJ_HMGR_PUBLIC); if (! IntCreatePrimarySurface()) { return FALSE; } hSystemBM = NtGdiCreateCompatibleDC(ScreenDeviceContext); NtGdiSelectFont(hSystemBM, NtGdiGetStockObject(SYSTEM_FONT)); GreSetDCOwner(hSystemBM, GDI_OBJ_HMGR_PUBLIC); /* Update the SERVERINFO */ gpsi->aiSysMet[SM_CXSCREEN] = gppdevPrimary->gdiinfo.ulHorzRes; gpsi->aiSysMet[SM_CYSCREEN] = gppdevPrimary->gdiinfo.ulVertRes; gpsi->Planes = NtGdiGetDeviceCaps(ScreenDeviceContext, PLANES); gpsi->BitsPixel = NtGdiGetDeviceCaps(ScreenDeviceContext, BITSPIXEL); gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel; gpsi->dmLogPixels = NtGdiGetDeviceCaps(ScreenDeviceContext, LOGPIXELSY); if (NtGdiGetDeviceCaps(ScreenDeviceContext, RASTERCAPS) & RC_PALETTE) { gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY; } else gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY; // Font is realized and this dc was previously set to internal DC_ATTR. gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar); gpsi->tmSysFont = tmw; /* Put the pointer in the center of the screen */ gpsi->ptCursor.x = gpsi->aiSysMet[SM_CXSCREEN] / 2; gpsi->ptCursor.y = gpsi->aiSysMet[SM_CYSCREEN] / 2; /* Attach monitor */ UserAttachMonitor((HDEV)gppdevPrimary); /* Setup the cursor */ co_IntLoadDefaultCursors(); /* Show the desktop */ pdesk = IntGetActiveDesktop(); ASSERT(pdesk); co_IntShowDesktop(pdesk, gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN], TRUE); return TRUE; }
/* * @implemented */ HDC WINAPI CreateCompatibleDC( _In_ HDC hdc) { HDC hdcNew; // PDC_ATTR pdcattr; hdcNew = NtGdiCreateCompatibleDC(hdc); #if 0 if ( hdc && hdcNew) { if (GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID*)&pdcattr)) { if (pdcattr->pvLIcm) IcmCompatibleDC(hdcNew, hdc, pdcattr); } } #endif return hdcNew; }
INT Test_NtGdiBitBlt(PTESTINFO pti) { BOOL bRet; HDC hdc1, hdc2; HBITMAP hbmp1, hOldBmp1, hbmp2, hOldBmp2; DWORD bytes1[4] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff}; DWORD bytes2[4] = {0x00000000, 0x0000000, 0x0000000, 0x00000000}; /* Test NULL dc */ SetLastError(ERROR_SUCCESS); bRet = NtGdiBitBlt((HDC)0, 0, 0, 10, 10, (HDC)0, 10, 10, SRCCOPY, 0, 0); TEST(bRet == FALSE); TEST(GetLastError() == ERROR_SUCCESS); /* Test invalid dc */ SetLastError(ERROR_SUCCESS); bRet = NtGdiBitBlt((HDC)0x123456, 0, 0, 10, 10, (HDC)0x123456, 10, 10, SRCCOPY, 0, 0); TEST(bRet == FALSE); TEST(GetLastError() == ERROR_SUCCESS); hdc1 = NtGdiCreateCompatibleDC(0); TEST(hdc1 != NULL); hdc2 = NtGdiCreateCompatibleDC(0); TEST(hdc2 != NULL); hbmp1 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes1 ); TEST(hbmp1 != NULL); hOldBmp1 = SelectObject(hdc1, hbmp1); TESTX(NtGdiGetPixel(hdc1, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc1, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc1, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc1, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); hbmp2 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes2 ); TEST(hbmp2 != NULL); hOldBmp2 = SelectObject(hdc2, hbmp2); bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 1, 1, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); NtGdiSetPixel(hdc2, 0, 0, 0x00000000); bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00ffffff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); NtGdiSetPixel(hdc2, 0, 0, 0x00000000); bRet = NtGdiBitBlt(hdc2, 2, 2, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); NtGdiSetPixel(hdc2, 0, 0, 0x00000000); NtGdiSetPixel(hdc2, 1, 0, 0x00000000); NtGdiSetPixel(hdc2, 0, 1, 0x00000000); NtGdiSetPixel(hdc2, 1, 1, 0x00000000); bRet = NtGdiBitBlt(hdc2, 0, 0, 2, 2, hdc1, 0, 0, SRCCOPY, 0, 0); TEST(bRet == TRUE); TEST(GetLastError() == ERROR_SUCCESS); TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0)); TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1)); TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0)); TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1)); SelectObject(hdc2, hOldBmp2); SelectObject(hdc1, hOldBmp1); DeleteObject(hbmp2); DeleteObject(hbmp1); DeleteDC(hdc1); DeleteDC(hdc2); return APISTATUS_NORMAL; }