panel.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. //! Diagnostics: the run's numbers on the picture (`VICTORY_PANEL=1`; off by
  2. //! default; F3 shows and hides it while our window has the focus): white
  3. //! text on a black box in the upper left corner of what is shown, so that a
  4. //! screenshot carries them, with what it costs itself on the submitting
  5. //! thread. Made again twice a second from the counters of
  6. //! the frame-rate line, memory and textures; a frame itself only copies the
  7. //! box out of a buffer in the card's memory. Copied onto the swap chain's
  8. //! buffer, behind the title's picture: saved frames and the frame recorder
  9. //! see the title's own.
  10. use std::sync::OnceLock;
  11. use std::sync::atomic::{AtomicBool, Ordering};
  12. use std::time::{Duration, Instant};
  13. use windows::Win32::Graphics::Direct3D12::*;
  14. use windows::Win32::Graphics::Dxgi::Common::*;
  15. use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_F3};
  16. use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
  17. use super::{Host, HostList, transition};
  18. /// How often the numbers change.
  19. const EVERY: Duration = Duration::from_millis(500);
  20. /// A character's dots, and with the space beside and below it.
  21. const GLYPH: (u32, u32) = (5, 7);
  22. const CELL: (u32, u32) = (6, 9);
  23. /// Characters in a line, lines, and the box's rim in dots.
  24. const COLUMNS: u32 = 40;
  25. const LINES: u32 = 9;
  26. const RIM: u32 = 3;
  27. /// The texts are put into one of these in turn: the card reads the others,
  28. /// at most half a second old.
  29. const UPLOADS: usize = 4;
  30. fn asked() -> bool {
  31. static ON: OnceLock<bool> = OnceLock::new();
  32. *ON.get_or_init(|| crate::switch::on("VICTORY_PANEL"))
  33. }
  34. /// Whether it is shown now.
  35. fn shown() -> &'static AtomicBool {
  36. static SHOWN: OnceLock<AtomicBool> = OnceLock::new();
  37. SHOWN.get_or_init(|| AtomicBool::new(asked()))
  38. }
  39. /// F3 was pressed since the last call, with one of our windows in front.
  40. fn pressed() -> bool {
  41. static DOWN: AtomicBool = AtomicBool::new(false);
  42. // SAFETY: a plain query.
  43. let down = unsafe { GetAsyncKeyState(i32::from(VK_F3)) } < 0;
  44. if DOWN.swap(down, Ordering::Relaxed) || !down {
  45. return false;
  46. }
  47. let mut process = 0;
  48. // SAFETY: plain queries; room for the answer.
  49. unsafe { GetWindowThreadProcessId(GetForegroundWindow(), &mut process) };
  50. process == std::process::id()
  51. }
  52. /// Seven rows of five dots, the leftmost the highest bit.
  53. #[rustfmt::skip]
  54. const fn glyph(c: u8) -> [u8; 7] {
  55. match c {
  56. b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110],
  57. b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
  58. b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111],
  59. b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110],
  60. b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010],
  61. b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110],
  62. b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110],
  63. b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100],
  64. b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110],
  65. b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100],
  66. b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001],
  67. b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110],
  68. b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111],
  69. b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110],
  70. b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111],
  71. b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000],
  72. b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111],
  73. b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
  74. b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
  75. b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100],
  76. b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
  77. b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
  78. b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
  79. b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001],
  80. b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
  81. b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000],
  82. b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101],
  83. b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001],
  84. b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110],
  85. b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
  86. b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
  87. b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
  88. b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
  89. b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
  90. b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
  91. b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
  92. b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100],
  93. b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
  94. b'-' => [0, 0, 0, 0b11111, 0, 0, 0],
  95. b' ' => [0; 7],
  96. _ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111],
  97. }
  98. }
  99. /// The box's size in pixels, a dot being `scale` of them each way.
  100. const fn size(scale: u32) -> (u32, u32) {
  101. ((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale)
  102. }
  103. /// Pixels to a dot for a picture that high: a 720-line screenshot of it
  104. /// shows one and a third.
  105. fn scale(height: u32) -> u32 {
  106. (height / 540).max(1)
  107. }
  108. /// Whether a dot of the picture of `lines` is white.
  109. fn lit(lines: &[String], x: u32, y: u32) -> bool {
  110. let (Some(x), Some(y)) = (x.checked_sub(RIM), y.checked_sub(RIM)) else {
  111. return false;
  112. };
  113. if x % CELL.0 >= GLYPH.0 || y % CELL.1 >= GLYPH.1 || x / CELL.0 >= COLUMNS {
  114. return false;
  115. }
  116. let Some(&c) = lines.get((y / CELL.1) as usize).and_then(|l| l.as_bytes().get((x / CELL.0) as usize)) else {
  117. return false;
  118. };
  119. (glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0
  120. }
  121. /// The bytes of a black and a white pixel of a swap chain's format.
  122. fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> {
  123. Some(match format {
  124. DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]],
  125. DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]],
  126. // Halves of 0 and 1.
  127. DXGI_FORMAT_R16G16B16A16_FLOAT => [
  128. &[0, 0, 0, 0, 0, 0, 0, 0x3C],
  129. &[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C],
  130. ],
  131. _ => return None,
  132. })
  133. }
  134. /// The box as rows of `pitch` bytes.
  135. fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec<u8> {
  136. let (width, height) = size(scale);
  137. let bytes = colours[0].len();
  138. let mut out = vec![0; pitch * height as usize];
  139. for y in 0..height / scale {
  140. let top = pitch * (y * scale) as usize;
  141. for x in 0..width / scale {
  142. let colour = colours[usize::from(lit(lines, x, y))];
  143. for i in 0..scale {
  144. let at = top + (x * scale + i) as usize * bytes;
  145. out[at..at + bytes].copy_from_slice(colour);
  146. }
  147. }
  148. for i in 1..scale as usize {
  149. out.copy_within(top..top + pitch, top + i * pitch);
  150. }
  151. }
  152. out
  153. }
  154. /// The counters read for it. They grow, and go back to 0 with the frame-rate
  155. /// line (right behind a look of ours).
  156. #[derive(Clone, Copy, Default)]
  157. struct Counters([u64; COUNTERS]);
  158. const COUNTERS: usize = 11;
  159. impl Counters {
  160. fn now() -> Counters {
  161. use super::{CARD_CLOCK_US, COPY_BACK, PREPARING};
  162. use crate::copystat::{C, peek};
  163. let get = |a: &std::sync::atomic::AtomicU64| a.load(Ordering::Relaxed);
  164. Counters([
  165. super::worked(),
  166. get(&CARD_CLOCK_US[0]),
  167. get(&CARD_CLOCK_US[1]),
  168. get(&CARD_CLOCK_US[2]),
  169. get(&PREPARING[3]),
  170. get(&COPY_BACK[0]),
  171. get(&COPY_BACK[1]),
  172. get(&crate::shadow::CARD_STATS[0]),
  173. crate::draw::dropped_now(),
  174. peek(C::RecordNs),
  175. crate::draw::drawn(),
  176. ])
  177. }
  178. /// What came since `before`, per frame.
  179. fn since(self, before: Counters, frames: f64) -> [f64; COUNTERS] {
  180. let mut out = [0.0; COUNTERS];
  181. for (i, out) in out.iter_mut().enumerate() {
  182. let (was, is) = (before.0[i], self.0[i]);
  183. *out = if is >= was { is - was } else { is } as f64 / frames;
  184. }
  185. out
  186. }
  187. }
  188. /// The text. `c`: [`Counters`] per frame, `ms` a frame's time, `worst` the
  189. /// longest frame's, `cost` what this takes of a frame, in microseconds.
  190. fn text(c: &[f64; COUNTERS], ms: f64, worst: f64, cost: f64, host: &Host) -> Vec<String> {
  191. let gb = |bytes: u64| bytes as f64 / (1u64 << 30) as f64;
  192. let (working, private) = crate::copystat::process_memory();
  193. let [budget, used, _, shared] = host.video_memory().unwrap_or_default();
  194. let idle = (c[1] / 1e3).min(ms);
  195. vec![
  196. format!("FPS {:.1} FRAME {ms:.1} MS LONGEST {worst:.0}", 1e3 / ms.max(0.001)),
  197. format!("DRAWS {:.0} DROPPED {:.0}", c[10], c[8]),
  198. format!("SUBMIT BUSY {:.1} WAITS FOR GPU {:.1}", c[0] / 1e3, c[3] / 1e3),
  199. format!("GPU BUSY {:.1} IDLE BEHIND US {:.1}", ms - idle, c[2] / 1e3),
  200. format!("RECORDING {:.0} MS COPY BACK {:.1}", c[9] / 1e6, c[5] / 1e3),
  201. format!("MB UP {:.0} TEXTURES {:.0} BACK {:.0}", c[7] / 1e6, c[4] / 1e6, c[6] / 1e6),
  202. format!("RAM {:.1} GB IN MEMORY {:.1}", gb(private), gb(working)),
  203. format!("VRAM {:.1}/{:.1} GB SHARED {:.1}", gb(used), gb(budget), gb(shared)),
  204. format!("THIS PANEL {:.0} US A FRAME", cost),
  205. ]
  206. }
  207. /// The buffers of a box that size and format.
  208. struct Buffers {
  209. format: DXGI_FORMAT,
  210. scale: u32,
  211. pitch: u32,
  212. uploads: Vec<(ID3D12Resource, *mut u8)>,
  213. card: ID3D12Resource,
  214. /// The upload written last.
  215. turn: usize,
  216. /// It is not in the card's buffer yet.
  217. fresh: bool,
  218. }
  219. // SAFETY: free-threaded resources, and memory only written under the presenter's lock.
  220. unsafe impl Send for Buffers {}
  221. impl Buffers {
  222. fn new(host: &Host, format: DXGI_FORMAT, scale: u32) -> Option<Buffers> {
  223. let (width, height) = size(scale);
  224. let pitch = (width * colours(format)?[0].len() as u32).next_multiple_of(256);
  225. let bytes = u64::from(pitch) * u64::from(height);
  226. let uploads = (0..UPLOADS).map(|_| host.upload_buffer(bytes)).collect::<Option<Vec<_>>>()?;
  227. let heap = D3D12_HEAP_PROPERTIES {
  228. Type: D3D12_HEAP_TYPE_DEFAULT,
  229. ..Default::default()
  230. };
  231. let desc = D3D12_RESOURCE_DESC {
  232. Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
  233. Width: bytes,
  234. Height: 1,
  235. DepthOrArraySize: 1,
  236. MipLevels: 1,
  237. SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
  238. Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
  239. ..Default::default()
  240. };
  241. let mut card: Option<ID3D12Resource> = None;
  242. // SAFETY: plain creation of a buffer.
  243. unsafe {
  244. host.device
  245. .CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut card)
  246. .ok()?;
  247. }
  248. Some(Buffers { format, scale, pitch, uploads, card: card?, turn: 0, fresh: false })
  249. }
  250. fn write(&mut self, lines: &[String]) {
  251. let Some(colours) = colours(self.format) else { return };
  252. let picture = painted(lines, self.scale, colours, self.pitch as usize);
  253. self.turn = (self.turn + 1) % UPLOADS;
  254. // SAFETY: a mapped upload buffer of the picture's size, which the card read a second or more ago.
  255. unsafe { std::ptr::copy_nonoverlapping(picture.as_ptr(), self.uploads[self.turn].1, picture.len()) };
  256. self.fresh = true;
  257. }
  258. }
  259. /// The panel of a presenter.
  260. pub(super) struct Panel {
  261. since: Instant,
  262. frames: u32,
  263. last: Instant,
  264. worst: f64,
  265. /// What this took since the last text.
  266. cost: Duration,
  267. before: Counters,
  268. lines: Vec<String>,
  269. changed: bool,
  270. buffers: Option<Buffers>,
  271. failed: bool,
  272. }
  273. impl Panel {
  274. pub(super) fn new() -> Panel {
  275. let now = Instant::now();
  276. Panel {
  277. since: now,
  278. frames: 0,
  279. last: now,
  280. worst: 0.0,
  281. cost: Duration::ZERO,
  282. before: Counters::default(),
  283. lines: Vec::new(),
  284. changed: false,
  285. buffers: None,
  286. failed: false,
  287. }
  288. }
  289. /// A frame was presented; `line`: the counters go back to 0 right behind
  290. /// this call. (Not shown it asks for the key's state and no more.)
  291. pub(super) fn frame(&mut self, line: bool) {
  292. if pressed() {
  293. shown().fetch_xor(true, Ordering::Relaxed);
  294. }
  295. if !shown().load(Ordering::Relaxed) {
  296. self.frames = 0;
  297. return;
  298. }
  299. let now = Instant::now();
  300. if self.frames == 0 && now - self.last > 2 * EVERY {
  301. // (Shown from here on.)
  302. (self.since, self.last, self.worst, self.before) = (now, now, 0.0, Counters::now());
  303. self.frames = 0;
  304. }
  305. self.frames += 1;
  306. self.worst = self.worst.max((now - self.last).as_secs_f64() * 1e3);
  307. self.last = now;
  308. let elapsed = now - self.since;
  309. if elapsed < EVERY && !(line && elapsed * 2 >= EVERY) {
  310. return;
  311. }
  312. let Some(host) = super::host() else { return };
  313. let frames = f64::from(self.frames);
  314. let counters = Counters::now();
  315. let c = counters.since(self.before, frames);
  316. self.before = counters;
  317. let cost = self.cost.as_secs_f64() * 1e6 / frames;
  318. self.lines = text(&c, elapsed.as_secs_f64() * 1e3 / frames, self.worst, cost, host);
  319. self.changed = true;
  320. (self.since, self.frames, self.worst) = (now, 0, 0.0);
  321. self.cost = now.elapsed();
  322. }
  323. /// Records the copy of the box onto `back`, a buffer of the swap chain of
  324. /// that size and format in the state to be copied into.
  325. pub(super) fn draw(
  326. &mut self,
  327. host: &Host,
  328. list: &HostList,
  329. back: &ID3D12Resource,
  330. (width, height): (u32, u32),
  331. format: DXGI_FORMAT,
  332. ) {
  333. if !shown().load(Ordering::Relaxed) || self.lines.is_empty() || self.failed {
  334. return;
  335. }
  336. let began = Instant::now();
  337. // Not the title's: the frame recorder leaves it out.
  338. let _ours = crate::replay::record::unrecorded();
  339. let scale = scale(height);
  340. if self.buffers.as_ref().is_none_or(|b| (b.format, b.scale) != (format, scale)) {
  341. // (What the card may still read stays: a picture's size changes once or twice in a run.)
  342. std::mem::forget(self.buffers.take());
  343. self.buffers = Buffers::new(host, format, scale);
  344. self.failed = self.buffers.is_none();
  345. self.changed = true;
  346. }
  347. let Some(buffers) = &mut self.buffers else { return };
  348. if std::mem::take(&mut self.changed) {
  349. buffers.write(&self.lines);
  350. }
  351. let (w, h) = size(scale);
  352. let list = &list.list;
  353. // SAFETY: an open list and live resources; the box lies within both.
  354. unsafe {
  355. if std::mem::take(&mut buffers.fresh) {
  356. list.CopyResource(&buffers.card, &buffers.uploads[buffers.turn].0);
  357. list.ResourceBarrier(&[transition(
  358. &buffers.card,
  359. D3D12_RESOURCE_STATE_COPY_DEST,
  360. D3D12_RESOURCE_STATE_COPY_SOURCE,
  361. )]);
  362. }
  363. let from = D3D12_TEXTURE_COPY_LOCATION {
  364. pResource: std::mem::transmute_copy(&buffers.card),
  365. Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
  366. Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 {
  367. PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
  368. Offset: 0,
  369. Footprint: D3D12_SUBRESOURCE_FOOTPRINT {
  370. Format: format,
  371. Width: w,
  372. Height: h,
  373. Depth: 1,
  374. RowPitch: buffers.pitch,
  375. },
  376. },
  377. },
  378. };
  379. let to = D3D12_TEXTURE_COPY_LOCATION {
  380. pResource: std::mem::transmute_copy(back),
  381. Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
  382. Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 },
  383. };
  384. let part = D3D12_BOX {
  385. left: 0,
  386. top: 0,
  387. front: 0,
  388. right: w.min(width),
  389. bottom: h.min(height),
  390. back: 1,
  391. };
  392. list.CopyTextureRegion(&to, 0, 0, 0, &from, Some(&part));
  393. }
  394. self.cost += began.elapsed();
  395. }
  396. }
  397. #[cfg(test)]
  398. mod tests {
  399. use super::*;
  400. /// Every character the lines use has its own picture, and no two look
  401. /// alike.
  402. #[test]
  403. fn characters_differ() {
  404. let used: Vec<u8> = (b'0'..=b'9').chain(b'A'..=b'Z').chain(*b"./- ").collect();
  405. for (i, a) in used.iter().enumerate() {
  406. assert_ne!(glyph(*a), glyph(b'#'), "{} has a picture", *a as char);
  407. assert!(glyph(*a).iter().all(|row| row >> GLYPH.0 == 0));
  408. for b in &used[i + 1..] {
  409. assert_ne!(glyph(*a), glyph(*b), "{} {}", *a as char, *b as char);
  410. }
  411. }
  412. }
  413. #[test]
  414. fn a_box_is_painted() {
  415. let lines = vec!["I".to_owned(), " i".to_owned()];
  416. for scale in [1, 2, 4] {
  417. let (width, height) = size(scale);
  418. let pitch = (width * 4).next_multiple_of(256) as usize;
  419. let colours = colours(DXGI_FORMAT_R10G10B10A2_UNORM).unwrap();
  420. let picture = painted(&lines, scale, colours, pitch);
  421. assert_eq!(picture.len(), pitch * height as usize);
  422. let at = |x: u32, y: u32| &picture[y as usize * pitch + x as usize * 4..][..4];
  423. // The rim is black, the first letter's top row lit in its middle.
  424. assert_eq!(at(0, 0), colours[0]);
  425. assert_eq!(at((RIM + 2) * scale, RIM * scale), colours[1]);
  426. assert_eq!(at((RIM + 2) * scale + scale - 1, RIM * scale + scale - 1), colours[1]);
  427. assert_eq!(at(RIM * scale, RIM * scale), colours[0]);
  428. // Small letters are shown as capitals, a line and a cell on.
  429. assert_eq!(at((RIM + CELL.0 + 2) * scale, (RIM + CELL.1) * scale), colours[1]);
  430. // Nothing past a line's end.
  431. assert_eq!(at((RIM + CELL.0 * 2 + 2) * scale, (RIM + CELL.1) * scale), colours[0]);
  432. }
  433. }
  434. #[test]
  435. fn counters_that_went_back_to_nothing_count_from_there() {
  436. let (mut a, mut b) = (Counters::default(), Counters::default());
  437. (a.0[0], b.0[0]) = (10, 30);
  438. (a.0[1], b.0[1]) = (50, 20);
  439. let c = b.since(a, 10.0);
  440. assert_eq!((c[0], c[1]), (2.0, 2.0));
  441. }
  442. }