+
+ end = start + duration;
+
+ if (start > m_timeEnd) {
+ return false;
+ }
+
+ if (end < m_time) {
+ return true;
+ }
+
+ double left = timeToPosition(start);
+ double right = timeToPosition(end);
+
+ int leftX = left;
+ int rightX = right;
+
+ bool selected = true;
+
+ if (m_selection.type == SelectProgram) {
+ selected = call.program == m_selection.program;
+ }
+
+ /* Draw last heat if needed */
+ if (leftX != lastX) {
+ drawHeat(painter, lastX, heat, gpu, selected);
+ lastX = leftX;
+ heat = 0;
+ }
+
+ if (rightX <= leftX + 1) {
+ if (rightX == lastX) {
+ /* Fully contained in this X */
+ heat += duration;
+ } else {
+ /* Split call time between the two pixels it occupies */
+ int64_t time = positionToTime(rightX);
+ heat += time - start;
+
+ drawHeat(painter, lastX, heat, gpu, selected);
+
+ heat = end - time;
+ lastX = rightX;
+ }
+ } else {
+ QRect rect;
+ rect.setLeft(left + 0.5);
+ rect.setWidth(right - left);
+ rect.setTop(0);
+ rect.setHeight(m_rowHeight);
+
+ if (m_selection.type == SelectTime) {
+ selected = (start >= m_selection.timeStart && start <= m_selection.timeEnd)
+ || (end >= m_selection.timeStart && end <= m_selection.timeEnd);
+ }
+
+ /* Draw background rect */
+ if (selected) {
+ if (gpu) {
+ painter.fillRect(rect, m_itemGpuBackground);
+ } else {
+ painter.fillRect(rect, m_itemCpuBackground);
+ }
+ } else {
+ painter.fillRect(rect, m_itemDeselectedBackground);
+ }
+
+ /* If wide enough, draw text */
+ if (rect.width() > 6) {
+ rect.adjust(1, 0, -1, -2);
+
+ if (selected) {
+ if (gpu) {
+ painter.setPen(m_itemGpuForeground);
+ } else {
+ painter.setPen(m_itemCpuForeground);
+ }
+ } else {
+ painter.setPen(m_itemDeselectedForeground);
+ }
+
+ painter.drawText(rect,
+ Qt::AlignLeft | Qt::AlignVCenter,
+ painter.fontMetrics().elidedText(QString::fromStdString(call.name), Qt::ElideRight, rect.width()));
+ }
+ }
+
+ return true;