Skip to content

Commit 74bf2fe

Browse files
committed
Optimize timeline drawing to avoid fully overlapped message sends and pack times
Previously, EPs were not drawn if they didn't paint any new pixels (which is often the case when zoomed far out, many small EPs can correspond to the same pixel). This generalizes that optimization to message send ticks and pack times. Change-Id: Idfbf97328fb2590c51b47937b6add904f6d8bad1
1 parent e65c9fa commit 74bf2fe

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/projections/Tools/Timeline/EntryMethodObject.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,11 @@ public boolean isDisplayed() {
763763
}
764764

765765

766-
public int paintMe(Graphics2D g2d, int actualDisplayWidth, int maxFilledX){
766+
public boolean paintMe(Graphics2D g2d, int actualDisplayWidth, MainPanel.MaxFilledX maxFilledX){
767+
boolean paintedEP = false;
767768
// If it is hidden, we may not display it
768769
if(!isDisplayed()){
769-
return -1;
770+
return paintedEP;
770771
}
771772

772773
int leftCoord = data.timeToScreenPixel(beginTime, actualDisplayWidth);
@@ -798,7 +799,9 @@ public int paintMe(Graphics2D g2d, int actualDisplayWidth, int maxFilledX){
798799
}
799800

800801
// Only draw this EMO if it covers some pixel that hasn't been filled yet
801-
if (right > maxFilledX) {
802+
if (right > maxFilledX.ep) {
803+
maxFilledX.ep = right;
804+
paintedEP = true;
802805

803806
// Determine the base color
804807
Paint c = determineColor();
@@ -878,7 +881,10 @@ public int paintMe(Graphics2D g2d, int actualDisplayWidth, int maxFilledX){
878881
// Compute the end pixel coordinate relative to the containing panel
879882
int packEndCoordX = data.timeToScreenPixelRight(packEndTime);
880883

881-
g2d.fillRect(packBeginCoordX, topCoord+verticalInset+rectHeight, (packEndCoordX-packBeginCoordX+1), data.messagePackHeight());
884+
if (packEndCoordX > maxFilledX.pack) {
885+
maxFilledX.pack = packEndCoordX;
886+
g2d.fillRect(packBeginCoordX, topCoord + verticalInset + rectHeight, (packEndCoordX - packBeginCoordX + 1), data.messagePackHeight());
887+
}
882888

883889
}
884890
}
@@ -898,13 +904,15 @@ public int paintMe(Graphics2D g2d, int actualDisplayWidth, int maxFilledX){
898904
{
899905
// Compute the pixel coordinate relative to the containing panel
900906
int msgCoordX = data.timeToScreenPixel(msgtime);
901-
902-
g2d.drawLine(msgCoordX, topCoord+verticalInset+rectHeight, msgCoordX, topCoord+verticalInset+rectHeight+data.messageSendHeight());
907+
if (msgCoordX > maxFilledX.msg) {
908+
maxFilledX.msg = msgCoordX;
909+
g2d.drawLine(msgCoordX, topCoord + verticalInset + rectHeight, msgCoordX, topCoord + verticalInset + rectHeight + data.messageSendHeight());
910+
}
903911
}
904912
}
905913
}
906914

907-
return right;
915+
return paintedEP;
908916
}
909917

910918

src/projections/Tools/Timeline/MainPanel.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ public void paintInParallel(Graphics g){
210210

211211
}
212212

213+
/**
214+
* Stores the maximum x coordinates of what has been drawn so far to avoid unnecessary overlapped drawing
215+
*/
216+
public class MaxFilledX {
217+
public int ep, pack, msg;
218+
219+
public MaxFilledX() {
220+
ep = 0;
221+
pack = 0;
222+
msg = 0;
223+
}
224+
}
213225
/**
214226
* Paint the desired clipped region for this component
215227
*
@@ -234,13 +246,14 @@ public long paintAll(Graphics2D g){
234246

235247
if(l != null){ // FIXME: this shouldn't be here but is to fix a race condition with reloading ranges once something is displayed
236248
Iterator<EntryMethodObject> iter = l.iterator(leftClipTime, rightClipTime);
237-
int maxFilledX = 0; // Tracks maximum x index of filled pixels for this PE, used to optimize away
238-
// drawing of multiple overlapping single pixel entry methods
249+
250+
// Saves the furthest right position EPs and msg lines have been drawn in
251+
// order to optimize performance by only drawing when new pixels will be colored in
252+
MaxFilledX maxFilledX = new MaxFilledX();
253+
239254
while(iter.hasNext()){
240255
EntryMethodObject o = iter.next();
241-
int emoMaxFilledX = o.paintMe((Graphics2D) g, getWidth(), maxFilledX);
242-
if (emoMaxFilledX > maxFilledX) {
243-
maxFilledX = emoMaxFilledX;
256+
if(o.paintMe((Graphics2D) g, getWidth(), maxFilledX)) {
244257
count1++;
245258
}
246259
}

0 commit comments

Comments
 (0)