• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
AttributeMap()14 AttributeMap::AttributeMap() {}
15 
16 AttributeMap::AttributeMap(const AttributeMap &other) = default;
17 
18 AttributeMap::~AttributeMap() = default;
19 
insert(EGLAttrib key,EGLAttrib value)20 void AttributeMap::insert(EGLAttrib key, EGLAttrib value)
21 {
22     mAttributes[key] = value;
23 }
24 
contains(EGLAttrib key) const25 bool AttributeMap::contains(EGLAttrib key) const
26 {
27     return (mAttributes.find(key) != mAttributes.end());
28 }
29 
get(EGLAttrib key) const30 EGLAttrib AttributeMap::get(EGLAttrib key) const
31 {
32     auto iter = mAttributes.find(key);
33     ASSERT(iter != mAttributes.end());
34     return iter->second;
35 }
36 
get(EGLAttrib key,EGLAttrib defaultValue) const37 EGLAttrib AttributeMap::get(EGLAttrib key, EGLAttrib defaultValue) const
38 {
39     auto iter = mAttributes.find(key);
40     return (iter != mAttributes.end()) ? iter->second : defaultValue;
41 }
42 
getAsInt(EGLAttrib key) const43 EGLint AttributeMap::getAsInt(EGLAttrib key) const
44 {
45     return static_cast<EGLint>(get(key));
46 }
47 
getAsInt(EGLAttrib key,EGLint defaultValue) const48 EGLint AttributeMap::getAsInt(EGLAttrib key, EGLint defaultValue) const
49 {
50     return static_cast<EGLint>(get(key, static_cast<EGLAttrib>(defaultValue)));
51 }
52 
isEmpty() const53 bool AttributeMap::isEmpty() const
54 {
55     return mAttributes.empty();
56 }
57 
toIntVector() const58 std::vector<EGLint> AttributeMap::toIntVector() const
59 {
60     std::vector<EGLint> ret;
61     for (const auto &pair : mAttributes)
62     {
63         ret.push_back(static_cast<EGLint>(pair.first));
64         ret.push_back(static_cast<EGLint>(pair.second));
65     }
66     ret.push_back(EGL_NONE);
67 
68     return ret;
69 }
70 
begin() const71 AttributeMap::const_iterator AttributeMap::begin() const
72 {
73     return mAttributes.begin();
74 }
75 
end() const76 AttributeMap::const_iterator AttributeMap::end() const
77 {
78     return mAttributes.end();
79 }
80 
81 // static
CreateFromIntArray(const EGLint * attributes)82 AttributeMap AttributeMap::CreateFromIntArray(const EGLint *attributes)
83 {
84     AttributeMap map;
85     if (attributes)
86     {
87         for (const EGLint *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)
88         {
89             map.insert(static_cast<EGLAttrib>(curAttrib[0]), static_cast<EGLAttrib>(curAttrib[1]));
90         }
91     }
92     return map;
93 }
94 
95 // static
CreateFromAttribArray(const EGLAttrib * attributes)96 AttributeMap AttributeMap::CreateFromAttribArray(const EGLAttrib *attributes)
97 {
98     AttributeMap map;
99     if (attributes)
100     {
101         for (const EGLAttrib *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)
102         {
103             map.insert(curAttrib[0], curAttrib[1]);
104         }
105     }
106     return map;
107 }
108 }  // namespace egl
109