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