1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
26 #include "vogleditor_qapicalltreemodel.h"
28 #include "vogl_common.h"
29 #include "vogl_trace_file_reader.h"
30 #include "vogl_trace_packet.h"
31 #include "vogl_trace_stream_types.h"
32 #include "vogleditor_gl_state_snapshot.h"
34 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_QApiCallTreeModel* pModel)
40 m_columnData[VOGL_ACTC_APICALL] = "API Call";
41 m_columnData[VOGL_ACTC_INDEX] = "Index";
42 m_columnData[VOGL_ACTC_FLAGS] = "";
43 m_columnData[VOGL_ACTC_GLCONTEXT] = "GL Context";
44 //m_ColumnTitles[VOGL_ACTC_BEGINTIME] = "Begin Time";
45 //m_ColumnTitles[VOGL_ACTC_ENDTIME] = "End Time";
46 m_columnData[VOGL_ACTC_DURATION] = "Duration (ns)";
49 // Constructor for frame nodes
50 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* frameItem, vogleditor_apiCallTreeItem* parent)
51 : m_parentItem(parent),
53 m_pFrameItem(frameItem),
56 if (frameItem != NULL)
59 tmp.sprintf("Frame %" PRIu64, frameItem->frameNumber());
60 m_columnData[VOGL_ACTC_APICALL] = tmp;
63 if (m_parentItem != NULL)
65 m_pModel = m_parentItem->m_pModel;
69 // Constructor for apiCall nodes
70 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(QString nodeText, vogleditor_apiCallItem* apiCallItem, vogleditor_apiCallTreeItem* parent)
71 : m_parentItem(parent),
72 m_pApiCallItem(apiCallItem),
76 m_columnData[VOGL_ACTC_APICALL] = nodeText;
78 if (apiCallItem != NULL)
80 m_columnData[VOGL_ACTC_INDEX] = (qulonglong)apiCallItem->globalCallIndex();
81 m_columnData[VOGL_ACTC_FLAGS] = "";
82 dynamic_string strContext;
83 m_columnData[VOGL_ACTC_GLCONTEXT] = strContext.format("0x%" PRIx64, apiCallItem->getGLPacket()->m_context_handle).c_str();
84 //m_columnData[VOGL_ACTC_BEGINTIME] = apiCallItem->startTime();
85 //m_columnData[VOGL_ACTC_ENDTIME] = apiCallItem->endTime();
86 m_columnData[VOGL_ACTC_DURATION] = (qulonglong)apiCallItem->duration();
89 if (m_parentItem != NULL)
91 m_pModel = m_parentItem->m_pModel;
95 vogleditor_apiCallTreeItem::~vogleditor_apiCallTreeItem()
97 if (m_pFrameItem != NULL)
103 if (m_pApiCallItem != NULL)
105 delete m_pApiCallItem;
106 m_pApiCallItem = NULL;
109 for (int i = 0; i < m_childItems.size(); i++)
111 delete m_childItems[i];
112 m_childItems[i] = NULL;
115 m_childItems.clear();
118 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const
123 void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild)
125 m_childItems.append(pChild);
128 int vogleditor_apiCallTreeItem::childCount() const
130 return m_childItems.size();
133 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::child(int index) const
135 if (index < 0 || index >= childCount())
140 return m_childItems[index];
143 vogleditor_apiCallItem* vogleditor_apiCallTreeItem::apiCallItem() const
145 return m_pApiCallItem;
148 vogleditor_frameItem* vogleditor_apiCallTreeItem::frameItem() const
153 void vogleditor_apiCallTreeItem::set_snapshot(vogleditor_gl_state_snapshot* pSnapshot)
157 m_pFrameItem->set_snapshot(pSnapshot);
162 m_pApiCallItem->set_snapshot(pSnapshot);
166 bool vogleditor_apiCallTreeItem::has_snapshot() const
168 bool bHasSnapshot = false;
171 bHasSnapshot = m_pFrameItem->has_snapshot();
176 bHasSnapshot = m_pApiCallItem->has_snapshot();
181 vogleditor_gl_state_snapshot* vogleditor_apiCallTreeItem::get_snapshot() const
183 vogleditor_gl_state_snapshot* pSnapshot = NULL;
186 pSnapshot = m_pFrameItem->get_snapshot();
191 pSnapshot = m_pApiCallItem->get_snapshot();
196 int vogleditor_apiCallTreeItem::columnCount() const
199 if (m_parentItem == NULL)
201 count = VOGL_MAX_ACTC;
205 m_pModel->columnCount();
211 QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
213 if (column >= VOGL_MAX_ACTC)
218 if (role == Qt::DecorationRole)
221 if (column == VOGL_ACTC_FLAGS)
225 if (get_snapshot()->is_outdated())
227 // snapshot was dirtied due to an earlier edit
228 return QColor(200, 0, 0);
230 else if (get_snapshot()->is_edited())
232 // snapshot has been edited
233 return QColor(200, 102, 0);
238 return QColor(0, 0, 255);
244 if (role == Qt::DisplayRole)
246 return m_columnData[column];
252 int vogleditor_apiCallTreeItem::row() const
254 // note, this is just the row within the current level of the hierarchy
256 return m_parentItem->m_childItems.indexOf(const_cast<vogleditor_apiCallTreeItem*>(this));