1 // 2 // Copyright 2015 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 // Debug.h: Defines debug state used for GL_KHR_debug 8 9 #ifndef LIBANGLE_DEBUG_H_ 10 #define LIBANGLE_DEBUG_H_ 11 12 #include "angle_gl.h" 13 #include "common/PackedEnums.h" 14 #include "common/angleutils.h" 15 #include "libANGLE/AttributeMap.h" 16 17 #include <deque> 18 #include <string> 19 #include <vector> 20 21 namespace gl 22 { 23 class Context; 24 25 class LabeledObject 26 { 27 public: ~LabeledObject()28 virtual ~LabeledObject() {} 29 virtual void setLabel(const Context *context, const std::string &label) = 0; 30 virtual const std::string &getLabel() const = 0; 31 }; 32 33 class Debug : angle::NonCopyable 34 { 35 public: 36 Debug(bool initialDebugState); 37 ~Debug(); 38 39 void setMaxLoggedMessages(GLuint maxLoggedMessages); 40 41 void setOutputEnabled(bool enabled); 42 bool isOutputEnabled() const; 43 44 void setOutputSynchronous(bool synchronous); 45 bool isOutputSynchronous() const; 46 47 void setCallback(GLDEBUGPROCKHR callback, const void *userParam); 48 GLDEBUGPROCKHR getCallback() const; 49 const void *getUserParam() const; 50 51 void insertMessage(GLenum source, 52 GLenum type, 53 GLuint id, 54 GLenum severity, 55 const std::string &message, 56 gl::LogSeverity logSeverity) const; 57 void insertMessage(GLenum source, 58 GLenum type, 59 GLuint id, 60 GLenum severity, 61 std::string &&message, 62 gl::LogSeverity logSeverity) const; 63 64 void setMessageControl(GLenum source, 65 GLenum type, 66 GLenum severity, 67 std::vector<GLuint> &&ids, 68 bool enabled); 69 size_t getMessages(GLuint count, 70 GLsizei bufSize, 71 GLenum *sources, 72 GLenum *types, 73 GLuint *ids, 74 GLenum *severities, 75 GLsizei *lengths, 76 GLchar *messageLog); 77 size_t getNextMessageLength() const; 78 size_t getMessageCount() const; 79 80 void pushGroup(GLenum source, GLuint id, std::string &&message); 81 void popGroup(); 82 size_t getGroupStackDepth() const; 83 84 // Helper for ANGLE_PERF_WARNING 85 void insertPerfWarning(GLenum severity, const char *message, uint32_t *repeatCount) const; 86 87 private: 88 bool isMessageEnabled(GLenum source, GLenum type, GLuint id, GLenum severity) const; 89 90 void pushDefaultGroup(); 91 92 struct Message 93 { 94 GLenum source; 95 GLenum type; 96 GLuint id; 97 GLenum severity; 98 std::string message; 99 }; 100 101 struct Control 102 { 103 Control(); 104 ~Control(); 105 Control(const Control &other); 106 107 GLenum source; 108 GLenum type; 109 GLenum severity; 110 std::vector<GLuint> ids; 111 bool enabled; 112 }; 113 114 struct Group 115 { 116 Group(); 117 ~Group(); 118 Group(const Group &other); 119 120 GLenum source; 121 GLuint id; 122 std::string message; 123 124 std::vector<Control> controls; 125 }; 126 127 bool mOutputEnabled; 128 GLDEBUGPROCKHR mCallbackFunction; 129 const void *mCallbackUserParam; 130 mutable std::deque<Message> mMessages; 131 GLuint mMaxLoggedMessages; 132 bool mOutputSynchronous; 133 std::vector<Group> mGroups; 134 }; 135 } // namespace gl 136 137 namespace egl 138 { 139 class LabeledObject 140 { 141 public: ~LabeledObject()142 virtual ~LabeledObject() {} 143 virtual void setLabel(EGLLabelKHR label) = 0; 144 virtual EGLLabelKHR getLabel() const = 0; 145 }; 146 147 class Debug : angle::NonCopyable 148 { 149 public: 150 Debug(); 151 152 void setCallback(EGLDEBUGPROCKHR callback, const AttributeMap &attribs); 153 EGLDEBUGPROCKHR getCallback() const; 154 bool isMessageTypeEnabled(MessageType type) const; 155 156 void insertMessage(EGLenum error, 157 const char *command, 158 MessageType messageType, 159 EGLLabelKHR threadLabel, 160 EGLLabelKHR objectLabel, 161 const std::string &message) const; 162 163 private: 164 EGLDEBUGPROCKHR mCallback; 165 angle::PackedEnumBitSet<MessageType> mEnabledMessageTypes; 166 }; 167 } // namespace egl 168 169 // Generate a perf warning. Only outputs the same message a few times to avoid spamming the logs. 170 #define ANGLE_PERF_WARNING(debug, severity, message) \ 171 do \ 172 { \ 173 static uint32_t sRepeatCount = 0; \ 174 (debug).insertPerfWarning(severity, message, &sRepeatCount); \ 175 } while (0) 176 177 #endif // LIBANGLE_DEBUG_H_ 178