summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-12-20 01:59:06 +0200
committerTor Lillqvist <tml@collabora.com>2013-12-20 02:00:18 +0200
commit4cae6fa29a07a238273453cef9d18e4171d430e8 (patch)
tree0d81646ddf5365aa0240e616034a701238bc2b30 /ios
parent18397efd14ba7a06a92f0f11f0f9b603e6d30c05 (diff)
Add tiles per second counter (averaged over last five seconds)
Change-Id: I11e282c1a72dbc6b41a5a89229065983b41eb65b
Diffstat (limited to 'ios')
-rw-r--r--ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m63
-rw-r--r--ios/experimental/TiledLibreOffice/TiledLibreOffice/View.h2
-rw-r--r--ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m17
3 files changed, 80 insertions, 2 deletions
diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m
index 57a13fb2c723..3756cd244d02 100644
--- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m
+++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m
@@ -19,6 +19,60 @@
@implementation TiledView
+static const int NTIMESTAMPS = 100;
+static const CFTimeInterval AVERAGINGTIME = 5;
+
+static CFTimeInterval tileTimestamps[NTIMESTAMPS];
+static int curFirstTimestamp = 0;
+static int curNextTimestamp = 0;
+
+static void dropOldTimestamps(CFTimeInterval now)
+{
+ // Drop too old timestamps
+ while (curFirstTimestamp != curNextTimestamp && now - tileTimestamps[curFirstTimestamp] >= AVERAGINGTIME)
+ curFirstTimestamp = (curFirstTimestamp + 1) % NTIMESTAMPS;
+}
+
+static void updateTilesPerSecond(UILabel *label)
+{
+ int n = (curNextTimestamp < curFirstTimestamp) ?
+ (NTIMESTAMPS - (curFirstTimestamp - curNextTimestamp))
+ : ((curNextTimestamp - curFirstTimestamp));
+
+ // NSLog(@"first:%d next:%d n:%d", curFirstTimestamp, curNextTimestamp, n);
+
+ double tps = n/AVERAGINGTIME;
+
+ [label setText:[NSString stringWithFormat:@"%.0f tiles/second", tps]];
+}
+
+- (void)didRenderTile
+{
+ CFTimeInterval now = CACurrentMediaTime();
+
+ @synchronized(self) {
+ dropOldTimestamps(now);
+
+ // Add new timestamp
+ tileTimestamps[curNextTimestamp] = now;
+ // Let next added replace newest if array full
+ if (curFirstTimestamp != (curNextTimestamp + 1) % NTIMESTAMPS)
+ curNextTimestamp = (curNextTimestamp + 1) % NTIMESTAMPS;
+
+ updateTilesPerSecond(((View *) [self superview]).tpsLabel);
+ }
+}
+
+- (void)updateTilesPerSecond
+{
+ CFTimeInterval now = CACurrentMediaTime();
+
+ @synchronized(self) {
+ dropOldTimestamps(now);
+ updateTilesPerSecond(((View *) [self superview]).tpsLabel);
+ }
+}
+
- (id)initWithFrame:(CGRect)frame scale:(CGFloat)scale maxZoom:(int)maxZoom
{
self = [super initWithFrame:frame];
@@ -28,6 +82,8 @@
catl.tileSize = CGSizeMake(512, 512);
catl.levelsOfDetail = log2(maxZoom) + 1;
catl.levelsOfDetailBias = catl.levelsOfDetail - 1;
+
+ [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTilesPerSecond) userInfo:nil repeats:YES];
}
return self;
}
@@ -44,8 +100,9 @@
// expected it to be called with a bbox of 256x256.
CGRect bb = CGContextGetClipBoundingBox(ctx);
- double zoomScale = [(View *) [self superview] zoomScale];
- CATiledLayer *catl = (CATiledLayer*) [self layer];
+
+ // double zoomScale = [(View *) [self superview] zoomScale];
+ // CATiledLayer *catl = (CATiledLayer*) [self layer];
CGContextSaveGState(ctx);
@@ -70,6 +127,8 @@
CGPointMake(bb.origin.x/self.scale, bb.origin.y/self.scale),
CGSizeMake(bb.size.width/self.scale, bb.size.height/self.scale));
+ [self didRenderTile];
+
CGContextRestoreGState(ctx);
// I am a bit confused about what tiles exactly I am drawing, so
diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.h b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.h
index 3043632d03c9..041471d40071 100644
--- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.h
+++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.h
@@ -10,6 +10,8 @@
@interface View : UIScrollView <UIScrollViewDelegate>
+@property UILabel *tpsLabel;
+
@end
// vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m
index 9291b4561369..8f4741b397f7 100644
--- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m
+++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m
@@ -37,6 +37,14 @@
self.subView = [[TiledView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.width*docAspectRatio) scale:widthScale maxZoom:MAXZOOM];
[self addSubview:self.subView];
+
+ UILabel *tpsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 300, 40)];
+ [tpsLabel setFont:[UIFont systemFontOfSize:38]];
+ [tpsLabel setBackgroundColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]];
+ [tpsLabel setTextColor: [UIColor colorWithRed:1 green:1 blue:0 alpha:1]];
+ [tpsLabel setTextAlignment: NSTextAlignmentRight];
+ [self addSubview:tpsLabel];
+ self.tpsLabel = tpsLabel;
}
return self;
}
@@ -46,6 +54,15 @@
return self.subView;
}
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView
+{
+ CGRect frame = ((View*) scrollView).tpsLabel.frame;
+
+ frame.origin.x = 20 + scrollView.contentOffset.x;
+ frame.origin.y = 20 + scrollView.contentOffset.y;
+ ((View *) scrollView).tpsLabel.frame = frame;
+}
+
@end
// vim:set shiftwidth=4 softtabstop=4 expandtab: