Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/util/frame_capture_test_utils.h
1693 views
1
//
2
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// frame_capture_test_utils:
7
// Helper functions for capture and replay of traces.
8
//
9
10
#ifndef UTIL_FRAME_CAPTURE_TEST_UTILS_H_
11
#define UTIL_FRAME_CAPTURE_TEST_UTILS_H_
12
13
#include <iostream>
14
#include <memory>
15
#include <sstream>
16
#include <type_traits>
17
#include <vector>
18
19
#include "common/angleutils.h"
20
#include "common/system_utils.h"
21
22
#define USE_SYSTEM_ZLIB
23
#include "compression_utils_portable.h"
24
25
#define ANGLE_MACRO_STRINGIZE_AUX(a) #a
26
#define ANGLE_MACRO_STRINGIZE(a) ANGLE_MACRO_STRINGIZE_AUX(a)
27
#define ANGLE_MACRO_CONCAT_AUX(a, b) a##b
28
#define ANGLE_MACRO_CONCAT(a, b) ANGLE_MACRO_CONCAT_AUX(a, b)
29
30
namespace angle
31
{
32
33
inline uint8_t *DecompressBinaryData(const std::vector<uint8_t> &compressedData)
34
{
35
uint32_t uncompressedSize =
36
zlib_internal::GetGzipUncompressedSize(compressedData.data(), compressedData.size());
37
38
std::unique_ptr<uint8_t[]> uncompressedData(new uint8_t[uncompressedSize]);
39
uLong destLen = uncompressedSize;
40
int zResult =
41
zlib_internal::GzipUncompressHelper(uncompressedData.get(), &destLen, compressedData.data(),
42
static_cast<uLong>(compressedData.size()));
43
44
if (zResult != Z_OK)
45
{
46
std::cerr << "Failure to decompressed binary data: " << zResult << "\n";
47
return nullptr;
48
}
49
50
return uncompressedData.release();
51
}
52
53
using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &);
54
using ValidateSerializedStateCallback = void (*)(const char *, const char *, uint32_t);
55
56
using SetBinaryDataDecompressCallbackFunc = void (*)(DecompressCallback);
57
using SetBinaryDataDirFunc = void (*)(const char *);
58
using SetupReplayFunc = void (*)();
59
using ReplayFrameFunc = void (*)(uint32_t);
60
using ResetReplayFunc = void (*)();
61
using FinishReplayFunc = void (*)();
62
using GetSerializedContextStateFunc = const char *(*)(uint32_t);
63
using SetValidateSerializedStateCallbackFunc = void (*)(ValidateSerializedStateCallback);
64
65
class TraceLibrary
66
{
67
public:
68
TraceLibrary(const char *traceNameIn)
69
{
70
std::stringstream traceNameStr;
71
#if !defined(ANGLE_PLATFORM_WINDOWS)
72
traceNameStr << "lib";
73
#endif // !defined(ANGLE_PLATFORM_WINDOWS)
74
traceNameStr << traceNameIn;
75
#if defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
76
// Added to shared library names in Android component builds in
77
// https://chromium.googlesource.com/chromium/src/+/9bacc8c4868cc802f69e1e858eea6757217a508f/build/toolchain/toolchain.gni#56
78
traceNameStr << ".cr";
79
#endif // defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
80
std::string traceName = traceNameStr.str();
81
mTraceLibrary.reset(OpenSharedLibrary(traceName.c_str(), SearchType::ModuleDir));
82
}
83
84
bool valid() const { return mTraceLibrary != nullptr; }
85
86
void setBinaryDataDir(const char *dataDir)
87
{
88
callFunc<SetBinaryDataDirFunc>("SetBinaryDataDir", dataDir);
89
}
90
91
void setBinaryDataDecompressCallback(DecompressCallback callback)
92
{
93
callFunc<SetBinaryDataDecompressCallbackFunc>("SetBinaryDataDecompressCallback", callback);
94
}
95
96
void replayFrame(uint32_t frameIndex) { callFunc<ReplayFrameFunc>("ReplayFrame", frameIndex); }
97
98
void setupReplay() { callFunc<SetupReplayFunc>("SetupReplay"); }
99
100
void resetReplay() { callFunc<ResetReplayFunc>("ResetReplay"); }
101
102
void finishReplay() { callFunc<FinishReplayFunc>("FinishReplay"); }
103
104
const char *getSerializedContextState(uint32_t frameIndex)
105
{
106
return callFunc<GetSerializedContextStateFunc>("GetSerializedContextState", frameIndex);
107
}
108
109
void setValidateSerializedStateCallback(ValidateSerializedStateCallback callback)
110
{
111
return callFunc<SetValidateSerializedStateCallbackFunc>(
112
"SetValidateSerializedStateCallback", callback);
113
}
114
115
private:
116
template <typename FuncT, typename... ArgsT>
117
typename std::result_of<FuncT(ArgsT...)>::type callFunc(const char *funcName, ArgsT... args)
118
{
119
void *untypedFunc = mTraceLibrary->getSymbol(funcName);
120
if (!untypedFunc)
121
{
122
fprintf(stderr, "Error loading function: %s\n", funcName);
123
ASSERT(untypedFunc);
124
}
125
auto typedFunc = reinterpret_cast<FuncT>(untypedFunc);
126
return typedFunc(args...);
127
}
128
129
std::unique_ptr<Library> mTraceLibrary;
130
};
131
132
} // namespace angle
133
134
#endif // UTIL_FRAME_CAPTURE_TEST_UTILS_H_
135
136