]> git.cworth.org Git - apitrace/blob - retrace/retrace.hpp
retrace: Split ScopedAllocator into its own header.
[apitrace] / retrace / retrace.hpp
1 /**************************************************************************
2  *
3  * Copyright 2011-2012 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef _RETRACE_HPP_
27 #define _RETRACE_HPP_
28
29 #include <assert.h>
30 #include <string.h>
31
32 #include <list>
33 #include <map>
34 #include <ostream>
35
36 #include "trace_model.hpp"
37 #include "trace_parser.hpp"
38 #include "trace_profiler.hpp"
39
40 #include "scoped_allocator.hpp"
41
42
43 namespace image {
44     class Image;
45 }
46
47
48 namespace retrace {
49
50
51 extern trace::Parser parser;
52 extern trace::Profiler profiler;
53
54
55 class ScopedAllocator : public ::ScopedAllocator
56 {
57 public:
58     /**
59      * Allocate an array with the same dimensions as the specified value.
60      */
61     inline void *
62     alloc(const trace::Value *value, size_t size) {
63         const trace::Array *array = dynamic_cast<const trace::Array *>(value);
64         if (array) {
65             return ::ScopedAllocator::alloc(array->size() * size);
66         }
67         const trace::Null *null = dynamic_cast<const trace::Null *>(value);
68         if (null) {
69             return NULL;
70         }
71         assert(0);
72         return NULL;
73     }
74
75 };
76
77
78 /**
79  * Output verbosity when retracing files.
80  */
81 extern int verbosity;
82
83 /**
84  * Debugging checks.
85  */
86 extern bool debug;
87
88 /**
89  * Add profiling data to the dump when retracing.
90  */
91 extern bool profiling;
92 extern bool profilingCpuTimes;
93 extern bool profilingGpuTimes;
94 extern bool profilingPixelsDrawn;
95
96 /**
97  * State dumping.
98  */
99 extern bool dumpingState;
100
101
102 enum Driver {
103     DRIVER_DEFAULT,
104     DRIVER_HARDWARE, // force hardware
105     DRIVER_SOFTWARE,
106     DRIVER_REFERENCE,
107     DRIVER_NULL,
108     DRIVER_MODULE,
109 };
110
111 extern Driver driver;
112 extern const char *driverModule;
113
114 extern bool doubleBuffer;
115 extern bool coreProfile;
116
117 extern unsigned frameNo;
118 extern unsigned callNo;
119
120
121 std::ostream &warning(trace::Call &call);
122
123
124 void ignore(trace::Call &call);
125 void unsupported(trace::Call &call);
126
127
128 typedef void (*Callback)(trace::Call &call);
129
130 struct Entry {
131     const char *name;
132     Callback callback;
133 };
134
135
136 struct stringComparer {
137   bool operator() (const char *a, const  char *b) const {
138     return strcmp(a, b) < 0;
139   }
140 };
141
142
143 extern const Entry stdc_callbacks[];
144
145
146 class Retracer
147 {
148     typedef std::map<const char *, Callback, stringComparer> Map;
149     Map map;
150
151     std::vector<Callback> callbacks;
152
153 public:
154     Retracer() {
155         addCallbacks(stdc_callbacks);
156     }
157
158     virtual ~Retracer() {}
159
160     void addCallback(const Entry *entry);
161     void addCallbacks(const Entry *entries);
162
163     void retrace(trace::Call &call);
164 };
165
166
167 class Dumper
168 {
169 public:
170     virtual image::Image *
171     getSnapshot(void) {
172         return NULL;
173     }
174
175     virtual bool
176     dumpState(std::ostream &os) {
177         return false;
178     }
179 };
180
181
182 extern Dumper *dumper;
183
184
185 void
186 setUp(void);
187
188 void
189 addCallbacks(retrace::Retracer &retracer);
190
191 void
192 frameComplete(trace::Call &call);
193
194
195
196 void
197 flushRendering(void);
198
199 void
200 waitForInput(void);
201
202 void
203 cleanUp(void);
204
205
206 } /* namespace retrace */
207
208 #endif /* _RETRACE_HPP_ */