2 * Copyright (C) 2008-2009 Torch Mobile Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 typedef struct HBITMAP__
* HBITMAP
;
25 typedef struct HDC__
* HDC
;
27 typedef struct tagBITMAPINFO BITMAPINFO
;
36 bool allocationCanFail() const { return m_allocationCanFail
; }
37 void setAllocationCanFail(bool c
) { m_allocationCanFail
= c
; }
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
);
53 friend MemoryManager
* memoryManager();
55 bool m_allocationCanFail
;
58 MemoryManager
* memoryManager();
60 class MemoryAllocationCanFail
{
62 MemoryAllocationCanFail() : m_old(memoryManager()->allocationCanFail()) { memoryManager()->setAllocationCanFail(true); }
63 ~MemoryAllocationCanFail() { memoryManager()->setAllocationCanFail(m_old
); }
68 class MemoryAllocationCannotFail
{
70 MemoryAllocationCannotFail() : m_old(memoryManager()->allocationCanFail()) { memoryManager()->setAllocationCanFail(false); }
71 ~MemoryAllocationCannotFail() { memoryManager()->setAllocationCanFail(m_old
); }
77 using WTF::MemoryManager
;
78 using WTF::memoryManager
;
79 using WTF::MemoryAllocationCanFail
;
80 using WTF::MemoryAllocationCannotFail
;