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)
41 m_columnData[VOGL_ACTC_APICALL] = "API Call";
42 m_columnData[VOGL_ACTC_INDEX] = "Index";
43 m_columnData[VOGL_ACTC_FLAGS] = "";
44 m_columnData[VOGL_ACTC_GLCONTEXT] = "GL Context";
45 //m_ColumnTitles[VOGL_ACTC_BEGINTIME] = "Begin Time";
46 //m_ColumnTitles[VOGL_ACTC_ENDTIME] = "End Time";
47 m_columnData[VOGL_ACTC_DURATION] = "Duration (ns)";
50 // Constructor for frame nodes
51 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* frameItem, vogleditor_apiCallTreeItem* parent)
52 : m_parentItem(parent),
54 m_pFrameItem(frameItem),
58 if (frameItem != NULL)
61 tmp.sprintf("Frame %" PRIu64, frameItem->frameNumber());
62 m_columnData[VOGL_ACTC_APICALL] = tmp;
65 if (m_parentItem != NULL)
67 m_pModel = m_parentItem->m_pModel;
71 // Constructor for apiCall nodes
72 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(QString nodeText, vogleditor_apiCallItem* apiCallItem, vogleditor_apiCallTreeItem* parent)
73 : m_parentItem(parent),
74 m_pApiCallItem(apiCallItem),
79 m_columnData[VOGL_ACTC_APICALL] = nodeText;
81 if (apiCallItem != NULL)
83 m_columnData[VOGL_ACTC_INDEX] = (qulonglong)apiCallItem->globalCallIndex();
84 m_columnData[VOGL_ACTC_FLAGS] = "";
85 dynamic_string strContext;
86 m_columnData[VOGL_ACTC_GLCONTEXT] = strContext.format("0x%" PRIx64, apiCallItem->getGLPacket()->m_context_handle).c_str();
87 //m_columnData[VOGL_ACTC_BEGINTIME] = apiCallItem->startTime();
88 //m_columnData[VOGL_ACTC_ENDTIME] = apiCallItem->endTime();
89 m_columnData[VOGL_ACTC_DURATION] = (qulonglong)apiCallItem->duration();
92 if (m_parentItem != NULL)
94 m_pModel = m_parentItem->m_pModel;
98 vogleditor_apiCallTreeItem::~vogleditor_apiCallTreeItem()
100 if (m_pFrameItem != NULL)
102 vogl_delete(m_pFrameItem);
106 if (m_pApiCallItem != NULL)
108 vogl_delete(m_pApiCallItem);
109 m_pApiCallItem = NULL;
112 for (int i = 0; i < m_childItems.size(); i++)
114 vogl_delete(m_childItems[i]);
115 m_childItems[i] = NULL;
118 m_childItems.clear();
121 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const
126 void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild)
128 pChild->m_localRowIndex = m_childItems.size();
129 m_childItems.append(pChild);
132 int vogleditor_apiCallTreeItem::childCount() const
134 return m_childItems.size();
137 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::child(int index) const
139 if (index < 0 || index >= childCount())
144 return m_childItems[index];
147 vogleditor_apiCallItem* vogleditor_apiCallTreeItem::apiCallItem() const
149 return m_pApiCallItem;
152 vogleditor_frameItem* vogleditor_apiCallTreeItem::frameItem() const
157 void vogleditor_apiCallTreeItem::set_snapshot(vogleditor_gl_state_snapshot* pSnapshot)
161 m_pFrameItem->set_snapshot(pSnapshot);
166 m_pApiCallItem->set_snapshot(pSnapshot);
170 bool vogleditor_apiCallTreeItem::has_snapshot() const
172 bool bHasSnapshot = false;
175 bHasSnapshot = m_pFrameItem->has_snapshot();
180 bHasSnapshot = m_pApiCallItem->has_snapshot();
185 vogleditor_gl_state_snapshot* vogleditor_apiCallTreeItem::get_snapshot() const
187 vogleditor_gl_state_snapshot* pSnapshot = NULL;
190 pSnapshot = m_pFrameItem->get_snapshot();
195 pSnapshot = m_pApiCallItem->get_snapshot();
200 int vogleditor_apiCallTreeItem::columnCount() const
203 if (m_parentItem == NULL)
205 count = VOGL_MAX_ACTC;
209 m_pModel->columnCount();
215 QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
217 if (column >= VOGL_MAX_ACTC)
222 if (role == Qt::DecorationRole)
225 if (column == VOGL_ACTC_FLAGS)
229 if (get_snapshot()->is_outdated())
231 // snapshot was dirtied due to an earlier edit
232 return QColor(200, 0, 0);
234 else if (get_snapshot()->is_edited())
236 // snapshot has been edited
237 return QColor(200, 102, 0);
242 return QColor(0, 0, 255);
248 if (role == Qt::DisplayRole)
250 return m_columnData[column];
256 int vogleditor_apiCallTreeItem::row() const
258 // note, this is just the row within the current level of the hierarchy
259 return m_localRowIndex;