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 #ifndef LIBANGLE_ATTRIBUTEMAP_H_ 8 #define LIBANGLE_ATTRIBUTEMAP_H_ 9 10 #include "common/PackedEnums.h" 11 12 #include <EGL/egl.h> 13 14 #include <map> 15 #include <vector> 16 17 namespace egl 18 { 19 20 class AttributeMap final 21 { 22 public: 23 AttributeMap(); 24 AttributeMap(const AttributeMap &other); 25 ~AttributeMap(); 26 27 void insert(EGLAttrib key, EGLAttrib value); 28 bool contains(EGLAttrib key) const; 29 30 EGLAttrib get(EGLAttrib key) const; 31 EGLAttrib get(EGLAttrib key, EGLAttrib defaultValue) const; 32 EGLint getAsInt(EGLAttrib key) const; 33 EGLint getAsInt(EGLAttrib key, EGLint defaultValue) const; 34 35 template <typename PackedEnumT> getAsPackedEnum(EGLAttrib key)36 PackedEnumT getAsPackedEnum(EGLAttrib key) const 37 { 38 return FromEGLenum<PackedEnumT>(static_cast<EGLenum>(get(key))); 39 } 40 41 template <typename PackedEnumT> getAsPackedEnum(EGLAttrib key,PackedEnumT defaultValue)42 PackedEnumT getAsPackedEnum(EGLAttrib key, PackedEnumT defaultValue) const 43 { 44 auto iter = mAttributes.find(key); 45 return (mAttributes.find(key) != mAttributes.end()) 46 ? FromEGLenum<PackedEnumT>(static_cast<EGLenum>(iter->second)) 47 : defaultValue; 48 } 49 50 bool isEmpty() const; 51 std::vector<EGLint> toIntVector() const; 52 53 typedef std::map<EGLAttrib, EGLAttrib>::const_iterator const_iterator; 54 55 const_iterator begin() const; 56 const_iterator end() const; 57 58 static AttributeMap CreateFromIntArray(const EGLint *attributes); 59 static AttributeMap CreateFromAttribArray(const EGLAttrib *attributes); 60 61 private: 62 std::map<EGLAttrib, EGLAttrib> mAttributes; 63 }; 64 } // namespace egl 65 66 #endif // LIBANGLE_ATTRIBUTEMAP_H_ 67