Repository navigation
Expand file tree
/
Copy pathrender_thread_info.cpp
More file actions
132 lines (110 loc) · 3.35 KB
/
Copy pathrender_thread_info.cpp
File metadata and controls
132 lines (110 loc) · 3.35 KB
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
124
125
126
127
128
129
130
131
132
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "render_thread_info.h"
#include "gfxstream/synchronization/Lock.h"
#include "frame_buffer.h"
#include <unordered_map>
#include <unordered_set>
namespace gfxstream {
namespace host {
using gfxstream::base::AutoLock;
using gfxstream::Stream;
using gfxstream::base::Lock;
static thread_local RenderThreadInfo* s_threadInfoPtr;
struct RenderThreadRegistry {
Lock lock;
std::unordered_set<RenderThreadInfo*> threadInfos;
};
static RenderThreadRegistry sRegistry;
RenderThreadInfo::RenderThreadInfo() {
s_threadInfoPtr = this;
AutoLock lock(sRegistry.lock);
sRegistry.threadInfos.insert(this);
}
RenderThreadInfo::~RenderThreadInfo() {
s_threadInfoPtr = nullptr;
AutoLock lock(sRegistry.lock);
sRegistry.threadInfos.erase(this);
}
RenderThreadInfo* RenderThreadInfo::get() {
return s_threadInfoPtr;
}
// Loop over all active render thread infos. Takes the global render thread info lock.
void RenderThreadInfo::forAllRenderThreadInfos(std::function<void(RenderThreadInfo*)> f) {
AutoLock lock(sRegistry.lock);
for (auto info: sRegistry.threadInfos) {
f(info);
}
}
#if GFXSTREAM_ENABLE_HOST_GLES
void RenderThreadInfo::initGl(gl::EmulationGl* emulationGl) { m_glInfo.emplace(emulationGl); }
#endif
void RenderThreadInfo::onSave(Stream* stream) {
// TODO(b/309858017): remove if when ready to bump snapshot version
if (FrameBuffer::getFB()->getFeatures().VulkanSnapshots.enabled()) {
stream->putBe64(m_puid);
}
#if GFXSTREAM_ENABLE_HOST_GLES
if (m_glInfo) {
stream->putBe32(1);
m_glInfo->onSave(stream);
} else {
stream->putBe32(0);
}
#endif
if (m_vkInfo) {
stream->putBe32(1);
m_vkInfo->onSave(stream);
} else {
stream->putBe32(0);
}
}
bool RenderThreadInfo::onLoad(Stream* stream) {
// TODO(b/309858017): remove if when ready to bump snapshot version
if (FrameBuffer::getFB()->getFeatures().VulkanSnapshots.enabled()) {
m_puid = stream->getBe64();
}
#if GFXSTREAM_ENABLE_HOST_GLES
const bool loadGlInfo = stream->getBe32() == 1;
if (loadGlInfo) {
if (!m_glInfo) {
m_glInfo.emplace(FrameBuffer::getFB()->getEmulationGl());
}
if (!m_glInfo->onLoad(stream)) {
return false;
}
}
#endif
const bool loadVkInfo = stream->getBe32() == 1;
if (loadVkInfo) {
if (!m_vkInfo) {
m_vkInfo.emplace();
}
if (!m_vkInfo->onLoad(stream)) {
return false;
}
}
return true;
}
void RenderThreadInfo::postLoadRefreshCurrentContextSurfacePtrs() {
#if GFXSTREAM_ENABLE_HOST_GLES
if (m_glInfo) {
m_glInfo->postLoadRefreshCurrentContextSurfacePtrs();
}
#endif
}
} // namespace host
} // namespace gfxstream