• 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 
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 
insert(EGLAttrib key,EGLAttrib value)22 void AttributeMap::insert(EGLAttrib key, EGLAttrib value)
23 {
24     mAttributes[key] = value;
25 }
26 
contains(EGLAttrib key) const27 bool AttributeMap::contains(EGLAttrib key) const
28 {
29     return (mAttributes.find(key) != mAttributes.end());
30 }
31 
get(EGLAttrib key) const32 EGLAttrib AttributeMap::get(EGLAttrib key) const
33 {
34     auto iter = mAttributes.find(key);
35     ASSERT(iter != mAttributes.end());
36     return iter->second;
37 }
38 
get(EGLAttrib key,EGLAttrib defaultValue) const39 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 
getAsInt(EGLAttrib key) const45 EGLint AttributeMap::getAsInt(EGLAttrib key) const
46 {
47     return static_cast<EGLint>(get(key));
48 }
49 
getAsInt(EGLAttrib key,EGLint defaultValue) const50 EGLint AttributeMap::getAsInt(EGLAttrib key, EGLint defaultValue) const
51 {
52     return static_cast<EGLint>(get(key, static_cast<EGLAttrib>(defaultValue)));
53 }
54 
isEmpty() const55 bool AttributeMap::isEmpty() const
56 {
57     return mAttributes.empty();
58 }
59 
toIntVector() const60 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 
begin() const73 AttributeMap::const_iterator AttributeMap::begin() const
74 {
75     return mAttributes.begin();
76 }
77 
end() const78 AttributeMap::const_iterator AttributeMap::end() const
79 {
80     return mAttributes.end();
81 }
82 
83 // static
CreateFromIntArray(const EGLint * attributes)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
CreateFromAttribArray(const EGLAttrib * attributes)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