forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventBrowser.cs
More file actions
1405 lines (1105 loc) · 43.5 KB
/
EventBrowser.cs
File metadata and controls
1405 lines (1105 loc) · 43.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015-2017 Baldur Karlsson
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using renderdocui.Code;
using renderdoc;
using System.IO;
namespace renderdocui.Windows
{
public partial class EventBrowser : DockContent, ILogViewerForm
{
class DeferredEvent
{
public UInt32 eventID = 0;
public bool marker = false;
}
private TreelistView.Node m_FrameNode = null;
Dictionary<uint, List<CounterResult>> m_Times = new Dictionary<uint, List<CounterResult>>();
private Core m_Core;
public EventBrowser(Core core)
{
InitializeComponent();
if (SystemInformation.HighContrast)
{
toolStrip1.Renderer = new ToolStripSystemRenderer();
jumpStrip.Renderer = new ToolStripSystemRenderer();
findStrip.Renderer = new ToolStripSystemRenderer();
bookmarkStrip.Renderer = new ToolStripSystemRenderer();
}
Icon = global::renderdocui.Properties.Resources.icon;
jumpToEID.Font =
findEvent.Font =
eventView.Font =
core.Config.PreferredFont;
HideJumpAndFind();
ClearBookmarks();
m_Core = core;
DockHandler.GetPersistStringCallback = PersistString;
var col = eventView.Columns["Drawcall"]; eventView.Columns.SetVisibleIndex(col, -1);
col = eventView.Columns["Duration"]; eventView.Columns.SetVisibleIndex(col, -1);
UpdateDurationColumn();
eventView.CellPainter.CellDataConverter = DataToString;
findEventButton.Enabled = false;
jumpEventButton.Enabled = false;
timeDraws.Enabled = false;
toggleBookmark.Enabled = false;
export.Enabled = false;
}
public class PersistData
{
public static int currentPersistVersion = 1;
public int persistVersion = currentPersistVersion;
public struct ColumnArrangement
{
public string fieldname;
public int visibleindex;
public int width;
};
public List<ColumnArrangement> visibleColumns = new List<ColumnArrangement>();
public static PersistData GetDefaults(TreelistView.TreeListView view)
{
PersistData data = new PersistData();
foreach (var c in view.Columns)
{
ColumnArrangement a = new ColumnArrangement();
a.fieldname = c.Fieldname;
a.visibleindex = c.VisibleIndex;
a.width = c.Width;
data.visibleColumns.Add(a);
}
return data;
}
}
public void InitFromPersistString(string str)
{
PersistData data = null;
try
{
if (str.Length > GetType().ToString().Length)
{
var reader = new StringReader(str.Substring(GetType().ToString().Length));
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(PersistData));
data = (PersistData)xs.Deserialize(reader);
reader.Close();
}
}
catch (System.Xml.XmlException)
{
}
catch (InvalidOperationException)
{
// don't need to handle it. Leave data null and pick up defaults below
}
if (data == null || data.persistVersion != PersistData.currentPersistVersion)
{
data = PersistData.GetDefaults(eventView);
}
ApplyPersistData(data);
}
private void ApplyPersistData(PersistData data)
{
// loop twice because first time will ensure the right columns are visible but
// e.g. if the first column we grabbed should be in visibleindex 2, it would
// get shown and be forced to 0 (arbitrary example). Second pass ensures the
// order is correct
for (int i = 0; i < 2; i++)
{
foreach (var c in data.visibleColumns)
{
var col = eventView.Columns[c.fieldname];
if (col == null) continue;
eventView.Columns.SetVisibleIndex(col, c.visibleindex);
if (i == 1)
col.Width = c.width;
}
}
}
private string PersistString()
{
var writer = new StringWriter();
writer.Write(GetType().ToString());
PersistData data = PersistData.GetDefaults(eventView);
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(PersistData));
xs.Serialize(writer, data);
return writer.ToString();
}
private PersistantConfig.TimeUnit m_TimeUnit = PersistantConfig.TimeUnit.Microseconds;
private void UpdateDurationColumn()
{
m_TimeUnit = m_Core.Config.EventBrowser_TimeUnit;
string durationString = PersistantConfig.UnitPrefix(m_TimeUnit);
eventView.Columns["Duration"].Caption = String.Format("Duration ({0})", durationString);
}
private string DataToString(TreelistView.TreeListColumn column, object data)
{
if (column.Fieldname == "Duration")
{
double f = (double)data;
if (f < 0.0)
return "";
if (m_Core.Config.EventBrowser_TimeUnit != m_TimeUnit)
UpdateDurationColumn();
if (m_Core.Config.EventBrowser_TimeUnit == PersistantConfig.TimeUnit.Milliseconds)
f *= 1000.0;
else if (m_Core.Config.EventBrowser_TimeUnit == PersistantConfig.TimeUnit.Microseconds)
f *= 1000000.0;
else if (m_Core.Config.EventBrowser_TimeUnit == PersistantConfig.TimeUnit.Nanoseconds)
f *= 1000000000.0;
return Formatter.Format(f);
}
return data.ToString();
}
private TreelistView.Node MakeMarker(string text)
{
return new TreelistView.Node(new object[] { "", "", text, -1.0 });
}
private TreelistView.Node MakeNode(UInt32 minEID, UInt32 maxEID, UInt32 minDraw, UInt32 maxDraw, string text, double duration)
{
string eidString = (maxEID == minEID) ? maxEID.ToString() : String.Format("{0}-{1}", minEID, maxEID);
string drawString = (maxDraw == minDraw) ? maxDraw.ToString() : String.Format("{0}-{1}", minDraw, maxDraw);
return new TreelistView.Node(new object[] {eidString, drawString, text.Replace("&", "&&"), duration });
}
private TreelistView.Node MakeNode(UInt32 EID, UInt32 draw, string text, double duration)
{
return new TreelistView.Node(new object[] { EID, draw, text.Replace("&", "&&"), duration });
}
private uint GetEndEventID(FetchDrawcall drawcall)
{
if (drawcall.children.Length == 0)
return drawcall.eventID;
return GetEndEventID(drawcall.children.Last());
}
private uint GetEndDrawID(FetchDrawcall drawcall)
{
if (drawcall.children.Length == 0)
return drawcall.drawcallID;
return GetEndDrawID(drawcall.children.Last());
}
public static bool ShouldHide(Core core, FetchDrawcall drawcall)
{
if (drawcall.flags.HasFlag(DrawcallFlags.PushMarker))
{
if (core.Config.EventBrowser_HideEmpty)
{
if (drawcall.children == null || drawcall.children.Length == 0)
return true;
bool allhidden = true;
foreach (FetchDrawcall child in drawcall.children)
{
if (ShouldHide(core, child))
continue;
allhidden = false;
break;
}
if (allhidden)
return true;
}
if (core.Config.EventBrowser_HideAPICalls)
{
if (drawcall.children == null || drawcall.children.Length == 0)
return false;
bool onlyapi = true;
foreach (FetchDrawcall child in drawcall.children)
{
if (ShouldHide(core, child))
continue;
if (!child.flags.HasFlag(DrawcallFlags.APICalls))
{
onlyapi = false;
break;
}
}
if (onlyapi)
return true;
}
}
return false;
}
private TreelistView.Node AddDrawcall(FetchDrawcall drawcall, TreelistView.Node root)
{
if (EventBrowser.ShouldHide(m_Core, drawcall))
return null;
UInt32 eventNum = drawcall.eventID;
TreelistView.Node drawNode = null;
if(drawcall.children.Length > 0)
drawNode = MakeNode(eventNum, GetEndEventID(drawcall), drawcall.drawcallID, GetEndDrawID(drawcall), drawcall.name, 0.0);
else
drawNode = MakeNode(eventNum, drawcall.drawcallID, drawcall.name, 0.0);
if (m_Core.Config.EventBrowser_ApplyColours)
{
// if alpha isn't 0, assume the colour is valid
if ((drawcall.flags & (DrawcallFlags.PushMarker | DrawcallFlags.SetMarker)) > 0 && drawcall.markerColour[3] > 0.0f)
{
float red = drawcall.markerColour[0];
float green = drawcall.markerColour[1];
float blue = drawcall.markerColour[2];
float alpha = drawcall.markerColour[3];
drawNode.TreeLineColor = drawcall.GetColor();
drawNode.TreeLineWidth = 3.0f;
if (m_Core.Config.EventBrowser_ColourEventRow)
{
drawNode.BackColor = drawcall.GetColor();
drawNode.ForeColor = drawcall.GetTextColor(eventView.ForeColor);
}
}
}
DeferredEvent def = new DeferredEvent();
def.eventID = eventNum;
def.marker = (drawcall.flags & DrawcallFlags.SetMarker) != 0;
drawNode.Tag = def;
if (drawcall.children != null && drawcall.children.Length > 0)
{
for (int i = 0; i < drawcall.children.Length; i++)
{
AddDrawcall(drawcall.children[i], drawNode);
if (i > 0 && drawNode.Nodes.Count >= 2 &&
(drawcall.children[i - 1].flags & DrawcallFlags.SetMarker) > 0)
{
DeferredEvent markerTag = drawNode.Nodes[drawNode.Nodes.Count - 2].Tag as DeferredEvent;
DeferredEvent drawTag = drawNode.Nodes.LastNode.Tag as DeferredEvent;
markerTag.eventID = drawTag.eventID;
}
}
bool found = false;
for (int i = drawNode.Nodes.Count - 1; i >= 0; i--)
{
DeferredEvent t = drawNode.Nodes[i].Tag as DeferredEvent;
if (t != null && !t.marker)
{
drawNode.Tag = drawNode.Nodes[i].Tag;
found = true;
break;
}
}
if (!found && !drawNode.Nodes.IsEmpty())
drawNode.Tag = drawNode.Nodes.LastNode.Tag;
}
if (drawNode.Nodes.IsEmpty() && (drawcall.flags & DrawcallFlags.PushMarker) != 0 && m_Core.Config.EventBrowser_HideEmpty)
return null;
root.Nodes.Add(drawNode);
return drawNode;
}
private uint GetNodeEventID(TreelistView.Node n)
{
DeferredEvent def = n.Tag as DeferredEvent;
if (def != null)
return def.eventID;
return 0;
}
private void SetDrawcallTimes(TreelistView.Node n, Dictionary<uint, List<CounterResult>> times)
{
if (n == null || times == null) return;
// parent nodes take the value of the sum of their children
double duration = 0.0;
// look up leaf nodes in the dictionary
if (n.Nodes.IsEmpty())
{
uint eid = GetNodeEventID(n);
DeferredEvent def = n.Tag as DeferredEvent;
if (def != null && def.marker)
duration = -1.0;
else if (times.ContainsKey(eid))
duration = times[eid][0].value.d;
else
duration = -1.0;
n["Duration"] = duration;
return;
}
for (int i = 0; i < n.Nodes.Count; i++)
{
SetDrawcallTimes(n.Nodes[i], times);
double nd = (double)n.Nodes[i]["Duration"];
if(nd > 0.0)
duration += nd;
}
n["Duration"] = duration;
}
private void AddFrameDrawcalls(TreelistView.Node frame, FetchDrawcall[] drawcalls)
{
eventView.BeginUpdate();
frame["Duration"] = -1.0;
DeferredEvent startEv = new DeferredEvent();
startEv.eventID = 0;
frame.Nodes.Clear();
frame.Nodes.Add(MakeNode(0, 0, "Frame Start", -1.0)).Tag = startEv;
for (int i = 0; i < drawcalls.Length; i++)
AddDrawcall(drawcalls[i], frame);
frame.Tag = frame.Nodes.LastNode.Tag;
eventView.EndUpdate();
}
public void OnLogfileClosed()
{
eventView.BeginUpdate();
eventView.Nodes.Clear();
m_FrameNode = null;
eventView.EndUpdate();
prevDraw.Enabled = false;
nextDraw.Enabled = false;
ClearBookmarks();
findEventButton.Enabled = false;
jumpEventButton.Enabled = false;
timeDraws.Enabled = false;
toggleBookmark.Enabled = false;
export.Enabled = false;
}
public void OnLogfileLoaded()
{
findEventButton.Enabled = true;
jumpEventButton.Enabled = true;
timeDraws.Enabled = true;
toggleBookmark.Enabled = true;
export.Enabled = true;
prevDraw.Enabled = false;
nextDraw.Enabled = false;
ClearBookmarks();
eventView.BeginUpdate();
eventView.Nodes.Clear();
{
m_FrameNode = eventView.Nodes.Add(MakeMarker("Frame #" + m_Core.FrameInfo.frameNumber.ToString()));
AddFrameDrawcalls(m_FrameNode, m_Core.GetDrawcalls());
}
eventView.EndUpdate();
{
// frame 1 -> event 1
TreelistView.Node node = eventView.Nodes[0].Nodes[0];
ExpandNode(node);
DeferredEvent evt = eventView.Nodes[0].Nodes.LastNode.Tag as DeferredEvent;
m_Core.SetEventID(null, evt.eventID + 1);
m_FrameNode.Tag = evt;
eventView.NodesSelection.Clear();
eventView.NodesSelection.Add(eventView.Nodes[0]);
eventView.FocusedNode = eventView.Nodes[0];
}
}
public void ExpandNode(TreelistView.Node node)
{
var n = node;
while (node != null)
{
node.Expand();
node = node.Parent;
}
eventView.EnsureVisible(n);
}
private bool FindEventNode(ref TreelistView.Node found, TreelistView.NodeCollection nodes, UInt32 eventID)
{
foreach (var n in nodes)
{
DeferredEvent ndef = n.Tag is DeferredEvent ? n.Tag as DeferredEvent : null;
DeferredEvent fdef = found != null && found.Tag is DeferredEvent ? found.Tag as DeferredEvent : null;
if (ndef != null)
{
if (ndef.eventID >= eventID && (found == null || ndef.eventID <= fdef.eventID))
found = n;
if (ndef.eventID == eventID && n.Nodes.Count == 0)
return true;
}
if (n.Nodes.Count > 0)
{
bool exact = FindEventNode(ref found, n.Nodes, eventID);
if (exact) return true;
}
}
return false;
}
private bool FindEventNode(ref TreelistView.Node found, UInt32 eventID)
{
bool ret = FindEventNode(ref found, eventView.Nodes[0].Nodes, eventID);
while (found != null && found.NextSibling != null && found.NextSibling.Tag is DeferredEvent)
{
DeferredEvent def = found.NextSibling.Tag as DeferredEvent;
if (def.eventID == eventID)
found = found.NextSibling;
else
break;
}
return ret;
}
private bool SelectEvent(UInt32 eventID)
{
if (eventView.Nodes.Count == 0) return false;
TreelistView.Node found = null;
FindEventNode(ref found, eventID);
if (found != null)
{
eventView.FocusedNode = found;
ExpandNode(found);
return true;
}
return false;
}
private void ClearFindIcons(TreelistView.NodeCollection nodes)
{
foreach (var n in nodes)
{
if (!IsBookmarked(GetNodeEventID(n)))
n.Image = null;
if (n.Nodes.Count > 0)
{
ClearFindIcons(n.Nodes);
}
}
}
private void ClearFindIcons()
{
if (eventView.Nodes.Count > 0)
{
ClearFindIcons(eventView.Nodes[0].Nodes);
eventView.Invalidate();
}
}
private int SetFindIcons(TreelistView.NodeCollection nodes, string filter)
{
int results = 0;
foreach (var n in nodes)
{
if (n.Tag is DeferredEvent)
{
if (n["Name"].ToString().ToUpperInvariant().Contains(filter))
{
if (!IsBookmarked(GetNodeEventID(n)))
n.Image = global::renderdocui.Properties.Resources.find;
results++;
}
}
if (n.Nodes.Count > 0)
{
results += SetFindIcons(n.Nodes, filter);
}
}
return results;
}
private int SetFindIcons(string filter)
{
if (filter.Length == 0)
return 0;
return SetFindIcons(eventView.Nodes[0].Nodes, filter.ToUpperInvariant());
}
private TreelistView.Node FindNode(TreelistView.NodeCollection nodes, string filter, UInt32 after)
{
foreach (var n in nodes)
{
if (n.Tag is DeferredEvent)
{
if (GetNodeEventID(n) > after && n["Name"].ToString().ToUpperInvariant().Contains(filter))
return n;
}
if (n.Nodes.Count > 0)
{
TreelistView.Node found = FindNode(n.Nodes, filter, after);
if (found != null)
return found;
}
}
return null;
}
private int FindEvent(TreelistView.NodeCollection nodes, string filter, UInt32 after, bool forward)
{
if(nodes == null) return -1;
for (int i = forward ? 0 : nodes.Count - 1;
i >= 0 && i < nodes.Count;
i += forward ? 1 : -1)
{
var n = nodes[i];
if (n.Tag is DeferredEvent)
{
DeferredEvent def = n.Tag as DeferredEvent;
bool matchesAfter = (forward && def.eventID > after) || (!forward && def.eventID < after);
if (matchesAfter && n["Name"].ToString().ToUpperInvariant().Contains(filter))
return (int)def.eventID;
}
if (n.Nodes.Count > 0)
{
int found = FindEvent(n.Nodes, filter, after, forward);
if (found > 0)
return found;
}
}
return -1;
}
private int FindEvent(string filter, UInt32 after, bool forward)
{
if (eventView.Nodes.Count == 0)
return 0;
return FindEvent(eventView.Nodes[0].Nodes, filter.ToUpperInvariant(), after, forward);
}
public void OnEventSelected(UInt32 eventID)
{
SelectEvent(eventID);
HighlightBookmarks();
Invalidate();
}
private void eventView_AfterSelect(object sender, TreeViewEventArgs e)
{
prevDraw.Enabled = false;
nextDraw.Enabled = false;
if (eventView.SelectedNode.Tag != null)
{
DeferredEvent def = eventView.SelectedNode.Tag as DeferredEvent;
m_Core.SetEventID(this, def.eventID);
FetchDrawcall draw = m_Core.CurDrawcall;
if (draw != null && draw.previous != null)
prevDraw.Enabled = true;
if (draw != null && draw.next != null)
nextDraw.Enabled = true;
}
HighlightBookmarks();
}
private void ShowJump()
{
HideJumpAndFind();
jumpStrip.Visible = true;
findStrip.Visible = false;
jumpToEID.Text = "";
jumpToEID.Focus();
}
private void ShowFind()
{
if(!findStrip.Visible)
HideJumpAndFind();
jumpStrip.Visible = false;
findStrip.Visible = true;
findEvent.Focus();
findEvent.BackColor = SystemColors.Window;
}
private void HideJumpAndFind()
{
jumpStrip.Visible = false;
findStrip.Visible = false;
ClearFindIcons();
}
private void eventView_KeyDown(object sender, KeyEventArgs e)
{
if (!m_Core.LogLoaded) return;
if (e.KeyCode == Keys.F3)
{
if(e.Shift)
Find(false);
else
Find(true);
}
if(e.Control)
{
Keys[] digits = { Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5,
Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.D0 };
for (int i = 0; i < 10; i++)
{
if (e.KeyCode == digits[i])
{
if (HasBookmark(i))
{
SelectEvent(GetBookmark(i));
}
}
}
if (e.KeyCode == Keys.B)
{
ToggleBookmark(m_Core.CurEvent);
}
if (e.KeyCode == Keys.G)
{
ShowJump();
}
if (e.KeyCode == Keys.F)
{
ShowFind();
}
if (e.KeyCode == Keys.T)
{
TimeDrawcalls();
}
if (e.KeyCode == Keys.C)
{
string text = "";
for (int i = 0; i < eventView.FocusedNode.Count; i++)
{
text += DataToString(eventView.Columns[i], eventView.FocusedNode[i]) + " ";
}
text += Environment.NewLine;
try
{
if (text.Length > 0)
Clipboard.SetText(text);
}
catch (System.Exception)
{
try
{
if (text.Length > 0)
Clipboard.SetDataObject(text);
}
catch (System.Exception)
{
// give up!
}
}
}
}
}
private void SelectColumns()
{
var columns = new Dictionary<string, bool>();
foreach (var c in eventView.Columns)
columns.Add(c.Fieldname, c.VisibleIndex >= 0);
var cs = new Dialogs.ColumnSelector(columns, "Name");
var result = cs.ShowDialog();
if (result == DialogResult.OK)
{
columns = cs.GetColumnValues();
foreach (var c in columns)
{
var col = eventView.Columns[c.Key];
if (col == null) continue;
if (!c.Value && col.VisibleIndex >= 0)
eventView.Columns.SetVisibleIndex(col, -1);
else if (c.Value && col.VisibleIndex < 0)
eventView.Columns.SetVisibleIndex(col, eventView.Columns.VisibleColumns.Length);
}
}
}
private void TimeDrawcalls()
{
m_Core.Renderer.BeginInvoke((ReplayRenderer r) =>
{
uint[] counters = { (uint)GPUCounters.EventGPUDuration };
var avail = r.EnumerateCounters();
var desc = r.DescribeCounter(counters[0]);
m_Times = r.FetchCounters(counters);
BeginInvoke((MethodInvoker)delegate
{
var col = eventView.Columns["Duration"];
if (col.VisibleIndex == -1)
{
eventView.Columns.SetVisibleIndex(col, eventView.Columns.VisibleColumns.Length);
}
eventView.BeginUpdate();
SetDrawcallTimes(m_FrameNode, m_Times);
eventView.EndUpdate();
});
});
}
private void jumpFind_Leave(object sender, EventArgs e)
{
if (findEvent.Text == "")
{
HideJumpAndFind();
}
}
private void jumpToEID_TextChanged(object sender, EventArgs e)
{
/*
UInt32 eid = 0;
if (UInt32.TryParse(jumpToEID.Text, out eid))
{
SelectEvent(0, eid);
}
*/
}
private void findEvent_TextChanged(object sender, EventArgs e)
{
if (findEvent.Text.Length > 0)
{
findHighlight.Enabled = false;
findHighlight.Enabled = true;
}
else
{
findHighlight.Enabled = false;
findEvent.BackColor = SystemColors.Window;
ClearFindIcons();
}
}
private void findHighlight_Tick(object sender, EventArgs e)
{
if (findEvent.Text.Length == 0)
{
findEvent.BackColor = SystemColors.Window;
ClearFindIcons();
}
ClearFindIcons();
int results = SetFindIcons(findEvent.Text);
if (results > 0)
findEvent.BackColor = SystemColors.Window;
else
findEvent.BackColor = Color.Red;
findHighlight.Enabled = false;
}
private void findEvent_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F3)
{
if (findHighlight.Enabled)
findHighlight.Enabled = false;
findHighlight_Tick(sender, null);
if (findEvent.Text.Length > 0)
{
Find(e.Shift ? false : true);
}
e.Handled = true;
}
}
private void findEvent_KeyPress(object sender, KeyPressEventArgs e)
{
// escape key
if (e.KeyChar == '\0')
{
findHighlight.Enabled = false;
HideJumpAndFind();
eventView.Focus();
e.Handled = true;
}
if (e.KeyChar == '\n' || e.KeyChar == '\r')
{
if (findHighlight.Enabled)
findHighlight.Enabled = false;
findHighlight_Tick(sender, null);
if (findEvent.Text.Length > 0)
{