Path: blob/main_old/src/libANGLE/AttributeMap.cpp
1693 views
//1// Copyright 2014 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#include "libANGLE/AttributeMap.h"78#include "common/debug.h"910namespace egl11{1213AttributeMap::AttributeMap() = default;1415AttributeMap::AttributeMap(const AttributeMap &other) = default;1617AttributeMap &AttributeMap::operator=(const AttributeMap &other) = default;1819AttributeMap::~AttributeMap() = default;2021void AttributeMap::insert(EGLAttrib key, EGLAttrib value)22{23mAttributes[key] = value;24}2526bool AttributeMap::contains(EGLAttrib key) const27{28return (mAttributes.find(key) != mAttributes.end());29}3031EGLAttrib AttributeMap::get(EGLAttrib key) const32{33auto iter = mAttributes.find(key);34ASSERT(iter != mAttributes.end());35return iter->second;36}3738EGLAttrib AttributeMap::get(EGLAttrib key, EGLAttrib defaultValue) const39{40auto iter = mAttributes.find(key);41return (iter != mAttributes.end()) ? iter->second : defaultValue;42}4344EGLint AttributeMap::getAsInt(EGLAttrib key) const45{46return static_cast<EGLint>(get(key));47}4849EGLint AttributeMap::getAsInt(EGLAttrib key, EGLint defaultValue) const50{51return static_cast<EGLint>(get(key, static_cast<EGLAttrib>(defaultValue)));52}5354bool AttributeMap::isEmpty() const55{56return mAttributes.empty();57}5859std::vector<EGLint> AttributeMap::toIntVector() const60{61std::vector<EGLint> ret;62for (const auto &pair : mAttributes)63{64ret.push_back(static_cast<EGLint>(pair.first));65ret.push_back(static_cast<EGLint>(pair.second));66}67ret.push_back(EGL_NONE);6869return ret;70}7172AttributeMap::const_iterator AttributeMap::begin() const73{74return mAttributes.begin();75}7677AttributeMap::const_iterator AttributeMap::end() const78{79return mAttributes.end();80}8182// static83AttributeMap AttributeMap::CreateFromIntArray(const EGLint *attributes)84{85AttributeMap map;86if (attributes)87{88for (const EGLint *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)89{90map.insert(static_cast<EGLAttrib>(curAttrib[0]), static_cast<EGLAttrib>(curAttrib[1]));91}92}93return map;94}9596// static97AttributeMap AttributeMap::CreateFromAttribArray(const EGLAttrib *attributes)98{99AttributeMap map;100if (attributes)101{102for (const EGLAttrib *curAttrib = attributes; curAttrib[0] != EGL_NONE; curAttrib += 2)103{104map.insert(curAttrib[0], curAttrib[1]);105}106}107return map;108}109} // namespace egl110111112