| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#include <winbase.h> |
| 23 |
|
| 24 |
typedef struct HBITMAP__* HBITMAP; |
| 25 |
typedef struct HDC__* HDC; |
| 26 |
typedef void *HANDLE; |
| 27 |
typedef struct tagBITMAPINFO BITMAPINFO; |
| 28 |
|
| 29 |
namespace WTF { |
| 30 |
|
| 31 |
class MemoryManager { |
| 32 |
public: |
| 33 |
MemoryManager(); |
| 34 |
~MemoryManager(); |
| 35 |
|
| 36 |
bool allocationCanFail() const { return m_allocationCanFail; } |
| 37 |
void setAllocationCanFail(bool c) { m_allocationCanFail = c; } |
| 38 |
|
| 39 |
static HBITMAP createCompatibleBitmap(HDC hdc, int width, int height); |
| 40 |
static HBITMAP createDIBSection(const BITMAPINFO* pbmi, void** ppvBits); |
| 41 |
static void* m_malloc(size_t size); |
| 42 |
static void* m_calloc(size_t num, size_t size); |
| 43 |
static void* m_realloc(void* p, size_t size); |
| 44 |
static void m_free(void*); |
| 45 |
static bool resizeMemory(void* p, size_t newSize); |
| 46 |
static void* allocate64kBlock(); |
| 47 |
static void free64kBlock(void*); |
| 48 |
static bool onIdle(DWORD& timeLimitMs); |
| 49 |
static LPVOID virtualAlloc(LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect); |
| 50 |
static BOOL virtualFree(LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType); |
| 51 |
|
| 52 |
private: |
| 53 |
friend MemoryManager* memoryManager(); |
| 54 |
|
| 55 |
bool m_allocationCanFail; |
| 56 |
}; |
| 57 |
|
| 58 |
MemoryManager* memoryManager(); |
| 59 |
|
| 60 |
class MemoryAllocationCanFail { |
| 61 |
public: |
| 62 |
MemoryAllocationCanFail() : m_old(memoryManager()->allocationCanFail()) { memoryManager()->setAllocationCanFail(true); } |
| 63 |
~MemoryAllocationCanFail() { memoryManager()->setAllocationCanFail(m_old); } |
| 64 |
private: |
| 65 |
bool m_old; |
| 66 |
}; |
| 67 |
|
| 68 |
class MemoryAllocationCannotFail { |
| 69 |
public: |
| 70 |
MemoryAllocationCannotFail() : m_old(memoryManager()->allocationCanFail()) { memoryManager()->setAllocationCanFail(false); } |
| 71 |
~MemoryAllocationCannotFail() { memoryManager()->setAllocationCanFail(m_old); } |
| 72 |
private: |
| 73 |
bool m_old; |
| 74 |
}; |
| 75 |
} |
| 76 |
|
| 77 |
using WTF::MemoryManager; |
| 78 |
using WTF::memoryManager; |
| 79 |
using WTF::MemoryAllocationCanFail; |
| 80 |
using WTF::MemoryAllocationCannotFail; |