#include "trace_loader.hpp" using namespace trace; Loader::Loader() : m_frameMarker(FrameMarker_SwapBuffers) { } Loader::~Loader() { close(); } Loader::FrameMarker Loader::frameMarker() const { return m_frameMarker; } void Loader::setFrameMarker(Loader::FrameMarker marker) { m_frameMarker = marker; } unsigned Loader::numberOfFrames() const { return m_frameBookmarks.size(); } unsigned Loader::numberOfCallsInFrame(unsigned frameIdx) const { if (frameIdx > m_frameBookmarks.size()) { return 0; } FrameBookmarks::const_iterator itr = m_frameBookmarks.find(frameIdx); return itr->second.numberOfCalls; } bool Loader::open(const char *filename) { if (!m_parser.open(filename)) { std::cerr << "error: failed to open " << filename << "\n"; return false; } if (!m_parser.supportsOffsets()) { std::cerr << "error: " <= 5) { std::cerr << "\tPercent scanned = " << m_parser.percentRead() << "..."<dump(std::cout, color); delete call; } return true; } void Loader::close() { m_parser.close(); } bool Loader::isCallAFrameMarker(const trace::Call *call) const { std::string name = call->name(); switch (m_frameMarker) { case FrameMarker_SwapBuffers: return call->flags & trace::CALL_FLAG_END_FRAME; break; case FrameMarker_Flush: return name == "glFlush"; break; case FrameMarker_Finish: return name == "glFinish"; break; case FrameMarker_Clear: return name == "glClear"; break; } return false; } std::vector Loader::frame(unsigned idx) { unsigned numOfCalls = numberOfCallsInFrame(idx); if (numOfCalls) { const FrameBookmark &frameBookmark = m_frameBookmarks[idx]; std::vector calls(numOfCalls); m_parser.setBookmark(frameBookmark.start); trace::Call *call; unsigned parsedCalls = 0; while ((call = m_parser.parse_call())) { calls[parsedCalls] = call; ++parsedCalls; if (isCallAFrameMarker(call)) { break; } } assert(parsedCalls == numOfCalls); return calls; } return std::vector(); }