Commit 8ceea819 by Geoff Lang Committed by Commit Bot

Refactor packed enum generation to support EGL enums.

Convert the very simple EGL texture type enum. BUG=angleproject:1618 Change-Id: Ieea382a282a8f2544f2982627e8445e6e5cea826 Reviewed-on: https://chromium-review.googlesource.com/1019386 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7b19a49b
...@@ -115,11 +115,14 @@ generators = { ...@@ -115,11 +115,14 @@ generators = {
], ],
'script': 'src/libANGLE/renderer/gl/generate_gl_dispatch_table.py', 'script': 'src/libANGLE/renderer/gl/generate_gl_dispatch_table.py',
}, },
'packed GLenum': { 'packed enum': {
'inputs': [ 'inputs': [
'src/libANGLE/packed_gl_enums.json', 'src/libANGLE/packed_gl_enums.json',
'src/libANGLE/packed_egl_enums.json',
], ],
'outputs': [ 'outputs': [
'src/libANGLE/PackedEGLEnums_autogen.cpp',
'src/libANGLE/PackedEGLEnums_autogen.h',
'src/libANGLE/PackedGLEnums_autogen.cpp', 'src/libANGLE/PackedGLEnums_autogen.cpp',
'src/libANGLE/PackedGLEnums_autogen.h', 'src/libANGLE/PackedGLEnums_autogen.h',
], ],
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#ifndef LIBANGLE_ATTRIBUTEMAP_H_ #ifndef LIBANGLE_ATTRIBUTEMAP_H_
#define LIBANGLE_ATTRIBUTEMAP_H_ #define LIBANGLE_ATTRIBUTEMAP_H_
#include "libANGLE/PackedEnums.h"
#include <EGL/egl.h> #include <EGL/egl.h>
...@@ -25,10 +26,27 @@ class AttributeMap final ...@@ -25,10 +26,27 @@ class AttributeMap final
void insert(EGLAttrib key, EGLAttrib value); void insert(EGLAttrib key, EGLAttrib value);
bool contains(EGLAttrib key) const; bool contains(EGLAttrib key) const;
EGLAttrib get(EGLAttrib key) const; EGLAttrib get(EGLAttrib key) const;
EGLAttrib get(EGLAttrib key, EGLAttrib defaultValue) const; EGLAttrib get(EGLAttrib key, EGLAttrib defaultValue) const;
EGLint getAsInt(EGLAttrib key) const; EGLint getAsInt(EGLAttrib key) const;
EGLint getAsInt(EGLAttrib key, EGLint defaultValue) const; EGLint getAsInt(EGLAttrib key, EGLint defaultValue) const;
template <typename PackedEnumT>
PackedEnumT getAsPackedEnum(EGLAttrib key) const
{
return FromEGLenum<PackedEnumT>(static_cast<EGLenum>(get(key)));
}
template <typename PackedEnumT>
PackedEnumT getAsPackedEnum(EGLAttrib key, PackedEnumT defaultValue) const
{
auto iter = mAttributes.find(key);
return (mAttributes.find(key) != mAttributes.end())
? FromEGLenum<PackedEnumT>(static_cast<EGLenum>(iter->second))
: defaultValue;
}
bool isEmpty() const; bool isEmpty() const;
std::vector<EGLint> toIntVector() const; std::vector<EGLint> toIntVector() const;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "libANGLE/Debug.h" #include "libANGLE/Debug.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/IndexRangeCache.h" #include "libANGLE/IndexRangeCache.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
namespace rx namespace rx
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
namespace rx namespace rx
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "libANGLE/Context_gles_1_0_autogen.h" #include "libANGLE/Context_gles_1_0_autogen.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/HandleAllocator.h" #include "libANGLE/HandleAllocator.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
#include "libANGLE/ResourceMap.h" #include "libANGLE/ResourceMap.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexAttribute.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define LIBANGLE_IMAGE_INDEX_H_ #define LIBANGLE_IMAGE_INDEX_H_
#include "common/mathutil.h" #include "common/mathutil.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "angle_gl.h" #include "angle_gl.h"
......
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_packed_gl_enums.py using data from packed_egl_enums.json.
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PackedEGLEnums_autogen.cpp:
// Implements ANGLE-specific enums classes for EGLenums and functions operating
// on them.
#include "libANGLE/PackedEGLEnums_autogen.h"
#include "common/debug.h"
namespace egl
{
template <>
TextureFormat FromEGLenum<TextureFormat>(EGLenum from)
{
switch (from)
{
case EGL_NO_TEXTURE:
return TextureFormat::NoTexture;
case EGL_TEXTURE_RGB:
return TextureFormat::RGB;
case EGL_TEXTURE_RGBA:
return TextureFormat::RGBA;
default:
return TextureFormat::InvalidEnum;
}
}
EGLenum ToEGLenum(TextureFormat from)
{
switch (from)
{
case TextureFormat::NoTexture:
return EGL_NO_TEXTURE;
case TextureFormat::RGB:
return EGL_TEXTURE_RGB;
case TextureFormat::RGBA:
return EGL_TEXTURE_RGBA;
default:
UNREACHABLE();
return 0;
}
}
} // namespace egl
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_packed_gl_enums.py using data from packed_egl_enums.json.
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PackedEGLEnums_autogen.h:
// Declares ANGLE-specific enums classes for EGLenums and functions operating
// on them.
#ifndef LIBANGLE_PACKEDEGLENUMS_AUTOGEN_H_
#define LIBANGLE_PACKEDEGLENUMS_AUTOGEN_H_
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <angle_gl.h>
#include <cstdint>
namespace egl
{
template <typename Enum>
Enum FromEGLenum(EGLenum from);
enum class TextureFormat : uint8_t
{
NoTexture = 0,
RGB = 1,
RGBA = 2,
InvalidEnum = 3,
EnumCount = 3,
};
template <>
TextureFormat FromEGLenum<TextureFormat>(EGLenum from);
EGLenum ToEGLenum(TextureFormat from);
} // namespace egl
#endif // LIBANGLE_PACKEDEGLENUMS_AUTOGEN_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// Declares ANGLE-specific enums classes for GLEnum and functions operating // Declares ANGLE-specific enums classes for GLEnum and functions operating
// on them. // on them.
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "common/utilities.h" #include "common/utilities.h"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef LIBANGLE_PACKEDGLENUMS_H_ #ifndef LIBANGLE_PACKEDGLENUMS_H_
#define LIBANGLE_PACKEDGLENUMS_H_ #define LIBANGLE_PACKEDGLENUMS_H_
#include "libANGLE/PackedEGLEnums_autogen.h"
#include "libANGLE/PackedGLEnums_autogen.h" #include "libANGLE/PackedGLEnums_autogen.h"
#include <array> #include <array>
...@@ -70,8 +71,8 @@ template <typename E, typename T> ...@@ -70,8 +71,8 @@ template <typename E, typename T>
class PackedEnumMap class PackedEnumMap
{ {
private: private:
using UnderlyingType = typename std::underlying_type<E>::type; using UnderlyingType = typename std::underlying_type<E>::type;
using Storage = std::array<T, EnumSize<E>()>; using Storage = std::array<T, EnumSize<E>()>;
Storage mData; Storage mData;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// PackedGLEnums_autogen.cpp: // PackedGLEnums_autogen.cpp:
// Implements ANGLE-specific enums classes for GLEnum and functions operating // Implements ANGLE-specific enums classes for GLenums and functions operating
// on them. // on them.
#include "libANGLE/PackedGLEnums_autogen.h" #include "libANGLE/PackedGLEnums_autogen.h"
...@@ -63,7 +63,7 @@ GLenum ToGLenum(AlphaTestFunc from) ...@@ -63,7 +63,7 @@ GLenum ToGLenum(AlphaTestFunc from)
return GL_NOTEQUAL; return GL_NOTEQUAL;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -131,7 +131,7 @@ GLenum ToGLenum(BufferBinding from) ...@@ -131,7 +131,7 @@ GLenum ToGLenum(BufferBinding from)
return GL_UNIFORM_BUFFER; return GL_UNIFORM_BUFFER;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -187,7 +187,7 @@ GLenum ToGLenum(BufferUsage from) ...@@ -187,7 +187,7 @@ GLenum ToGLenum(BufferUsage from)
return GL_STREAM_READ; return GL_STREAM_READ;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -227,7 +227,7 @@ GLenum ToGLenum(ClientVertexArrayType from) ...@@ -227,7 +227,7 @@ GLenum ToGLenum(ClientVertexArrayType from)
return GL_VERTEX_ARRAY; return GL_VERTEX_ARRAY;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -259,7 +259,7 @@ GLenum ToGLenum(CullFaceMode from) ...@@ -259,7 +259,7 @@ GLenum ToGLenum(CullFaceMode from)
return GL_FRONT_AND_BACK; return GL_FRONT_AND_BACK;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -291,7 +291,7 @@ GLenum ToGLenum(FogMode from) ...@@ -291,7 +291,7 @@ GLenum ToGLenum(FogMode from)
return GL_LINEAR; return GL_LINEAR;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -323,7 +323,7 @@ GLenum ToGLenum(HintSetting from) ...@@ -323,7 +323,7 @@ GLenum ToGLenum(HintSetting from)
return GL_NICEST; return GL_NICEST;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -407,7 +407,7 @@ GLenum ToGLenum(LogicalOperation from) ...@@ -407,7 +407,7 @@ GLenum ToGLenum(LogicalOperation from)
return GL_XOR; return GL_XOR;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -439,7 +439,7 @@ GLenum ToGLenum(MatrixType from) ...@@ -439,7 +439,7 @@ GLenum ToGLenum(MatrixType from)
return GL_TEXTURE; return GL_TEXTURE;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -475,7 +475,7 @@ GLenum ToGLenum(ShaderType from) ...@@ -475,7 +475,7 @@ GLenum ToGLenum(ShaderType from)
return GL_COMPUTE_SHADER; return GL_COMPUTE_SHADER;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -503,7 +503,7 @@ GLenum ToGLenum(ShadingModel from) ...@@ -503,7 +503,7 @@ GLenum ToGLenum(ShadingModel from)
return GL_SMOOTH; return GL_SMOOTH;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -555,7 +555,7 @@ GLenum ToGLenum(TextureCombine from) ...@@ -555,7 +555,7 @@ GLenum ToGLenum(TextureCombine from)
return GL_SUBTRACT; return GL_SUBTRACT;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -599,7 +599,7 @@ GLenum ToGLenum(TextureEnvMode from) ...@@ -599,7 +599,7 @@ GLenum ToGLenum(TextureEnvMode from)
return GL_REPLACE; return GL_REPLACE;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -635,7 +635,7 @@ GLenum ToGLenum(TextureOp from) ...@@ -635,7 +635,7 @@ GLenum ToGLenum(TextureOp from)
return GL_SRC_COLOR; return GL_SRC_COLOR;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -671,7 +671,7 @@ GLenum ToGLenum(TextureSrc from) ...@@ -671,7 +671,7 @@ GLenum ToGLenum(TextureSrc from)
return GL_TEXTURE; return GL_TEXTURE;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -739,7 +739,7 @@ GLenum ToGLenum(TextureTarget from) ...@@ -739,7 +739,7 @@ GLenum ToGLenum(TextureTarget from)
return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -787,7 +787,7 @@ GLenum ToGLenum(TextureType from) ...@@ -787,7 +787,7 @@ GLenum ToGLenum(TextureType from)
return GL_TEXTURE_CUBE_MAP; return GL_TEXTURE_CUBE_MAP;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
...@@ -827,7 +827,7 @@ GLenum ToGLenum(VertexArrayType from) ...@@ -827,7 +827,7 @@ GLenum ToGLenum(VertexArrayType from)
return GL_VERTEX_ARRAY; return GL_VERTEX_ARRAY;
default: default:
UNREACHABLE(); UNREACHABLE();
return GL_NONE; return 0;
} }
} }
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// PackedGLEnums_autogen.h: // PackedGLEnums_autogen.h:
// Declares ANGLE-specific enums classes for GLEnum and functions operating // Declares ANGLE-specific enums classes for GLenums and functions operating
// on them. // on them.
#ifndef LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_ #ifndef LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_
#define LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_ #define LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <angle_gl.h> #include <angle_gl.h>
#include <cstdint> #include <cstdint>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "libANGLE/VaryingPacking.h" #include "libANGLE/VaryingPacking.h"
#include <functional> #include <functional>
......
...@@ -53,7 +53,7 @@ Surface::Surface(EGLint surfaceType, ...@@ -53,7 +53,7 @@ Surface::Surface(EGLint surfaceType,
mFixedSize(false), mFixedSize(false),
mFixedWidth(0), mFixedWidth(0),
mFixedHeight(0), mFixedHeight(0),
mTextureFormat(EGL_NO_TEXTURE), mTextureFormat(TextureFormat::NoTexture),
mTextureTarget(EGL_NO_TEXTURE), mTextureTarget(EGL_NO_TEXTURE),
// FIXME: Determine actual pixel aspect ratio // FIXME: Determine actual pixel aspect ratio
mPixelAspectRatio(static_cast<EGLint>(1.0 * EGL_DISPLAY_SCALING)), mPixelAspectRatio(static_cast<EGLint>(1.0 * EGL_DISPLAY_SCALING)),
...@@ -99,7 +99,7 @@ Surface::Surface(EGLint surfaceType, ...@@ -99,7 +99,7 @@ Surface::Surface(EGLint surfaceType,
if (mType != EGL_WINDOW_BIT) if (mType != EGL_WINDOW_BIT)
{ {
mTextureFormat = static_cast<EGLenum>(attributes.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE)); mTextureFormat = attributes.getAsPackedEnum(EGL_TEXTURE_FORMAT, TextureFormat::NoTexture);
mTextureTarget = static_cast<EGLenum>(attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE)); mTextureTarget = static_cast<EGLenum>(attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE));
} }
...@@ -312,7 +312,7 @@ EGLenum Surface::getSwapBehavior() const ...@@ -312,7 +312,7 @@ EGLenum Surface::getSwapBehavior() const
return mSwapBehavior; return mSwapBehavior;
} }
EGLenum Surface::getTextureFormat() const TextureFormat Surface::getTextureFormat() const
{ {
return mTextureFormat; return mTextureFormat;
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "libANGLE/AttributeMap.h" #include "libANGLE/AttributeMap.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/FramebufferAttachment.h" #include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/PackedEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/SurfaceImpl.h" #include "libANGLE/renderer/SurfaceImpl.h"
...@@ -85,7 +86,7 @@ class Surface : public gl::FramebufferAttachmentObject ...@@ -85,7 +86,7 @@ class Surface : public gl::FramebufferAttachmentObject
EGLint getPixelAspectRatio() const; EGLint getPixelAspectRatio() const;
EGLenum getRenderBuffer() const; EGLenum getRenderBuffer() const;
EGLenum getSwapBehavior() const; EGLenum getSwapBehavior() const;
EGLenum getTextureFormat() const; TextureFormat getTextureFormat() const;
EGLenum getTextureTarget() const; EGLenum getTextureTarget() const;
bool getLargestPbuffer() const; bool getLargestPbuffer() const;
EGLenum getGLColorspace() const; EGLenum getGLColorspace() const;
...@@ -170,7 +171,7 @@ class Surface : public gl::FramebufferAttachmentObject ...@@ -170,7 +171,7 @@ class Surface : public gl::FramebufferAttachmentObject
bool mRobustResourceInitialization; bool mRobustResourceInitialization;
EGLenum mTextureFormat; TextureFormat mTextureFormat;
EGLenum mTextureTarget; EGLenum mTextureTarget;
EGLint mPixelAspectRatio; // Display aspect ratio EGLint mPixelAspectRatio; // Display aspect ratio
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "common/vector_utils.h" #include "common/vector_utils.h"
#include "libANGLE/Constants.h" #include "libANGLE/Constants.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
#include <stdint.h> #include <stdint.h>
......
# Copyright 2016 The ANGLE Project Authors. All rights reserved. # Copyright 2018 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# #
# gen_packed_gl_enums.py: # gen_packed_gl_enums.py:
# Code generation for the packed GL enums. # Code generation for the packed enums.
import datetime, json, os, sys import datetime, json, os, sys
from collections import namedtuple from collections import namedtuple
...@@ -11,7 +11,20 @@ from collections import namedtuple ...@@ -11,7 +11,20 @@ from collections import namedtuple
Enum = namedtuple('Enum', ['name', 'values', 'max_value']) Enum = namedtuple('Enum', ['name', 'values', 'max_value'])
EnumValue = namedtuple('EnumValue', ['name', 'gl_name', 'value']) EnumValue = namedtuple('EnumValue', ['name', 'gl_name', 'value'])
kJsonFileName = "packed_gl_enums.json" Generators = [
{
'json': 'packed_gl_enums.json',
'output': 'PackedGLEnums',
'namespace': 'gl',
'enum_type': 'GLenum',
},
{
'json': 'packed_egl_enums.json',
'output': 'PackedEGLEnums',
'namespace': 'egl',
'enum_type': 'EGLenum',
},
]
def load_enums(path): def load_enums(path):
with open(path) as map_file: with open(path) as map_file:
...@@ -41,6 +54,12 @@ def load_enums(path): ...@@ -41,6 +54,12 @@ def load_enums(path):
enums.sort(key=lambda enum: enum.name) enums.sort(key=lambda enum: enum.name)
return enums return enums
def generate_include_guard(path):
return path.replace(".", "_").upper()
def header_name_from_cpp_name(path):
return path.replace(".cpp", ".h")
header_template = """// GENERATED FILE - DO NOT EDIT. header_template = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}. // Generated by {script_name} using data from {data_source_name}.
// //
...@@ -48,26 +67,28 @@ header_template = """// GENERATED FILE - DO NOT EDIT. ...@@ -48,26 +67,28 @@ header_template = """// GENERATED FILE - DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// PackedGLEnums_autogen.h: // {file_name}:
// Declares ANGLE-specific enums classes for GLEnum and functions operating // Declares ANGLE-specific enums classes for {api_enum_name}s and functions operating
// on them. // on them.
#ifndef LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_ #ifndef LIBANGLE_{include_guard}_
#define LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_ #define LIBANGLE_{include_guard}_
#include <angle_gl.h> #include <angle_gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <cstdint> #include <cstdint>
namespace gl namespace {namespace}
{{ {{
template<typename Enum> template<typename Enum>
Enum FromGLenum(GLenum from); Enum From{api_enum_name}({api_enum_name} from);
{content} {content}
}} // namespace gl }} // namespace {namespace}
#endif // LIBANGLE_PACKEDGLENUMS_AUTOGEN_H_ #endif // LIBANGLE_{include_guard}_
""" """
enum_declaration_template = """ enum_declaration_template = """
...@@ -80,11 +101,11 @@ enum class {enum_name} : uint8_t ...@@ -80,11 +101,11 @@ enum class {enum_name} : uint8_t
}}; }};
template<> template<>
{enum_name} FromGLenum<{enum_name}>(GLenum from); {enum_name} From{api_enum_name}<{enum_name}>({api_enum_name} from);
GLenum ToGLenum({enum_name} from); {api_enum_name} To{api_enum_name}({enum_name} from);
""" """
def write_header(enums, path): def write_header(enums, path_prefix, file_name, data_source_name, namespace, api_enum_name):
content = [''] content = ['']
for enum in enums: for enum in enums:
...@@ -95,17 +116,22 @@ def write_header(enums, path): ...@@ -95,17 +116,22 @@ def write_header(enums, path):
content.append(enum_declaration_template.format( content.append(enum_declaration_template.format(
enum_name = enum.name, enum_name = enum.name,
max_value = str(enum.max_value), max_value = str(enum.max_value),
value_declarations = '\n'.join(value_declarations) value_declarations = '\n'.join(value_declarations),
api_enum_name = api_enum_name
)) ))
header = header_template.format( header = header_template.format(
content = ''.join(content), content = ''.join(content),
copyright_year = datetime.date.today().year, copyright_year = datetime.date.today().year,
data_source_name = kJsonFileName, data_source_name = data_source_name,
script_name = sys.argv[0] script_name = sys.argv[0],
file_name = file_name,
include_guard = generate_include_guard(file_name),
namespace = namespace,
api_enum_name = api_enum_name
) )
with (open(path, 'wt')) as f: with (open(path_prefix + file_name, 'wt')) as f:
f.write(header) f.write(header)
cpp_template = """// GENERATED FILE - DO NOT EDIT. cpp_template = """// GENERATED FILE - DO NOT EDIT.
...@@ -115,22 +141,22 @@ cpp_template = """// GENERATED FILE - DO NOT EDIT. ...@@ -115,22 +141,22 @@ cpp_template = """// GENERATED FILE - DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// PackedGLEnums_autogen.cpp: // {file_name}:
// Implements ANGLE-specific enums classes for GLEnum and functions operating // Implements ANGLE-specific enums classes for {api_enum_name}s and functions operating
// on them. // on them.
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/PackedGLEnums_autogen.h" #include "libANGLE/{header_name}"
namespace gl namespace {namespace}
{{ {{
{content} {content}
}} // namespace gl }} // namespace {namespace}
""" """
enum_implementation_template = """ enum_implementation_template = """
template<> template<>
{enum_name} FromGLenum<{enum_name}>(GLenum from) {enum_name} From{api_enum_name}<{enum_name}>({api_enum_name} from)
{{ {{
switch(from) switch(from)
{{ {{
...@@ -139,17 +165,17 @@ template<> ...@@ -139,17 +165,17 @@ template<>
}} }}
}} }}
GLenum ToGLenum({enum_name} from) {api_enum_name} To{api_enum_name}({enum_name} from)
{{ {{
switch(from) switch(from)
{{ {{
{to_glenum_cases} {to_glenum_cases}
default: UNREACHABLE(); return GL_NONE; default: UNREACHABLE(); return 0;
}} }}
}} }}
""" """
def write_cpp(enums, path): def write_cpp(enums, path_prefix, file_name, data_source_name, namespace, api_enum_name):
content = [''] content = ['']
for enum in enums: for enum in enums:
...@@ -164,22 +190,32 @@ def write_cpp(enums, path): ...@@ -164,22 +190,32 @@ def write_cpp(enums, path):
enum_name = enum.name, enum_name = enum.name,
from_glenum_cases = '\n'.join(from_glenum_cases), from_glenum_cases = '\n'.join(from_glenum_cases),
max_value = str(enum.max_value), max_value = str(enum.max_value),
to_glenum_cases = '\n'.join(to_glenum_cases) to_glenum_cases = '\n'.join(to_glenum_cases),
api_enum_name = api_enum_name
)) ))
cpp = cpp_template.format( cpp = cpp_template.format(
content = ''.join(content), content = ''.join(content),
copyright_year = datetime.date.today().year, copyright_year = datetime.date.today().year,
data_source_name = kJsonFileName, data_source_name = data_source_name,
script_name = sys.argv[0] script_name = sys.argv[0],
file_name = file_name,
header_name = header_name_from_cpp_name(file_name),
namespace = namespace,
api_enum_name = api_enum_name
) )
with (open(path, 'wt')) as f: with (open(path_prefix + file_name, 'wt')) as f:
f.write(cpp) f.write(cpp)
if __name__ == '__main__': if __name__ == '__main__':
path_prefix = os.path.dirname(os.path.realpath(__file__)) + os.path.sep path_prefix = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
enums = load_enums(path_prefix + kJsonFileName)
write_header(enums, path_prefix + 'PackedGLEnums_autogen.h') for generator in Generators:
write_cpp(enums, path_prefix + 'PackedGLEnums_autogen.cpp') json_file = generator['json']
output_file = generator['output']
namespace = generator['namespace']
enum_type = generator['enum_type']
enums = load_enums(path_prefix + json_file)
write_header(enums, path_prefix, output_file + '_autogen.h', json_file, namespace, enum_type)
write_cpp(enums, path_prefix, output_file + '_autogen.cpp', json_file, namespace, enum_type)
{
"TextureFormat":
{
"NoTexture": "EGL_NO_TEXTURE",
"RGB": "EGL_TEXTURE_RGB",
"RGBA": "EGL_TEXTURE_RGBA"
}
}
...@@ -1937,7 +1937,7 @@ void QuerySurfaceAttrib(const Surface *surface, EGLint attribute, EGLint *value) ...@@ -1937,7 +1937,7 @@ void QuerySurfaceAttrib(const Surface *surface, EGLint attribute, EGLint *value)
// The EGL spec states that value is not written if the surface is not a pbuffer // The EGL spec states that value is not written if the surface is not a pbuffer
if (surface->getType() == EGL_PBUFFER_BIT) if (surface->getType() == EGL_PBUFFER_BIT)
{ {
*value = surface->getTextureFormat(); *value = ToEGLenum(surface->getTextureFormat());
} }
break; break;
case EGL_TEXTURE_TARGET: case EGL_TEXTURE_TARGET:
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <EGL/egl.h> #include <EGL/egl.h>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "common/mathutil.h" #include "common/mathutil.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/Observer.h" #include "libANGLE/Observer.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <stdint.h> #include <stdint.h>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
namespace gl namespace gl
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
namespace gl namespace gl
{ {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "common/mathutil.h" #include "common/mathutil.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef LIBANGLE_VALIDATION_ES2_H_ #ifndef LIBANGLE_VALIDATION_ES2_H_
#define LIBANGLE_VALIDATION_ES2_H_ #define LIBANGLE_VALIDATION_ES2_H_
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef LIBANGLE_VALIDATION_ES3_H_ #ifndef LIBANGLE_VALIDATION_ES3_H_
#define LIBANGLE_VALIDATION_ES3_H_ #define LIBANGLE_VALIDATION_ES3_H_
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef LIBANGLE_VALIDATION_ES31_H_ #ifndef LIBANGLE_VALIDATION_ES31_H_
#define LIBANGLE_VALIDATION_ES31_H_ #define LIBANGLE_VALIDATION_ES31_H_
#include "libANGLE/PackedGLEnums.h" #include "libANGLE/PackedEnums.h"
#include <GLES3/gl31.h> #include <GLES3/gl31.h>
......
...@@ -184,8 +184,10 @@ ...@@ -184,8 +184,10 @@
'libANGLE/MemoryProgramCache.h', 'libANGLE/MemoryProgramCache.h',
'libANGLE/Observer.cpp', 'libANGLE/Observer.cpp',
'libANGLE/Observer.h', 'libANGLE/Observer.h',
'libANGLE/PackedGLEnums.cpp', 'libANGLE/PackedEGLEnums_autogen.cpp',
'libANGLE/PackedGLEnums.h', 'libANGLE/PackedEGLEnums_autogen.h',
'libANGLE/PackedEnums.cpp',
'libANGLE/PackedEnums.h',
'libANGLE/PackedGLEnums_autogen.cpp', 'libANGLE/PackedGLEnums_autogen.cpp',
'libANGLE/PackedGLEnums_autogen.h', 'libANGLE/PackedGLEnums_autogen.h',
'libANGLE/Path.h', 'libANGLE/Path.h',
......
...@@ -752,7 +752,7 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b ...@@ -752,7 +752,7 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b
return EGL_FALSE; return EGL_FALSE;
} }
if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE) if (eglSurface->getTextureFormat() == TextureFormat::NoTexture)
{ {
thread->setError(EglBadMatch()); thread->setError(EglBadMatch());
return EGL_FALSE; return EGL_FALSE;
...@@ -839,7 +839,7 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin ...@@ -839,7 +839,7 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin
return EGL_FALSE; return EGL_FALSE;
} }
if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE) if (eglSurface->getTextureFormat() == TextureFormat::NoTexture)
{ {
thread->setError(EglBadMatch()); thread->setError(EglBadMatch());
return EGL_FALSE; return EGL_FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment