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