• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
57                        angle::EntryPoint entryPoint) const;
58     void insertMessage(GLenum source,
59                        GLenum type,
60                        GLuint id,
61                        GLenum severity,
62                        std::string &&message,
63                        gl::LogSeverity logSeverity,
64                        angle::EntryPoint entryPoint) const;
65 
66     void setMessageControl(GLenum source,
67                            GLenum type,
68                            GLenum severity,
69                            std::vector<GLuint> &&ids,
70                            bool enabled);
71     size_t getMessages(GLuint count,
72                        GLsizei bufSize,
73                        GLenum *sources,
74                        GLenum *types,
75                        GLuint *ids,
76                        GLenum *severities,
77                        GLsizei *lengths,
78                        GLchar *messageLog);
79     size_t getNextMessageLength() const;
80     size_t getMessageCount() const;
81 
82     void pushGroup(GLenum source, GLuint id, std::string &&message);
83     void popGroup();
84     size_t getGroupStackDepth() const;
85 
86     // Helper for ANGLE_PERF_WARNING
87     void insertPerfWarning(GLenum severity, const char *message, uint32_t *repeatCount) const;
88 
89   private:
90     bool isMessageEnabled(GLenum source, GLenum type, GLuint id, GLenum severity) const;
91 
92     void pushDefaultGroup();
93 
94     struct Message
95     {
96         GLenum source;
97         GLenum type;
98         GLuint id;
99         GLenum severity;
100         std::string message;
101     };
102 
103     struct Control
104     {
105         Control();
106         ~Control();
107         Control(const Control &other);
108 
109         GLenum source;
110         GLenum type;
111         GLenum severity;
112         std::vector<GLuint> ids;
113         bool enabled;
114     };
115 
116     struct Group
117     {
118         Group();
119         ~Group();
120         Group(const Group &other);
121 
122         GLenum source;
123         GLuint id;
124         std::string message;
125 
126         std::vector<Control> controls;
127     };
128 
129     bool mOutputEnabled;
130     GLDEBUGPROCKHR mCallbackFunction;
131     const void *mCallbackUserParam;
132     mutable std::deque<Message> mMessages;
133     GLuint mMaxLoggedMessages;
134     bool mOutputSynchronous;
135     std::vector<Group> mGroups;
136 };
137 }  // namespace gl
138 
139 namespace egl
140 {
141 class LabeledObject
142 {
143   public:
~LabeledObject()144     virtual ~LabeledObject() {}
145     virtual void setLabel(EGLLabelKHR label) = 0;
146     virtual EGLLabelKHR getLabel() const     = 0;
147 };
148 
149 class Debug : angle::NonCopyable
150 {
151   public:
152     Debug();
153 
154     void setCallback(EGLDEBUGPROCKHR callback, const AttributeMap &attribs);
155     EGLDEBUGPROCKHR getCallback() const;
156     bool isMessageTypeEnabled(MessageType type) const;
157 
158     void insertMessage(EGLenum error,
159                        const char *command,
160                        MessageType messageType,
161                        EGLLabelKHR threadLabel,
162                        EGLLabelKHR objectLabel,
163                        const std::string &message) const;
164 
165   private:
166     EGLDEBUGPROCKHR mCallback;
167     angle::PackedEnumBitSet<MessageType> mEnabledMessageTypes;
168 };
169 }  // namespace egl
170 
171 // Generate a perf warning.  Only outputs the same message a few times to avoid spamming the logs.
172 #define ANGLE_PERF_WARNING(debug, severity, message)                 \
173     do                                                               \
174     {                                                                \
175         static uint32_t sRepeatCount = 0;                            \
176         (debug).insertPerfWarning(severity, message, &sRepeatCount); \
177     } while (0)
178 
179 #endif  // LIBANGLE_DEBUG_H_
180