]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_apicalltreeitem.cpp
UI: Improve processing time of vogleditor_apicalltreeitem by pre-calculating the...
[vogl] / src / vogleditor / vogleditor_apicalltreeitem.cpp
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
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 #include "vogleditor_qapicalltreemodel.h"
27
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"
33
34 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_QApiCallTreeModel* pModel)
35  : m_parentItem(NULL),
36    m_pApiCallItem(NULL),
37    m_pFrameItem(NULL),
38    m_pModel(pModel),
39    m_localRowIndex(0)
40 {
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)";
48 }
49
50 // Constructor for frame nodes
51 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* frameItem, vogleditor_apiCallTreeItem* parent)
52  : m_parentItem(parent),
53    m_pApiCallItem(NULL),
54    m_pFrameItem(frameItem),
55    m_pModel(NULL),
56    m_localRowIndex(0)
57 {
58    if (frameItem != NULL)
59    {
60       QString tmp;
61       tmp.sprintf("Frame %" PRIu64, frameItem->frameNumber());
62       m_columnData[VOGL_ACTC_APICALL] = tmp;
63    }
64
65    if (m_parentItem != NULL)
66    {
67       m_pModel = m_parentItem->m_pModel;
68    }
69 }
70
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),
75    m_pFrameItem(NULL),
76    m_pModel(NULL),
77    m_localRowIndex(0)
78 {
79    m_columnData[VOGL_ACTC_APICALL] = nodeText;
80
81    if (apiCallItem != NULL)
82    {
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();
90    }
91
92    if (m_parentItem != NULL)
93    {
94       m_pModel = m_parentItem->m_pModel;
95    }
96 }
97
98 vogleditor_apiCallTreeItem::~vogleditor_apiCallTreeItem()
99 {
100    if (m_pFrameItem != NULL)
101    {
102       delete m_pFrameItem;
103       m_pFrameItem = NULL;
104    }
105
106    if (m_pApiCallItem != NULL)
107    {
108       delete m_pApiCallItem;
109       m_pApiCallItem = NULL;
110    }
111
112    for (int i = 0; i < m_childItems.size(); i++)
113    {
114       delete m_childItems[i];
115       m_childItems[i] = NULL;
116    }
117
118    m_childItems.clear();
119 }
120
121 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const
122 {
123    return m_parentItem;
124 }
125
126 void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild)
127 {
128     pChild->m_localRowIndex = m_childItems.size();
129     m_childItems.append(pChild);
130 }
131
132 int vogleditor_apiCallTreeItem::childCount() const
133 {
134    return m_childItems.size();
135 }
136
137 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::child(int index) const
138 {
139    if (index < 0 || index >= childCount())
140    {
141       return NULL;
142    }
143
144    return m_childItems[index];
145 }
146
147 vogleditor_apiCallItem* vogleditor_apiCallTreeItem::apiCallItem() const
148 {
149    return m_pApiCallItem;
150 }
151
152 vogleditor_frameItem* vogleditor_apiCallTreeItem::frameItem() const
153 {
154    return m_pFrameItem;
155 }
156
157 void vogleditor_apiCallTreeItem::set_snapshot(vogleditor_gl_state_snapshot* pSnapshot)
158 {
159     if (m_pFrameItem)
160     {
161         m_pFrameItem->set_snapshot(pSnapshot);
162     }
163
164     if (m_pApiCallItem)
165     {
166         m_pApiCallItem->set_snapshot(pSnapshot);
167     }
168 }
169
170 bool vogleditor_apiCallTreeItem::has_snapshot() const
171 {
172     bool bHasSnapshot = false;
173     if (m_pFrameItem)
174     {
175         bHasSnapshot = m_pFrameItem->has_snapshot();
176     }
177
178     if (m_pApiCallItem)
179     {
180         bHasSnapshot = m_pApiCallItem->has_snapshot();
181     }
182     return bHasSnapshot;
183 }
184
185 vogleditor_gl_state_snapshot* vogleditor_apiCallTreeItem::get_snapshot() const
186 {
187     vogleditor_gl_state_snapshot* pSnapshot = NULL;
188     if (m_pFrameItem)
189     {
190         pSnapshot = m_pFrameItem->get_snapshot();
191     }
192
193     if (m_pApiCallItem)
194     {
195         pSnapshot = m_pApiCallItem->get_snapshot();
196     }
197     return pSnapshot;
198 }
199
200 int vogleditor_apiCallTreeItem::columnCount() const
201 {
202    int count = 0;
203    if (m_parentItem == NULL)
204    {
205       count = VOGL_MAX_ACTC;
206    }
207    else
208    {
209       m_pModel->columnCount();
210    }
211
212    return count;
213 }
214
215 QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
216 {
217    if (column >= VOGL_MAX_ACTC)
218    {
219       return QVariant();
220    }
221
222    if (role == Qt::DecorationRole)
223    {
224        // handle flags
225        if (column == VOGL_ACTC_FLAGS)
226        {
227            if (has_snapshot())
228            {
229                if (get_snapshot()->is_outdated())
230                {
231                    // snapshot was dirtied due to an earlier edit
232                    return QColor(200, 0, 0);
233                }
234                else if (get_snapshot()->is_edited())
235                {
236                    // snapshot has been edited
237                    return QColor(200, 102, 0);
238                }
239                else
240                {
241                    // snapshot is good
242                    return QColor(0, 0, 255);
243                }
244            }
245        }
246    }
247
248    if (role == Qt::DisplayRole)
249    {
250        return m_columnData[column];
251    }
252
253    return QVariant();
254 }
255
256 int vogleditor_apiCallTreeItem::row() const
257 {
258    // note, this is just the row within the current level of the hierarchy
259    return m_localRowIndex;
260 }