Commit 485cdd8b by Jamie Madill Committed by Commit Bot

Add std::ostream output for packed enums.

This can be used to convert them to strings for debugging. It can also be helpful for frame capture and replay. Currently the enums are output as GLenum values. Bug: angleproject:3611 Change-Id: Ifcd04449e0ef61e125e0db65aa0dcc2bf48b38ca Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1678399Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent db990834
......@@ -438,15 +438,15 @@
"Vulkan mandatory format support table:third_party/vulkan-headers/src/registry/vk.xml":
"8af0f992bd45c2d9500eb5ed60c256d6",
"packed enum:src/common/PackedEGLEnums_autogen.cpp":
"c9f7cea85751e5a39b92bccc1d97f3bd",
"51fe45095a4c15fb0cdc3b2dc13ad437",
"packed enum:src/common/PackedEGLEnums_autogen.h":
"4073274726e0c926765c5ab8b21dc3de",
"96a117fc4265af386798a5553a719ff2",
"packed enum:src/common/PackedGLEnums_autogen.cpp":
"0968e9a68f277d1b7d4c43baed605802",
"2a00295fec7437c7e1e6e3166482ae81",
"packed enum:src/common/PackedGLEnums_autogen.h":
"c4229059d3e46601148dce802e198ca4",
"bf4b4a3c61a67df0e7e2fc0820ee7e79",
"packed enum:src/common/gen_packed_gl_enums.py":
"cc463afc5e37b0f73e119fec59a39420",
"b3e96ea44f52ec23ee893bd843dfd2cb",
"packed enum:src/common/packed_egl_enums.json":
"5f591d220ee53b6e54a27d1523a3ab79",
"packed enum:src/common/packed_gl_enums.json":
......
......@@ -47,6 +47,26 @@ EGLenum ToEGLenum(CompositorTiming from)
}
}
std::ostream &operator<<(std::ostream &os, CompositorTiming value)
{
switch (value)
{
case CompositorTiming::CompositeDeadline:
os << "EGL_COMPOSITE_DEADLINE_ANDROID";
break;
case CompositorTiming::CompositInterval:
os << "EGL_COMPOSITE_INTERVAL_ANDROID";
break;
case CompositorTiming::CompositToPresentLatency:
os << "EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
template <>
MessageType FromEGLenum<MessageType>(EGLenum from)
{
......@@ -83,6 +103,29 @@ EGLenum ToEGLenum(MessageType from)
}
}
std::ostream &operator<<(std::ostream &os, MessageType value)
{
switch (value)
{
case MessageType::Critical:
os << "EGL_DEBUG_MSG_CRITICAL_KHR";
break;
case MessageType::Error:
os << "EGL_DEBUG_MSG_ERROR_KHR";
break;
case MessageType::Warn:
os << "EGL_DEBUG_MSG_WARN_KHR";
break;
case MessageType::Info:
os << "EGL_DEBUG_MSG_INFO_KHR";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
template <>
ObjectType FromEGLenum<ObjectType>(EGLenum from)
{
......@@ -131,6 +174,38 @@ EGLenum ToEGLenum(ObjectType from)
}
}
std::ostream &operator<<(std::ostream &os, ObjectType value)
{
switch (value)
{
case ObjectType::Thread:
os << "EGL_OBJECT_THREAD_KHR";
break;
case ObjectType::Display:
os << "EGL_OBJECT_DISPLAY_KHR";
break;
case ObjectType::Context:
os << "EGL_OBJECT_CONTEXT_KHR";
break;
case ObjectType::Surface:
os << "EGL_OBJECT_SURFACE_KHR";
break;
case ObjectType::Image:
os << "EGL_OBJECT_IMAGE_KHR";
break;
case ObjectType::Sync:
os << "EGL_OBJECT_SYNC_KHR";
break;
case ObjectType::Stream:
os << "EGL_OBJECT_STREAM_KHR";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
template <>
TextureFormat FromEGLenum<TextureFormat>(EGLenum from)
{
......@@ -163,6 +238,26 @@ EGLenum ToEGLenum(TextureFormat from)
}
}
std::ostream &operator<<(std::ostream &os, TextureFormat value)
{
switch (value)
{
case TextureFormat::NoTexture:
os << "EGL_NO_TEXTURE";
break;
case TextureFormat::RGB:
os << "EGL_TEXTURE_RGB";
break;
case TextureFormat::RGBA:
os << "EGL_TEXTURE_RGBA";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
template <>
Timestamp FromEGLenum<Timestamp>(EGLenum from)
{
......@@ -219,4 +314,42 @@ EGLenum ToEGLenum(Timestamp from)
}
}
std::ostream &operator<<(std::ostream &os, Timestamp value)
{
switch (value)
{
case Timestamp::RequestedPresentTime:
os << "EGL_REQUESTED_PRESENT_TIME_ANDROID";
break;
case Timestamp::RenderingCompleteTime:
os << "EGL_RENDERING_COMPLETE_TIME_ANDROID";
break;
case Timestamp::CompositionLatchTime:
os << "EGL_COMPOSITION_LATCH_TIME_ANDROID";
break;
case Timestamp::FirstCompositionStartTime:
os << "EGL_FIRST_COMPOSITION_START_TIME_ANDROID";
break;
case Timestamp::LastCompositionStartTime:
os << "EGL_LAST_COMPOSITION_START_TIME_ANDROID";
break;
case Timestamp::FirstCompositionGPUFinishedTime:
os << "EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID";
break;
case Timestamp::DisplayPresentTime:
os << "EGL_DISPLAY_PRESENT_TIME_ANDROID";
break;
case Timestamp::DequeueReadyTime:
os << "EGL_DEQUEUE_READY_TIME_ANDROID";
break;
case Timestamp::ReadsDoneTime:
os << "EGL_READS_DONE_TIME_ANDROID";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
} // namespace egl
......@@ -17,6 +17,7 @@
#include <angle_gl.h>
#include <cstdint>
#include <ostream>
namespace egl
{
......@@ -37,6 +38,7 @@ enum class CompositorTiming : uint8_t
template <>
CompositorTiming FromEGLenum<CompositorTiming>(EGLenum from);
EGLenum ToEGLenum(CompositorTiming from);
std::ostream &operator<<(std::ostream &os, CompositorTiming value);
enum class MessageType : uint8_t
{
......@@ -52,6 +54,7 @@ enum class MessageType : uint8_t
template <>
MessageType FromEGLenum<MessageType>(EGLenum from);
EGLenum ToEGLenum(MessageType from);
std::ostream &operator<<(std::ostream &os, MessageType value);
enum class ObjectType : uint8_t
{
......@@ -70,6 +73,7 @@ enum class ObjectType : uint8_t
template <>
ObjectType FromEGLenum<ObjectType>(EGLenum from);
EGLenum ToEGLenum(ObjectType from);
std::ostream &operator<<(std::ostream &os, ObjectType value);
enum class TextureFormat : uint8_t
{
......@@ -84,6 +88,7 @@ enum class TextureFormat : uint8_t
template <>
TextureFormat FromEGLenum<TextureFormat>(EGLenum from);
EGLenum ToEGLenum(TextureFormat from);
std::ostream &operator<<(std::ostream &os, TextureFormat value);
enum class Timestamp : uint8_t
{
......@@ -104,6 +109,7 @@ enum class Timestamp : uint8_t
template <>
Timestamp FromEGLenum<Timestamp>(EGLenum from);
EGLenum ToEGLenum(Timestamp from);
std::ostream &operator<<(std::ostream &os, Timestamp value);
} // namespace egl
......
......@@ -170,6 +170,114 @@ bool IsMultisampled(gl::TextureType type)
}
}
std::ostream &operator<<(std::ostream &os, PrimitiveMode value)
{
switch (value)
{
case PrimitiveMode::LineLoop:
os << "GL_LINE_LOOP";
break;
case PrimitiveMode::Lines:
os << "GL_LINES";
break;
case PrimitiveMode::LinesAdjacency:
os << "GL_LINES_ADJACENCY";
break;
case PrimitiveMode::LineStrip:
os << "GL_LINE_STRIP";
break;
case PrimitiveMode::LineStripAdjacency:
os << "GL_LINE_STRIP_ADJANCENCY";
break;
case PrimitiveMode::Points:
os << "GL_POINTS";
break;
case PrimitiveMode::TriangleFan:
os << "GL_TRIANGLE_FAN";
break;
case PrimitiveMode::Triangles:
os << "GL_TRIANGLES";
break;
case PrimitiveMode::TrianglesAdjacency:
os << "GL_TRIANGLES_ADJANCENCY";
break;
case PrimitiveMode::TriangleStrip:
os << "GL_TRIANGLE_STRIP";
break;
case PrimitiveMode::TriangleStripAdjacency:
os << "GL_TRIANGLE_STRIP_ADJACENCY";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
std::ostream &operator<<(std::ostream &os, DrawElementsType value)
{
switch (value)
{
case DrawElementsType::UnsignedByte:
os << "GL_UNSIGNED_BYTE";
break;
case DrawElementsType::UnsignedShort:
os << "GL_UNSIGNED_SHORT";
break;
case DrawElementsType::UnsignedInt:
os << "GL_UNSIGNED_INT";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
std::ostream &operator<<(std::ostream &os, VertexAttribType value)
{
switch (value)
{
case VertexAttribType::Byte:
os << "GL_UNSIGNED_BYTE";
break;
case VertexAttribType::Fixed:
os << "GL_FIXED";
break;
case VertexAttribType::Float:
os << "GL_FLOAT";
break;
case VertexAttribType::HalfFloat:
os << "GL_HALF_FLOAT";
break;
case VertexAttribType::Int:
os << "GL_INT";
break;
case VertexAttribType::Int2101010:
os << "GL_INT_10_10_10_2";
break;
case VertexAttribType::Short:
os << "GL_SHORT";
break;
case VertexAttribType::UnsignedByte:
os << "GL_UNSIGNED_BYTE";
break;
case VertexAttribType::UnsignedInt:
os << "GL_UNSIGNED_INT";
break;
case VertexAttribType::UnsignedInt2101010:
os << "GL_UNSIGNED_INT_10_10_10_2";
break;
case VertexAttribType::UnsignedShort:
os << "GL_UNSIGNED_SHORT";
break;
default:
os << "GL_INVALID_ENUM";
break;
}
return os;
}
} // namespace gl
namespace egl
......
......@@ -269,6 +269,8 @@ static_assert(ToGLenum(PrimitiveMode::TrianglesAdjacency) == GL_TRIANGLES_ADJACE
static_assert(ToGLenum(PrimitiveMode::TriangleStripAdjacency) == GL_TRIANGLE_STRIP_ADJACENCY,
"PrimitiveMode violation");
std::ostream &operator<<(std::ostream &os, PrimitiveMode value);
enum class DrawElementsType : size_t
{
UnsignedByte = 0,
......@@ -311,6 +313,8 @@ ANGLE_VALIDATE_PACKED_ENUM(DrawElementsType, UnsignedByte, GL_UNSIGNED_BYTE);
ANGLE_VALIDATE_PACKED_ENUM(DrawElementsType, UnsignedShort, GL_UNSIGNED_SHORT);
ANGLE_VALIDATE_PACKED_ENUM(DrawElementsType, UnsignedInt, GL_UNSIGNED_INT);
std::ostream &operator<<(std::ostream &os, DrawElementsType value);
enum class VertexAttribType
{
Byte = 0, // GLenum == 0x1400
......@@ -367,6 +371,8 @@ ANGLE_VALIDATE_PACKED_ENUM(VertexAttribType, HalfFloat, GL_HALF_FLOAT);
ANGLE_VALIDATE_PACKED_ENUM(VertexAttribType, Fixed, GL_FIXED);
ANGLE_VALIDATE_PACKED_ENUM(VertexAttribType, Int2101010, GL_INT_2_10_10_10_REV);
ANGLE_VALIDATE_PACKED_ENUM(VertexAttribType, UnsignedInt2101010, GL_UNSIGNED_INT_2_10_10_10_REV);
std::ostream &operator<<(std::ostream &os, VertexAttribType value);
} // namespace gl
namespace egl
......
......@@ -17,6 +17,7 @@
#include <angle_gl.h>
#include <cstdint>
#include <ostream>
namespace gl
{
......@@ -42,6 +43,7 @@ enum class AlphaTestFunc : uint8_t
template <>
AlphaTestFunc FromGLenum<AlphaTestFunc>(GLenum from);
GLenum ToGLenum(AlphaTestFunc from);
std::ostream &operator<<(std::ostream &os, AlphaTestFunc value);
enum class BufferBinding : uint8_t
{
......@@ -65,6 +67,7 @@ enum class BufferBinding : uint8_t
template <>
BufferBinding FromGLenum<BufferBinding>(GLenum from);
GLenum ToGLenum(BufferBinding from);
std::ostream &operator<<(std::ostream &os, BufferBinding value);
enum class BufferUsage : uint8_t
{
......@@ -85,6 +88,7 @@ enum class BufferUsage : uint8_t
template <>
BufferUsage FromGLenum<BufferUsage>(GLenum from);
GLenum ToGLenum(BufferUsage from);
std::ostream &operator<<(std::ostream &os, BufferUsage value);
enum class ClientVertexArrayType : uint8_t
{
......@@ -101,6 +105,7 @@ enum class ClientVertexArrayType : uint8_t
template <>
ClientVertexArrayType FromGLenum<ClientVertexArrayType>(GLenum from);
GLenum ToGLenum(ClientVertexArrayType from);
std::ostream &operator<<(std::ostream &os, ClientVertexArrayType value);
enum class CullFaceMode : uint8_t
{
......@@ -115,6 +120,7 @@ enum class CullFaceMode : uint8_t
template <>
CullFaceMode FromGLenum<CullFaceMode>(GLenum from);
GLenum ToGLenum(CullFaceMode from);
std::ostream &operator<<(std::ostream &os, CullFaceMode value);
enum class FilterMode : uint8_t
{
......@@ -131,6 +137,7 @@ enum class FilterMode : uint8_t
template <>
FilterMode FromGLenum<FilterMode>(GLenum from);
GLenum ToGLenum(FilterMode from);
std::ostream &operator<<(std::ostream &os, FilterMode value);
enum class FogMode : uint8_t
{
......@@ -145,6 +152,7 @@ enum class FogMode : uint8_t
template <>
FogMode FromGLenum<FogMode>(GLenum from);
GLenum ToGLenum(FogMode from);
std::ostream &operator<<(std::ostream &os, FogMode value);
enum class GraphicsResetStatus : uint8_t
{
......@@ -160,6 +168,7 @@ enum class GraphicsResetStatus : uint8_t
template <>
GraphicsResetStatus FromGLenum<GraphicsResetStatus>(GLenum from);
GLenum ToGLenum(GraphicsResetStatus from);
std::ostream &operator<<(std::ostream &os, GraphicsResetStatus value);
enum class HandleType : uint8_t
{
......@@ -172,6 +181,7 @@ enum class HandleType : uint8_t
template <>
HandleType FromGLenum<HandleType>(GLenum from);
GLenum ToGLenum(HandleType from);
std::ostream &operator<<(std::ostream &os, HandleType value);
enum class HintSetting : uint8_t
{
......@@ -186,6 +196,7 @@ enum class HintSetting : uint8_t
template <>
HintSetting FromGLenum<HintSetting>(GLenum from);
GLenum ToGLenum(HintSetting from);
std::ostream &operator<<(std::ostream &os, HintSetting value);
enum class ImageLayout : uint8_t
{
......@@ -207,6 +218,7 @@ enum class ImageLayout : uint8_t
template <>
ImageLayout FromGLenum<ImageLayout>(GLenum from);
GLenum ToGLenum(ImageLayout from);
std::ostream &operator<<(std::ostream &os, ImageLayout value);
enum class LightParameter : uint8_t
{
......@@ -229,6 +241,7 @@ enum class LightParameter : uint8_t
template <>
LightParameter FromGLenum<LightParameter>(GLenum from);
GLenum ToGLenum(LightParameter from);
std::ostream &operator<<(std::ostream &os, LightParameter value);
enum class LogicalOperation : uint8_t
{
......@@ -256,6 +269,7 @@ enum class LogicalOperation : uint8_t
template <>
LogicalOperation FromGLenum<LogicalOperation>(GLenum from);
GLenum ToGLenum(LogicalOperation from);
std::ostream &operator<<(std::ostream &os, LogicalOperation value);
enum class MaterialParameter : uint8_t
{
......@@ -273,6 +287,7 @@ enum class MaterialParameter : uint8_t
template <>
MaterialParameter FromGLenum<MaterialParameter>(GLenum from);
GLenum ToGLenum(MaterialParameter from);
std::ostream &operator<<(std::ostream &os, MaterialParameter value);
enum class MatrixType : uint8_t
{
......@@ -287,6 +302,7 @@ enum class MatrixType : uint8_t
template <>
MatrixType FromGLenum<MatrixType>(GLenum from);
GLenum ToGLenum(MatrixType from);
std::ostream &operator<<(std::ostream &os, MatrixType value);
enum class PointParameter : uint8_t
{
......@@ -302,6 +318,7 @@ enum class PointParameter : uint8_t
template <>
PointParameter FromGLenum<PointParameter>(GLenum from);
GLenum ToGLenum(PointParameter from);
std::ostream &operator<<(std::ostream &os, PointParameter value);
enum class ProvokingVertex : uint8_t
{
......@@ -315,6 +332,7 @@ enum class ProvokingVertex : uint8_t
template <>
ProvokingVertex FromGLenum<ProvokingVertex>(GLenum from);
GLenum ToGLenum(ProvokingVertex from);
std::ostream &operator<<(std::ostream &os, ProvokingVertex value);
enum class QueryType : uint8_t
{
......@@ -333,6 +351,7 @@ enum class QueryType : uint8_t
template <>
QueryType FromGLenum<QueryType>(GLenum from);
GLenum ToGLenum(QueryType from);
std::ostream &operator<<(std::ostream &os, QueryType value);
enum class ShaderType : uint8_t
{
......@@ -348,6 +367,7 @@ enum class ShaderType : uint8_t
template <>
ShaderType FromGLenum<ShaderType>(GLenum from);
GLenum ToGLenum(ShaderType from);
std::ostream &operator<<(std::ostream &os, ShaderType value);
enum class ShadingModel : uint8_t
{
......@@ -361,6 +381,7 @@ enum class ShadingModel : uint8_t
template <>
ShadingModel FromGLenum<ShadingModel>(GLenum from);
GLenum ToGLenum(ShadingModel from);
std::ostream &operator<<(std::ostream &os, ShadingModel value);
enum class TextureCombine : uint8_t
{
......@@ -380,6 +401,7 @@ enum class TextureCombine : uint8_t
template <>
TextureCombine FromGLenum<TextureCombine>(GLenum from);
GLenum ToGLenum(TextureCombine from);
std::ostream &operator<<(std::ostream &os, TextureCombine value);
enum class TextureEnvMode : uint8_t
{
......@@ -397,6 +419,7 @@ enum class TextureEnvMode : uint8_t
template <>
TextureEnvMode FromGLenum<TextureEnvMode>(GLenum from);
GLenum ToGLenum(TextureEnvMode from);
std::ostream &operator<<(std::ostream &os, TextureEnvMode value);
enum class TextureEnvParameter : uint8_t
{
......@@ -427,6 +450,7 @@ enum class TextureEnvParameter : uint8_t
template <>
TextureEnvParameter FromGLenum<TextureEnvParameter>(GLenum from);
GLenum ToGLenum(TextureEnvParameter from);
std::ostream &operator<<(std::ostream &os, TextureEnvParameter value);
enum class TextureEnvTarget : uint8_t
{
......@@ -440,6 +464,7 @@ enum class TextureEnvTarget : uint8_t
template <>
TextureEnvTarget FromGLenum<TextureEnvTarget>(GLenum from);
GLenum ToGLenum(TextureEnvTarget from);
std::ostream &operator<<(std::ostream &os, TextureEnvTarget value);
enum class TextureOp : uint8_t
{
......@@ -455,6 +480,7 @@ enum class TextureOp : uint8_t
template <>
TextureOp FromGLenum<TextureOp>(GLenum from);
GLenum ToGLenum(TextureOp from);
std::ostream &operator<<(std::ostream &os, TextureOp value);
enum class TextureSrc : uint8_t
{
......@@ -470,6 +496,7 @@ enum class TextureSrc : uint8_t
template <>
TextureSrc FromGLenum<TextureSrc>(GLenum from);
GLenum ToGLenum(TextureSrc from);
std::ostream &operator<<(std::ostream &os, TextureSrc value);
enum class TextureTarget : uint8_t
{
......@@ -494,6 +521,7 @@ enum class TextureTarget : uint8_t
template <>
TextureTarget FromGLenum<TextureTarget>(GLenum from);
GLenum ToGLenum(TextureTarget from);
std::ostream &operator<<(std::ostream &os, TextureTarget value);
enum class TextureType : uint8_t
{
......@@ -513,6 +541,7 @@ enum class TextureType : uint8_t
template <>
TextureType FromGLenum<TextureType>(GLenum from);
GLenum ToGLenum(TextureType from);
std::ostream &operator<<(std::ostream &os, TextureType value);
enum class VertexArrayType : uint8_t
{
......@@ -529,6 +558,7 @@ enum class VertexArrayType : uint8_t
template <>
VertexArrayType FromGLenum<VertexArrayType>(GLenum from);
GLenum ToGLenum(VertexArrayType from);
std::ostream &operator<<(std::ostream &os, VertexArrayType value);
enum class WrapMode : uint8_t
{
......@@ -544,6 +574,7 @@ enum class WrapMode : uint8_t
template <>
WrapMode FromGLenum<WrapMode>(GLenum from);
GLenum ToGLenum(WrapMode from);
std::ostream &operator<<(std::ostream &os, WrapMode value);
} // namespace gl
......
......@@ -77,6 +77,7 @@ header_template = """// GENERATED FILE - DO NOT EDIT.
#include <EGL/eglext.h>
#include <cstdint>
#include <ostream>
namespace {namespace}
{{
......@@ -101,6 +102,7 @@ enum class {enum_name} : uint8_t
template <>
{enum_name} From{api_enum_name}<{enum_name}>({api_enum_name} from);
{api_enum_name} To{api_enum_name}({enum_name} from);
std::ostream &operator<<(std::ostream &os, {enum_name} value);
"""
......@@ -175,6 +177,18 @@ template <>
return 0;
}}
}}
std::ostream &operator<<(std::ostream &os, {enum_name} value)
{{
switch (value)
{{
{ostream_cases}
default:
os << "GL_INVALID_ENUM";
break;
}}
return os;
}}
"""
......@@ -184,12 +198,15 @@ def write_cpp(enums, path_prefix, file_name, data_source_name, namespace, api_en
for enum in enums:
from_glenum_cases = []
to_glenum_cases = []
ostream_cases = []
for value in enum.values:
qualified_name = enum.name + '::' + value.name
from_glenum_cases.append(' case ' + value.gl_name + ':\n return ' +
qualified_name + ';')
to_glenum_cases.append(' case ' + qualified_name + ':\n return ' +
value.gl_name + ';')
ostream_cases.append(' case ' + qualified_name + ':\n os << "' +
value.gl_name + '";\n break;')
content.append(
enum_implementation_template.format(
......@@ -197,7 +214,8 @@ def write_cpp(enums, path_prefix, file_name, data_source_name, namespace, api_en
from_glenum_cases='\n'.join(from_glenum_cases),
max_value=str(enum.max_value),
to_glenum_cases='\n'.join(to_glenum_cases),
api_enum_name=api_enum_name))
api_enum_name=api_enum_name,
ostream_cases='\n'.join(ostream_cases)))
cpp = cpp_template.format(
content=''.join(content),
......
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