Mercurial > hg > svgui
comparison layer/ScrollableImageCache.cpp @ 1164:f2f43802718b 3.0-integration
More timings and cache hit counts
author | Chris Cannam |
---|---|
date | Thu, 10 Nov 2016 09:58:28 +0000 |
parents | c53ed1a6fcbd |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
1163:ab169938832a | 1164:f2f43802718b |
---|---|
12 COPYING included with this distribution for more information. | 12 COPYING included with this distribution for more information. |
13 */ | 13 */ |
14 | 14 |
15 #include "ScrollableImageCache.h" | 15 #include "ScrollableImageCache.h" |
16 | 16 |
17 #include "base/HitCount.h" | |
18 | |
17 #include <iostream> | 19 #include <iostream> |
18 using namespace std; | 20 using namespace std; |
19 | 21 |
20 //#define DEBUG_SCROLLABLE_IMAGE_CACHE 1 | 22 //#define DEBUG_SCROLLABLE_IMAGE_CACHE 1 |
21 | 23 |
22 void | 24 void |
23 ScrollableImageCache::scrollTo(const LayerGeometryProvider *v, | 25 ScrollableImageCache::scrollTo(const LayerGeometryProvider *v, |
24 sv_frame_t newStartFrame) | 26 sv_frame_t newStartFrame) |
25 { | 27 { |
28 static HitCount count("ScrollableImageCache: scrolling"); | |
29 | |
26 int dx = (v->getXForFrame(m_startFrame) - | 30 int dx = (v->getXForFrame(m_startFrame) - |
27 v->getXForFrame(newStartFrame)); | 31 v->getXForFrame(newStartFrame)); |
28 | 32 |
29 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE | 33 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE |
30 cerr << "ScrollableImageCache::scrollTo: start frame " << m_startFrame | 34 cerr << "ScrollableImageCache::scrollTo: start frame " << m_startFrame |
31 << " -> " << newStartFrame << ", dx = " << dx << endl; | 35 << " -> " << newStartFrame << ", dx = " << dx << endl; |
32 #endif | 36 #endif |
33 | 37 |
34 if (m_startFrame == newStartFrame) { | 38 if (m_startFrame == newStartFrame) { |
35 // haven't moved | 39 // haven't moved |
40 count.hit(); | |
36 return; | 41 return; |
37 } | 42 } |
38 | 43 |
39 m_startFrame = newStartFrame; | 44 m_startFrame = newStartFrame; |
40 | 45 |
41 if (!isValid()) { | 46 if (!isValid()) { |
47 count.miss(); | |
42 return; | 48 return; |
43 } | 49 } |
44 | 50 |
45 int w = m_image.width(); | 51 int w = m_image.width(); |
46 | 52 |
47 if (dx == 0) { | 53 if (dx == 0) { |
48 // haven't moved visibly (even though start frame may have changed) | 54 // haven't moved visibly (even though start frame may have changed) |
55 count.hit(); | |
49 return; | 56 return; |
50 } | 57 } |
51 | 58 |
52 if (dx <= -w || dx >= w) { | 59 if (dx <= -w || dx >= w) { |
53 // scrolled entirely off | 60 // scrolled entirely off |
54 invalidate(); | 61 invalidate(); |
55 return; | 62 count.miss(); |
56 } | 63 return; |
64 } | |
65 | |
66 count.partial(); | |
57 | 67 |
58 // dx is in range, cache is scrollable | 68 // dx is in range, cache is scrollable |
59 | 69 |
60 int dxp = dx; | 70 int dxp = dx; |
61 if (dxp < 0) dxp = -dxp; | 71 if (dxp < 0) dxp = -dxp; |