Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/libANGLE/AttributeMap.cpp
1693 views
1
//
2
// Copyright 2014 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
7
#include "libANGLE/AttributeMap.h"
8
9
#include "common/debug.h"
10
11
namespace egl
12
{
13
14
AttributeMap::AttributeMap() = default;
15
16
AttributeMap::AttributeMap(const AttributeMap &other) = default;
17
18
AttributeMap &AttributeMap::operator=(const AttributeMap &other) = default;
19
20
AttributeMap::~AttributeMap() = default;
21
22
void AttributeMap::insert(EGLAttrib key, EGLAttrib value)
23
{
24
mAttributes[key] = value;
25
}
26
27
bool AttributeMap::contains(EGLAttrib key) const
28
{
29
return (mAttributes.find(key) != mAttributes.end());
30
}
31
32
EGLAttrib AttributeMap::get(EGLAttrib key) const
33
{
34
auto iter = mAttributes.find(key);
35
ASSERT(iter != mAttributes.end());
36
return iter->second;
37
}
38
39
EGLAttrib AttributeMap::get(EGLAttrib key, EGLAttrib defaultValue) const
40
{
41
auto iter = mAttributes.find(key);
42
return (iter != mAttributes.end()) ? iter->second : defaultValue;
43
}
44
45
EGLint AttributeMap::getAsInt(EGLAttrib key) const
46
{
47
return static_cast<EGLint>(get(key));
48
}
49
50
EGLint AttributeMap::getAsInt(EGLAttrib key, EGLint defaultValue) const
51
{
52
return static_cast<EGLint>(get(key, static_cast<EGLAttrib>(defaultValue)));
53
}
54
55
bool AttributeMap::isEmpty() const
56
{
57
return mAttributes.empty();
58
}
59
60
std::vector<EGLint> AttributeMap::toIntVector() const
61
{
62
std::vector<EGLint> ret;
63
for (const auto &pair : mAttributes)
64
{
65
ret.push_back(static_cast<EGLint>(pair.first));
66
ret.push_back(static_cast<EGLint>(pair.second));
67
}
68
ret.push_back(EGL_NONE);
69
70
return ret;
71
}
72
73
AttributeMap::const_iterator AttributeMap::begin() const
74
{
75
return mAttributes.begin();
76
}
77
78
AttributeMap::const_iterator AttributeMap::end() const
79
{
80
return mAttributes.end();
81
}
82
83
// static
84
AttributeMap AttributeMap::CreateFromIntArray(const EGLint *attributes)
85
{
86
AttributeMap map;
87
if (attributes)
88
{
89
for (const EGLint *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)
90
{
91
map.insert(static_cast<EGLAttrib>(curAttrib[0]), static_cast<EGLAttrib>(curAttrib[1]));
92
}
93
}
94
return map;
95
}
96
97
// static
98
AttributeMap AttributeMap::CreateFromAttribArray(const EGLAttrib *attributes)
99
{
100
AttributeMap map;
101
if (attributes)
102
{
103
for (const EGLAttrib *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)
104
{
105
map.insert(curAttrib[0], curAttrib[1]);
106
}
107
}
108
return map;
109
}
110
} // namespace egl
111
112