Reactos

[WIN32SS] Remove NATIVE_REACTX check - reenable Oleg's code (#8554)

* [REACTX] Simple Non-AGP ddraw allocator
* [WIN32SS] remove NATIVE_REACTX check - reenable oleg's code
JIRA issue: CORE-19142

Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>

authored by

Justin Miller
Hermès BÉLUSCA - MAÏTO
and committed by
GitHub
c990b725 a08d639b

+257 -30
-4
win32ss/CMakeLists.txt
··· 4 4 # Give WIN32 subsystem its own project. 5 5 PROJECT(WIN32SS) 6 6 7 - if (NATIVE_REACTX) 8 - add_definitions(-DNATIVE_REACTX) 9 - endif() 10 - 11 7 add_subdirectory(drivers) 12 8 13 9 if(USE_DIBLIB)
-16
win32ss/gdi/eng/pdevobj.c
··· 337 337 return ppdev->pSurface; 338 338 } 339 339 340 - #ifdef NATIVE_REACTX 341 340 BOOL 342 341 PDEVOBJ_bEnableDirectDraw( 343 342 _Inout_ PPDEVOBJ ppdev) ··· 386 385 TRACE("DxDdDynamicModeChange(ppdev %p, ppdev2 %p)\n", ppdev, ppdev2); 387 386 pfnDdDynamicModeChange((HDEV)ppdev, (HDEV)ppdev2, 0); 388 387 } 389 - #endif 390 388 391 389 VOID 392 390 PDEVOBJ_vEnableDisplay( ··· 417 415 if (ppdev->flFlags & PDEV_DISABLED) 418 416 return TRUE; 419 417 420 - #ifdef NATIVE_REACTX 421 418 PDEVOBJ_vSuspendDirectDraw(ppdev); 422 - #endif 423 419 424 420 TRACE("DrvAssertMode(dhpdev %p, FALSE)\n", ppdev->dhpdev); 425 421 assertVal = ppdev->pfn.AssertMode(ppdev->dhpdev, FALSE); ··· 604 600 return NULL; 605 601 } 606 602 607 - #ifdef NATIVE_REACTX 608 603 /* Enable DirectDraw */ 609 604 if (!PDEVOBJ_bEnableDirectDraw(ppdev)) 610 605 { ··· 613 608 EngUnloadImage(pldev); 614 609 return NULL; 615 610 } 616 - #endif 617 611 618 612 /* Remove some acceleration capabilities from driver */ 619 613 PDEVOBJ_vFilterDriverHooks(ppdev); ··· 698 692 ppdev->pfn.CompletePDEV(ppdev->dhpdev, (HDEV)ppdev); 699 693 ppdev2->pfn.CompletePDEV(ppdev2->dhpdev, (HDEV)ppdev2); 700 694 701 - #ifdef NATIVE_REACTX 702 695 /* Switch DirectDraw mode */ 703 696 PDEVOBJ_vSwitchDirectDraw(ppdev, ppdev2); 704 - #endif 705 697 706 698 return TRUE; 707 699 } ··· 732 724 if (!PDEVOBJ_bDisableDisplay(ppdev)) 733 725 { 734 726 DPRINT1("PDEVOBJ_bDisableDisplay() failed\n"); 735 - #ifdef NATIVE_REACTX 736 727 /* Resume DirectDraw in case of failure */ 737 728 PDEVOBJ_vResumeDirectDraw(ppdev); 738 - #endif 739 729 goto leave; 740 730 } 741 731 ··· 756 746 goto leave2; 757 747 } 758 748 759 - #ifdef NATIVE_REACTX 760 749 /* 4. Temporarily suspend DirectDraw for mode change */ 761 750 PDEVOBJ_vSuspendDirectDraw(ppdev); 762 751 PDEVOBJ_vSuspendDirectDraw(ppdevTmp); 763 - #endif 764 752 765 753 /* 5. Switch the PDEVs */ 766 754 if (!PDEVOBJ_bDynamicModeChange(ppdev, ppdevTmp)) ··· 770 758 goto leave2; 771 759 } 772 760 773 - #ifdef NATIVE_REACTX 774 761 /* 6. Resume DirectDraw */ 775 762 PDEVOBJ_vResumeDirectDraw(ppdev); 776 763 PDEVOBJ_vResumeDirectDraw(ppdevTmp); 777 - #endif 778 764 779 765 /* Release temp PDEV */ 780 766 PDEVOBJ_vRelease(ppdevTmp); 781 767 782 - #ifdef NATIVE_REACTX 783 768 /* Re-initialize DirectDraw data */ 784 769 ppdev->pEDDgpl->hDev = (HDEV)ppdev; 785 770 ppdev->pEDDgpl->dhpdev = ppdev->dhpdev; 786 - #endif 787 771 788 772 /* Update primary display capabilities */ 789 773 if (ppdev == gpmdev->ppdevGlobal)
+1
win32ss/reactx/dxg/CMakeLists.txt
··· 8 8 dd.c 9 9 ddraw.c 10 10 ddsurf.c 11 + dxgallocator.c 11 12 eng.c 12 13 historic.c 13 14 dxg_int.h)
+43
win32ss/reactx/dxg/ddraw.c
··· 189 189 190 190 intDdGetAllDriverInfo(peDdGl); 191 191 192 + /* 193 + * Initialize video memory heaps for surface allocation. 194 + * This is done specifically for vmware, nothing else is likely to use it yet. 195 + * But it's done well enough that native ddraw.dll seems happy. 196 + */ 197 + if (peDdGl->pvmList && peDdGl->dwNumHeaps > 0) 198 + { 199 + VIDEOMEMORY *VidMemEntry; 200 + LPVMEMHEAP HeapStruct; 201 + DWORD HeapIndex; 202 + DWORD DisplayPitch = peDdGl->ddHalInfo.vmiData.lDisplayPitch; 203 + 204 + for (HeapIndex = 0, VidMemEntry = peDdGl->pvmList; 205 + HeapIndex < peDdGl->dwNumHeaps; 206 + HeapIndex++, VidMemEntry++) 207 + { 208 + if (VidMemEntry->dwFlags & (VIDMEM_ISHEAP | VIDMEM_HEAPDISABLED)) 209 + continue; 210 + 211 + HeapStruct = (LPVMEMHEAP)EngAllocMem(FL_ZERO_MEMORY, sizeof(*HeapStruct), TAG_GDDV); 212 + if (!HeapStruct) 213 + { 214 + VidMemEntry->dwFlags |= VIDMEM_HEAPDISABLED; 215 + continue; 216 + } 217 + 218 + if (VidMemEntry->dwFlags & VIDMEM_ISLINEAR) 219 + { 220 + HeapStruct->dwFlags = VMEMHEAP_LINEAR; 221 + HeapStruct->dwTotalSize = VidMemEntry->fpEnd - VidMemEntry->fpStart + 1; 222 + } 223 + else 224 + { 225 + HeapStruct->dwFlags = VMEMHEAP_RECTANGULAR; 226 + HeapStruct->stride = DisplayPitch ? DisplayPitch : VidMemEntry->dwWidth; 227 + HeapStruct->dwTotalSize = HeapStruct->stride * VidMemEntry->dwHeight; 228 + } 229 + 230 + VidMemEntry->lpHeap = HeapStruct; 231 + VidMemEntry->dwFlags |= VIDMEM_ISHEAP; 232 + } 233 + } 234 + 192 235 // enable DirectDraw acceleration 193 236 peDdGl->fl |= 1; 194 237 }
+6 -10
win32ss/reactx/dxg/dxg_driver.h
··· 631 631 return 0; 632 632 } 633 633 634 - DWORD 634 + FLATPTR 635 635 NTAPI 636 636 DxDdHeapVidMemAllocAligned( 637 - PVOID p1, 638 - PVOID p2, 639 - PVOID p3, 640 - PVOID p4, 641 - PVOID p5) 642 - { 643 - TRACE(); 644 - return 0; 645 - } 637 + LPVIDMEM DdrawVidMem, 638 + DWORD Width, 639 + DWORD Height, 640 + LPSURFACEALIGNMENT Alignment, 641 + LPDWORD ResolvedPitch); 646 642 647 643 DWORD 648 644 NTAPI
+207
win32ss/reactx/dxg/dxgallocator.c
··· 1 + /* 2 + * PROJECT: ReactX Graphics Legacy Kernel 3 + * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 + * PURPOSE: DirectDraw video memory allocator 5 + * COPYRIGHT: Copyright 2026 Justin Miller <justin.miller@reactos.org> 6 + */ 7 + 8 + #include <dxg_int.h> 9 + 10 + FLATPTR 11 + WINAPI 12 + DdrawMemAlloc( 13 + _In_ LPVMEMHEAP pvmh, 14 + _In_ DWORD Width, 15 + _In_ DWORD Height, 16 + _Out_opt_ LPDWORD AllocSize, 17 + _In_opt_ LPSURFACEALIGNMENT Alignment, 18 + _Out_opt_ LPDWORD ResolvedPitch) 19 + { 20 + FLATPTR MemPtr; 21 + DWORD RequiredBytes; 22 + DWORD CurrentPos; 23 + 24 + if (!pvmh) 25 + { 26 + if (AllocSize) 27 + *AllocSize = 0; 28 + return (FLATPTR)NULL; 29 + } 30 + 31 + /* Retrieve memory boundaries from temporary storage */ 32 + FLATPTR MemBase = (FLATPTR)pvmh->freeList; 33 + FLATPTR MemLimit = (FLATPTR)pvmh->allocList; 34 + 35 + if (!MemBase || !MemLimit || MemLimit <= MemBase) 36 + { 37 + DbgPrint("No valid video memory range\n"); 38 + if (AllocSize) 39 + *AllocSize = 0; 40 + return (FLATPTR)NULL; 41 + } 42 + 43 + CurrentPos = pvmh->dwCommitedSize; 44 + CurrentPos = ALIGN_UP(CurrentPos, sizeof(ULONG)); 45 + 46 + if (pvmh->dwFlags & VMEMHEAP_LINEAR) 47 + { 48 + /* Handle linear memory allocation */ 49 + RequiredBytes = Width; 50 + } 51 + else 52 + { 53 + /* Handle rectangular memory allocation */ 54 + Width = pvmh->stride ? pvmh->stride : Width; 55 + RequiredBytes = Width * Height; 56 + } 57 + MemPtr = MemBase + CurrentPos; 58 + 59 + if (MemPtr + RequiredBytes > MemLimit) 60 + { 61 + DbgPrint("Out of memory\n"); 62 + if (AllocSize) 63 + *AllocSize = 0; 64 + return (FLATPTR)NULL; 65 + } 66 + 67 + pvmh->dwCommitedSize = CurrentPos + RequiredBytes; 68 + 69 + if (ResolvedPitch) 70 + *ResolvedPitch = (LONG)Width; 71 + if (AllocSize) 72 + *AllocSize = RequiredBytes; 73 + 74 + return MemPtr; 75 + } 76 + 77 + /* 78 + * Allocates memory from a DirectDraw video memory heap 79 + */ 80 + FLATPTR 81 + WINAPI 82 + DxDdHeapDdrawMemAlloc( 83 + _In_ LPVIDMEM DdrawVidMem, 84 + _In_ DWORD Width, 85 + _In_ DWORD Height, 86 + _In_opt_ LPSURFACEALIGNMENT Alignment, 87 + _Out_opt_ LPDWORD ResolvedPitch, 88 + _Out_ PDWORD AllocSize) 89 + { 90 + FLATPTR Result; 91 + DWORD ActualSize = 0; 92 + 93 + if (!DdrawVidMem || !DdrawVidMem->lpHeap) 94 + { 95 + if (AllocSize) 96 + *AllocSize = 0; 97 + return (FLATPTR)NULL; 98 + } 99 + 100 + if ((DdrawVidMem->dwFlags & VIDMEM_ISNONLOCAL) && 101 + !DdrawVidMem->lpHeap->pvPhysRsrv) 102 + { 103 + if (AllocSize) 104 + *AllocSize = 0; 105 + return (FLATPTR)NULL; 106 + } 107 + 108 + /* Determine memory region boundaries */ 109 + FLATPTR MemBegin = DdrawVidMem->fpStart; 110 + FLATPTR MemEnd; 111 + 112 + if (DdrawVidMem->dwFlags & VIDMEM_ISLINEAR) 113 + { 114 + MemEnd = DdrawVidMem->fpEnd; 115 + } 116 + else if (DdrawVidMem->dwFlags & VIDMEM_ISRECTANGULAR) 117 + { 118 + MemEnd = MemBegin + (DdrawVidMem->dwWidth * DdrawVidMem->dwHeight); 119 + } 120 + else 121 + { 122 + MemEnd = DdrawVidMem->fpEnd; 123 + } 124 + 125 + if (!MemBegin) 126 + { 127 + if (AllocSize) 128 + *AllocSize = 0; 129 + return (FLATPTR)NULL; 130 + } 131 + 132 + /* Fallback to heap size if end address is invalid */ 133 + if (!MemEnd || MemEnd <= MemBegin) 134 + { 135 + if (DdrawVidMem->lpHeap && DdrawVidMem->lpHeap->dwTotalSize > 0) 136 + { 137 + MemEnd = MemBegin + DdrawVidMem->lpHeap->dwTotalSize; 138 + } 139 + else 140 + { 141 + if (AllocSize) 142 + *AllocSize = 0; 143 + return (FLATPTR)NULL; 144 + } 145 + } 146 + 147 + /* 148 + * In DxgKrnl we are given APIs to allocate ranges for DMA. 149 + * In Vista this is used for trying to deal with ddraw on a dedicated surface 150 + * outside of DWMs... control. 151 + * 152 + * In legacy DirectX these ranges are passed from the driver as valid areas to do 153 + * allocation from, depending on this dxg driver to do the tracking. 154 + * We don't care much to replicate ALL of this yet. 155 + */ 156 + FLATPTR SavedBegin = (FLATPTR)DdrawVidMem->lpHeap->freeList; 157 + FLATPTR SavedEnd = (FLATPTR)DdrawVidMem->lpHeap->allocList; 158 + DdrawVidMem->lpHeap->freeList = (LPVOID)MemBegin; 159 + DdrawVidMem->lpHeap->allocList = (LPVOID)MemEnd; 160 + 161 + Result = DdrawMemAlloc(DdrawVidMem->lpHeap, Width, Height, &ActualSize, 162 + Alignment, ResolvedPitch); 163 + 164 + if (!Result) 165 + { 166 + if (AllocSize) 167 + *AllocSize = 0; 168 + return Result; 169 + } 170 + 171 + DdrawVidMem->lpHeap->freeList = (LPVOID)SavedBegin; 172 + DdrawVidMem->lpHeap->allocList = (LPVOID)SavedEnd; 173 + 174 + if (AllocSize) 175 + *AllocSize = ActualSize; 176 + 177 + return Result; 178 + } 179 + 180 + FLATPTR 181 + NTAPI 182 + DxDdHeapVidMemAllocAligned( 183 + LPVIDMEM DdrawVidMem, 184 + DWORD Width, 185 + DWORD Height, 186 + LPSURFACEALIGNMENT Alignment, 187 + LPDWORD ResolvedPitch) 188 + { 189 + DWORD SizeOut = 0; 190 + 191 + if (!DdrawVidMem || !DdrawVidMem->lpHeap || 192 + (DdrawVidMem->dwFlags & VIDMEM_HEAPDISABLED)) 193 + { 194 + return (FLATPTR)NULL; 195 + } 196 + 197 + if (DdrawVidMem->dwFlags & VIDMEM_ISNONLOCAL) 198 + { 199 + if (!DdrawVidMem->lpHeap->pvPhysRsrv) 200 + return (FLATPTR)NULL; 201 + DbgPrint("AGP memory not supported\n"); 202 + return (FLATPTR)NULL; 203 + } 204 + 205 + return DxDdHeapDdrawMemAlloc(DdrawVidMem, Width, Height, 206 + Alignment, ResolvedPitch, &SizeOut); 207 + }