-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCGImageCache.cpp
123 lines (93 loc) · 2.41 KB
/
CGImageCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// CGImageCache.cpp
//
// CGImageCache Class
// Copyright (c) 2015 by Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
#include "PixelMacros.h"
CGImageCache::~CGImageCache (void)
// CGImageCache destructor
{
int i;
for (i = 0; i < m_Cache8.GetCount(); i++)
delete m_Cache8[i];
for (i = 0; i < m_Cache32.GetCount(); i++)
delete m_Cache32[i];
}
CG8bitImage *CGImageCache::Alloc8 (void)
// Alloc8
//
// Allocated a new image and returns it. We still maintain ownership of the
// object, however. The caller MUST NOT free the pointer (though they are free
// to call Free or Sweep.
{
CG8bitImage *pNewImage = new CG8bitImage;
m_Cache8.Insert(pNewImage);
return pNewImage;
}
CG32bitImage *CGImageCache::Alloc32 (void)
// Alloc32
//
// Allocated a new image and returns it. We still maintain ownership of the
// object, however. The caller MUST NOT free the pointer (though they are free
// to call Free or Sweep.
{
CG32bitImage *pNewImage = new CG32bitImage;
m_Cache32.Insert(pNewImage);
return pNewImage;
}
void CGImageCache::ClearMarks (void)
// ClearMarks
//
// Clears all marks
{
int i;
for (i = 0; i < m_Cache8.GetCount(); i++)
m_Cache8[i]->SetMarked(false);
for (i = 0; i < m_Cache32.GetCount(); i++)
m_Cache32[i]->SetMarked(false);
}
void CGImageCache::Free8 (CG8bitImage *pImage)
// Free8
//
// Frees a given image previously created with Alloc. This should only be
// called when the caller can guarantee that no one else holds the pointer.
{
int i;
for (i = 0; i < m_Cache8.GetCount(); i++)
if (m_Cache8[i] == pImage)
{
m_Cache8.Delete(i);
delete pImage;
break;
}
}
void CGImageCache::Free32 (CG32bitImage *pImage)
// Free32
//
// Frees a given image previously created with Alloc. This should only be
// called when the caller can guarantee that no one else holds the pointer.
{
int i;
for (i = 0; i < m_Cache32.GetCount(); i++)
if (m_Cache32[i] == pImage)
{
m_Cache32.Delete(i);
delete pImage;
break;
}
}
void CGImageCache::Sweep (void)
// Sweep
//
// Releases memory from all images that are not marked. But we DO NOT delete
// the image. Callers may recreate the image using the same pointer returned by
// Alloc.
{
int i;
for (i = 0; i < m_Cache8.GetCount(); i++)
if (!m_Cache8[i]->IsMarked())
m_Cache8[i]->CleanUp();
for (i = 0; i < m_Cache32.GetCount(); i++)
if (!m_Cache32[i]->IsMarked())
m_Cache32[i]->CleanUp();
}