-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathgl_lost_manager.cpp
76 lines (66 loc) · 1.93 KB
/
gl_lost_manager.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
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
#include "gfx/gl_lost_manager.h"
std::vector<GfxResourceHolder *> *holders;
static bool inLost;
void register_gl_resource_holder(GfxResourceHolder *holder) {
if (inLost) {
FLOG("BAD: Should not call register_gl_resource_holder from lost path");
return;
}
if (holders) {
holders->push_back(holder);
} else {
WLOG("GL resource holder not initialized, cannot register resource");
}
}
void unregister_gl_resource_holder(GfxResourceHolder *holder) {
if (inLost) {
FLOG("BAD: Should not call unregister_gl_resource_holder from lost path");
return;
}
if (holders) {
for (size_t i = 0; i < holders->size(); i++) {
if ((*holders)[i] == holder) {
holders->erase(holders->begin() + i);
return;
}
}
WLOG("unregister_gl_resource_holder: Resource not registered");
} else {
WLOG("GL resource holder not initialized or already shutdown, cannot unregister resource");
}
}
void gl_lost() {
inLost = true;
if (!holders) {
WLOG("GL resource holder not initialized, cannot process lost request");
inLost = false;
return;
}
// TODO: We should really do this when we get the context back, not during gl_lost...
ILOG("gl_lost() restoring %i items:", (int)holders->size());
for (size_t i = 0; i < holders->size(); i++) {
ILOG("GLLost(%i / %i, %p)", (int)(i + 1), (int) holders->size(), (*holders)[i]);
(*holders)[i]->GLLost();
}
ILOG("gl_lost() completed restoring %i items:", (int)holders->size());
inLost = false;
}
void gl_lost_manager_init() {
if (holders) {
FLOG("Double GL lost manager init");
// Dead here (FLOG), no need to delete holders
}
holders = new std::vector<GfxResourceHolder *>();
}
void gl_lost_manager_shutdown() {
if (!holders) {
FLOG("Lost manager already shutdown");
} else if (holders->size() > 0) {
ELOG("Lost manager shutdown with %i objects still registered", (int)holders->size());
}
delete holders;
holders = 0;
}